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

@@ -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,21 +197,13 @@ 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());

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() );
@@ -693,6 +693,8 @@ bool InteractiveImageHandler::mousePosition(osgViewer::View* view, osg::NodeVisi
bool InteractiveImageHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv)
{
if (ea.getHandled()) return false;
if (!_image) return false;
switch(ea.getEventType())
{

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;