25#include <wx/dcclient.h>
26#include <wx/dcgraph.h>
27#include <wx/dcmemory.h>
28#include <wx/dcprint.h>
40#include <cairo-win32.h>
41#include <wx/msw/enhmeta.h>
46#include <ApplicationServices/ApplicationServices.h>
47#include <cairo-quartz.h>
57 if( wxPrinterDC* printerDC =
dynamic_cast<wxPrinterDC*
>( aDC ) )
58 m_gcdc =
new wxGCDC( *printerDC );
59 else if( wxMemoryDC* memoryDC =
dynamic_cast<wxMemoryDC*
>( aDC ) )
60 m_gcdc =
new wxGCDC( *memoryDC );
61 else if( wxWindowDC* windowDC =
dynamic_cast<wxWindowDC*
>( aDC ) )
62 m_gcdc =
new wxGCDC( *windowDC );
64 else if( wxEnhMetaFileDC* enhMFDC =
dynamic_cast<wxEnhMetaFileDC*
>( aDC ) )
65 m_gcdc =
new wxGCDC( *enhMFDC );
68 throw std::runtime_error(
"Unhandled wxDC type" );
70 wxGraphicsContext* gctx =
m_gcdc->GetGraphicsContext();
73 throw std::runtime_error(
"Could not get the Graphics Context" );
76 m_ctx =
static_cast<cairo_t*
>( gctx->GetNativeContext() );
84#define DEFAULT_DPI 72.0
85#define KICAD_PRINTER_DPI 4800.0
90 m_dpi = KICAD_PRINTER_DPI;
94 Gdiplus::Graphics* g =
static_cast<Gdiplus::Graphics*
>( gctx->GetNativeContext() );
96 m_surface = cairo_win32_printing_surface_create(
static_cast<HDC
>( m_hdc ) );
98 m_dpi = GetDeviceCaps(
static_cast<HDC
>( m_hdc ), LOGPIXELSX );
102 wxSize size =
m_gcdc->GetSize();
103 CGContextRef cg = (CGContextRef) gctx->GetNativeContext();
104 m_surface = cairo_quartz_surface_create_for_cg_context( cg, size.x, size.y );
106 wxASSERT( aDC->GetPPI().x == aDC->GetPPI().y );
107 m_dpi = aDC->GetPPI().x;
110 if( !
m_ctx || cairo_status(
m_ctx ) != CAIRO_STATUS_SUCCESS )
111 throw std::runtime_error(
"Could not create Cairo context" );
114 throw std::runtime_error(
"Could not create Cairo surface" );
116 cairo_reference(
m_ctx );
125 wxGraphicsContext* gctx =
m_gcdc->GetGraphicsContext();
126 Gdiplus::Graphics* g =
static_cast<Gdiplus::Graphics*
>( gctx->GetNativeContext() );
127 g->ReleaseHDC(
static_cast<HDC
>( m_hdc ) );
131 cairo_destroy(
m_ctx );
137 std::unique_ptr<CAIRO_PRINT_CTX> aContext ) :
158 const VECTOR2D paperSizeIUTransposed( paperSizeIU.
y, paperSizeIU.
x );
211 auto printCtx = std::make_unique<CAIRO_PRINT_CTX>( aDC );
212 return std::make_unique<CAIRO_PRINT_GAL>( aOptions, std::move( printCtx ) );
cairo_surface_t * m_surface
Cairo surface.
cairo_t * m_context
Cairo image.
cairo_t * m_currentContext
Currently used Cairo context for drawing.
CAIRO_PRINT_CTX(wxDC *aDC)
cairo_surface_t * m_surface
void SetSheetSize(const VECTOR2D &aSize) override
bool isLandscape() const
< Returns true if page orientation is landscape
bool m_hasNativeLandscapeRotation
CAIRO_PRINT_GAL(GAL_DISPLAY_OPTIONS &aDisplayOptions, std::unique_ptr< CAIRO_PRINT_CTX > aContext)
void SetNativePaperSize(const VECTOR2D &aSize, bool aRotateIfLandscape) override
std::unique_ptr< CAIRO_PRINT_CTX > m_printCtx
void ComputeWorldScreenMatrix() override
Compute the world <-> screen transformation matrix.
VECTOR2D m_nativePaperSize
Flag indicating whether the platform rotates page automatically or GAL needs to handle it in the tran...
A color representation with 4 components: red, green, blue, alpha.
static std::unique_ptr< GAL_PRINT > Create(GAL_DISPLAY_OPTIONS &aOptions, wxDC *aDC)
MATRIX3x3D m_worldScreenMatrix
World transformation.
MATRIX3x3D m_screenWorldMatrix
Screen transformation.
double m_zoomFactor
The zoom factor.
double m_worldUnitLength
The unit length of the world coordinates [inch].
double m_worldScale
The scale factor world->screen.
bool m_globalFlipY
Flag for Y axis flipping.
void SetScreenSize(const VECTOR2I &aSize)
double m_screenDPI
The dots per inch of the screen.
bool m_globalFlipX
Flag for X axis flipping.
VECTOR2D m_lookAtPoint
Point to be looked at in world space.
void SetScreenDPI(double aScreenDPI)
Set the dots per inch of the screen.
void SetIdentity()
Set the matrix to the identity matrix.
void SetRotation(T aAngle)
Set the rotation components of the matrix.
void SetScale(VECTOR2< T > aScale)
Set the scale components of the matrix.
void SetTranslation(VECTOR2< T > aTranslation)
Set the translation components of the matrix.
MATRIX3x3 Inverse() const
Determine the inverse of the matrix.
The Cairo implementation of the graphics abstraction layer.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D