From da5e6b8b74439b59f6a08e45e5ff20ab5b3aebf0 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Fri, 8 Apr 2005 11:15:23 +0000 Subject: [PATCH] Annotations: removed the opened attribute from TextAnnotation. Fixed a bug in Annotation::Window. PDFGenerator: added postprocessing for handle the special pdf cases on TextAnnotations (where window geometry is embedded in annotation, not in popup and the annotation should be represented as an icon). svn path=/branches/kpdf_annotations/kdegraphics/kpdf/; revision=404023 --- core/annotations.cpp | 16 +++------ core/annotations.h | 1 - core/generator_pdf/generator_pdf.cpp | 52 +++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/core/annotations.cpp b/core/annotations.cpp index cb678d96a..a44f686df 100644 --- a/core/annotations.cpp +++ b/core/annotations.cpp @@ -88,7 +88,7 @@ Annotation::Style::Style() effectIntensity( 1.0 ) {} Annotation::Window::Window() - : flags( 0 ), width( 0 ), height( 0 ) {} + : flags( -1 ), width( 0 ), height( 0 ) {} Annotation::Revision::Revision() : annotation( 0 ), scope( Reply ), type( None ) {} @@ -312,15 +312,13 @@ void Annotation::store( QDomNode & annNode, QDomDocument & document ) const /** TextAnnotation [Annotation] */ TextAnnotation::TextAnnotation() - : Annotation(), textType( Linked ), textFont(), - textOpened( false ), textIcon( "Comment" ), inplaceAlign( 0 ), - inplaceIntent( Unknown ) + : Annotation(), textType( Linked ), textFont(), textIcon( "Comment" ), + inplaceAlign( 0 ), inplaceIntent( Unknown ) {} TextAnnotation::TextAnnotation( const QDomNode & node ) - : Annotation( node ), textType( Linked ), textFont(), - textOpened( false ), textIcon( "Comment" ), inplaceAlign( 0 ), - inplaceIntent( Unknown ) + : Annotation( node ), textType( Linked ), textFont(), textIcon( "Comment" ), + inplaceAlign( 0 ), inplaceIntent( Unknown ) { // loop through the whole children looking for a 'text' element QDomNode subNode = node.firstChild(); @@ -336,8 +334,6 @@ TextAnnotation::TextAnnotation( const QDomNode & node ) textType = (TextAnnotation::TextType)e.attribute( "type" ).toInt(); if ( e.hasAttribute( "font" ) ) textFont.fromString( e.attribute( "font" ) ); - if ( e.hasAttribute( "opened" ) ) - textOpened = e.attribute( "opened" ).toInt(); if ( e.hasAttribute( "icon" ) ) textIcon = e.attribute( "icon" ); if ( e.hasAttribute( "align" ) ) @@ -386,8 +382,6 @@ void TextAnnotation::store( QDomNode & node, QDomDocument & document ) const textElement.setAttribute( "type", (int)textType ); if ( textFont != QApplication::font() ) textElement.setAttribute( "font", textFont.toString() ); - if ( textOpened ) - textElement.setAttribute( "opened", textOpened ); if ( textIcon != "Comment" ) textElement.setAttribute( "icon", textIcon ); if ( inplaceAlign ) diff --git a/core/annotations.h b/core/annotations.h index 62c4349f6..4d7cdc8c7 100644 --- a/core/annotations.h +++ b/core/annotations.h @@ -156,7 +156,6 @@ struct TextAnnotation : public Annotation // data fields 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 diff --git a/core/generator_pdf/generator_pdf.cpp b/core/generator_pdf/generator_pdf.cpp index 1d3ae3a70..712d343c4 100644 --- a/core/generator_pdf/generator_pdf.cpp +++ b/core/generator_pdf/generator_pdf.cpp @@ -810,6 +810,12 @@ struct ResolveWindow 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) @@ -830,6 +836,7 @@ void PDFGenerator::addAnnotations( Page * pdfPage, KPDFPage * page ) // lists of Windows and Revisions that needs resolution QValueList< ResolveRevision > resolveRevList; QValueList< ResolveWindow > resolvePopList; + QValueList< PostProcessText > ppTextList; // build a normalized transform matrix for this page at 100% scale GfxState * gfxState = new GfxState( 72.0, 72.0, pdfPage->getMediaBox(), pdfPage->getRotate(), gTrue ); @@ -884,13 +891,18 @@ void PDFGenerator::addAnnotations( Page * pdfPage, KPDFPage * page ) { // -> textType t->textType = TextAnnotation::Linked; - // -> textOpened - XPDFReader::lookupBool( annotDict, "Open", t->textOpened ); // -> textIcon XPDFReader::lookupName( annotDict, "Name", t->textIcon ); + // request for postprocessing window geometry + PostProcessText request; + request.textAnnotation = t; + request.opened = false; + XPDFReader::lookupBool( annotDict, "Open", request.opened ); + ppTextList.append( request ); } else { + // NOTE: please provide testcases for FreeText (don't have any) - Enrico // -> textType t->textType = TextAnnotation::InPlace; // -> textFont @@ -1394,7 +1406,8 @@ void PDFGenerator::addAnnotations( Page * pdfPage, KPDFPage * page ) Annotation::Window & w = request.annotation->window; // transfer properties to Annotation's window - w.flags = pa->flags & (Annotation::Hidden | Annotation::FixedRotation); + w.flags = pa->flags & (Annotation::Hidden | + Annotation::FixedSize | Annotation::FixedRotation); if ( !pop->shown ) w.flags |= Annotation::Hidden; w.topLeft.x = pa->boundary.left; @@ -1447,7 +1460,38 @@ void PDFGenerator::addAnnotations( Page * pdfPage, KPDFPage * page ) annotationsMap.remove( excludeIDs[ i ] ); } - /** 4 - finally SET ANNOTATIONS to the page */ + /** 4 - POSTPROCESS TextAnnotations (when window geom is embedded) */ + if ( !ppTextList.isEmpty() ) + { + QValueList< PostProcessText >::const_iterator it = ppTextList.begin(), end = ppTextList.end(); + for ( ; it != end; ++it ) + { + const PostProcessText & request = *it; + Annotation::Window & window = request.textAnnotation->window; + // if not present, 'create' the window in-place over the annotation + if ( window.flags == -1 ) + { + window.flags = 0; + NormalizedRect & geom = request.textAnnotation->boundary; + // initialize window geometry to annotation's one + int width = (int)( page->width() * ( geom.right - geom.left ) ), + height = (int)( page->height() * ( geom.bottom - geom.top ) ); + window.topLeft.x = geom.left > 0.0 ? geom.left : 0.0; + window.topLeft.y = geom.top > 0.0 ? geom.top : 0.0; + window.width = width < 200 ? 200 : width; + window.height = height < 120 ? 120 : width; + // resize annotation's geometry to an icon + geom.right = geom.left + 22.0 / page->width(); + geom.bottom = geom.top + 22.0 / page->height(); + } + // (pdf) if text is not 'opened', force window hiding. if the window + // was parsed from popup, the flag should already be set + if ( !request.opened && window.flags != -1 ) + window.flags |= Annotation::Hidden; + } + } + + /** 5 - finally SET ANNOTATIONS to the page */ QMap< int, Annotation * >::Iterator it = annotationsMap.begin(), end = annotationsMap.end(); for ( ; it != end; ++it ) page->addAnnotation( it.data() );