[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-patches
Subject:    gdi32: Add wrapper for accessing 26.6 fixed point types.
From:       Ralf Habacker <ralf () habacker ! de>
Date:       2013-10-09 6:40:15
Message-ID: 5254FA4F.8050706 () habacker ! de
[Download RAW message or body]

- corrected wrong assumption that type of variable adv is FT_Pos
- doc typo fix

---
 dlls/gdi32/freetype.c |   91
++++++++++++++++++++++++++++++++++---------------
 1 Datei geändert, 63 Zeilen hinzugefügt(+), 28 Zeilen entfernt(-)



["0005-gdi32-Add-wrapper-for-accessing-26.6-fixed-point-typ.patch" (text/x-patch)]

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index bd4c895..2769f49 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -903,6 +903,40 @@ static inline FT_Fixed FT_FixedFromFIXED(FIXED f)
     return (FT_Fixed)((int)f.value << 16 | (unsigned int)f.fract);
 }
 
+/*
+   Return integral part of the 26.6 fixed point value f.
+*/
+static inline int FTPos266ToInt(FT_Pos f)
+{
+    return f >> 6;
+}
+
+/*
+   Return fraction part of the 26.6 fixed point value f.
+*/
+static inline int FTPos266Frac(FT_Pos f)
+{
+    return f & 63;
+}
+
+/*
+   Return the largest integral value that is not
+   greater than the 26.6 fixed point value f.
+*/
+static inline FT_Pos FTPos266Floor(FT_Pos f)
+{
+    return f & -64;
+}
+
+/*
+   Return the smallest integral value that is not
+   less than the 26.6 fixed point value f.
+*/
+static inline FT_Pos FTPos266Ceil(FT_Pos f)
+{
+    return (f+63) & -64;
+}
+
 static BOOL is_hinting_enabled(void)
 {
     static int enabled = -1;
@@ -5850,11 +5884,11 @@ static BOOL freetype_EnumFonts( PHYSDEV dev, LPLOGFONTW plf, \
FONTENUMPROCW proc,  
 static void FTVectorToPOINTFX(FT_Vector *vec, POINTFX *pt)
 {
-    pt->x.value = vec->x >> 6;
-    pt->x.fract = (vec->x & 0x3f) << 10;
+    pt->x.value = FTPos266ToInt(vec->x);
+    pt->x.fract = FTPos266Frac(vec->x) << 10;
     pt->x.fract |= ((pt->x.fract >> 6) | (pt->x.fract >> 12));
-    pt->y.value = vec->y >> 6;
-    pt->y.fract = (vec->y & 0x3f) << 10;
+    pt->y.value = FTPos266ToInt(vec->y);
+    pt->y.fract = FTPos266Frac(vec->y) << 10;
     pt->y.fract |= ((pt->y.fract >> 6) | (pt->y.fract >> 12));
     return;
 }
@@ -6191,8 +6225,9 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
glyph, UINT format,  DWORD width, height, pitch, needed = 0;
     FT_Bitmap ft_bitmap;
     FT_Error err;
-    INT left, right, top = 0, bottom = 0, adv;
-    INT origin_x = 0, origin_y = 0;
+    FT_Pos left, right, top = 0, bottom = 0;
+    int adv;
+    FT_Pos origin_x = 0, origin_y = 0;
     FT_Angle angle = 0;
     FT_Int load_flags = FT_LOAD_DEFAULT | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
     double widthRatio = 1.0;
@@ -6402,7 +6437,7 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
                glyph, UINT format,
             em_scale = MulDiv(incoming_font->ppem, 1 << 16, \
                incoming_font->ft_face->units_per_EM);
             avgAdvance = pFT_MulFix(incoming_font->ntmAvgWidth, em_scale);
             if (avgAdvance &&
-                (metrics.horiAdvance+63) >> 6 == \
pFT_MulFix(incoming_font->ntmAvgWidth*2, em_scale)) +                \
FTPos266ToInt(FTPos266Ceil(metrics.horiAdvance)) == \
pFT_MulFix(incoming_font->ntmAvgWidth*2, em_scale))  TRACE("Fixed-pitch full-width \
character detected\n");  else
                 avgAdvance = 0; /* cancel this feature */
@@ -6410,15 +6445,15 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
glyph, UINT format,  }
 
     if(!needsTransform) {
-        left = (INT)(metrics.horiBearingX) & -64;
-        right = (INT)((metrics.horiBearingX + metrics.width) + 63) & -64;
+        left = FTPos266Floor(metrics.horiBearingX);
+        right = FTPos266Ceil(metrics.horiBearingX + metrics.width);
         if (!avgAdvance)
-            adv = (INT)(metrics.horiAdvance + 63) >> 6;
+            adv = FTPos266ToInt(FTPos266Ceil(metrics.horiAdvance));
         else
             adv = (INT)avgAdvance * 2;
 
-	top = (metrics.horiBearingY + 63) & -64;
-	bottom = (metrics.horiBearingY - metrics.height) & -64;
+        top = FTPos266Ceil(metrics.horiBearingY);
+        bottom = FTPos266Floor(metrics.horiBearingY - metrics.height);
 	lpgm->gmCellIncX = adv;
 	lpgm->gmCellIncY = 0;
         origin_x = left;
@@ -6446,10 +6481,10 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
glyph, UINT format,  }
 	    }
 	}
-	left = left & -64;
-	right = (right + 63) & -64;
-	bottom = bottom & -64;
-	top = (top + 63) & -64;
+        left = FTPos266Floor(left);
+        right = FTPos266Ceil(right);
+        bottom = FTPos266Floor(bottom);
+        top = FTPos266Ceil(top);
 
         if (tategaki)
         {
@@ -6468,7 +6503,7 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
                glyph, UINT format,
                         vec.y = metrics.horiBearingX + yc * metrics.width;
                     }
 
-                    TRACE ("Vec %ld,%ld\n", vec.x>>6, vec.y>>6);
+                    TRACE ("Vec %d,%d\n", FTPos266ToInt(vec.x), \
FTPos266ToInt(vec.y));  pFT_Vector_Transform(&vec, &transMat);
                     if(xc == 0 && yc == 0) {
                         origin_x = vec.x;
@@ -6479,8 +6514,8 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
glyph, UINT format,  }
                 }
             }
-            origin_x = origin_x & -64;
-            origin_y = (origin_y + 63) & -64;
+            origin_x = FTPos266Floor(origin_x);
+            origin_y = FTPos266Ceil(origin_y);
         }
         else
         {
@@ -6488,13 +6523,13 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
glyph, UINT format,  origin_y = top;
         }
 
-	TRACE("transformed box: (%d,%d - %d,%d)\n", left, top, right, bottom);
+        TRACE("transformed box: (%d,%d - %d,%d)\n", FTPos266ToInt(left), \
FTPos266ToInt(top), FTPos266ToInt(right), FTPos266ToInt(bottom));  vec.x = \
metrics.horiAdvance;  vec.y = 0;
 	pFT_Vector_Transform(&vec, &transMat);
-	lpgm->gmCellIncY = -((vec.y+63) >> 6);
+        lpgm->gmCellIncY = -FTPos266ToInt(FTPos266Ceil(vec.y));
 	if (!avgAdvance || vec.y)
-	    lpgm->gmCellIncX = (vec.x+63) >> 6;
+            lpgm->gmCellIncX = FTPos266ToInt(FTPos266Ceil(vec.x));
 	else {
 	    vec.x = incoming_font->ntmAvgWidth;
 	    vec.y = 0;
@@ -6509,7 +6544,7 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
glyph, UINT format,  vec.y = 0;
         pFT_Vector_Transform(&vec, &transMatUnrotated);
         if (!avgAdvance || vec.y)
-            adv = (vec.x+63) >> 6;
+            adv = FTPos266ToInt(FTPos266Ceil(vec.x));
         else {
             vec.x = incoming_font->ntmAvgWidth;
             vec.y = 0;
@@ -6518,13 +6553,13 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT \
glyph, UINT format,  }
     }
 
-    width  = (right - left) >> 6;
-    height = (top - bottom) >> 6;
+    width  = FTPos266ToInt(right - left);
+    height = FTPos266ToInt(top - bottom);
     lpgm->gmBlackBoxX = width;
     lpgm->gmBlackBoxY = height;
-    lpgm->gmptGlyphOrigin.x = origin_x >> 6;
-    lpgm->gmptGlyphOrigin.y = origin_y >> 6;
-    abc->abcA = left >> 6;
+    lpgm->gmptGlyphOrigin.x = FTPos266ToInt(origin_x);
+    lpgm->gmptGlyphOrigin.y = FTPos266ToInt(origin_y);
+    abc->abcA = FTPos266ToInt(left);
     abc->abcB = width;
     abc->abcC = adv - abc->abcA - abc->abcB;
 





[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic