Clinton Stimpson : usp10: Implement ScriptStringXtoCP.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Dec 18 05:34:46 CST 2006


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

Author: Clinton Stimpson <cjstimpson at utwire.net>
Date:   Fri Dec 15 19:28:17 2006 -0700

usp10: Implement ScriptStringXtoCP.

---

 dlls/usp10/tests/usp10.c |    4 +-
 dlls/usp10/usp10.c       |   49 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/dlls/usp10/tests/usp10.c b/dlls/usp10/tests/usp10.c
index b522b88..5aa9631 100644
--- a/dlls/usp10/tests/usp10.c
+++ b/dlls/usp10/tests/usp10.c
@@ -829,7 +829,7 @@ static void test_ScriptStringXtoCP_CPtoX
         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
         ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
         todo_wine ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
-        todo_wine ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
+        ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
                                   iTrailing, X);
 
         /*
@@ -861,7 +861,7 @@ static void test_ScriptStringXtoCP_CPtoX
         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
         ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
         todo_wine ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, X);
-        todo_wine ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
+        ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
                                   iTrailing, X);
 
         /*
diff --git a/dlls/usp10/usp10.c b/dlls/usp10/usp10.c
index feedc5b..14f6fe9 100644
--- a/dlls/usp10/usp10.c
+++ b/dlls/usp10/usp10.c
@@ -585,12 +585,55 @@ HRESULT WINAPI ScriptStringCPtoX(SCRIPT_
  */
 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing) 
 {
-    FIXME("(%p), %d, (%p), (%p): stub\n", ssa, iX, piCh, piTrailing);
-    *piCh = 0;                          /* Set a reasonable value */
-    *piTrailing = 0;
+    StringAnalysis* analysis = ssa;
+    int i;
+    int j;
+    int runningX = 0;
+    int runningCp = 0;
+    int width;
+
+    TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
+
+    if(!ssa || !piCh || !piTrailing)
+    {
+        return 1;
+    }
+
+    /* out of range */
+    if(iX < 0)
+    {
+        *piCh = -1;
+        *piTrailing = TRUE;
+    return S_OK;
+    }
+
+    for(i=0; i<analysis->numItems; i++)
+    {
+        for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
+        {
+            width = analysis->glyphs[i].piAdvance[j];
+            if(iX < (runningX + width))
+            {
+                *piCh = runningCp;
+                if((iX - runningX) > width/2)
+                    *piTrailing = TRUE;
+                else
+                    *piTrailing = FALSE;
+                return S_OK;
+            }
+            runningX += width;
+            runningCp++;
+        }
+    }
+
+    /* out of range */
+    *piCh = analysis->pItem[analysis->numItems].iCharPos;
+    *piTrailing = FALSE;
+
     return S_OK;
 }
 
+
 /***********************************************************************
  *      ScriptStringFree (USP10.@)
  *




More information about the wine-cvs mailing list