Commit d07efe68 authored by Enrico Ros's avatar Enrico Ros
Browse files

Preliminar support for saving images with RMB popup.

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=356240
parent fbc3b2ff
......@@ -24,6 +24,7 @@
#include <qimage.h>
#include "page.h"
#include "GfxState.h"
#include "SplashBitmap.h"
#include "TextOutputDev.h"
#include "QOutputDev.h"
......@@ -39,10 +40,13 @@ KPDFOutputDev::KPDFOutputDev(SplashColor paperColor)
KPDFOutputDev::~KPDFOutputDev()
{
QValueList< KPDFLink * >::iterator it = m_links.begin(), end = m_links.end();
for ( ; it != end; ++it )
delete *it;
delete m_pixmap;
QValueList< KPDFLink * >::iterator itL = m_links.begin(), endL = m_links.end();
for ( ; itL != endL; ++itL )
delete *itL;
QValueList< KPDFActiveRect * >::iterator itR = m_rects.begin(), endR = m_rects.end();
for ( ; itR != endR; ++itR )
delete *itR;
delete m_pixmap;
delete m_text;
}
......@@ -86,6 +90,13 @@ QValueList< KPDFLink * > KPDFOutputDev::takeLinks()
return linksCopy;
}
QValueList< KPDFActiveRect * > KPDFOutputDev::takeActiveRects()
{
QValueList< KPDFActiveRect * > rectsCopy( m_rects );
m_rects.clear();
return rectsCopy;
}
void KPDFOutputDev::startPage(int pageNum, GfxState *state)
{
m_pageNum = pageNum;
......@@ -120,7 +131,7 @@ void KPDFOutputDev::endPage()
SplashOutputDev::startPage(0, NULL);
}
void KPDFOutputDev::drawLink(Link * link, Catalog */*catalog*/)
void KPDFOutputDev::drawLink(Link * link, Catalog * catalog)
{
if ( !link->isOk() )
return;
......@@ -137,6 +148,9 @@ void KPDFOutputDev::drawLink(Link * link, Catalog */*catalog*/)
// add the link to the vector container
m_links.push_back( l );
// call parent's link handler
SplashOutputDev::drawLink(link, catalog);
}
void KPDFOutputDev::updateFont(GfxState *state)
......@@ -159,6 +173,48 @@ GBool KPDFOutputDev::beginType3Char(GfxState *state, double x, double y, double
m_text->addChar(state, x, y, dx, dy, code, u, uLen);
return SplashOutputDev::beginType3Char(state, x, y, dx, dy, code, u, uLen);
}
/*void KPDFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg)
{
double * ctm = state->getCTM();
printf("> %d %d %f %f %f %f %f %f\n", width, height, ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
SplashOutputDev::drawImageMask(state, ref, str, width, height, invert, inlineImg);
}
*/
void KPDFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
int _width, int _height, GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg)
{
// find out image rect from the Coord Transform Matrix
double * ctm = state->getCTM();
int left = (int)ctm[4],
top = (int)ctm[5],
width = (int)ctm[0],
height = (int)ctm[3];
// normalize width
if ( width < 0 )
{
width = -width;
left -= width;
}
// normalize height
if ( height < 0 )
{
height = -height;
top -= height;
}
if ( width > 10 && height > 10 )
{
KPDFActiveRect * r = new KPDFActiveRect(left, top, width, height);
// add the rect to the vector container
m_rects.push_back( r );
}
// call parent's image handler
SplashOutputDev::drawImage(state, ref, str, _width, _height, colorMap, maskColors, inlineImg);
}
// END KPDFOutputDev
......
......@@ -24,6 +24,7 @@
class TextPage;
class KPDFLink;
class KPDFActiveRect;
/**
* @short A SplashOutputDev renderer that grabs text and links.
......@@ -45,9 +46,10 @@ public:
// takes pointers out of the class (so deletion it's up to others)
QPixmap * takePixmap();
TextPage * takeTextPage();
QValueList< KPDFLink * > takeLinks();
QValueList< KPDFLink * > takeLinks();
QValueList< KPDFActiveRect * > takeActiveRects();
/** inherited from OutputDev */
/** inherited from OutputDev */
// Start a page.
virtual void startPage(int pageNum, GfxState *state);
// End a page.
......@@ -59,6 +61,13 @@ public:
//----- text drawing
virtual void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, Unicode *u, int uLen);
virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
//----- image drawing
/* virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg);*/
virtual void drawImage(GfxState *state, Object *ref, Stream *str,
int width, int height, GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg);
private:
// the pixmap where the page is drawn (generated on every execution)
......@@ -71,7 +80,10 @@ private:
TextPage * m_text;
// links generated on demand
QValueList< KPDFLink * > m_links;
QValueList< KPDFLink * > m_links;
// active areas on page
QValueList< KPDFActiveRect * > m_rects;
};
......
......@@ -47,6 +47,9 @@ KPDFPage::~KPDFPage()
QValueList< KPDFLink * >::iterator lIt = m_links.begin(), lEnd = m_links.end();
for ( ; lIt != lEnd; ++lIt )
delete *lIt;
QValueList< KPDFActiveRect * >::iterator rIt = m_rects.begin(), rEnd = m_rects.end();
for ( ; rIt != rEnd; ++rIt )
delete *rIt;
delete m_text;
}
......@@ -83,6 +86,17 @@ bool KPDFPage::hasLink( int mouseX, int mouseY ) const
return false;
}
bool KPDFPage::hasActiveRect( int mouseX, int mouseY ) const
{
if ( m_rects.count() < 1 )
return false;
QValueList< KPDFActiveRect * >::const_iterator it = m_rects.begin(), end = m_rects.end();
for ( ; it != end; ++it )
if ( (*it)->contains( mouseX, mouseY ) )
return true;
return false;
}
// BEGIN commands (paint / search)
const KPDFLink * KPDFPage::getLink( int mouseX, int mouseY ) const
{
......@@ -212,6 +226,14 @@ void KPDFPage::setLinks( const QValueList<KPDFLink *> links )
m_links = links;
}
void KPDFPage::setActiveRects( const QValueList<KPDFActiveRect *> rects )
{
QValueList< KPDFActiveRect * >::iterator it = m_rects.begin(), end = m_rects.end();
for ( ; it != end; ++it )
delete *it;
m_rects = rects;
}
/*
void KPDFPage::setPixmapOverlayNotations( ..DOMdescription.. )
{ //TODO this
......@@ -355,3 +377,15 @@ const char * KPDFLink::getURI() const
{
return m_uri;
}
KPDFActiveRect::KPDFActiveRect(int left, int top, int width, int height)
: m_left(left), m_top(top), m_right(left + width), m_bottom(top + height)
{
}
bool KPDFActiveRect::contains(int x, int y)
{
return (x > m_left) && (x < m_right) && (y > m_top) && (y < m_bottom);
}
......@@ -19,6 +19,7 @@ class TextPage;
class LinkAction;
class LinkDest;
class KPDFLink;
class KPDFActiveRect;
/**
* @short Collector for all the data belonging to a page.
......@@ -48,6 +49,7 @@ public:
QString getTextInRect( const QRect & rect ) const;
bool hasLink( int mouseX, int mouseY ) const;
const KPDFLink * getLink( int mouseX, int mouseY ) const;
bool hasActiveRect( int mouseX, int mouseY ) const;
void drawPixmap( int id, QPainter * p, const QRect & rect, int width, int height ) const;
// commands (not const methods caled by KPDFDocument)
......@@ -59,6 +61,7 @@ public:
void setPixmap( int id, QPixmap * pixmap );
void setSearchPage( TextPage * text );
void setLinks( const QValueList<KPDFLink *> links );
void setActiveRects( const QValueList<KPDFActiveRect *> rects );
/*void setPixmapOverlayNotations( ..DOMdescription.. );*/
private:
......@@ -70,6 +73,7 @@ private:
QMap< int, QPixmap * > m_pixmaps;
TextPage * m_text;
QValueList< KPDFLink * > m_links;
QValueList< KPDFActiveRect * > m_rects;
};
......@@ -122,4 +126,22 @@ private:
int m_refNum, m_refGen;
};
/**
* @short Describes an 'active' rectange on the page.
*
* ...
*/
class KPDFActiveRect
{
public:
KPDFActiveRect(int left, int top, int width, int height);
// query
bool contains(int x, int y);
private:
int m_left, m_top, m_right, m_bottom;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment