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