unsigned FTRemap(FT_Face face, FTMappingPtr tm, unsigned code) { unsigned index; char *name; unsigned glyph_index; if(tm->mapping) { if(tm->named) { name = FontEncName(code, tm->mapping); if(!name) return 0; glyph_index = FT_Get_Name_Index(face, name); return glyph_index; } else { index = FontEncRecode(code, tm->mapping) + tm->base; FT_Set_Charmap(face, tm->cmap); glyph_index = FT_Get_Char_Index(face, index); return glyph_index; } } else { if(code < 0x100) { index = code; FT_Set_Charmap(face, tm->cmap); glyph_index = FT_Get_Char_Index(face, index); return glyph_index; } else return 0; } }
char * font_encoding_name(unsigned code, FontEncPtr encoding, FontMapPtr mapping) { if(encoding != mapping->encoding) { ErrorF("Inconsistent mapping/encoding\n"); return 0; } return FontEncName(code, mapping); }
static int checkEncoding(FT_Face face, char *encoding_name) { FontEncPtr encoding; FontMapPtr mapping; int i, j, c, koi8; char *n; encoding = FontEncFind(encoding_name, NULL); if(!encoding) return 0; /* An encoding is ``small'' if one of the following is true: - it is linear and has no more than 256 codepoints; or - it is a matrix encoding and has no more than one column. For small encodings using Unicode indices, we require perfect coverage except for CODE_IGNORED and KOI-8 IBM-PC compatibility. For large encodings, we require coverage up to bigEncodingFuzz. For encodings using PS names (currently Adobe Standard and Adobe Symbol only), we require perfect coverage. */ if(FT_Has_PS_Glyph_Names(face)) { for(mapping = encoding->mappings; mapping; mapping = mapping->next) { if(mapping->type == FONT_ENCODING_POSTSCRIPT) { if(encoding->row_size > 0) { for(i = encoding->first; i < encoding->size; i++) { for(j = encoding->first_col; j < encoding->row_size; j++) { n = FontEncName((i<<8) | j, mapping); if(n && FT_Get_Name_Index(face, n) == 0) { return 0; } } } return 1; } else { for(i = encoding->first; i < encoding->size; i++) { n = FontEncName(i, mapping); if(n && FT_Get_Name_Index(face, n) == 0) { return 0; } } return 1; } } } } for(mapping = encoding->mappings; mapping; mapping = mapping->next) { if(find_cmap(mapping->type, mapping->pid, mapping->eid, face)) { int total = 0, failed = 0; if(encoding->row_size > 0) { int estimate = (encoding->size - encoding->first) * (encoding->row_size - encoding->first_col); for(i = encoding->first; i < encoding->size; i++) { for(j = encoding->first_col; j < encoding->row_size; j++) { c = FontEncRecode((i<<8) | j, mapping); if(CODE_IGNORED(c)) { continue; } else { if(FT_Get_Char_Index(face, c) == 0) { failed++; } total++; if((encoding->size <= 1 && failed > 0) || ((float)failed >= bigEncodingFuzz * estimate)) { return 0; } } } } if((float)failed >= total * bigEncodingFuzz) return 0; else return 1; } else { int estimate = encoding->size - encoding->first; /* For the KOI8 encodings, we ignore the lack of linedrawing and pseudo-math characters */ if(strncmp(encoding->name, "koi8-", 5) == 0) koi8 = 1; else koi8 = 0; for(i = encoding->first; i < encoding->size; i++) { c = FontEncRecode(i, mapping); if(CODE_IGNORED(c) || (koi8 && ((c >= 0x2200 && c < 0x2600) || c == 0x00b2))) { continue; } else { if(FT_Get_Char_Index(face, c) == 0) { failed++; } total++; if((encoding->size <= 256 && failed > 0) || ((float)failed >= bigEncodingFuzz * estimate)) { return 0; } } } if((float)failed >= total * bigEncodingFuzz) return 0; else return 1; } } } return 0; }