[LPK] Make GetCharacterPlacement caret positions respect bidi. (#842)
authorBaruch Rutman <peterooch@gmail.com>
Fri, 7 Sep 2018 07:45:35 +0000 (10:45 +0300)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 9 Sep 2018 16:03:45 +0000 (18:03 +0200)
- Try to make use of ScriptStringCPtoX when trying to fill the lpCaretPos struct member;
  if USP10 error happens fallback to the unreorder method.
- Remove now incorrect debug print.

dll/win32/lpk/bidi.c
dll/win32/lpk/lpk.c
win32ss/gdi/gdi32/objects/font.c

index a380e1f..1d92cfd 100644 (file)
@@ -460,7 +460,12 @@ BOOL BIDI_Reorder(
 
     if (lpGlyphs)
     {
+#ifdef __REACTOS__
+        /* ReactOS r57677 and r57679 */
+        cMaxGlyphs = 3 * uCount / 2 + 16;
+#else
         cMaxGlyphs = 1.5 * uCount + 16;
+#endif
         run_glyphs = HeapAlloc(GetProcessHeap(),0,sizeof(WORD) * cMaxGlyphs);
         if (!run_glyphs)
         {
index 075778b..b567d74 100644 (file)
@@ -134,9 +134,11 @@ LpkGetCharacterPlacement(
     DWORD dwFlags,
     DWORD dwUnused)
 {
+    DWORD ret = 0;
+    HRESULT hr;
+    SCRIPT_STRING_ANALYSIS ssa;
     LPWORD lpGlyphs = NULL;
     SIZE size;
-    DWORD ret = 0;
     UINT nSet, i;
     INT cGlyphs;
 
@@ -190,16 +192,36 @@ LpkGetCharacterPlacement(
         }
     }
 
-    /* FIXME: Currently not bidi compliant! */
     if (lpResults->lpCaretPos)
     {
         int pos = 0;
 
-        lpResults->lpCaretPos[0] = 0;
-        for (i = 1; i < nSet; i++)
+        hr = ScriptStringAnalyse(hdc, lpString, nSet,
+#ifdef __REACTOS__
+                                 /* ReactOS r57677 and r57679 */
+                                 (3 * nSet / 2 + 16),
+#else
+                                 (1.5 * nSet + 16),
+#endif
+                                 -1, SSA_GLYPHS, -1,
+                                 NULL, NULL, NULL, NULL, NULL, &ssa);
+        if (hr == S_OK)
+        {
+            for (i = 0; i < nSet; i++)
+            {
+                if (ScriptStringCPtoX(ssa, i, FALSE, &pos) == S_OK)
+                    lpResults->lpCaretPos[i] = pos;
+            }
+            ScriptStringFree(&ssa);
+        }
+        else
         {
-            if (GetTextExtentPoint32W(hdc, &(lpString[i - 1]), 1, &size))
-                lpResults->lpCaretPos[i] = (pos += size.cx);
+            lpResults->lpCaretPos[0] = 0;
+            for (i = 1; i < nSet; i++)
+            {
+                if (GetTextExtentPoint32W(hdc, &(lpString[i - 1]), 1, &size))
+                    lpResults->lpCaretPos[i] = (pos += size.cx);
+            }
         }
     }
 
index 871ea50..38758fa 100644 (file)
@@ -450,8 +450,6 @@ GetCharacterPlacementW(
 
     if (dwFlags&(~GCP_REORDER)) DPRINT("flags 0x%08lx ignored\n", dwFlags);
     if (lpResults->lpClass) DPRINT("classes not implemented\n");
-    if (lpResults->lpCaretPos && (dwFlags & GCP_REORDER))
-        DPRINT("Caret positions for complex scripts not implemented\n");
 
     nSet = (UINT)uCount;
     if (nSet > lpResults->nGlyphs)