65
65
CMAPMapper *CMAPMapper::createUnicodeMapper(const CMAPTable *cmap)
68
le_uint16 nSubtables = SWAPW(cmap->numberSubtables);
69
const CMAPEncodingSubtable *subtable = NULL;
70
le_uint32 offset1 = 0, offset10 = 0;
72
for (i = 0; i < nSubtables; i += 1) {
73
const CMAPEncodingSubtableHeader *esh = &cmap->encodingSubtableHeaders[i];
75
if (SWAPW(esh->platformID) == 3) {
76
switch (SWAPW(esh->platformSpecificID)) {
78
offset1 = SWAPL(esh->encodingOffset);
82
offset10 = SWAPL(esh->encodingOffset);
91
subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset10);
92
} else if (offset1 != 0) {
93
subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset1);
98
switch (SWAPW(subtable->format)) {
100
return new CMAPFormat4Mapper(cmap, (const CMAPFormat4Encoding *) subtable);
104
const CMAPFormat12Encoding *encoding = (const CMAPFormat12Encoding *) subtable;
106
return new CMAPGroupMapper(cmap, encoding->groups, SWAPL(encoding->nGroups));
68
le_uint16 nSubtables = SWAPW(cmap->numberSubtables);
69
const CMAPEncodingSubtable *subtable = NULL;
70
le_uint32 offset1 = 0, offset10 = 0;
72
for (i = 0; i < nSubtables; i += 1) {
73
const CMAPEncodingSubtableHeader *esh = &cmap->encodingSubtableHeaders[i];
75
if (SWAPW(esh->platformID) == 3) {
76
switch (SWAPW(esh->platformSpecificID)) {
78
offset1 = SWAPL(esh->encodingOffset);
82
offset10 = SWAPL(esh->encodingOffset);
91
subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset10);
92
} else if (offset1 != 0) {
93
subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset1);
98
switch (SWAPW(subtable->format)) {
100
return new CMAPFormat4Mapper(cmap, (const CMAPFormat4Encoding *) subtable);
104
const CMAPFormat12Encoding *encoding = (const CMAPFormat12Encoding *) subtable;
106
return new CMAPGroupMapper(cmap, encoding->groups, SWAPL(encoding->nGroups));
116
116
CMAPFormat4Mapper::CMAPFormat4Mapper(const CMAPTable *cmap, const CMAPFormat4Encoding *header)
119
le_uint16 segCount = SWAPW(header->segCountX2) / 2;
119
le_uint16 segCount = SWAPW(header->segCountX2) / 2;
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];
129
129
LEGlyphID CMAPFormat4Mapper::unicodeToGlyph(LEUnicode32 unicode32) const
131
if (unicode32 >= 0x10000) {
135
LEUnicode16 unicode = (LEUnicode16) unicode32;
137
le_uint16 probe = 1 << fEntrySelector;
138
LEGlyphID result = 0;
140
if (SWAPW(fStartCodes[fRangeShift]) <= unicode) {
144
while (probe > (1 << 0)) {
147
if (SWAPW(fStartCodes[index + probe]) <= unicode) {
152
if (unicode >= SWAPW(fStartCodes[index]) && unicode <= SWAPW(fEndCodes[index])) {
153
if (fIdRangeOffset[index] == 0) {
154
result = (LEGlyphID) unicode;
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);
160
result = SWAPW(glyphIndexTable[offset]);
163
result += SWAPW(fIdDelta[index]);
131
if (unicode32 >= 0x10000) {
135
LEUnicode16 unicode = (LEUnicode16) unicode32;
137
le_uint16 probe = 1 << fEntrySelector;
138
LEGlyphID result = 0;
140
if (SWAPW(fStartCodes[fRangeShift]) <= unicode) {
144
while (probe > (1 << 0)) {
147
if (SWAPW(fStartCodes[index + probe]) <= unicode) {
152
if (unicode >= SWAPW(fStartCodes[index]) && unicode <= SWAPW(fEndCodes[index])) {
153
if (fIdRangeOffset[index] == 0) {
154
result = (LEGlyphID) unicode;
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);
160
result = SWAPW(glyphIndexTable[offset]);
163
result += SWAPW(fIdDelta[index]);
171
171
CMAPFormat4Mapper::~CMAPFormat4Mapper()
173
// parent destructor does it all
173
// parent destructor does it all
176
176
CMAPGroupMapper::CMAPGroupMapper(const CMAPTable *cmap, const CMAPGroup *groups, le_uint32 nGroups)
177
: CMAPMapper(cmap), fGroups(groups)
177
: CMAPMapper(cmap), fGroups(groups)
179
179
le_uint8 bit = highBit(nGroups);
180
180
fPower = 1 << bit;