Hello, 

I am working on a little program to allow me to annotate PDF files.
I am using PoDoFo to parse the pdf's and to save them. I found out
that PoDoFo, as of yet, does not fully support hilight annotations.
In particular it doesn't allow me to set/get the QuadPoints array in 
the annotation's dictionary which is required for hilight 
annotations (Pdf spec. v1.7, section 8.4.5 Annotation Types --- 
Text Markup Annotations, p. 634 ).

Below is my first attempt at implementing hilight annotation support 
in PoDoFo (basically add a PdfArray parameter to the constructor of 
an annotation and to PdfPage::CreateAnnotation which will hold the 
QuadPoints array. Then, in the constructor, I add this array to the
annotation's dictionary. Furthermore I add a method 
PdfAnnotation::GetQuadPoints which retrieves the QuadPoints array).

I am not sure if this is the right approach. Reading through the 
spec, it seems, that to fully support all annotation types, a 
better thought out approach would be necessary --- i.e. to not add
new annotation type support ad hoc. That would be quite a lot of
work and I am not able to commit myself to this so I only hacked up 
the hilight annotation support which I need. 

Have a nice day,

Jonathan Verner
Index: PdfAnnotation.h
===================================================================
--- PdfAnnotation.h	(revision 947)
+++ PdfAnnotation.h	(working copy)
@@ -109,7 +109,7 @@
      *
      *  \see PdfPage::CreateAnnotation
      */
-    PdfAnnotation( PdfPage* pPage, EPdfAnnotation eAnnot, const PdfRect & rRect, PdfVecObjects* pParent );
+    PdfAnnotation( PdfPage* pPage, EPdfAnnotation eAnnot, const PdfRect & rRect, PdfVecObjects* pParent, PdfArray *quadPoints = NULL );
 
     /** Create a PdfAnnotation from an existing object
      *
@@ -136,6 +137,19 @@
      */
     PdfRect GetRect() const;
 
+    /** Get the quad points associated with the annotation (if appropriate).
+     *  This array is used in text markup annotations to describe the
+     *  regions affected by the markup (i.e. the hilighted words, one
+     *  quadrilateral per word)
+     *
+     *  \returns a PdfArray of 8xn numbers describing the
+     *           x,y coordinates of BL BR TR TL corners of the
+     *           quadrilaterals. If inappropriate, returns
+     *           an empty array.
+     */
+
+    PdfArray GetQuadPoints() const;
+
     /** Set the flags of this annotation.
      *  \param uiFlags is an unsigned 32bit integer with different 
      *                 EPdfAnnotationFlags OR'ed together.
Index: PdfPage.cpp
===================================================================
--- PdfPage.cpp	(revision 947)
+++ PdfPage.cpp	(working copy)
@@ -232,9 +232,9 @@
     return pObj ? static_cast<int>(pObj->GetArray().size()) : 0;
 }
 
-PdfAnnotation* PdfPage::CreateAnnotation( EPdfAnnotation eType, const PdfRect & rRect )
+PdfAnnotation* PdfPage::CreateAnnotation( EPdfAnnotation eType, const PdfRect & rRect, PdfArray *quadPoints )
 {
-    PdfAnnotation* pAnnot = new PdfAnnotation( this, eType, rRect, m_pObject->GetOwner() );
+    PdfAnnotation* pAnnot = new PdfAnnotation( this, eType, rRect, m_pObject->GetOwner(), quadPoints );
     PdfObject*     pObj   = this->GetAnnotationsArray( true );
     PdfReference   ref    = pAnnot->GetObject()->Reference();
 
Index: PdfPage.h
===================================================================
--- PdfPage.h	(revision 947)
+++ PdfPage.h	(working copy)
@@ -150,7 +150,7 @@
      *
      *  \returns the annotation object which is owned by the PdfPage
      */
-    PdfAnnotation* CreateAnnotation( EPdfAnnotation eType, const PdfRect & rRect );
+    PdfAnnotation* CreateAnnotation( EPdfAnnotation eType, const PdfRect & rRect, PdfArray *quadPoints = NULL );
 
     /** Get the annotation with index index of the current page.
      *  \param index the index of the annotation to retrieve
Index: PdfAnnotation.cpp
===================================================================
--- PdfAnnotation.cpp	(revision 947)
+++ PdfAnnotation.cpp	(working copy)
@@ -61,7 +61,7 @@
     NULL
 };
 
-PdfAnnotation::PdfAnnotation( PdfPage* pPage, EPdfAnnotation eAnnot, const PdfRect & rRect, PdfVecObjects* pParent )
+PdfAnnotation::PdfAnnotation( PdfPage* pPage, EPdfAnnotation eAnnot, const PdfRect & rRect, PdfVecObjects* pParent, PdfArray *quadPoints )
     : PdfElement( "Annot", pParent ), m_eAnnotation( eAnnot ), m_pAction( NULL ), m_pFileSpec( NULL ), m_pPage( pPage )
 {
     PdfVariant    rect;
@@ -85,8 +85,14 @@
     m_pObject->GetDictionary().AddKey( PdfName::KeyRect, rect );
     m_pObject->GetDictionary().AddKey( "P", pPage->GetObject()->Reference() );
     m_pObject->GetDictionary().AddKey( "M", sDate );
+    if ( eAnnot == ePdfAnnotation_Highlight ) { 
+      if ( ! quadPoints ) PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
+      m_pObject->GetDictionary().AddKey( "QuadPoints", *quadPoints );
+    }
 }
 
+
+
 PdfAnnotation::PdfAnnotation( PdfObject* pObject, PdfPage* pPage )
     : PdfElement( "Annot", pObject ), m_eAnnotation( ePdfAnnotation_Unknown ), m_pAction( NULL ), m_pFileSpec( NULL ), m_pPage( pPage )
 {
@@ -107,23 +113,39 @@
    return PdfRect();
 }

+PdfArray PdfAnnotation::GetQuadPoints() const
+{
+  if( m_pObject->GetDictionary().HasKey( "QuadPoints" ) )
+    return PdfArray( m_pObject->GetDictionary().GetKey( "QuadPoints" )->GetArray() );
+  return PdfArray();
+}


Attachment: signature.asc
Description: This is a digitally signed message part.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to