static void pango_cairo_win32_font_done_font (PangoFont *font) { cairo_scaled_font_t *scaled_font = pango_cairo_win32_font_get_scaled_font (PANGO_CAIRO_FONT (font)); cairo_win32_scaled_font_done_font (scaled_font); }
float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { if (m_platformData.useGDI()) return widthForGDIGlyph(glyph); if (!m_platformData.size()) return 0; HDC hdc = GetDC(0); SaveDC(hdc); cairo_scaled_font_t* scaledFont = m_platformData.scaledFont(); cairo_win32_scaled_font_select_font(scaledFont, hdc); int width; GetCharWidthI(hdc, glyph, 1, 0, &width); cairo_win32_scaled_font_done_font(scaledFont); RestoreDC(hdc, -1); ReleaseDC(0, hdc); const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_platformData.size(); return width * metricsMultiplier; }
static PangoFontMetrics * create_metrics_for_context (PangoFont *font, PangoContext *context) { PangoCairoWin32Font *cwfont = PANGO_CAIRO_WIN32_FONT (font); PangoFontMetrics *metrics; PangoFontDescription *font_desc; PangoLayout *layout; PangoRectangle extents; PangoLanguage *language = pango_context_get_language (context); const char *sample_str = pango_language_get_sample_string (language); cairo_scaled_font_t *scaled_font; cairo_font_extents_t font_extents; double height; metrics = pango_font_metrics_new (); scaled_font = pango_cairo_win32_font_get_scaled_font (PANGO_CAIRO_FONT (cwfont)); cairo_scaled_font_extents (scaled_font, &font_extents); cairo_win32_scaled_font_done_font (scaled_font); metrics->ascent = font_extents.ascent * PANGO_SCALE; metrics->descent = font_extents.descent * PANGO_SCALE; /* FIXME: Should get the real settings for these from the TrueType * font file. */ height = metrics->ascent + metrics->descent; metrics->underline_thickness = height / 14; metrics->underline_position = - metrics->underline_thickness; metrics->strikethrough_thickness = metrics->underline_thickness; metrics->strikethrough_position = height / 4; pango_quantize_line_geometry (&metrics->underline_thickness, &metrics->underline_position); pango_quantize_line_geometry (&metrics->strikethrough_thickness, &metrics->strikethrough_position); layout = pango_layout_new (context); font_desc = pango_font_describe_with_absolute_size (font); pango_layout_set_font_description (layout, font_desc); pango_layout_set_text (layout, sample_str, -1); pango_layout_get_extents (layout, NULL, &extents); metrics->approximate_char_width = extents.width / g_utf8_strlen (sample_str, -1); pango_layout_set_text (layout, "0123456789", -1); metrics->approximate_digit_width = max_glyph_width (layout); pango_font_description_free (font_desc); g_object_unref (layout); return metrics; }
void SimpleFontData::platformInit() { m_scriptCache = 0; m_scriptFontProperties = 0; m_isSystemFont = false; m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f; if (m_platformData.useGDI()) return initGDIFont(); HDC hdc = GetDC(0); SaveDC(hdc); cairo_scaled_font_t* scaledFont = m_platformData.scaledFont(); const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_platformData.size(); cairo_win32_scaled_font_select_font(scaledFont, hdc); TEXTMETRIC textMetrics; GetTextMetrics(hdc, &textMetrics); float ascent = textMetrics.tmAscent * metricsMultiplier; float descent = textMetrics.tmDescent * metricsMultiplier; float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts. float lineGap = textMetrics.tmExternalLeading * metricsMultiplier; m_fontMetrics.setAscent(ascent); m_fontMetrics.setDescent(descent); m_fontMetrics.setLineGap(lineGap); m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap)); m_avgCharWidth = textMetrics.tmAveCharWidth * metricsMultiplier; m_maxCharWidth = textMetrics.tmMaxCharWidth * metricsMultiplier; OUTLINETEXTMETRIC metrics; if (GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics) > 0) { // This is a TrueType font. We might be able to get an accurate xHeight GLYPHMETRICS gm; MAT2 mat = { 1, 0, 0, 1 }; DWORD len = GetGlyphOutline(hdc, 'x', GGO_METRICS, &gm, 0, 0, &mat); if (len != GDI_ERROR && gm.gmptGlyphOrigin.y > 0) xHeight = gm.gmptGlyphOrigin.y * metricsMultiplier; } m_fontMetrics.setXHeight(xHeight); cairo_win32_scaled_font_done_font(scaledFont); m_isSystemFont = false; m_scriptCache = 0; m_scriptFontProperties = 0; RestoreDC(hdc, -1); ReleaseDC(0, hdc); }
void Font::platformInit() { m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f; m_scriptCache = 0; m_scriptFontProperties = 0; m_isSystemFont = false; if (m_platformData.useGDI()) return initGDIFont(); if (!m_platformData.size()) { m_fontMetrics.reset(); m_avgCharWidth = 0; m_maxCharWidth = 0; m_isSystemFont = false; m_scriptCache = 0; m_scriptFontProperties = 0; return; } HWndDC dc(0); SaveDC(dc); cairo_scaled_font_t* scaledFont = m_platformData.scaledFont(); const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_platformData.size(); cairo_win32_scaled_font_select_font(scaledFont, dc); TEXTMETRIC textMetrics; GetTextMetrics(dc, &textMetrics); float ascent = textMetrics.tmAscent * metricsMultiplier; float descent = textMetrics.tmDescent * metricsMultiplier; float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts. float lineGap = textMetrics.tmExternalLeading * metricsMultiplier; int faceLength = ::GetTextFace(dc, 0, 0); Vector<WCHAR> faceName(faceLength); ::GetTextFace(dc, faceLength, faceName.data()); m_isSystemFont = !wcscmp(faceName.data(), L"Lucida Grande"); ascent = ascentConsideringMacAscentHack(faceName.data(), ascent, descent); m_fontMetrics.setAscent(ascent); m_fontMetrics.setDescent(descent); m_fontMetrics.setLineGap(lineGap); m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap)); m_avgCharWidth = textMetrics.tmAveCharWidth * metricsMultiplier; m_maxCharWidth = textMetrics.tmMaxCharWidth * metricsMultiplier; cairo_text_extents_t extents; cairo_scaled_font_text_extents(scaledFont, "x", &extents); xHeight = -extents.y_bearing; m_fontMetrics.setXHeight(xHeight); cairo_win32_scaled_font_done_font(scaledFont); m_scriptCache = 0; m_scriptFontProperties = 0; RestoreDC(dc, -1); }