From 5854b36f0a6b2663dc2c504b30c52148990761ff Mon Sep 17 00:00:00 2001 From: handa Date: Wed, 24 Dec 2008 13:20:11 +0000 Subject: [PATCH] (get_uvs_glyph): Complete the code. --- src/otfdrive.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/otfdrive.c b/src/otfdrive.c index 115cf9f..90be525 100644 --- a/src/otfdrive.c +++ b/src/otfdrive.c @@ -1339,6 +1339,66 @@ lookup_encoding_12 (OTF_EncodingSubtable12 *sub12, OTF_GlyphString *gstring) static OTF_GlyphID get_uvs_glyph (OTF_cmap *cmap, OTF_EncodingSubtable14 *sub14, int c1, int c2) { + unsigned nRecords = sub14->nRecords; + OTF_VariationSelectorRecord *record; + unsigned i; + + for (i = 0; i < nRecords; i++) + { + record = &sub14->Records[i]; + if (record->varSelector == c2) + { + if (record->defaultUVSOffset) + { + OTF_UnicodeValueRange *uVRs = record->unicodeValueRanges; + unsigned numUVRs = record->numUnicodeValueRanges; + unsigned top = numUVRs, bottom = 0, middle; + + if (uVRs[0].startUnicodeValue <= c1) + { + unsigned additionalCount, startUnicodeValue; + + for (;;) + { + middle = (top + bottom) / 2; + if (c1 < uVRs[middle].startUnicodeValue) + top = middle; + else if (bottom == middle) + break; + else + bottom = middle; + } + startUnicodeValue = uVRs[bottom].startUnicodeValue; + additionalCount = uVRs[bottom].additionalCount; + if (c1 <= startUnicodeValue + additionalCount) + return cmap->unicode_table[c1]; + } + } + if (record->nonDefaultUVSOffset) + { + OTF_UVSMapping *uvsMappings = record->uvsMappings; + unsigned numUVSMs = record->numUVSMappings; + unsigned top = numUVSMs, bottom = 0, middle; + + if (uvsMappings[0].unicodeValue <= c1) + { + for (;;) + { + middle = (top + bottom) / 2; + if (c1 < uvsMappings[middle].unicodeValue) + top = middle; + else if (bottom == middle) + break; + else + bottom = middle; + } + if (uvsMappings[bottom].unicodeValue == c1) + return uvsMappings[bottom].glyphID; + } + } + return 0; + } + } return 0; } -- 1.7.10.4