All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PDFView.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5 #ifndef PDFTRON_H_CPPPDFPDFView
6 #define PDFTRON_H_CPPPDFPDFView
7 
8 #include <Common/BasicTypes.h>
9 #include <PDF/PDFDoc.h>
11 #include <PDF/PDFRasterizer.h>
12 #include <PDF/Highlights.h>
13 #include <PDF/LinkInfo.h>
14 #include <PDF/OCG/Context.h>
15 #include <C/PDF/TRN_PDFView.h>
16 #include <PDF/Selection.h>
17 #include <PDF/DocumentConversion.h>
18 #include <SDF/ObjSet.h>
20 #include <PDF/ActionParameter.h>
21 #ifdef SWIG
22 #include <PDF/Callback.h>
23 #endif
24 
25 namespace pdftron {
26  namespace PDF {
27 
72 class PDFView
73 {
74 public:
75 
80  PDFView();
81  ~PDFView();
82 
88  void SetDoc(PDFDoc& doc);
89 
98  void OpenUniversalDoc(DocumentConversion& conversion);
99 
103  void CloseDoc();
104 
108  PDFDoc* GetDoc();
109 
114  void DocLock(bool cancel_threads);
115 
119  void DocUnlock();
120 
126  bool DocTryLock( int milliseconds = 0 );
127 
139  void DocLockRead();
140 
144  void DocUnlockRead();
145 
151  bool DocTryLockRead( int milliseconds = 0 );
152 
157  {
158  e_single_page = 1, //<<< Display one page at a time.
159  e_single_continuous, //<<< Display the pages in one column.
160  e_facing, //<<< Display the pages two at a time, with odd-numbered pages on the left.
161  e_facing_continuous, //<<< Display the pages in two columns, with odd-numbered pages on the left.
162  e_facing_cover, //<<< Display the pages two at a time, with odd-numbered pages on the right.
163  e_facing_continuous_cover //<<< Display the pages in two columns, with odd-numbered pages on the right.
164  };
165 
173 
178 
189 
202  void SetColorPostProcessColors(unsigned int white_color, unsigned int black_color);
203 
208 
212  int GetCurrentPage() const;
213 
217  int GetPageCount() const;
218 
224  bool GotoFirstPage();
225 
231  bool GotoLastPage();
232 
238  bool GotoNextPage();
239 
245  bool GotoPreviousPage();
246 
252  bool SetCurrentPage(int page_num);
253 
261  bool ShowRect( int page_num, const Rect& rect );
262 
268  std::vector<int> GetVisiblePages() const ;
269 
275  double GetZoom() const;
276 
284  bool SetZoom(double zoom);
285 
313  bool SetZoom(int x, int y, double zoom);
314 
331  bool SmartZoom(int x, int y);
335  void RotateClockwise();
336 
340  void RotateCounterClockwise();
341 
345  Page::Rotate GetRotation() const;
346 
352  int GetPageNumberFromScreenPt(double x, double y) const;
353 
357  Point ConvScreenPtToCanvasPt(const Point& pt) const;
358 
359 #ifndef SWIG
360  void ConvScreenPtToCanvasPt(double& x, double& y) const;
361 #endif
362 
366  Point ConvCanvasPtToScreenPt(const Point& pt) const;
367 
368 #ifndef SWIG
369  void ConvCanvasPtToScreenPt(double& x, double& y) const;
370 #endif
371 
379  Point ConvCanvasPtToPagePt(const Point& pt, int page_num = -1) const;
380 
381 #ifndef SWIG
382  void ConvCanvasPtToPagePt(double& x, double& y, int page_num = -1) const;
383 #endif
384 
392  Point ConvPagePtToCanvasPt(const Point& pt, int page_num = -1) const;
393 
394 #ifndef SWIG
395  void ConvPagePtToCanvasPt(double& x, double& y, int page_num = -1) const;
396 #endif
397 
405  Point ConvScreenPtToPagePt(const Point& pt, int page_num = -1) const;
406 
407 #ifndef SWIG
408  void ConvScreenPtToPagePt(double& x, double& y, int page_num = -1) const;
409 #endif
410 
420  Point ConvPagePtToScreenPt(const Point& pt, int page_num = -1) const;
421 
422 #ifndef SWIG
423  void ConvPagePtToScreenPt(double& x, double& y, int page_num = -1) const;
424 #endif
425 
430  Point SnapToNearestInDoc(const Point& screen_pt);
431 
438  void SetSnappingMode(UInt32 mode_flags);
439 
455  Common::Matrix2D GetDeviceTransform(int page_num = -1) const;
456 
464 #ifdef SWIG
465  void SetErrorReportProc(Callback* instance);
466 #else
467  void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void* data);
468 #endif
469 
478  typedef void (*CurrentPageProc) (int current_page, int num_pages, void* data);
479 
488 #ifdef SWIG
489  void SetCurrentPageProc(Callback* instance);
490 #else
491  void SetCurrentPageProc(CurrentPageProc curr_pagenum_proc, void* data);
492 #endif
493 
503  typedef void(*JavaScriptEventProc) (const char* event_type, const char* json, void* data);
504 
512 #ifdef SWIG
513  void SetJavaScriptEventCallBack(Callback* instance);
514 #else
515  void SetJavaScriptEventCallBack(JavaScriptEventProc js_proc, void* data);
516 #endif
517 
525  typedef void (*CurrentZoomProc) (double curr_zoom_proc, void* data);
526 
535 #ifdef SWIG
536  void SetCurrentZoomProc(Callback* instance);
537 #else
538  void SetCurrentZoomProc(CurrentZoomProc curr_zoom_proc, void* data);
539 #endif
540 
546  void ExecuteAction(Action& action);
547 
548  void ExecuteAction(ActionParameter& action_param);
549 
553  double GetCanvasWidth() const;
554 
558  double GetCanvasHeight() const;
559 
563  double GetHScrollPos() const;
564 
568  double GetVScrollPos() const;
569 
576  void OnScroll(int pix_dx, int pix_dy);
577 
584  void SetHScrollPos(double pos);
585 
608  void SetVScrollPos(double pos);
609 
617  void OnSize(int width, int height);
618 
627  bool IsFinishedRendering(bool visible_region_only) const;
628 
633  void CancelRendering();
634 
638  void Update(bool all = false);
639 
644  void Update(const Rect& update);
645 
651  void Update(const Annot& annot, int page_num);
652 
657  void Update(const Field& field);
658 
665  void UpdatePageLayout();
666 
672 #ifdef SWIG
673  std::vector<unsigned char> GetBuffer() const;
674 #else
675  const char* GetBuffer() const;
676 #endif
677 
690  void UpdateBuffer();
691 
696  int GetBufferWidth() const;
697 
702  int GetBufferHeight() const;
703 
708  int GetBufferStride() const;
709 
716  void SetDrawAnnotations(bool render_annots);
717 
730  void SetUrlExtraction(bool enabled);
731 
744  LinkInfo GetLinkAt(int x, int y);
745 
751  void SetHighlightFields(bool highlight_fields);
752 
762  void SetAntiAliasing(bool enable_aa);
763 
772  void SetPathHinting(bool enable_hinting);
773 
784  void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust);
785 
799  void SetImageSmoothing(bool smoothing_enabled = true);
800 
808  void SetCaching(bool enabled);
809 
819 
832  void SetGamma(double exp);
833 
844 
860  void SetOCGContext(const OCG::Context& ctx);
861 
870 
876  void UpdateOCGContext();
877 
878 
885  typedef void (*RenderBeginEventProc) (void* data);
886 
898  typedef void (*RenderFinishEventProc) (void* data, bool canceled);
899 
912 #ifdef SWIG
913  void SetRenderBeginProc(class Callback* instance);
914 #else
915  void SetRenderBeginProc(RenderBeginEventProc proc, void* data);
916 #endif
917 
930 #ifdef SWIG
931  void SetRenderFinishProc(class Callback* instance);
932 #else
933  void SetRenderFinishProc(RenderFinishEventProc proc, void* data);
934 #endif
935 
936 
948  };
949 
955 
963  bool Select(double x1, double y1, double x2, double y2);
964 
973  bool SelectWithSnapping(double x1, double y1, double x2, double y2, bool snap_to_start, bool snap_to_end);
974 
982  bool SelectWithSmartSnapping(double x1, double y1, double x2, double y2);
983 
991  bool Select(double x1, double y1, int page1, double x2, double y2, int page2);
992 
1001  bool SelectWithSnapping(double x1, double y1, int page1, double x2, double y2, int page2,
1002  bool snap_to_start, bool snap_to_end);
1003 
1011  bool SelectWithSmartSnapping(double x1, double y1, int page1, double x2, double y2, int page2);
1012 
1019  bool Select(const Highlights& highlights);
1020 
1027  bool Select(const Selection& select);
1028 
1033  void CancelFindText();
1034 
1038  void SelectAll();
1039 
1043  bool HasSelection() const;
1044 
1048  void ClearSelection();
1049 
1053  Selection GetSelection( int pagenum = -1 ) const;
1054 
1059  int GetSelectionBeginPage() const ;
1060 
1065  int GetSelectionEndPage() const;
1066 
1071  bool HasSelectionOnPage( int ipage ) const;
1072 
1079  void PrepareWords(int page_num);
1080 
1085  bool WereWordsPrepared(int page_num) const;
1086 
1091  bool IsThereTextInRect(double x1, double y1, double x2, double y2) const;
1092 
1103  void PrepareAnnotsForMouse(int page_num, double distance_threshold, double minimum_line_weight);
1104 
1109  bool WereAnnotsForMousePrepared(int page_num) const;
1110 
1116  Annot::Type GetAnnotTypeUnder(double x, double y);
1117 
1122  void SetPageBorderVisibility(bool border_visible);
1123 
1129  void SetPageTransparencyGrid(bool trans_grid_visible);
1130 
1135  void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b);
1136 
1142  void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a = 255);
1143 
1153  void SetHorizontalAlign(int align);
1154 
1164  void SetVerticalAlign(int align);
1165 
1175  void SetPageSpacing(int horiz_col_space, int vert_col_space, int horiz_pad, int vert_pad);
1176 
1189  static void SetViewerCache(SDF::SDFDoc& document, size_t max_cache_size, bool on_disk);
1190 
1194  void Destroy();
1195 
1199  void SetDevicePixelDensity(double dpi, double scale_factor);
1200 
1209  Rect GetScreenRectForAnnot(Annot annot, int page_num = -1);
1210 
1221  Annot GetAnnotationAt(int x, int y, double distanceThreshold, double minimumLineWeight);
1222 
1233  {
1238  PVM_SIZE //must stay as the last element
1239  };
1240 
1247  void SetPageViewMode(PageViewMode mode);
1248 
1252  PageViewMode GetPageViewMode() const;
1253 
1260  void RefreshAndUpdate(const ViewChangeCollection& view_change);
1261 
1274  void SetPageRefViewMode(PageViewMode mode);
1275 
1281 
1295  void SetupThumbnails(bool use_embedded, bool generate_at_runtime, bool use_disk_cache, int thumb_max_side_length, size_t max_abs_cache_size, double max_perc_cache_size);
1296 
1300  void ClearThumbCache();
1301 
1313  typedef void (*ThumbAsyncHandler) (int page_num, bool was_thumb_found, const char* thumb_buf, int thumb_width, int thumb_height, void* custom_data);
1314 
1323 #ifdef SWIG
1324  void GetThumbAsync(int page_num, Callback* instance);
1325 #else
1326  void GetThumbAsync(int page_num, ThumbAsyncHandler proc, void* custom_data);
1327 #endif
1328 
1336  size_t GetThumbInCacheSize(int page_num);
1337 
1348  bool GetThumbInCache(int page_num, UChar* buf, UInt32& out_width, UInt32& out_height);
1349 
1350  /*
1351  * Cancel all pending GetThumbAsync requests. Your callback function will still be called
1352  * for each canceled request, but 'was_thumb_found' will be set to 'false'.
1353  */
1354  void CancelAllThumbRequests();
1355 
1361  typedef void (*RequestRenderInWorkerThreadProc) (void* custom_data);
1362 
1371 #ifdef SWIG
1372  void SetRequestRenderInWorkerThreadProc(Callback* instance);
1373 #else
1375 #endif
1376 
1382  typedef void (*FindTextHandler)(bool success, PDF::Selection selection, void* custom_data);
1383 
1384 
1385 #ifdef SWIG
1386 
1392  void SetFindTextHandler(Callback* instance);
1393 #else // SWIG
1394 
1401  void SetFindTextHandler(PDFView::FindTextHandler proc, void* custom_data);
1402 #endif // SWIG
1403 
1415  void FindTextAsync(const UString& search_str, bool match_case, bool match_whole_word, bool search_up, bool reg_exp);
1416 
1425  std::vector<Annot> GetAnnotationsOnPage(int page_num);
1426 
1427  void EnableUndoRedo();
1428  UString Undo();
1429  UString Redo();
1430  void TakeSnapshot(const UString& meta_info);
1433  void RevertAllChanges();
1434 
1436 
1437 
1438  // @cond PRIVATE_DOC
1439 private:
1440  TRN_PDFView mp_view;
1441  TRN_PDFDoc temp_doc;
1442 
1443  // PDFView should not be copied
1444  PDFView(const PDFView&);
1445  PDFView& operator= (const PDFView&);
1446 
1447  FindTextHandler mp_findtexthandler;
1448  void* mp_findtextdata;
1449 
1450  static void StaticTRNPDFViewFindTextHandler(TRN_Bool success, TRN_PDFViewSelection selection, void* custom_data);
1451 
1452  //for internal use only
1453 #if defined(__iOS__)
1454 public:
1455  #include <Impl/PDFView.internal>
1456 #endif // defined(__iOS__)
1457  // @endcond
1458 };
1459 
1460 #include <Impl/PDFView.inl>
1461 
1462  }; // namespace PDF
1463 }; // namespace pdftron
1464 
1465 #endif // PDFTRON_H_CPPPDFPDFView
bool DocTryLock(int milliseconds=0)
void SetPageSpacing(int horiz_col_space, int vert_col_space, int horiz_pad, int vert_pad)
void(* JavaScriptEventProc)(const char *event_type, const char *json, void *data)
Definition: PDFView.h:503
void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a=255)
Point SnapToNearestInDoc(const Point &screen_pt)
void SetVScrollPos(double pos)
void SetRasterizerType(PDFRasterizer::Type type)
void SetHScrollPos(double pos)
PagePresentationMode GetPagePresentationMode() const
bool SelectWithSmartSnapping(double x1, double y1, double x2, double y2)
std::vector< Annot > GetAnnotationsOnPage(int page_num)
void OnScroll(int pix_dx, int pix_dy)
bool WereWordsPrepared(int page_num) const
void SetPageRefViewMode(PageViewMode mode)
bool DocTryLockRead(int milliseconds=0)
void PrepareWords(int page_num)
void SetRequestRenderInWorkerThreadProc(RequestRenderInWorkerThreadProc proc, void *custom_data)
void(* RenderFinishEventProc)(void *data, bool canceled)
Definition: PDFView.h:898
bool IsFinishedRendering(bool visible_region_only) const
void SetVerticalAlign(int align)
void(* RenderBeginEventProc)(void *data)
Definition: PDFView.h:885
void SetOCGContext(const OCG::Context &ctx)
void SetUrlExtraction(bool enabled)
size_t GetThumbInCacheSize(int page_num)
TRN_UInt8 UInt8
Definition: BasicTypes.h:15
Annot GetAnnotationAt(int x, int y, double distanceThreshold, double minimumLineWeight)
OCG::Context GetOCGContext()
void SetFindTextHandler(PDFView::FindTextHandler proc, void *custom_data)
int GetPageNumberFromScreenPt(double x, double y) const
Point ConvPagePtToScreenPt(const Point &pt, int page_num=-1) const
void SetPagePresentationMode(PagePresentationMode mode)
void(* CurrentZoomProc)(double curr_zoom_proc, void *data)
Definition: PDFView.h:525
Point ConvCanvasPtToPagePt(const Point &pt, int page_num=-1) const
Selection GetSelection(int pagenum=-1) const
Page::Rotate GetRotation() const
bool SelectWithSnapping(double x1, double y1, double x2, double y2, bool snap_to_start, bool snap_to_end)
void SetupThumbnails(bool use_embedded, bool generate_at_runtime, bool use_disk_cache, int thumb_max_side_length, size_t max_abs_cache_size, double max_perc_cache_size)
bool HasSelectionOnPage(int ipage) const
int GetBufferStride() const
void SetDoc(PDFDoc &doc)
void SetCurrentZoomProc(CurrentZoomProc curr_zoom_proc, void *data)
void FindTextAsync(const UString &search_str, bool match_case, bool match_whole_word, bool search_up, bool reg_exp)
void SetAntiAliasing(bool enable_aa)
ExternalAnnotManager GetExternalAnnotManager(const UString &author)
void(* RequestRenderInWorkerThreadProc)(void *custom_data)
Definition: PDFView.h:1361
void SetOverprint(PDFRasterizer::OverprintPreviewMode op)
Point ConvScreenPtToCanvasPt(const Point &pt) const
void Update(bool all=false)
void PrepareAnnotsForMouse(int page_num, double distance_threshold, double minimum_line_weight)
bool SetZoom(double zoom)
void SetGamma(double exp)
Point ConvCanvasPtToScreenPt(const Point &pt) const
void SetPathHinting(bool enable_hinting)
double GetZoom() const
bool SetCurrentPage(int page_num)
void SetImageSmoothing(bool smoothing_enabled=true)
void(* ErrorReportProc)(const char *message, void *data)
Point ConvPagePtToCanvasPt(const Point &pt, int page_num=-1) const
void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b)
double GetHScrollPos() const
void SetColorPostProcessMode(PDFRasterizer::ColorPostProcessMode mode)
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
void TakeSnapshot(const UString &meta_info)
void(* FindTextHandler)(bool success, PDF::Selection selection, void *custom_data)
Definition: PDFView.h:1382
const char * GetBuffer() const
PageViewMode GetPageRefViewMode() const
void(* ThumbAsyncHandler)(int page_num, bool was_thumb_found, const char *thumb_buf, int thumb_width, int thumb_height, void *custom_data)
Definition: PDFView.h:1313
void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void *data)
void GetThumbAsync(int page_num, ThumbAsyncHandler proc, void *custom_data)
Point ConvScreenPtToPagePt(const Point &pt, int page_num=-1) const
TRN_UChar UChar
Definition: BasicTypes.h:12
void SetSnappingMode(UInt32 mode_flags)
void SetDrawAnnotations(bool render_annots)
double GetVScrollPos() const
double GetCanvasHeight() const
void DocLock(bool cancel_threads)
void SetPageTransparencyGrid(bool trans_grid_visible)
std::vector< int > GetVisiblePages() const
bool Select(double x1, double y1, double x2, double y2)
void SetRenderFinishProc(RenderFinishEventProc proc, void *data)
void RefreshAndUpdate(const ViewChangeCollection &view_change)
void SetJavaScriptEventCallBack(JavaScriptEventProc js_proc, void *data)
void SetHorizontalAlign(int align)
int GetSelectionEndPage() const
bool ShowRect(int page_num, const Rect &rect)
void ExecuteAction(Action &action)
bool WereAnnotsForMousePrepared(int page_num) const
void SetRenderBeginProc(RenderBeginEventProc proc, void *data)
Annot::Type GetAnnotTypeUnder(double x, double y)
bool IsThereTextInRect(double x1, double y1, double x2, double y2) const
void SetPageBorderVisibility(bool border_visible)
void SetCurrentPageProc(CurrentPageProc curr_pagenum_proc, void *data)
int GetSelectionBeginPage() const
bool GetThumbInCache(int page_num, UChar *buf, UInt32 &out_width, UInt32 &out_height)
bool HasSelection() const
int GetBufferWidth() const
void OnSize(int width, int height)
void SetHighlightFields(bool highlight_fields)
PDFRasterizer::ColorPostProcessMode GetColorPostProcessMode() const
void SetPageViewMode(PageViewMode mode)
LinkInfo GetLinkAt(int x, int y)
int GetPageCount() const
void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust)
void SetColorPostProcessColors(unsigned int white_color, unsigned int black_color)
Rect GetScreenRectForAnnot(Annot annot, int page_num=-1)
static void SetViewerCache(SDF::SDFDoc &document, size_t max_cache_size, bool on_disk)
Common::Matrix2D GetDeviceTransform(int page_num=-1) const
void(* CurrentPageProc)(int current_page, int num_pages, void *data)
Definition: PDFView.h:478
int GetCurrentPage() const
bool SmartZoom(int x, int y)
PageViewMode GetPageViewMode() const
void OpenUniversalDoc(DocumentConversion &conversion)
void SetCaching(bool enabled)
void SetTextSelectionMode(TextSelectionMode tm)
double GetCanvasWidth() const
void SetDevicePixelDensity(double dpi, double scale_factor)
int GetBufferHeight() const