~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/layout/MarkToBasePosnSubtables.cpp

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * @(#)MarkToBasePosnSubtables.cpp      1.5 00/03/15
3
 
 *
4
 
 * (C) Copyright IBM Corp. 1998, 1999, 2000, 2001 - All Rights Reserved
5
 
 *
6
 
 */
7
 
 
8
 
#include "LETypes.h"
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"
17
 
#include "LESwaps.h"
18
 
 
19
 
U_NAMESPACE_BEGIN
20
 
 
21
 
LEGlyphID MarkToBasePositioningSubtable::findBaseGlyph(GlyphIterator *glyphIterator) const
22
 
{
23
 
    if (glyphIterator->prev()) {
24
 
        return glyphIterator->getCurrGlyphID();
25
 
    }
26
 
 
27
 
    return 0xFFFF;
28
 
}
29
 
 
30
 
le_int32 MarkToBasePositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
31
 
{
32
 
    LEGlyphID markGlyph = glyphIterator->getCurrGlyphID();
33
 
    le_int32 markCoverage = getGlyphCoverage((LEGlyphID) markGlyph);
34
 
 
35
 
    if (markCoverage < 0) {
36
 
        // markGlyph isn't a covered mark glyph
37
 
        return 0;
38
 
    }
39
 
 
40
 
    LEPoint markAnchor;
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);
44
 
 
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!
48
 
        return 0;
49
 
    }
50
 
 
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);
57
 
 
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...
62
 
        return 0;
63
 
    }
64
 
 
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;
69
 
 
70
 
    anchorTable->getAnchor(baseGlyph, fontInstance, baseAnchor);
71
 
 
72
 
    fontInstance->getGlyphAdvance(markGlyph, pixels);
73
 
    fontInstance->pixelsToUnits(pixels, markAdvance);
74
 
 
75
 
    float anchorDiffX = baseAnchor.fX - markAnchor.fX;
76
 
    float anchorDiffY = baseAnchor.fY - markAnchor.fY;
77
 
 
78
 
    if (glyphIterator->isRightToLeft()) {
79
 
        float adjustX = markAdvance.fX + anchorDiffX;
80
 
 
81
 
        glyphIterator->adjustCurrGlyphPositionAdjustment(anchorDiffX, -anchorDiffY, -adjustX, anchorDiffY);
82
 
    } else {
83
 
        LEPoint baseAdvance;
84
 
 
85
 
        fontInstance->getGlyphAdvance(baseGlyph, pixels);
86
 
        fontInstance->pixelsToUnits(pixels, baseAdvance);
87
 
 
88
 
        float adjustX = baseAdvance.fX - anchorDiffX;
89
 
        float advAdjustX = adjustX - markAdvance.fX;
90
 
 
91
 
        glyphIterator->adjustCurrGlyphPositionAdjustment(-adjustX, -anchorDiffY, advAdjustX, anchorDiffY);
92
 
    }
93
 
 
94
 
    return 1;
95
 
}
96
 
 
97
 
U_NAMESPACE_END