4
* (C) Copyright IBM Corp. 1998, 1999, 2000, 2001 - All Rights Reserved
9
#include "LEFontInstance.h"
10
#include "OpenTypeTables.h"
11
#include "AnchorTables.h"
12
#include "MarkArrays.h"
13
#include "GlyphPositioningTables.h"
14
#include "AttachmentPosnSubtables.h"
15
#include "MarkToLigaturePosnSubtables.h"
16
#include "GlyphIterator.h"
21
LEGlyphID MarkToLigaturePositioningSubtable::findLigatureGlyph(GlyphIterator *glyphIterator) const
23
if (glyphIterator->prev()) {
24
return glyphIterator->getCurrGlyphID();
30
le_int32 MarkToLigaturePositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
32
LEGlyphID markGlyph = glyphIterator->getCurrGlyphID();
33
le_int32 markCoverage = getGlyphCoverage((LEGlyphID) markGlyph);
35
if (markCoverage < 0) {
36
// markGlyph isn't a covered mark glyph
41
const MarkArray *markArray = (const MarkArray *) ((char *) this + SWAPW(markArrayOffset));
42
le_int32 markClass = markArray->getMarkClass(markGlyph, markCoverage, fontInstance, markAnchor);
43
le_uint16 mcCount = SWAPW(classCount);
45
if (markClass < 0 || markClass >= mcCount) {
46
// markGlyph isn't in the mark array or its
47
// mark class is too big. The table is mal-formed!
51
// FIXME: we probably don't want to find a ligature before a previous base glyph...
52
GlyphIterator ligatureIterator(*glyphIterator, lfIgnoreMarks /*| lfIgnoreBaseGlyphs*/);
53
LEGlyphID ligatureGlyph = findLigatureGlyph(&ligatureIterator);
54
le_int32 ligatureCoverage = getBaseCoverage((LEGlyphID) ligatureGlyph);
55
const LigatureArray *ligatureArray = (const LigatureArray *) ((char *) this + SWAPW(baseArrayOffset));
56
le_uint16 ligatureCount = SWAPW(ligatureArray->ligatureCount);
58
if (ligatureCoverage < 0 || ligatureCoverage >= ligatureCount) {
59
// The ligature glyph isn't covered, or the coverage
60
// index is too big. The latter means that the
61
// table is mal-formed...
65
le_int32 markPosition = glyphIterator->getCurrStreamPosition();
66
Offset ligatureAttachOffset = SWAPW(ligatureArray->ligatureAttachTableOffsetArray[ligatureCoverage]);
67
const LigatureAttachTable *ligatureAttachTable = (const LigatureAttachTable *) ((char *) ligatureArray + ligatureAttachOffset);
68
le_int32 componentCount = SWAPW(ligatureAttachTable->componentCount);
69
le_int32 component = ligatureIterator.getMarkComponent(markPosition);
71
if (component >= componentCount) {
72
// should really just bail at this point...
73
component = componentCount - 1;
76
const ComponentRecord *componentRecord = &ligatureAttachTable->componentRecordArray[component * mcCount];
77
Offset anchorTableOffset = SWAPW(componentRecord->ligatureAnchorTableOffsetArray[markClass]);
78
const AnchorTable *anchorTable = (const AnchorTable *) ((char *) ligatureAttachTable + anchorTableOffset);
79
LEPoint ligatureAnchor, markAdvance, pixels;
81
anchorTable->getAnchor(ligatureGlyph, fontInstance, ligatureAnchor);
83
fontInstance->getGlyphAdvance(markGlyph, pixels);
84
fontInstance->pixelsToUnits(pixels, markAdvance);
86
float anchorDiffX = ligatureAnchor.fX - markAnchor.fX;
87
float anchorDiffY = ligatureAnchor.fY - markAnchor.fY;
89
if (glyphIterator->isRightToLeft()) {
90
float adjustX = markAdvance.fX + anchorDiffX;
92
glyphIterator->adjustCurrGlyphPositionAdjustment(anchorDiffX, -anchorDiffY, -adjustX, anchorDiffY);
94
LEPoint ligatureAdvance;
96
fontInstance->getGlyphAdvance(ligatureGlyph, pixels);
97
fontInstance->pixelsToUnits(pixels, ligatureAdvance);
99
float adjustX = ligatureAdvance.fX - anchorDiffX;
100
float advAdjustX = adjustX - markAdvance.fX;
102
glyphIterator->adjustCurrGlyphPositionAdjustment(-adjustX, -anchorDiffY, advAdjustX, anchorDiffY);