Commit bcc2542e authored by Enrico Ros's avatar Enrico Ros

Big update to annotations. DataStructures passed the recursive saving

and retrieval xml test. This second rewrite seems better than the
previous one. Maybe it's not perfect bug finally it's good enought
to move ahead now.

Annotations:
  Restored and verified XML loading/saving with recursive storing and
  retrieval of referenced objects. 100% verified and tested. Finally
  all is working as expected. The structure is clean and it's simple
  to choose the way to go now: rendering. Updated AnnotationUtils, More
  comments, removed leak.
Page:
  Adapted to changes to AnnotationUtils and Annotation, changed context
  saving.
Misc updates on TODO and PDFGenerator (fixed Ext flag).

svn path=/branches/kpdf_annotations/kdegraphics/kpdf/; revision=403863
parent 659ae73b
......@@ -6,23 +6,21 @@ Legend:
MRG - MeRGed (code from a branch or a patch)
In progress [working on]:
-> annotations: DS refactor (97%)
-> annotations: pdf parser adaptation (95%)
-> annotations: xml storage adaptation (6%)
-> annotations: renderers in PagePainter (for the 6 markup annots)
-> annotations: handlers in PageView for WindowAnnots and others..
-> annotations: creators in PageViewAnnotator (60% done)
-> annotations: framework (BR67300,BR62793) and tools (BR67300,BR91251)
-> annotations: add the annot pane (cool plz!)
-> (done: 100%) refactor, pdf parser, xml storage
-> check mouse wrapping not screH / 2
-> check unscaledwidth/height.. necessary ?
-> check if fix was applied in head only (pageview.cpp 1676)
-> investigating crash on quit() on the document provided by Mikolaj
More items (first items will enter 'In progress list' first):
-> merge with head: core/ has no qwidgets around. the head fonts can't make exception!
use getMetaData for getting the font list instead of 'passing a klistview to the generator'!
-> pageview: add vp damaging queue and flush function. add coolfx to smoothmove using damaging
-> annotations: add config option for default name change
-> annotations: toolbar: display tooltip only the first time
-> annotations: provide nice wizards. Make it easy to deliver/copy/move the xml files (by Uga)
......
This diff is collapsed.
......@@ -23,7 +23,7 @@ class Annotation;
* @short Helper class for (recoursive) annotation retrieval/storage.
*
*/
class AnnotationManager
class AnnotationUtils
{
public:
// restore an annotation (with revisions if needed) from a dom
......@@ -33,8 +33,13 @@ class AnnotationManager
// 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, QDomNode & parentNode,
QDomDocument & document );
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 );
};
......@@ -50,7 +55,8 @@ class AnnotationManager
struct Annotation
{
// enum definitions
enum SubType { AText, ALine, AGeom, AHighlight, AStamp, AInk, A_BASE };
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, Dashed, Beveled, Inset, Underline };
......@@ -83,6 +89,8 @@ struct Annotation
// pen effects
LineEffect effect; // LineEffect::NoEffect
double effectIntensity; // 1.0
// default initializer
Style();
} style;
/** properties: popup window */
......@@ -98,6 +106,8 @@ struct Annotation
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 */
......@@ -108,6 +118,8 @@ struct Annotation
// scope and type of revision
RevScope scope; // Reply
RevType type; // None
// default initializer
Revision();
};
QValueList< Revision > revisions; // empty by default
......@@ -121,11 +133,10 @@ struct Annotation
// methods: default constructor / virtual destructor
Annotation();
virtual ~Annotation() {};
virtual ~Annotation();
};
//BEGIN Annotations Definition
// a helper used to shorten the code presented below
#define AN_COMMONDECL( className, rttiType )\
className();\
......@@ -143,14 +154,14 @@ struct TextAnnotation : public Annotation
enum InplaceIntent { Unknown, Callout, TypeWriter };
// data fields
TextType textType;
QFont textFont;
bool textOpened;
QString textIcon;
int inplaceAlign; // 0:left, 1:center, 2:right
QString inplaceText; // '' overrides contents
NormalizedPoint inplaceCallout[3];
InplaceIntent inplaceIntent;
TextType textType; // Linked
QFont textFont; // app def font
bool textOpened; // false
QString textIcon; // 'Comment'
int inplaceAlign; // 0:left, 1:center, 2:right
QString inplaceText; // '' overrides contents
NormalizedPoint inplaceCallout[3]; //
InplaceIntent inplaceIntent; // Unknown
};
struct LineAnnotation : public Annotation
......@@ -165,14 +176,14 @@ struct LineAnnotation : public Annotation
// data fields (note uses border for rendering style)
QValueList<NormalizedPoint> linePoints;
TermStyle lineStartStyle;
TermStyle lineEndStyle;
bool lineClosed; // false (if true connect first and last points)
QColor lineInnerColor;
double lineLeadingFwdPt;
double lineLeadingBackPt;
bool lineShowCaption;
LineIntent lineIntent;
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
......@@ -184,9 +195,9 @@ struct GeomAnnotation : public Annotation
enum GeomType { InscribedSquare, InscribedCircle };
// data fields (note uses border for rendering style)
GeomType geomType;
QColor geomInnerColor;
int geomWidthPt; // 18
GeomType geomType; // InscribedSquare
QColor geomInnerColor; //
int geomWidthPt; // 18
};
struct HighlightAnnotation : public Annotation
......@@ -198,7 +209,7 @@ struct HighlightAnnotation : public Annotation
enum HighlightType { Highlight, Underline, Squiggly, StrikeOut };
// data fields
HighlightType highlightType;
HighlightType highlightType; // Highlight
QValueList<NormalizedPoint[4]> highlightQuads;
};
......@@ -208,7 +219,7 @@ struct StampAnnotation : public Annotation
AN_COMMONDECL( StampAnnotation, AStamp )
// data fields
QString stampIconName;
QString stampIconName; // 'kpdf'
};
struct InkAnnotation : public Annotation
......@@ -219,6 +230,5 @@ struct InkAnnotation : public Annotation
// data fields
QValueList< QValueList<NormalizedPoint> > inkPaths;
};
//END Annotations definition
#endif
......@@ -1190,8 +1190,10 @@ void PDFGenerator::addAnnotations( Page * pdfPage, KPDFPage * page )
XPDFReader::lookupDate( annotDict, "M", annotation->modifyDate );
if ( annotation->creationDate.isNull() && !annotation->modifyDate.isNull() )
annotation->creationDate = annotation->modifyDate;
// -> flags (set External since annotation is already on file)
int flags = Annotation::External;
// -> flags: set the external attribute since it's embedded on file
annotation->flags |= Annotation::External;
// -> flags
int flags = 0;
XPDFReader::lookupInt( annotDict, "F", flags );
if ( flags & 0x2 )
annotation->flags |= Annotation::Hidden;
......@@ -1366,7 +1368,7 @@ void PDFGenerator::addAnnotations( Page * pdfPage, KPDFPage * page )
kdDebug() << "PDFGenerator: clash for annotations with ID:" << annotID << endl;
annotationsMap[ annotID ] = annotation;
}
}
} // end Annotation/PopupWindow parsing loop
/** 2 - RESOLVE POPUPS (popup.* -> annotation.window) */
if ( !resolvePopList.isEmpty() && !popupsMap.isEmpty() )
......@@ -1441,7 +1443,7 @@ void PDFGenerator::addAnnotations( Page * pdfPage, KPDFPage * page )
annotationsMap.remove( excludeIDs[ i ] );
}
// finally add annotations to the page
/** 4 - finally SET ANNOTATIONS to the page */
QMap< int, Annotation * >::Iterator it = annotationsMap.begin(), end = annotationsMap.end();
for ( ; it != end; ++it )
page->addAnnotation( it.data() );
......
......@@ -320,7 +320,7 @@ void KPDFPage::restoreLocalContents( const QDomNode & pageNode )
annotationNode = annotationNode.nextSibling();
// get annotation from the dom element
Annotation * annotation = AnnotationManager::createAnnotation( annotElement );
Annotation * annotation = AnnotationUtils::createAnnotation( annotElement );
// append annotation to the list or show warning
if ( annotation )
......@@ -343,56 +343,53 @@ void KPDFPage::restoreLocalContents( const QDomNode & pageNode )
void KPDFPage::saveLocalContents( QDomNode & parentNode, QDomDocument & document )
{
// only add a node if there is some stuff to write into
if ( m_bookmarked || !m_annotations.isEmpty() )
{
// create the page node and set the 'number' attribute
QDomElement pageElement = document.createElement( "page" );
parentNode.appendChild( pageElement );
pageElement.setAttribute( "number", m_number );
if ( !m_bookmarked && m_annotations.isEmpty() )
return;
// add bookmark info if is bookmarked
if ( m_bookmarked )
{
// create the pageElement's 'bookmark' child
QDomElement bookmarkElement = document.createElement( "bookmark" );
pageElement.appendChild( bookmarkElement );
// create the page node and set the 'number' attribute
QDomElement pageElement = document.createElement( "page" );
parentNode.appendChild( pageElement );
pageElement.setAttribute( "number", m_number );
// add attributes to the element
//bookmarkElement.setAttribute( "name", bookmark name );
}
// add bookmark info if is bookmarked
if ( m_bookmarked )
{
// create the pageElement's 'bookmark' child
QDomElement bookmarkElement = document.createElement( "bookmark" );
pageElement.appendChild( bookmarkElement );
// add attributes to the element
//bookmarkElement.setAttribute( "name", bookmark name );
}
// add annotations info if has got any
if ( !m_annotations.isEmpty() )
// add annotations info if has got any
if ( !m_annotations.isEmpty() )
{
struct timeval ts, te;
gettimeofday( &ts, NULL );
// create the annotationList
QDomElement annotListElement = document.createElement( "annotationList" );
pageElement.appendChild( annotListElement );
// add every annotation to the annotationList
QValueList< Annotation * >::iterator aIt = m_annotations.begin(), aEnd = m_annotations.end();
for ( ; aIt != aEnd; ++aIt )
{
struct timeval ts, te;
gettimeofday( &ts, NULL );
// create the annotationList
QDomElement annotListElement = document.createElement( "annotationList" );
pageElement.appendChild( annotListElement );
// add every annotation to the annotationList
int addedAnnotations = 0;
QValueList< Annotation * >::iterator aIt = m_annotations.begin(), aEnd = m_annotations.end();
for ( ; aIt != aEnd; ++aIt )
// get annotation
const Annotation * a = *aIt;
// only save kpdf annotations (not the embedded in file ones)
if ( !(a->flags & Annotation::External) )
{
// get annotation
const Annotation * a = *aIt;
// only save annotations created by us (not loaded from document)
if ( !a->flags & Annotation::External )
{
AnnotationManager::storeAnnotation( a, annotListElement, document );
addedAnnotations++;
}
// append an filled-up element called 'annotation' to the list
QDomElement annElement = document.createElement( "annotation" );
AnnotationUtils::storeAnnotation( a, annElement, document );
annotListElement.appendChild( annElement );
}
// add number of children annotations as attribute
if ( addedAnnotations )
annotListElement.setAttribute( "annotations", addedAnnotations );
gettimeofday( &te, NULL );
double startTime = (double)ts.tv_sec + ((double)ts.tv_usec) / 1000000.0;
double endTime = (double)te.tv_sec + ((double)te.tv_usec) / 1000000.0;
kdDebug() << "annots: XML Save Time: " << (endTime-startTime)*1000.0 << "ms" << endl;
}
gettimeofday( &te, NULL );
double startTime = (double)ts.tv_sec + ((double)ts.tv_usec) / 1000000.0;
double endTime = (double)te.tv_sec + ((double)te.tv_usec) / 1000000.0;
kdDebug() << "annots: XML Save Time: " << (endTime-startTime)*1000.0 << "ms" << endl;
}
}
......
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