2006-09-11 10:44:17 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2006 Brad Hards <bradh@frogmouth.net>
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2006-10-21 22:10:09 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
2006-09-11 10:44:17 +00:00
|
|
|
02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _OKULAR_GENERATOR_XPS_H_
|
|
|
|
#define _OKULAR_GENERATOR_XPS_H_
|
|
|
|
|
|
|
|
#include "core/generator.h"
|
2006-12-28 16:45:50 +00:00
|
|
|
#include <QDomDocument>
|
2006-09-21 11:41:46 +00:00
|
|
|
#include <QXmlDefaultHandler>
|
2006-09-11 10:44:17 +00:00
|
|
|
|
|
|
|
#include <kzip.h>
|
|
|
|
|
2006-09-21 11:41:46 +00:00
|
|
|
class XpsPage;
|
|
|
|
|
|
|
|
class XpsHandler: public QXmlDefaultHandler
|
|
|
|
{
|
|
|
|
public:
|
2006-09-26 11:53:27 +00:00
|
|
|
XpsHandler( XpsPage *page );
|
2006-09-21 11:41:46 +00:00
|
|
|
~XpsHandler();
|
|
|
|
|
|
|
|
bool startElement( const QString & nameSpace,
|
|
|
|
const QString & localName,
|
|
|
|
const QString & qname,
|
|
|
|
const QXmlAttributes & atts );
|
|
|
|
bool endElement( const QString & nameSpace,
|
|
|
|
const QString & localName,
|
|
|
|
const QString & qname );
|
|
|
|
bool startDocument();
|
|
|
|
|
|
|
|
private:
|
2006-09-26 11:53:27 +00:00
|
|
|
/**
|
|
|
|
Parse an abbreviated path "Data" description
|
|
|
|
\param data the string containing the whitespace separated values
|
|
|
|
|
|
|
|
\note sets the m_currentPath and possibly other private variables
|
|
|
|
|
|
|
|
\see XPS specification 4.2.3 and Appendix G
|
|
|
|
*/
|
|
|
|
void parseAbbreviatedPathData( const QString &data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Parse a "Matrix" attribute string
|
|
|
|
\param csv the comma separated list of values
|
|
|
|
\return the QMatrix corresponding to the affine transform
|
|
|
|
given in the attribute
|
|
|
|
|
|
|
|
\see XPS specification 7.4.1
|
|
|
|
*/
|
|
|
|
QMatrix attsToMatrix( const QString &csv );
|
|
|
|
|
2006-09-21 11:41:46 +00:00
|
|
|
XpsPage *m_page;
|
|
|
|
QPainter *m_painter;
|
|
|
|
|
|
|
|
QBrush m_currentBrush;
|
|
|
|
QPen m_currentPen;
|
|
|
|
QPainterPath m_currentPath;
|
|
|
|
|
|
|
|
QImage m_image;
|
|
|
|
QRectF m_viewbox;
|
|
|
|
QRectF m_viewport;
|
|
|
|
};
|
|
|
|
|
2006-09-11 10:44:17 +00:00
|
|
|
class XpsPage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
XpsPage(KZip *archive, const QString &fileName);
|
|
|
|
~XpsPage();
|
|
|
|
|
|
|
|
QSize size() const;
|
2006-09-26 11:53:27 +00:00
|
|
|
bool renderToImage( QImage *p );
|
2006-09-21 11:41:46 +00:00
|
|
|
|
|
|
|
QImage loadImageFromFile( const QString &filename );
|
|
|
|
int loadFontByName( const QString &fontName );
|
|
|
|
|
2006-09-11 10:44:17 +00:00
|
|
|
private:
|
2006-09-21 11:41:46 +00:00
|
|
|
KZip *m_archive;
|
|
|
|
const QString m_fileName;
|
2006-09-11 10:44:17 +00:00
|
|
|
QDomDocument m_dom;
|
|
|
|
|
|
|
|
QSize m_pageSize;
|
2006-09-23 00:42:42 +00:00
|
|
|
|
|
|
|
QFontDatabase m_fontDatabase;
|
2006-09-11 10:44:17 +00:00
|
|
|
|
|
|
|
QString m_thumbnailFileName;
|
|
|
|
bool m_thumbnailMightBeAvailable;
|
|
|
|
QImage m_thumbnail;
|
|
|
|
bool m_thumbnailIsLoaded;
|
|
|
|
|
2006-09-26 11:53:27 +00:00
|
|
|
QImage *m_pageImage;
|
2006-09-21 11:41:46 +00:00
|
|
|
bool m_pageIsRendered;
|
2006-09-23 00:42:42 +00:00
|
|
|
|
|
|
|
friend class XpsHandler;
|
2006-09-11 10:44:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Represents one of the (perhaps the only) documents in an XpsFile
|
|
|
|
*/
|
|
|
|
class XpsDocument
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
XpsDocument(KZip *archive, const QString &fileName);
|
|
|
|
~XpsDocument();
|
|
|
|
|
|
|
|
/**
|
|
|
|
the total number of pages in this document
|
|
|
|
*/
|
|
|
|
int numPages() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
obtain a certain page from this document
|
|
|
|
|
|
|
|
\param pageNum the number of the page to return
|
|
|
|
|
|
|
|
\note page numbers are zero based - they run from 0 to
|
|
|
|
numPages() - 1
|
|
|
|
*/
|
|
|
|
XpsPage* page(int pageNum) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList<XpsPage*> m_pages;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Represents the contents of a Microsoft XML Paper Specification
|
|
|
|
format document.
|
|
|
|
*/
|
|
|
|
class XpsFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
XpsFile();
|
|
|
|
~XpsFile();
|
|
|
|
|
|
|
|
bool loadDocument( const QString & fileName );
|
|
|
|
bool closeDocument();
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::DocumentInfo * generateDocumentInfo();
|
2006-09-11 10:44:17 +00:00
|
|
|
|
|
|
|
QImage thumbnail();
|
|
|
|
|
|
|
|
/**
|
|
|
|
the total number of XpsDocuments with this file
|
|
|
|
*/
|
|
|
|
int numDocuments() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
the total number of pages in all the XpsDocuments within this
|
|
|
|
file
|
|
|
|
*/
|
|
|
|
int numPages() const;
|
|
|
|
|
2006-09-21 11:41:46 +00:00
|
|
|
/**
|
|
|
|
a page from the file
|
|
|
|
|
|
|
|
\param pageNum the page number of the page to return
|
|
|
|
|
|
|
|
\note page numbers are zero based - they run from 0 to
|
|
|
|
numPages() - 1
|
|
|
|
*/
|
|
|
|
XpsPage* page(int pageNum) const;
|
|
|
|
|
2006-09-11 10:44:17 +00:00
|
|
|
/**
|
|
|
|
obtain a certain document from this file
|
|
|
|
|
|
|
|
\param documentNum the number of the document to return
|
|
|
|
|
2006-09-21 11:41:46 +00:00
|
|
|
\note document numbers are zero based - they run from 0 to
|
2006-09-11 10:44:17 +00:00
|
|
|
numDocuments() - 1
|
|
|
|
*/
|
|
|
|
XpsDocument* document(int documentNum) const;
|
|
|
|
private:
|
|
|
|
QList<XpsDocument*> m_documents;
|
2006-09-21 11:41:46 +00:00
|
|
|
QList<XpsPage*> m_pages;
|
2006-09-11 10:44:17 +00:00
|
|
|
|
|
|
|
QString m_thumbnailFileName;
|
|
|
|
bool m_thumbnailMightBeAvailable;
|
|
|
|
QImage m_thumbnail;
|
|
|
|
bool m_thumbnailIsLoaded;
|
|
|
|
|
|
|
|
QString m_corePropertiesFileName;
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::DocumentInfo * m_docInfo;
|
2006-09-11 10:44:17 +00:00
|
|
|
|
|
|
|
KZip *xpsArchive;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
class XpsGenerator : public Okular::Generator
|
2006-09-11 10:44:17 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2006-10-22 11:25:08 +00:00
|
|
|
XpsGenerator();
|
2006-09-11 10:44:17 +00:00
|
|
|
virtual ~XpsGenerator();
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );
|
2006-09-11 10:44:17 +00:00
|
|
|
bool closeDocument();
|
|
|
|
|
2006-10-20 16:51:46 +00:00
|
|
|
bool canGeneratePixmap( bool async ) const;
|
2006-09-21 08:45:36 +00:00
|
|
|
void generatePixmap( Okular::PixmapRequest * request );
|
2006-09-11 10:44:17 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::DocumentInfo * generateDocumentInfo();
|
2006-09-11 10:44:17 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
private:
|
|
|
|
XpsFile *m_xpsFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|