Jacek Caban : gdi32: Move bidi text reordering to ExtTextOutW.

Alexandre Julliard julliard at winehq.org
Thu Aug 19 16:00:06 CDT 2021


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Aug 19 10:25:33 2021 +0200

gdi32: Move bidi text reordering to ExtTextOutW.

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  | 36 +++++-------------------------------
 dlls/gdi32/gdidc.c | 15 ---------------
 dlls/gdi32/text.c  | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 8be802af450..526b236ac71 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -5855,8 +5855,6 @@ BOOL WINAPI NtGdiExtTextOutW( HDC hdc, INT x, INT y, UINT flags, const RECT *lpr
                               const WCHAR *str, UINT count, const INT *lpDx, DWORD cp )
 {
     BOOL ret = FALSE;
-    LPWSTR reordered_str = (LPWSTR)str;
-    WORD *glyphs = NULL;
     UINT align;
     DWORD layout;
     POINT pt;
@@ -5903,26 +5901,6 @@ BOOL WINAPI NtGdiExtTextOutW( HDC hdc, INT x, INT y, UINT flags, const RECT *lpr
         align ^= TA_RTLREADING;
     }
 
-    if( !(flags & (ETO_GLYPH_INDEX | ETO_IGNORELANGUAGE)) && count > 0 )
-    {
-        INT cGlyphs;
-        reordered_str = HeapAlloc(GetProcessHeap(), 0, count*sizeof(WCHAR));
-
-        BIDI_Reorder( hdc, str, count, GCP_REORDER,
-                      (align & TA_RTLREADING) ? WINE_GCPW_FORCE_RTL : WINE_GCPW_FORCE_LTR,
-                      reordered_str, count, NULL, &glyphs, &cGlyphs);
-
-        flags |= ETO_IGNORELANGUAGE;
-        if (glyphs)
-        {
-            flags |= ETO_GLYPH_INDEX;
-            if (cGlyphs != count)
-                count = cGlyphs;
-        }
-    }
-    else if(flags & ETO_GLYPH_INDEX)
-        glyphs = reordered_str;
-
     TRACE("%p, %d, %d, %08x, %s, %s, %d, %p)\n", hdc, x, y, flags,
           wine_dbgstr_rect(lprect), debugstr_wn(str, count), count, lpDx);
     TRACE("align = %x bkmode = %x mapmode = %x\n", align, dc->attr->background_mode,
@@ -6014,9 +5992,9 @@ BOOL WINAPI NtGdiExtTextOutW( HDC hdc, INT x, INT y, UINT flags, const RECT *lpr
             INT *dx = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*dx) );
 
             if (flags & ETO_GLYPH_INDEX)
-                GetTextExtentExPointI( hdc, glyphs, count, -1, NULL, dx, &sz );
+                GetTextExtentExPointI( hdc, str, count, -1, NULL, dx, &sz );
             else
-                GetTextExtentExPointW( hdc, reordered_str, count, -1, NULL, dx, &sz );
+                GetTextExtentExPointW( hdc, str, count, -1, NULL, dx, &sz );
 
             deltas[0].x = dx[0];
             deltas[0].y = 0;
@@ -6062,9 +6040,9 @@ BOOL WINAPI NtGdiExtTextOutW( HDC hdc, INT x, INT y, UINT flags, const RECT *lpr
         POINT desired[2];
 
         if(flags & ETO_GLYPH_INDEX)
-            GetTextExtentPointI(hdc, glyphs, count, &sz);
+            GetTextExtentPointI(hdc, str, count, &sz);
         else
-            GetTextExtentPointW(hdc, reordered_str, count, &sz);
+            GetTextExtentPointW(hdc, str, count, &sz);
         desired[0].x = desired[0].y = 0;
         desired[1].x = sz.cx;
         desired[1].y = 0;
@@ -6152,14 +6130,10 @@ BOOL WINAPI NtGdiExtTextOutW( HDC hdc, INT x, INT y, UINT flags, const RECT *lpr
     }
 
     ret = physdev->funcs->pExtTextOut( physdev, x, y, (flags & ~ETO_OPAQUE), &rc,
-                                       glyphs ? glyphs : reordered_str, count, (INT*)deltas );
+                                       str, count, (INT*)deltas );
 
 done:
     HeapFree(GetProcessHeap(), 0, deltas);
-    if(glyphs != reordered_str)
-        HeapFree(GetProcessHeap(), 0, glyphs);
-    if(reordered_str != str)
-        HeapFree(GetProcessHeap(), 0, reordered_str);
 
     if (ret && (lf.lfUnderline || lf.lfStrikeOut))
     {
diff --git a/dlls/gdi32/gdidc.c b/dlls/gdi32/gdidc.c
index 87cfe7d99f4..68bffdfbac3 100644
--- a/dlls/gdi32/gdidc.c
+++ b/dlls/gdi32/gdidc.c
@@ -1350,21 +1350,6 @@ BOOL WINAPI GdiGradientFill( HDC hdc, TRIVERTEX *vert_array, ULONG nvert,
     return NtGdiGradientFill( hdc, vert_array, nvert, grad_array, ngrad, mode );
 }
 
-/***********************************************************************
- *           ExtTextOutW    (GDI32.@)
- */
-BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags, const RECT *rect,
-                         const WCHAR *str, UINT count, const INT *dx )
-{
-    DC_ATTR *dc_attr;
-
-    if (is_meta_dc( hdc )) return METADC_ExtTextOut( hdc, x, y, flags, rect, str, count, dx );
-    if (!(dc_attr = get_dc_attr( hdc ))) return FALSE;
-    if (dc_attr->emf && !EMFDC_ExtTextOut( dc_attr, x, y, flags, rect, str, count, dx ))
-        return FALSE;
-    return NtGdiExtTextOutW( hdc, x, y, flags, rect, str, count, dx, 0 );
-}
-
 /***********************************************************************
  *           SetTextJustification    (GDI32.@)
  */
diff --git a/dlls/gdi32/text.c b/dlls/gdi32/text.c
index 7e2d5d6a90e..f6188713ee3 100644
--- a/dlls/gdi32/text.c
+++ b/dlls/gdi32/text.c
@@ -48,6 +48,7 @@
 #include "winnls.h"
 #include "usp10.h"
 #include "wine/debug.h"
+#include "gdi_private.h"
 #include "ntgdi_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(bidi);
@@ -654,3 +655,45 @@ cleanup:
     ScriptFreeCache(&psc);
     return ret;
 }
+
+/***********************************************************************
+ *           ExtTextOutW    (GDI32.@)
+ */
+BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags, const RECT *rect,
+                         const WCHAR *str, UINT count, const INT *dx )
+{
+    WORD *glyphs = NULL;
+    DC_ATTR *dc_attr;
+    BOOL ret;
+
+    if (count > INT_MAX) return FALSE;
+    if (is_meta_dc( hdc )) return METADC_ExtTextOut( hdc, x, y, flags, rect, str, count, dx );
+    if (!(dc_attr = get_dc_attr( hdc ))) return FALSE;
+    if (dc_attr->emf && !EMFDC_ExtTextOut( dc_attr, x, y, flags, rect, str, count, dx ))
+        return FALSE;
+
+    if (!(flags & (ETO_GLYPH_INDEX | ETO_IGNORELANGUAGE)) && count > 0)
+    {
+        UINT bidi_flags;
+        int glyphs_count;
+
+        bidi_flags = (dc_attr->text_align & TA_RTLREADING) || (flags & ETO_RTLREADING)
+            ? WINE_GCPW_FORCE_RTL : WINE_GCPW_FORCE_LTR;
+
+        BIDI_Reorder( hdc, str, count, GCP_REORDER, bidi_flags, NULL, 0, NULL,
+                      &glyphs, &glyphs_count );
+
+        flags |= ETO_IGNORELANGUAGE;
+        if (glyphs)
+        {
+            flags |= ETO_GLYPH_INDEX;
+            count = glyphs_count;
+            str = glyphs;
+        }
+    }
+
+    ret = NtGdiExtTextOutW( hdc, x, y, flags, rect, str, count, dx, 0 );
+
+    HeapFree( GetProcessHeap(), 0, glyphs );
+    return ret;
+}




More information about the wine-cvs mailing list