2004-09-08 12:41:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2004-11-06 01:19:35 +00:00
|
|
|
// qt/kde includes
|
2004-09-08 12:41:14 +00:00
|
|
|
#include <qpixmap.h>
|
|
|
|
#include <qstring.h>
|
2004-09-15 20:45:00 +00:00
|
|
|
#include <qmap.h>
|
2004-12-10 16:04:45 +00:00
|
|
|
#include <kdebug.h>
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
// local includes
|
|
|
|
#include "page.h"
|
2005-01-02 22:33:28 +00:00
|
|
|
#include "pagetransition.h"
|
2004-12-10 16:04:45 +00:00
|
|
|
#include "link.h"
|
2005-01-02 14:37:49 +00:00
|
|
|
#include "conf/settings.h"
|
2004-12-10 16:04:45 +00:00
|
|
|
#include "xpdf/TextOutputDev.h"
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2004-09-10 17:44:05 +00:00
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
/** class KPDFPage **/
|
|
|
|
|
2004-11-06 00:56:55 +00:00
|
|
|
KPDFPage::KPDFPage( uint page, float w, float h, int r )
|
|
|
|
: m_number( page ), m_rotation( r ), m_attributes( 0 ),
|
|
|
|
m_width( w ), m_height( h ), m_sLeft( 0 ), m_sTop( 0 ),
|
2005-01-02 20:32:58 +00:00
|
|
|
m_sRight( 0 ), m_sBottom( 0 ), m_text( 0 ), m_transition( 0 )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-10-17 17:20:51 +00:00
|
|
|
// if landscape swap width <-> height (rotate 90deg CCW)
|
|
|
|
if ( r == 90 || r == 270 )
|
|
|
|
{
|
|
|
|
m_width = h;
|
|
|
|
m_height = w;
|
|
|
|
}
|
2005-01-18 16:43:36 +00:00
|
|
|
// avoid Division-By-Zero problems in the program
|
|
|
|
if ( m_width <= 0 )
|
|
|
|
m_width = 1;
|
|
|
|
if ( m_height <= 0 )
|
|
|
|
m_height = 1;
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KPDFPage::~KPDFPage()
|
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
deletePixmapsAndRects();
|
2004-09-08 12:41:14 +00:00
|
|
|
delete m_text;
|
2005-01-02 20:39:41 +00:00
|
|
|
delete m_transition;
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-15 20:45:00 +00:00
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
bool KPDFPage::hasPixmap( int id, int width, int height ) const
|
|
|
|
{
|
|
|
|
if ( !m_pixmaps.contains( id ) )
|
|
|
|
return false;
|
2004-12-21 12:38:52 +00:00
|
|
|
if ( width == -1 || height == -1 )
|
|
|
|
return true;
|
2004-09-16 21:04:49 +00:00
|
|
|
QPixmap * p = m_pixmaps[ id ];
|
|
|
|
return p ? ( p->width() == width && p->height() == height ) : false;
|
|
|
|
}
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
bool KPDFPage::hasSearchPage() const
|
|
|
|
{
|
|
|
|
return m_text != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KPDFPage::hasRect( int mouseX, int mouseY ) const
|
2004-09-16 21:04:49 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
if ( m_rects.count() < 1 )
|
2004-10-02 14:30:30 +00:00
|
|
|
return false;
|
2004-12-10 16:04:45 +00:00
|
|
|
QValueList< KPDFPageRect * >::const_iterator it = m_rects.begin(), end = m_rects.end();
|
2004-10-02 14:30:30 +00:00
|
|
|
for ( ; it != end; ++it )
|
|
|
|
if ( (*it)->contains( mouseX, mouseY ) )
|
|
|
|
return true;
|
|
|
|
return false;
|
2004-09-16 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-26 21:20:17 +00:00
|
|
|
bool KPDFPage::hasLink( int mouseX, int mouseY ) const
|
|
|
|
{
|
|
|
|
const KPDFPageRect *r;
|
|
|
|
r = getRect( mouseX, mouseY);
|
|
|
|
return r && r->pointerType() == KPDFPageRect::Link;
|
|
|
|
}
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
const KPDFPageRect * KPDFPage::getRect( int mouseX, int mouseY ) const
|
2004-10-20 16:27:20 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
QValueList< KPDFPageRect * >::const_iterator it = m_rects.begin(), end = m_rects.end();
|
2004-10-20 16:27:20 +00:00
|
|
|
for ( ; it != end; ++it )
|
|
|
|
if ( (*it)->contains( mouseX, mouseY ) )
|
2004-12-10 16:04:45 +00:00
|
|
|
return *it;
|
|
|
|
return 0;
|
2004-10-20 16:27:20 +00:00
|
|
|
}
|
|
|
|
|
2005-01-02 20:32:58 +00:00
|
|
|
const KPDFPageTransition * KPDFPage::getTransition() const
|
|
|
|
{
|
|
|
|
return m_transition;
|
|
|
|
}
|
|
|
|
|
2005-01-10 13:43:44 +00:00
|
|
|
const QPoint KPDFPage::getLastSearchCenter() const
|
|
|
|
{
|
|
|
|
int centerX = (int)((m_sRight + m_sLeft) / 2),
|
|
|
|
centerY = (int)((m_sTop + m_sBottom) / 2);
|
|
|
|
return QPoint( centerX, centerY );
|
|
|
|
}
|
|
|
|
|
2004-11-06 00:56:55 +00:00
|
|
|
const QString KPDFPage::getTextInRect( const QRect & rect, double zoom ) const
|
|
|
|
{
|
|
|
|
if ( !m_text )
|
|
|
|
return QString::null;
|
|
|
|
int left = (int)((double)rect.left() / zoom),
|
|
|
|
top = (int)((double)rect.top() / zoom),
|
|
|
|
right = (int)((double)rect.right() / zoom),
|
|
|
|
bottom = (int)((double)rect.bottom() / zoom);
|
|
|
|
GString * text = m_text->getText( left, top, right, bottom );
|
2005-01-17 18:27:31 +00:00
|
|
|
QString result = QString::fromUtf8( text->getCString() );
|
|
|
|
delete text;
|
|
|
|
return result;
|
2004-11-06 00:56:55 +00:00
|
|
|
}
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
bool KPDFPage::hasText( const QString & text, bool strictCase, bool fromTop )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-09-16 21:04:49 +00:00
|
|
|
if ( !m_text )
|
2004-09-15 20:45:00 +00:00
|
|
|
return false;
|
2004-09-16 21:04:49 +00:00
|
|
|
|
2005-01-08 17:13:36 +00:00
|
|
|
const QChar* str = text.unicode();
|
2004-09-16 21:04:49 +00:00
|
|
|
int len = text.length();
|
|
|
|
Unicode *u = (Unicode *)gmalloc(len * sizeof(Unicode));
|
|
|
|
for (int i = 0; i < len; ++i)
|
2005-01-08 17:13:36 +00:00
|
|
|
u[i] = str[i].unicode();
|
2004-09-16 21:04:49 +00:00
|
|
|
|
2005-01-10 13:43:44 +00:00
|
|
|
bool found = false;
|
|
|
|
while ( !found )
|
2004-09-16 21:04:49 +00:00
|
|
|
{
|
2005-01-10 13:43:44 +00:00
|
|
|
found = m_text->findText( u, len, fromTop ? gTrue : gFalse, gTrue, fromTop ? gFalse : gTrue, gFalse, &m_sLeft, &m_sTop, &m_sRight, &m_sBottom );
|
|
|
|
if ( !found )
|
|
|
|
break;
|
|
|
|
if( strictCase )
|
|
|
|
{
|
|
|
|
// since we're in 'Case sensitive' mode, check if words are identical
|
|
|
|
GString * orig = m_text->getText( m_sLeft, m_sTop, m_sRight, m_sBottom );
|
|
|
|
found = QString::fromUtf8( orig->getCString() ) == text;
|
|
|
|
if ( !found && fromTop )
|
|
|
|
fromTop = false;
|
|
|
|
}
|
2004-09-16 21:04:49 +00:00
|
|
|
}
|
2004-12-26 22:34:50 +00:00
|
|
|
gfree(u);
|
2004-09-16 21:04:49 +00:00
|
|
|
return found;
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-15 20:45:00 +00:00
|
|
|
void KPDFPage::setPixmap( int id, QPixmap * pixmap )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-09-30 18:07:15 +00:00
|
|
|
if ( m_pixmaps.contains( id ) )
|
2004-09-15 20:45:00 +00:00
|
|
|
delete m_pixmaps[id];
|
|
|
|
m_pixmaps[id] = pixmap;
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
void KPDFPage::setSearchPage( TextPage * tp )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-09-10 17:44:05 +00:00
|
|
|
delete m_text;
|
2004-09-16 21:04:49 +00:00
|
|
|
m_text = tp;
|
2004-09-10 17:44:05 +00:00
|
|
|
}
|
2004-09-11 15:59:32 +00:00
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
void KPDFPage::setRects( const QValueList< KPDFPageRect * > rects )
|
2004-10-20 16:27:20 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
QValueList< KPDFPageRect * >::iterator it = m_rects.begin(), end = m_rects.end();
|
2004-10-20 16:27:20 +00:00
|
|
|
for ( ; it != end; ++it )
|
|
|
|
delete *it;
|
|
|
|
m_rects = rects;
|
|
|
|
}
|
|
|
|
|
2005-01-02 20:32:58 +00:00
|
|
|
void KPDFPage::setTransition( const KPDFPageTransition * transition )
|
|
|
|
{
|
2005-01-02 21:49:27 +00:00
|
|
|
delete m_transition;
|
2005-01-02 20:32:58 +00:00
|
|
|
m_transition = transition;
|
|
|
|
}
|
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
void KPDFPage::deletePixmap( int id )
|
|
|
|
{
|
|
|
|
if ( m_pixmaps.contains( id ) )
|
|
|
|
{
|
|
|
|
delete m_pixmaps[ id ];
|
|
|
|
m_pixmaps.remove( id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
void KPDFPage::deletePixmapsAndRects()
|
2004-11-12 10:58:33 +00:00
|
|
|
{
|
|
|
|
// delete all stored pixmaps
|
|
|
|
QMap<int,QPixmap *>::iterator it = m_pixmaps.begin(), end = m_pixmaps.end();
|
|
|
|
for ( ; it != end; ++it )
|
|
|
|
delete *it;
|
|
|
|
m_pixmaps.clear();
|
2004-12-10 16:04:45 +00:00
|
|
|
// delete PageRects
|
|
|
|
QValueList< KPDFPageRect * >::iterator rIt = m_rects.begin(), rEnd = m_rects.end();
|
2004-11-12 10:58:33 +00:00
|
|
|
for ( ; rIt != rEnd; ++rIt )
|
|
|
|
delete *rIt;
|
|
|
|
m_rects.clear();
|
|
|
|
}
|
|
|
|
|
2004-11-06 00:56:55 +00:00
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
/** class KPDFPageRect **/
|
|
|
|
|
|
|
|
KPDFPageRect::KPDFPageRect( int l, int t, int r, int b )
|
|
|
|
: m_pointerType( NoPointer ), m_pointer( 0 )
|
|
|
|
{
|
|
|
|
// assign coordinates swapping them if negative width or height
|
|
|
|
m_xMin = r > l ? l : r;
|
|
|
|
m_xMax = r > l ? r : l;
|
|
|
|
m_yMin = b > t ? t : b;
|
|
|
|
m_yMax = b > t ? b : t;
|
|
|
|
}
|
|
|
|
|
|
|
|
KPDFPageRect::~KPDFPageRect()
|
|
|
|
{
|
|
|
|
deletePointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KPDFPageRect::contains( int x, int y ) const
|
|
|
|
{
|
|
|
|
return (x > m_xMin) && (x < m_xMax) && (y > m_yMin) && (y < m_yMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect KPDFPageRect::geometry() const
|
|
|
|
{
|
|
|
|
return QRect( m_xMin, m_yMin, m_xMax - m_xMin, m_yMax - m_yMin );
|
|
|
|
}
|
|
|
|
|
|
|
|
void KPDFPageRect::setPointer( void * object, enum PointerType pType )
|
|
|
|
{
|
|
|
|
deletePointer();
|
|
|
|
m_pointer = object;
|
|
|
|
m_pointerType = pType;
|
|
|
|
}
|
|
|
|
|
|
|
|
KPDFPageRect::PointerType KPDFPageRect::pointerType() const
|
|
|
|
{
|
|
|
|
return m_pointerType;
|
|
|
|
}
|
|
|
|
|
|
|
|
const void * KPDFPageRect::pointer() const
|
|
|
|
{
|
|
|
|
return m_pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KPDFPageRect::deletePointer()
|
|
|
|
{
|
|
|
|
if ( !m_pointer )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( m_pointerType == Link )
|
|
|
|
delete static_cast<KPDFLink*>( m_pointer );
|
|
|
|
else
|
|
|
|
kdDebug() << "Object deletion not implemented for type '"
|
|
|
|
<< m_pointerType << "' ." << endl;
|
|
|
|
}
|