sl@0: /* sl@0: * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved sl@0: * sl@0: */ sl@0: sl@0: #include "LETypes.h" sl@0: #include "LEFontInstance.h" sl@0: #include "OpenTypeTables.h" sl@0: #include "AnchorTables.h" sl@0: #include "MarkArrays.h" sl@0: #include "GlyphPositioningTables.h" sl@0: #include "AttachmentPosnSubtables.h" sl@0: #include "MarkToLigaturePosnSubtables.h" sl@0: #include "GlyphIterator.h" sl@0: #include "LESwaps.h" sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: LEGlyphID MarkToLigaturePositioningSubtable::findLigatureGlyph(GlyphIterator *glyphIterator) const sl@0: { sl@0: if (glyphIterator->prev()) { sl@0: return glyphIterator->getCurrGlyphID(); sl@0: } sl@0: sl@0: return 0xFFFF; sl@0: } sl@0: sl@0: le_int32 MarkToLigaturePositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const sl@0: { sl@0: LEGlyphID markGlyph = glyphIterator->getCurrGlyphID(); sl@0: le_int32 markCoverage = getGlyphCoverage((LEGlyphID) markGlyph); sl@0: sl@0: if (markCoverage < 0) { sl@0: // markGlyph isn't a covered mark glyph sl@0: return 0; sl@0: } sl@0: sl@0: LEPoint markAnchor; sl@0: const MarkArray *markArray = (const MarkArray *) ((char *) this + SWAPW(markArrayOffset)); sl@0: le_int32 markClass = markArray->getMarkClass(markGlyph, markCoverage, fontInstance, markAnchor); sl@0: le_uint16 mcCount = SWAPW(classCount); sl@0: sl@0: if (markClass < 0 || markClass >= mcCount) { sl@0: // markGlyph isn't in the mark array or its sl@0: // mark class is too big. The table is mal-formed! sl@0: return 0; sl@0: } sl@0: sl@0: // FIXME: we probably don't want to find a ligature before a previous base glyph... sl@0: GlyphIterator ligatureIterator(*glyphIterator, (le_uint16) (lfIgnoreMarks /*| lfIgnoreBaseGlyphs*/)); sl@0: LEGlyphID ligatureGlyph = findLigatureGlyph(&ligatureIterator); sl@0: le_int32 ligatureCoverage = getBaseCoverage((LEGlyphID) ligatureGlyph); sl@0: const LigatureArray *ligatureArray = (const LigatureArray *) ((char *) this + SWAPW(baseArrayOffset)); sl@0: le_uint16 ligatureCount = SWAPW(ligatureArray->ligatureCount); sl@0: sl@0: if (ligatureCoverage < 0 || ligatureCoverage >= ligatureCount) { sl@0: // The ligature glyph isn't covered, or the coverage sl@0: // index is too big. The latter means that the sl@0: // table is mal-formed... sl@0: return 0; sl@0: } sl@0: sl@0: le_int32 markPosition = glyphIterator->getCurrStreamPosition(); sl@0: Offset ligatureAttachOffset = SWAPW(ligatureArray->ligatureAttachTableOffsetArray[ligatureCoverage]); sl@0: const LigatureAttachTable *ligatureAttachTable = (const LigatureAttachTable *) ((char *) ligatureArray + ligatureAttachOffset); sl@0: le_int32 componentCount = SWAPW(ligatureAttachTable->componentCount); sl@0: le_int32 component = ligatureIterator.getMarkComponent(markPosition); sl@0: sl@0: if (component >= componentCount) { sl@0: // should really just bail at this point... sl@0: component = componentCount - 1; sl@0: } sl@0: sl@0: const ComponentRecord *componentRecord = &ligatureAttachTable->componentRecordArray[component * mcCount]; sl@0: Offset anchorTableOffset = SWAPW(componentRecord->ligatureAnchorTableOffsetArray[markClass]); sl@0: const AnchorTable *anchorTable = (const AnchorTable *) ((char *) ligatureAttachTable + anchorTableOffset); sl@0: LEPoint ligatureAnchor, markAdvance, pixels; sl@0: sl@0: anchorTable->getAnchor(ligatureGlyph, fontInstance, ligatureAnchor); sl@0: sl@0: fontInstance->getGlyphAdvance(markGlyph, pixels); sl@0: fontInstance->pixelsToUnits(pixels, markAdvance); sl@0: sl@0: float anchorDiffX = ligatureAnchor.fX - markAnchor.fX; sl@0: float anchorDiffY = ligatureAnchor.fY - markAnchor.fY; sl@0: sl@0: glyphIterator->setCurrGlyphBaseOffset(ligatureIterator.getCurrStreamPosition()); sl@0: sl@0: if (glyphIterator->isRightToLeft()) { sl@0: glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX, anchorDiffY, -markAdvance.fX, -markAdvance.fY); sl@0: } else { sl@0: LEPoint ligatureAdvance; sl@0: sl@0: fontInstance->getGlyphAdvance(ligatureGlyph, pixels); sl@0: fontInstance->pixelsToUnits(pixels, ligatureAdvance); sl@0: sl@0: glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX - ligatureAdvance.fX, anchorDiffY - ligatureAdvance.fY, -markAdvance.fX, -markAdvance.fY); sl@0: } sl@0: sl@0: return 1; sl@0: } sl@0: sl@0: U_NAMESPACE_END