Added support for setting background colour of Pdf document.
This commit is contained in:
parent
c0ac01c576
commit
d8c17e4c4c
@ -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;
|
||||
|
@ -1,5 +1,7 @@
|
||||
SET(TARGET_SRC osgvnc.cpp)
|
||||
|
||||
SET(TARGET_ADDED_LIBRARIES osgWidget )
|
||||
|
||||
#### end var setup ###
|
||||
SETUP_EXAMPLE(osgvnc)
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
@ -85,11 +93,13 @@ class PdfImage : public osg::Image
|
||||
|
||||
void setPreviousPageKeyEvent(int key) { _previousPageKeyEvent = key; }
|
||||
int getPreviousPageKeyEvent() const { return _previousPageKeyEvent; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~PdfImage() {}
|
||||
|
||||
osg::Vec4 _backgroundColor;
|
||||
|
||||
int _pageNum;
|
||||
int _nextPageKeyEvent;
|
||||
int _previousPageKeyEvent;
|
||||
|
@ -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)
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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())
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user