📄 usp10.c
字号:
}
/* out of range */
*piCh = analysis->pItem[analysis->numItems].iCharPos;
*piTrailing = FALSE;
return S_OK;
}
/***********************************************************************
* ScriptStringFree (USP10.@)
*
* Free a string analysis.
*
* PARAMS
* pssa [I] string analysis.
*
* RETURNS
* Success: S_OK
* Failure: Non-zero HRESULT value.
*/
HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
{
StringAnalysis* analysis;
BOOL invalid;
int i;
TRACE("(%p)\n", pssa);
if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
invalid = analysis->invalid;
for (i = 0; i < analysis->numItems; i++)
{
usp_free(analysis->glyphs[i].glyphs);
usp_free(analysis->glyphs[i].pwLogClust);
usp_free(analysis->glyphs[i].piAdvance);
usp_free(analysis->glyphs[i].psva);
usp_free(analysis->glyphs[i].pGoffset);
usp_free(analysis->glyphs[i].abc);
}
usp_free(analysis->glyphs);
usp_free(analysis->pItem);
usp_free(analysis->logattrs);
usp_free(analysis->sz);
usp_free(analysis);
if (invalid) return E_INVALIDARG;
return S_OK;
}
/***********************************************************************
* ScriptCPtoX (USP10.@)
*
*/
HRESULT WINAPI ScriptCPtoX(int iCP,
BOOL fTrailing,
int cChars,
int cGlyphs,
const WORD *pwLogClust,
const SCRIPT_VISATTR *psva,
const int *piAdvance,
const SCRIPT_ANALYSIS *psa,
int *piX)
{
int item;
int iPosX;
float fMaxPosX = 0;
TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
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 */
TRACE("*piX=%d\n", *piX);
return S_OK;
}
/***********************************************************************
* ScriptXtoCP (USP10.@)
*
*/
HRESULT WINAPI ScriptXtoCP(int iX,
int cChars,
int cGlyphs,
const WORD *pwLogClust,
const SCRIPT_VISATTR *psva,
const int *piAdvance,
const SCRIPT_ANALYSIS *psa,
int *piCP,
int *piTrailing)
{
int item;
int iPosX;
float fMaxPosX = 1;
float fAvePosX;
TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
psa, piCP, piTrailing);
if (iX < 0) /* iX is before start of run */
{
*piCP = -1;
*piTrailing = TRUE;
return S_OK;
}
for (item=0; item < cGlyphs; item++) /* total piAdvance */
fMaxPosX += piAdvance[item];
if (iX >= fMaxPosX) /* iX too large */
{
*piCP = cChars;
*piTrailing = FALSE;
return S_OK;
}
fAvePosX = fMaxPosX / cGlyphs;
iPosX = fAvePosX;
for (item = 1; item < cGlyphs && iPosX < iX; item++)
iPosX += fAvePosX;
if (iPosX - iX > fAvePosX/2)
*piTrailing = 0;
else
*piTrailing = 1; /* yep we are over halfway */
*piCP = item -1; /* Return character position */
TRACE("*piCP=%d iPposX=%d\n", *piCP, iPosX);
return S_OK;
}
/***********************************************************************
* ScriptBreak (USP10.@)
*
* Retrieve line break information.
*
* PARAMS
* chars [I] Array of characters.
* sa [I] String analysis.
* la [I] Array of logical attribute structures.
*
* RETURNS
* Success: S_OK
* Failure: S_FALSE
*/
HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
{
unsigned int i;
TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
if (!la) return S_FALSE;
for (i = 0; i < count; i++)
{
memset(&la[i], 0, sizeof(SCRIPT_LOGATTR));
/* FIXME: set the other flags */
la[i].fWhiteSpace = isspaceW(chars[i]);
la[i].fCharStop = 1;
}
return S_OK;
}
static const struct
{
WCHAR start;
WCHAR end;
DWORD flag;
}
complex_ranges[] =
{
{ 0, 0x0b, SIC_COMPLEX },
{ 0x0c, 0x0c, SIC_NEUTRAL },
{ 0x0d, 0x1f, SIC_COMPLEX },
{ 0x20, 0x2f, SIC_NEUTRAL },
{ 0x30, 0x39, SIC_ASCIIDIGIT },
{ 0x3a, 0x40, SIC_NEUTRAL },
{ 0x5b, 0x60, SIC_NEUTRAL },
{ 0x7b, 0x7e, SIC_NEUTRAL },
{ 0x7f, 0x9f, SIC_COMPLEX },
{ 0xa0, 0xa5, SIC_NEUTRAL },
{ 0xa7, 0xa8, SIC_NEUTRAL },
{ 0xab, 0xab, SIC_NEUTRAL },
{ 0xad, 0xad, SIC_NEUTRAL },
{ 0xaf, 0xaf, SIC_NEUTRAL },
{ 0xb0, 0xb1, SIC_NEUTRAL },
{ 0xb4, 0xb4, SIC_NEUTRAL },
{ 0xb6, 0xb8, SIC_NEUTRAL },
{ 0xbb, 0xbf, SIC_NEUTRAL },
{ 0xd7, 0xd7, SIC_NEUTRAL },
{ 0xf7, 0xf7, SIC_NEUTRAL },
{ 0x2b9, 0x2ba, SIC_NEUTRAL },
{ 0x2c2, 0x2cf, SIC_NEUTRAL },
{ 0x2d2, 0x2df, SIC_NEUTRAL },
{ 0x2e5, 0x2e9, SIC_COMPLEX },
{ 0x2ea, 0x2ed, SIC_NEUTRAL },
{ 0x300, 0x362, SIC_COMPLEX },
{ 0x530, 0x60b, SIC_COMPLEX },
{ 0x60c, 0x60d, SIC_NEUTRAL },
{ 0x60e, 0x669, SIC_COMPLEX },
{ 0x66a, 0x66a, SIC_NEUTRAL },
{ 0x66b, 0x6e8, SIC_COMPLEX },
{ 0x6e9, 0x6e9, SIC_NEUTRAL },
{ 0x6ea, 0x7bf, SIC_COMPLEX },
{ 0x900, 0x1360, SIC_COMPLEX },
{ 0x137d, 0x137f, SIC_COMPLEX },
{ 0x1680, 0x1680, SIC_NEUTRAL },
{ 0x1780, 0x18af, SIC_COMPLEX },
{ 0x2000, 0x200a, SIC_NEUTRAL },
{ 0x200b, 0x200f, SIC_COMPLEX },
{ 0x2010, 0x2016, SIC_NEUTRAL },
{ 0x2018, 0x2022, SIC_NEUTRAL },
{ 0x2024, 0x2028, SIC_NEUTRAL },
{ 0x2029, 0x202e, SIC_COMPLEX },
{ 0x202f, 0x2037, SIC_NEUTRAL },
{ 0x2039, 0x203c, SIC_NEUTRAL },
{ 0x2044, 0x2046, SIC_NEUTRAL },
{ 0x206a, 0x206f, SIC_COMPLEX },
{ 0x207a, 0x207e, SIC_NEUTRAL },
{ 0x208a, 0x20aa, SIC_NEUTRAL },
{ 0x20ac, 0x20cf, SIC_NEUTRAL },
{ 0x20d0, 0x20ff, SIC_COMPLEX },
{ 0x2103, 0x2103, SIC_NEUTRAL },
{ 0x2105, 0x2105, SIC_NEUTRAL },
{ 0x2109, 0x2109, SIC_NEUTRAL },
{ 0x2116, 0x2116, SIC_NEUTRAL },
{ 0x2121, 0x2122, SIC_NEUTRAL },
{ 0x212e, 0x212e, SIC_NEUTRAL },
{ 0x2153, 0x2154, SIC_NEUTRAL },
{ 0x215b, 0x215e, SIC_NEUTRAL },
{ 0x2190, 0x2199, SIC_NEUTRAL },
{ 0x21b8, 0x21b9, SIC_NEUTRAL },
{ 0x21d2, 0x21d2, SIC_NEUTRAL },
{ 0x21d4, 0x21d4, SIC_NEUTRAL },
{ 0x21e7, 0x21e7, SIC_NEUTRAL },
{ 0x2200, 0x2200, SIC_NEUTRAL },
{ 0x2202, 0x2203, SIC_NEUTRAL },
{ 0x2207, 0x2208, SIC_NEUTRAL },
{ 0x220b, 0x220b, SIC_NEUTRAL },
{ 0x220f, 0x220f, SIC_NEUTRAL },
{ 0x2211, 0x2213, SIC_NEUTRAL },
{ 0x2215, 0x2215, SIC_NEUTRAL },
{ 0x221a, 0x221a, SIC_NEUTRAL },
{ 0x221d, 0x2220, SIC_NEUTRAL },
{ 0x2223, 0x2223, SIC_NEUTRAL },
{ 0x2225, 0x2225, SIC_NEUTRAL },
{ 0x2227, 0x222c, SIC_NEUTRAL },
{ 0x222e, 0x222e, SIC_NEUTRAL },
{ 0x2234, 0x2237, SIC_NEUTRAL },
{ 0x223c, 0x223d, SIC_NEUTRAL },
{ 0x2248, 0x2248, SIC_NEUTRAL },
{ 0x224c, 0x224c, SIC_NEUTRAL },
{ 0x2252, 0x2252, SIC_NEUTRAL },
{ 0x2260, 0x2261, SIC_NEUTRAL },
{ 0x2264, 0x2267, SIC_NEUTRAL },
{ 0x226a, 0x226b, SIC_NEUTRAL },
{ 0x226e, 0x226f, SIC_NEUTRAL },
{ 0x2282, 0x2283, SIC_NEUTRAL },
{ 0x2286, 0x2287, SIC_NEUTRAL },
{ 0x2295, 0x2295, SIC_NEUTRAL },
{ 0x2299, 0x2299, SIC_NEUTRAL },
{ 0x22a5, 0x22a5, SIC_NEUTRAL },
{ 0x22bf, 0x22bf, SIC_NEUTRAL },
{ 0x2312, 0x2312, SIC_NEUTRAL },
{ 0x24ea, 0x24ea, SIC_COMPLEX },
{ 0x2500, 0x254b, SIC_NEUTRAL },
{ 0x2550, 0x256d, SIC_NEUTRAL },
{ 0x256e, 0x2574, SIC_NEUTRAL },
{ 0x2581, 0x258f, SIC_NEUTRAL },
{ 0x2592, 0x2595, SIC_NEUTRAL },
{ 0x25a0, 0x25a1, SIC_NEUTRAL },
{ 0x25a3, 0x25a9, SIC_NEUTRAL },
{ 0x25b2, 0x25b3, SIC_NEUTRAL },
{ 0x25b6, 0x25b7, SIC_NEUTRAL },
{ 0x25bc, 0x25bd, SIC_NEUTRAL },
{ 0x25c0, 0x25c1, SIC_NEUTRAL },
{ 0x25c6, 0x25c8, SIC_NEUTRAL },
{ 0x25cb, 0x25cb, SIC_NEUTRAL },
{ 0x25ce, 0x25d1, SIC_NEUTRAL },
{ 0x25e2, 0x25e5, SIC_NEUTRAL },
{ 0x25ef, 0x25ef, SIC_NEUTRAL },
{ 0x2605, 0x2606, SIC_NEUTRAL },
{ 0x2609, 0x2609, SIC_NEUTRAL },
{ 0x260e, 0x260f, SIC_NEUTRAL },
{ 0x261c, 0x261c, SIC_NEUTRAL },
{ 0x261e, 0x261e, SIC_NEUTRAL },
{ 0x2640, 0x2640, SIC_NEUTRAL },
{ 0x2642, 0x2642, SIC_NEUTRAL },
{ 0x2660, 0x2661, SIC_NEUTRAL },
{ 0x2663, 0x2665, SIC_NEUTRAL },
{ 0x2667, 0x266a, SIC_NEUTRAL },
{ 0x266c, 0x266d, SIC_NEUTRAL },
{ 0x266f, 0x266f, SIC_NEUTRAL },
{ 0x273d, 0x273d, SIC_NEUTRAL },
{ 0x2e80, 0x312f, SIC_COMPLEX },
{ 0x3190, 0x31bf, SIC_COMPLEX },
{ 0x31f0, 0x31ff, SIC_COMPLEX },
{ 0x3220, 0x325f, SIC_COMPLEX },
{ 0x3280, 0xa4ff, SIC_COMPLEX },
{ 0xd800, 0xdfff, SIC_COMPLEX },
{ 0xe000, 0xf8ff, SIC_NEUTRAL },
{ 0xf900, 0xfaff, SIC_COMPLEX },
{ 0xfb13, 0xfb28, SIC_COMPLEX },
{ 0xfb29, 0xfb29, SIC_NEUTRAL },
{ 0xfb2a, 0xfb4f, SIC_COMPLEX },
{ 0xfd3e, 0xfd3f, SIC_NEUTRAL },
{ 0xfdd0, 0xfdef, SIC_COMPLEX },
{ 0xfe20, 0xfe6f, SIC_COMPLEX },
{ 0xfeff, 0xfeff, SIC_COMPLEX },
{ 0xff01, 0xff5e, SIC_COMPLEX },
{ 0xff61, 0xff9f, SIC_COMPLEX },
{ 0xffe0, 0xffe6, SIC_COMPLEX },
{ 0xffe8, 0xffee, SIC_COMPLEX },
{ 0xfff9, 0xfffb, SIC_COMPLEX },
{ 0xfffe, 0xfffe, SIC_COMPLEX }
};
/***********************************************************************
* ScriptIsComplex (USP10.@)
*
* Determine if a string is complex.
*
* PARAMS
* chars [I] Array of characters to test.
* len [I] Length in characters.
* flag [I] Flag.
*
* RETURNS
* Success: S_OK
* Failure: S_FALSE
*
* NOTES
* Behaviour matches that of WinXP.
*/
HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
{
unsigned int i, j;
TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
for (i = 0; i < len; i++)
{
for (j = 0; j < sizeof(complex_ranges)/sizeof(complex_ranges[0]); j++)
{
if (chars[i] >= complex_ranges[j].start &&
chars[i] <= complex_ranges[j].end &&
(flag & complex_ranges[j].flag)) return S_OK;
}
}
return S_FALSE;
}
/***********************************************************************
* ScriptShape (USP10.@)
*
* Produce glyphs and visual attributes for a run.
*
* PARAMS
* hdc [I] Device context.
* psc [I/O] Opaque pointer to a script cache.
* pwcChars [I] Array of characters specifying the run.
* cChars [I] Number of characters in pwcChars.
* cMaxGlyphs [I] Length of pwOutGlyphs.
* psa [I/O] String analysis.
* pwOutGlyphs [O] Array of glyphs.
* pwLogClust [O] Array of logical cluster info.
* psva [O] Array of visual attributes.
* pcGlyphs [O] Number of glyphs returned.
*
* RETURNS
* Success: S_OK
* Failure: Non-zero HRESULT value.
*/
HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
int cChars, int cMaxGlyphs,
SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
SCRIPT_VISATTR *psva, int *pcGlyphs)
{
int cnt;
HRESULT hr;
*pcGlyphs = cChars;
TRACE("(%p, %p, %p, %d, %d, %p)\n", hdc, psc, pwcChars, cChars, cMaxGlyphs, psa);
if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
if ((hr = get_script_cache(hdc, psc))) return hr;
TRACE("Before: ");
for (cnt = 0; cnt < cChars; cnt++)
TRACE("%4x",pwcChars[cnt]);
TRACE("\n");
if (!psa->fNoGlyphIndex) { /* Glyph translate */
if (!(GetGlyphIndicesW((HDC)get_cache_hdc(psc), (LPCWSTR) pwcChars, (int)cChars, (LPWORD) pwOutGlyphs,(DWORD) 0)))
return S_FALSE;
TRACE("After: ");
for (cnt = 0; cnt < cChars; cnt++) {
TRACE("%04x",pwOutGlyphs[cnt]);
}
TRACE("\n");
}
else {
TRACE("After: ");
for (cnt = 0; cnt < cChars; cnt++) { /* no translate so set up */
pwOutGlyphs[cnt] = pwcChars[cnt]; /* copy in to out and */
TRACE("%04x",pwOutGlyphs[cnt]);
}
TRACE("\n");
}
/* Set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
for (cnt = 0; cnt < cChars; cnt++) {
/* FIXME: set to better values */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -