Re: [Podofo-users] About fix for CVE-2017- 6845 (Was: Re: Next PoDoFo Release 0.9.6)

2018-02-22 Thread Dominik Seichter via Podofo-users
Hi zyx

Yes that makes sense. I was also wandering why we do have logic checks only
in debug.

Would you be so kind and remove the #ifdef NDEBUG? i do not have acess to
svn right now.

Thanks
Dominik

Am 22.02.2018 09:30 schrieb "zyx" :

> On Wed, 2018-02-21 at 21:51 +0100, Dominik Seichter wrote:
> > It should always be legal to call this:
> > PODOFO_RAISE_LOGIC_IF( m_stack.empty(), "Can get current
> > graphicsstate!" );
> >
> > As it translates to:
> > if( m_stack.empty() ) {
> >  throw ...
> > }
>
> Hi,
> the macro is fine, the problem is whether you compile Release or Debug
> version of the PoDoFo. From src/base/PdfError.h:
>
>#ifndef NDEBUG
>// Woo for double-negatives. We define PODOFO_RAISE_LOGIC_IF unless
> we've been told not to by NDEBUG.
>#define PODOFO_RAISE_LOGIC_IF( x, y ) { if (x) throw
> ::PoDoFo::PdfError( ePdfError_InternalLogic, __FILE__, __LINE__, y ); };
>#else
>#define PODOFO_RAISE_LOGIC_IF( x, y ) {};
>#endif
>
> My suggestion was to remove that '#ifndef NDEBUG' and define the
> PODOFO_RAISE_LOGIC_IF with the 'throw' always, regardless of the build
> type.
>
> Bye,
> zyx
>
--
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


Re: [Podofo-users] About fix for CVE-2017- 6845 (Was: Re: Next PoDoFo Release 0.9.6)

2018-02-22 Thread zyx
On Wed, 2018-02-21 at 21:51 +0100, Dominik Seichter wrote:
> It should always be legal to call this:
> PODOFO_RAISE_LOGIC_IF( m_stack.empty(), "Can get current
> graphicsstate!" );
> 
> As it translates to:
> if( m_stack.empty() ) {
>  throw ...
> }

Hi,
the macro is fine, the problem is whether you compile Release or Debug
version of the PoDoFo. From src/base/PdfError.h:

   #ifndef NDEBUG
   // Woo for double-negatives. We define PODOFO_RAISE_LOGIC_IF unless 
we've been told not to by NDEBUG.
   #define PODOFO_RAISE_LOGIC_IF( x, y ) { if (x) throw ::PoDoFo::PdfError( 
ePdfError_InternalLogic, __FILE__, __LINE__, y ); };
   #else
   #define PODOFO_RAISE_LOGIC_IF( x, y ) {};
   #endif

My suggestion was to remove that '#ifndef NDEBUG' and define the
PODOFO_RAISE_LOGIC_IF with the 'throw' always, regardless of the build
type.

Bye,
zyx

--
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


Re: [Podofo-users] Next PoDoFo Release 0.9.6

2018-02-22 Thread zyx
On Wed, 2018-02-21 at 22:44 +0100, Francesco Pretto wrote:
> Can I send git formatted patches to the mailing list?

Hi,
git-formatted patches are perfectly fine (they generate unified diffs,
which are also easy to read). Ideally include some description what and
why you did in the patch.
Thanks and bye,
zyx

--
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


[Podofo-users] Fwd: Check for preventing signatures from decryption not sufficient

2018-02-22 Thread F. E.
Hello dear podofo users,

today i stumbled upon a parsing bug in PdfTokenizer::ReadDictionary. With
SVN revision 1794, a check was added to prevent a signature content stream
from being decrypted by comparing the dictionary type to "Sig". But this
requires the type to be known/parsed beforehand, otherwise the dictionary
doesn't contain the type (yet). Consequently, if you have a pdf file where
the '/Type/Sig' is declared after the signature content, the check does not
work and the signature content gets decrypted, which in my case ultimately
prevented the pdf file from being loaded successfully. When I prevented the
decryption during debugging, the pdf file was loaded successfully.

I consulted the pdf reference for this issue, but couldn't find any
indication that the dictionary type has to be specified before the
signature content occurs, my test pdf should be perfectly valid. So podofo
needs to be fixed. I tried to analyze the code and a possible solution /
workaround, but I'm not feeling confident & competent enough to come up
with a good, working patch.

Regards,
F.E.
--
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


Re: [Podofo-users] About fix for CVE-2017- 6845 (Was: Re: Next PoDoFo Release 0.9.6)

2018-02-22 Thread zyx
On Thu, 2018-02-22 at 09:38 +0100, Dominik Seichter wrote:
> Would you be so kind and remove the #ifdef NDEBUG? i do not have
> acess to svn right now.
> 

Hi,
sure thing, done as revision 1892:
http://sourceforge.net/p/podofo/code/1892

Bye,
zyx

--
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


[Podofo-users] [PATCH 05/13] PdfPagesTree::InsertPage: Fix "atIndex" is really a 0-based index

2018-02-22 Thread Francesco Pretto

This is also specified in the API documentation. Without the fix
there was a crash trying to insert page at index 0
---
 src/doc/PdfPagesTree.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/doc/PdfPagesTree.cpp b/src/doc/PdfPagesTree.cpp
index 2ee8ea2..9d851d3 100644
--- a/src/doc/PdfPagesTree.cpp
+++ b/src/doc/PdfPagesTree.cpp
@@ -247,11 +247,11 @@ PdfPage* PdfPagesTree::InsertPage( const PdfRect & rSize, 
int atIndex)
 {
 PdfPage* pPage = new PdfPage( rSize, GetRoot()->GetOwner() );
 
-	 if (atIndex < 0 || atIndex >= this->GetTotalNumberOfPages()) {

-atIndex = this->GetTotalNumberOfPages() - 1;
-}
+   if (atIndex < 0 || atIndex > this->GetTotalNumberOfPages()) {
+atIndex = this->GetTotalNumberOfPages();
+   }
 
-	 InsertPage( atIndex - 1, pPage );

+   InsertPage(atIndex, pPage );
 m_cache.AddPageObject( atIndex, pPage );
 
 return pPage;

--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 10/13] PdfVariant: Added SetString method

2018-02-22 Thread Francesco Pretto

---
 src/base/PdfVariant.h | 25 +
 1 file changed, 25 insertions(+)

diff --git a/src/base/PdfVariant.h b/src/base/PdfVariant.h
index f9217d8..fbd3c32 100644
--- a/src/base/PdfVariant.h
+++ b/src/base/PdfVariant.h
@@ -275,6 +275,14 @@ class PODOFO_API PdfVariant {
  *  \return the value of the number
  */
 inline double GetReal() const;
+
+/** Set the string value of this object
+*  \param d the string value
+*
+*  This will set the dirty flag of this object.
+*  \see IsDirty
+*/
+inline void SetString(const PdfString &);
 
 /** \returns the value of the object as string.

  */
@@ -722,6 +730,23 @@ PdfData & PdfVariant::GetRawData()
 // We need a c-style casts here to avoid crashes
 // because a reinterpret_cast might point to a different position.
 return *((PdfData*)m_Data.pData);
+}
+
+// -
+//
+// -
+void PdfVariant::SetString(const PdfString )
+{
+DelayedLoad();
+
+if (!IsString())
+{
+PODOFO_RAISE_ERROR(ePdfError_InvalidDataType);
+}
+
+AssertMutable();
+*((PdfString*)m_Data.pData) = str;
+SetDirty(true);
 }
 
 // -

--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 13/13] PdfDictionary: Added support for range iteration

2018-02-22 Thread Francesco Pretto

Also added a convenience GetSize() method
---
 src/base/PdfDictionary.cpp | 10 ++
 src/base/PdfDictionary.h   | 16 +++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/base/PdfDictionary.cpp b/src/base/PdfDictionary.cpp
index 65ed73a..d2e3da5 100644
--- a/src/base/PdfDictionary.cpp
+++ b/src/base/PdfDictionary.cpp
@@ -364,6 +364,16 @@ void PdfDictionary::SetDirty( bool bDirty )
 ++it;
 }
 }
+}
+
+TCIKeyMap PdfDictionary::begin() const
+{
+return m_mapKeys.begin();
+}
+
+TCIKeyMap PdfDictionary::end() const
+{
+return m_mapKeys.end();
 }
 
 };

diff --git a/src/base/PdfDictionary.h b/src/base/PdfDictionary.h
index 67043af..7a25f5a 100644
--- a/src/base/PdfDictionary.h
+++ b/src/base/PdfDictionary.h
@@ -238,6 +238,11 @@ class PODOFO_API PdfDictionary : public PdfDataType {
  */
 void Write( PdfOutputDevice* pDevice, EPdfWriteMode eWriteMode,
 const PdfEncrypt* pEncrypt, const PdfName & keyStop = 
PdfName::KeyNull ) const;
+
+/**
+*  \returns the size of the internal map
+*/
+inline size_t GetSize() const;
 
 /** Get access to the internal map of keys.

  *
@@ -270,7 +275,11 @@ class PODOFO_API PdfDictionary : public PdfDataType {
  *
  *  \see IsDirty
  */
-virtual void SetDirty( bool bDirty );
+virtual void SetDirty( bool bDirty );
+
+ public:
+ TCIKeyMap begin() const;
+ TCIKeyMap end() const;
 
  private:

 TKeyMap  m_mapKeys;
@@ -281,6 +290,11 @@ class PODOFO_API PdfDictionary : public PdfDataType {
 typedef std::vector  TVecDictionaries;
 typedefTVecDictionaries::iterator   TIVecDictionaries;
 typedefTVecDictionaries::const_iterator TCIVecDictionaries;
+
+size_t PdfDictionary::GetSize() const
+{
+return m_mapKeys.size();
+}
 
 // -

 //
--
2.16.1.windows.1


--
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


[Podofo-users] [PATCH] Fix compilation error including libidn in MSVC

2018-02-22 Thread Francesco Pretto

---
 src/base/PdfEncrypt.cpp | 5 +
 1 file changed, 5 insertions(+)

diff --git a/src/base/PdfEncrypt.cpp b/src/base/PdfEncrypt.cpp
index 115925f..06cf8bd 100644
--- a/src/base/PdfEncrypt.cpp
+++ b/src/base/PdfEncrypt.cpp
@@ -38,6 +38,11 @@
 #ifdef PODOFO_HAVE_LIBIDN
 // AES-256 dependencies :
 // SASL
+#if defined(_MSC_VER)
+// Fix missing posix "ssize_t" typedef in MS compilers
+#include 
+typedef SSIZE_T ssize_t;
+#endif
 #include 
 #include 
 #endif // PODOFO_HAVE_LIBIDN
--
2.16.1.windows.1


--
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


[Podofo-users] [PATCH 3/3] PdfAnnotation: Added GetAppearanceStream method

2018-02-22 Thread Francesco Pretto

Returns found apperance object in the owner dictionary
---
 src/doc/PdfAnnotation.cpp | 37 -
 src/doc/PdfAnnotation.h   | 10 +-
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/src/doc/PdfAnnotation.cpp b/src/doc/PdfAnnotation.cpp
index 765da2f..712ec7f 100644
--- a/src/doc/PdfAnnotation.cpp
+++ b/src/doc/PdfAnnotation.cpp
@@ -246,9 +246,29 @@ void PdfAnnotation::SetAppearanceStream( PdfObject* 
pObject, EPdfAnnotationAppea
 bool PdfAnnotation::HasAppearanceStream() const
 {
 return this->GetObject()->GetDictionary().HasKey( "AP" );
+}
+
+PdfObject * PdfAnnotation::GetAppearanceStream(EPdfAnnotationAppearance 
eAppearance) const
+{
+PdfObject *apObj;
+if (!this->GetObject()->GetDictionary().TryGetKey("AP", apObj))
+return nullptr;
+
+if (apObj->GetDataType() != ePdfDataType_Dictionary)
+PODOFO_RAISE_ERROR(ePdfError_InvalidDataType);
+
+PdfName apName = GetAppearanceName(eAppearance);
+PdfObject *apObjInn;
+if (!apObj->GetDictionary().TryGetKey(apName, apObjInn))
+return nullptr;
+
+if (apObjInn->GetDataType() != ePdfDataType_Reference)
+PODOFO_RAISE_ERROR(ePdfError_InvalidDataType);
+
+PdfReference reference = apObjInn->GetReference();
+return GetObject()->GetOwner()->GetObject(reference);
 }
 
-

 void PdfAnnotation::SetFlags( pdf_uint32 uiFlags )
 {
 this->GetObject()->GetDictionary().AddKey( "F", PdfVariant( 
static_cast(uiFlags) ) );
@@ -434,6 +454,21 @@ void PdfAnnotation::SetColor()
 {
 PdfArray c;
 this->GetObject()->GetDictionary().AddKey( "C", c );
+}
+
+PdfName PdfAnnotation::GetAppearanceName(EPdfAnnotationAppearance eAppearance) 
const
+{
+switch (eAppearance)
+{
+case PoDoFo::ePdfAnnotationAppearance_Normal:
+return PdfName("N");
+case PoDoFo::ePdfAnnotationAppearance_Rollover:
+return PdfName("R");
+case PoDoFo::ePdfAnnotationAppearance_Down:
+return PdfName("D");
+default:
+PODOFO_RAISE_ERROR_INFO(ePdfError_InternalLogic, "Invalid appearance 
type");
+}
 }
 
 };

diff --git a/src/doc/PdfAnnotation.h b/src/doc/PdfAnnotation.h
index ccbd504..739b7cf 100644
--- a/src/doc/PdfAnnotation.h
+++ b/src/doc/PdfAnnotation.h
@@ -164,7 +164,12 @@ class PODOFO_DOC_API PdfAnnotation : public PdfElement {
 /**
  * \returns true if this annotation has an appearance stream
  */
-bool HasAppearanceStream() const;
+bool HasAppearanceStream() const;
+
+/**
+* \returns the appearance stream for this object
+*/
+PdfObject * GetAppearanceStream(EPdfAnnotationAppearance eAppearance = 
ePdfAnnotationAppearance_Normal) const;
 
 /** Get the rectangle of this annotation

  *  \returns a rectangle
@@ -402,6 +407,9 @@ class PODOFO_DOC_API PdfAnnotation : public PdfElement {
  *  \returns the page of this PdfField
  */
 inline PdfPage* GetPage() const;
+
+ private:
+ PdfName GetAppearanceName(EPdfAnnotationAppearance eAppearance) const;
 
  private:

 /** Convert an annotation enum to its string representation
--
2.16.1.windows.1


--
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


[Podofo-users] [PATCH 08/13] PdfDictionary: Added efficient TryGetKey method

2018-02-22 Thread Francesco Pretto

---
 src/base/PdfDictionary.cpp | 13 +
 src/base/PdfDictionary.h   | 12 +++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/base/PdfDictionary.cpp b/src/base/PdfDictionary.cpp
index b0be927..65ed73a 100644
--- a/src/base/PdfDictionary.cpp
+++ b/src/base/PdfDictionary.cpp
@@ -166,6 +166,19 @@ const PdfObject* PdfDictionary::GetKey( const PdfName & 
key ) const
 }
 
 return NULL;

+}
+
+const bool PdfDictionary::TryGetKey(const PdfName & key, PdfObject *& object) 
const
+{
+TCIKeyMap found = m_mapKeys.find(key);
+if (found == m_mapKeys.end())
+{
+object = nullptr;
+return false;
+}
+
+object = found->second;
+return true;
 }
 
 PdfObject* PdfDictionary::GetKey( const PdfName & key )

diff --git a/src/base/PdfDictionary.h b/src/base/PdfDictionary.h
index 0a4493a..67043af 100644
--- a/src/base/PdfDictionary.h
+++ b/src/base/PdfDictionary.h
@@ -165,7 +165,17 @@ class PODOFO_API PdfDictionary : public PdfDataType {
  *
  *  \returns pointer to the found value or 0 if the key was not found.
  */
-const PdfObject* GetKey( const PdfName & key ) const;
+const PdfObject* GetKey( const PdfName & key ) const;
+
+/** Try Get the keys value out of the dictionary.
+*
+*  \param key look for the key names pszKey in the dictionary
+*  \object found object, null if not not found
+*
+*  \returns true if key found
+*  \see GetKey
+*/
+const bool TryGetKey(const PdfName & key, PdfObject *& object) const;
 
 /** Get the keys value out of the dictionary.  This is an overloaded member

  * function.
--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 03/13] PdfPainter: Removed unneed cast

2018-02-22 Thread Francesco Pretto

PdfImage is a PdfXObject
---
 src/doc/PdfPainter.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/doc/PdfPainter.cpp b/src/doc/PdfPainter.cpp
index 03a5d05..fc5c0de 100644
--- a/src/doc/PdfPainter.cpp
+++ b/src/doc/PdfPainter.cpp
@@ -1320,7 +1320,7 @@ void PdfPainter::DrawGlyph( PdfMemDocument* pDocument, 
double dX, double dY, con
 
 void PdfPainter::DrawImage( double dX, double dY, PdfImage* pObject, double dScaleX, double dScaleY )

 {
-this->DrawXObject( dX, dY, reinterpret_cast(pObject),
+this->DrawXObject( dX, dY, pObject,
dScaleX * pObject->GetPageSize().GetWidth(),
dScaleY * pObject->GetPageSize().GetHeight() );
 }
--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 09/13] PdfPage: Added SetMediaBox method

2018-02-22 Thread Francesco Pretto

---
 src/doc/PdfPage.cpp | 13 +
 src/doc/PdfPage.h   |  5 +
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/doc/PdfPage.cpp b/src/doc/PdfPage.cpp
index e933732..d0437ee 100644
--- a/src/doc/PdfPage.cpp
+++ b/src/doc/PdfPage.cpp
@@ -105,10 +105,8 @@ PdfPage::~PdfPage()
 }
 
 void PdfPage::InitNewPage( const PdfRect & rSize )

-{
-PdfVariant mediabox;
-rSize.ToVariant( mediabox );
-this->GetObject()->GetDictionary().AddKey( "MediaBox", mediabox );
+{
+SetMediaBox(rSize);
 
 // The PDF specification suggests that we send all available PDF Procedure sets

 this->GetObject()->GetDictionary().AddKey( "Resources", PdfObject( 
PdfDictionary() ) );
@@ -563,6 +561,13 @@ bool PdfPage::SetPageHeight(int newHeight)
 {
 return false;
 }
+}
+
+void PdfPage::SetMediaBox(const PdfRect & rSize)
+{
+PdfVariant mediaBox;
+rSize.ToVariant(mediaBox);
+this->GetObject()->GetDictionary().AddKey("MediaBox", mediaBox);
 }
 
 void PdfPage::SetTrimBox( const PdfRect & rSize )

diff --git a/src/doc/PdfPage.h b/src/doc/PdfPage.h
index fe04869..2e5fc23 100644
--- a/src/doc/PdfPage.h
+++ b/src/doc/PdfPage.h
@@ -108,6 +108,11 @@ class PODOFO_DOC_API PdfPage : public PdfElement, public 
PdfCanvas {
  *
  */
 bool SetPageHeight(int newHeight);
+
+/** Set the mediabox in PDF Units
+*  \param rSize a PdfRect specifying the mediabox of the page (i.e the 
/TrimBox key) in PDF units
+*/
+void SetMediaBox(const PdfRect & rSize);
 
 /** Set the trimbox in PDF Units

  *  \param rSize a PdfRect specifying the trimbox of the page (i.e the 
/TrimBox key) in PDF units
--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 06/13] PdfAnnotation: Removed duplicated set rect on constructor

2018-02-22 Thread Francesco Pretto

---
 src/doc/PdfAnnotation.cpp | 4 
 1 file changed, 4 deletions(-)

diff --git a/src/doc/PdfAnnotation.cpp b/src/doc/PdfAnnotation.cpp
index a02f05d..f95e82c 100644
--- a/src/doc/PdfAnnotation.cpp
+++ b/src/doc/PdfAnnotation.cpp
@@ -92,10 +92,6 @@ PdfAnnotation::PdfAnnotation( PdfPage* pPage, EPdfAnnotation 
eAnnot, const PdfRe
 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
 }
 
-rRect.ToVariant( rect );

-
-this->GetObject()->GetDictionary().AddKey( PdfName::KeyRect, rect );
-
 rRect.ToVariant( rect );
 date.ToString( sDate );
 
--

2.16.1.windows.1



--
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


[Podofo-users] [PATCH 12/13] Added .editorconfig

2018-02-22 Thread Francesco Pretto

See http://editorconfig.org/
---
 .editorconfig | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 .editorconfig

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 000..6dbc0b2
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,11 @@
+[*.{cpp,h,hpp}]
+end_of_line = crlf
+charset = utf-8
+indent_style = space
+indent_size = 4
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.txt]
+end_of_line = lf
+charset = utf-8
--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 00/13] Miscellaneous fixes and improvements

2018-02-22 Thread Francesco Pretto

It follows a series of patches with miscellaneous crash fixes and
improvements to the API. Most of them should be straightforward.
On some enums I added a convenience "Unknown" value following the
convention often found in Podofo that Unknown=0xff. This is helpful
for me when casting to other private enums that I use which follow
convention Unknown=0. Also I added a convenience .editorconfig file.

Francesco Pretto (13):
  Fix msvc source group for podofo project headers
  PdfMemDocument::Load: Fix wrong use of memcpy instead of wmemcpy
  PdfPainter: Removed unneed cast
  PdfAnnotation: Added SetRect
  PdfPagesTree::InsertPage: Fix "atIndex" is really a 0-based index
  PdfAnnotation: Removed duplicated set rect on constructor
  EPdfDataType: Apply 0xff convention on unknown enum value
  PdfDictionary: Added efficient TryGetKey method
  PdfPage: Added SetMediaBox method
  PdfVariant: Added SetString method
  EPdfPageSize: Added convenience Unknown value using the 0xff
convention
  Added .editorconfig
  PdfDictionary: Added support for range iteration

 .editorconfig  | 11 +++
 src/CMakeLists.txt | 16 +---
 src/base/PdfDefines.h  |  6 --
 src/base/PdfDictionary.cpp | 23 +++
 src/base/PdfDictionary.h   | 28 ++--
 src/base/PdfVariant.h  | 25 +
 src/doc/PdfAnnotation.cpp  | 12 
 src/doc/PdfAnnotation.h|  7 ++-
 src/doc/PdfMemDocument.cpp |  2 +-
 src/doc/PdfPage.cpp| 13 +
 src/doc/PdfPage.h  |  5 +
 src/doc/PdfPagesTree.cpp   |  8 
 src/doc/PdfPainter.cpp |  2 +-
 13 files changed, 132 insertions(+), 26 deletions(-)
 create mode 100644 .editorconfig

--
2.16.1.windows.1


--
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


[Podofo-users] [PATCH 01/13] Fix msvc source group for podofo project headers

2018-02-22 Thread Francesco Pretto

Header files must be added to ADD_LIBRARY() to be seen in MSVC
---
 src/CMakeLists.txt | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 72f2f0f..06f277c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -225,15 +225,17 @@ SET(PODOFO_DOC_HEADERS
   doc/PdfTilingPattern.h
   doc/PdfXObject.h
   )
+
+SET(HEADER_FILES
+  ${PODOFO_HEADERS}
+  ${PODOFO_BASE_HEADERS}
+  ${PODOFO_BASE_HEADERS2}
+  ${PODOFO_DOC_HEADERS})
 
 # Create a Source Group for Visual Studio

 # so that headers are listed in the folder view
 # and are easier accessible
-SOURCE_GROUP(Headers FILES
-  ${PODOFO_HEADERS}
-  ${PODOFO_BASE_HEADERS}
-  ${PODOFO_BASE_HEADERS2}
-  ${PODOFO_DOC_HEADERS})
+SOURCE_GROUP("Header Files" FILES ${HEADER_FILES})
 
 INSTALL(FILES ${PODOFO_HEADERS}

   DESTINATION "include/podofo"
@@ -257,7 +259,7 @@ ENDIF(NOT PODOFO_BUILD_SHARED AND NOT PODOFO_BUILD_STATIC)
 
 IF(PODOFO_BUILD_STATIC)

 MESSAGE("Building static PoDoFo library")
-ADD_LIBRARY(podofo_static STATIC ${PODOFO_BASE_SOURCES} 
${PODOFO_DOC_SOURCES})
+ADD_LIBRARY(podofo_static STATIC ${PODOFO_BASE_SOURCES} 
${PODOFO_DOC_SOURCES} ${HEADER_FILES})
 TARGET_LINK_LIBRARIES(podofo_static ${PODOFO_LIB_DEPENDS})
 SET_TARGET_PROPERTIES(podofo_static PROPERTIES
 VERSION "${PODOFO_LIBVERSION}"
@@ -278,7 +280,7 @@ ENDIF(PODOFO_BUILD_STATIC)
 
 IF(PODOFO_BUILD_SHARED)

 MESSAGE("Building shared PoDoFo library")
-ADD_LIBRARY(podofo_shared SHARED ${PODOFO_BASE_SOURCES} 
${PODOFO_DOC_SOURCES})
+ADD_LIBRARY(podofo_shared SHARED ${PODOFO_BASE_SOURCES} 
${PODOFO_DOC_SOURCES} ${HEADER_FILES})
 TARGET_LINK_LIBRARIES(podofo_shared ${PODOFO_LIB_DEPENDS})
 # TODO: set /wd4251 flag if we're doing a debug build with
 # Visual Studio, since it produces invalid warnings about STL
--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 04/13] PdfAnnotation: Added SetRect

2018-02-22 Thread Francesco Pretto

---
 src/doc/PdfAnnotation.cpp | 8 
 src/doc/PdfAnnotation.h   | 7 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/doc/PdfAnnotation.cpp b/src/doc/PdfAnnotation.cpp
index 941435b..a02f05d 100644
--- a/src/doc/PdfAnnotation.cpp
+++ b/src/doc/PdfAnnotation.cpp
@@ -123,6 +123,14 @@ PdfRect PdfAnnotation::GetRect() const
 return PdfRect( this->GetObject()->GetDictionary().GetKey( 
PdfName::KeyRect )->GetArray() );
 
return PdfRect();

+}
+
+void PdfAnnotation::SetRect(const PdfRect & rrect)
+{
+PdfVariantrect;
+rrect.ToVariant(rect);
+this->GetObject()->GetDictionary().AddKey( PdfName::KeyRect, rect );
+
 }
 
 void SetAppearanceStreamForObject( PdfObject* pForObject, PdfXObject* pObject, EPdfAnnotationAppearance eAppearance, const PdfName & state )

diff --git a/src/doc/PdfAnnotation.h b/src/doc/PdfAnnotation.h
index 7aa1c6f..b774af7 100644
--- a/src/doc/PdfAnnotation.h
+++ b/src/doc/PdfAnnotation.h
@@ -161,7 +161,12 @@ class PODOFO_DOC_API PdfAnnotation : public PdfElement {
 /** Get the rectangle of this annotation
  *  \returns a rectangle
  */
-PdfRect GetRect() const;
+PdfRect GetRect() const;
+
+/** Set the rectangle of this annotation
+*  \param rrect
+*/
+void SetRect( const PdfRect & rrect);
 
 /** Set the flags of this annotation.

  *  \param uiFlags is an unsigned 32bit integer with different
--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 11/13] EPdfPageSize: Added convenience Unknown value using the 0xff convention

2018-02-22 Thread Francesco Pretto

---
 src/base/PdfDefines.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/base/PdfDefines.h b/src/base/PdfDefines.h
index 6f35be5..fcd8f23 100644
--- a/src/base/PdfDefines.h
+++ b/src/base/PdfDefines.h
@@ -381,7 +381,9 @@ enum EPdfPageSize {
 ePdfPageSize_A6,  /**< DIN A6  */
 ePdfPageSize_Letter,  /**< Letter  */
 ePdfPageSize_Legal,   /**< Legal   */
-ePdfPageSize_Tabloid  /**< Tabloid */
+ePdfPageSize_Tabloid, /**< Tabloid */
+
+ePdfPageSize_Unknown = 0xff
 };
 
 /**

--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 02/13] PdfMemDocument::Load: Fix wrong use of memcpy instead of wmemcpy

2018-02-22 Thread Francesco Pretto

---
 src/doc/PdfMemDocument.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/doc/PdfMemDocument.cpp b/src/doc/PdfMemDocument.cpp
index 04e5034..a7255ee 100644
--- a/src/doc/PdfMemDocument.cpp
+++ b/src/doc/PdfMemDocument.cpp
@@ -271,7 +271,7 @@ void PdfMemDocument::Load( const wchar_t* pszFilename, bool 
bForUpdate )
 {
 int lLen = wcslen( pszFilename );
 m_wchar_pszUpdatingFilename = static_cast( podofo_malloc( 
sizeof( wchar_t ) * ( lLen + 1 ) ) );
-memcpy( m_wchar_pszUpdatingFilename, pszFilename, lLen );
+wmemcpy( m_wchar_pszUpdatingFilename, pszFilename, lLen );
 m_wchar_pszUpdatingFilename[lLen] = L'\0';
 }
 
--

2.16.1.windows.1



--
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


[Podofo-users] [PATCH 2/3] PdfSignatureField::SetAppearanceStream: Removed use of unuseful SetAppearanceStreamForObject method

2018-02-22 Thread Francesco Pretto

This was confusing: m_pObject is the annotation PdfObject
---
 src/doc/PdfSignatureField.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/doc/PdfSignatureField.cpp b/src/doc/PdfSignatureField.cpp
index 92a92d7..eb8d57e 100644
--- a/src/doc/PdfSignatureField.cpp
+++ b/src/doc/PdfSignatureField.cpp
@@ -81,7 +81,7 @@ void PdfSignatureField::SetAppearanceStream( PdfObject* 
pObject, EPdfAnnotationA
 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
 }
 
-SetAppearanceStreamForObject( m_pObject, pObject, eAppearance, state );

+m_pWidget->SetAppearanceStream( pObject, eAppearance, state );
 
 this->GetAppearanceCharacteristics( true );

 }
--
2.16.1.windows.1



--
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


[Podofo-users] [PATCH 0/3] Improvements to annotations appearance API

2018-02-22 Thread Francesco Pretto

Currently the API support setting annotation appearance only from PdfXObject.
This is arbitrarily limiting the API: the appearance can be set from
a generic PdfObject. Also there's no accessibility method for the current
set appearance. The patch series add overloads accepting a PdfObject.
I recommend in the future to deprecate methods signatures accepting PdfXObject,
which are cluttering the API unnecessarily.

Francesco Pretto (3):
  PdfAnnotation: Allow set appearance from PdfObject
  PdfSignatureField::SetAppearanceStream: Removed use of unuseful
SetAppearanceStreamForObject method
  PdfAnnotation: Added GetAppearanceStream method

 src/doc/PdfAnnotation.cpp | 61 +--
 src/doc/PdfAnnotation.h   | 21 +--
 src/doc/PdfField.cpp  | 18 ++---
 src/doc/PdfField.h| 18 +++--
 src/doc/PdfSignatureField.cpp |  9 +--
 src/doc/PdfSignatureField.h   |  8 ++
 6 files changed, 117 insertions(+), 18 deletions(-)

--
2.16.1.windows.1


--
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


[Podofo-users] [PATCH 1/3] PdfAnnotation: Allow set appearance from PdfObject

2018-02-22 Thread Francesco Pretto

Also reflected on PdfCheckbox and PdfSignature
---
 src/doc/PdfAnnotation.cpp | 24 +---
 src/doc/PdfAnnotation.h   | 11 ++-
 src/doc/PdfField.cpp  | 18 ++
 src/doc/PdfField.h| 18 --
 src/doc/PdfSignatureField.cpp |  7 ++-
 src/doc/PdfSignatureField.h   |  8 
 6 files changed, 71 insertions(+), 15 deletions(-)

diff --git a/src/doc/PdfAnnotation.cpp b/src/doc/PdfAnnotation.cpp
index f95e82c..765da2f 100644
--- a/src/doc/PdfAnnotation.cpp
+++ b/src/doc/PdfAnnotation.cpp
@@ -127,9 +127,14 @@ void PdfAnnotation::SetRect(const PdfRect & rrect)
 rrect.ToVariant(rect);
 this->GetObject()->GetDictionary().AddKey( PdfName::KeyRect, rect );
 
+}

+
+void SetAppearanceStreamForObject(PdfObject* pForObject, PdfXObject* pObject, 
EPdfAnnotationAppearance eAppearance, const PdfName & state)
+{
+SetAppearanceStreamForObject( pForObject, pObject->GetObject(), 
eAppearance, state );
 }
 
-void SetAppearanceStreamForObject( PdfObject* pForObject, PdfXObject* pObject, EPdfAnnotationAppearance eAppearance, const PdfName & state )

+void SetAppearanceStreamForObject( PdfObject* pForObject, PdfObject* pObject, 
EPdfAnnotationAppearance eAppearance, const PdfName & state )
 {
 PdfDictionary dict;
 PdfDictionary internal;
@@ -183,7 +188,7 @@ void SetAppearanceStreamForObject( PdfObject* pForObject, 
PdfXObject* pObject, E
 PODOFO_RAISE_ERROR( ePdfError_InvalidDataType );
 }
 
-objAP->GetDictionary().AddKey( name, pObject->GetObject()->Reference() );

+objAP->GetDictionary().AddKey( name, pObject->Reference() );
 }
 else
 {
@@ -195,11 +200,11 @@ void SetAppearanceStreamForObject( PdfObject* pForObject, 
PdfXObject* pObject, E
 
 if( objAP->GetDictionary().HasKey( name ) )

 {
-objAP->GetDictionary().GetKey( name )->GetDictionary().AddKey( 
state, pObject->GetObject()->Reference() );
+objAP->GetDictionary().GetKey( name )->GetDictionary().AddKey( 
state, pObject->Reference() );
 }
 else
 {
-internal.AddKey( state, pObject->GetObject()->Reference() );
+internal.AddKey( state, pObject->Reference() );
 objAP->GetDictionary().AddKey( name, internal );
 }
 }
@@ -208,12 +213,12 @@ void SetAppearanceStreamForObject( PdfObject* pForObject, 
PdfXObject* pObject, E
 {
 if( !state.GetLength() )
 {
-dict.AddKey( name, pObject->GetObject()->Reference() );
+dict.AddKey( name, pObject->Reference() );
 pForObject->GetDictionary().AddKey( "AP", dict );
 }
 else
 {
-internal.AddKey( state, pObject->GetObject()->Reference() );
+internal.AddKey( state, pObject->Reference() );
 dict.AddKey( name, internal );
 pForObject->GetDictionary().AddKey( "AP", dict );
 }
@@ -227,8 +232,13 @@ void SetAppearanceStreamForObject( PdfObject* pForObject, 
PdfXObject* pObject, E
 }
 }
 }
+
+void PdfAnnotation::SetAppearanceStream(PdfXObject* pObject, 
EPdfAnnotationAppearance eAppearance, const PdfName & state)
+{
+SetAppearanceStream( pObject->GetObject(), eAppearance, state );
+}
 
-void PdfAnnotation::SetAppearanceStream( PdfXObject* pObject, EPdfAnnotationAppearance eAppearance, const PdfName & state )

+void PdfAnnotation::SetAppearanceStream( PdfObject* pObject, 
EPdfAnnotationAppearance eAppearance, const PdfName & state )
 {
 SetAppearanceStreamForObject( this->GetObject(), pObject, eAppearance, 
state );
 }
diff --git a/src/doc/PdfAnnotation.h b/src/doc/PdfAnnotation.h
index b774af7..ccbd504 100644
--- a/src/doc/PdfAnnotation.h
+++ b/src/doc/PdfAnnotation.h
@@ -152,6 +152,14 @@ class PODOFO_DOC_API PdfAnnotation : public PdfElement {
  *  \param state the state for which set it the pObject; states depend on 
the annotation type
  */
 void SetAppearanceStream( PdfXObject* pObject, EPdfAnnotationAppearance eAppearance = 
ePdfAnnotationAppearance_Normal, const PdfName & state = "" );
+
+/** Set an appearance stream for this object
+*  to specify its visual appearance
+*  \param pObject an Object
+*  \param eApperance an apperance type to set
+*  \param state the state for which set it the pObject; states depend on 
the annotation type
+*/
+void SetAppearanceStream( PdfObject* pObject, EPdfAnnotationAppearance eAppearance = 
ePdfAnnotationAppearance_Normal, const PdfName & state = "" );
 
 /**

  * \returns true if this annotation has an appearance stream
@@ -413,8 +421,9 @@ class PODOFO_DOC_API PdfAnnotation : public PdfElement {
 PdfPage*   m_pPage;
 };
 
-// helper function, to avoid code duplication

+// helper functions, to avoid code duplication
 void SetAppearanceStreamForObject( PdfObject* 

Re: [Podofo-users] [PATCH 08/13] PdfDictionary: Added efficient TryGetKey method

2018-02-22 Thread Francesco Pretto
I would like to add the the lack of this method makes PoDoFo quite
inefficient in many code paths because of the intrinsic double lookup
of the pattern "if (haskey) then getkey". Also PdfDictionary::GetKey()
is surprisingly doing a double lookup inside (this is screaming for a
optmization fix)! It's strange that someone benchmarked unordered_map
vs map and didn't think about removing all the double lookups in the
code ;)

--
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


[Podofo-users] Watermarks?

2018-02-22 Thread Olivier Mascia
Dear all,

How about watermarking pages?
Either with text, images or PDF pages?

I mean, take two existing PDF files A and B.
Update file A, placing content of page B.2 so it displays underneath (or over) 
page A.1 existing content?

Or given PDF file A, add text or images underneath (or over) page A.2?

Is there any known piece of code (even pseudo code of course or just some 
explanations) which would give pointers on how to achieve this using PoDoFo or 
building it around PoDoFo?

Thanks,
-- 
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia



--
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


Re: [Podofo-users] Watermarks?

2018-02-22 Thread Matthew Brincke
Hello Olivier, hello all,
On 22 February 2018 at 17:54 Olivier Mascia  wrote:
> 
> 
> Dear all,
> 
> How about watermarking pages?
> Either with text, images or PDF pages?
>
I'm no expert for "watermarking", especially about securing/hardening
against removal of such a watermark (e.g. e-books marked with customer data).

> I mean, take two existing PDF files A and B.
> Update file A, placing content of page B.2 so it displays underneath
> (or over) page A.1 existing content?
> 
> Or given PDF file A, add text or images underneath (or over) page A.2?
Ah, that is meant: If there's any problem doing that with PoDoFo, it's the
latter's bug ;-). Just append the page's stream to the watermark's (what
comes later draws over the preceding content). In case graphics settings
could be changed in a page without reset: call PdfPainter::Save() first
(on an empty page, which has to be set first), then PdfPainter::GetCanvas(),
append the background's content's stream PdfPage::GetContents()->GetStream()
to the former's return object, call PdfPainter::Restore(), then append the
foreground likewise, call PdfPainter::FinishPage() (is automatically called
by SetPage()) and you should be set (sorry, I haven't tested this yet with
a current revision of PoDoFo, so please report any oddities you see).

> 
> Is there any known piece of code (even pseudo code of course or just some
> explanations) which would give pointers on how to achieve this using PoDoFo
> or building it around PoDoFo?

Please see above for an explanation/recipe. I hope this helps you.
> 
> Thanks,
> -- 
> Best Regards, Meilleures salutations, Met vriendelijke groeten,
> Olivier Mascia
> 
Best regards, mabri

--
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


Re: [Podofo-users] Watermarks?

2018-02-22 Thread Olivier Mascia
> Le 22 févr. 2018 à 21:47, Matthew Brincke  a écrit :
> 
>> How about watermarking pages?
>> Either with text, images or PDF pages?
>> 
> I'm no expert for "watermarking", especially about securing/hardening
> against removal of such a watermark (e.g. e-books marked with customer data).

No need for such securing for what I want to do.
My use of the word "watermarking" was misleading. :)

>> I mean, take two existing PDF files A and B.
>> Update file A, placing content of page B.2 so it displays underneath
>> (or over) page A.1 existing content?
>> 
>> Or given PDF file A, add text or images underneath (or over) page A.2?
> Ah, that is meant: If there's any problem doing that with PoDoFo, it's the
> latter's bug ;-). Just append the page's stream to the watermark's (what
> comes later draws over the preceding content). In case graphics settings
> could be changed in a page without reset: call PdfPainter::Save() first
> (on an empty page, which has to be set first), then PdfPainter::GetCanvas(),
> append the background's content's stream PdfPage::GetContents()->GetStream()
> to the former's return object, call PdfPainter::Restore(), then append the
> foreground likewise, call PdfPainter::FinishPage() (is automatically called
> by SetPage()) and you should be set (sorry, I haven't tested this yet with
> a current revision of PoDoFo, so please report any oddities you see).
> 
>> 
>> Is there any known piece of code (even pseudo code of course or just some
>> explanations) which would give pointers on how to achieve this using PoDoFo
>> or building it around PoDoFo?
> 
> Please see above for an explanation/recipe. I hope this helps you.

The whole picture seems perfectly clear!!  Many many thanks.
I'll experiment on sat/sun.  I'll share any oddities I might find, hoping it 
won't be mistakes on my side.

-- 
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia



--
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


Re: [Podofo-users] [PATCH 05/13] PdfPagesTree::InsertPage: Fix "atIndex" is really a 0-based index

2018-02-22 Thread Matthew Brincke
Hello Francesco, hello all,
> On 22 February 2018 at 12:20 Francesco Pretto  wrote:
> 
> 
> This is also specified in the API documentation. Without the fix
> there was a crash trying to insert page at index 0

where did it crash? What kind of crash was it, please? I've looked in
the source code and couldn't find a reason for a crash, the index -1
for InsertPage(int, PdfPage*) just means "insert before the first page".

> ---
>   src/doc/PdfPagesTree.cpp | 8 
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/doc/PdfPagesTree.cpp b/src/doc/PdfPagesTree.cpp
> index 2ee8ea2..9d851d3 100644
> --- a/src/doc/PdfPagesTree.cpp
> +++ b/src/doc/PdfPagesTree.cpp
> @@ -247,11 +247,11 @@ PdfPage* PdfPagesTree::InsertPage( const PdfRect & 
> rSize, int atIndex)
>   {
>   PdfPage* pPage = new PdfPage( rSize, GetRoot()->GetOwner() );
>   
> -  if (atIndex < 0 || atIndex >= this->GetTotalNumberOfPages()) {
> -  atIndex = this->GetTotalNumberOfPages() - 1;
> -  }
> + if (atIndex < 0 || atIndex > this->GetTotalNumberOfPages()) {
> +  atIndex = this->GetTotalNumberOfPages();
> + }
>   
> -  InsertPage( atIndex - 1, pPage );
> + InsertPage(atIndex, pPage );
>   m_cache.AddPageObject( atIndex, pPage );
>   
>   return pPage;
I'm sorry, I can't really recommend this your patch for acceptance and
wouldn't commit it myself because:
- insertion before the first page through this wouldn't be possible
- insertion after the last one (giving the correct, by its doc comment,
  index this->GetTotalNumberOfPages() wouldn't work either: in the
  method InsertPage(int, PdfObject*) the index is taken as the page index
  after which to insert, which isn't found, messages of critical severity
  are output, no insertion is done, then AddPageObject() can't work either
  (even if it would add, that wouldn't be correct, because the page wasn't
  inserted into the pages tree)
- I'd commit your changed if-clause together with doc-comment clarifying
  (and indentation fixes), acknowledging you gave me the idea

Best regards, mabri

--
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


Re: [Podofo-users] [PATCH 05/13] PdfPagesTree::InsertPage: Fix "atIndex" is really a 0-based index

2018-02-22 Thread Francesco Pretto
On 23 February 2018 at 00:13, Matthew Brincke  wrote:
> where did it crash? What kind of crash was it, please? I've looked in
> the source code and couldn't find a reason for a crash, the index -1
> for InsertPage(int, PdfPage*) just means "insert before the first page".
>

Inserting page with index 0 in an empty document will crash. Following
common zero based index convention, the following code should work,
page count should be 3, and internal order of the pages should be
page2, page1, page3.

PdfMemDocument document;
PdfRect rect;
auto page1 = document.InsertPage(rect, 0);
auto page2  = document.InsertPage(rect, 0);
auto page3 = document.InsertPage(rect, 2);
int count = document.GetPageCount();

Having said this, my patch has **indeed** problems and doesn't really
work in the previous example. I didn't quite get how it works the
internal collection of pages. I will look at it tomorrow.

> - insertion before the first page through this wouldn't be possible [...]
> - insertion after the last one wouldn't work either [...]

I don't understand if you disagree with the zero based index API or
you just say that my patch doesn't work as intended (which is true).
Inserting before the first page is inserting at zero. Inserting after
last one is inserting at number of pages. Negative and out of range
indices can still be supported by clamping (in other notable APIs they
are usually treated as errors).

--
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


Re: [Podofo-users] [PATCH 05/13] PdfPagesTree::InsertPage: Fix "atIndex" is really a 0-based index

2018-02-22 Thread Matthew Brincke
Hello Francesco, hello all,
> On 23 February 2018 at 01:05 Francesco Pretto  wrote:
> 
> 
> On 23 February 2018 at 00:13, Matthew Brincke  wrote:
> > where did it crash? What kind of crash was it, please? I've looked in
> > the source code and couldn't find a reason for a crash, the index -1
> > for InsertPage(int, PdfPage*) just means "insert before the first page".
> >
> 
> Inserting page with index 0 in an empty document will crash. Following
ah, I see, I think I've found it: Do you mean that the GetKey() call in
src/doc/PdfPagesTree.cpp line 620 throws then? I'll fix that probably on
the coming weekend or before (if you haven't by then, I mean, if your
solution will be correct, I'll commit it, maybe with some doc clarifying).

> common zero based index convention, the following code should work,
> page count should be 3, and internal order of the pages should be
> page2, page1, page3.
> 
> PdfMemDocument document;
> PdfRect rect;
> auto page1 = document.InsertPage(rect, 0);
> auto page2  = document.InsertPage(rect, 0);
> auto page3 = document.InsertPage(rect, 2);
> int count = document.GetPageCount();
> 
> Having said this, my patch has **indeed** problems and doesn't really
> work in the previous example. I didn't quite get how it works the
> internal collection of pages. I will look at it tomorrow.
Ah, thanks. I'm looking forward to your next suggestion.
> 
> > - insertion before the first page through this wouldn't be possible [...]
> > - insertion after the last one wouldn't work either [...]
> 
> I don't understand if you disagree with the zero based index API or
> you just say that my patch doesn't work as intended (which is true).
> Inserting before the first page is inserting at zero. Inserting after
> last one is inserting at number of pages. Negative and out of range
> indices can still be supported by clamping (in other notable APIs they
> are usually treated as errors).

I didn't/don't want to change this API (including the special meaning of
the index -1, I don't really understand why there are more negative ones).
So it's currently "-1"-based as I see it, so my answer is "both".
I'm not sure whether clamping is the best idea, though ...

Best regards, mabri

P.S. I wish you a sound sleep this night if you're located in Europe ;-).

--
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


Re: [Podofo-users] [PATCH 03/13] PdfPainter: Removed unneed cast

2018-02-22 Thread Matthew Brincke
Hello Francesco, hello all,

> On 22 February 2018 at 12:20 Francesco Pretto  wrote:
> 
> 
> PdfImage is a PdfXObject
> ---
>   src/doc/PdfPainter.cpp | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/doc/PdfPainter.cpp b/src/doc/PdfPainter.cpp
> index 03a5d05..fc5c0de 100644
> --- a/src/doc/PdfPainter.cpp
> +++ b/src/doc/PdfPainter.cpp
> @@ -1320,7 +1320,7 @@ void PdfPainter::DrawGlyph( PdfMemDocument* pDocument, 
> double dX, double dY, con
>   
>   void PdfPainter::DrawImage( double dX, double dY, PdfImage* pObject, double 
> dScaleX, double dScaleY )
>   {
> -this->DrawXObject( dX, dY, reinterpret_cast(pObject),
> +this->DrawXObject( dX, dY, pObject,
>  dScaleX * pObject->GetPageSize().GetWidth(),
>  dScaleY * pObject->GetPageSize().GetHeight() );
>   }
> -- 
> 2.16.1.windows.1

I see it the same, even doubt the cast is correct, so:
Thanks for the patch, I've committed it in svn r1893: 
https://sourceforge.net/p/podofo/code/1893/

Best regards, mabri

--
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


Re: [Podofo-users] [PATCH 0/1] More flexibility when using PoDoFo as a static library

2018-02-22 Thread zyx
On Thu, 2018-02-22 at 13:05 +0100, Francesco Pretto wrote:
> The current patch convert headers to really use
> relative paths, allowing to use podofo with #include 
> notation.

Hi,
you should discuss such invasive changes before suggesting them and
sending them to the list. Your changes in public headers are wrong.
Maybe they make things easier for static library usage, but they break
dynamic library usage.

> Additionally (or alternatively) I recommend to change the layout
> of PoDoFo source to totally eradicate the need for wrapper headers.

I agree with that and I've been thinking of it some time ago too. Some
projects just rename the 'src' with the expected directory name (in
this case 'podofo'), which avoids one directory level in the sources,
but having 'src/podofo/...' is also fine by me.

One unrelated comment to this issue, but being related to your
submissions: when you said you are going to send git-formatted patches,
then I expected patch attachments, not emails with patches in their
body. I know git can do it, but you see that what had been received on
the list is just a plain mess. Your [Patch 0/X], should, from my point
of view, contain patches which are related to it, otherwise those
messages are completely out of order. And why do I expect patches as
attachments? Different mail clients mangle message content differently,
thus simple copy into a file can cause problems, like with white-
space characters. And some web mail services even do not support saving
message to an .mbox file, thus people have bad luck. Saving attachments
is supported by every client and it makes sure the attachment is the
same as you generated it, not as the mail client interprets it.

I also do not like tons of small patches when they are supposed to fix
one issue (the sources should be buildable after each commit, which
adds some burden to the thing), but I agree that it's sometimes better
to split it. I mean, while some of your changes are fine to be in
parts, I'd merge some into one a-bit-larger patch. Just my opinion.
Bye,
zyx

--
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