[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Devel] cmap support for BDF
From: |
Detlef Würkner |
Subject: |
[Devel] cmap support for BDF |
Date: |
Thu, 13 Jun 2002 00:36:40 +0200 |
Hello!
The current BDF driver crashes if FT_CONFIG_OPTON_USE_CMAPS is defined
since it lacks support for that. I just added it by reusing code from
the PCF driver:
----8<----
--- freetype-2.1.1/src/bdf/bdfdrivr.c.ori Mon Jun 3 20:01:23 2002
+++ freetype-2.1.1/src/bdf/bdfdrivr.c Wed Jun 12 21:52:43 2002
@@ -46,6 +46,162 @@
#define FT_COMPONENT trace_bdfdriver
+#ifdef FT_CONFIG_OPTION_USE_CMAPS
+
+ typedef struct BDF_CMapRec_
+ {
+ FT_CMapRec cmap;
+ FT_UInt num_encodings;
+ BDF_encoding_el* encodings;
+
+ } BDF_CMapRec, *BDF_CMap;
+
+
+ FT_CALLBACK_DEF( FT_Error )
+ bdf_cmap_init( BDF_CMap cmap )
+ {
+ BDF_Face face = (BDF_Face)FT_CMAP_FACE( cmap );
+
+
+ cmap->num_encodings = face->bdffont->glyphs_used - 1;
+ cmap->encodings = face->en_table;
+
+ return FT_Err_Ok;
+ }
+
+
+ FT_CALLBACK_DEF( void )
+ bdf_cmap_done( BDF_CMap cmap )
+ {
+ cmap->encodings = NULL;
+ cmap->num_encodings = 0;
+ }
+
+
+ FT_CALLBACK_DEF( FT_UInt )
+ bdf_cmap_char_index( BDF_CMap cmap,
+ FT_UInt32 charcode )
+ {
+ BDF_encoding_el* encodings = cmap->encodings;
+ FT_UInt min, max, mid;
+ FT_UInt result = 0;
+
+
+ min = 0;
+ max = cmap->num_encodings;
+
+ while ( min < max )
+ {
+ FT_UInt32 code;
+
+
+ mid = ( min + max ) >> 1;
+ code = encodings[mid].enc;
+
+ if ( charcode == code )
+ {
+ result = encodings[mid].glyph;
+ break;
+ }
+
+ if ( charcode < code )
+ max = mid;
+ else
+ min = mid + 1;
+ }
+
+ return result;
+ }
+
+
+ FT_CALLBACK_DEF( FT_UInt )
+ bdf_cmap_char_next( BDF_CMap cmap,
+ FT_UInt32 *acharcode )
+ {
+ BDF_encoding_el* encodings = cmap->encodings;
+ FT_UInt min, max, mid;
+ FT_UInt32 charcode = *acharcode + 1;
+ FT_UInt result = 0;
+
+
+ min = 0;
+ max = cmap->num_encodings;
+
+ while ( min < max )
+ {
+ FT_UInt32 code;
+
+
+ mid = ( min + max ) >> 1;
+ code = encodings[mid].enc;
+
+ if ( charcode == code )
+ {
+ result = encodings[mid].glyph;
+ goto Exit;
+ }
+
+ if ( charcode < code )
+ max = mid;
+ else
+ min = mid + 1;
+ }
+
+ charcode = 0;
+ if ( min < cmap->num_encodings )
+ {
+ charcode = encodings[min].enc;
+ result = encodings[min].glyph;
+ }
+
+ Exit:
+ *acharcode = charcode;
+ return result;
+ }
+
+
+ FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec bdf_cmap_class =
+ {
+ sizeof( BDF_CMapRec ),
+ (FT_CMap_InitFunc) bdf_cmap_init,
+ (FT_CMap_DoneFunc) bdf_cmap_done,
+ (FT_CMap_CharIndexFunc)bdf_cmap_char_index,
+ (FT_CMap_CharNextFunc) bdf_cmap_char_next
+ };
+
+#else /* !FT_CONFIG_OPTION_USE_CMAPS */
+
+ static
+ FT_UInt BDF_Get_Char_Index( FT_CharMap charmap,
+ FT_ULong char_code )
+ {
+ BDF_Face face = (BDF_Face)charmap->face;
+ BDF_encoding_el* en_table = face->en_table;
+ int low, high, mid;
+
+
+ FT_TRACE4(( "BDF_Get_Char_Index %ld\n", char_code ));
+
+ low = 0;
+ high = face->bdffont->glyphs_used - 1;
+
+ while ( low <= high )
+ {
+ mid = ( low + high ) / 2;
+ if ( char_code < en_table[mid].enc )
+ high = mid - 1;
+ else if ( char_code > en_table[mid].enc )
+ low = mid + 1;
+ else
+ return en_table[mid].glyph;
+ }
+
+ return face->bdffont->default_glyph;
+ }
+
+#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
+
+
FT_CALLBACK_DEF( FT_Error )
BDF_Face_Done( BDF_Face face )
{
@@ -231,6 +387,7 @@
/* charmaps */
{
bdf_property_t *charset_registry = 0, *charset_encoding = 0;
+ FT_Bool unicode_charmap = 0;
charset_registry =
@@ -252,20 +409,72 @@
goto Exit;
ft_strcpy( face->charset_registry, charset_registry->value.atom );
ft_strcpy( face->charset_encoding, charset_encoding->value.atom );
+ if ( !ft_strcmp( face->charset_registry, "ISO10646" ) ||
+ ( !ft_strcmp( face->charset_registry, "ISO8859" ) &&
+ !ft_strcmp( face->charset_encoding, "1" ) ) )
+ unicode_charmap = 1;
+
+#ifdef FT_CONFIG_OPTION_USE_CMAPS
+
+ {
+ FT_CharMapRec charmap;
+
+
+ charmap.face = FT_FACE( face );
+ charmap.encoding = ft_encoding_none;
+ charmap.platform_id = 0;
+ charmap.encoding_id = 0;
+
+ if ( unicode_charmap )
+ {
+ charmap.encoding = ft_encoding_unicode;
+ charmap.platform_id = 3;
+ charmap.encoding_id = 1;
+ }
+
+ error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL );
+ }
+
+#else /* !FT_CONFIG_OPTION_USE_CMAPS */
face->charmap.encoding = ft_encoding_none;
face->charmap.platform_id = 0;
face->charmap.encoding_id = 0;
+ if ( unicode_charmap )
+ {
+ face->charmap.encoding = ft_encoding_unicode;
+ face->charmap.platform_id = 3;
+ face->charmap.encoding_id = 1;
+ }
face->charmap.face = root;
face->charmap_handle = &face->charmap;
root->charmap = face->charmap_handle;
+#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
+
goto Exit;
}
}
/* otherwise assume adobe standard encoding */
+
+#ifdef FT_CONFIG_OPTION_USE_CMAPS
+
+ {
+ FT_CharMapRec charmap;
+
+
+ charmap.face = FT_FACE( face );
+ charmap.encoding = ft_encoding_none;
+ charmap.platform_id = 0;
+ charmap.encoding_id = 0;
+
+ error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL );
+ }
+
+#else /* !FT_CONFIG_OPTION_USE_CMAPS */
+
face->charmap.encoding = ft_encoding_adobe_standard;
face->charmap.platform_id = 7; /* taken from t1objs.c */
face->charmap.encoding_id = 0;
@@ -273,6 +482,9 @@
face->charmap_handle = &face->charmap;
root->charmap = face->charmap_handle;
+
+#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
+
}
}
@@ -461,35 +673,6 @@
}
- static
- FT_UInt BDF_Get_Char_Index( FT_CharMap charmap,
- FT_ULong char_code )
- {
- BDF_Face face = (BDF_Face)charmap->face;
- BDF_encoding_el* en_table = face->en_table;
- int low, high, mid;
-
-
- FT_TRACE4(( "BDF_Get_Char_Index %ld\n", char_code ));
-
- low = 0;
- high = face->bdffont->glyphs_used - 1;
-
- while ( low <= high )
- {
- mid = ( low + high ) / 2;
- if ( char_code < en_table[mid].enc )
- high = mid - 1;
- else if ( char_code > en_table[mid].enc )
- low = mid + 1;
- else
- return en_table[mid].glyph;
- }
-
- return face->bdffont->default_glyph;
- }
-
-
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec bdf_driver_class =
{
@@ -524,7 +707,7 @@
(FT_Slot_LoadFunc) BDF_Glyph_Load,
-#ifndef FT_CONFIG_OPTION_USE_CMAPS
+#ifdef FT_CONFIG_OPTION_USE_CMAPS
(FT_CharMap_CharIndexFunc)0,
#else
(FT_CharMap_CharIndexFunc)BDF_Get_Char_Index,
@@ -534,10 +717,10 @@
(FT_Face_AttachFunc) 0,
(FT_Face_GetAdvancesFunc) 0,
-#ifndef FT_CONFIG_OPTION_USE_CMAPS
- (FT_CharMap_CharNextFunc) 0, /* BDF_Char_Get_Next,*/
-#else
+#ifdef FT_CONFIG_OPTION_USE_CMAPS
(FT_CharMap_CharNextFunc) 0
+#else
+ (FT_CharMap_CharNextFunc) 0 /* BDF_Get_Next_Char */
#endif
};
----8<----
Ciao, Detlef
--
_ // address@hidden
\X/ Detlef Wuerkner, Langgoens/Germany
- [Devel] cmap support for BDF,
Detlef Würkner <=