2
* @(#)MarkToBasePosnSubtables.cpp 1.5 00/03/15
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 "MarkToBasePosnSubtables.h"
16
#include "GlyphIterator.h"
21
LEGlyphID MarkToBasePositioningSubtable::findBaseGlyph(GlyphIterator *glyphIterator) const
23
if (glyphIterator->prev()) {
24
return glyphIterator->getCurrGlyphID();
30
le_int32 MarkToBasePositioningSubtable::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 base glyph before a previous ligature...
52
GlyphIterator baseIterator(*glyphIterator, lfIgnoreMarks /*| lfIgnoreLigatures*/);
53
LEGlyphID baseGlyph = findBaseGlyph(&baseIterator);
54
le_int32 baseCoverage = getBaseCoverage((LEGlyphID) baseGlyph);
55
const BaseArray *baseArray = (const BaseArray *) ((char *) this + SWAPW(baseArrayOffset));
56
le_uint16 baseCount = SWAPW(baseArray->baseRecordCount);
58
if (baseCoverage < 0 || baseCoverage >= baseCount) {
59
// The base glyph isn't covered, or the coverage
60
// index is too big. The latter means that the
61
// table is mal-formed...
65
const BaseRecord *baseRecord = &baseArray->baseRecordArray[baseCoverage * mcCount];
66
Offset anchorTableOffset = SWAPW(baseRecord->baseAnchorTableOffsetArray[markClass]);
67
const AnchorTable *anchorTable = (const AnchorTable *) ((char *) baseArray + anchorTableOffset);
68
LEPoint baseAnchor, markAdvance, pixels;
70
anchorTable->getAnchor(baseGlyph, fontInstance, baseAnchor);
72
fontInstance->getGlyphAdvance(markGlyph, pixels);
73
fontInstance->pixelsToUnits(pixels, markAdvance);
75
float anchorDiffX = baseAnchor.fX - markAnchor.fX;
76
float anchorDiffY = baseAnchor.fY - markAnchor.fY;
78
if (glyphIterator->isRightToLeft()) {
79
float adjustX = markAdvance.fX + anchorDiffX;
81
glyphIterator->adjustCurrGlyphPositionAdjustment(anchorDiffX, -anchorDiffY, -adjustX, anchorDiffY);
85
fontInstance->getGlyphAdvance(baseGlyph, pixels);
86
fontInstance->pixelsToUnits(pixels, baseAdvance);
88
float adjustX = baseAdvance.fX - anchorDiffX;
89
float advAdjustX = adjustX - markAdvance.fX;
91
glyphIterator->adjustCurrGlyphPositionAdjustment(-adjustX, -anchorDiffY, advAdjustX, anchorDiffY);