usp10: Move text metrics into the script cache. Start using accessor functions.
This commit is contained in:
parent
6a12d679b0
commit
06ed81ecc0
|
@ -145,6 +145,8 @@ static const SCRIPT_PROPERTIES *script_props[] =
|
|||
|
||||
typedef struct {
|
||||
HDC hdc;
|
||||
LONG height;
|
||||
WCHAR default_char;
|
||||
} ScriptCache;
|
||||
|
||||
typedef struct {
|
||||
|
@ -190,15 +192,50 @@ static inline void usp_free(LPVOID mem)
|
|||
HeapFree(GetProcessHeap(), 0, mem);
|
||||
}
|
||||
|
||||
static HDC get_cache_hdc(SCRIPT_CACHE *psc)
|
||||
{
|
||||
return ((ScriptCache *)*psc)->hdc;
|
||||
}
|
||||
|
||||
static WCHAR get_cache_default_char(SCRIPT_CACHE *psc)
|
||||
{
|
||||
return ((ScriptCache *)*psc)->default_char;
|
||||
}
|
||||
|
||||
static LONG get_cache_height(SCRIPT_CACHE *psc)
|
||||
{
|
||||
return ((ScriptCache *)*psc)->height;
|
||||
}
|
||||
|
||||
static HRESULT init_script_cache(const HDC hdc, ScriptCache *sc)
|
||||
{
|
||||
TEXTMETRICW metric;
|
||||
|
||||
if (!GetTextMetricsW(hdc, &metric)) return E_INVALIDARG;
|
||||
sc->height = metric.tmHeight;
|
||||
sc->default_char = metric.tmDefaultChar;
|
||||
sc->hdc = hdc;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT get_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
|
||||
{
|
||||
if (!psc) return E_INVALIDARG;
|
||||
if (!*psc)
|
||||
{
|
||||
HRESULT ret;
|
||||
ScriptCache *sc;
|
||||
|
||||
if (!hdc) return E_PENDING;
|
||||
if (!(*psc = usp_alloc(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
|
||||
((ScriptCache *)*psc)->hdc = hdc;
|
||||
if (!(sc = usp_zero_alloc(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
|
||||
if ((ret = init_script_cache(hdc, sc)))
|
||||
{
|
||||
usp_free(sc);
|
||||
return ret;
|
||||
}
|
||||
*psc = sc;
|
||||
}
|
||||
TRACE("<- %p\n", *psc);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -284,7 +321,6 @@ HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
|
|||
HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
|
||||
{
|
||||
HRESULT hr;
|
||||
TEXTMETRICW ptm;
|
||||
|
||||
TRACE("%p,%p,%p\n", hdc, psc, sfp);
|
||||
|
||||
|
@ -296,10 +332,7 @@ HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPR
|
|||
|
||||
/* return something sensible? */
|
||||
sfp->wgBlank = 0;
|
||||
if (GetTextMetricsW(((ScriptCache *)*psc)->hdc, &ptm))
|
||||
sfp->wgDefault = ptm.tmDefaultChar;
|
||||
else
|
||||
sfp->wgDefault = 0;
|
||||
sfp->wgDefault = get_cache_default_char(psc);
|
||||
sfp->wgInvalid = 0;
|
||||
sfp->wgKashida = 0xffff;
|
||||
sfp->iKashidaWidth = 0;
|
||||
|
@ -1191,7 +1224,7 @@ HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
|
|||
TRACE("\n");
|
||||
|
||||
if (!psa->fNoGlyphIndex) { /* Glyph translate */
|
||||
if (!(GetGlyphIndicesW(((ScriptCache *)*psc)->hdc, pwcChars, cChars, pwOutGlyphs, 0)))
|
||||
if (!(GetGlyphIndicesW(get_cache_hdc(psc), pwcChars, cChars, pwOutGlyphs, 0)))
|
||||
return S_FALSE;
|
||||
|
||||
TRACE("After: ");
|
||||
|
@ -1247,7 +1280,7 @@ HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
|
|||
memset(pABC, 0, sizeof(ABC));
|
||||
|
||||
/* FIXME: set pGoffset to more reasonable values */
|
||||
if (!GetCharABCWidthsI(((ScriptCache *)*psc)->hdc, 0, cGlyphs, (WORD *) pwGlyphs, lpABC ))
|
||||
if (!GetCharABCWidthsI(get_cache_hdc(psc), 0, cGlyphs, (WORD *) pwGlyphs, lpABC ))
|
||||
{
|
||||
WARN("Could not get ABC values\n");
|
||||
for (wcnt = 0; wcnt < cGlyphs; wcnt++) {
|
||||
|
@ -1311,7 +1344,7 @@ HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars
|
|||
TRACE("%4x",pwcInChars[cnt]);
|
||||
TRACE("\n");
|
||||
|
||||
GetGlyphIndicesW(((ScriptCache *)*psc)->hdc, pwcInChars, cChars, pwOutGlyphs, 0);
|
||||
GetGlyphIndicesW(get_cache_hdc(psc), pwcInChars, cChars, pwOutGlyphs, 0);
|
||||
|
||||
TRACE("After: ");
|
||||
for (cnt = 0; cnt < cChars; cnt++) {
|
||||
|
@ -1345,7 +1378,7 @@ HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UIN
|
|||
if (!psa->fNoGlyphIndex) /* Have Glyphs? */
|
||||
fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
|
||||
|
||||
if (!ExtTextOutW(((ScriptCache *)*psc)->hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
|
||||
if (!ExtTextOutW(get_cache_hdc(psc), x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
|
||||
return S_FALSE;
|
||||
|
||||
return S_OK;
|
||||
|
@ -1368,17 +1401,13 @@ HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UIN
|
|||
HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
|
||||
{
|
||||
HRESULT hr;
|
||||
TEXTMETRICW metric;
|
||||
|
||||
TRACE("(%p, %p, %p)\n", hdc, psc, height);
|
||||
|
||||
if (!height) return E_INVALIDARG;
|
||||
if ((hr = get_script_cache(hdc, psc))) return hr;
|
||||
|
||||
/* FIXME: get this from the cache */
|
||||
if (!GetTextMetricsW(((ScriptCache *)*psc)->hdc, &metric)) return E_INVALIDARG;
|
||||
|
||||
*height = metric.tmHeight;
|
||||
*height = get_cache_height(psc);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -1406,7 +1435,7 @@ HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, AB
|
|||
if ((hr = get_script_cache(hdc, psc))) return hr;
|
||||
|
||||
/* FIXME: get this from the cache */
|
||||
if (!GetCharABCWidthsW(((ScriptCache *)*psc)->hdc, glyph, glyph, abc)) return E_HANDLE;
|
||||
if (!GetCharABCWidthsW(get_cache_hdc(psc), glyph, glyph, abc)) return E_HANDLE;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -1529,7 +1558,6 @@ const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
|
|||
{
|
||||
unsigned int i, j;
|
||||
StringAnalysis *analysis = ssa;
|
||||
TEXTMETRICW metric;
|
||||
|
||||
TRACE("(%p)\n", ssa);
|
||||
|
||||
|
@ -1537,20 +1565,8 @@ const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
|
|||
|
||||
if (!analysis->sz)
|
||||
{
|
||||
if (!(analysis->sz = usp_alloc(sizeof(SIZE))))
|
||||
return NULL;
|
||||
|
||||
/* FIXME: These values should be calculated at a more
|
||||
* appropriate place so that we can just pass cached
|
||||
* values here.
|
||||
*/
|
||||
if (!GetTextMetricsW(analysis->sc->hdc, &metric))
|
||||
{
|
||||
usp_free(analysis->sz);
|
||||
analysis->sz = NULL;
|
||||
return NULL;
|
||||
}
|
||||
analysis->sz->cy = metric.tmHeight;
|
||||
if (!(analysis->sz = usp_alloc(sizeof(SIZE)))) return NULL;
|
||||
analysis->sz->cy = analysis->sc->height;
|
||||
|
||||
analysis->sz->cx = 0;
|
||||
for (i = 0; i < analysis->numItems; i++)
|
||||
|
|
Loading…
Reference in New Issue