freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] Re: address@hidden: Bug#149575: freetype1-tools: Bad computation


From: Werner LEMBERG
Subject: [Devel] Re: address@hidden: Bug#149575: freetype1-tools: Bad computation of heights in vpl files with ttf2tfm]
Date: Thu, 20 Jun 2002 19:08:40 +0200 (CEST)

[About ttf2tfm which incorrectly assumes that the x-height of TTFs is
always 400 PostScript units.]

> However, it heavily relies on the font having a correct x-height
> parameter, which, if I am not mistaken, is always equal to 400.

Indeed, this is a bug which hasn't been noticed by any user before.
The patch below (which I'll commit to the CVS soon) adds handling of
the TTF OS/2 table version 2 to FreeType 1 together with a proper fix
for ttf2tfm.  Please test.

> Btw, I found a small bug in the T1 encoding. This appears in the pdf
> file that I join here (first page). The \c command is wrong about
> the bounding box.

Yes.  You should check the LaTeX Bug Database (try
www.latex-project.org as a starting point) whether this has been
reported already; otherwise submit a bug report.

> The best way to attack this is probably to compute x-height from the
> size of 'x'.

Exactly.  This will be used if the sxHeight field of the OS/2 table
is zero.  The value `400' is now the last resort if there isn't an
`x' glyph in the font.

> Another way (for badly designed fonts) is to allow for some move
> down (using (MAP (MOVEDOWN 138.0) (SETCHAR O ...)) for each
> accent). Maybe some new switches should allow that. I, at least,
> would like a switch that doesn't try to be overzealous about
> accents, and a switch to specify x-height.

Mhm, let's first see whether my patch works reasonable.


    Werner

======================================================================

--- ./lib/ttload.c.old  Thu Mar 14 09:08:36 2002
+++ ./lib/ttload.c      Thu Jun 20 16:35:35 2002
@@ -5,7 +5,7 @@
  *
  *    TrueType Tables Loader.
  *
- *  Copyright 1996-2001 by
+ *  Copyright 1996-2001, 2002 by
  *  David Turner, Robert Wilhelm, and Werner Lemberg.
  *
  *  This file is part of the FreeType project, and may only be used
@@ -1290,6 +1290,14 @@
 
     FORGET_Frame();
 
+    os2->ulCodePageRange1 = 0;
+    os2->ulCodePageRange2 = 0;
+    os2->sxHeight         = 0;
+    os2->sCapHeight       = 0;
+    os2->usDefaultChar    = 0;
+    os2->usBreakChar      = 0;
+    os2->usMaxContext     = 0;
+
     if ( os2->version >= 0x0001 )
     {
       /* only version 1 tables */
@@ -1301,11 +1309,22 @@
       os2->ulCodePageRange2 = GET_ULong();
 
       FORGET_Frame();
-    }
-    else
-    {
-      os2->ulCodePageRange1 = 0;
-      os2->ulCodePageRange2 = 0;
+
+      if ( os2->version >= 0x0002 )
+      {
+        /* only version 2 tables */
+
+        if ( ACCESS_Frame( 10L ) )
+          return error;
+
+        os2->sxHeight      = GET_Short();
+        os2->sCapHeight    = GET_Short();
+        os2->usDefaultChar = GET_UShort();
+        os2->usBreakChar   = GET_UShort();
+        os2->usMaxContext  = GET_UShort();
+
+        FORGET_Frame();
+      }
     }
 
     PTRACE2(( "loaded\n" ));
--- ./lib/freetype.h.old        Sat Jan 19 03:24:57 2002
+++ ./lib/freetype.h    Thu Jun 20 16:38:31 2002
@@ -4,7 +4,7 @@
  *
  *    High-level interface specification.
  *
- *  Copyright 1996-2001 by
+ *  Copyright 1996-2001, 2002 by
  *  David Turner, Robert Wilhelm, and Werner Lemberg.
  *
  *  This file is part of the FreeType project and may only be used,
@@ -520,6 +520,14 @@
 
     TT_ULong   ulCodePageRange1;       /* Bits 0-31   */
     TT_ULong   ulCodePageRange2;       /* Bits 32-63  */
+
+    /* only version 2 tables: */
+
+    TT_Short   sxHeight;
+    TT_Short   sCapHeight;
+    TT_UShort  usDefaultChar;
+    TT_UShort  usBreakChar;
+    TT_UShort  usMaxContext;
   };
 
   typedef struct TT_OS2_  TT_OS2;
--- ./freetype1-contrib/ttf2pk/ttfaux.c.old     Thu Mar 14 21:24:48 2002
+++ ./freetype1-contrib/ttf2pk/ttfaux.c Thu Jun 20 16:59:35 2002
@@ -3,7 +3,7 @@
  *
  *   This file is part of the ttf2pk package.
  *
- *   Copyright 1997-1999, 2000 by
+ *   Copyright 1997-1999, 2000, 2002 by
  *     Frederic Loyer <address@hidden>
  *     Werner Lemberg <address@hidden>
  */
@@ -260,6 +260,7 @@
     fnt->units_per_em = properties.header->Units_Per_EM;
     fnt->fixedpitch = properties.postscript->isFixedPitch;
     fnt->italicangle = properties.postscript->italicAngle / 65536.0;
+    fnt->xheight = properties.os2->sxHeight * 1000 / fnt->units_per_em;
 
     if (fnt->PSnames != Only)
     {
--- ./freetype1-contrib/ttf2pk/newobj.c.old     Mon Jan  7 07:55:14 2002
+++ ./freetype1-contrib/ttf2pk/newobj.c Thu Jun 20 16:55:37 2002
@@ -321,7 +321,7 @@
   fnt->pid = 3;
   fnt->eid = 1;
 
-  fnt->xheight = 400;
+  fnt->xheight = 0;
   fnt->fontspace = 0;
 
   fnt->y_offset = 0.25;
--- ./freetype1-contrib/ttf2pk/ttf2tfm.c.old    Mon Jan  7 13:50:56 2002
+++ ./freetype1-contrib/ttf2pk/ttf2tfm.c        Thu Jun 20 19:05:56 2002
@@ -863,6 +863,18 @@
       if (font.replacements)
         warning("Replacement glyphs will be ignored.");
 
+      /* second try to get an xheight value */
+      if (font.xheight == 0)
+      {
+        if (NULL != (ti = findadobe("x", font.charlist)))
+          font.xheight = ti->ury;
+        else if (font.pid == 3 && font.eid == 1 &&
+                 NULL != (ti = findadobe(".c0x78", font.charlist)))
+          font.xheight = ti->ury;
+        else
+          font.xheight = 400;
+      }
+
       if (NULL != (ti = findadobe("space", font.charlist)))
         font.fontspace = ti->width;
       else if (NULL != (ti = findadobe(".c0x20", font.charlist)))
@@ -889,6 +901,18 @@
 
     readttf(&font, quiet, False);
     replace_glyphs(&font);
+
+    /* second try to get an xheight value */
+    if (font.xheight == 0)
+    {
+      if (NULL != (ti = findadobe("x", font.charlist)))
+        font.xheight = ti->ury;
+      else if (font.pid == 3 && font.eid == 1 &&
+               NULL != (ti = findadobe(".c0x78", font.charlist)))
+        font.xheight = ti->ury;
+      else
+        font.xheight = 400;
+    }
 
     if (NULL != (ti = findadobe("space", font.charlist)))
       font.fontspace = ti->width;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]