From: handa Date: Wed, 24 Dec 2008 13:20:11 +0000 (+0000) Subject: (get_uvs_glyph): Complete the code. X-Git-Tag: REL-0-9-9~22 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5854b36f0a6b2663dc2c504b30c52148990761ff;p=m17n%2Flibotf.git (get_uvs_glyph): Complete the code. --- 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; }