Commit 06ed81ec authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

usp10: Move text metrics into the script cache. Start using accessor functions.

parent 6a12d679
...@@ -145,6 +145,8 @@ static const SCRIPT_PROPERTIES *script_props[] = ...@@ -145,6 +145,8 @@ static const SCRIPT_PROPERTIES *script_props[] =
typedef struct { typedef struct {
HDC hdc; HDC hdc;
LONG height;
WCHAR default_char;
} ScriptCache; } ScriptCache;
typedef struct { typedef struct {
...@@ -190,15 +192,50 @@ static inline void usp_free(LPVOID mem) ...@@ -190,15 +192,50 @@ static inline void usp_free(LPVOID mem)
HeapFree(GetProcessHeap(), 0, 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) static HRESULT get_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
{ {
if (!psc) return E_INVALIDARG; if (!psc) return E_INVALIDARG;
if (!*psc) if (!*psc)
{ {
HRESULT ret;
ScriptCache *sc;
if (!hdc) return E_PENDING; if (!hdc) return E_PENDING;
if (!(*psc = usp_alloc(sizeof(ScriptCache)))) return E_OUTOFMEMORY; if (!(sc = usp_zero_alloc(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
((ScriptCache *)*psc)->hdc = hdc; if ((ret = init_script_cache(hdc, sc)))
{
usp_free(sc);
return ret;
}
*psc = sc;
} }
TRACE("<- %p\n", *psc);
return S_OK; return S_OK;
} }
...@@ -284,7 +321,6 @@ HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num) ...@@ -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 WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
{ {
HRESULT hr; HRESULT hr;
TEXTMETRICW ptm;
TRACE("%p,%p,%p\n", hdc, psc, sfp); TRACE("%p,%p,%p\n", hdc, psc, sfp);
...@@ -296,10 +332,7 @@ HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPR ...@@ -296,10 +332,7 @@ HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPR
/* return something sensible? */ /* return something sensible? */
sfp->wgBlank = 0; sfp->wgBlank = 0;
if (GetTextMetricsW(((ScriptCache *)*psc)->hdc, &ptm)) sfp->wgDefault = get_cache_default_char(psc);
sfp->wgDefault = ptm.tmDefaultChar;
else
sfp->wgDefault = 0;
sfp->wgInvalid = 0; sfp->wgInvalid = 0;
sfp->wgKashida = 0xffff; sfp->wgKashida = 0xffff;
sfp->iKashidaWidth = 0; sfp->iKashidaWidth = 0;
...@@ -1191,7 +1224,7 @@ HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars, ...@@ -1191,7 +1224,7 @@ HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
TRACE("\n"); TRACE("\n");
if (!psa->fNoGlyphIndex) { /* Glyph translate */ 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; return S_FALSE;
TRACE("After: "); TRACE("After: ");
...@@ -1247,7 +1280,7 @@ HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs, ...@@ -1247,7 +1280,7 @@ HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
memset(pABC, 0, sizeof(ABC)); memset(pABC, 0, sizeof(ABC));
/* FIXME: set pGoffset to more reasonable values */ /* 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"); WARN("Could not get ABC values\n");
for (wcnt = 0; wcnt < cGlyphs; wcnt++) { for (wcnt = 0; wcnt < cGlyphs; wcnt++) {
...@@ -1311,7 +1344,7 @@ HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars ...@@ -1311,7 +1344,7 @@ HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars
TRACE("%4x",pwcInChars[cnt]); TRACE("%4x",pwcInChars[cnt]);
TRACE("\n"); TRACE("\n");
GetGlyphIndicesW(((ScriptCache *)*psc)->hdc, pwcInChars, cChars, pwOutGlyphs, 0); GetGlyphIndicesW(get_cache_hdc(psc), pwcInChars, cChars, pwOutGlyphs, 0);
TRACE("After: "); TRACE("After: ");
for (cnt = 0; cnt < cChars; cnt++) { for (cnt = 0; cnt < cChars; cnt++) {
...@@ -1345,7 +1378,7 @@ HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UIN ...@@ -1345,7 +1378,7 @@ HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UIN
if (!psa->fNoGlyphIndex) /* Have Glyphs? */ if (!psa->fNoGlyphIndex) /* Have Glyphs? */
fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */ 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_FALSE;
return S_OK; return S_OK;
...@@ -1368,17 +1401,13 @@ HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UIN ...@@ -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 WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
{ {
HRESULT hr; HRESULT hr;
TEXTMETRICW metric;
TRACE("(%p, %p, %p)\n", hdc, psc, height); TRACE("(%p, %p, %p)\n", hdc, psc, height);
if (!height) return E_INVALIDARG; if (!height) return E_INVALIDARG;
if ((hr = get_script_cache(hdc, psc))) return hr; if ((hr = get_script_cache(hdc, psc))) return hr;
/* FIXME: get this from the cache */ *height = get_cache_height(psc);
if (!GetTextMetricsW(((ScriptCache *)*psc)->hdc, &metric)) return E_INVALIDARG;
*height = metric.tmHeight;
return S_OK; return S_OK;
} }
...@@ -1406,7 +1435,7 @@ HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, AB ...@@ -1406,7 +1435,7 @@ HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, AB
if ((hr = get_script_cache(hdc, psc))) return hr; if ((hr = get_script_cache(hdc, psc))) return hr;
/* FIXME: get this from the cache */ /* 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; return S_OK;
} }
...@@ -1529,7 +1558,6 @@ const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa) ...@@ -1529,7 +1558,6 @@ const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
{ {
unsigned int i, j; unsigned int i, j;
StringAnalysis *analysis = ssa; StringAnalysis *analysis = ssa;
TEXTMETRICW metric;
TRACE("(%p)\n", ssa); TRACE("(%p)\n", ssa);
...@@ -1537,20 +1565,8 @@ const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa) ...@@ -1537,20 +1565,8 @@ const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
if (!analysis->sz) if (!analysis->sz)
{ {
if (!(analysis->sz = usp_alloc(sizeof(SIZE)))) if (!(analysis->sz = usp_alloc(sizeof(SIZE)))) return NULL;
return NULL; analysis->sz->cy = analysis->sc->height;
/* 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;
analysis->sz->cx = 0; analysis->sz->cx = 0;
for (i = 0; i < analysis->numItems; i++) for (i = 0; i < analysis->numItems; i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment