X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ca65c0440a7163e4e37e48b1c4329709d722db47..3c86150dd768b4e490b603227de28aa57275ee4b:/src/generic/dcpsg.cpp diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 8f7d2b07de..b83d33c47e 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -1285,6 +1285,25 @@ void draw_bezier_outline(wxPostScriptDC* caller, #endif + +#if wxUSE_PANGO +static void InitializePangoContext(PangoContext *context) +{ +#ifdef __WXGTK__ + pango_context_set_base_dir(context, + gtk_widget_get_default_direction() == GTK_TEXT_DIR_LTR ? + PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL); + pango_context_set_language(context, gtk_get_default_language()); +#else + // FIXME: assuming LTR is incorrect! + pango_context_set_base_dir(context, PANGO_DIRECTION_LTR); + wxString lang = wxLocale::GetCanonicalName(); + pango_context_set_language(context, + pango_language_from_string(lang::ToAscii())); +#endif +} +#endif + void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) { wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); @@ -1333,13 +1352,12 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) int ps_dpi = 72; int pango_dpi = 600; PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi ); + + InitializePangoContext(context); double scale = (double)pango_dpi / (double)ps_dpi; scale /= m_userScaleY; - pango_context_set_language (context, pango_language_from_string ("en_US")); - pango_context_set_base_dir (context, PANGO_DIRECTION_LTR ); - pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description ); PangoLayout *layout = pango_layout_new (context); @@ -2069,12 +2087,11 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, int pango_dpi = 600; PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi ); + InitializePangoContext(context); + double scale = pango_dpi / wx_dpi; scale /= m_userScaleY; - pango_context_set_language (context, pango_language_from_string ("en_US")); - pango_context_set_base_dir (context, PANGO_DIRECTION_LTR ); - PangoLayout *layout = pango_layout_new (context); PangoFontDescription *desc = fontToUse->GetNativeFontInfo()->description; @@ -2086,17 +2103,18 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); #endif pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); - PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; PangoRectangle rect; - pango_layout_line_get_extents(line, NULL, &rect); + pango_layout_get_extents(layout, NULL, &rect); - if (x) (*x) = (wxCoord) ( rect.width / PANGO_SCALE / scale ); - if (y) (*y) = (wxCoord) ( rect.height / PANGO_SCALE / scale ); + if (x) (*x) = (wxCoord) ( PANGO_PIXELS(rect.width) / scale ); + if (y) (*y) = (wxCoord) ( PANGO_PIXELS(rect.height) / scale ); if (descent) { - // Do something about metrics here - (*descent) = 0; + PangoLayoutIter *iter = pango_layout_get_iter(layout); + int baseline = pango_layout_iter_get_baseline(iter); + pango_layout_iter_free(iter); + *descent = wxCoord(*y - PANGO_PIXELS(baseline) / scale); } if (externalLeading) (*externalLeading) = 0; // ??