]> git.imager.perl.org - imager.git/commitdiff
use the font's first character map if we don't find a unicode map (FT1)
authorTony Cook <tony@develop=help.com>
Thu, 10 Jan 2002 12:37:18 +0000 (12:37 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 10 Jan 2002 12:37:18 +0000 (12:37 +0000)
use the glyphs' bounding boxes rather than the global ascent/descent to
get the size of the render bitmap, to work around fonts with broken
metrics

Changes
font.c
t/t35ttfont.t

diff --git a/Changes b/Changes
index ed7dd807059ded5625b7a09f477072b4e00ffa5f..a33a5db6506fa40de72b626af200608305efb3e2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -581,6 +581,11 @@ Revision history for Perl extension Imager.
         - modify the Freetype2 font code to pick it's own encoding
           rather than using whatever strange translation FT2 happens to 
           pick
+        - modify the FT1 font code to use the first encoding as a default
+          if we don't find a unicode encoding
+        - use the glyph bbox to calculate the glyph bitmaps for rendering
+          with FT1 rather than the global ascender/descender.  This helps
+          with fonts that have broken metrics.
 
 =================================================================
 
diff --git a/font.c b/font.c
index c7784246a268ed0b404d0d016374e07b088e75fa..6046241c4ec3573d5a8880e0502fc50d2de3f4c0 100644 (file)
--- a/font.c
+++ b/font.c
@@ -557,10 +557,15 @@ i_tt_new(char *fontname) {
   for ( i = 0; i < n; i++ ) {
     TT_Get_CharMap_ID( handle->face, i, &platform, &encoding );
     if ( (platform == 3 && encoding == 1 ) || (platform == 0 && encoding == 0 ) ) {
+      mm_log((2,"i_tt_new - found char map platform %u encoding %u\n", platform, encoding));
       TT_Get_CharMap( handle->face, i, &(handle->char_map) );
       break;
     }
   }
+  if (!USTRCT(handle->char_map) && n != 0) {
+    /* just use the first one */
+    TT_Get_CharMap( handle->face, 0, &(handle->char_map));
+  }
 
   /* Zero the pointsizes - and ordering */
   
@@ -877,7 +882,7 @@ i_tt_render_all_glyphs( TT_Fonthandle *handle, int inst, TT_Raster_Map *bit, TT_
   */
 
   x=-cords[0]; /* FIXME: If you font is antialiased this should be expanded by one to allow for aa expansion and the allocation too - do before passing here */
-  y=-cords[1];
+  y=-cords[4];
   
   for ( i = 0; i < len; i++ ) {
     j = txt[i];
@@ -1016,7 +1021,7 @@ i_tt_rasterize( TT_Fonthandle *handle, TT_Raster_Map *bit, int cords[6], float p
   i_tt_bbox_inst( handle, inst, txt, len, cords );
   
   width  = cords[2]-cords[0];
-  height = cords[3]-cords[1];
+  height = cords[5]-cords[4];
   
   mm_log((1,"i_tt_rasterize: width=%d, height=%d\n",width, height )); 
   
@@ -1065,7 +1070,7 @@ i_tt_cp( TT_Fonthandle *handle, i_img *im, int xb, int yb, int channel, float po
   
   if (! i_tt_rasterize( handle, &bit, cords, points, txt, len, smooth ) ) return 0;
   
-  ascent=cords[3];
+  ascent=cords[5];
   st_offset=cords[0];
 
   i_tt_dump_raster_map_channel( im, &bit, xb-st_offset , yb-ascent, channel, smooth );
@@ -1100,7 +1105,7 @@ i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float
   
   if (! i_tt_rasterize( handle, &bit, cords, points, txt, len, smooth ) ) return 0;
   
-  ascent=cords[3];
+  ascent=cords[5];
   st_offset=cords[0];
 
   i_tt_dump_raster_map2( im, &bit, xb+st_offset, yb-ascent, cl, smooth ); 
index af0a9e543fdf48da8e5b9c303e85c40310e381e7..39eb7c821850433c5601b078203bade3f5439efc 100644 (file)
@@ -12,7 +12,7 @@ use Imager qw(:all);
 $loaded = 1;
 print "ok 1\n";
 
-init_log("testout/t35ttfont.log",1);
+init_log("testout/t35ttfont.log",2);
 
 sub skip { 
   print "ok 2 # skip\n";
@@ -61,13 +61,14 @@ $backgr=Imager::ImgRaw::new(500,300,3);
 
 #     i_tt_set_aa(2);
 
-i_tt_text($ttraw,$backgr,100,100,$bgcolor,50.0,'test',4,1);
+i_tt_text($ttraw,$backgr,100,120,$bgcolor,50.0,'test',4,1);
 
 my $ugly = Imager::i_tt_new("./fontfiles/ImUgly.ttf");
-i_tt_text($ugly, $backgr,100, 50, $bgcolor, 14, 'g%g', 3, 1);
-i_tt_text($ugly, $backgr,150, 50, $bgcolor, 14, 'delta', 5, 1);
-i_tt_text($ttraw, $backgr, 20, 10, $bgcolor, 14, 'abcdefghijklmnopqrstuvwxyz{|}', 29, 1);
-i_tt_text($ttraw, $backgr, 20, 30, $bgcolor, 14, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 26, 1);
+i_tt_text($ugly, $backgr,100, 80, $bgcolor, 14, 'g%g', 3, 1);
+i_tt_text($ugly, $backgr,150, 80, $bgcolor, 14, 'delta', 5, 1);
+i_draw($backgr,0,20,499,20,i_color_new(0,127,0,0));
+i_tt_text($ttraw, $backgr, 20, 20, $bgcolor, 14, 'abcdefghijklmnopqrstuvwxyz{|}', 29, 1);
+i_tt_text($ttraw, $backgr, 20, 50, $bgcolor, 14, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 26, 1);
 
 
 open(FH,">testout/t35ttfont2.ppm") || die "cannot open testout/t35ttfont.ppm\n";