2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
*
|
2013-04-18 21:24:51 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "LEFontInstance.h"
|
|
|
|
#include "OpenTypeTables.h"
|
|
|
|
#include "AnchorTables.h"
|
|
|
|
#include "MarkArrays.h"
|
|
|
|
#include "GlyphPositioningTables.h"
|
2000-12-21 02:44:45 +00:00
|
|
|
#include "AttachmentPosnSubtables.h"
|
|
|
|
#include "MarkToBasePosnSubtables.h"
|
2000-11-28 20:56:52 +00:00
|
|
|
#include "GlyphIterator.h"
|
|
|
|
#include "LESwaps.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
LEGlyphID MarkToBasePositioningSubtable::findBaseGlyph(GlyphIterator *glyphIterator) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
if (glyphIterator->prev()) {
|
|
|
|
return glyphIterator->getCurrGlyphID();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0xFFFF;
|
|
|
|
}
|
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
le_int32 MarkToBasePositioningSubtable::process(const LETableReference &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
LEGlyphID markGlyph = glyphIterator->getCurrGlyphID();
|
2013-04-18 21:24:51 +00:00
|
|
|
le_int32 markCoverage = getGlyphCoverage(base, (LEGlyphID) markGlyph, success);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
if (markCoverage < 0) {
|
|
|
|
// markGlyph isn't a covered mark glyph
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LEPoint markAnchor;
|
2001-01-19 00:30:17 +00:00
|
|
|
const MarkArray *markArray = (const MarkArray *) ((char *) this + SWAPW(markArrayOffset));
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 markClass = markArray->getMarkClass(markGlyph, markCoverage, fontInstance, markAnchor);
|
|
|
|
le_uint16 mcCount = SWAPW(classCount);
|
|
|
|
|
|
|
|
if (markClass < 0 || markClass >= mcCount) {
|
|
|
|
// markGlyph isn't in the mark array or its
|
|
|
|
// mark class is too big. The table is mal-formed!
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: We probably don't want to find a base glyph before a previous ligature...
|
2003-03-11 02:28:18 +00:00
|
|
|
GlyphIterator baseIterator(*glyphIterator, (le_uint16) (lfIgnoreMarks /*| lfIgnoreLigatures*/));
|
2000-11-28 20:56:52 +00:00
|
|
|
LEGlyphID baseGlyph = findBaseGlyph(&baseIterator);
|
2013-04-18 21:24:51 +00:00
|
|
|
le_int32 baseCoverage = getBaseCoverage(base, (LEGlyphID) baseGlyph, success);
|
2001-01-19 00:30:17 +00:00
|
|
|
const BaseArray *baseArray = (const BaseArray *) ((char *) this + SWAPW(baseArrayOffset));
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 baseCount = SWAPW(baseArray->baseRecordCount);
|
|
|
|
|
|
|
|
if (baseCoverage < 0 || baseCoverage >= baseCount) {
|
|
|
|
// The base glyph isn't covered, or the coverage
|
|
|
|
// index is too big. The latter means that the
|
|
|
|
// table is mal-formed...
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
const BaseRecord *baseRecord = &baseArray->baseRecordArray[baseCoverage * mcCount];
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset anchorTableOffset = SWAPW(baseRecord->baseAnchorTableOffsetArray[markClass]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const AnchorTable *anchorTable = (const AnchorTable *) ((char *) baseArray + anchorTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
LEPoint baseAnchor, markAdvance, pixels;
|
|
|
|
|
2004-05-07 23:29:16 +00:00
|
|
|
if (anchorTableOffset == 0) {
|
|
|
|
// this means the table is mal-formed...
|
|
|
|
glyphIterator->setCurrGlyphBaseOffset(baseIterator.getCurrStreamPosition());
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-01 18:25:52 +00:00
|
|
|
|
2000-11-28 20:56:52 +00:00
|
|
|
anchorTable->getAnchor(baseGlyph, fontInstance, baseAnchor);
|
|
|
|
|
|
|
|
fontInstance->getGlyphAdvance(markGlyph, pixels);
|
|
|
|
fontInstance->pixelsToUnits(pixels, markAdvance);
|
|
|
|
|
|
|
|
float anchorDiffX = baseAnchor.fX - markAnchor.fX;
|
|
|
|
float anchorDiffY = baseAnchor.fY - markAnchor.fY;
|
|
|
|
|
2002-06-10 23:40:33 +00:00
|
|
|
glyphIterator->setCurrGlyphBaseOffset(baseIterator.getCurrStreamPosition());
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2002-06-10 23:40:33 +00:00
|
|
|
if (glyphIterator->isRightToLeft()) {
|
2010-01-07 22:32:53 +00:00
|
|
|
// FIXME: need similar patch to below; also in MarkToLigature and MarkToMark
|
|
|
|
// (is there a better way to approach this for all the cases?)
|
2004-08-20 18:12:26 +00:00
|
|
|
glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX, anchorDiffY, -markAdvance.fX, -markAdvance.fY);
|
2000-11-28 20:56:52 +00:00
|
|
|
} else {
|
|
|
|
LEPoint baseAdvance;
|
|
|
|
|
|
|
|
fontInstance->getGlyphAdvance(baseGlyph, pixels);
|
2010-01-07 22:32:53 +00:00
|
|
|
|
|
|
|
//JK: adjustment needs to account for non-zero advance of any marks between base glyph and current mark
|
|
|
|
GlyphIterator gi(baseIterator, (le_uint16)0); // copy of baseIterator that won't ignore marks
|
|
|
|
gi.next(); // point beyond the base glyph
|
|
|
|
while (gi.getCurrStreamPosition() < glyphIterator->getCurrStreamPosition()) { // for all intervening glyphs (marks)...
|
|
|
|
LEGlyphID otherMark = gi.getCurrGlyphID();
|
|
|
|
LEPoint px;
|
|
|
|
fontInstance->getGlyphAdvance(otherMark, px); // get advance, in case it's non-zero
|
|
|
|
pixels.fX += px.fX; // and add that to the base glyph's advance
|
|
|
|
pixels.fY += px.fY;
|
|
|
|
gi.next();
|
|
|
|
}
|
|
|
|
// end of JK patch
|
|
|
|
|
2000-11-28 20:56:52 +00:00
|
|
|
fontInstance->pixelsToUnits(pixels, baseAdvance);
|
|
|
|
|
2004-08-20 18:12:26 +00:00
|
|
|
glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX - baseAdvance.fX, anchorDiffY - baseAdvance.fY, -markAdvance.fX, -markAdvance.fY);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2001-10-16 00:39:01 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|