Hi Dom!

Attached is an updated version of the patch with getters
made inline and throwing an exception if information is unavailable.
I have introduced a new exception for this case as none of the others
seemed to fit.

Best,

Jonathan

Dne pátek 14 května 2010 13:23:33 jste napsal(a): 
> Hi Jonathan,
> 
> Thanks for your contribution! Very nice addition.
> 
> I suggest that you make the getters inline. As well, I would prefer if 
the
> getters would throw an exception if the required information is not
> available. Could you please update your patch? I will commit it, as 
soon
> as I get the updated version.
> 
> Best regards,
>       Dom
From 74f569c3c657b31f8e572eb5005d86ba5ba05ab2 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.h |  187 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/PdfError.h       |    1 +
 2 files changed, 188 insertions(+), 0 deletions(-)

diff --git a/src/PdfDestination.h b/src/PdfDestination.h
index 2b5ae23..2e165dd 100644
--- a/src/PdfDestination.h
+++ b/src/PdfDestination.h
@@ -24,6 +24,7 @@
 #include "PdfDefines.h"
 
 #include "PdfArray.h"
+#include "PdfRect.h"
 #include "PdfReference.h"
 
 namespace PoDoFo {
@@ -43,6 +44,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,7 +126,54 @@ class PODOFO_API PdfDestination {
      */
     PdfPage* GetPage();
     
+    /** Get the destination fit type
+     *
+     *  \returns the fit type
+     */
+    inline EPdfDestinationType GetType() const;
+    
+    /** Get the destination zoom 
+     *  Destination must be of type XYZ
+     *  otherwise exception is thrown.
+     *
+     *  \returns the zoom
+     */
+    inline double GetZoom() const;
+    
+    /** Get the destination rect 
+     *  Destination must be of type FirR
+     *  otherwise exception is thrown
+     *
+     *  \returns the destination rect
+     */
+    inline PdfRect GetRect() const;
+     
+    /** Get the destination Top position
+     *  Destination must be of type XYZ, FitH, FitR, FitBH
+     *  otherwise exception is thrown.
+     * 
+     * \returns the Top position
+     */
+    inline double GetTop() const; 
+    
+    /** Get the destination Left position 
+     *  Destination must be of type XYZ, FitV or FitR
+     *  otherwise exception is thrown.
+     * 
+     * \returns the Left position
+     */
+    inline double GetLeft() const;
+    
+    /** Get the destination Value 
+     *  Destination must be of type FitH, FitV
+     *  or FitBH, otherwise exception is thrown 
+     * 
+     *  \returns the destination Value
+     */
+    inline double GetDValue() const;
+    
     /** Get access to the internal object
+     *
      *  \returns the internal PdfObject
      */
     inline PdfObject* GetObject();
@@ -119,6 +184,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,7 +236,116 @@ 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;
+}
+
+// -----------------------------------------------------
+// 
+// -----------------------------------------------------
+inline 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; 
+}
+
+// -----------------------------------------------------
+// 
+// -----------------------------------------------------
+inline double PdfDestination::GetDValue() const 
+{
+  EPdfDestinationType tp = GetType();
+  
+  if ( tp != ePdfDestinationType_FitH && tp != ePdfDestinationType_FitV && tp != ePdfDestinationType_FitBH )
+    PODOFO_RAISE_ERROR( ePdfError_WrongDestinationType );
+  
+  return m_array[2].GetReal();
+}
+
+// -----------------------------------------------------
+// 
+// -----------------------------------------------------
+inline double PdfDestination::GetLeft() const
+{
+  EPdfDestinationType tp = GetType();
+  
+  if ( tp != ePdfDestinationType_FitV && tp != ePdfDestinationType_XYZ && tp != ePdfDestinationType_FitR )
+    PODOFO_RAISE_ERROR( ePdfError_WrongDestinationType );
+  
+  return m_array[2].GetReal();
+}
+
+// -----------------------------------------------------
+// 
+// -----------------------------------------------------
+inline PdfRect PdfDestination::GetRect() const
+{
+  if ( GetType() != ePdfDestinationType_FitR )
+    PODOFO_RAISE_ERROR( ePdfError_WrongDestinationType );
+  
+  return PdfRect(m_array[2].GetReal(),m_array[3].GetReal(),m_array[4].GetReal(), m_array[5].GetReal());
+}
+
+// -----------------------------------------------------
+// 
+// -----------------------------------------------------
+inline double PdfDestination::GetTop() const
+{
+  EPdfDestinationType tp = GetType();
+  
+  switch (tp) { 
+    case ePdfDestinationType_XYZ:
+      return m_array[3].GetReal();
+    case ePdfDestinationType_FitH:
+    case ePdfDestinationType_FitBH:
+      return m_array[2].GetReal();
+    case ePdfDestinationType_FitR:
+      return m_array[5].GetReal();
+    default:
+      PODOFO_RAISE_ERROR( ePdfError_WrongDestinationType );
+  };
+}
+
+// -----------------------------------------------------
+// 
+// -----------------------------------------------------
+inline double PdfDestination::GetZoom() const
+{
+  
+  if ( GetType() != ePdfDestinationType_XYZ )
+    PODOFO_RAISE_ERROR( ePdfError_WrongDestinationType );
+  
+  return m_array[4].GetReal();
+}
+
 };
 
+
+
+
 #endif // _PDF_DESTINATION_H_
 
diff --git a/src/PdfError.h b/src/PdfError.h
index f23d44c..9bb1ff0 100644
--- a/src/PdfError.h
+++ b/src/PdfError.h
@@ -89,6 +89,7 @@ enum EPdfError {
     ePdfError_UnsupportedFilter,        /**< The requested filter is not yet implemented. */
     ePdfError_UnsupportedFontFormat,    /**< This font format is not supported by PoDoFO. */
     ePdfError_ActionAlreadyPresent,     /**< An Action was already present when trying to add a Destination */
+    ePdfError_WrongDestinationType,     /**< The requested field is not available for the given destination type */
 
     ePdfError_MissingEndStream,         /**< The required token endstream was not found. */
     ePdfError_Date,                     /**< Date/time error */
-- 
1.7.0.4

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

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

Reply via email to