dwrite: Scale glyph run analysis advances and offsets with ppdip factor.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2015-10-19 08:43:02 +03:00 committed by Alexandre Julliard
parent 6262cc325f
commit 2fdee67dd2
2 changed files with 43 additions and 16 deletions

View File

@ -4381,6 +4381,7 @@ HRESULT create_glyphrunanalysis(DWRITE_RENDERING_MODE rendering_mode, DWRITE_MEA
FLOAT ppdip, DWRITE_GRID_FIT_MODE gridfit_mode, DWRITE_TEXT_ANTIALIAS_MODE aa_mode, FLOAT originX, FLOAT originY, IDWriteGlyphRunAnalysis **ret)
{
struct dwrite_glyphrunanalysis *analysis;
UINT32 i;
*ret = NULL;
@ -4425,12 +4426,17 @@ HRESULT create_glyphrunanalysis(DWRITE_RENDERING_MODE rendering_mode, DWRITE_MEA
memcpy(analysis->glyphs, run->glyphIndices, run->glyphCount*sizeof(*run->glyphIndices));
if (run->glyphAdvances)
memcpy(analysis->advances, run->glyphAdvances, run->glyphCount*sizeof(*run->glyphAdvances));
if (run->glyphAdvances) {
if (ppdip == 1.0f)
memcpy(analysis->advances, run->glyphAdvances, run->glyphCount*sizeof(*run->glyphAdvances));
else {
for (i = 0; i < run->glyphCount; i++)
analysis->advances[i] = run->glyphAdvances[i] * ppdip;
}
}
else {
DWRITE_FONT_METRICS metrics;
IDWriteFontFace1 *fontface1;
UINT32 i;
IDWriteFontFace_GetMetrics(run->fontFace, &metrics);
IDWriteFontFace_QueryInterface(run->fontFace, &IID_IDWriteFontFace1, (void**)&fontface1);
@ -4445,7 +4451,7 @@ HRESULT create_glyphrunanalysis(DWRITE_RENDERING_MODE rendering_mode, DWRITE_MEA
hr = IDWriteFontFace1_GetDesignGlyphAdvances(fontface1, 1, run->glyphIndices + i, &a, run->isSideways);
if (FAILED(hr))
a = 0;
analysis->advances[i] = get_scaled_advance_width(a, run->fontEmSize, &metrics);
analysis->advances[i] = get_scaled_advance_width(a, run->fontEmSize, &metrics) * ppdip;
break;
case DWRITE_MEASURING_MODE_GDI_CLASSIC:
case DWRITE_MEASURING_MODE_GDI_NATURAL:
@ -4454,7 +4460,7 @@ HRESULT create_glyphrunanalysis(DWRITE_RENDERING_MODE rendering_mode, DWRITE_MEA
if (FAILED(hr))
analysis->advances[i] = 0.0;
else
analysis->advances[i] = floorf(a * run->fontEmSize * ppdip / metrics.designUnitsPerEm + 0.5f) / ppdip;
analysis->advances[i] = floorf(a * run->fontEmSize * ppdip / metrics.designUnitsPerEm + 0.5f);
break;
default:
;
@ -4464,8 +4470,16 @@ HRESULT create_glyphrunanalysis(DWRITE_RENDERING_MODE rendering_mode, DWRITE_MEA
IDWriteFontFace1_Release(fontface1);
}
if (run->glyphOffsets)
memcpy(analysis->offsets, run->glyphOffsets, run->glyphCount*sizeof(*run->glyphOffsets));
if (run->glyphOffsets) {
if (ppdip == 1.0f)
memcpy(analysis->offsets, run->glyphOffsets, run->glyphCount*sizeof(*run->glyphOffsets));
else {
for (i = 0; i < run->glyphCount; i++) {
analysis->offsets[i].advanceOffset = run->glyphOffsets[i].advanceOffset * ppdip;
analysis->offsets[i].ascenderOffset = run->glyphOffsets[i].ascenderOffset * ppdip;
}
}
}
*ret = &analysis->IDWriteGlyphRunAnalysis_iface;
return S_OK;

View File

@ -3497,11 +3497,11 @@ static void test_CreateGlyphRunAnalysis(void)
DWRITE_GLYPH_RUN run;
IDWriteFontFace *face;
UINT16 glyph, glyphs[10];
FLOAT advance;
FLOAT advances[2];
HRESULT hr;
UINT32 ch;
RECT rect, rect2;
DWRITE_GLYPH_OFFSET offset;
DWRITE_GLYPH_OFFSET offsets[2];
DWRITE_GLYPH_METRICS metrics;
DWRITE_FONT_METRICS fm;
int i;
@ -3517,17 +3517,17 @@ static void test_CreateGlyphRunAnalysis(void)
hr = IDWriteFontFace_GetDesignGlyphMetrics(face, &glyph, 1, &metrics, FALSE);
ok(hr == S_OK, "got 0x%08x\n", hr);
advance = metrics.advanceWidth;
advances[0] = metrics.advanceWidth;
offset.advanceOffset = 0.0;
offset.ascenderOffset = 0.0;
offsets[0].advanceOffset = 0.0;
offsets[0].ascenderOffset = 0.0;
run.fontFace = face;
run.fontEmSize = 24.0;
run.glyphCount = 1;
run.glyphIndices = &glyph;
run.glyphAdvances = &advance;
run.glyphOffsets = &offset;
run.glyphAdvances = advances;
run.glyphOffsets = offsets;
run.isSideways = FALSE;
run.bidiLevel = 0;
@ -3680,7 +3680,7 @@ static void test_CreateGlyphRunAnalysis(void)
run.fontEmSize = 24.0;
run.glyphCount = 1;
run.glyphIndices = &glyph;
run.glyphAdvances = &advance;
run.glyphAdvances = advances;
run.glyphOffsets = NULL;
run.isSideways = FALSE;
run.bidiLevel = 0;
@ -3719,12 +3719,14 @@ static void test_CreateGlyphRunAnalysis(void)
IDWriteGlyphRunAnalysis_Release(analysis);
/* test that advances are scaled according to ppdip too */
glyphs[0] = glyphs[1] = glyph;
advances[0] = advances[1] = 100.0f;
run.fontFace = face;
run.fontEmSize = 24.0;
run.glyphCount = 2;
run.glyphIndices = glyphs;
run.glyphAdvances = NULL;
run.glyphAdvances = advances;
run.glyphOffsets = NULL;
run.isSideways = FALSE;
run.bidiLevel = 0;
@ -3739,7 +3741,18 @@ static void test_CreateGlyphRunAnalysis(void)
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(!IsRectEmpty(&rect2), "got empty bounds\n");
ok(!EqualRect(&rect, &rect2), "got wrong rect2\n");
ok((rect2.right - rect.left) > advances[0], "got rect width %d for advance %f\n", rect.right - rect.left, advances[0]);
IDWriteGlyphRunAnalysis_Release(analysis);
hr = IDWriteFactory_CreateGlyphRunAnalysis(factory, &run, 2.0, NULL,
DWRITE_RENDERING_MODE_ALIASED, DWRITE_MEASURING_MODE_NATURAL,
0.0, 0.0, &analysis);
ok(hr == S_OK, "got 0x%08x\n", hr);
SetRectEmpty(&rect);
hr = IDWriteGlyphRunAnalysis_GetAlphaTextureBounds(analysis, DWRITE_TEXTURE_ALIASED_1x1, &rect);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok((rect.right - rect.left) > 2 * advances[0], "got rect width %d for advance %f\n", rect.right - rect.left, advances[0]);
IDWriteGlyphRunAnalysis_Release(analysis);
IDWriteFontFace_Release(face);