|
1 /* |
|
2 * |
|
3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved |
|
4 * |
|
5 */ |
|
6 |
|
7 #include "LETypes.h" |
|
8 #include "LEFontInstance.h" |
|
9 #include "OpenTypeTables.h" |
|
10 #include "AnchorTables.h" |
|
11 #include "MarkArrays.h" |
|
12 #include "GlyphPositioningTables.h" |
|
13 #include "AttachmentPosnSubtables.h" |
|
14 #include "MarkToBasePosnSubtables.h" |
|
15 #include "GlyphIterator.h" |
|
16 #include "LESwaps.h" |
|
17 |
|
18 U_NAMESPACE_BEGIN |
|
19 |
|
20 LEGlyphID MarkToBasePositioningSubtable::findBaseGlyph(GlyphIterator *glyphIterator) const |
|
21 { |
|
22 if (glyphIterator->prev()) { |
|
23 return glyphIterator->getCurrGlyphID(); |
|
24 } |
|
25 |
|
26 return 0xFFFF; |
|
27 } |
|
28 |
|
29 le_int32 MarkToBasePositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const |
|
30 { |
|
31 LEGlyphID markGlyph = glyphIterator->getCurrGlyphID(); |
|
32 le_int32 markCoverage = getGlyphCoverage((LEGlyphID) markGlyph); |
|
33 |
|
34 if (markCoverage < 0) { |
|
35 // markGlyph isn't a covered mark glyph |
|
36 return 0; |
|
37 } |
|
38 |
|
39 LEPoint markAnchor; |
|
40 const MarkArray *markArray = (const MarkArray *) ((char *) this + SWAPW(markArrayOffset)); |
|
41 le_int32 markClass = markArray->getMarkClass(markGlyph, markCoverage, fontInstance, markAnchor); |
|
42 le_uint16 mcCount = SWAPW(classCount); |
|
43 |
|
44 if (markClass < 0 || markClass >= mcCount) { |
|
45 // markGlyph isn't in the mark array or its |
|
46 // mark class is too big. The table is mal-formed! |
|
47 return 0; |
|
48 } |
|
49 |
|
50 // FIXME: We probably don't want to find a base glyph before a previous ligature... |
|
51 GlyphIterator baseIterator(*glyphIterator, (le_uint16) (lfIgnoreMarks /*| lfIgnoreLigatures*/)); |
|
52 LEGlyphID baseGlyph = findBaseGlyph(&baseIterator); |
|
53 le_int32 baseCoverage = getBaseCoverage((LEGlyphID) baseGlyph); |
|
54 const BaseArray *baseArray = (const BaseArray *) ((char *) this + SWAPW(baseArrayOffset)); |
|
55 le_uint16 baseCount = SWAPW(baseArray->baseRecordCount); |
|
56 |
|
57 if (baseCoverage < 0 || baseCoverage >= baseCount) { |
|
58 // The base glyph isn't covered, or the coverage |
|
59 // index is too big. The latter means that the |
|
60 // table is mal-formed... |
|
61 return 0; |
|
62 } |
|
63 |
|
64 const BaseRecord *baseRecord = &baseArray->baseRecordArray[baseCoverage * mcCount]; |
|
65 Offset anchorTableOffset = SWAPW(baseRecord->baseAnchorTableOffsetArray[markClass]); |
|
66 const AnchorTable *anchorTable = (const AnchorTable *) ((char *) baseArray + anchorTableOffset); |
|
67 LEPoint baseAnchor, markAdvance, pixels; |
|
68 |
|
69 if (anchorTableOffset == 0) { |
|
70 // this means the table is mal-formed... |
|
71 glyphIterator->setCurrGlyphBaseOffset(baseIterator.getCurrStreamPosition()); |
|
72 return 0; |
|
73 } |
|
74 |
|
75 anchorTable->getAnchor(baseGlyph, fontInstance, baseAnchor); |
|
76 |
|
77 fontInstance->getGlyphAdvance(markGlyph, pixels); |
|
78 fontInstance->pixelsToUnits(pixels, markAdvance); |
|
79 |
|
80 float anchorDiffX = baseAnchor.fX - markAnchor.fX; |
|
81 float anchorDiffY = baseAnchor.fY - markAnchor.fY; |
|
82 |
|
83 glyphIterator->setCurrGlyphBaseOffset(baseIterator.getCurrStreamPosition()); |
|
84 |
|
85 if (glyphIterator->isRightToLeft()) { |
|
86 glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX, anchorDiffY, -markAdvance.fX, -markAdvance.fY); |
|
87 } else { |
|
88 LEPoint baseAdvance; |
|
89 |
|
90 fontInstance->getGlyphAdvance(baseGlyph, pixels); |
|
91 fontInstance->pixelsToUnits(pixels, baseAdvance); |
|
92 |
|
93 glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX - baseAdvance.fX, anchorDiffY - baseAdvance.fY, -markAdvance.fX, -markAdvance.fY); |
|
94 } |
|
95 |
|
96 return 1; |
|
97 } |
|
98 |
|
99 U_NAMESPACE_END |