Hi Dominik.

Thank you for applying the patch. The approach to have a separate
method to set the quadpoints is definitely better, my bad. Sorry to 
overwhelm you, but attached please find another patch, which has
two objectives:

  1) fixes a typo in the SetQuadPoints method

  2) Adds the possibility to set/get the color of the annotations.
      Without this, the hilight annotations are transparent (since
      the C key is missing from the dictionary), so are not of much
      use :-)

Regarding the refactoring, I can also try to think about it, but I 
don't have much experience and even less time :-(

Best, 

Jonathan

P.S. The documentation for the quadpoints follows the pdf spec.,
but seems to be at odds with how it actually works in Acrobat 
Reader. I seem to get the best results if the order of the points
is TopLeft TopRright BottomLeft BottomRight. However there might
be a bug somewhere in my code, so I'll try to do some more testing
to confirm where the problem is.
     
Dne Saturday 15 November 2008 16:46:31 Dominik Seichter napsal(a):
> Hi Jonathan,
>
> Thanks for your patch. I commited the GetQuadPoints method you
> added. Instead of adding the quadpoints argument to the
> CreateAnnotation method, I added a method SetQuadPoints. This
> should work for you as well and is more consistent with all the
> currently available annotations.
>
> The annotation API is not very good and needs some refactoring.
> So the set method is no good solution either, but I prefer it
> more to adding all possible arguments to the CreateAnnoations
> method. This might be a matter of taste. Well, maybe I'l lfind
> sometimes a minute to think of a better approach. Patches are
> welcome of course :)
>
> best regards
>       Dom
Index: PdfAnnotation.h
===================================================================
--- PdfAnnotation.h	(revision 967)
+++ PdfAnnotation.h	(working copy)
@@ -294,6 +294,62 @@
      */
     void SetQuadPoints( const PdfArray & rQuadPoints );
 
+    /** Get the color key of the Annotation dictionary
+     *  which defines the color of the annotation, 
+     *  as per 8.4 of the pdf spec. The PdfArray contains
+     *  0 to four numbers, depending on the colorspace in
+     *  which the color is specified
+     *  0 numbers means the annotation is transparent
+     *  1 number specifies the intensity of the color in grayscale
+     *  3 numbers specifie the color in the RGB colorspace and
+     *  4 numbers specify the color in the CMYK colorspace
+     *
+     *  \returns a PdfArray of either 0, 1, 3 or 4 numbers
+     *           depending on the colorspace in which the color
+     *           is specified
+     */
+
+    PdfArray GetColor() const;
+
+    /** Set the C key of the Annotation dictionary, which defines the
+     *  color of the annotation, as per 8.4 of the pdf spec. Parameters
+     *  give the color in rgb colorspace coordinates
+     *
+     *  \param r number from 0 to 1, the intensity of the red channel 
+     *  \param g number from 0 to 1, the intensity of the green channel 
+     *  \param b number from 0 to 1, the intensity of the blue channel 
+     */
+
+    void SetColor( double r, double g, double b );
+
+    /** Set the C key of the Annotation dictionary, which defines the
+     *  color of the annotation, as per 8.4 of the pdf spec. Parameters
+     *  give the color in cmyk colorspace coordinates
+     *
+     *  \param c number from 0 to 1, the intensity of the cyan channel 
+     *  \param m number from 0 to 1, the intensity of the magneta channel 
+     *  \param y number from 0 to 1, the intensity of the yellow channel 
+     *  \param k number from 0 to 1, the intensity of the black channel 
+     */
+
+    void SetColor( double c, double m, double y, double k );
+
+    /** Set the C key of the Annotation dictionary, which defines the
+     *  color of the annotation, as per 8.4 of the pdf spec. Parameters
+     *  give the color in grayscale colorspace coordinates
+     *
+     *  \param gray  number from 0 to 1, the intensity of the black
+     */
+
+    void SetColor( double gray );
+
+    /** Set the C key of the Annotation dictionary to an empty array, which,
+     *  as per 8.4 of the pdf spec., makes the annotation transparent
+     *
+     */
+
+    void SetColor();
+
     /** Get the type of this annotation
      *  \returns the annotation type
      */
Index: PdfAnnotation.cpp
===================================================================
--- PdfAnnotation.cpp	(revision 967)
+++ PdfAnnotation.cpp	(working copy)
@@ -272,10 +272,44 @@
 
 void PdfAnnotation::SetQuadPoints( const PdfArray & rQuadPoints )
 {
-    if ( m_eAnnotation == ePdfAnnotation_Highlight )
+    if ( m_eAnnotation != ePdfAnnotation_Highlight )
         PODOFO_RAISE_ERROR_INFO( ePdfError_InternalLogic, "Must be a highlight annotation to set quad points" );
 
     m_pObject->GetDictionary().AddKey( "QuadPoints", rQuadPoints );
 }
 
+PdfArray PdfAnnotation::GetColor() const
+{
+    if( m_pObject->GetDictionary().HasKey( "C" ) )
+        return PdfArray( m_pObject->GetDictionary().GetKey( "C" )->GetArray() );
+    return PdfArray();
+}
+
+void PdfAnnotation::SetColor( double r, double g, double b ) {
+  PdfArray c;
+  c.push_back( PdfVariant( r ) );
+  c.push_back( PdfVariant( g ) );
+  c.push_back( PdfVariant( b ) );
+  m_pObject->GetDictionary().AddKey( "C", c );
+}
+void PdfAnnotation::SetColor( double C, double M, double Y, double K ) {
+  PdfArray c;
+  c.push_back( PdfVariant( C ) );
+  c.push_back( PdfVariant( M ) );
+  c.push_back( PdfVariant( Y ) );
+  c.push_back( PdfVariant( K ) );
+  m_pObject->GetDictionary().AddKey( "C", c );
+}
+
+void PdfAnnotation::SetColor( double gray ) {
+  PdfArray c;
+  c.push_back( PdfVariant( gray ) );
+  m_pObject->GetDictionary().AddKey( "C", c );
+}
+
+void PdfAnnotation::SetColor() {
+  PdfArray c;
+  m_pObject->GetDictionary().AddKey( "C", c );
+}
+
 };

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