wxMaxima
Loading...
Searching...
No Matches
pdfdc.h
Go to the documentation of this file.
1
2// Name: pdfdc.h
3// Purpose:
4// Author: Ulrich Telle
5// Created: 2010-11-28
6// Copyright: (c) Ulrich Telle
7// Licence: wxWindows licence
9
11
12#ifndef _PDF_DC_H_
13#define _PDF_DC_H_
14
15#include <wx/defs.h>
16#include <wx/cmndata.h>
17#include <wx/dc.h>
18
19#include <stack>
20
21#if wxUSE_LISTCTRL
22class wxListCtrl;
23#endif
24
25#if wxUSE_GRID
26class wxGrid;
27#endif
28
29#include "wx/pdfdocument.h"
30#include "wx/pdffont.h"
31
34{
35 wxPDF_MAPMODESTYLE_STANDARD = 1,
36 wxPDF_MAPMODESTYLE_MSW,
37 wxPDF_MAPMODESTYLE_GTK,
38 wxPDF_MAPMODESTYLE_MAC,
43};
44
46class WXDLLIMPEXP_PDFDOC wxPdfDC : public wxDC
47{
48public:
50 wxPdfDC();
51
53
74 wxPdfDC(const wxPrintData& printData);
75
77
103 wxPdfDC(wxPdfDocument* pdfDocument, double templateWidth, double templateHeight);
104
106
109 wxPdfDocument* GetPdfDocument();
110
112
116 void SetResolution(int ppi);
117
119
123 int GetResolution() const;
124
126
145 void SetFontResolution(int ppi);
146
148
153 int GetFontResolution() const;
154
156
160 void SetImageType(wxBitmapType bitmapType, int quality = 75);
161
163
169 void SetMapModeStyle(wxPdfMapModeStyle style);
170
172
176 wxPdfMapModeStyle GetMapModeStyle() const;
177
178#if wxUSE_LISTCTRL
180
186 void DrawList(const wxListCtrl* list, wxCoord x, wxCoord y,
187 const wxPdfListCtrlOptions& options = wxPdfListCtrlOptions());
188#endif
189
190#if wxUSE_GRID
192
198 void DrawGrid(const wxGrid* grid, wxCoord x, wxCoord y,
199 const wxPdfGridOptions& options = wxPdfGridOptions());
200#endif
201
202private:
203 wxDECLARE_DYNAMIC_CLASS(wxPdfDC);
204};
205
206#if wxCHECK_VERSION(3,1,0)
207#else
208#define wxOVERRIDE
209#endif
210
212class WXDLLIMPEXP_PDFDOC wxPdfDCImpl: public wxDCImpl
213{
214public:
216
219 wxPdfDCImpl(wxPdfDC *owner);
220
222
226 wxPdfDCImpl(wxPdfDC* owner, const wxPrintData& data);
227
229
235 wxPdfDCImpl(wxPdfDC* owner, wxPdfDocument* pdfDocument, double templateWidth, double templateHeight);
236
238
244 wxPdfDCImpl(wxPdfDC* owner, const wxString& file, int w = 300, int h = 200);
245
247 virtual ~wxPdfDCImpl();
248
250 void Init();
251
253
256 wxPdfDocument* GetPdfDocument();
257
259
263 void SetPrintData(const wxPrintData& data);
264
266
269 wxPrintData& GetPrintData() { return m_printData; }
270
272
276 void SetResolution(int ppi);
277
279
283 virtual int GetResolution() const wxOVERRIDE;
284
286
289 void SetFontResolution(int ppi);
290
292 int GetFontResolution() const;
293
295
299 void SetImageType(wxBitmapType bitmapType, int quality = 75);
300
301 // implement base class pure virtuals
302
303 virtual void Clear() wxOVERRIDE;
304
306
311 virtual bool StartDoc(const wxString& message) wxOVERRIDE;
312
314
317 virtual void EndDoc() wxOVERRIDE;
318
320
323 virtual void StartPage() wxOVERRIDE;
324
326
329 virtual void EndPage() wxOVERRIDE;
330 virtual void SetFont(const wxFont& font) wxOVERRIDE;
331 virtual void SetPen(const wxPen& pen) wxOVERRIDE;
332 virtual void SetBrush(const wxBrush& brush) wxOVERRIDE;
333 virtual void SetBackground(const wxBrush& brush) wxOVERRIDE;
334 virtual void SetBackgroundMode(int mode) wxOVERRIDE;
335#if wxUSE_PALETTE
336 virtual void SetPalette(const wxPalette& palette) wxOVERRIDE;
337#endif // wxUSE_PALETTE
338
339 virtual void DestroyClippingRegion() wxOVERRIDE;
340
341 virtual wxCoord GetCharHeight() const wxOVERRIDE;
342 virtual wxCoord GetCharWidth() const wxOVERRIDE;
343
344 virtual bool CanDrawBitmap() const wxOVERRIDE;
345 virtual bool CanGetTextExtent() const wxOVERRIDE;
346 virtual int GetDepth() const wxOVERRIDE;
347 virtual wxSize GetPPI() const wxOVERRIDE;
348
349 virtual void SetMapMode(wxMappingMode mode) wxOVERRIDE;
350 virtual void SetUserScale(double x, double y) wxOVERRIDE;
351
352 virtual void SetLogicalScale(double x, double y) wxOVERRIDE;
353 virtual void SetLogicalOrigin(wxCoord x, wxCoord y) wxOVERRIDE;
354 virtual void SetDeviceOrigin(wxCoord x, wxCoord y) wxOVERRIDE;
355 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) wxOVERRIDE;
356
357#if wxUSE_DC_TRANSFORM_MATRIX
358 virtual bool CanUseTransformMatrix() const wxOVERRIDE;
359
361
366 virtual bool SetTransformMatrix(const wxAffineMatrix2D& matrix) wxOVERRIDE;
367
369
373 virtual wxAffineMatrix2D GetTransformMatrix() const wxOVERRIDE;
374
376
379 virtual void ResetTransformMatrix() wxOVERRIDE;
380#endif // wxUSE_DC_TRANSFORM_MATRIX
381
382 virtual void SetLogicalFunction(wxRasterOperationMode function) wxOVERRIDE;
383
384 virtual void SetTextForeground(const wxColour& colour) wxOVERRIDE;
385 virtual void ComputeScaleAndOrigin() wxOVERRIDE;
386
387#if wxUSE_GRAPHICS_CONTEXT
391
395 virtual wxGraphicsContext* GetGraphicsContext() const wxOVERRIDE;
396
398
402 virtual void SetGraphicsContext(wxGraphicsContext* ctx) wxOVERRIDE;
403#endif // wxUSE_GRAPHICS_CONTEXT
404
405#if 0
406 // RTL related functions
407 // ---------------------
408
409 // get or change the layout direction (LTR or RTL) for this dc,
410 // wxLayout_Default is returned if layout direction is not supported
411 virtual wxLayoutDirection GetLayoutDirection() const
412 { return wxLayout_Default; }
413 virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir))
414 { }
415#endif
416
417protected:
418 // the true implementations
419 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
420 wxFloodFillStyle style = wxFLOOD_SURFACE) wxOVERRIDE;
421
422 virtual void DoGradientFillLinear(const wxRect& rect,
423 const wxColour& initialColour,
424 const wxColour& destColour,
425 wxDirection nDirection = wxEAST) wxOVERRIDE;
426
427 virtual void DoGradientFillConcentric(const wxRect& rect,
428 const wxColour& initialColour,
429 const wxColour& destColour,
430 const wxPoint& circleCenter) wxOVERRIDE;
431
432 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour* col) const wxOVERRIDE;
433
434 virtual void DoDrawPoint(wxCoord x, wxCoord y) wxOVERRIDE;
435
436#if wxUSE_SPLINES
437 virtual void DoDrawSpline(const wxPointList* points) wxOVERRIDE;
438#endif
439
440 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE;
441
442 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
443 wxCoord x2, wxCoord y2,
444 wxCoord xc, wxCoord yc) wxOVERRIDE;
445
446 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
447 wxCoord width, wxCoord height) wxOVERRIDE;
448
449 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
450 double sa, double ea) wxOVERRIDE;
451
452 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE;
453 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
454 wxCoord width, wxCoord height,
455 double radius) wxOVERRIDE;
456 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE;
457
458 virtual void DoCrossHair(wxCoord x, wxCoord y) wxOVERRIDE;
459
460 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) wxOVERRIDE;
461 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
462 bool useMask = false) wxOVERRIDE;
463
464 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) wxOVERRIDE;
465 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
466 double angle) wxOVERRIDE;
467
468 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
469 wxDC* source, wxCoord xsrc, wxCoord ysrc,
470 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
471 wxCoord xsrcMask = -1, wxCoord ysrcMask = -1) wxOVERRIDE;
472
473 virtual void DoGetSize(int* width, int* height) const wxOVERRIDE;
474 virtual void DoGetSizeMM(int* width, int* height) const wxOVERRIDE;
475
476 virtual void DoDrawLines(int n, const wxPoint points[],
477 wxCoord xoffset, wxCoord yoffset) wxOVERRIDE;
478 virtual void DoDrawPolygon(int n, const wxPoint points[],
479 wxCoord xoffset, wxCoord yoffset,
480 wxPolygonFillMode fillStyle = wxODDEVEN_RULE) wxOVERRIDE;
481 virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[],
482 wxCoord xoffset, wxCoord yoffset,
483 wxPolygonFillMode fillStyle) wxOVERRIDE;
484
485 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
486 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
487 wxCoord width, wxCoord height) wxOVERRIDE;
488 virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE;
489
490 virtual void DoGetTextExtent(const wxString& string,
491 wxCoord* x, wxCoord* y,
492 wxCoord* descent = NULL,
493 wxCoord* externalLeading = NULL,
494 const wxFont* theFont = NULL) const wxOVERRIDE;
495
496 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const wxOVERRIDE;
497
498public:
499 int GetDrawingStyle();
500 bool StretchBlt(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
501 wxBitmap* bitmap);
502 int IncreaseImageCounter();
503
504 void SetMapModeStyle(wxPdfMapModeStyle style) { m_mappingModeStyle = style; }
505 wxPdfMapModeStyle GetMapModeStyle() const { return m_mappingModeStyle; }
506
507 double ScaleLogicalToPdfX(wxCoord x) const;
508 double ScaleLogicalToPdfXRel(wxCoord x) const;
509 double ScaleLogicalToPdfY(wxCoord y) const;
510 double ScaleLogicalToPdfYRel(wxCoord y) const;
511 double ScaleFontSizeToPdf(int pointSize) const;
512 int ScalePdfToFontMetric(double metric) const;
513
514private:
515 int FindPdfFont(wxFont* font) const;
516
518 static double ScreenFontResolution();
519
520 bool MustSetCurrentPen(const wxPen& currentPen) const;
521 bool MustSetCurrentBrush(const wxBrush& currentBrush) const;
522
523 void SetupPen(bool force = false);
524 void SetupBrush(bool force = false);
525 void SetupAlpha();
526 void SetupTextAlpha();
527 void CalculateFontMetrics(wxPdfFontDescription* desc, int pointSize,
528 int* height, int* ascent, int* descent, int* extLeading) const;
529
530 bool m_templateMode;
531 double m_templateWidth;
532 double m_templateHeight;
533 double m_ppi;
534 double m_ppiPdfFont;
535 wxPdfDocument* m_pdfDocument;
536 wxPrintData m_printData;
537 wxPdfMapModeStyle m_mappingModeStyle;
538
539 wxPdfColour m_cachedPdfColour;
540 wxUint32 m_cachedRGB;
541 wxPen m_pdfPen;
542 wxBrush m_pdfBrush;
543
544 bool m_inTransform;
545 wxAffineMatrix2D m_matrix;
546 wxPen m_pdfPenSaved;
547 wxBrush m_pdfBrushSaved;
548
549 bool m_jpegFormat;
550 int m_jpegQuality;
551
552 static int ms_imageCount;
553
554#if wxUSE_GRAPHICS_CONTEXT
555 // Lazily-allocated GC that draws into m_pdfDocument. Owned by this DC;
556 // mutable so the const GetGraphicsContext() accessor can build it on
557 // first use, matching the pattern in wxWindowsDCImpl etc.
558 mutable wxGraphicsContext* m_graphicContext;
559#endif
560
561 wxDECLARE_DYNAMIC_CLASS(wxPdfDCImpl);
562};
563
564#endif
Class representing wxPdfDocument colours.
Definition: pdfcolour.h:40
Class representing the PDF drawing context implementation.
Definition: pdfdc.h:213
wxPdfDCImpl(wxPdfDC *owner, const wxString &file, int w=300, int h=200)
Constructor initializing with a file.
wxPrintData & GetPrintData()
Returns the print data.
Definition: pdfdc.h:269
Class representing a PDF drawing context.
Definition: pdfdc.h:47
Class representing a PDF document.
Definition: pdfdocument.h:176
Class representing a font description.
Definition: pdffontdescription.h:24
Options that control how a wxListCtrl is rendered into a PDF document.
Definition: pdflistctrl.h:66
wxPdfMapModeStyle
Enumeration of map mode styles.
Definition: pdfdc.h:34
@ wxPDF_MAPMODESTYLE_PDF
same font sizes and text position as with the wxPdfDocument API
Definition: pdfdc.h:40
@ wxPDF_MAPMODESTYLE_PDFFONTSCALE
same font sizes as with the wxPdfDocument API
Definition: pdfdc.h:42
Interface of the wxPdfDocument class.
Interface of wxPdfFont class.