static void test_fontfamily_properties (void) { GpFontFamily* FontFamily = NULL; GpStatus stat; UINT16 result = 0; stat = GdipCreateFontFamilyFromName(arial, NULL, &FontFamily); if(stat == FontFamilyNotFound) skip("Arial not installed\n"); else { stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok (result == 2355, "Expected 2355, got %d\n", result); result = 0; stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 2048, "Expected 2048, got %d\n", result); result = 0; stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 1854, "Expected 1854, got %d\n", result); result = 0; stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result); ok(result == 434, "Expected 434, got %d\n", result); GdipDeleteFontFamily(FontFamily); } stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, &FontFamily); if(stat == FontFamilyNotFound) skip("Times New Roman not installed\n"); else { result = 0; stat = GdipGetLineSpacing(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 2355, "Expected 2355, got %d\n", result); result = 0; stat = GdipGetEmHeight(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 2048, "Expected 2048, got %d\n", result); result = 0; stat = GdipGetCellAscent(FontFamily, FontStyleRegular, &result); expect(Ok, stat); ok(result == 1825, "Expected 1825, got %d\n", result); result = 0; stat = GdipGetCellDescent(FontFamily, FontStyleRegular, &result); ok(result == 443, "Expected 443 got %d\n", result); GdipDeleteFontFamily(FontFamily); } }
static void gdip_get_font_metrics(GpFont *font, struct font_metrics *fm) { INT style; GpFontFamily *family; GpStatus stat; stat = GdipGetFontStyle(font, &style); expect(Ok, stat); stat = GdipGetFontHeight(font, NULL, &fm->font_height); expect(Ok, stat); stat = GdipGetFontSize(font, &fm->font_size); expect(Ok, stat); fm->lfHeight = (INT)(fm->font_size * -1.0); stat = GdipGetFamily(font, &family); expect(Ok, stat); stat = GdipGetEmHeight(family, style, &fm->em_height); expect(Ok, stat); stat = GdipGetLineSpacing(family, style, &fm->line_spacing); expect(Ok, stat); stat = GdipGetCellAscent(family, style, &fm->ascent); expect(Ok, stat); stat = GdipGetCellDescent(family, style, &fm->descent); expect(Ok, stat); GdipDeleteFontFamily(family); }
/******************************************************************************* * GdipGetFontHeightGivenDPI [GDIPLUS.@] * PARAMS * font [I] Font to retrieve DPI from * dpi [I] DPI to assume * height [O] Return value * * RETURNS * SUCCESS: Ok * FAILURE: InvalidParameter if font or height is NULL * * NOTES * According to MSDN, the result is (lineSpacing)*(fontSize / emHeight)*dpi * (for anything other than unit Pixel) */ GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi, REAL *height) { GpStatus stat; INT style; UINT16 line_spacing, em_height; REAL font_size; if (!font || !height) return InvalidParameter; TRACE("%p (%s), %f, %p\n", font, debugstr_w(font->family->FamilyName), dpi, height); font_size = units_to_pixels(get_font_size(font), font->unit, dpi); style = get_font_style(font); stat = GdipGetLineSpacing(font->family, style, &line_spacing); if (stat != Ok) return stat; stat = GdipGetEmHeight(font->family, style, &em_height); if (stat != Ok) return stat; *height = (REAL)line_spacing * font_size / (REAL)em_height; TRACE("%s,%d => %f\n", debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, *height); return Ok; }
/******************************************************************************* * GdipGetFontHeightGivenDPI [GDIPLUS.@] * PARAMS * font [I] Font to retrieve DPI from * dpi [I] DPI to assume * height [O] Return value * * RETURNS * SUCCESS: Ok * FAILURE: InvalidParameter if font or height is NULL * * NOTES * According to MSDN, the result is (lineSpacing)*(fontSize / emHeight)*dpi * (for anything other than unit Pixel) */ GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi, REAL *height) { GpStatus stat; INT style; UINT16 line_spacing, em_height; REAL font_height, font_size; if (!font || !height) return InvalidParameter; TRACE("%p (%s), %f, %p\n", font, debugstr_w(font->family->FamilyName), dpi, height); font_size = get_font_size(font); style = get_font_style(font); stat = GdipGetLineSpacing(font->family, style, &line_spacing); if (stat != Ok) return stat; stat = GdipGetEmHeight(font->family, style, &em_height); if (stat != Ok) return stat; font_height = (REAL)line_spacing * font_size / (REAL)em_height; switch (font->unit) { case UnitPixel: case UnitWorld: *height = font_height; break; case UnitPoint: *height = font_height * dpi * inch_per_point; break; case UnitInch: *height = font_height * dpi; break; case UnitDocument: *height = font_height * (dpi / 300.0); break; case UnitMillimeter: *height = font_height * (dpi / mm_per_inch); break; default: FIXME("Unhandled unit type: %d\n", font->unit); return NotImplemented; } TRACE("%s,%d(unit %d) => %f\n", debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, font->unit, *height); return Ok; }
static GF_Err gdip_get_font_info(GF_FontReader *dr, char **font_name, s32 *em_size, s32 *ascent, s32 *descent, s32 *underline, s32 *line_spacing, s32 *max_advance_h, s32 *max_advance_v) { UINT16 val, em; FontPriv *ctx = (FontPriv *)dr->udta; *font_name = NULL; *em_size = *ascent = *descent = *line_spacing = *max_advance_h = *max_advance_v = 0; if (!ctx->font) return GF_BAD_PARAM; GdipGetEmHeight(ctx->font, ctx->font_style, &em); *em_size = (s32) em; GdipGetCellAscent(ctx->font, ctx->font_style, &val); ctx->ascent = (Float) val; *ascent = (s32) val; GdipGetCellDescent(ctx->font, ctx->font_style, &val); *descent = (s32) val; *descent *= -1; ctx->descent = -1 * (Float) val; *underline = *descent / 2; GdipGetLineSpacing(ctx->font, ctx->font_style, &val); *line_spacing = (s32) val; *max_advance_v = *ascent - *descent; unsigned short test_str[4]; Fixed w, h, w2; ctx->em_size = (Float) *em_size; test_str[0] = (unsigned short) '_'; test_str[1] = (unsigned short) '\0'; gdip_get_text_size(dr, test_str, &w, &h); ctx->underscore_width = FIX2FLT(w); test_str[0] = (unsigned short) '_'; test_str[1] = (unsigned short) ' '; test_str[2] = (unsigned short) '_'; test_str[3] = (unsigned short) '\0'; gdip_get_text_size(dr, test_str, &w2, &h); ctx->whitespace_width = FIX2FLT(w2 - 2*w); *max_advance_h = (s32) MAX(ctx->underscore_width, ctx->whitespace_width); return GF_OK; }
static M4Err gdip_get_font_metrics(FontRaster *dr, Float *ascent, Float *descent, Float *lineSpacing) { UINT16 val, em; FontPriv *ctx = (FontPriv *)dr->priv; *ascent = *descent = *lineSpacing = 0.0; if (!ctx->font) return M4BadParam; GdipGetEmHeight(ctx->font, ctx->font_style, &em); GdipGetCellAscent(ctx->font, ctx->font_style, &val); *ascent = ctx->font_size * val; *ascent /= em; GdipGetCellDescent(ctx->font, ctx->font_style, &val); *descent = ctx->font_size * val; *descent /= em; GdipGetLineSpacing(ctx->font, ctx->font_style, &val); *lineSpacing = ctx->font_size * val; *lineSpacing /= em; return M4OK; }
static void test_logfont(void) { LOGFONTA lfa, lfa2; GpFont *font; GpFontFamily *family; GpStatus stat; GpGraphics *graphics; HDC hdc = GetDC(0); INT style; REAL rval; UINT16 em_height, line_spacing; Unit unit; GdipCreateFromHDC(hdc, &graphics); memset(&lfa, 0, sizeof(LOGFONTA)); memset(&lfa2, 0xff, sizeof(LOGFONTA)); lstrcpyA(lfa.lfFaceName, "Tahoma"); stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font); expect(Ok, stat); stat = GdipGetLogFontA(font, graphics, &lfa2); expect(Ok, stat); ok(lfa2.lfHeight < 0, "Expected negative height\n"); expect(0, lfa2.lfWidth); expect(0, lfa2.lfEscapement); expect(0, lfa2.lfOrientation); ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n"); expect(0, lfa2.lfItalic); expect(0, lfa2.lfUnderline); expect(0, lfa2.lfStrikeOut); ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET, "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet); expect(0, lfa2.lfOutPrecision); expect(0, lfa2.lfClipPrecision); expect(0, lfa2.lfQuality); expect(0, lfa2.lfPitchAndFamily); GdipDeleteFont(font); memset(&lfa, 0, sizeof(LOGFONTA)); lfa.lfHeight = 25; lfa.lfWidth = 25; lfa.lfEscapement = lfa.lfOrientation = 50; lfa.lfItalic = lfa.lfUnderline = lfa.lfStrikeOut = TRUE; memset(&lfa2, 0xff, sizeof(LOGFONTA)); lstrcpyA(lfa.lfFaceName, "Tahoma"); stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font); expect(Ok, stat); stat = GdipGetLogFontA(font, graphics, &lfa2); expect(Ok, stat); ok(lfa2.lfHeight < 0, "Expected negative height\n"); expect(0, lfa2.lfWidth); expect(0, lfa2.lfEscapement); expect(0, lfa2.lfOrientation); ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n"); expect(TRUE, lfa2.lfItalic); expect(TRUE, lfa2.lfUnderline); expect(TRUE, lfa2.lfStrikeOut); ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET, "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet); expect(0, lfa2.lfOutPrecision); expect(0, lfa2.lfClipPrecision); expect(0, lfa2.lfQuality); expect(0, lfa2.lfPitchAndFamily); stat = GdipGetFontStyle(font, &style); expect(Ok, stat); ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout), "Expected , got %d\n", style); stat = GdipGetFontUnit(font, &unit); expect(Ok, stat); expect(UnitWorld, unit); stat = GdipGetFontHeight(font, graphics, &rval); expect(Ok, stat); expectf(25.347656, rval); stat = GdipGetFontSize(font, &rval); expect(Ok, stat); expectf(21.0, rval); stat = GdipGetFamily(font, &family); expect(Ok, stat); stat = GdipGetEmHeight(family, FontStyleRegular, &em_height); expect(Ok, stat); expect(2048, em_height); stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing); expect(Ok, stat); expect(2472, line_spacing); GdipDeleteFontFamily(family); GdipDeleteFont(font); memset(&lfa, 0, sizeof(lfa)); lfa.lfHeight = -25; lstrcpyA(lfa.lfFaceName, "Tahoma"); stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font); expect(Ok, stat); memset(&lfa2, 0xff, sizeof(lfa2)); stat = GdipGetLogFontA(font, graphics, &lfa2); expect(Ok, stat); expect(lfa.lfHeight, lfa2.lfHeight); stat = GdipGetFontUnit(font, &unit); expect(Ok, stat); expect(UnitWorld, unit); stat = GdipGetFontHeight(font, graphics, &rval); expect(Ok, stat); expectf(30.175781, rval); stat = GdipGetFontSize(font, &rval); expect(Ok, stat); expectf(25.0, rval); stat = GdipGetFamily(font, &family); expect(Ok, stat); stat = GdipGetEmHeight(family, FontStyleRegular, &em_height); expect(Ok, stat); expect(2048, em_height); stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing); expect(Ok, stat); expect(2472, line_spacing); GdipDeleteFontFamily(family); GdipDeleteFont(font); GdipDeleteGraphics(graphics); ReleaseDC(0, hdc); }