os/textandloc/fontservices/textshaperplugin/IcuSource/layout/MarkToLigaturePosnSubtables.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
sl@0
     3
 *
sl@0
     4
 */
sl@0
     5
sl@0
     6
#include "LETypes.h"
sl@0
     7
#include "LEFontInstance.h"
sl@0
     8
#include "OpenTypeTables.h"
sl@0
     9
#include "AnchorTables.h"
sl@0
    10
#include "MarkArrays.h"
sl@0
    11
#include "GlyphPositioningTables.h"
sl@0
    12
#include "AttachmentPosnSubtables.h"
sl@0
    13
#include "MarkToLigaturePosnSubtables.h"
sl@0
    14
#include "GlyphIterator.h"
sl@0
    15
#include "LESwaps.h"
sl@0
    16
sl@0
    17
U_NAMESPACE_BEGIN
sl@0
    18
sl@0
    19
LEGlyphID MarkToLigaturePositioningSubtable::findLigatureGlyph(GlyphIterator *glyphIterator) const
sl@0
    20
{
sl@0
    21
    if (glyphIterator->prev()) {
sl@0
    22
        return glyphIterator->getCurrGlyphID();
sl@0
    23
    }
sl@0
    24
sl@0
    25
    return 0xFFFF;
sl@0
    26
}
sl@0
    27
sl@0
    28
le_int32 MarkToLigaturePositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
sl@0
    29
{
sl@0
    30
    LEGlyphID markGlyph = glyphIterator->getCurrGlyphID();
sl@0
    31
    le_int32 markCoverage = getGlyphCoverage((LEGlyphID) markGlyph);
sl@0
    32
sl@0
    33
    if (markCoverage < 0) {
sl@0
    34
        // markGlyph isn't a covered mark glyph
sl@0
    35
        return 0;
sl@0
    36
    }
sl@0
    37
sl@0
    38
    LEPoint markAnchor;
sl@0
    39
    const MarkArray *markArray = (const MarkArray *) ((char *) this + SWAPW(markArrayOffset));
sl@0
    40
    le_int32 markClass = markArray->getMarkClass(markGlyph, markCoverage, fontInstance, markAnchor);
sl@0
    41
    le_uint16 mcCount = SWAPW(classCount);
sl@0
    42
sl@0
    43
    if (markClass < 0 || markClass >= mcCount) {
sl@0
    44
        // markGlyph isn't in the mark array or its
sl@0
    45
        // mark class is too big. The table is mal-formed!
sl@0
    46
        return 0;
sl@0
    47
    }
sl@0
    48
sl@0
    49
    // FIXME: we probably don't want to find a ligature before a previous base glyph...
sl@0
    50
    GlyphIterator ligatureIterator(*glyphIterator, (le_uint16) (lfIgnoreMarks /*| lfIgnoreBaseGlyphs*/));
sl@0
    51
    LEGlyphID ligatureGlyph = findLigatureGlyph(&ligatureIterator);
sl@0
    52
    le_int32 ligatureCoverage = getBaseCoverage((LEGlyphID) ligatureGlyph);
sl@0
    53
    const LigatureArray *ligatureArray = (const LigatureArray *) ((char *) this + SWAPW(baseArrayOffset));
sl@0
    54
    le_uint16 ligatureCount = SWAPW(ligatureArray->ligatureCount);
sl@0
    55
sl@0
    56
    if (ligatureCoverage < 0 || ligatureCoverage >= ligatureCount) {
sl@0
    57
        // The ligature glyph isn't covered, or the coverage
sl@0
    58
        // index is too big. The latter means that the
sl@0
    59
        // table is mal-formed...
sl@0
    60
        return 0;
sl@0
    61
    }
sl@0
    62
sl@0
    63
    le_int32 markPosition = glyphIterator->getCurrStreamPosition();
sl@0
    64
    Offset ligatureAttachOffset = SWAPW(ligatureArray->ligatureAttachTableOffsetArray[ligatureCoverage]);
sl@0
    65
    const LigatureAttachTable *ligatureAttachTable = (const LigatureAttachTable *) ((char *) ligatureArray + ligatureAttachOffset);
sl@0
    66
    le_int32 componentCount = SWAPW(ligatureAttachTable->componentCount);
sl@0
    67
    le_int32 component = ligatureIterator.getMarkComponent(markPosition);
sl@0
    68
sl@0
    69
    if (component >= componentCount) {
sl@0
    70
        // should really just bail at this point...
sl@0
    71
        component = componentCount - 1;
sl@0
    72
    }
sl@0
    73
sl@0
    74
    const ComponentRecord *componentRecord = &ligatureAttachTable->componentRecordArray[component * mcCount];
sl@0
    75
    Offset anchorTableOffset = SWAPW(componentRecord->ligatureAnchorTableOffsetArray[markClass]);
sl@0
    76
    const AnchorTable *anchorTable = (const AnchorTable *) ((char *) ligatureAttachTable + anchorTableOffset);
sl@0
    77
    LEPoint ligatureAnchor, markAdvance, pixels;
sl@0
    78
sl@0
    79
    anchorTable->getAnchor(ligatureGlyph, fontInstance, ligatureAnchor);
sl@0
    80
sl@0
    81
    fontInstance->getGlyphAdvance(markGlyph, pixels);
sl@0
    82
    fontInstance->pixelsToUnits(pixels, markAdvance);
sl@0
    83
sl@0
    84
    float anchorDiffX = ligatureAnchor.fX - markAnchor.fX;
sl@0
    85
    float anchorDiffY = ligatureAnchor.fY - markAnchor.fY;
sl@0
    86
sl@0
    87
    glyphIterator->setCurrGlyphBaseOffset(ligatureIterator.getCurrStreamPosition());
sl@0
    88
sl@0
    89
    if (glyphIterator->isRightToLeft()) {
sl@0
    90
        glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX, anchorDiffY, -markAdvance.fX, -markAdvance.fY);
sl@0
    91
    } else {
sl@0
    92
        LEPoint ligatureAdvance;
sl@0
    93
sl@0
    94
        fontInstance->getGlyphAdvance(ligatureGlyph, pixels);
sl@0
    95
        fontInstance->pixelsToUnits(pixels, ligatureAdvance);
sl@0
    96
sl@0
    97
        glyphIterator->setCurrGlyphPositionAdjustment(anchorDiffX - ligatureAdvance.fX, anchorDiffY - ligatureAdvance.fY, -markAdvance.fX, -markAdvance.fY);
sl@0
    98
    }
sl@0
    99
sl@0
   100
    return 1;
sl@0
   101
}
sl@0
   102
sl@0
   103
U_NAMESPACE_END