dwrite: Implement GetMetrics() for DWRITE_FONT_METRICS1.

This commit is contained in:
Nikolay Sivov 2014-11-06 11:49:06 +03:00 committed by Alexandre Julliard
parent 0f93668637
commit 6ce8cc149e
5 changed files with 96 additions and 14 deletions

View File

@ -114,7 +114,7 @@ extern HRESULT opentype_get_font_table(IDWriteFontFileStream*,DWRITE_FONT_FACE_T
extern void opentype_cmap_get_glyphindex(void*,UINT32,UINT16*) DECLSPEC_HIDDEN;
extern HRESULT opentype_cmap_get_unicode_ranges(void*,UINT32,DWRITE_UNICODE_RANGE*,UINT32*) DECLSPEC_HIDDEN;
extern void opentype_get_font_properties(const void*,const void*,DWRITE_FONT_STRETCH*,DWRITE_FONT_WEIGHT*,DWRITE_FONT_STYLE*) DECLSPEC_HIDDEN;
extern void opentype_get_font_metrics(const void*,const void*,const void*,DWRITE_FONT_METRICS*) DECLSPEC_HIDDEN;
extern void opentype_get_font_metrics(const void*,const void*,const void*,DWRITE_FONT_METRICS1*) DECLSPEC_HIDDEN;
extern HRESULT opentype_get_font_strings_from_id(const void*,DWRITE_INFORMATIONAL_STRING_ID,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN;
extern HRESULT bidi_computelevels(const WCHAR*,UINT32,UINT8,UINT8*,UINT8*) DECLSPEC_HIDDEN;

View File

@ -37,7 +37,7 @@ struct dwrite_font_data {
DWRITE_FONT_STYLE style;
DWRITE_FONT_STRETCH stretch;
DWRITE_FONT_WEIGHT weight;
DWRITE_FONT_METRICS metrics;
DWRITE_FONT_METRICS1 metrics;
IDWriteLocalizedStrings *info_strings[DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME+1];
/* data needed to create fontface instance */
@ -112,7 +112,7 @@ struct dwrite_fontface {
USHORT simulations;
DWRITE_FONT_FACE_TYPE type;
DWRITE_FONT_METRICS metrics;
DWRITE_FONT_METRICS1 metrics;
struct dwrite_fonttable cmap;
};
@ -315,7 +315,7 @@ static void WINAPI dwritefontface_GetMetrics(IDWriteFontFace2 *iface, DWRITE_FON
{
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
TRACE("(%p)->(%p)\n", This, metrics);
*metrics = This->metrics;
memcpy(metrics, &This->metrics, sizeof(*metrics));
}
static UINT16 WINAPI dwritefontface_GetGlyphCount(IDWriteFontFace2 *iface)
@ -433,11 +433,11 @@ static HRESULT WINAPI dwritefontface_GetGdiCompatibleGlyphMetrics(IDWriteFontFac
return E_NOTIMPL;
}
static HRESULT WINAPI dwritefontface1_GetMetrics(IDWriteFontFace2 *iface, DWRITE_FONT_METRICS1 *metrics)
static void WINAPI dwritefontface1_GetMetrics(IDWriteFontFace2 *iface, DWRITE_FONT_METRICS1 *metrics)
{
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
FIXME("(%p)->(%p): stub\n", This, metrics);
return E_NOTIMPL;
TRACE("(%p)->(%p)\n", This, metrics);
*metrics = This->metrics;
}
static HRESULT WINAPI dwritefontface1_GetGdiCompatibleMetrics(IDWriteFontFace2 *iface, FLOAT em_size, FLOAT pixels_per_dip,
@ -612,7 +612,7 @@ static const IDWriteFontFace2Vtbl dwritefontfacevtbl = {
};
static void get_font_properties_from_stream(IDWriteFontFileStream *stream, DWRITE_FONT_FACE_TYPE face_type,
UINT32 face_index, DWRITE_FONT_METRICS *metrics, DWRITE_FONT_STRETCH *stretch, DWRITE_FONT_WEIGHT *weight,
UINT32 face_index, DWRITE_FONT_METRICS1 *metrics, DWRITE_FONT_STRETCH *stretch, DWRITE_FONT_WEIGHT *weight,
DWRITE_FONT_STYLE *style)
{
const void *tt_os2 = NULL, *tt_head = NULL, *tt_post = NULL;
@ -645,7 +645,7 @@ HRESULT convert_fontface_to_logfont(IDWriteFontFace *face, LOGFONTW *logfont)
DWRITE_FONT_SIMULATIONS simulations;
DWRITE_FONT_FACE_TYPE face_type;
IDWriteFontFileStream *stream;
DWRITE_FONT_METRICS metrics;
DWRITE_FONT_METRICS1 metrics;
DWRITE_FONT_STRETCH stretch;
DWRITE_FONT_STYLE style;
DWRITE_FONT_WEIGHT weight;
@ -893,7 +893,7 @@ static void WINAPI dwritefont_GetMetrics(IDWriteFont2 *iface, DWRITE_FONT_METRIC
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
TRACE("(%p)->(%p)\n", This, metrics);
*metrics = This->data->metrics;
memcpy(metrics, &This->data->metrics, sizeof(*metrics));
}
static HRESULT WINAPI dwritefont_HasCharacter(IDWriteFont2 *iface, UINT32 value, BOOL *exists)
@ -937,7 +937,8 @@ static HRESULT WINAPI dwritefont_CreateFontFace(IDWriteFont2 *iface, IDWriteFont
static void WINAPI dwritefont1_GetMetrics(IDWriteFont2 *iface, DWRITE_FONT_METRICS1 *metrics)
{
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
FIXME("(%p)->(%p): stub\n", This, metrics);
TRACE("(%p)->(%p)\n", This, metrics);
*metrics = This->data->metrics;
}
static void WINAPI dwritefont1_GetPanose(IDWriteFont2 *iface, DWRITE_PANOSE *panose)

View File

@ -858,7 +858,7 @@ HRESULT opentype_cmap_get_unicode_ranges(void *data, UINT32 max_count, DWRITE_UN
return *count > max_count ? E_NOT_SUFFICIENT_BUFFER : S_OK;
}
void opentype_get_font_metrics(const void *os2, const void *head, const void *post, DWRITE_FONT_METRICS *metrics)
void opentype_get_font_metrics(const void *os2, const void *head, const void *post, DWRITE_FONT_METRICS1 *metrics)
{
TT_OS2_V2 *tt_os2 = (TT_OS2_V2*)os2;
TT_HEAD *tt_head = (TT_HEAD*)head;
@ -874,10 +874,24 @@ void opentype_get_font_metrics(const void *os2, const void *head, const void *po
metrics->xHeight = GET_BE_WORD(tt_os2->sxHeight);
metrics->strikethroughPosition = GET_BE_WORD(tt_os2->yStrikeoutPosition);
metrics->strikethroughThickness = GET_BE_WORD(tt_os2->yStrikeoutSize);
metrics->subscriptPositionX = GET_BE_WORD(tt_os2->ySubscriptXOffset);
/* Y offset is stored as positive offset below baseline */
metrics->subscriptPositionY = -GET_BE_WORD(tt_os2->ySubscriptYOffset);
metrics->subscriptSizeX = GET_BE_WORD(tt_os2->ySubscriptXSize);
metrics->subscriptSizeY = GET_BE_WORD(tt_os2->ySubscriptYSize);
metrics->superscriptPositionX = GET_BE_WORD(tt_os2->ySuperscriptXOffset);
metrics->superscriptPositionY = GET_BE_WORD(tt_os2->ySuperscriptYOffset);
metrics->superscriptSizeX = GET_BE_WORD(tt_os2->ySuperscriptXSize);
metrics->superscriptSizeY = GET_BE_WORD(tt_os2->ySuperscriptYSize);
}
if (tt_head)
if (tt_head) {
metrics->designUnitsPerEm = GET_BE_WORD(tt_head->unitsPerEm);
metrics->glyphBoxLeft = GET_BE_WORD(tt_head->xMin);
metrics->glyphBoxTop = GET_BE_WORD(tt_head->yMax);
metrics->glyphBoxRight = GET_BE_WORD(tt_head->xMax);
metrics->glyphBoxBottom = GET_BE_WORD(tt_head->yMin);
}
if (tt_post) {
metrics->underlinePosition = GET_BE_WORD(tt_post->underlinePosition);

View File

@ -960,6 +960,7 @@ static void test_GetMetrics(void)
IDWriteFontFace *fontface;
IDWriteFactory *factory;
OUTLINETEXTMETRICW otm;
IDWriteFont1 *font1;
IDWriteFont *font;
LOGFONTW logfont;
HRESULT hr;
@ -1028,6 +1029,72 @@ todo_wine
ok(metrics.strikethroughPosition > 0, "strikethroughPosition %d\n", metrics.strikethroughPosition);
ok(metrics.strikethroughThickness != 0, "strikethroughThickness %u\n", metrics.strikethroughThickness);
hr = IDWriteFont_QueryInterface(font, &IID_IDWriteFont1, (void**)&font1);
if (hr == S_OK) {
DWRITE_FONT_METRICS1 metrics1;
IDWriteFontFace1 *fontface1;
memset(&metrics1, 0, sizeof(metrics1));
IDWriteFont1_GetMetrics(font1, &metrics1);
ok(metrics1.designUnitsPerEm != 0, "designUnitsPerEm %u\n", metrics1.designUnitsPerEm);
ok(metrics1.ascent != 0, "ascent %u\n", metrics1.ascent);
ok(metrics1.descent != 0, "descent %u\n", metrics1.descent);
todo_wine
ok(metrics1.lineGap == 0, "lineGap %d\n", metrics1.lineGap);
ok(metrics1.capHeight, "capHeight %u\n", metrics1.capHeight);
ok(metrics1.xHeight != 0, "xHeight %u\n", metrics1.xHeight);
ok(metrics1.underlinePosition < 0, "underlinePosition %d\n", metrics1.underlinePosition);
ok(metrics1.underlineThickness != 0, "underlineThickness %u\n", metrics1.underlineThickness);
ok(metrics1.strikethroughPosition > 0, "strikethroughPosition %d\n", metrics1.strikethroughPosition);
ok(metrics1.strikethroughThickness != 0, "strikethroughThickness %u\n", metrics1.strikethroughThickness);
ok(metrics1.glyphBoxLeft < 0, "glyphBoxLeft %d\n", metrics1.glyphBoxLeft);
ok(metrics1.glyphBoxTop > 0, "glyphBoxTop %d\n", metrics1.glyphBoxTop);
ok(metrics1.glyphBoxRight > 0, "glyphBoxRight %d\n", metrics1.glyphBoxRight);
ok(metrics1.glyphBoxBottom < 0, "glyphBoxBottom %d\n", metrics1.glyphBoxBottom);
ok(metrics1.subscriptPositionY < 0, "subscriptPositionY %d\n", metrics1.subscriptPositionY);
ok(metrics1.subscriptSizeX > 0, "subscriptSizeX %d\n", metrics1.subscriptSizeX);
ok(metrics1.subscriptSizeY > 0, "subscriptSizeY %d\n", metrics1.subscriptSizeY);
ok(metrics1.superscriptPositionY > 0, "superscriptPositionY %d\n", metrics1.superscriptPositionY);
ok(metrics1.superscriptSizeX > 0, "superscriptSizeX %d\n", metrics1.superscriptSizeX);
ok(metrics1.superscriptSizeY > 0, "superscriptSizeY %d\n", metrics1.superscriptSizeY);
ok(!metrics1.hasTypographicMetrics, "hasTypographicMetrics %d\n", metrics1.hasTypographicMetrics);
hr = IDWriteFontFace_QueryInterface(fontface, &IID_IDWriteFontFace1, (void**)&fontface1);
ok(hr == S_OK, "got 0x%08x\n", hr);
memset(&metrics1, 0, sizeof(metrics1));
IDWriteFontFace1_GetMetrics(fontface1, &metrics1);
ok(metrics1.designUnitsPerEm != 0, "designUnitsPerEm %u\n", metrics1.designUnitsPerEm);
ok(metrics1.ascent != 0, "ascent %u\n", metrics1.ascent);
ok(metrics1.descent != 0, "descent %u\n", metrics1.descent);
todo_wine
ok(metrics1.lineGap == 0, "lineGap %d\n", metrics1.lineGap);
ok(metrics1.capHeight, "capHeight %u\n", metrics1.capHeight);
ok(metrics1.xHeight != 0, "xHeight %u\n", metrics1.xHeight);
ok(metrics1.underlinePosition < 0, "underlinePosition %d\n", metrics1.underlinePosition);
ok(metrics1.underlineThickness != 0, "underlineThickness %u\n", metrics1.underlineThickness);
ok(metrics1.strikethroughPosition > 0, "strikethroughPosition %d\n", metrics1.strikethroughPosition);
ok(metrics1.strikethroughThickness != 0, "strikethroughThickness %u\n", metrics1.strikethroughThickness);
ok(metrics1.glyphBoxLeft < 0, "glyphBoxLeft %d\n", metrics1.glyphBoxLeft);
ok(metrics1.glyphBoxTop > 0, "glyphBoxTop %d\n", metrics1.glyphBoxTop);
ok(metrics1.glyphBoxRight > 0, "glyphBoxRight %d\n", metrics1.glyphBoxRight);
ok(metrics1.glyphBoxBottom < 0, "glyphBoxBottom %d\n", metrics1.glyphBoxBottom);
ok(metrics1.subscriptPositionY < 0, "subscriptPositionY %d\n", metrics1.subscriptPositionY);
ok(metrics1.subscriptSizeX > 0, "subscriptSizeX %d\n", metrics1.subscriptSizeX);
ok(metrics1.subscriptSizeY > 0, "subscriptSizeY %d\n", metrics1.subscriptSizeY);
ok(metrics1.superscriptPositionY > 0, "superscriptPositionY %d\n", metrics1.superscriptPositionY);
ok(metrics1.superscriptSizeX > 0, "superscriptSizeX %d\n", metrics1.superscriptSizeX);
ok(metrics1.superscriptSizeY > 0, "superscriptSizeY %d\n", metrics1.superscriptSizeY);
ok(!metrics1.hasTypographicMetrics, "hasTypographicMetrics %d\n", metrics1.hasTypographicMetrics);
IDWriteFontFace1_Release(fontface1);
IDWriteFont1_Release(font1);
}
else
win_skip("DWRITE_FONT_METRICS1 is not supported.\n");
IDWriteFontFace_Release(fontface);
IDWriteFont_Release(font);

View File

@ -593,7 +593,7 @@ uuid(a71efdb4-9fdb-4838-ad90-cfc3be8c3daf)
]
interface IDWriteFontFace1 : IDWriteFontFace
{
HRESULT GetMetrics(DWRITE_FONT_METRICS1 *metrics);
void GetMetrics(DWRITE_FONT_METRICS1 *metrics);
HRESULT GetGdiCompatibleMetrics(FLOAT em_size,
FLOAT pixels_per_dip,
const DWRITE_MATRIX *transform,