X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4f320d7c57daa1cd4bc86cbe1da1ef1619b22edc..bf7470fe143838b3cc928edb5838e78f0670c539:/src/msw/graphics.cpp diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 7e42d37f03..984df21971 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -40,10 +40,10 @@ #include "wx/private/graphics.h" #include "wx/msw/wrapgdip.h" #include "wx/msw/dc.h" -#include "wx/dcgraph.h" #if wxUSE_ENH_METAFILE #include "wx/msw/enhmeta.h" #endif +#include "wx/dcgraph.h" #include "wx/msw/private.h" // needs to be before #include @@ -370,10 +370,10 @@ public: virtual void GetSize( wxDouble* width, wxDouble *height ); Graphics* GetGraphics() const { return m_context; } - bool IsPrinting() const { return m_isPrinting; } - // utility to setup page scale etc for printing - void SetupForPrinting(); +protected: + + wxDouble m_fontScaleRatio; private: void Init(); @@ -385,7 +385,6 @@ private: const wxGraphicsBrush& backgroundBrush); Graphics* m_context; - GraphicsStates m_stateStack; GraphicsState m_state1; GraphicsState m_state2; @@ -393,8 +392,6 @@ private: wxDouble m_width; wxDouble m_height; - bool m_isPrinting; - DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext) }; @@ -414,10 +411,18 @@ public: } private: - HDC m_hdc; + HDC m_hdc ; DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusMeasuringContext) } ; +class wxGDIPlusPrintingContext : public wxGDIPlusContext +{ +public: + wxGDIPlusPrintingContext( wxGraphicsRenderer* renderer, const wxDC& dc ); + virtual ~wxGDIPlusPrintingContext() { } +protected: +}; + //----------------------------------------------------------------------------- // wxGDIPlusRenderer declaration //----------------------------------------------------------------------------- @@ -634,7 +639,13 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p wxBitmap* bmp = pen.GetStipple(); if ( bmp && bmp->Ok() ) { - m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE()); + m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(), +#if wxUSE_PALETTE + (HPALETTE)bmp->GetPalette()->GetHPALETTE() +#else + NULL +#endif + ); m_penBrush = new TextureBrush(m_penImage); m_pen->SetBrush( m_penBrush ); } @@ -737,7 +748,13 @@ wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer , const wxB if ( bmp && bmp->Ok() ) { wxDELETE( m_brushImage ); - m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE()); + m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(), +#if wxUSE_PALETTE + (HPALETTE)bmp->GetPalette()->GetHPALETTE() +#else + NULL +#endif + ); m_brush = new TextureBrush(m_brushImage); } } @@ -839,27 +856,23 @@ wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer* renderer, if ( font.GetWeight() == wxFONTWEIGHT_BOLD ) style |= FontStyleBold; - if ( gc->IsPrinting() ) - { - Graphics* context = gc->GetGraphics(); + Graphics* context = gc->GetGraphics(); - Unit fontUnit = context->GetPageUnit(); - // if fontUnit is UnitDisplay, then specify UnitPixel, otherwise - // you'll get a "InvalidParameter" from GDI+ - if ( fontUnit == UnitDisplay ) - fontUnit = UnitPixel; + Unit fontUnit = context->GetPageUnit(); + // if fontUnit is UnitDisplay, then specify UnitPixel, otherwise + // you'll get a "InvalidParameter" from GDI+ + if ( fontUnit == UnitDisplay ) + fontUnit = UnitPixel; - REAL points = font.GetPointSize(); - REAL size = points * (100.0 / 72.0); + REAL points = font.GetPointSize(); - // NB: font unit should match context's unit. We can use UnitPixel, - // as that is what the print context should use. - m_font = new Font( s, size, style, fontUnit ); - } - else - { - m_font = new Font( s, font.GetPointSize(), style ); - } + // This scaling is needed when we use unit other than the + // default UnitPoint. It works for both display and printing. + REAL size = points * (100.0 / 72.0); + + // NB: font unit should match context's unit. We can use UnitPixel, + // as that is what the print context should use. + m_font = new Font( s, size, style, fontUnit ); m_textBrush = new SolidBrush(wxColourToColor(col)); } @@ -894,7 +907,13 @@ wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, Bitmap* image = NULL; if ( bmp.GetMask() ) { - Bitmap interim((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE()) ; + Bitmap interim((HBITMAP)bmp.GetHBITMAP(), +#if wxUSE_PALETTE + (HPALETTE)bmp.GetPalette()->GetHPALETTE() +#else + NULL +#endif + ); size_t width = interim.GetWidth(); size_t height = interim.GetHeight(); @@ -950,7 +969,13 @@ wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, } else { - image = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE()); + image = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(), +#if wxUSE_PALETTE + (HPALETTE)bmp.GetPalette()->GetHPALETTE() +#else + NULL +#endif + ); if ( bmp.HasAlpha() && GetPixelFormatSize(image->GetPixelFormat()) == 32 ) { size_t width = image->GetWidth(); @@ -1243,15 +1268,13 @@ public : bool m_offset; } ; -wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc, wxDouble width, wxDouble height ) +wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc, wxDouble width, wxDouble height ) : wxGraphicsContext(renderer) { Init(); - - m_context = new Graphics(hdc); + m_context = new Graphics( hdc); m_width = width; m_height = height; - SetDefaults(); } @@ -1302,7 +1325,7 @@ void wxGDIPlusContext::Init() m_state2= 0; m_height = 0; m_width = 0; - m_isPrinting = false; + m_fontScaleRatio = 1.0; } void wxGDIPlusContext::SetDefaults() @@ -1314,21 +1337,6 @@ void wxGDIPlusContext::SetDefaults() m_state2 = m_context->Save(); } -void wxGDIPlusContext::SetupForPrinting() -{ - //m_context->SetPageUnit(UnitDocument); - - // Setup page scale, based on DPI ratio. - // Antecedent should be 100dpi when the default page unit (UnitDisplay) - // is used. Page unit UnitDocument would require 300dpi instead. - // Note that calling SetPageScale() does not have effect on non-printing - // DCs (that is, any other than wxPrinterDC or wxEnhMetaFileDC). - REAL dpiRatio = 100.0 / m_context->GetDpiY(); - m_context->SetPageScale(dpiRatio); - - m_isPrinting = true; -} - wxGDIPlusContext::~wxGDIPlusContext() { if ( m_context ) @@ -1608,7 +1616,6 @@ wxGraphicsFont wxGDIPlusContext::CreateFont( const wxFont &font, return renderer->CreateGDIPlusFont(this, font, col); } - void wxGDIPlusContext::DoDrawFilledText(const wxString& str, wxDouble x, wxDouble y, const wxGraphicsBrush& brush) @@ -1650,12 +1657,7 @@ void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDo f->GetFamily(&ffamily) ; - REAL factorY; - if ( !IsPrinting() ) - factorY = m_context->GetDpiY() / 72.0; - else - // when printing the page scaling already does the trick - factorY = 1.0; + REAL factorY = m_fontScaleRatio; REAL rDescent = ffamily.GetCellDescent(FontStyleRegular) * f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); @@ -1785,6 +1787,32 @@ void wxGDIPlusContext::GetSize( wxDouble* width, wxDouble *height ) *height = m_height; } +//----------------------------------------------------------------------------- +// wxGDIPlusPrintingContext implementation +//----------------------------------------------------------------------------- + +wxGDIPlusPrintingContext::wxGDIPlusPrintingContext( wxGraphicsRenderer* renderer, + const wxDC& dc ) + : wxGDIPlusContext(renderer, dc) +{ + Graphics* context = GetGraphics(); + + //m_context->SetPageUnit(UnitDocument); + + // Setup page scale, based on DPI ratio. + // Antecedent should be 100dpi when the default page unit + // (UnitDisplay) is used. Page unit UnitDocument would require 300dpi + // instead. Note that calling SetPageScale() does not have effect on + // non-printing DCs (that is, any other than wxPrinterDC or + // wxEnhMetaFileDC). + REAL dpiRatio = 100.0 / context->GetDpiY(); + context->SetPageScale(dpiRatio); + + // We use this modifier when measuring fonts. It is needed because the + // page scale is modified above. + m_fontScaleRatio = context->GetDpiY() / 72.0; +} + //----------------------------------------------------------------------------- // wxGDIPlusRenderer implementation //----------------------------------------------------------------------------- @@ -1854,8 +1882,7 @@ wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc) wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc) { ENSURE_LOADED_OR_RETURN(NULL); - wxGDIPlusContext* context = new wxGDIPlusContext(this, dc); - context->SetupForPrinting(); + wxGDIPlusContext* context = new wxGDIPlusPrintingContext(this, dc); return context; } #endif @@ -1864,8 +1891,7 @@ wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc) wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxEnhMetaFileDC& dc) { ENSURE_LOADED_OR_RETURN(NULL); - wxGDIPlusContext* context = new wxGDIPlusContext(this, dc); - context->SetupForPrinting(); + wxGDIPlusContext* context = new wxGDIPlusPrintingContext(this, dc); return context; } #endif