From 50bf5fca3470396d8a490abc3d87ffa9c33167d2 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 6 Jul 2015 23:08:37 +0300 Subject: [PATCH] dwrite: Implement GetPanose(). --- dlls/dwrite/dwrite_private.h | 10 ++++++-- dlls/dwrite/font.c | 12 +++++++-- dlls/dwrite/gdiinterop.c | 10 +++----- dlls/dwrite/opentype.c | 19 ++++++++------ dlls/dwrite/tests/font.c | 50 ++++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 18 deletions(-) diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index 34f67f012df..3619e530cd7 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -125,11 +125,17 @@ extern BOOL is_face_type_supported(DWRITE_FONT_FACE_TYPE) DECLSPEC_HIDDEN; extern HRESULT get_family_names_from_stream(IDWriteFontFileStream*,UINT32,DWRITE_FONT_FACE_TYPE,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; /* Opentype font table functions */ +struct dwrite_font_props { + DWRITE_FONT_STYLE style; + DWRITE_FONT_STRETCH stretch; + DWRITE_FONT_WEIGHT weight; + DWRITE_PANOSE panose; +}; + extern HRESULT opentype_analyze_font(IDWriteFontFileStream*,UINT32*,DWRITE_FONT_FILE_TYPE*,DWRITE_FONT_FACE_TYPE*,BOOL*) DECLSPEC_HIDDEN; extern HRESULT opentype_get_font_table(IDWriteFontFileStream*,DWRITE_FONT_FACE_TYPE,UINT32,UINT32,const void**,void**,UINT32*,BOOL*) DECLSPEC_HIDDEN; extern HRESULT opentype_cmap_get_unicode_ranges(void*,UINT32,DWRITE_UNICODE_RANGE*,UINT32*) DECLSPEC_HIDDEN; -extern void opentype_get_font_properties(IDWriteFontFileStream*,DWRITE_FONT_FACE_TYPE,UINT32,DWRITE_FONT_STRETCH*, - DWRITE_FONT_WEIGHT*,DWRITE_FONT_STYLE*) DECLSPEC_HIDDEN; +extern void opentype_get_font_properties(IDWriteFontFileStream*,DWRITE_FONT_FACE_TYPE,UINT32,struct dwrite_font_props*) DECLSPEC_HIDDEN; extern void opentype_get_font_metrics(IDWriteFontFileStream*,DWRITE_FONT_FACE_TYPE,UINT32,DWRITE_FONT_METRICS1*,DWRITE_CARET_METRICS*) DECLSPEC_HIDDEN; extern HRESULT opentype_get_font_strings_from_id(const void*,DWRITE_INFORMATIONAL_STRING_ID,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; extern HRESULT opentype_get_typographic_features(IDWriteFontFace*,UINT32,UINT32,UINT32,UINT32*,DWRITE_FONT_FEATURE_TAG*) DECLSPEC_HIDDEN; diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 20918678607..d9b65219252 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -39,6 +39,7 @@ struct dwrite_font_data { DWRITE_FONT_STYLE style; DWRITE_FONT_STRETCH stretch; DWRITE_FONT_WEIGHT weight; + DWRITE_PANOSE panose; DWRITE_FONT_METRICS1 metrics; IDWriteLocalizedStrings *info_strings[DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME+1]; @@ -1094,7 +1095,8 @@ static void WINAPI dwritefont1_GetMetrics(IDWriteFont2 *iface, DWRITE_FONT_METRI static void WINAPI dwritefont1_GetPanose(IDWriteFont2 *iface, DWRITE_PANOSE *panose) { struct dwrite_font *This = impl_from_IDWriteFont2(iface); - FIXME("(%p)->(%p): stub\n", This, panose); + TRACE("(%p)->(%p)\n", This, panose); + *panose = This->data->panose; } static HRESULT WINAPI dwritefont1_GetUnicodeRanges(IDWriteFont2 *iface, UINT32 max_count, DWRITE_UNICODE_RANGE *ranges, UINT32 *count) @@ -1631,6 +1633,7 @@ static HRESULT init_font_data(IDWriteFactory2 *factory, IDWriteFontFile *file, U { void *os2_context, *head_context; const void *tt_os2 = NULL, *tt_head = NULL; + struct dwrite_font_props props; struct dwrite_font_data *data; HRESULT hr; @@ -1655,9 +1658,14 @@ static HRESULT init_font_data(IDWriteFactory2 *factory, IDWriteFontFile *file, U opentype_get_font_table(*stream, face_type, face_index, MS_OS2_TAG, &tt_os2, &os2_context, NULL, NULL); opentype_get_font_table(*stream, face_type, face_index, MS_HEAD_TAG, &tt_head, &head_context, NULL, NULL); - opentype_get_font_properties(*stream, face_type, face_index, &data->stretch, &data->weight, &data->style); + opentype_get_font_properties(*stream, face_type, face_index, &props); opentype_get_font_metrics(*stream, face_type, face_index, &data->metrics, NULL); + data->style = props.style; + data->stretch = props.stretch; + data->weight = props.weight; + data->panose = props.panose; + if (tt_os2) IDWriteFontFileStream_ReleaseFileFragment(*stream, os2_context); if (tt_head) diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c index 8f91ded815e..83a245aef85 100644 --- a/dlls/dwrite/gdiinterop.c +++ b/dlls/dwrite/gdiinterop.c @@ -411,10 +411,8 @@ static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop *ifa IDWriteLocalizedStrings *familynames; DWRITE_FONT_SIMULATIONS simulations; DWRITE_FONT_FACE_TYPE face_type; + struct dwrite_font_props props; IDWriteFontFileStream *stream; - DWRITE_FONT_STRETCH stretch; - DWRITE_FONT_STYLE style; - DWRITE_FONT_WEIGHT weight; IDWriteFontFile *file = NULL; UINT32 index; BOOL exists; @@ -437,7 +435,7 @@ static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop *ifa index = IDWriteFontFace_GetIndex(fontface); face_type = IDWriteFontFace_GetType(fontface); - opentype_get_font_properties(stream, face_type, index, &stretch, &weight, &style); + opentype_get_font_properties(stream, face_type, index, &props); hr = get_family_names_from_stream(stream, index, face_type, &familynames); IDWriteFontFile_Release(file); IDWriteFontFileStream_Release(stream); @@ -447,8 +445,8 @@ static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop *ifa simulations = IDWriteFontFace_GetSimulations(fontface); logfont->lfCharSet = DEFAULT_CHARSET; - logfont->lfWeight = weight; - logfont->lfItalic = style == DWRITE_FONT_STYLE_ITALIC || (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE); + logfont->lfWeight = props.weight; + logfont->lfItalic = props.style == DWRITE_FONT_STYLE_ITALIC || (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE); logfont->lfOutPrecision = OUT_OUTLINE_PRECIS; logfont->lfFaceName[0] = 0; diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index cbc50907787..3d51e3118ff 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -954,7 +954,7 @@ void opentype_get_font_metrics(IDWriteFontFileStream *stream, DWRITE_FONT_FACE_T } void opentype_get_font_properties(IDWriteFontFileStream *stream, DWRITE_FONT_FACE_TYPE type, UINT32 index, - DWRITE_FONT_STRETCH *stretch, DWRITE_FONT_WEIGHT *weight, DWRITE_FONT_STYLE *style) + struct dwrite_font_props *props) { void *os2_context, *head_context; const TT_OS2_V2 *tt_os2; @@ -964,23 +964,26 @@ void opentype_get_font_properties(IDWriteFontFileStream *stream, DWRITE_FONT_FAC opentype_get_font_table(stream, type, index, MS_HEAD_TAG, (const void**)&tt_head, &head_context, NULL, NULL); /* default stretch, weight and style to normal */ - *stretch = DWRITE_FONT_STRETCH_NORMAL; - *weight = DWRITE_FONT_WEIGHT_NORMAL; - *style = DWRITE_FONT_STYLE_NORMAL; + props->stretch = DWRITE_FONT_STRETCH_NORMAL; + props->weight = DWRITE_FONT_WEIGHT_NORMAL; + props->style = DWRITE_FONT_STYLE_NORMAL; + memset(&props->panose, 0, sizeof(props->panose)); /* DWRITE_FONT_STRETCH enumeration values directly match font data values */ if (tt_os2) { if (GET_BE_WORD(tt_os2->usWidthClass) <= DWRITE_FONT_STRETCH_ULTRA_EXPANDED) - *stretch = GET_BE_WORD(tt_os2->usWidthClass); + props->stretch = GET_BE_WORD(tt_os2->usWidthClass); - *weight = GET_BE_WORD(tt_os2->usWeightClass); - TRACE("stretch=%d, weight=%d\n", *stretch, *weight); + props->weight = GET_BE_WORD(tt_os2->usWeightClass); + memcpy(&props->panose, &tt_os2->panose, sizeof(props->panose)); + + TRACE("stretch=%d, weight=%d\n", props->stretch, props->weight); } if (tt_head) { USHORT macStyle = GET_BE_WORD(tt_head->macStyle); if (macStyle & 0x0002) - *style = DWRITE_FONT_STYLE_ITALIC; + props->style = DWRITE_FONT_STYLE_ITALIC; } if (tt_os2) diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index d3ac83ca7d0..ae25b6ca08b 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -3634,6 +3634,55 @@ static void test_GetGdiCompatibleMetrics(void) IDWriteFactory_Release(factory); } +static void test_GetPanose(void) +{ + IDWriteFactory *factory; + IDWriteFont1 *font1; + IDWriteFont *font; + HRESULT hr; + + factory = create_factory(); + font = get_tahoma_instance(factory, DWRITE_FONT_STYLE_NORMAL); + + hr = IDWriteFont_QueryInterface(font, &IID_IDWriteFont1, (void**)&font1); + IDWriteFont_Release(font); + if (hr == S_OK) { + DWRITE_PANOSE panose; + + if (0) /* crashes on native */ + IDWriteFont1_GetPanose(font1, NULL); + + memset(&panose, 0, sizeof(panose)); + IDWriteFont1_GetPanose(font1, &panose); + ok(panose.familyKind == DWRITE_PANOSE_FAMILY_TEXT_DISPLAY, + "got %u\n", panose.familyKind); + ok(panose.text.serifStyle == DWRITE_PANOSE_SERIF_STYLE_NORMAL_SANS, + "got %u\n", panose.text.serifStyle); + ok(panose.text.weight == DWRITE_PANOSE_WEIGHT_MEDIUM, + "got %u\n", panose.text.weight); + ok(panose.text.proportion == DWRITE_PANOSE_PROPORTION_EVEN_WIDTH, + "got %u\n", panose.text.proportion); + ok(panose.text.contrast == DWRITE_PANOSE_CONTRAST_VERY_LOW, + "got %u\n", panose.text.contrast); + ok(panose.text.strokeVariation == DWRITE_PANOSE_STROKE_VARIATION_GRADUAL_VERTICAL, + "got %u\n", panose.text.strokeVariation); + ok(panose.text.armStyle == DWRITE_PANOSE_ARM_STYLE_STRAIGHT_ARMS_VERTICAL, + "got %u\n", panose.text.armStyle); + ok(panose.text.letterform == DWRITE_PANOSE_LETTERFORM_NORMAL_BOXED, + "got %u\n", panose.text.letterform); + ok(panose.text.midline == DWRITE_PANOSE_MIDLINE_STANDARD_TRIMMED, + "got %u\n", panose.text.midline); + ok(panose.text.xHeight == DWRITE_PANOSE_XHEIGHT_CONSTANT_LARGE, + "got %u\n", panose.text.xHeight); + + IDWriteFont1_Release(font1); + } + else + win_skip("GetPanose() is not supported.\n"); + + IDWriteFactory_Release(factory); +} + START_TEST(font) { IDWriteFactory *factory; @@ -3678,6 +3727,7 @@ START_TEST(font) test_CreateRenderingParams(); test_CreateGlyphRunAnalysis(); test_GetGdiCompatibleMetrics(); + test_GetPanose(); IDWriteFactory_Release(factory); }