--- cffobjs.c.o Fri Mar 08 19:32:12 2002 +++ cffobjs.c Mon May 20 20:10:00 2002 @@ -414,6 +414,130 @@ return ft_encoding_none; } +/*[[ 6/28/01db kludge up a character map */ + FT_UInt CID_Fake_Charmap_func( TT_CMapTable* charmap, + FT_ULong char_code ) + + { /* a 'good' format for the map is quite debatable */ + /* assuming the character set is sorted, could be a bogus assumption */ + + CFF_Font *font; + int lower, middle, upper; + FT_UShort *base; + FT_UShort v; + + /* pick up the face */ + + font = (CFF_Font *) charmap->c.cmap0.glyphIdArray; + + if (charmap->format == 0x7ffe) { /* CFF "encoding" */ + base = font->encoding.codes; + return base[char_code]; + } + if (charmap->format != 0x7fff) + return 0; /* not us */ + + /* binary search */ + + base = font->charset.sids; + upper = font->num_glyphs - 1; + lower = 0; + while ( lower <= upper ) + { + middle = (lower + upper) >> 1; + v = base[middle]; + if ( v < char_code ) + lower = middle + 1; + else if ( v > char_code ) + upper = middle - 1; + else + return middle; + } + return 0; + } + + FT_LOCAL_DEF + FT_Error CFF_CID_Fake_Charmap( FT_Face root, + CFF_Face face, + CFF_Font_Dict* dict ) + + { + /* trying to plug the hole in cffdrivr.c/cff_get_char_index + + disconnection between CFF/CID/CharSet and Charmap + + have to allocate a dummy charmap and put enough info to sort this out + we need a TT_CharMap and TT_CMapTable + the TT_CMapTable has to be marked as 'loaded' + TT_CMapTable->get_index has to point to our magic function + cffdrvr.c/cff_get_char_index calls it + + be careful with the char map cause it's freed elsewhere based on format + + Disconnect between root->charmaps and face->charmaps + + some questionable memory issues; face + + for encoding, drove off the wrong flag - + the codes are allocated even if they're not populated, + now checking for offset instead + */ + + int error = 0; + FT_Memory memory; + TT_CharMapRec* charmap; + TT_CMapTable* cmap; + CFF_Font* cff = (CFF_Font*)face->extra.data; + int format; + + if (dict->cid_registry ) + format = 0x7fff; + else if (cff->encoding.offset) /* based on offset being present */ + format = 0x7ffe; + else + return 0; /* don't bother */ + + memory = root->memory; + if ( ALLOC_ARRAY( root->charmaps, root->num_charmaps, FT_CharMap ) ) + goto Exit; + face->num_charmaps = 1; + + /* reserve space in face table for actual cmap tables */ + if ( ALLOC_ARRAY( face->charmaps, + 1, + TT_CharMapRec ) ) + goto Exit; + + /* space for pointers */ + root->num_charmaps = 1; + if ( ALLOC_ARRAY( root->charmaps, 1, FT_CharMap ) ) + goto Exit; + + charmap = face->charmaps; + root->charmap = (FT_CharMap)charmap; + root->charmaps[0] = (FT_CharMap)charmap; + + charmap->root.face = root; + charmap->root.encoding = ft_encoding_none; + charmap->root.platform_id = 0; + charmap->root.encoding_id = 0; + cmap = &charmap->cmap; + cmap->platformID = 0; + cmap->platformEncodingID = 0; + cmap->format = format; + cmap->length = 0; + /*cmap->version = 0;*//* 5/20/2002 for 2.0.9 - went away*/ + /**/ + cmap->loaded = 1; + cmap->offset = -1; + cmap->c.cmap0.glyphIdArray = (FT_Byte *)face->extra.data; + cmap->get_index = CID_Fake_Charmap_func; + cmap->get_next_char = 0; /* 5/20/2002 for 2.0.9 - is this needed? */ + + Exit: + return error; + } +/*]]*/ /*************************************************************************/ /* */ @@ -678,6 +802,10 @@ root->charmaps[n] = (FT_CharMap)charmap; } } + else /* [[ 6/28/01 db we need to kludge up a charmap */ + { + error = CFF_CID_Fake_Charmap(root, face, dict); + } /* ]] */ } }