According to Pdf Reference 1.7, 3.8.4 Rectangles:

"Note: Although rectangles are conventionally specified by their lower-left and 
upperright
corners, it is acceptable to specify any two diagonally opposite corners. 
Applications
that process PDF should be prepared to normalize such rectangles in situations
where specific corners are required."

PdfRect class defines a rectangle by lower-left point plus width/height. 
Normalization
of coordinates from array of reals is currently not performed and will result 
in rectangles
with negative width/height when x1 > x2 and/or y1 > y2, which appeared to 
happen in my test
documents. The attached patch performs the required normalization by swapping 
coordinates
in such cases.


---
  src/base/PdfRect.cpp | 31 ++++++++++++++++++++++++++-----
  1 file changed, 26 insertions(+), 5 deletions(-)



diff --git a/src/base/PdfRect.cpp b/src/base/PdfRect.cpp
index f2d3449..482e318 100644
--- a/src/base/PdfRect.cpp
+++ b/src/base/PdfRect.cpp
@@ -40,6 +40,8 @@
 #include <iostream>
 #include <sstream>
 #include <iomanip>
+
+static void NormalizeCoordinates( double &coord1, double &coord2 );
 
 namespace PoDoFo {
 
@@ -103,11 +105,20 @@ std::string PdfRect::ToString() const
 void PdfRect::FromArray( const PdfArray& inArray )
 {
     if ( inArray.size() == 4 ) 
-    {
-        m_dLeft   = inArray[0].GetReal();
-        m_dBottom = inArray[1].GetReal();
-        m_dWidth  = inArray[2].GetReal() - m_dLeft;
-        m_dHeight = inArray[3].GetReal() - m_dBottom;
+    {
+        double x1 = inArray[0].GetReal();
+        double y1 = inArray[1].GetReal();
+        double x2 = inArray[2].GetReal();
+        double y2 = inArray[3].GetReal();
+
+        // See Pdf Reference 1.7, 3.8.4 Rectangles
+        NormalizeCoordinates( x1, x2 );
+        NormalizeCoordinates( y1, y2 );
+
+        m_dLeft   = x1;
+        m_dBottom = y1;
+        m_dWidth  = x2 - x1;
+        m_dHeight = y2 - y1;
     }
     else 
     {
@@ -160,3 +171,13 @@ PdfRect & PdfRect::operator=( const PdfRect & rhs )
 }
 
 };
+
+void NormalizeCoordinates( double & coord1, double & coord2 )
+{
+    if ( coord1 > coord2 )
+    {
+        double temp = coord1;
+        coord1 = coord2;
+        coord2 = temp;
+    }
+}


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to