usp10: Corrections to ScriptCPtoX.

This commit is contained in:
Aric Stewart 2011-03-08 14:33:29 -06:00 committed by Alexandre Julliard
parent 2ecbfbe5df
commit 73f743f6d2
2 changed files with 153 additions and 44 deletions

View File

@ -1074,7 +1074,8 @@ static void test_ScriptXtoX(void)
int iX, iCP; int iX, iCP;
int cChars; int cChars;
int cGlyphs; int cGlyphs;
WORD pwLogClust[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; WORD pwLogClustXtoCP[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
WORD pwLogClustCPtoX[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
SCRIPT_VISATTR psva[10]; SCRIPT_VISATTR psva[10];
int piAdvance[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203}; int piAdvance[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
int piCP, piX; int piCP, piX;
@ -1088,7 +1089,7 @@ static void test_ScriptXtoX(void)
iX = -1; iX = -1;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing); hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClustXtoCP, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
if (piTrailing) if (piTrailing)
ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP); ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
@ -1098,7 +1099,7 @@ static void test_ScriptXtoX(void)
iX = 1954; iX = 1954;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing); hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClustXtoCP, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
if (piTrailing) /* win2k3 */ if (piTrailing) /* win2k3 */
ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP); ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
@ -1108,7 +1109,7 @@ static void test_ScriptXtoX(void)
iX = 779; iX = 779;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing); hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClustXtoCP, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
ok(piCP == 3 || ok(piCP == 3 ||
piCP == -1, /* win2k3 */ piCP == -1, /* win2k3 */
@ -1118,7 +1119,7 @@ static void test_ScriptXtoX(void)
iX = 780; iX = 780;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing); hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClustXtoCP, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
ok(piCP == 3 || ok(piCP == 3 ||
piCP == -1, /* win2k3 */ piCP == -1, /* win2k3 */
@ -1128,7 +1129,7 @@ static void test_ScriptXtoX(void)
iX = 868; iX = 868;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing); hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClustXtoCP, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
ok(piCP == 4 || ok(piCP == 4 ||
piCP == -1, /* win2k3 */ piCP == -1, /* win2k3 */
@ -1137,7 +1138,7 @@ static void test_ScriptXtoX(void)
iX = 0; iX = 0;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing); hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClustXtoCP, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
ok(piCP == 0 || ok(piCP == 0 ||
piCP == 10, /* win2k3 */ piCP == 10, /* win2k3 */
@ -1146,68 +1147,135 @@ static void test_ScriptXtoX(void)
iX = 195; iX = 195;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing); hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClustXtoCP, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
ok(piCP == 0, "iX=%d should return piCP=0 not %d\n", iX, piCP); ok(piCP == 0, "iX=%d should return piCP=0 not %d\n", iX, piCP);
iX = 196; iX = 196;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing); hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClustXtoCP, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
ok(piCP == 1 || ok(piCP == 1 ||
piCP == 0, /* win2k3 */ piCP == 0, /* win2k3 */
"iX=%d should return piCP=1 or piCP=0 not %d\n", iX, piCP); "iX=%d should return piCP=1 or piCP=0 not %d\n", iX, piCP);
iCP=0;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 0,
"iCP=%d should return piX=0 not %d\n", iCP, piX);
iCP=1;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 66,
"iCP=%d should return piX=66 not %d\n", iCP, piX);
iCP=2;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 133,
"iCP=%d should return piX=133 not %d\n", iCP, piX);
iCP=3;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 200,
"iCP=%d should return piX=200 not %d\n", iCP, piX);
iCP=4;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 295,
"iCP=%d should return piX=295 not %d\n", iCP, piX);
iCP=5; iCP=5;
fTrailing = FALSE; fTrailing = FALSE;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX); hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 976 || ok(piX == 390,
piX == 100, /* win2k3 */ "iCP=%d should return piX=390 not %d\n", iCP, piX);
"iCP=%d should return piX=976 or piX=100 not %d\n", iCP, piX);
iCP=5;
fTrailing = TRUE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 1171 ||
piX == 80, /* win2k3 */
"iCP=%d should return piX=1171 or piX=80 not %d\n", iCP, piX);
iCP=6; iCP=6;
fTrailing = FALSE; fTrailing = FALSE;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX); hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 1171 || ok(piX == 495,
piX == 80, /* win2k3 */ "iCP=%d should return piX=495 not %d\n", iCP, piX);
"iCP=%d should return piX=1171 or piX=80 not %d\n", iCP, piX);
iCP=7;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 600,
"iCP=%d should return piX=600 not %d\n", iCP, piX);
iCP=8;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 1051,
"iCP=%d should return piX=1051 not %d\n", iCP, piX);
iCP=9;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 1502,
"iCP=%d should return piX=1502 not %d\n", iCP, piX);
iCP=10;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 1953,
"iCP=%d should return piX=1953 not %d\n", iCP, piX);
iCP=11; iCP=11;
fTrailing = FALSE; fTrailing = FALSE;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX); hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 1953 || ok(piX == 1953,
piX == 0, /* win2k3 */ "iCP=%d should return piX=1953 %d\n", iCP, piX);
"iCP=%d should return piX=1953 or piX=0 not %d\n", iCP, piX);
iCP=11; iCP=11;
fTrailing = TRUE; fTrailing = TRUE;
cChars = 10; cChars = 10;
cGlyphs = 10; cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX); hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr); ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 1953 || ok(piX == 1953,
piX == 0, /* win2k3 */ "iCP=%d should return piX=1953 not %d\n", iCP, piX);
"iCP=%d should return piX=1953 or piX=0 not %d\n", iCP, piX);
} }
static void test_ScriptString(HDC hdc) static void test_ScriptString(HDC hdc)

View File

@ -1101,18 +1101,59 @@ HRESULT WINAPI ScriptCPtoX(int iCP,
int *piX) int *piX)
{ {
int item; int item;
int iPosX; float iPosX;
float fMaxPosX = 0; int iSpecial = -1;
int iCluster = -1;
int clust_size = 1;
float special_size = 0.0;
TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n", TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
psa, piX); psa, piX);
for (item=0; item < cGlyphs; item++) /* total piAdvance */
fMaxPosX += piAdvance[item];
iPosX = (fMaxPosX/cGlyphs)*(iCP+fTrailing);
if (iPosX > fMaxPosX)
iPosX = fMaxPosX;
*piX = iPosX; /* Return something in range */
if (fTrailing)
iCP++;
iPosX = 0.0;
for (item=0; item < iCP && item < cGlyphs; item++)
{
if (iSpecial == -1 && (iCluster == -1 || (iCluster != -1 && iCluster+clust_size <= item)))
{
int check;
int clust = pwLogClust[item];
clust_size = 1;
iCluster = -1;
for (check = item+1; check < cGlyphs; check++)
{
if (pwLogClust[check] == clust)
{
clust_size ++;
if (iCluster == -1)
iCluster = item;
}
else break;
}
if (check >= cGlyphs)
{
for (check = clust; check < cGlyphs; check++)
special_size += piAdvance[check];
iSpecial = item;
special_size /= (cChars - item);
iPosX += special_size;
}
else
iPosX += piAdvance[clust] / (float)clust_size;
}
else if (iSpecial != -1)
iPosX += special_size;
else /* (iCluster != -1) */
iPosX += piAdvance[pwLogClust[iCluster]] / (float)clust_size;
}
*piX = iPosX;
TRACE("*piX=%d\n", *piX); TRACE("*piX=%d\n", *piX);
return S_OK; return S_OK;
} }