#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 <commdlg.h>
#include "wx/stack.h"
-WX_DECLARE_STACK(GraphicsState, GraphicsStates);
-
namespace
{
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();
const wxGraphicsBrush& backgroundBrush);
Graphics* m_context;
-
- GraphicsStates m_stateStack;
+ wxStack<GraphicsState> m_stateStack;
GraphicsState m_state1;
GraphicsState m_state2;
wxDouble m_width;
wxDouble m_height;
- bool m_isPrinting;
-
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext)
};
}
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
//-----------------------------------------------------------------------------
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 );
}
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);
}
}
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));
}
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();
}
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();
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();
}
m_state2= 0;
m_height = 0;
m_width = 0;
- m_isPrinting = false;
+ m_fontScaleRatio = 1.0;
}
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 )
return renderer->CreateGDIPlusFont(this, font, col);
}
-
void wxGDIPlusContext::DoDrawFilledText(const wxString& str,
wxDouble x, wxDouble y,
const wxGraphicsBrush& brush)
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);
*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
//-----------------------------------------------------------------------------
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
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