KiCad PCB EDA Suite
cairo_print.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 CERN
3  * Author: Maciej Suminski <maciej.suminski@cern.ch>
4  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef _CAIRO_PRINT_H_
21 #define _CAIRO_PRINT_H_
22 
23 #include <gal/cairo/cairo_gal.h>
24 #include <gal/gal_print.h>
25 
26 class wxDC;
27 class wxGCDC;
28 
29 namespace KIGFX
30 {
36 {
37 public:
38  CAIRO_PRINT_CTX( wxDC* aDC );
40 
41  cairo_t* GetContext() const
42  {
43  return m_ctx;
44  }
45 
46  cairo_surface_t* GetSurface() const
47  {
48  return m_surface;
49  }
50 
51  double GetNativeDPI() const override
52  {
53  return m_dpi;
54  }
55 
56  bool HasNativeLandscapeRotation() const override
57  {
58 #if defined(__WXGTK__) && !defined(__WXGTK3__)
59  return false;
60 #else
61  return true;
62 #endif
63  }
64 
65 private:
66  wxGCDC* m_gcdc;
67  cairo_t* m_ctx;
68  cairo_surface_t* m_surface;
69 
70 #ifdef __WXMSW__
71  void* m_hdc; // the real type is HDC, but do not pull in extra headers
73 #endif /* __WXMSW__ */
74 
75  double m_dpi;
76 };
77 
78 
80 {
81 public:
82  CAIRO_PRINT_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions,
83  std::unique_ptr<CAIRO_PRINT_CTX> aContext );
84 
85  void SetLineWidth( float aLineWidth ) override;
86 
87  void ComputeWorldScreenMatrix() override;
88 
89  GAL* GetGAL() override
90  {
91  return this;
92  }
93 
94  PRINT_CONTEXT* GetPrintCtx() const override
95  {
96  return m_printCtx.get();
97  }
98 
104  void SetNativePaperSize( const VECTOR2D& aSize, bool aRotateIfLandscape ) override;
105 
109  void SetSheetSize( const VECTOR2D& aSize ) override;
110 
111 private:
113  bool isLandscape() const
114  {
115  return m_nativePaperSize.x > m_nativePaperSize.y;
116  }
117 
120 
124 
125  std::unique_ptr<CAIRO_PRINT_CTX> m_printCtx;
126 };
127 } // namespace KIGFX
128 
129 #endif /* _CAIRO_PRINT_H_ */
Wrapper around GAL to provide information needed for printing.
Definition: gal_print.h:43
double GetNativeDPI() const override
Definition: cairo_print.h:51
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
cairo_surface_t * m_surface
Definition: cairo_print.h:68
std::unique_ptr< CAIRO_PRINT_CTX > m_printCtx
Definition: cairo_print.h:125
cairo_t * GetContext() const
Definition: cairo_print.h:41
bool HasNativeLandscapeRotation() const override
Definition: cairo_print.h:56
GAL * GetGAL() override
Definition: cairo_print.h:89
CAIRO_PRINT_CTX provides a Cairo context created from wxPrintDC.
Definition: cairo_print.h:35
CAIRO_PRINT_CTX(wxDC *aDC)
Definition: cairo_print.cpp:42
cairo_surface_t * GetSurface() const
Definition: cairo_print.h:46
bool isLandscape() const
Returns true if page orientation is landscape
Definition: cairo_print.h:113
VECTOR2D m_nativePaperSize
Printout size
Definition: cairo_print.h:119
PRINT_CONTEXT * GetPrintCtx() const override
Definition: cairo_print.h:94
bool m_hasNativeLandscapeRotation
Flag indicating whether the platform rotates page automatically or GAL needs to handle it in the tran...
Definition: cairo_print.h:123
Class GAL is the abstract interface for drawing on a 2D-surface.