Clinton Stimpson : usp10: Implement ScriptStringCPtoX.

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


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

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

usp10: Implement ScriptStringCPtoX.

---

 dlls/usp10/tests/usp10.c |   28 ++++++++++++----------------
 dlls/usp10/usp10.c       |   43 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 52 insertions(+), 19 deletions(-)

diff --git a/dlls/usp10/tests/usp10.c b/dlls/usp10/tests/usp10.c
index 5aa9631..b291301 100644
--- a/dlls/usp10/tests/usp10.c
+++ b/dlls/usp10/tests/usp10.c
@@ -795,11 +795,8 @@ static void test_ScriptStringXtoCP_CPtoX
             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
             ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
-            if(Cp == 0)
-              ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
-            else
-              todo_wine ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
-            ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
+            ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
+            ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n", 
                                   iTrailing, X);
             fTrailing = TRUE;
             hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
@@ -812,11 +809,10 @@ static void test_ScriptStringXtoCP_CPtoX
              * one input to ScriptStringCPtoX.  This means that the Cp to X position and back
              * again works
              */
-            todo_wine ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
-            ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
+            ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
+            ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n", 
                                    iTrailing, X);
         }
-
         /*
          * This test is to check that if the X position is just inside the trailing edge of the
          * character then iTrailing will indicate the trailing edge, ie. TRUE
@@ -828,8 +824,8 @@ static void test_ScriptStringXtoCP_CPtoX
         X--;                                /* put X just inside the trailing edge */
         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);
-        ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
+        ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
+        ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n", 
                                   iTrailing, X);
 
         /*
@@ -844,8 +840,8 @@ static void test_ScriptStringXtoCP_CPtoX
         X++;                                /* put X just outside the trailing edge */
         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);
-        ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
+        ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
+        ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n", 
                                   iTrailing, X);
 
         /*
@@ -860,8 +856,8 @@ static void test_ScriptStringXtoCP_CPtoX
         X--;                                /* put X just outside the leading edge */
         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);
-        ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
+        ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, X);
+        ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n", 
                                   iTrailing, X);
 
         /*
@@ -887,13 +883,13 @@ static void test_ScriptStringXtoCP_CPtoX
         fTrailing = FALSE;
         Cp = String_len + 1; 
         hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
-        todo_wine ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
+        ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
 
         hr = ScriptStringFree(&ssa);
         /*
          * ScriptStringCPtoX should free ssa, hence ScriptStringFree should fail
          */
-        todo_wine ok(hr == E_INVALIDARG, "ScriptStringFree should return E_INVALIDARG not %08x\n", hr);
+        ok(hr == E_INVALIDARG, "ScriptStringFree should return E_INVALIDARG not %08x\n", hr);
     }
 }
 
diff --git a/dlls/usp10/usp10.c b/dlls/usp10/usp10.c
index 14f6fe9..448153f 100644
--- a/dlls/usp10/usp10.c
+++ b/dlls/usp10/usp10.c
@@ -574,9 +574,46 @@ HRESULT WINAPI ScriptStringOut(SCRIPT_ST
  */
 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
 {
-    FIXME("(%p), %d, %d, (%p): stub\n", ssa, icp, fTrailing, pX);
-    *pX = 0;                             /* Set a reasonable value */
-    return S_OK;
+    int i, j;
+    int runningX = 0;
+    int runningCp = 0;
+    StringAnalysis* analysis = ssa;
+    TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
+
+    if(!ssa || !pX)
+    {
+        return 1;
+    }
+
+    /* icp out of range */
+    if(icp < 0)
+    {
+        analysis->invalid = TRUE;
+        return E_INVALIDARG;
+    }
+
+    for(i=0; i<analysis->numItems; i++)
+    {
+        for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
+        {
+            if(runningCp == icp && fTrailing == FALSE)
+            {
+                *pX = runningX;
+                return S_OK;
+            }
+            runningX += analysis->glyphs[i].piAdvance[j];
+            if(runningCp == icp && fTrailing == TRUE)
+            {
+                *pX = runningX;
+                return S_OK;
+            }
+            runningCp++;
+        }
+    }
+
+    /* icp out of range */
+    analysis->invalid = TRUE;
+    return E_INVALIDARG;
 }
 
 /***********************************************************************




More information about the wine-cvs mailing list