remove some duplication in font scaling code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett 2007-12-17 07:05:35 +00:00
parent f7732fa59a
commit 46142dc952

View File

@ -1559,71 +1559,51 @@ void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
pango_attr_list_unref(attrs); pango_attr_list_unref(attrs);
} }
int w,h; int oldSize = 0;
const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
if (fabs(m_scaleY - 1.0) > 0.00001) if (isScaled)
{ {
// If there is a user or actually any scale applied to // If there is a user or actually any scale applied to
// the device context, scale the font. // the device context, scale the font.
// scale font description // scale font description
gint oldSize = pango_font_description_get_size( m_fontdesc ); oldSize = pango_font_description_get_size(m_fontdesc);
double size = oldSize; pango_font_description_set_size(m_fontdesc, int(oldSize * m_scaleY));
size = size * m_scaleY;
pango_font_description_set_size( m_fontdesc, (gint)size );
// actually apply scaled font // actually apply scaled font
pango_layout_set_font_description( m_layout, m_fontdesc ); pango_layout_set_font_description( m_layout, m_fontdesc );
}
int w, h;
pango_layout_get_pixel_size(m_layout, &w, &h); pango_layout_get_pixel_size(m_layout, &w, &h);
if (m_backgroundMode == wxSOLID) if (m_backgroundMode == wxSOLID)
{ {
gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
gdk_draw_rectangle(m_gdkwindow, m_textGC, TRUE, x, y, w, h); gdk_draw_rectangle(m_gdkwindow, m_textGC, true, x, y, w, h);
gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
} }
// Draw layout. // Draw layout.
int x_rtl = x;
if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft)
gdk_draw_layout( m_gdkwindow, m_textGC, x-w, y, m_layout ); x_rtl -= w;
else gdk_draw_layout(m_gdkwindow, m_textGC, x_rtl, y, m_layout);
gdk_draw_layout( m_gdkwindow, m_textGC, x, y, m_layout );
if (isScaled)
{
// reset unscaled size // reset unscaled size
pango_font_description_set_size( m_fontdesc, oldSize ); pango_font_description_set_size( m_fontdesc, oldSize );
// actually apply unscaled font // actually apply unscaled font
pango_layout_set_font_description( m_layout, m_fontdesc ); pango_layout_set_font_description( m_layout, m_fontdesc );
} }
else
{
pango_layout_get_pixel_size( m_layout, &w, &h );
if ( m_backgroundMode == wxSOLID )
{
gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
gdk_draw_rectangle(m_gdkwindow, m_textGC, TRUE, x, y, w, h);
gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
}
// Draw layout.
if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft)
gdk_draw_layout( m_gdkwindow, m_textGC, x-w, y, m_layout );
else
gdk_draw_layout( m_gdkwindow, m_textGC, x, y, m_layout );
}
if (underlined) if (underlined)
{ {
// undo underline attributes setting: // undo underline attributes setting:
pango_layout_set_attributes(m_layout, NULL); pango_layout_set_attributes(m_layout, NULL);
} }
wxCoord width = w; CalcBoundingBox(x + int(w / m_scaleX), y + int(h / m_scaleY));
wxCoord height = h;
width = wxCoord(width / m_scaleX);
height = wxCoord(height / m_scaleY);
CalcBoundingBox (x + width, y + height);
CalcBoundingBox(x, y); CalcBoundingBox(x, y);
} }