fonts: fix underlining with bitmap fonts

Huw D M Davies h.davies1 at physics.ox.ac.uk
Mon Nov 15 06:17:37 CST 2004


        Huw Davies <huw at codeweavers.com>
        Fallback to some sensible default values when underlining and
        striking out bitmap fonts.
        Rotate the strikeout line if the escapement is non-zero.
-- 
Huw Davies
huw at codeweavers.com
Index: dlls/x11drv/xrender.c
===================================================================
RCS file: /home/wine/wine/dlls/x11drv/xrender.c,v
retrieving revision 1.49
diff -u -r1.49 xrender.c
--- dlls/x11drv/xrender.c	9 Nov 2004 20:02:57 -0000	1.49
+++ dlls/x11drv/xrender.c	15 Nov 2004 12:03:57 -0000
@@ -1472,42 +1472,58 @@
     LeaveCriticalSection(&xrender_cs);
 
     if (lf.lfUnderline || lf.lfStrikeOut) {
-        int linePos;
-        unsigned int lineWidth;
+        int underlinePos, strikeoutPos;
+        int underlineWidth, strikeoutWidth;
         UINT nMetricsSize = GetOutlineTextMetricsW(hdc, 0, NULL);
-        OUTLINETEXTMETRICW* otm = HeapAlloc(GetProcessHeap(), 0, nMetricsSize);
-        if (!otm) goto done;
+        OUTLINETEXTMETRICW* otm = NULL;
 
-        GetOutlineTextMetricsW(hdc, nMetricsSize, otm);
+        if(!nMetricsSize) {
+            underlinePos = 0;
+            underlineWidth = tm.tmAscent / 20 + 1;
+            strikeoutPos = tm.tmAscent / 2;
+            strikeoutWidth = underlineWidth;
+        } else {
+            otm = HeapAlloc(GetProcessHeap(), 0, nMetricsSize);
+            if (!otm) goto done;
+
+            GetOutlineTextMetricsW(hdc, nMetricsSize, otm);
+            underlinePos = otm->otmsUnderscorePosition;
+            underlineWidth = otm->otmsUnderscoreSize;
+            strikeoutPos = otm->otmsStrikeoutPosition;
+            strikeoutWidth = otm->otmsStrikeoutSize;
+        }
 
         wine_tsx11_lock();
         XSetForeground( gdi_display, physDev->gc, physDev->textPixel );
 
         if (lf.lfUnderline) {
-            linePos = X11DRV_YWStoDS(physDev, otm->otmsUnderscorePosition);
-            lineWidth = X11DRV_YWStoDS(physDev, otm->otmsUnderscoreSize);
+            underlinePos = X11DRV_YWStoDS(physDev, underlinePos);
+            underlineWidth = X11DRV_YWStoDS(physDev, underlineWidth);
 
-            XSetLineAttributes( gdi_display, physDev->gc, lineWidth,
+            XSetLineAttributes( gdi_display, physDev->gc, underlineWidth,
                                 LineSolid, CapProjecting, JoinBevel );
             XDrawLine( gdi_display, physDev->drawable, physDev->gc,
-                       physDev->org.x + x - linePos * sinEsc,
-                       physDev->org.y + y - linePos * cosEsc,
-                       physDev->org.x + x + width * cosEsc - linePos * sinEsc,
-                       physDev->org.y + y - width * sinEsc - linePos * cosEsc );
+                       physDev->org.x + x - underlinePos * sinEsc,
+                       physDev->org.y + y - underlinePos * cosEsc,
+                       physDev->org.x + x + width * cosEsc - underlinePos * sinEsc,
+                       physDev->org.y + y - width * sinEsc - underlinePos * cosEsc );
         }
 
         if (lf.lfStrikeOut) { 
-            linePos = X11DRV_YWStoDS(physDev, otm->otmsStrikeoutPosition);
-            lineWidth = X11DRV_YWStoDS(physDev, otm->otmsStrikeoutSize);
+            strikeoutPos = X11DRV_YWStoDS(physDev, strikeoutPos);
+            strikeoutWidth = X11DRV_YWStoDS(physDev, strikeoutWidth);
             
-            XSetLineAttributes( gdi_display, physDev->gc, lineWidth,
+            XSetLineAttributes( gdi_display, physDev->gc, strikeoutWidth,
                                 LineSolid, CapProjecting, JoinBevel );
             XDrawLine( gdi_display, physDev->drawable, physDev->gc,
-                       physDev->org.x + x, physDev->org.y + y - linePos,
-                       physDev->org.x + x + width, physDev->org.y + y - linePos );
+                       physDev->org.x + x - strikeoutPos * sinEsc,
+                       physDev->org.y + y - strikeoutPos * cosEsc,
+                       physDev->org.x + x + width * cosEsc - strikeoutPos * sinEsc,
+                       physDev->org.y + y - width * sinEsc - strikeoutPos * cosEsc);
         }
         wine_tsx11_unlock();
-        HeapFree(GetProcessHeap(), 0, otm);
+        if(otm)
+            HeapFree(GetProcessHeap(), 0, otm);
     }
 
     if(deltas && deltas != lpDx)



More information about the wine-patches mailing list