Added support for setting background colour of Pdf document.

This commit is contained in:
Robert Osfield 2008-12-09 09:26:51 +00:00
parent c0ac01c576
commit d8c17e4c4c
8 changed files with 25 additions and 13 deletions

View File

@ -20,6 +20,7 @@ int main(int argc,char** argv)
osgWidget::GeometryHints hints(osg::Vec3(1.0f,0.0f,0.0f),
osg::Vec3(1.0f,0.0f,0.0f),
osg::Vec3(0.0f,0.0f,1.0f),
osg::Vec4(1.0f,1.0f,1.0f,1.0f),
osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO);
osg::ref_ptr<osg::Group> group = new osg::Group;

View File

@ -1,5 +1,7 @@
SET(TARGET_SRC osgvnc.cpp)
SET(TARGET_ADDED_LIBRARIES osgWidget )
#### end var setup ###
SETUP_EXAMPLE(osgvnc)

View File

@ -4,6 +4,8 @@
#include <osgGA/TrackballManipulator>
#include <osgWidget/VncClient>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
@ -50,6 +52,7 @@ int main(int argc,char** argv)
osgWidget::GeometryHints hints(osg::Vec3(1.0f,0.0f,0.0f),
osg::Vec3(1.0f,0.0f,0.0f),
osg::Vec3(0.0f,0.0f,1.0f),
osg::Vec4(1.0f,1.0f,1.0f,1.0f),
osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO);
osg::ref_ptr<osg::Group> group = new osg::Group;

View File

@ -36,20 +36,24 @@ struct GeometryHints
position(0.0f,0.0f,0.0f),
widthVec(1.0f,0.0f,0.0f),
heightVec(0.0f,1.0f,0.0f),
backgroundColor(1.0f,1.0f,1.0f,1.0f),
aspectRatioPolicy(RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO) {}
GeometryHints(const osg::Vec3& pos,
const osg::Vec3& wVec,
const osg::Vec3& hVec,
const osg::Vec4& bColor,
AspectRatioPolicy asp=RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO):
position(pos),
widthVec(wVec),
heightVec(hVec),
backgroundColor(bColor),
aspectRatioPolicy(asp) {}
osg::Vec3 position;
osg::Vec3 widthVec;
osg::Vec3 heightVec;
osg::Vec4 backgroundColor;
AspectRatioPolicy aspectRatioPolicy;
};
@ -60,10 +64,14 @@ class PdfImage : public osg::Image
public:
PdfImage():
_backgroundColor(1.0f,1.0f,1.0f,1.0f),
_pageNum(0),
_nextPageKeyEvent('n'),
_previousPageKeyEvent('p') {}
void setBackgroundColor(const osg::Vec4& backgroundColor) { _backgroundColor = backgroundColor; }
const osg::Vec4& getBackgroundColor() const { return _backgroundColor; }
int getPageNum() const { return _pageNum; }
virtual int getNumOfPages() = 0;
@ -90,6 +98,8 @@ class PdfImage : public osg::Image
virtual ~PdfImage() {}
osg::Vec4 _backgroundColor;
int _pageNum;
int _nextPageKeyEvent;
int _previousPageKeyEvent;

View File

@ -4,7 +4,7 @@ INCLUDE_DIRECTORIES( ${CAIRO_INCLUDE_DIRS} ${POPPLER_INCLUDE_DIRS} )
LINK_DIRECTORIES(${CAIRO_LIBRARY_DIRS} ${POPPLER_LIB_DIRS})
SET(TARGET_EXTERNAL_LIBRARIES ${CAIRO_LIBRARIES} ${POPPLER_LIBRARIES} )
SET(TARGET_ADDED_LIBRARIES osgWidget )
SET(TARGET_ADDED_LIBRARIES osgWidget osgVolume)
#### end var setup ###
SETUP_PLUGIN(pdf)

View File

@ -16,6 +16,7 @@
#include <osgDB/FileUtils>
#include <osgWidget/PdfReader>
#include <osgVolume/ImageUtils>
#include <cairo.h>
#include <poppler.h>
@ -196,22 +197,14 @@ class PopplerPdfImage : public osgWidget::PdfImage
_cairoImage->create((unsigned int)(w*2.0),(unsigned int)(h*2.0));
double r = 1.0;
double g = 1.0;
double b = 1.0;
double a = 1.0;
osgVolume::clearImageToColor(this, _backgroundColor);
cairo_save(_cairoImage->getContext());
cairo_set_source_rgba(_cairoImage->getContext(), r, g, b, a);
cairo_rectangle(_cairoImage->getContext(), 0.0, 0.0, double(s()), double(t()));
cairo_fill(_cairoImage->getContext());
cairo_scale(_cairoImage->getContext(), double(s())/w, double(t())/h);
poppler_page_render(page, _cairoImage->getContext());
cairo_restore(_cairoImage->getContext());
dirty();

View File

@ -676,7 +676,7 @@ bool InteractiveImageHandler::mousePosition(osgViewer::View* view, osg::NodeVisi
x = int( tc.x() );
y = int( tc.y() );
}
else
else if (_image.valid())
{
x = int( float(_image->s()) * tc.x() );
y = int( float(_image->t()) * tc.y() );
@ -694,6 +694,8 @@ bool InteractiveImageHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUI
{
if (ea.getHandled()) return false;
if (!_image) return false;
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::MOVE):

View File

@ -31,6 +31,7 @@ bool PdfReader::assign(PdfImage* pdfImage, GeometryHints hints)
if (!pdfImage) return false;
_pdfImage = pdfImage;
_pdfImage->setBackgroundColor(hints.backgroundColor);
bool flip = _pdfImage->getOrigin()==osg::Image::TOP_LEFT;