summaryrefslogtreecommitdiff
path: root/src/gf/gfdrivr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gf/gfdrivr.c')
-rw-r--r--src/gf/gfdrivr.c120
1 files changed, 112 insertions, 8 deletions
diff --git a/src/gf/gfdrivr.c b/src/gf/gfdrivr.c
index e3ee126fc..5cebaee23 100644
--- a/src/gf/gfdrivr.c
+++ b/src/gf/gfdrivr.c
@@ -21,6 +21,7 @@
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
#include FT_TRUETYPE_IDS_H
+#include FT_INTERNAL_TFM_H
#include FT_SERVICE_GF_H
#include FT_SERVICE_FONT_FORMAT_H
@@ -164,10 +165,22 @@
GF_Glyph go=NULL;
FT_UInt16 i,count;
+ TFM_Service tfm;
+
FT_UNUSED( num_params );
FT_UNUSED( params );
+ face->tfm = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
+ "tfm" );
+ tfm = (TFM_Service)face->tfm;
+ if ( !tfm )
+ {
+ FT_ERROR(( "GF_Face_Init: cannot access `tfm' module\n" ));
+ error = FT_THROW( Missing_Module );
+ goto Exit;
+ }
+
FT_TRACE2(( "GF driver\n" ));
/* load font */
@@ -240,17 +253,21 @@
{
FT_Bitmap_Size* bsize = gfface->available_sizes;
- /* FT_UShort x_res, y_res; */
+ FT_UShort x_res, y_res;
bsize->height = (FT_Short) face->gf_glyph->font_bbx_h ;
bsize->width = (FT_Short) face->gf_glyph->font_bbx_w ;
- bsize->size = (FT_Pos) face->gf_glyph->ds << 6 ;
+ bsize->size = (FT_Pos) FT_MulDiv( FT_ABS( face->gf_glyph->ds ),
+ 64 * 7200,
+ 72270L );
- /* x_res = toint( go->hppp * 72.27 ); */
- /* y_res = toint( go->vppp * 72.27 ); */
+ x_res = toint( go->hppp * 72.27 );
+ y_res = toint( go->vppp * 72.27 );
- bsize->y_ppem = (FT_Pos)(bsize->size/10) << 6 ;
- bsize->x_ppem = (FT_Pos)bsize->y_ppem ;
+ bsize->y_ppem = (FT_Pos) toint((face->gf_glyph->ds * y_res)/ 72.27) << 6 ;
+ bsize->x_ppem = (FT_Pos)FT_MulDiv( bsize->y_ppem,
+ x_res,
+ y_res ); ;
}
/* Charmaps */
@@ -373,7 +390,7 @@
FT_TRACE1(( "GF_Glyph_Load: glyph index %d\n", glyph_index ));
- if ( glyph_index < 0 )
+ if ( (FT_Int)glyph_index < 0 )
glyph_index = 0;
if ((glyph_index < go->code_min) || (go->code_max < glyph_index))
@@ -427,6 +444,93 @@
return error;
}
+ FT_LOCAL_DEF( void )
+ TFM_Done_Metrics( FT_Memory memory,
+ TFM_FontInfo fi )
+ {
+ FT_FREE(fi->width);
+ FT_FREE(fi->height);
+ FT_FREE(fi->depth);
+ FT_FREE( fi );
+ }
+
+ /* parse a TFM metrics file */
+ FT_LOCAL_DEF( FT_Error )
+ TFM_Read_Metrics( FT_Face gf_face,
+ FT_Stream stream )
+ {
+ TFM_Service tfm;
+ FT_Memory memory = stream->memory;
+ TFM_ParserRec parser;
+ TFM_FontInfo fi = NULL;
+ FT_Error error = FT_ERR( Unknown_File_Format );
+ GF_Face face = (GF_Face)gf_face;
+ GF_Glyph gf_glyph= face->gf_glyph;
+
+
+ if ( face->tfm_data )
+ {
+ FT_TRACE1(( "TFM_Read_Metrics:"
+ " Freeing previously attached metrics data.\n" ));
+ TFM_Done_Metrics( memory, (TFM_FontInfo)face->tfm_data );
+
+ face->tfm_data = NULL;
+ }
+
+ if ( FT_NEW( fi ) )
+ goto Exit;
+
+ FT_TRACE4(( "TFM_Read_Metrics: Invoking TFM_Service.\n" ));
+
+ tfm = (TFM_Service)face->tfm;
+
+ /* Initialise TFM Service */
+ error = tfm->init( &parser,
+ memory,
+ stream );
+
+ if ( !error )
+ {
+ FT_TRACE4(( "TFM_Read_Metrics: Initialised tfm metric data.\n" ));
+ parser.FontInfo = fi;
+ parser.user_data = gf_glyph;
+
+ error = tfm->parse_metrics( &parser );
+ if( !error )
+ FT_TRACE4(( "TFM_Read_Metrics: parsing TFM metric information done.\n" ));
+
+ FT_TRACE6(( "TFM_Read_Metrics: TFM Metric Information:\n"
+ " Check Sum : %ld\n"
+ " Design Size: %ld\n"
+ " Begin Char : %d\n"
+ " End Char : %d\n"
+ " font_bbx_w : %d\n"
+ " font_bbx_h : %d\n"
+ " slant : %d\n", parser.FontInfo->cs, parser.FontInfo->design_size, parser.FontInfo->begin_char,
+ parser.FontInfo->end_char, parser.FontInfo->font_bbx_w,
+ parser.FontInfo->font_bbx_h, parser.FontInfo->slant ));
+ tfm->done( &parser );
+ }
+
+ if ( !error )
+ {
+ /* Modify GF_Glyph data according to TFM metric values */
+
+ /*face->gf_glyph->font_bbx_w = fi->font_bbx_w;
+ face->gf_glyph->font_bbx_h = fi->font_bbx_h;
+ */
+
+ face->tfm_data = fi;
+ fi = NULL;
+ }
+
+ Exit:
+ if ( fi )
+ TFM_Done_Metrics( memory, fi );
+
+ return error;
+ }
+
/*
*
* SERVICES LIST
@@ -483,7 +587,7 @@
GF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */
NULL, /* FT_Face_GetKerningFunc get_kerning */
- NULL, /* FT_Face_AttachFunc attach_file */
+ TFM_Read_Metrics, /* FT_Face_AttachFunc attach_file */
NULL, /* FT_Face_GetAdvancesFunc get_advances */
GF_Size_Request, /* FT_Size_RequestFunc request_size */