PdfReader 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGWIDGET_PDFREADER
  14. #define OSGWIDGET_PDFREADER
  15. #include <osg/Image>
  16. #include <osg/Geode>
  17. #include <osgWidget/Export>
  18. namespace osgWidget {
  19. /** Hints structure that can be passed to PdfReader and VncClient classes to help guide them on what geometry to build.*/
  20. struct GeometryHints
  21. {
  22. enum AspectRatioPolicy
  23. {
  24. RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO,
  25. RESIZE_WIDTH_TO_MAINTAINCE_ASPECT_RATIO,
  26. IGNORE_DOCUMENT_ASPECT_RATIO
  27. };
  28. GeometryHints():
  29. position(0.0f,0.0f,0.0f),
  30. widthVec(1.0f,0.0f,0.0f),
  31. heightVec(0.0f,1.0f,0.0f),
  32. backgroundColor(1.0f,1.0f,1.0f,1.0f),
  33. aspectRatioPolicy(RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO),
  34. widthResolution(1024),
  35. heightResolution(1024) {}
  36. GeometryHints(const osg::Vec3& pos,
  37. const osg::Vec3& wVec,
  38. const osg::Vec3& hVec,
  39. const osg::Vec4& bColor,
  40. AspectRatioPolicy asp=RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO,
  41. unsigned int wRes=1024,
  42. unsigned int hRes=1024):
  43. position(pos),
  44. widthVec(wVec),
  45. heightVec(hVec),
  46. backgroundColor(bColor),
  47. aspectRatioPolicy(asp),
  48. widthResolution(wRes),
  49. heightResolution(hRes) {}
  50. osg::Vec3 position;
  51. osg::Vec3 widthVec;
  52. osg::Vec3 heightVec;
  53. osg::Vec4 backgroundColor;
  54. AspectRatioPolicy aspectRatioPolicy;
  55. unsigned int widthResolution;
  56. unsigned int heightResolution;
  57. };
  58. /** Pure virtual base class for interfacing with implementation of PDF reader.*/
  59. class PdfImage : public osg::Image
  60. {
  61. public:
  62. PdfImage():
  63. _backgroundColor(1.0f,1.0f,1.0f,1.0f),
  64. _pageNum(0),
  65. _nextPageKeyEvent('n'),
  66. _previousPageKeyEvent('p') {}
  67. void setBackgroundColor(const osg::Vec4& backgroundColor) { _backgroundColor = backgroundColor; }
  68. const osg::Vec4& getBackgroundColor() const { return _backgroundColor; }
  69. int getPageNum() const { return _pageNum; }
  70. virtual int getNumOfPages() = 0;
  71. virtual bool page(int pageNum) = 0;
  72. bool previous()
  73. {
  74. return page(_pageNum-1);
  75. }
  76. bool next()
  77. {
  78. return page(_pageNum+1);
  79. }
  80. void setNextPageKeyEvent(int key) { _nextPageKeyEvent = key; }
  81. int getNextPageKeyEvent() const { return _nextPageKeyEvent; }
  82. void setPreviousPageKeyEvent(int key) { _previousPageKeyEvent = key; }
  83. int getPreviousPageKeyEvent() const { return _previousPageKeyEvent; }
  84. protected:
  85. virtual ~PdfImage() {}
  86. osg::Vec4 _backgroundColor;
  87. int _pageNum;
  88. int _nextPageKeyEvent;
  89. int _previousPageKeyEvent;
  90. };
  91. /** Convenience class that provides a interactive quad that can be placed directly in the scene.*/
  92. class OSGWIDGET_EXPORT PdfReader : public osg::Geode
  93. {
  94. public:
  95. PdfReader() {}
  96. PdfReader(const std::string& filename, const GeometryHints& hints = GeometryHints());
  97. bool assign(PdfImage* pdfImage, const GeometryHints& hints = GeometryHints());
  98. bool open(const std::string& filename, const GeometryHints& hints = GeometryHints());
  99. bool page(int pageNum);
  100. bool previous();
  101. bool next();
  102. protected:
  103. osg::ref_ptr<PdfImage> _pdfImage;
  104. };
  105. }
  106. #endif