All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PDFDraw.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5 #ifndef PDFTRON_H_CPPPDFPDFDraw
6 #define PDFTRON_H_CPPPDFPDFDraw
7 
8 #include <PDF/PDFRasterizer.h>
9 #include <C/PDF/TRN_PDFDraw.h>
10 
11 #ifdef SWIG
12 #include <PDF/Callback.h>
13 #endif
14 
15 // @cond PRIVATE_DOC
16 #ifndef SWIGHIDDEN
17 #if defined(_WIN32)
18  // A forward declaration for GDI+ Bitmap-s which can be directly created using PDFDraw::GetBitmap() method.
19  namespace Gdiplus { class Bitmap; };
20 #endif
21 #endif
22 // @endcond
23 
24 
25 
26 
27 namespace pdftron {
28  namespace PDF {
29 
30 
31 //return type for PDFDraw::GetBitmap
33 {
34  std::vector<unsigned char> buf;
35 
36 public:
37  BitmapInfo(int w, int h, int s, double d, char* b) {
38  width = w;
39  height = h;
40  stride = s;
41  dpi = d;
42  buf.resize(h*s);
43  memcpy(&buf[0], b, h*s);
44  }
45  int width;
46  int height;
47  int stride;
48  double dpi;
49 
50  //copy constructor
51  BitmapInfo(const BitmapInfo& b) {
52  width = b.width;
53  height = b.height;
54  stride = b.stride;
55  dpi = b.dpi;
56  std::vector<unsigned char> temp(b.GetBuffer());
57  buf.swap(temp);
58  }
59 
60  std::vector<unsigned char> GetBuffer() const {
61  return buf;
62  }
63 };
64 
65 class Separation;
66 
74 class PDFDraw
75 {
76 public:
77 
85  PDFDraw(double dpi = 92);
86  ~PDFDraw();
87 
100 
121  void SetDPI(double dpi);
122 
135  void SetImageSize(int width, int height, bool preserve_aspect_ratio = true);
136 
143  void SetPageBox(Page::Box region);
144 
151  void SetClipRect(Rect clip_rect);
152 
159  void SetFlipYAxis(bool flip_y);
160 
170  void SetRotate(Page::Rotate r);
171 
178  void SetDrawAnnotations(bool render_annots);
179 
185  void SetHighlightFields(bool highlight_fields);
186 
196  void SetAntiAliasing(bool enable_aa);
197 
206  void SetPathHinting(bool enable_hinting);
207 
218  void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust);
219 
234  void SetImageSmoothing(bool smoothing_enabled = true, bool hq_image_resampling = false);
235 
242  void SetCaching(bool enabled = true);
243 
256  void SetGamma(double exp);
257 
267  void SetOCGContext(OCG::Context* ctx);
268 
278  void SetPrintMode(bool is_printing);
279 
292  void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b);
293 
308  void SetPageTransparent(bool is_transparent);
309 
320 
404  void Export(Page page, const UString& filename, const char* format = "PNG", SDF::Obj encoder_params = 0);
405 
414  void Export(Page page, Filters::Filter& stream, const char* format = "PNG", SDF::Obj encoder_params = 0);
415 
424  #ifdef __DOTNET
425  System::Drawing::Bitmap* GetBitmap(Page page);
426  #endif
427 
444 #if defined(_WIN32) && !defined(__WINRT__)
445  void DrawInRect(Page& page, void* hdc, const Rect& rect);
446 #endif
447 
451  enum PixelFormat {
459  };
460 
484  const BitmapInfo GetBitmap(Page page, PixelFormat pix_fmt = e_bgra, bool demult = false);
485 
498  std::vector<Separation> GetSeparationBitmaps(Page page);
499 
500 #ifndef SWIG
501  const UChar* GetBitmap(Page page, int& out_width, int& out_height, int& out_stride, double& out_dpi,
502  PixelFormat pix_fmt = e_bgra, bool demult = false);
503 #endif
504 
512 #ifdef SWIG
513  void SetErrorReportProc(Callback* instance);
514 #else
515  void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void* data);
516 #endif
517 
528 
532  void Destroy();
533 
534 // @cond PRIVATE_DOC
535 #ifndef SWIGHIDDEN
536  TRN_PDFDraw mp_draw;
537 #endif
538 private:
539  // PDFDraw should not be copied
540  PDFDraw(const PDFDraw& other);
541  PDFDraw& operator= (const PDFDraw&);
542 // @endcond
543 };
544 
545 
546 #include <Impl/PDFDraw.inl>
547 
548 
549  }; // namespace PDF
550 }; // namespace pdftron
551 
552 #endif // PDFTRON_H_CPPPDFPDFDraw
void SetGamma(double exp)
void SetPathHinting(bool enable_hinting)
void SetClipRect(Rect clip_rect)
void SetPrintMode(bool is_printing)
void SetImageSmoothing(bool smoothing_enabled=true, bool hq_image_resampling=false)
void SetPageBox(Page::Box region)
PDFDraw(double dpi=92)
TRN_UInt8 UInt8
Definition: BasicTypes.h:15
BitmapInfo(const BitmapInfo &b)
Definition: PDFDraw.h:51
void(* ErrorReportProc)(const char *message, void *data)
void SetPageTransparent(bool is_transparent)
void SetImageSize(int width, int height, bool preserve_aspect_ratio=true)
BitmapInfo(int w, int h, int s, double d, char *b)
Definition: PDFDraw.h:37
std::vector< Separation > GetSeparationBitmaps(Page page)
void SetRotate(Page::Rotate r)
void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b)
TRN_UChar UChar
Definition: BasicTypes.h:12
void SetFlipYAxis(bool flip_y)
void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void *data)
std::vector< unsigned char > GetBuffer() const
Definition: PDFDraw.h:60
void SetDPI(double dpi)
void Export(Page page, const UString &filename, const char *format="PNG", SDF::Obj encoder_params=0)
void SetRasterizerType(PDFRasterizer::Type type)
void SetCaching(bool enabled=true)
const BitmapInfo GetBitmap(Page page, PixelFormat pix_fmt=e_bgra, bool demult=false)
void SetDrawAnnotations(bool render_annots)
void SetOCGContext(OCG::Context *ctx)
void SetColorPostProcessMode(PDFRasterizer::ColorPostProcessMode mode)
void SetHighlightFields(bool highlight_fields)
void SetAntiAliasing(bool enable_aa)
void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust)
void SetOverprint(PDFRasterizer::OverprintPreviewMode op)