2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
*
|
2005-08-18 21:54:52 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2005 - 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 "MarkToMarkPosnSubtables.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 MarkToMarkPositioningSubtable::findMark2Glyph(GlyphIterator *glyphIterator) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2002-06-22 00:34:39 +00:00
|
|
|
if (glyphIterator->findMark2Glyph()) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return glyphIterator->getCurrGlyphID();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0xFFFF;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_int32 MarkToMarkPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
LEGlyphID markGlyph = glyphIterator->getCurrGlyphID();
|
|
|
|
le_int32 markCoverage = getGlyphCoverage((LEGlyphID) markGlyph);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-10-03 16:41:02 +00:00
|
|
|
GlyphIterator mark2Iterator(*glyphIterator);
|
2000-11-28 20:56:52 +00:00
|
|
|
LEGlyphID mark2Glyph = findMark2Glyph(&mark2Iterator);
|
|
|
|
le_int32 mark2Coverage = getBaseCoverage((LEGlyphID) mark2Glyph);
|
2001-01-19 00:30:17 +00:00
|
|
|
const Mark2Array *mark2Array = (const Mark2Array *) ((char *) this + SWAPW(baseArrayOffset));
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 mark2Count = SWAPW(mark2Array->mark2RecordCount);
|
|
|
|
|
|
|
|
if (mark2Coverage < 0 || mark2Coverage >= mark2Count) {
|
|
|
|
// The mark2 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 Mark2Record *mark2Record = &mark2Array->mark2RecordArray[mark2Coverage * mcCount];
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset anchorTableOffset = SWAPW(mark2Record->mark2AnchorTableOffsetArray[markClass]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const AnchorTable *anchorTable = (const AnchorTable *) ((char *) mark2Array + anchorTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
LEPoint mark2Anchor, markAdvance, pixels;
|
|
|
|
|
2005-08-18 21:54:52 +00:00
|
|
|
if (anchorTableOffset == 0) {
|
|
|
|
// this seems to mean that the marks don't attach...
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-11-28 20:56:52 +00:00
|
|
|
anchorTable->getAnchor(mark2Glyph, fontInstance, mark2Anchor);
|
|
|
|
|
|
|
|
fontInstance->getGlyphAdvance(markGlyph, pixels);
|
|
|
|
fontInstance->pixelsToUnits(pixels, markAdvance);
|
|
|
|
|
|
|
|
float anchorDiffX = mark2Anchor.fX - markAnchor.fX;
|
|
|
|
float anchorDiffY = mark2Anchor.fY - markAnchor.fY;
|
|
|
|
|
2002-06-10 23:40:33 +00:00
|
|
|
glyphIterator->setCurrGlyphBaseOffset(mark2Iterator.getCurrStreamPosition());
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2002-06-10 23:40:33 +00:00
|
|
|
if (glyphIterator->isRightToLeft()) {
|
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 mark2Advance;
|
|
|
|
|
|
|
|
fontInstance->getGlyphAdvance(mark2Glyph, pixels);
|
|
|
|
fontInstance->pixelsToUnits(pixels, mark2Advance);
|
|
|
|
|
2004-08-20 18:12:26 +00:00
|
|
|
glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX - mark2Advance.fX, anchorDiffY - mark2Advance.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
|