Commit 181f0982 authored by Albert Astals Cid's avatar Albert Astals Cid

* qt4/src/Makefile.am

        * qt4/src/poppler-annotation-helper.h
        * qt4/src/poppler-annotation.cc
        * qt4/src/poppler-annotation.h
        * qt4/src/poppler-link.cc
        * qt4/src/poppler-link.h
        * qt4/src/poppler-page.cc
        * qt4/src/poppler-qt4.h: Code for annotations stripped from oKular,
        it's all based on Enrico's work, so ask him for details, the problem
        is that he left KDE development a while ago.
parent 3a48e89d
2006-05-12 Albert Astals Cid <aacid@kde.org>
* qt4/src/Makefile.am
* qt4/src/poppler-annotation-helper.h
* qt4/src/poppler-annotation.cc
* qt4/src/poppler-annotation.h
* qt4/src/poppler-link.cc
* qt4/src/poppler-link.h
* qt4/src/poppler-page.cc
* qt4/src/poppler-qt4.h: Code for annotations stripped from oKular,
it's all based on Enrico's work, so ask him for details, the problem
is that he left KDE development a while ago.
2006-05-09 Albert Astals Cid <aacid@kde.org>
* qt4/src/Makefile.am:
......
......@@ -10,6 +10,7 @@ poppler_includedir = $(includedir)/poppler
poppler_include_HEADERS = \
poppler-qt4.h \
poppler-link.h \
poppler-annotation.h \
../../qt/poppler-page-transition.h
lib_LTLIBRARIES = libpoppler-qt4.la
......@@ -21,6 +22,7 @@ libpoppler_qt4_la_SOURCES = \
poppler-embeddedfile.cc \
poppler-textbox.cc \
poppler-link.cc \
poppler-annotation.cc \
../../qt/poppler-page-transition.cc \
poppler-private.h
......
/* poppler-annotation-helper.h: qt interface to poppler
* Copyright (C) 2006, Albert Astals Cid <aacid@kde.org>
* Adapting code from
* 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, 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.
*/
#include <QtCore/QDebug>
namespace Poppler {
class XPDFReader
{
public:
// find named symbol and parse it
static void lookupName( Dict *, const char *, QString & dest );
static void lookupString( Dict *, const char *, QString & dest );
static void lookupBool( Dict *, const char *, bool & dest );
static void lookupInt( Dict *, const char *, int & dest );
static void lookupNum( Dict *, const char *, double & dest );
static int lookupNumArray( Dict *, const char *, double * dest, int len );
static void lookupColor( Dict *, const char *, QColor & color );
static void lookupIntRef( Dict *, const char *, int & dest );
static void lookupDate( Dict *, const char *, QDateTime & dest );
// transform from user coords to normalized ones using the matrix M
static inline void transform( double * M, double x, double y, QPointF &res );
};
void XPDFReader::lookupName( Dict * dict, const char * type, QString & dest )
{
Object nameObj;
dict->lookup( type, &nameObj );
if ( nameObj.isNull() )
return;
if ( nameObj.isName() )
dest = nameObj.getName();
else
qDebug() << type << " is not Name." << endl;
nameObj.free();
}
void XPDFReader::lookupString( Dict * dict, const char * type, QString & dest )
{
Object stringObj;
dict->lookup( type, &stringObj );
if ( stringObj.isNull() )
return;
if ( stringObj.isString() )
dest = stringObj.getString()->getCString();
else
qDebug() << type << " is not String." << endl;
stringObj.free();
}
void XPDFReader::lookupBool( Dict * dict, const char * type, bool & dest )
{
Object boolObj;
dict->lookup( type, &boolObj );
if ( boolObj.isNull() )
return;
if ( boolObj.isBool() )
dest = boolObj.getBool() == gTrue;
else
qDebug() << type << " is not Bool." << endl;
boolObj.free();
}
void XPDFReader::lookupInt( Dict * dict, const char * type, int & dest )
{
Object intObj;
dict->lookup( type, &intObj );
if ( intObj.isNull() )
return;
if ( intObj.isInt() )
dest = intObj.getInt();
else
qDebug() << type << " is not Int." << endl;
intObj.free();
}
void XPDFReader::lookupNum( Dict * dict, const char * type, double & dest )
{
Object numObj;
dict->lookup( type, &numObj );
if ( numObj.isNull() )
return;
if ( numObj.isNum() )
dest = numObj.getNum();
else
qDebug() << type << " is not Num." << endl;
numObj.free();
}
int XPDFReader::lookupNumArray( Dict * dict, const char * type, double * dest, int len )
{
Object arrObj;
dict->lookup( type, &arrObj );
if ( arrObj.isNull() )
return 0;
Object numObj;
if ( arrObj.isArray() )
{
len = qMin( len, arrObj.arrayGetLength() );
for ( int i = 0; i < len; i++ )
{
dest[i] = arrObj.arrayGet( i, &numObj )->getNum();
numObj.free();
}
}
else
{
len = 0;
qDebug() << type << "is not Array." << endl;
}
arrObj.free();
return len;
}
void XPDFReader::lookupColor( Dict * dict, const char * type, QColor & dest )
{
double c[3];
if ( XPDFReader::lookupNumArray( dict, type, c, 3 ) == 3 )
dest = QColor( (int)(c[0]*255.0), (int)(c[1]*255.0), (int)(c[2]*255.0));
}
void XPDFReader::lookupIntRef( Dict * dict, const char * type, int & dest )
{
Object refObj;
dict->lookupNF( type, &refObj );
if ( refObj.isNull() )
return;
if ( refObj.isRef() )
dest = refObj.getRefNum();
else
qDebug() << type << " is not Ref." << endl;
refObj.free();
}
void XPDFReader::lookupDate( Dict * dict, const char * type, QDateTime & dest )
{
Object dateObj;
dict->lookup( type, &dateObj );
if ( dateObj.isNull() )
return;
if ( dateObj.isString() )
{
const char * s = dateObj.getString()->getCString();
if ( s[0] == 'D' && s[1] == ':' )
s += 2;
int year, mon, day, hour, min, sec;
if ( sscanf( s, "%4d%2d%2d%2d%2d%2d", &year, &mon, &day, &hour, &min, &sec ) == 6 )
{
QDate d( year, mon, day );
QTime t( hour, min, sec );
if ( d.isValid() && t.isValid() )
dest = QDateTime(d, t);
}
else
qDebug() << "Wrong Date format '" << s << "' for '" << type << "'." << endl;
}
else
qDebug() << type << " is not Date" << endl;
dateObj.free();
}
void XPDFReader::transform( double * M, double x, double y, QPointF &res )
{
res.setX( M[0] * x + M[2] * y + M[4] );
res.setY( M[1] * x + M[3] * y + M[5] );
}
/** @short Helper classes for CROSSDEPS resolving and DS conversion. */
struct ResolveRevision
{
int prevAnnotationID; // ID of the annotation to be reparended
int nextAnnotationID; // (only needed for speeding up resolving)
Annotation * nextAnnotation; // annotation that will act as parent
Annotation::RevScope nextScope; // scope of revision (Reply)
Annotation::RevType nextType; // type of revision (None)
};
struct ResolveWindow
{
int popupWindowID; // ID of the (maybe shared) window
Annotation * annotation; // annotation having the popup window
};
struct PostProcessText // this handles a special pdf case conversion
{
Annotation * textAnnotation; // a popup text annotation (not FreeText)
bool opened; // pdf property to convert to window flags
};
struct PopupWindow
{
Annotation * dummyAnnotation; // window properties (in pdf as Annotation)
bool shown; // converted to Annotation::Hidden flag
};
}
This diff is collapsed.
/* poppler-annotation.h: qt interface to poppler
* Copyright (C) 2006, Albert Astals Cid
* Adapting code from
* 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, 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.
*/
#ifndef _POPPLER_ANNOTATION_H_
#define _POPPLER_ANNOTATION_H_
#include <QtCore/QDateTime>
#include <QtCore/QLinkedList>
#include <QtCore/QPointF>
#include <QtCore/QRectF>
#include <QtGui/QFont>
namespace Poppler {
class Annotation;
/**
* @short Helper class for (recoursive) annotation retrieval/storage.
*
*/
class AnnotationUtils
{
public:
// restore an annotation (with revisions if needed) from a dom
// element. returns a pointer to the complete annotation or 0 if
// element is invalid.
static Annotation * createAnnotation( const QDomElement & annElement );
// save the 'ann' annotations as a child of parentElement taking
// care of saving all revisions if 'ann' has any.
static void storeAnnotation( const Annotation * ann,
QDomElement & annElement, QDomDocument & document );
// return an element called 'name' from the direct children of
// parentNode or a null element if not found
static QDomElement findChildElement( const QDomNode & parentNode,
const QString & name );
//static inline QRect annotationGeometry( const Annotation * ann,
// int pageWidth, int pageHeight, int scaledWidth, int scaledHeight ) const;
};
/**
* @short Annotation struct holds properties shared by all annotations.
*
* An Annotation is an object (text note, highlight, sound, popup window, ..)
* contained by a Page in the document.
*
*/
struct Annotation
{
// enum definitions
// WARNING!!! oKular uses that very same values so if you change them notify the author!
enum SubType { AText = 1, ALine = 2, AGeom = 3, AHighlight = 4, AStamp = 5,
AInk = 6, A_BASE = 0 };
enum Flag { Hidden = 1, FixedSize = 2, FixedRotation = 4, DenyPrint = 8,
DenyWrite = 16, DenyDelete = 32, ToggleHidingOnMouse = 64, External = 128 };
enum LineStyle { Solid = 1, Dashed = 2, Beveled = 4, Inset = 8, Underline = 16 };
enum LineEffect { NoEffect = 1, Cloudy = 2};
enum RevScope { Reply = 1, Group = 2, Delete = 4 };
enum RevType { None = 1, Marked = 2, Unmarked = 4, Accepted = 8, Rejected = 16, Cancelled = 32, Completed = 64 };
/** properties: contents related */
QString author; // ''
QString contents; // ''
QString uniqueName; // '#NUMBER#'
QDateTime modifyDate; // before or equal to currentDateTime()
QDateTime creationDate; // before or equal to modifyDate
/** properties: look/interaction related */
int flags; // 0
QRectF boundary; // valid or isNull()
struct Style
{
// appearance properties
QColor color; // black
double opacity; // 1.0
// pen properties
double width; // 1.0
LineStyle style; // LineStyle::Solid
double xCorners; // 0.0
double yCorners; // 0.0
int marks; // 3
int spaces; // 0
// pen effects
LineEffect effect; // LineEffect::NoEffect
double effectIntensity; // 1.0
// default initializer
Style();
} style;
/** properties: popup window */
struct Window
{
// window state (Hidden, FixedRotation, Deny* flags allowed)
int flags; // -1 (never initialized) -> 0 (if inited and shown)
// geometric properties
QPointF topLeft; // no default, inited to boundary.topLeft
int width; // no default
int height; // no default
// window contens/override properties
QString title; // '' text in the titlebar (overrides author)
QString summary; // '' short description (displayed if not empty)
QString text; // '' text for the window (overrides annot->contents)
// default initializer
Window();
} window;
/** properties: versioning */
struct Revision
{
// child revision
Annotation * annotation; // not null
// scope and type of revision
RevScope scope; // Reply
RevType type; // None
// default initializer
Revision();
};
QLinkedList< Revision > revisions; // empty by default
// methods: query annotation's type for runtime type identification
virtual SubType subType() const { return A_BASE; }
//QRect geometry( int scaledWidth, int scaledHeight, KPDFPage * page );
// methods: storage/retrieval from xml nodes
Annotation( const QDomNode & node );
virtual void store( QDomNode & parentNode, QDomDocument & document ) const;
// methods: default constructor / virtual destructor
Annotation();
virtual ~Annotation();
};
// a helper used to shorten the code presented below
#define AN_COMMONDECL( className, rttiType )\
className();\
className( const class QDomNode & node );\
void store( QDomNode & parentNode, QDomDocument & document ) const;\
SubType subType() const { return rttiType; }
struct TextAnnotation : public Annotation
{
// common stuff for Annotation derived classes
AN_COMMONDECL( TextAnnotation, AText );
// local enums
enum TextType { Linked, InPlace };
enum InplaceIntent { Unknown, Callout, TypeWriter };
// data fields
TextType textType; // Linked
QString textIcon; // 'Comment'
QFont textFont; // app def font
int inplaceAlign; // 0:left, 1:center, 2:right
QString inplaceText; // '' overrides contents
QPointF inplaceCallout[3]; //
InplaceIntent inplaceIntent; // Unknown
};
struct LineAnnotation : public Annotation
{
// common stuff for Annotation derived classes
AN_COMMONDECL( LineAnnotation, ALine )
// local enums
enum TermStyle { Square, Circle, Diamond, OpenArrow, ClosedArrow, None,
Butt, ROpenArrow, RClosedArrow, Slash };
enum LineIntent { Unknown, Arrow, Dimension, PolygonCloud };
// data fields (note uses border for rendering style)
QLinkedList<QPointF> linePoints;
TermStyle lineStartStyle; // None
TermStyle lineEndStyle; // None
bool lineClosed; // false (if true draw close shape)
QColor lineInnerColor; //
double lineLeadingFwdPt; // 0.0
double lineLeadingBackPt; // 0.0
bool lineShowCaption; // false
LineIntent lineIntent; // Unknown
};
struct GeomAnnotation : public Annotation
{
// common stuff for Annotation derived classes
AN_COMMONDECL( GeomAnnotation, AGeom )
// common enums
enum GeomType { InscribedSquare, InscribedCircle };
// data fields (note uses border for rendering style)
GeomType geomType; // InscribedSquare
QColor geomInnerColor; //
int geomWidthPt; // 18
};
struct HighlightAnnotation : public Annotation
{
// common stuff for Annotation derived classes
AN_COMMONDECL( HighlightAnnotation, AHighlight )
// local enums
enum HighlightType { Highlight, Squiggly, Underline, StrikeOut };
// data fields
HighlightType highlightType; // Highlight
struct Quad
{
QPointF points[4]; // 8 valid coords
bool capStart; // false (vtx 1-4) [K]
bool capEnd; // false (vtx 2-3) [K]
double feather; // 0.1 (in range 0..1) [K]
};
QList< Quad > highlightQuads; // not empty
};
struct StampAnnotation : public Annotation
{
// common stuff for Annotation derived classes
AN_COMMONDECL( StampAnnotation, AStamp )
// data fields
QString stampIconName; // 'kpdf'
};
struct InkAnnotation : public Annotation
{
// common stuff for Annotation derived classes
AN_COMMONDECL( InkAnnotation, AInk )
// data fields
QList< QLinkedList<QPointF> > inkPaths;
};
}
#endif
/* poppler-page.cc: qt interface to poppler
/* poppler-link.cc: qt interface to poppler
* Copyright (C) 2006, Albert Astals Cid
* Adapting code from
* 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
......
/* poppler-link.cc: qt interface to poppler
/* poppler-link.h: qt interface to poppler
* Copyright (C) 2006, Albert Astals Cid <aacid@kde.org>
* Adapting code from
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>
......
This diff is collapsed.
......@@ -28,8 +28,9 @@
#include <QtGui/QPixmap>
#include <QtXml/QDomDocument>
#include <poppler-page-transition.h>
#include <poppler-annotation.h>
#include <poppler-link.h>
#include <poppler-page-transition.h>
class EmbFile;
......@@ -395,6 +396,11 @@ delete pixmap;
*/
QList<Link*> links() const;
/**
Returns the annotations of the page
*/
QList<Annotation*> annotations () const;
private:
Page(const Document *doc, int index);
PageData *m_page;
......
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