fonts: avoid a divide by zero

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

 



        Huw Davies <huw@xxxxxxxxxxxxxxx>
        If usWinAscent and usWinDescent are zero then use the Ascender
        and Descender values instead.
        
-- 
Huw Davies
huw@xxxxxxxxxxxxxxx
Index: dlls/gdi/freetype.c
===================================================================
RCS file: /home/wine/wine/dlls/gdi/freetype.c,v
retrieving revision 1.45
diff -u -r1.45 freetype.c
--- dlls/gdi/freetype.c	19 Nov 2003 02:18:13 -0000	1.45
+++ dlls/gdi/freetype.c	8 Dec 2003 12:12:09 -0000
@@ -899,9 +899,12 @@
 static LONG calc_ppem_for_height(FT_Face ft_face, LONG height)
 {
     TT_OS2 *pOS2;
+    TT_HoriHeader *pHori;
+
     LONG ppem;
 
     pOS2 = pFT_Get_Sfnt_Table(ft_face, ft_sfnt_os2);
+    pHori = pFT_Get_Sfnt_Table(ft_face, ft_sfnt_hhea);
 
     if(height == 0) height = 16;
 
@@ -919,9 +922,14 @@
      *
      */
 
-    if(height > 0)
-        ppem = ft_face->units_per_EM * height /
-	    (pOS2->usWinAscent + pOS2->usWinDescent);
+    if(height > 0) {
+        if(pOS2->usWinAscent == 0 && pOS2->usWinDescent == 0)
+            ppem = ft_face->units_per_EM * height /
+                (pHori->Ascender - pHori->Descender);
+        else
+            ppem = ft_face->units_per_EM * height /
+                (pOS2->usWinAscent + pOS2->usWinDescent);
+    }
     else
         ppem = -height;
 
@@ -2109,6 +2117,7 @@
     WCHAR *family_nameW, *style_nameW;
     WCHAR spaceW[] = {' ', '\0'};
     char *cp;
+    INT ascent, descent;
 
     TRACE("font=%p\n", font);
 
@@ -2179,14 +2188,22 @@
 
 #define TM font->potm->otmTextMetrics
 
+    if(pOS2->usWinAscent == 0 && pOS2->usWinDescent == 0) {
+        ascent = pHori->Ascender;
+        descent = -pHori->Descender;
+    } else {
+        ascent = pOS2->usWinAscent;
+        descent = pOS2->usWinDescent;
+    }
+
     if(font->yMax) {
 	TM.tmAscent = font->yMax;
 	TM.tmDescent = -font->yMin;
 	TM.tmInternalLeading = (TM.tmAscent + TM.tmDescent) - ft_face->size->metrics.y_ppem;
     } else {
-	TM.tmAscent = (pFT_MulFix(pOS2->usWinAscent, y_scale) + 32) >> 6;
-	TM.tmDescent = (pFT_MulFix(pOS2->usWinDescent, y_scale) + 32) >> 6;
-	TM.tmInternalLeading = (pFT_MulFix(pOS2->usWinAscent + pOS2->usWinDescent
+	TM.tmAscent = (pFT_MulFix(ascent, y_scale) + 32) >> 6;
+	TM.tmDescent = (pFT_MulFix(descent, y_scale) + 32) >> 6;
+	TM.tmInternalLeading = (pFT_MulFix(ascent + descent
 					    - ft_face->units_per_EM, y_scale) + 32) >> 6;
     }
 
@@ -2196,7 +2213,7 @@
      el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
     */
     TM.tmExternalLeading = max(0, (pFT_MulFix(pHori->Line_Gap -
-       		 ((pOS2->usWinAscent + pOS2->usWinDescent) -
+       		 ((ascent + descent) -
 		  (pHori->Ascender - pHori->Descender)), y_scale) + 32) >> 6);
 
     TM.tmAveCharWidth = (pFT_MulFix(pOS2->xAvgCharWidth, x_scale) + 32) >> 6;


[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux