usp10: Update ScriptCPtoX to handle RTL runs.

This commit is contained in:
Aric Stewart 2011-03-11 12:47:37 -06:00 committed by Alexandre Julliard
parent 4bacb3f24e
commit 3f7ad460ef
2 changed files with 146 additions and 2 deletions

View File

@ -1076,6 +1076,7 @@ static void test_ScriptXtoX(void)
int cGlyphs; int cGlyphs;
WORD pwLogClustXtoCP[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}; WORD pwLogClustCPtoX[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
WORD pwLogClustCPtoX_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
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;
@ -1276,6 +1277,116 @@ static void test_ScriptXtoX(void)
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,
"iCP=%d should return piX=1953 not %d\n", iCP, piX); "iCP=%d should return piX=1953 not %d\n", iCP, piX);
items[0].a.fRTL = TRUE;
iCP=0;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 780,
"iCP=%d should return piX=780 not %d\n", iCP, piX);
iCP=1;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 720,
"iCP=%d should return piX=720 not %d\n", iCP, piX);
iCP=2;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 660,
"iCP=%d should return piX=660 not %d\n", iCP, piX);
iCP=3;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, 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=4;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 495,
"iCP=%d should return piX=495 not %d\n", iCP, piX);
iCP=5;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, psva, piAdvance, &items[0].a, &piX);
ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
ok(piX == 390,
"iCP=%d should return piX=390 not %d\n", iCP, piX);
iCP=6;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, 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=7;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, 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=8;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, 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=9;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, 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=10;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, 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=11;
fTrailing = FALSE;
cChars = 10;
cGlyphs = 10;
hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClustCPtoX_RTL, 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 %d\n", iCP, piX);
} }
static void test_ScriptString(HDC hdc) static void test_ScriptString(HDC hdc)

View File

@ -1106,13 +1106,39 @@ HRESULT WINAPI ScriptCPtoX(int iCP,
int iCluster = -1; int iCluster = -1;
int clust_size = 1; int clust_size = 1;
float special_size = 0.0; float special_size = 0.0;
int iMaxPos = 0;
BOOL rtl = FALSE;
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);
if (psa->fRTL && ! psa->fLogicalOrder)
rtl = TRUE;
if (fTrailing) if (fTrailing)
iCP++; {
if (rtl)
iCP--;
else
iCP++;
}
if (rtl)
{
int max_clust = pwLogClust[0];
for (item=0; item < cGlyphs; item++)
if (pwLogClust[item] > max_clust)
{
ERR("We do not handle non reversed clusters properly\n");
break;
}
iMaxPos = 0;
for (item = max_clust; item >=0; item --)
iMaxPos += piAdvance[item];
}
iPosX = 0.0; iPosX = 0.0;
for (item=0; item < iCP && item < cGlyphs; item++) for (item=0; item < iCP && item < cGlyphs; item++)
@ -1136,7 +1162,7 @@ HRESULT WINAPI ScriptCPtoX(int iCP,
else break; else break;
} }
if (check >= cGlyphs) if (check >= cGlyphs && !iMaxPos)
{ {
for (check = clust; check < cGlyphs; check++) for (check = clust; check < cGlyphs; check++)
special_size += piAdvance[check]; special_size += piAdvance[check];
@ -1153,6 +1179,13 @@ HRESULT WINAPI ScriptCPtoX(int iCP,
iPosX += piAdvance[pwLogClust[iCluster]] / (float)clust_size; iPosX += piAdvance[pwLogClust[iCluster]] / (float)clust_size;
} }
if (iMaxPos > 0)
{
iPosX = iMaxPos - iPosX;
if (iPosX < 0)
iPosX = 0;
}
*piX = iPosX; *piX = iPosX;
TRACE("*piX=%d\n", *piX); TRACE("*piX=%d\n", *piX);
return S_OK; return S_OK;