Jacek Caban : gdi32: Move ExtTextOutW wrappers to text.c.

Alexandre Julliard julliard at winehq.org
Fri Aug 20 16:12:55 CDT 2021


Module: wine
Branch: master
Commit: cd60db086a4c96df797fb81b7e5461f286b99531
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=cd60db086a4c96df797fb81b7e5461f286b99531

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Aug 20 10:41:01 2021 +0200

gdi32: Move ExtTextOutW wrappers to text.c.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdi32/font.c | 111 ----------------------------------------------
 dlls/gdi32/text.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+), 111 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 359ebfbc0bd..6905d21751b 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -5748,66 +5748,6 @@ BOOL CDECL nulldrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT
     return TRUE;
 }
 
-
-/***********************************************************************
- *           ExtTextOutA    (GDI32.@)
- *
- * See ExtTextOutW.
- */
-BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
-                         const RECT *lprect, LPCSTR str, UINT count, const INT *lpDx )
-{
-    INT wlen;
-    UINT codepage;
-    LPWSTR p;
-    BOOL ret;
-    LPINT lpDxW = NULL;
-
-    if (count > INT_MAX) return FALSE;
-
-    if (flags & ETO_GLYPH_INDEX)
-        return ExtTextOutW( hdc, x, y, flags, lprect, (LPCWSTR)str, count, lpDx );
-
-    p = FONT_mbtowc(hdc, str, count, &wlen, &codepage);
-
-    if (lpDx) {
-        unsigned int i = 0, j = 0;
-
-        /* allocate enough for a ETO_PDY */
-        lpDxW = HeapAlloc( GetProcessHeap(), 0, 2*wlen*sizeof(INT));
-        while(i < count) {
-            if(IsDBCSLeadByteEx(codepage, str[i]))
-            {
-                if(flags & ETO_PDY)
-                {
-                    lpDxW[j++] = lpDx[i * 2]     + lpDx[(i + 1) * 2];
-                    lpDxW[j++] = lpDx[i * 2 + 1] + lpDx[(i + 1) * 2 + 1];
-                }
-                else
-                    lpDxW[j++] = lpDx[i] + lpDx[i + 1];
-                i = i + 2;
-            }
-            else
-            {
-                if(flags & ETO_PDY)
-                {
-                    lpDxW[j++] = lpDx[i * 2];
-                    lpDxW[j++] = lpDx[i * 2 + 1];
-                }
-                else
-                    lpDxW[j++] = lpDx[i];
-                i = i + 1;
-            }
-        }
-    }
-
-    ret = ExtTextOutW( hdc, x, y, flags, lprect, p, wlen, lpDxW );
-
-    HeapFree( GetProcessHeap(), 0, p );
-    HeapFree( GetProcessHeap(), 0, lpDxW );
-    return ret;
-}
-
 /***********************************************************************
  *           get_line_width
  *
@@ -6213,57 +6153,6 @@ done:
 }
 
 
-/***********************************************************************
- *           TextOutA    (GDI32.@)
- */
-BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
-{
-    return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
-}
-
-
-/***********************************************************************
- *           TextOutW    (GDI32.@)
- */
-BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
-{
-    return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
-}
-
-
-/***********************************************************************
- *		PolyTextOutA (GDI32.@)
- *
- * See PolyTextOutW.
- */
-BOOL WINAPI PolyTextOutA( HDC hdc, const POLYTEXTA *pptxt, INT cStrings )
-{
-    for (; cStrings>0; cStrings--, pptxt++)
-        if (!ExtTextOutA( hdc, pptxt->x, pptxt->y, pptxt->uiFlags, &pptxt->rcl, pptxt->lpstr, pptxt->n, pptxt->pdx ))
-            return FALSE;
-    return TRUE;
-}
-
-
-
-/***********************************************************************
- *		PolyTextOutW (GDI32.@)
- *
- * Draw several Strings
- *
- * RETURNS
- *  TRUE:  Success.
- *  FALSE: Failure.
- */
-BOOL WINAPI PolyTextOutW( HDC hdc, const POLYTEXTW *pptxt, INT cStrings )
-{
-    for (; cStrings>0; cStrings--, pptxt++)
-        if (!ExtTextOutW( hdc, pptxt->x, pptxt->y, pptxt->uiFlags, &pptxt->rcl, pptxt->lpstr, pptxt->n, pptxt->pdx ))
-            return FALSE;
-    return TRUE;
-}
-
-
 /***********************************************************************
  *          GetAspectRatioFilterEx  (GDI32.@)
  */
diff --git a/dlls/gdi32/text.c b/dlls/gdi32/text.c
index 156cb3986aa..66a51e89817 100644
--- a/dlls/gdi32/text.c
+++ b/dlls/gdi32/text.c
@@ -669,6 +669,36 @@ cleanup:
     return ret;
 }
 
+/***********************************************************************
+ *           text_mbtowc
+ *
+ * Returns a Unicode translation of str using the charset of the
+ * currently selected font in hdc.  If count is -1 then str is assumed
+ * to be '\0' terminated, otherwise it contains the number of bytes to
+ * convert.  If plenW is non-NULL, on return it will point to the
+ * number of WCHARs that have been written.  If ret_cp is non-NULL, on
+ * return it will point to the codepage used in the conversion.  The
+ * caller should free the returned string from the process heap
+ * itself.
+ */
+static WCHAR *text_mbtowc( HDC hdc, const char *str, INT count, INT *plenW, UINT *ret_cp )
+{
+    UINT cp;
+    INT lenW;
+    LPWSTR strW;
+
+    cp = GdiGetCodePage( hdc );
+
+    if (count == -1) count = strlen( str );
+    lenW = MultiByteToWideChar( cp, 0, str, count, NULL, 0 );
+    strW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) );
+    MultiByteToWideChar( cp, 0, str, count, strW, lenW );
+    TRACE( "mapped %s -> %s\n", debugstr_an(str, count), debugstr_wn(strW, lenW) );
+    if (plenW) *plenW = lenW;
+    if (ret_cp) *ret_cp = cp;
+    return strW;
+}
+
 /***********************************************************************
  *           ExtTextOutW    (GDI32.@)
  */
@@ -711,6 +741,104 @@ BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags, const RECT *rect,
     return ret;
 }
 
+/***********************************************************************
+ *           ExtTextOutA    (GDI32.@)
+ */
+BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags, const RECT *rect,
+                         const char *str, UINT count, const INT *dx )
+{
+    INT wlen;
+    UINT codepage;
+    WCHAR *p;
+    BOOL ret;
+    INT *dxW = NULL;
+
+    if (count > INT_MAX) return FALSE;
+
+    if (flags & ETO_GLYPH_INDEX)
+        return ExtTextOutW( hdc, x, y, flags, rect, (const WCHAR *)str, count, dx );
+
+    p = text_mbtowc( hdc, str, count, &wlen, &codepage );
+
+    if (dx)
+    {
+        unsigned int i = 0, j = 0;
+
+        /* allocate enough for a ETO_PDY */
+        dxW = HeapAlloc( GetProcessHeap(), 0, 2 * wlen * sizeof(INT) );
+        while (i < count)
+        {
+            if (IsDBCSLeadByteEx( codepage, str[i] ))
+            {
+                if (flags & ETO_PDY)
+                {
+                    dxW[j++] = dx[i * 2]     + dx[(i + 1) * 2];
+                    dxW[j++] = dx[i * 2 + 1] + dx[(i + 1) * 2 + 1];
+                }
+                else
+                    dxW[j++] = dx[i] + dx[i + 1];
+                i = i + 2;
+            }
+            else
+            {
+                if (flags & ETO_PDY)
+                {
+                    dxW[j++] = dx[i * 2];
+                    dxW[j++] = dx[i * 2 + 1];
+                }
+                else
+                    dxW[j++] = dx[i];
+                i = i + 1;
+            }
+        }
+    }
+
+    ret = ExtTextOutW( hdc, x, y, flags, rect, p, wlen, dxW );
+
+    HeapFree( GetProcessHeap(), 0, p );
+    HeapFree( GetProcessHeap(), 0, dxW );
+    return ret;
+}
+
+/***********************************************************************
+ *           TextOutA    (GDI32.@)
+ */
+BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, const char *str, INT count )
+{
+    return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
+}
+
+/***********************************************************************
+ *           TextOutW    (GDI32.@)
+ */
+BOOL WINAPI TextOutW( HDC hdc, INT x, INT y, const WCHAR *str, INT count )
+{
+    return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
+}
+
+
+/***********************************************************************
+ *           PolyTextOutA    (GDI32.@)
+ */
+BOOL WINAPI PolyTextOutA( HDC hdc, const POLYTEXTA *pt, INT count )
+{
+    for (; count>0; count--, pt++)
+        if (!ExtTextOutA( hdc, pt->x, pt->y, pt->uiFlags, &pt->rcl, pt->lpstr, pt->n, pt->pdx ))
+            return FALSE;
+    return TRUE;
+}
+
+/***********************************************************************
+ *           PolyTextOutW    (GDI32.@)
+ */
+BOOL WINAPI PolyTextOutW( HDC hdc, const POLYTEXTW *pt, INT count )
+{
+    for (; count>0; count--, pt++)
+        if (!ExtTextOutW( hdc, pt->x, pt->y, pt->uiFlags, &pt->rcl, pt->lpstr, pt->n, pt->pdx ))
+            return FALSE;
+    return TRUE;
+}
+
 static int kern_pair( const KERNINGPAIR *kern, int count, WCHAR c1, WCHAR c2 )
 {
     int i;




More information about the wine-cvs mailing list