Commit 56c98450 authored by Albert Astals Cid's avatar Albert Astals Cid

Improvements to the Qt4 frontend, comments welcome

parent c80ebf23
2006-04-02 Albert Astals Cid <aacid@kde.org>
* m4/qt.m4: Add QtXml lib to Qt4 binding as now it's needed
* qt4/src/poppler-document.cc: Add the possibility to get the toc of
a file, print it to PS and get a LinkDestination from a "symbolic" name
* qt4/src/poppler-page.cc: Add the possibility of getting the defaultCTM
2006-04-01 Albert Astals Cid <aacid@kde.org>
* poppler/XRef.cc: Fix parsing of some TOCs, bug was due a int to uint
......
......@@ -129,9 +129,9 @@ fi
if test "x$have_qt4" == "xyes"; then
$1[]_CXXFLAGS="-I$qt4_incdir"
if test x$windows_qt = xyes; then
$1[]_LIBS="-L$qt4_libdir -lQtCore4 -lQtGui4"
$1[]_LIBS="-L$qt4_libdir -lQtCore4 -lQtGui4 -lQtXml4"
else
$1[]_LIBS="-L$qt4_libdir -lQtCore -lQtGui"
$1[]_LIBS="-L$qt4_libdir -lQtCore -lQtGui -lQtXml"
fi
ifelse([$2], , :, [$2])
else
......
......@@ -19,6 +19,7 @@ libpoppler_qt4_la_SOURCES = \
poppler-fontinfo.cc \
poppler-embeddedfile.cc \
poppler-textbox.cc \
poppler-link.cc \
../../qt/poppler-page-transition.cc \
poppler-private.h
......
......@@ -18,19 +18,26 @@
*/
#define UNSTABLE_POPPLER_QT4
#include <poppler-qt4.h>
#include <QtCore/QFile>
#include <QtGui/QImage>
#include <QtCore/QByteArray>
#include "poppler-qt4.h"
#include <ErrorCodes.h>
#include <GlobalParams.h>
#include <Outline.h>
#include <PDFDoc.h>
#include <PSOutputDev.h>
#include <Stream.h>
#include <UGooString.h>
#include <Catalog.h>
#include "UGooString.h"
#include <ErrorCodes.h>
#include <splash/SplashBitmap.h>
#include "poppler-private.h"
#include <Stream.h>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtGui/QImage>
#include <QtCore/QByteArray>
#include "poppler-private.h"
namespace Poppler {
......@@ -181,16 +188,6 @@ namespace Poppler {
}
/* borrowed from kpdf */
static QString unicodeToQString(Unicode* u, int len) {
QString ret;
ret.resize(len);
QChar* qch = (QChar*) ret.unicode();
for (;len;--len)
*qch++ = (QChar) *u++;
return ret;
}
/* borrowed from kpdf */
QString Document::info( const QString & type ) const
{
......@@ -371,6 +368,58 @@ namespace Poppler {
{
return (!(0 == m_doc->doc.getCatalog()->numEmbeddedFiles()));
}
QDomDocument *Document::toc() const
{
Outline * outline = m_doc->doc.getOutline();
if ( !outline )
return NULL;
GooList * items = outline->getItems();
if ( !items || items->getLength() < 1 )
return NULL;
QDomDocument *toc = new QDomDocument();
if ( items->getLength() > 0 )
m_doc->addTocChildren( toc, toc, items );
return toc;
}
LinkDestination *Document::linkDestination( const QString &name )
{
UGooString * namedDest = QStringToUGooString( name );
LinkDest * destination = m_doc->doc.findDest( namedDest );
if ( destination )
{
LinkDestinationData ldd(destination, &m_doc->doc);
LinkDestination *ld = new LinkDestination(ldd);
delete namedDest;
return ld;
}
else return NULL;
}
bool Document::print(const QString &file, const QList<int> pageList, double hDPI, double vDPI, int rotate)
{
PSOutputDev *psOut = new PSOutputDev(file.toLatin1().data(), m_doc->doc.getXRef(), m_doc->doc.getCatalog(), 1, m_doc->doc.getNumPages(), psModePS);
if (psOut->isOk())
{
foreach(int page, pageList)
{
m_doc->doc.displayPage(psOut, page, hDPI, vDPI, rotate, gFalse, globalParams->getPSCrop(), gFalse);
}
delete psOut;
return true;
}
else
{
delete psOut;
return false;
}
}
QDateTime convertDate( char *dateString )
{
......
/* poppler-page.cc: qt interface to poppler
* Copyright (C) 2006, Albert Astals Cid
*
* 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, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define UNSTABLE_POPPLER_QT4
#include <poppler-qt4.h>
#include <poppler-private.h>
#include <QtCore/QStringList>
#include "Link.h"
namespace Poppler {
LinkDestination::LinkDestination(const LinkDestinationData &data)
{
LinkDest *ld = data.ld;
if (ld->getKind() == ::destXYZ) m_kind = destXYZ;
else if (ld->getKind() == ::destFit) m_kind = destFit;
else if (ld->getKind() == ::destFitH) m_kind = destFitH;
else if (ld->getKind() == ::destFitV) m_kind = destFitV;
else if (ld->getKind() == ::destFitR) m_kind = destFitR;
else if (ld->getKind() == ::destFitB) m_kind = destFitB;
else if (ld->getKind() == ::destFitBH) m_kind = destFitBH;
else if (ld->getKind() == ::destFitBV) m_kind = destFitBV;
if ( !ld->isPageRef() ) m_pageNum = ld->getPageNum();
else
{
Ref ref = ld->getPageRef();
m_pageNum = data.doc->findPage( ref.num, ref.gen );
}
m_left = ld->getLeft();
m_bottom = ld->getBottom();
m_right = ld->getRight();
m_top = ld->getTop();
m_zoom = ld->getZoom();
m_changeLeft = ld->getChangeLeft();
m_changeTop = ld->getChangeTop();
m_changeZoom = ld->getChangeZoom();
}
LinkDestination::LinkDestination(const QString &description)
{
QStringList tokens = description.split( ';' );
m_kind = static_cast<Kind>(tokens.at(0).toInt());
m_pageNum = tokens.at(1).toInt();
m_left = tokens.at(2).toDouble();
m_bottom = tokens.at(3).toDouble();
m_top = tokens.at(4).toDouble();
m_zoom = tokens.at(5).toDouble();
m_changeLeft = static_cast<bool>(tokens.at(6).toInt());
m_changeTop = static_cast<bool>(tokens.at(7).toInt());
m_changeZoom = static_cast<bool>(tokens.at(8).toInt());
}
LinkDestination::Kind LinkDestination::kind() const
{
return m_kind;
}
int LinkDestination::pageNumber() const
{
return m_pageNum;
}
double LinkDestination::left() const
{
return m_left;
}
double LinkDestination::bottom() const
{
return m_bottom;
}
double LinkDestination::right() const
{
return m_right;
}
double LinkDestination::top() const
{
return m_top;
}
double LinkDestination::zoom() const
{
return m_zoom;
}
bool LinkDestination::isChangeLeft() const
{
return m_changeLeft;
}
bool LinkDestination::isChangeTop() const
{
return m_changeTop;
}
bool LinkDestination::isChangeZoom() const
{
return m_changeZoom;
}
QString LinkDestination::toString() const
{
QString s = QString::number( (qint8)m_kind );
s += ";" + QString::number( m_pageNum );
s += ";" + QString::number( m_left );
s += ";" + QString::number( m_bottom );
s += ";" + QString::number( m_right );
s += ";" + QString::number( m_top );
s += ";" + QString::number( m_zoom );
s += ";" + QString::number( (qint8)m_changeLeft );
s += ";" + QString::number( (qint8)m_changeTop );
s += ";" + QString::number( (qint8)m_changeZoom );
return s;
}
}
......@@ -194,7 +194,7 @@ PageTransition *Page::transition() const
Object o;
PageTransitionParams params;
params.dictObj = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1)->getTrans(&o);
m_page->transition = new PageTransition(params);
if (params.dictObj->isDict()) m_page->transition = new PageTransition(params);
o.free();
}
return m_page->transition;
......@@ -235,4 +235,11 @@ Page::Orientation Page::orientation() const
}
}
void Page::defaultCTM(double *CTM, double dpiX, double dpiY, int rotate, bool upsideDown)
{
::Page *p;
p = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
p->getDefaultCTM(CTM, dpiX, dpiY, rotate, upsideDown);
}
}
/* poppler-private.h: qt interface to poppler
* Copyright (C) 2005, Net Integration Technologies, Inc.
* Copyright (C) 2006 by Albert Astals Cid <aacid@kde.org>
* Inspired on code by
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es>
* 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
......@@ -16,13 +20,47 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <PDFDoc.h>
#include <GfxState.h>
#include <Link.h>
#include <Outline.h>
#include <PDFDoc.h>
#include <FontInfo.h>
#include <SplashOutputDev.h>
#include <UGooString.h>
namespace Poppler {
/* borrowed from kpdf */
static QString unicodeToQString(Unicode* u, int len) {
QString ret;
ret.resize(len);
QChar* qch = (QChar*) ret.unicode();
for (;len;--len)
*qch++ = (QChar) *u++;
return ret;
}
static UGooString *QStringToUGooString(const QString &s) {
int len = s.length();
Unicode *u = (Unicode *)gmallocn(s.length(), sizeof(Unicode));
for (int i = 0; i < len; ++i)
u[i] = s.at(i).unicode();
return new UGooString(u, len);
}
class LinkDestinationData
{
public:
LinkDestinationData( LinkDest *l, PDFDoc *pdfdoc ) : ld(l), doc(pdfdoc)
{
}
LinkDest *ld;
PDFDoc *doc;
};
class DocumentData {
public:
DocumentData(GooString *filePath, GooString *ownerPassword, GooString *userPassword) :
......@@ -54,6 +92,61 @@ namespace Poppler {
return m_splashOutputDev;
}
void addTocChildren( QDomDocument * docSyn, QDomNode * parent, GooList * items )
{
int numItems = items->getLength();
for ( int i = 0; i < numItems; ++i )
{
// iterate over every object in 'items'
OutlineItem * outlineItem = (OutlineItem *)items->get( i );
// 1. create element using outlineItem's title as tagName
QString name;
Unicode * uniChar = outlineItem->getTitle();
int titleLength = outlineItem->getTitleLength();
name = unicodeToQString(uniChar, titleLength);
if ( name.isEmpty() )
continue;
QDomElement item = docSyn->createElement( name );
parent->appendChild( item );
// 2. find the page the link refers to
LinkAction * a = outlineItem->getAction();
if ( a && ( a->getKind() == actionGoTo || a->getKind() == actionGoToR ) )
{
// page number is contained/referenced in a LinkGoTo
LinkGoTo * g = static_cast< LinkGoTo * >( a );
LinkDest * destination = g->getDest();
if ( !destination && g->getNamedDest() )
{
// no 'destination' but an internal 'named reference'. we could
// get the destination for the page now, but it's VERY time consuming,
// so better storing the reference and provide the viewport on demand
UGooString *s = g->getNamedDest();
QString aux = unicodeToQString( s->unicode(), s->getLength() );
item.setAttribute( "DestinationName", aux );
}
else if ( destination->isOk() )
{
LinkDestinationData ldd(destination, &doc);
item.setAttribute( "Destination", LinkDestination(ldd).toString() );
}
if ( a->getKind() == actionGoToR )
{
LinkGoToR * g2 = static_cast< LinkGoToR * >( a );
item.setAttribute( "ExternalFileName", g2->getFileName()->getCString() );
}
}
// 3. recursively descend over children
outlineItem->open();
GooList * children = outlineItem->getKids();
if ( children )
addTocChildren( docSyn, &item, children );
}
}
class PDFDoc doc;
bool locked;
FontInfoScanner *m_fontInfoScanner;
......
......@@ -25,6 +25,7 @@
#include <QtCore/QByteArray>
#include <QtCore/QDateTime>
#include <QtGui/QPixmap>
#include <QtXml/QDomDocument>
#include <poppler-page-transition.h>
......@@ -83,14 +84,14 @@ namespace Poppler {
class FontInfo {
public:
enum Type {
unknown,
Type1,
Type1C,
Type3,
TrueType,
CIDType0,
CIDType0C,
CIDTrueType
unknown = 0,
Type1 = 1,
Type1C = 2,
Type3 = 3,
TrueType = 4,
CIDType0 = 5,
CIDType0C = 6,
CIDTrueType = 7
};
/**
......@@ -356,11 +357,61 @@ delete pixmap;
The orientation of the page
*/
Orientation orientation() const;
/**
The default CTM
*/
void defaultCTM(double *CTM, double dpiX, double dpiY, int rotate, bool upsideDown);
private:
Page(const Document *doc, int index);
PageData *m_page;
};
class LinkDestinationData;
class LinkDestination
{
public:
enum Kind
{
destXYZ = 1,
destFit = 2,
destFitH = 3,
destFitV = 4,
destFitR = 5,
destFitB = 6,
destFitBH = 7,
destFitBV = 8
};
LinkDestination(const LinkDestinationData &data);
LinkDestination(const QString &description);
// Accessors.
Kind kind() const;
int pageNumber() const;
double left() const;
double bottom() const;
double right() const;
double top() const;
double zoom() const;
bool isChangeLeft() const;
bool isChangeTop() const;
bool isChangeZoom() const;
QString toString() const;
private:
Kind m_kind; // destination type
int m_pageNum; // page number
double m_left, m_bottom; // position
double m_right, m_top;
double m_zoom; // zoom factor
bool m_changeLeft, m_changeTop; // for destXYZ links, which position
bool m_changeZoom; // components to change
};
class DocumentData;
/**
......@@ -615,6 +666,25 @@ delete pixmap;
Whether there are any documents embedded in this PDF document.
*/
bool hasEmbeddedFiles() const;
/**
Gets the TOC of the Document, it is application responsabiliy to delete
it when no longer needed
* In the tree the tag name is the 'screen' name of the entry. A tag can have
* attributes. Here follows the list of tag attributes with meaning:
* - Destination: A string description of the referred destination
* - DestinationName: A 'named reference' to the viewport that must be converted
* using linkDestination( *destination_name* )
* - ExternalFileName: A link to a external filename
Returns NULL if the Document does not have TOC
*/
QDomDocument *toc() const;
LinkDestination *linkDestination( const QString &name );
bool print(const QString &fileName, const QList<int> pageList, double hDPI, double vDPI, int rotate);
~Document();
......
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