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

« back to all changes in this revision

Viewing changes to source/test/letest/cmaps.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2005-05-21 22:44:31 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: package-import@ubuntu.com-20050521224431-r7rktfhnu1n4tf1g
Tags: 2.1-2.1
Rename icu-doc to icu21-doc. icu-doc is built by the icu28 package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
 
65
65
CMAPMapper *CMAPMapper::createUnicodeMapper(const CMAPTable *cmap)
66
66
{
67
 
        le_uint16 i;
68
 
        le_uint16 nSubtables = SWAPW(cmap->numberSubtables);
69
 
        const CMAPEncodingSubtable *subtable = NULL;
70
 
        le_uint32 offset1 = 0, offset10 = 0;
71
 
 
72
 
        for (i = 0; i < nSubtables; i += 1) {
73
 
                const CMAPEncodingSubtableHeader *esh = &cmap->encodingSubtableHeaders[i];
74
 
 
75
 
                if (SWAPW(esh->platformID) == 3) {
76
 
                        switch (SWAPW(esh->platformSpecificID)) {
77
 
                        case 1:
78
 
                                offset1 = SWAPL(esh->encodingOffset);
79
 
                                break;
80
 
 
81
 
                        case 10:
82
 
                                offset10 = SWAPL(esh->encodingOffset);
83
 
                                break;
84
 
                        }
85
 
                }
86
 
        }
87
 
 
88
 
 
89
 
        if (offset10 != 0)
90
 
        {
91
 
                subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset10);
92
 
        } else if (offset1 != 0) {
93
 
                subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset1);
94
 
        } else {
95
 
                return NULL;
96
 
        }
97
 
 
98
 
        switch (SWAPW(subtable->format)) {
99
 
        case 4:
100
 
                return new CMAPFormat4Mapper(cmap, (const CMAPFormat4Encoding *) subtable);
101
 
 
102
 
        case 12:
103
 
        {
104
 
                const CMAPFormat12Encoding *encoding = (const CMAPFormat12Encoding *) subtable;
105
 
 
106
 
                return new CMAPGroupMapper(cmap, encoding->groups, SWAPL(encoding->nGroups));
107
 
        }
108
 
 
109
 
        default:
110
 
                break;
111
 
        }
112
 
 
113
 
        return NULL;
 
67
    le_uint16 i;
 
68
    le_uint16 nSubtables = SWAPW(cmap->numberSubtables);
 
69
    const CMAPEncodingSubtable *subtable = NULL;
 
70
    le_uint32 offset1 = 0, offset10 = 0;
 
71
 
 
72
    for (i = 0; i < nSubtables; i += 1) {
 
73
        const CMAPEncodingSubtableHeader *esh = &cmap->encodingSubtableHeaders[i];
 
74
 
 
75
        if (SWAPW(esh->platformID) == 3) {
 
76
            switch (SWAPW(esh->platformSpecificID)) {
 
77
            case 1:
 
78
                offset1 = SWAPL(esh->encodingOffset);
 
79
                break;
 
80
 
 
81
            case 10:
 
82
                offset10 = SWAPL(esh->encodingOffset);
 
83
                break;
 
84
            }
 
85
        }
 
86
    }
 
87
 
 
88
 
 
89
    if (offset10 != 0)
 
90
    {
 
91
        subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset10);
 
92
    } else if (offset1 != 0) {
 
93
        subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset1);
 
94
    } else {
 
95
        return NULL;
 
96
    }
 
97
 
 
98
    switch (SWAPW(subtable->format)) {
 
99
    case 4:
 
100
        return new CMAPFormat4Mapper(cmap, (const CMAPFormat4Encoding *) subtable);
 
101
 
 
102
    case 12:
 
103
    {
 
104
        const CMAPFormat12Encoding *encoding = (const CMAPFormat12Encoding *) subtable;
 
105
 
 
106
        return new CMAPGroupMapper(cmap, encoding->groups, SWAPL(encoding->nGroups));
 
107
    }
 
108
 
 
109
    default:
 
110
        break;
 
111
    }
 
112
 
 
113
    return NULL;
114
114
}
115
115
 
116
116
CMAPFormat4Mapper::CMAPFormat4Mapper(const CMAPTable *cmap, const CMAPFormat4Encoding *header)
117
 
        : CMAPMapper(cmap)
 
117
    : CMAPMapper(cmap)
118
118
{
119
 
        le_uint16 segCount = SWAPW(header->segCountX2) / 2;
 
119
    le_uint16 segCount = SWAPW(header->segCountX2) / 2;
120
120
 
121
 
        fEntrySelector = SWAPW(header->entrySelector);
122
 
        fRangeShift = SWAPW(header->rangeShift) / 2;
123
 
        fEndCodes = &header->endCodes[0];
124
 
        fStartCodes = &header->endCodes[segCount + 1]; // + 1 for reservedPad...
125
 
        fIdDelta = &fStartCodes[segCount];
126
 
        fIdRangeOffset = &fIdDelta[segCount];
 
121
    fEntrySelector = SWAPW(header->entrySelector);
 
122
    fRangeShift = SWAPW(header->rangeShift) / 2;
 
123
    fEndCodes = &header->endCodes[0];
 
124
    fStartCodes = &header->endCodes[segCount + 1]; // + 1 for reservedPad...
 
125
    fIdDelta = &fStartCodes[segCount];
 
126
    fIdRangeOffset = &fIdDelta[segCount];
127
127
}
128
128
 
129
129
LEGlyphID CMAPFormat4Mapper::unicodeToGlyph(LEUnicode32 unicode32) const
130
130
{
131
 
        if (unicode32 >= 0x10000) {
132
 
                return 0;
133
 
        }
134
 
 
135
 
        LEUnicode16 unicode = (LEUnicode16) unicode32;
136
 
        le_uint16 index = 0;
137
 
        le_uint16 probe = 1 << fEntrySelector;
138
 
        LEGlyphID result = 0;
139
 
 
140
 
        if (SWAPW(fStartCodes[fRangeShift]) <= unicode) {
141
 
                index = fRangeShift;
142
 
        }
143
 
 
144
 
        while (probe > (1 << 0)) {
145
 
                probe >>= 1;
146
 
 
147
 
                if (SWAPW(fStartCodes[index + probe]) <= unicode) {
148
 
                        index += probe;
149
 
                }
150
 
        }
151
 
 
152
 
        if (unicode >= SWAPW(fStartCodes[index]) && unicode <= SWAPW(fEndCodes[index])) {
153
 
                if (fIdRangeOffset[index] == 0) {
154
 
                        result = (LEGlyphID) unicode;
155
 
                } else {
156
 
                        le_uint16 offset = unicode - SWAPW(fStartCodes[index]);
157
 
                        le_uint16 rangeOffset = SWAPW(fIdRangeOffset[index]);
158
 
                        le_uint16 *glyphIndexTable = (le_uint16 *) ((char *) &fIdRangeOffset[index] + rangeOffset);
159
 
 
160
 
                        result = SWAPW(glyphIndexTable[offset]);
161
 
                }
162
 
 
163
 
                result += SWAPW(fIdDelta[index]);
164
 
        } else {
165
 
                result = 0;
166
 
        }
167
 
 
168
 
        return result;
 
131
    if (unicode32 >= 0x10000) {
 
132
        return 0;
 
133
    }
 
134
 
 
135
    LEUnicode16 unicode = (LEUnicode16) unicode32;
 
136
    le_uint16 index = 0;
 
137
    le_uint16 probe = 1 << fEntrySelector;
 
138
    LEGlyphID result = 0;
 
139
 
 
140
    if (SWAPW(fStartCodes[fRangeShift]) <= unicode) {
 
141
        index = fRangeShift;
 
142
    }
 
143
 
 
144
    while (probe > (1 << 0)) {
 
145
        probe >>= 1;
 
146
 
 
147
        if (SWAPW(fStartCodes[index + probe]) <= unicode) {
 
148
            index += probe;
 
149
        }
 
150
    }
 
151
 
 
152
    if (unicode >= SWAPW(fStartCodes[index]) && unicode <= SWAPW(fEndCodes[index])) {
 
153
        if (fIdRangeOffset[index] == 0) {
 
154
            result = (LEGlyphID) unicode;
 
155
        } else {
 
156
            le_uint16 offset = unicode - SWAPW(fStartCodes[index]);
 
157
            le_uint16 rangeOffset = SWAPW(fIdRangeOffset[index]);
 
158
            le_uint16 *glyphIndexTable = (le_uint16 *) ((char *) &fIdRangeOffset[index] + rangeOffset);
 
159
 
 
160
            result = SWAPW(glyphIndexTable[offset]);
 
161
        }
 
162
 
 
163
        result += SWAPW(fIdDelta[index]);
 
164
    } else {
 
165
        result = 0;
 
166
    }
 
167
 
 
168
    return result;
169
169
}
170
170
 
171
171
CMAPFormat4Mapper::~CMAPFormat4Mapper()
172
172
{
173
 
        // parent destructor does it all
 
173
    // parent destructor does it all
174
174
}
175
175
 
176
176
CMAPGroupMapper::CMAPGroupMapper(const CMAPTable *cmap, const CMAPGroup *groups, le_uint32 nGroups)
177
 
        : CMAPMapper(cmap), fGroups(groups)
 
177
    : CMAPMapper(cmap), fGroups(groups)
178
178
{
179
179
    le_uint8 bit = highBit(nGroups);
180
180
    fPower = 1 << bit;
207
207
 
208
208
CMAPGroupMapper::~CMAPGroupMapper()
209
209
{
210
 
        // parent destructor does it all
 
210
    // parent destructor does it all
211
211
}
212
212