@@ -169,29 +169,36 @@ void FontEngine::buildGidToCharCodeMap (RangeMap &charmap) const {
169169 // In case the Unicode map of the font doesn't cover all characters, some
170170 // of them could still be identified by their names if present in the font.
171171 if (FT_HAS_GLYPH_NAMES (_currentFace)) {
172+ NumericRanges<uint32_t > usedCodepoints;
173+ for (size_t i=0 ; i < charmap.numRanges (); i++)
174+ usedCodepoints.addRange (charmap.getRange (i).minval (), charmap.getRange (i).maxval ());
172175 if (charmap.empty ())
173- addCharsByGlyphNames (1 , getNumGlyphs (), charmap);
176+ addCharsByGlyphNames (1 , getNumGlyphs (), charmap, usedCodepoints );
174177 else {
175- addCharsByGlyphNames (1 , charmap.minKey ()-1 , charmap);
178+ addCharsByGlyphNames (1 , charmap.minKey ()-1 , charmap, usedCodepoints );
176179 for (size_t i=1 ; i < charmap.numRanges (); i++)
177- addCharsByGlyphNames (charmap.getRange (i-1 ).max ()+1 , charmap.getRange (i).min ()-1 , charmap);
178- addCharsByGlyphNames (charmap.maxKey ()+1 , getNumGlyphs (), charmap);
180+ addCharsByGlyphNames (charmap.getRange (i-1 ).max ()+1 , charmap.getRange (i).min ()-1 , charmap, usedCodepoints );
181+ addCharsByGlyphNames (charmap.maxKey ()+1 , getNumGlyphs (), charmap, usedCodepoints );
179182 }
180183 }
181184}
182185
183186
184187/* * Looks for known glyph names in a given GID range and adds the corresponding
185- * GID->code point mapping to a character map.
188+ * GID->code point mapping to a character map if the code point is not already present .
186189 * @param[in] minGID minimum GID of range to iterate
187190 * @param[in] maxGID maximum GID of range to iterate
188- * @param[in,out] charmap character map taking the new mappings */
189- void FontEngine::addCharsByGlyphNames (uint32_t minGID, uint32_t maxGID, RangeMap &charmap) const {
191+ * @param[in,out] charmap character map taking the new mappings
192+ * @param[in,out] ucp collection of code points already present in the character map */
193+ void FontEngine::addCharsByGlyphNames (uint32_t minGID, uint32_t maxGID, RangeMap &charmap, CodepointRanges &ucp) const {
190194 for (uint32_t gid=minGID; gid <= maxGID; gid++) {
191195 char glyphName[64 ];
192196 if (FT_Get_Glyph_Name (_currentFace, gid, glyphName, 64 ) == 0 ) {
193- if (int32_t cp = Unicode::aglNameToCodepoint (glyphName))
197+ const int32_t cp = Unicode::aglNameToCodepoint (glyphName);
198+ if (cp && !ucp.valueExists (cp)) {
194199 charmap.addRange (gid, gid, cp);
200+ ucp.addRange (cp);
201+ }
195202 }
196203 }
197204}
0 commit comments