stop ft1.x support dropping descenders
authorTony Cook <tony@develop=help.com>
Fri, 5 Oct 2001 13:49:21 +0000 (13:49 +0000)
committerTony Cook <tony@develop=help.com>
Fri, 5 Oct 2001 13:49:21 +0000 (13:49 +0000)
Changes
MANIFEST
font.c
fontfiles/ImUgly.ttf [new file with mode: 0644]
t/t35ttfont.t

diff --git a/Changes b/Changes
index a2d926f..28664fa 100644 (file)
--- a/Changes
+++ b/Changes
@@ -517,6 +517,9 @@ Revision history for Perl extension Imager.
         - unsharp mask
         - make i_conv() clamp the bottom end of the samples range too
           (makes it useful for sharpening)
+        - adjust ascender/descender values for FT1.x to avoid losing
+          descenders (specifically the bottom of "g" in ImUgly.ttf or
+          arial.ttf at 14pixels)
 
 =================================================================
 
index 33baea2..f4d7804 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -49,6 +49,7 @@ tags.c
 trans2.c
 iolayer.h
 iolayer.c
+fontfiles/ImUgly.ttf
 fontfiles/dcr10.afm
 fontfiles/dcr10.pfb
 fontfiles/dodge.ttf
diff --git a/font.c b/font.c
index 395d7da..293b5be 100644 (file)
--- a/font.c
+++ b/font.c
@@ -1134,8 +1134,8 @@ i_tt_bbox_inst( TT_Fonthandle *handle, int inst ,const char *txt, int len, int c
   mm_log((1,"i_tt_box_inst(handle 0x%X,inst %d,txt '%.*s', len %d)\n",handle,inst,len,txt,len));
 
   upm     = handle->properties.header->Units_Per_EM;
-  gascent  = ( handle->properties.horizontal->Ascender  * handle->instanceh[inst].imetrics.y_ppem ) / upm;
-  gdescent = ( handle->properties.horizontal->Descender * handle->instanceh[inst].imetrics.y_ppem ) / upm;
+  gascent  = ( handle->properties.horizontal->Ascender  * handle->instanceh[inst].imetrics.y_ppem + upm - 1) / upm;
+  gdescent = ( handle->properties.horizontal->Descender * handle->instanceh[inst].imetrics.y_ppem - upm + 1) / upm;
   
   width   = 0;
   start   = 0;
@@ -1148,15 +1148,15 @@ i_tt_bbox_inst( TT_Fonthandle *handle, int inst ,const char *txt, int len, int c
     if ( i_tt_get_glyph(handle,inst,j) ) {
       TT_Glyph_Metrics *gm = handle->instanceh[inst].gmetrics + j;
       width += gm->advance   / 64;
-      casc   = gm->bbox.yMax / 64;
-      cdesc  = gm->bbox.yMin / 64;
+      casc   = (gm->bbox.yMax+63) / 64;
+      cdesc  = (gm->bbox.yMin-63) / 64;
 
       mm_log((1, "i_tt_box_inst: glyph='%c' casc=%d cdesc=%d\n", j, casc, cdesc));
 
       if (first) {
        start    = gm->bbox.xMin / 64;
-       ascent   = gm->bbox.yMax / 64;
-       descent  = gm->bbox.yMin / 64;
+       ascent   = (gm->bbox.yMax+63) / 64;
+       descent  = (gm->bbox.yMin-63) / 64;
        first = 0;
       }
       if (i == len-1) {
diff --git a/fontfiles/ImUgly.ttf b/fontfiles/ImUgly.ttf
new file mode 100644 (file)
index 0000000..eb07393
Binary files /dev/null and b/fontfiles/ImUgly.ttf differ
index a82bba5..0caeacd 100644 (file)
@@ -63,6 +63,11 @@ $backgr=Imager::ImgRaw::new(500,300,3);
 
 i_tt_text($ttraw,$backgr,100,100,$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', 1, 1);
+i_tt_text($ugly, $backgr,150, 50, $bgcolor, 14, 'delta', 5, 1);
+
+
 open(FH,">testout/t35ttfont2.ppm") || die "cannot open testout/t35ttfont.ppm\n";
 binmode(FH);
 $IO = Imager::io_new_fd( fileno(FH) );