[WIN32SS][FONT] Fix font metrics (#713)
[reactos.git] / win32ss / user / rtl / text.c
index b8cdfc7..9ab726c 100644 (file)
@@ -63,128 +63,6 @@ void _font_assert(const char *msg, const char *file, int line)
 #endif
 }
 
 #endif
 }
 
-/***********************************************************************
- *           TEXT_TabbedTextOut
- *
- * Helper function for TabbedTextOut() and GetTabbedTextExtent().
- * Note: this doesn't work too well for text-alignment modes other
- *       than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
- */
-/* WINE synced 22-May-2006 */
-LONG TEXT_TabbedTextOut( HDC hdc,
-                         INT x,
-                         INT y,
-                         LPCWSTR lpstr,
-                         INT count,
-                         INT cTabStops,
-                         const INT *lpTabPos,
-                         INT nTabOrg,
-                         BOOL fDisplayText )
-{
-    INT defWidth;
-    SIZE extent;
-    int i, j;
-    int start = x;
-    TEXTMETRICW tm;
-
-    if (!lpTabPos)
-        cTabStops=0;
-
-#ifdef _WIN32K_
-    GreGetTextMetricsW( hdc, &tm );
-#else
-    GetTextMetricsW( hdc, &tm );
-#endif
-
-    if (cTabStops == 1)
-    {
-        defWidth = *lpTabPos;
-        cTabStops = 0;
-    }
-    else
-    {
-        defWidth = 8 * tm.tmAveCharWidth;
-    }
-
-    while (count > 0)
-    {
-        RECT r;
-        INT x0;
-        x0 = x;
-        r.left = x0;
-        /* chop the string into substrings of 0 or more <tabs>
-         * possibly followed by 1 or more normal characters */
-        for (i = 0; i < count; i++)
-            if (lpstr[i] != '\t') break;
-        for (j = i; j < count; j++)
-            if (lpstr[j] == '\t') break;
-        /* get the extent of the normal character part */
-#ifdef _WIN32K_
-        GreGetTextExtentW( hdc, (LPWSTR)lpstr + i, j - i , &extent, 0 );
-#else
-        GetTextExtentPointW( hdc, lpstr + i, j - i , &extent );
-#endif
-        /* and if there is a <tab>, calculate its position */
-        if( i) {
-            /* get x coordinate for the drawing of this string */
-            for (; cTabStops > i; lpTabPos++, cTabStops--)
-            {
-                if( nTabOrg + abs( *lpTabPos) > x) {
-                    if( lpTabPos[ i - 1] >= 0) {
-                        /* a left aligned tab */
-                        x = nTabOrg + lpTabPos[ i-1] + extent.cx;
-                        break;
-                    }
-                    else
-                    {
-                        /* if tab pos is negative then text is right-aligned
-                         * to tab stop meaning that the string extends to the
-                         * left, so we must subtract the width of the string */
-                        if (nTabOrg - lpTabPos[ i - 1] - extent.cx > x)
-                        {
-                            x = nTabOrg - lpTabPos[ i - 1];
-                            x0 = x - extent.cx;
-                            break;
-                        }
-                    }
-                }
-            }
-            /* if we have run out of tab stops and we have a valid default tab
-             * stop width then round x up to that width */
-            if ((cTabStops <= i) && (defWidth > 0)) {
-                x0 = nTabOrg + ((x - nTabOrg) / defWidth + i) * defWidth;
-                x = x0 + extent.cx;
-            } else if ((cTabStops <= i) && (defWidth < 0)) {
-                x = nTabOrg + ((x - nTabOrg + extent.cx) / -defWidth + i)
-                    * -defWidth;
-                x0 = x - extent.cx;
-            }
-        } else
-            x += extent.cx;
-
-        if (fDisplayText)
-        {
-            r.top    = y;
-            r.right  = x;
-            r.bottom = y + extent.cy;
-#ifdef _WIN32K_
-            GreExtTextOutW( hdc, x0, y, GreGetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
-                         &r, (LPWSTR)lpstr + i, j - i, NULL, 0 );
-#else
-            ExtTextOutW( hdc, x0, y, GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
-                         &r, lpstr + i, j - i, NULL );
-#endif
-        }
-        count -= j;
-        lpstr += j;
-    }
-
-    if(!extent.cy)
-        extent.cy = tm.tmHeight;
-
-    return MAKELONG(x - start, extent.cy);
-}
-
 /*********************************************************************
  *
  *            DrawText functions
 /*********************************************************************
  *
  *            DrawText functions
@@ -285,11 +163,7 @@ static void TEXT_Ellipsify (HDC hdc, WCHAR *str, unsigned int max_len,
 {
     unsigned int len_ellipsis;
     unsigned int lo, mid, hi;
 {
     unsigned int len_ellipsis;
     unsigned int lo, mid, hi;
-#ifdef _WIN32K_
-    len_ellipsis = wcslen (ELLIPSISW);
-#else
     len_ellipsis = strlenW (ELLIPSISW);
     len_ellipsis = strlenW (ELLIPSISW);
-#endif
     if (len_ellipsis > max_len) len_ellipsis = max_len;
     if (*len_str > max_len - len_ellipsis)
         *len_str = max_len - len_ellipsis;
     if (len_ellipsis > max_len) len_ellipsis = max_len;
     if (*len_str > max_len - len_ellipsis)
         *len_str = max_len - len_ellipsis;
@@ -396,11 +270,7 @@ static void TEXT_PathEllipsify (HDC hdc, WCHAR *str, unsigned int max_len,
     int len_trailing;
     int len_under;
     WCHAR *lastBkSlash, *lastFwdSlash, *lastSlash;
     int len_trailing;
     int len_under;
     WCHAR *lastBkSlash, *lastFwdSlash, *lastSlash;
-#ifdef _WIN32K_
-    len_ellipsis = wcslen (ELLIPSISW);
-#else
     len_ellipsis = strlenW (ELLIPSISW);
     len_ellipsis = strlenW (ELLIPSISW);
-#endif
     if (!max_len) return;
     if (len_ellipsis >= max_len) len_ellipsis = max_len - 1;
     if (*len_str + len_ellipsis >= max_len)
     if (!max_len) return;
     if (len_ellipsis >= max_len) len_ellipsis = max_len - 1;
     if (*len_str + len_ellipsis >= max_len)
@@ -1029,13 +899,13 @@ static void TEXT_DrawUnderscore (HDC hdc, int x, int y, const WCHAR *str, int of
     HPEN hpen;
     HPEN oldPen;
 #ifdef _WIN32K_
     HPEN hpen;
     HPEN oldPen;
 #ifdef _WIN32K_
-    GreGetTextExtentW (hdc, (LPWSTR)str, offset, &size, 0);
+    GreGetTextExtentW (hdc, str, offset, &size, 0);
 #else
     GetTextExtentPointW (hdc, str, offset, &size);
 #endif
     prefix_x = x + size.cx;
 #ifdef _WIN32K_
 #else
     GetTextExtentPointW (hdc, str, offset, &size);
 #endif
     prefix_x = x + size.cx;
 #ifdef _WIN32K_
-    GreGetTextExtentW (hdc, (LPWSTR)str, offset+1, &size, 0);
+    GreGetTextExtentW (hdc, str, offset+1, &size, 0);
 #else
     GetTextExtentPointW (hdc, str, offset+1, &size);
 #endif
 #else
     GetTextExtentPointW (hdc, str, offset+1, &size);
 #endif
@@ -1108,6 +978,9 @@ INT WINAPI DrawTextExWorker( HDC hdc,
     int prefix_offset;
     ellipsis_data ellip;
     BOOL invert_y=FALSE;
     int prefix_offset;
     ellipsis_data ellip;
     BOOL invert_y=FALSE;
+
+    HRGN    hrgn = 0;
+
 #ifdef _WIN32K_
     TRACE("%S, %d, %08x\n", str, count, flags);
 #else
 #ifdef _WIN32K_
     TRACE("%S, %d, %08x\n", str, count, flags);
 #else
@@ -1189,12 +1062,45 @@ INT WINAPI DrawTextExWorker( HDC hdc,
 
     if (flags & DT_EXPANDTABS)
     {
 
     if (flags & DT_EXPANDTABS)
     {
-        int tabstop = ((flags & DT_TABSTOP) && dtp) ? dtp->iTabLength : 8;
+        int tabstop = ((flags & DT_TABSTOP) && dtp && dtp->iTabLength) ? dtp->iTabLength : 8;
        tabwidth = tm.tmAveCharWidth * tabstop;
     }
 
     if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
        tabwidth = tm.tmAveCharWidth * tabstop;
     }
 
     if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
-
+#ifndef _WIN32K_ ///// Fix CORE-2201.
+    if (!(flags & DT_NOCLIP) )
+    {
+       int hasClip;
+       hrgn = CreateRectRgn(0,0,0,0);
+       if (hrgn)
+       {
+          hasClip = GetClipRgn(hdc, hrgn);
+          // If the region to be retrieved is NULL, the return value is 0.
+          if (hasClip != 1)
+          {
+             DeleteObject(hrgn);
+             hrgn = NULL;
+          }
+          IntersectClipRect(hdc, rect->left, rect->top, rect->right, rect->bottom);
+       }
+    }
+#else
+    if (!(flags & DT_NOCLIP) )
+    {
+       int hasClip;
+       hrgn = NtGdiCreateRectRgn(0,0,0,0);
+       if (hrgn)
+       {
+          hasClip = NtGdiGetRandomRgn(hdc, hrgn, CLIPRGN);
+          if (hasClip != 1)
+          {
+             GreDeleteObject(hrgn);
+             hrgn = NULL;
+          }
+          NtGdiIntersectClipRect(hdc, rect->left, rect->top, rect->right, rect->bottom);
+       }
+    }
+#endif /////
     if (flags & DT_MODIFYSTRING)
     {
         size_retstr = (count + 4) * sizeof (WCHAR);
     if (flags & DT_MODIFYSTRING)
     {
         size_retstr = (count + 4) * sizeof (WCHAR);
@@ -1251,8 +1157,10 @@ INT WINAPI DrawTextExWorker( HDC hdc,
                 }
                 else
                 {
                 }
                 else
                 {
-#endif
+                    y = rect->top + (rect->bottom - rect->top + (invert_y ? size.cy : -size.cy)) / 2;
+#else
                     y = rect->top + (rect->bottom - rect->top) / 2 + (invert_y ? (size.cy / 2) : (-size.cy / 2));
                     y = rect->top + (rect->bottom - rect->top) / 2 + (invert_y ? (size.cy / 2) : (-size.cy / 2));
+#endif
 #ifdef __REACTOS__
                 }
             }
 #ifdef __REACTOS__
                 }
             }
@@ -1276,7 +1184,7 @@ INT WINAPI DrawTextExWorker( HDC hdc,
                     len_seg = p - str;
                     if (len_seg != len &&
 #ifdef _WIN32K_
                     len_seg = p - str;
                     if (len_seg != len &&
 #ifdef _WIN32K_
-                        !GreGetTextExtentW(hdc, (LPWSTR)str, len_seg, &size, 0))
+                        !GreGetTextExtentW(hdc, str, len_seg, &size, 0))
 #else
                         !GetTextExtentPointW(hdc, str, len_seg, &size))
 #endif
 #else
                         !GetTextExtentPointW(hdc, str, len_seg, &size))
 #endif
@@ -1295,7 +1203,7 @@ INT WINAPI DrawTextExWorker( HDC hdc,
                 if (!GreExtTextOutW( hdc, xseg, y,
                                     ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
                                     ((flags & DT_RTLREADING) ? ETO_RTLREADING : 0),
                 if (!GreExtTextOutW( hdc, xseg, y,
                                     ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
                                     ((flags & DT_RTLREADING) ? ETO_RTLREADING : 0),
-                                    rect, (LPWSTR)str, len_seg, NULL, 0 ))
+                                    rect, str, len_seg, NULL, 0 ))
 #else
                 if (!ExtTextOutW( hdc, xseg, y,
                                  ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
 #else
                 if (!ExtTextOutW( hdc, xseg, y,
                                  ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
@@ -1348,6 +1256,26 @@ INT WINAPI DrawTextExWorker( HDC hdc,
     }
     while (strPtr && !last_line);
 
     }
     while (strPtr && !last_line);
 
+#ifndef _WIN32K_
+    if (!(flags & DT_NOCLIP) )
+    {
+       SelectClipRgn(hdc, hrgn);
+       if (hrgn)
+       {
+          DeleteObject(hrgn);
+       }
+    }
+#else
+    if (!(flags & DT_NOCLIP) )
+    {
+       NtGdiExtSelectClipRgn(hdc, hrgn, RGN_COPY);
+       if (hrgn)
+       {
+          GreDeleteObject(hrgn);
+       }
+    }
+#endif
+
     if (flags & DT_CALCRECT)
     {
        rect->right = rect->left + max_width;
     if (flags & DT_CALCRECT)
     {
        rect->right = rect->left + max_width;