| 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 | |
|---|
| 14 | #ifndef OSGWIDGET_PDFREADER |
|---|
| 15 | #define OSGWIDGET_PDFREADER |
|---|
| 16 | |
|---|
| 17 | #include <osg/Image> |
|---|
| 18 | #include <osg/Geode> |
|---|
| 19 | |
|---|
| 20 | #include <osgWidget/Export> |
|---|
| 21 | |
|---|
| 22 | namespace osgWidget { |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | /** Hints structure that can be passed to PdfReader and VncClient classes to help guide them on what geometry to build.*/ |
|---|
| 26 | struct GeometryHints |
|---|
| 27 | { |
|---|
| 28 | enum AspectRatioPolicy |
|---|
| 29 | { |
|---|
| 30 | RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO, |
|---|
| 31 | RESIZE_WIDTH_TO_MAINTAINCE_ASPECT_RATIO, |
|---|
| 32 | IGNORE_DOCUMENT_ASPECT_RATIO |
|---|
| 33 | }; |
|---|
| 34 | |
|---|
| 35 | GeometryHints(): |
|---|
| 36 | position(0.0f,0.0f,0.0f), |
|---|
| 37 | widthVec(1.0f,0.0f,0.0f), |
|---|
| 38 | heightVec(0.0f,1.0f,0.0f), |
|---|
| 39 | backgroundColor(1.0f,1.0f,1.0f,1.0f), |
|---|
| 40 | aspectRatioPolicy(RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO), |
|---|
| 41 | widthResolution(1024), |
|---|
| 42 | heightResolution(1024) {} |
|---|
| 43 | |
|---|
| 44 | GeometryHints(const osg::Vec3& pos, |
|---|
| 45 | const osg::Vec3& wVec, |
|---|
| 46 | const osg::Vec3& hVec, |
|---|
| 47 | const osg::Vec4& bColor, |
|---|
| 48 | AspectRatioPolicy asp=RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO, |
|---|
| 49 | unsigned int wRes=1024, |
|---|
| 50 | unsigned int hRes=1024): |
|---|
| 51 | position(pos), |
|---|
| 52 | widthVec(wVec), |
|---|
| 53 | heightVec(hVec), |
|---|
| 54 | backgroundColor(bColor), |
|---|
| 55 | aspectRatioPolicy(asp), |
|---|
| 56 | widthResolution(wRes), |
|---|
| 57 | heightResolution(hRes) {} |
|---|
| 58 | |
|---|
| 59 | osg::Vec3 position; |
|---|
| 60 | osg::Vec3 widthVec; |
|---|
| 61 | osg::Vec3 heightVec; |
|---|
| 62 | |
|---|
| 63 | osg::Vec4 backgroundColor; |
|---|
| 64 | |
|---|
| 65 | AspectRatioPolicy aspectRatioPolicy; |
|---|
| 66 | |
|---|
| 67 | unsigned int widthResolution; |
|---|
| 68 | unsigned int heightResolution; |
|---|
| 69 | |
|---|
| 70 | }; |
|---|
| 71 | |
|---|
| 72 | /** Pure virtual base class for interfacing with implementation of PDF reader.*/ |
|---|
| 73 | class PdfImage : public osg::Image |
|---|
| 74 | { |
|---|
| 75 | public: |
|---|
| 76 | |
|---|
| 77 | PdfImage(): |
|---|
| 78 | _backgroundColor(1.0f,1.0f,1.0f,1.0f), |
|---|
| 79 | _pageNum(0), |
|---|
| 80 | _nextPageKeyEvent('n'), |
|---|
| 81 | _previousPageKeyEvent('p') {} |
|---|
| 82 | |
|---|
| 83 | void setBackgroundColor(const osg::Vec4& backgroundColor) { _backgroundColor = backgroundColor; } |
|---|
| 84 | const osg::Vec4& getBackgroundColor() const { return _backgroundColor; } |
|---|
| 85 | |
|---|
| 86 | int getPageNum() const { return _pageNum; } |
|---|
| 87 | |
|---|
| 88 | virtual int getNumOfPages() = 0; |
|---|
| 89 | |
|---|
| 90 | virtual bool page(int pageNum) = 0; |
|---|
| 91 | |
|---|
| 92 | bool previous() |
|---|
| 93 | { |
|---|
| 94 | return page(_pageNum-1); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | bool next() |
|---|
| 98 | { |
|---|
| 99 | return page(_pageNum+1); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | void setNextPageKeyEvent(int key) { _nextPageKeyEvent = key; } |
|---|
| 103 | int getNextPageKeyEvent() const { return _nextPageKeyEvent; } |
|---|
| 104 | |
|---|
| 105 | void setPreviousPageKeyEvent(int key) { _previousPageKeyEvent = key; } |
|---|
| 106 | int getPreviousPageKeyEvent() const { return _previousPageKeyEvent; } |
|---|
| 107 | |
|---|
| 108 | protected: |
|---|
| 109 | |
|---|
| 110 | virtual ~PdfImage() {} |
|---|
| 111 | |
|---|
| 112 | osg::Vec4 _backgroundColor; |
|---|
| 113 | |
|---|
| 114 | int _pageNum; |
|---|
| 115 | int _nextPageKeyEvent; |
|---|
| 116 | int _previousPageKeyEvent; |
|---|
| 117 | |
|---|
| 118 | }; |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | /** Convinience class that provides a interactive quad that can be placed directly in the scene.*/ |
|---|
| 122 | class OSGWIDGET_EXPORT PdfReader : public osg::Geode |
|---|
| 123 | { |
|---|
| 124 | public: |
|---|
| 125 | |
|---|
| 126 | PdfReader() {} |
|---|
| 127 | |
|---|
| 128 | PdfReader(const std::string& filename, const GeometryHints& hints = GeometryHints()); |
|---|
| 129 | |
|---|
| 130 | bool assign(PdfImage* pdfImage, const GeometryHints& hints = GeometryHints()); |
|---|
| 131 | |
|---|
| 132 | bool open(const std::string& filename, const GeometryHints& hints = GeometryHints()); |
|---|
| 133 | |
|---|
| 134 | bool page(int pageNum); |
|---|
| 135 | |
|---|
| 136 | bool previous(); |
|---|
| 137 | |
|---|
| 138 | bool next(); |
|---|
| 139 | |
|---|
| 140 | protected: |
|---|
| 141 | |
|---|
| 142 | osg::ref_ptr<PdfImage> _pdfImage; |
|---|
| 143 | }; |
|---|
| 144 | |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | #endif |
|---|