From e0829eb70f2bfba8ad7e2231058282cb14e818ca Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Fri, 15 Dec 2006 19:28:25 -0700 Subject: [PATCH] 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 5aa9631b899..b291301e2d5 100644 --- a/dlls/usp10/tests/usp10.c +++ b/dlls/usp10/tests/usp10.c @@ -795,11 +795,8 @@ static void test_ScriptStringXtoCP_CPtoX(HDC hdc) 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(HDC hdc) * 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(HDC hdc) 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(HDC hdc) 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(HDC hdc) 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(HDC hdc) 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 14f6fe902d3..448153f4be1 100644 --- a/dlls/usp10/usp10.c +++ b/dlls/usp10/usp10.c @@ -574,9 +574,46 @@ HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa, */ 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; inumItems; i++) + { + for(j=0; jglyphs[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; } /*********************************************************************** -- 2.11.4.GIT