sl@0: /* 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 "MarkToBasePosnSubtables.h" sl@0: #include "GlyphIterator.h" sl@0: #include "LESwaps.h" sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: LEGlyphID MarkToBasePositioningSubtable::findBaseGlyph(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 MarkToBasePositioningSubtable::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 base glyph before a previous ligature... sl@0: GlyphIterator baseIterator(*glyphIterator, (le_uint16) (lfIgnoreMarks /*| lfIgnoreLigatures*/)); sl@0: LEGlyphID baseGlyph = findBaseGlyph(&baseIterator); sl@0: le_int32 baseCoverage = getBaseCoverage((LEGlyphID) baseGlyph); sl@0: const BaseArray *baseArray = (const BaseArray *) ((char *) this + SWAPW(baseArrayOffset)); sl@0: le_uint16 baseCount = SWAPW(baseArray->baseRecordCount); sl@0: sl@0: if (baseCoverage < 0 || baseCoverage >= baseCount) { sl@0: // The base 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: const BaseRecord *baseRecord = &baseArray->baseRecordArray[baseCoverage * mcCount]; sl@0: Offset anchorTableOffset = SWAPW(baseRecord->baseAnchorTableOffsetArray[markClass]); sl@0: const AnchorTable *anchorTable = (const AnchorTable *) ((char *) baseArray + anchorTableOffset); sl@0: LEPoint baseAnchor, markAdvance, pixels; sl@0: sl@0: if (anchorTableOffset == 0) { sl@0: // this means the table is mal-formed... sl@0: glyphIterator->setCurrGlyphBaseOffset(baseIterator.getCurrStreamPosition()); sl@0: return 0; sl@0: } sl@0: sl@0: anchorTable->getAnchor(baseGlyph, fontInstance, baseAnchor); sl@0: sl@0: fontInstance->getGlyphAdvance(markGlyph, pixels); sl@0: fontInstance->pixelsToUnits(pixels, markAdvance); sl@0: sl@0: float anchorDiffX = baseAnchor.fX - markAnchor.fX; sl@0: float anchorDiffY = baseAnchor.fY - markAnchor.fY; sl@0: sl@0: glyphIterator->setCurrGlyphBaseOffset(baseIterator.getCurrStreamPosition()); sl@0: sl@0: if (glyphIterator->isRightToLeft()) { sl@0: glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX, anchorDiffY, -markAdvance.fX, -markAdvance.fY); sl@0: } else { sl@0: LEPoint baseAdvance; sl@0: sl@0: fontInstance->getGlyphAdvance(baseGlyph, pixels); sl@0: fontInstance->pixelsToUnits(pixels, baseAdvance); sl@0: sl@0: glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX - baseAdvance.fX, anchorDiffY - baseAdvance.fY, -markAdvance.fX, -markAdvance.fY); sl@0: } sl@0: sl@0: return 1; sl@0: } sl@0: sl@0: U_NAMESPACE_END