Hello, 

I am working on a program which uses PoDoFo to save/read 
annotations to/from pdf files. When I am reading a Link Annotation and 
get its Destination, I need to be able to actually find the parameters of 
the destination. The PdfDestination class has a method to determine
the Page but no method to e.g. determine the fit rectangle. Attached
is a patch which adds methods that allow to retrieve this additional
information.

I have some questions:

First Is there another way to do this which I missed and which would
make this patch superfluous?

Regarding the patch: 

 1) Should the get methods be made inline?

 2) Since the information available depends on the Destination Type,
     should the get methods check whether the destination type
     supports the information to be got or should this be left up
     to the user? If it should check, then in case the information is
     unavailable, should it return a "void" value or should it throw
     an error.



Have a nice day,

Jonathan Verner
From 4d864492ae6f4845a177aa8619ce61eff7680427 Mon Sep 17 00:00:00 2001
From: Jonathan L. Verner <[email protected]>
Date: Fri, 14 May 2010 11:55:22 +0200
Subject: [PATCH] Add methods to the PdfDestination class to access its internal array and parameters.

---
 src/PdfDestination.cpp |   44 +++++++++++++++++++++++
 src/PdfDestination.h   |   89 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+), 0 deletions(-)

diff --git a/src/PdfDestination.cpp b/src/PdfDestination.cpp
index 21104a7..fee8845 100644
--- a/src/PdfDestination.cpp
+++ b/src/PdfDestination.cpp
@@ -189,4 +189,48 @@ PdfPage* PdfDestination::GetPage()
     return pDoc->GetPagesTree()->GetPage( m_array[0].GetReference() );
 }
 
+EPdfDestinationType PdfDestination::GetType() const {
+  if ( !m_array.size() ) 
+    return ePdfDestinationType_Unknown;  
+
+  PdfName tp = m_array[1].GetName();
+  
+  if ( tp == PdfName("XYZ") ) return ePdfDestinationType_XYZ;
+  if ( tp == PdfName("Fit") ) return ePdfDestinationType_Fit;
+  if ( tp == PdfName("FitH") ) return ePdfDestinationType_FitH;
+  if ( tp == PdfName("FitV") ) return ePdfDestinationType_FitV;   
+  if ( tp == PdfName("FitR") ) return ePdfDestinationType_FitR; 
+  if ( tp == PdfName("FitB") ) return ePdfDestinationType_FitB; 
+  if ( tp == PdfName("FitBH") ) return ePdfDestinationType_FitBH; 
+  if ( tp == PdfName("FitBV") ) return ePdfDestinationType_FitBV; 
+  
+  return ePdfDestinationType_Unknown; 
+}
+
+
+double PdfDestination::GetDValue() const 
+{
+  return m_array[2].GetReal();
+}
+
+double PdfDestination::GetLeft() const
+{
+  return m_array[2].GetReal();
+}
+
+PdfRect PdfDestination::GetRect() const
+{
+  return PdfRect(m_array[2].GetReal(),m_array[3].GetReal(),m_array[4].GetReal(), m_array[5].GetReal());
+}
+
+double PdfDestination::GetTop() const
+{
+  return m_array[3].GetReal();
+}
+
+double PdfDestination::GetZoom() const
+{
+  return m_array[4].GetReal();
+}
+
 };
diff --git a/src/PdfDestination.h b/src/PdfDestination.h
index 2b5ae23..d2a79e1 100644
--- a/src/PdfDestination.h
+++ b/src/PdfDestination.h
@@ -43,6 +43,23 @@ enum EPdfDestinationFit {
     ePdfDestinationFit_Unknown = 0xFF
 };
 
+/** Destination type, as per 12.3.2.2 of the Pdf spec.
+ *
+ *  (see table 151 in the pdf spec)
+ */
+enum EPdfDestinationType {
+  ePdfDestinationType_XYZ,
+  ePdfDestinationType_Fit,
+  ePdfDestinationType_FitH,
+  ePdfDestinationType_FitV,
+  ePdfDestinationType_FitR,
+  ePdfDestinationType_FitB,
+  ePdfDestinationType_FitBH,
+  ePdfDestinationType_FitBV,
+  
+  ePdfDestinationType_Unknown = 0xFF
+};
+
 /** A destination in a PDF file.
  *  A destination can either be a page or an action.
  *
@@ -108,6 +125,47 @@ class PODOFO_API PdfDestination {
      */
     PdfPage* GetPage();
     
+    /** Get the destination fit type
+     *
+     *  \returns the fit type
+     */
+    EPdfDestinationType GetType() const;
+    
+    /** Get the destination zoom (if available, based
+     *  on the fit type)
+     *
+     *  \returns the zoom
+     */
+    double GetZoom() const;
+    
+    /** Get the destination rect (if available, based
+     *  on the fit type)
+     *
+     *  \returns the destination rect
+     */
+    PdfRect GetRect() const;
+     
+    /** Get the destination Top position (if available,
+     * based on the fit type)
+     * 
+     * \returns the Top position
+     */
+    double GetTop() const; 
+    
+    /** Get the destination Left position (if available,
+     * based on the fit type)
+     * 
+     * \returns the Left position
+     */
+    double GetLeft() const;
+    
+    /** Get the destination Value (if available,
+     * based on the fit type)
+     * 
+     * \returns the destination Value
+     */
+    double GetDValue() const;
+    
     /** Get access to the internal object
      *  \returns the internal PdfObject
      */
@@ -119,6 +177,19 @@ class PODOFO_API PdfDestination {
      *  \returns the internal PdfObject
      */
     inline const PdfObject* GetObject() const;
+
+    /** Get access to the internal array
+     *  \returns the internal PdfArray
+     */
+    inline PdfArray &GetArray();
+    
+    /** Get access to the internal array
+     *  This is an overloaded member function.
+     *
+     *  \returns the internal PdfArray
+     */
+    inline const PdfArray &GetArray() const;
+
     
     /** Adds this destination to an dictionary.
      *  This method handles the all the complexities of making sure it's added correctly
@@ -158,6 +229,24 @@ inline const PdfObject* PdfDestination::GetObject() const
     return m_pObject;
 }
 
+// -----------------------------------------------------
+// 
+// -----------------------------------------------------
+inline PdfArray &PdfDestination::GetArray()
+{
+    return m_array;
+}
+
+// -----------------------------------------------------
+// 
+// -----------------------------------------------------
+inline const PdfArray &PdfDestination::GetArray() const
+{
+    return m_array;
+}
+
+
+
 };
 
 #endif // _PDF_DESTINATION_H_
-- 
1.7.0.4

------------------------------------------------------------------------------

_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to