1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
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.
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.
14#ifndef OSGWIDGET_PDFREADER
15#define OSGWIDGET_PDFREADER
20#include <osgWidget/Export>
25/** Hints structure that can be passed to PdfReader and VncClient classes to help guide them on what geometry to build.*/
28 enum AspectRatioPolicy
30 RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO,
31 RESIZE_WIDTH_TO_MAINTAINCE_ASPECT_RATIO,
32 IGNORE_DOCUMENT_ASPECT_RATIO
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) {}
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):
54 backgroundColor(bColor),
55 aspectRatioPolicy(asp),
56 widthResolution(wRes),
57 heightResolution(hRes) {}
63 osg::Vec4 backgroundColor;
65 AspectRatioPolicy aspectRatioPolicy;
67 unsigned int widthResolution;
68 unsigned int heightResolution;
72/** Pure virtual base class for interfacing with implementation of PDF reader.*/
73class PdfImage : public osg::Image
78 _backgroundColor(1.0f,1.0f,1.0f,1.0f),
80 _nextPageKeyEvent('n'),
81 _previousPageKeyEvent('p') {}
83 void setBackgroundColor(const osg::Vec4& backgroundColor) { _backgroundColor = backgroundColor; }
84 const osg::Vec4& getBackgroundColor() const { return _backgroundColor; }
86 int getPageNum() const { return _pageNum; }
88 virtual int getNumOfPages() = 0;
90 virtual bool page(int pageNum) = 0;
94 return page(_pageNum-1);
99 return page(_pageNum+1);
102 void setNextPageKeyEvent(int key) { _nextPageKeyEvent = key; }
103 int getNextPageKeyEvent() const { return _nextPageKeyEvent; }
105 void setPreviousPageKeyEvent(int key) { _previousPageKeyEvent = key; }
106 int getPreviousPageKeyEvent() const { return _previousPageKeyEvent; }
110 virtual ~PdfImage() {}
112 osg::Vec4 _backgroundColor;
115 int _nextPageKeyEvent;
116 int _previousPageKeyEvent;
121/** Convenience class that provides a interactive quad that can be placed directly in the scene.*/
122class OSGWIDGET_EXPORT PdfReader : public osg::Geode
128 PdfReader(const std::string& filename, const GeometryHints& hints = GeometryHints());
130 bool assign(PdfImage* pdfImage, const GeometryHints& hints = GeometryHints());
132 bool open(const std::string& filename, const GeometryHints& hints = GeometryHints());
134 bool page(int pageNum);
142 osg::ref_ptr<PdfImage> _pdfImage;