podofo-svn Mailing List for PoDoFo (Page 3)
A PDF parsing, modification and creation library.
Brought to you by:
domseichter
This list is closed, nobody may subscribe to it.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(39) |
Jul
(42) |
Aug
(134) |
Sep
(48) |
Oct
(105) |
Nov
(19) |
Dec
(9) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(48) |
Feb
(70) |
Mar
(26) |
Apr
(13) |
May
(49) |
Jun
(40) |
Jul
(49) |
Aug
(34) |
Sep
(49) |
Oct
(20) |
Nov
(71) |
Dec
(4) |
2008 |
Jan
(14) |
Feb
(2) |
Mar
(6) |
Apr
(24) |
May
(33) |
Jun
(36) |
Jul
(12) |
Aug
(26) |
Sep
(37) |
Oct
(35) |
Nov
(10) |
Dec
(15) |
2009 |
Jan
(4) |
Feb
(1) |
Mar
(9) |
Apr
(39) |
May
(14) |
Jun
(17) |
Jul
(46) |
Aug
(37) |
Sep
(3) |
Oct
(8) |
Nov
(7) |
Dec
(13) |
2010 |
Jan
(3) |
Feb
(18) |
Mar
(5) |
Apr
(23) |
May
(16) |
Jun
(19) |
Jul
(7) |
Aug
(29) |
Sep
(12) |
Oct
(43) |
Nov
(20) |
Dec
(14) |
2011 |
Jan
(22) |
Feb
(5) |
Mar
(36) |
Apr
(12) |
May
(2) |
Jun
(4) |
Jul
(3) |
Aug
(1) |
Sep
(4) |
Oct
(8) |
Nov
(2) |
Dec
(6) |
2012 |
Jan
(6) |
Feb
|
Mar
(2) |
Apr
|
May
(4) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
(3) |
2013 |
Jan
|
Feb
(6) |
Mar
(3) |
Apr
(1) |
May
(24) |
Jun
(2) |
Jul
(12) |
Aug
(3) |
Sep
(1) |
Oct
(17) |
Nov
|
Dec
|
2014 |
Jan
(2) |
Feb
(1) |
Mar
(4) |
Apr
(11) |
May
(4) |
Jun
(47) |
Jul
(13) |
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
(2) |
Mar
(2) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
(2) |
Aug
(2) |
Sep
(4) |
Oct
(7) |
Nov
(10) |
Dec
(2) |
2016 |
Jan
|
Feb
(2) |
Mar
|
Apr
(16) |
May
(45) |
Jun
(8) |
Jul
(6) |
Aug
(1) |
Sep
(3) |
Oct
(7) |
Nov
(13) |
Dec
(5) |
2017 |
Jan
(15) |
Feb
(4) |
Mar
(3) |
Apr
(8) |
May
(8) |
Jun
(5) |
Jul
(2) |
Aug
(1) |
Sep
(1) |
Oct
(2) |
Nov
|
Dec
(3) |
2018 |
Jan
(12) |
Feb
(17) |
Mar
(12) |
Apr
(16) |
May
(1) |
Jun
(1) |
Jul
(5) |
Aug
(5) |
Sep
(6) |
Oct
(3) |
Nov
(7) |
Dec
(3) |
2019 |
Jan
(4) |
Feb
(10) |
Mar
(5) |
Apr
(6) |
May
(12) |
Jun
(2) |
Jul
(3) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
(8) |
Apr
|
May
(4) |
Jun
(2) |
Jul
|
Aug
(2) |
Sep
|
Oct
(3) |
Nov
|
Dec
(2) |
2021 |
Jan
(15) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(10) |
Sep
|
Oct
|
Nov
(1) |
Dec
(1) |
2022 |
Jan
(1) |
Feb
|
Mar
(6) |
Apr
(5) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <mc...@us...> - 2020-10-10 17:33:04
|
Revision: 2016 http://sourceforge.net/p/podofo/code/2016 Author: mc-zyx Date: 2020-10-10 17:33:01 +0000 (Sat, 10 Oct 2020) Log Message: ----------- Patch by Josef Rokos: Fix text wrapping with Unicode characters in PdfPainter::DrawMultiLineText() Fix text wrapping with Unicode characters. Without the change it incorrectly recognizes some characters as space (for instance "c") and wraps text on this position. This results in incorrect output from PdfPainter::DrawMultiLineText method. Modified Paths: -------------- podofo/trunk/src/podofo/doc/PdfPainter.cpp Modified: podofo/trunk/src/podofo/doc/PdfPainter.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfPainter.cpp 2020-10-10 17:26:15 UTC (rev 2015) +++ podofo/trunk/src/podofo/doc/PdfPainter.cpp 2020-10-10 17:33:01 UTC (rev 2016) @@ -105,7 +105,7 @@ static inline bool IsSpaceChar(pdf_utf16be ch) { - return isspace( SwapCharBytesIfRequired(ch) & 0x00FF ) != 0; + return iswspace( SwapCharBytesIfRequired(ch) ) != 0; } PdfPainter::PdfPainter() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-10-10 17:26:18
|
Revision: 2015 http://sourceforge.net/p/podofo/code/2015 Author: mc-zyx Date: 2020-10-10 17:26:15 +0000 (Sat, 10 Oct 2020) Log Message: ----------- Patch by Josef Rokos: Properly trim Unicode text in PdfTextField::SetText() Trim Unicode text in PdfTextField::SetText method when maximum length is set. Without the change it incorrectly counts one letter as two characters. Modified Paths: -------------- podofo/trunk/src/podofo/doc/PdfField.cpp Modified: podofo/trunk/src/podofo/doc/PdfField.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfField.cpp 2020-10-10 17:17:47 UTC (rev 2014) +++ podofo/trunk/src/podofo/doc/PdfField.cpp 2020-10-10 17:26:15 UTC (rev 2015) @@ -734,8 +734,8 @@ // if rsText is longer than maxlen, truncate it pdf_long nMax = this->GetMaxLen(); - if( nMax != -1 && rsText.GetLength() > nMax ) - m_pObject->GetDictionary().AddKey( key, PdfString( rsText.GetString(), nMax ) ); + if( nMax != -1 && (rsText.IsUnicode() ? rsText.GetUnicodeLength() : rsText.GetLength()) > nMax ) + m_pObject->GetDictionary().AddKey( key, rsText.IsUnicode() ? PdfString( rsText.GetUnicode(), nMax) : PdfString( rsText.GetString(), nMax ) ); else m_pObject->GetDictionary().AddKey( key, rsText ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-10-10 17:17:49
|
Revision: 2014 http://sourceforge.net/p/podofo/code/2014 Author: mc-zyx Date: 2020-10-10 17:17:47 +0000 (Sat, 10 Oct 2020) Log Message: ----------- Fix possible memory leak in PdfXRefStreamParserObject::ParseStream() Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfXRefStreamParserObject.cpp Modified: podofo/trunk/src/podofo/base/PdfXRefStreamParserObject.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfXRefStreamParserObject.cpp 2020-08-12 08:25:00 UTC (rev 2013) +++ podofo/trunk/src/podofo/base/PdfXRefStreamParserObject.cpp 2020-10-10 17:17:47 UTC (rev 2014) @@ -34,6 +34,7 @@ #include "PdfXRefStreamParserObject.h" #include "PdfArray.h" +#include "PdfDefinesPrivate.h" #include "PdfDictionary.h" #include "PdfStream.h" #include "PdfVariant.h" @@ -147,7 +148,22 @@ std::vector<pdf_int64>::const_iterator it = rvecIndeces.begin(); - char* const pStart = pBuffer; + #ifdef PODOFO_HAVE_UNIQUE_PTR + std::unique_ptr<char, decltype( &podofo_free )> pStart( pBuffer, &podofo_free ); + #else // PODOFO_HAVE_UNIQUE_PTR + class StrAutoPtr { + private: + char *str; + public: + StrAutoPtr( char *in_str ) : str( in_str ) {} + ~StrAutoPtr() { + podofo_free( str ); + } + char *get( void ) const { return str; } + }; + StrAutoPtr pStart( pBuffer ); + #endif // PODOFO_HAVE_UNIQUE_PTR + while( it != rvecIndeces.end() ) { pdf_int64 nFirstObj = *it; ++it; @@ -161,7 +177,7 @@ //printf("nCount=%i\n", static_cast<int>(nCount)); while( nCount > 0 ) { - if( (pBuffer - pStart) >= lBufferLen ) + if( (pBuffer - pStart.get()) >= lBufferLen ) { PODOFO_RAISE_ERROR_INFO( ePdfError_NoXRef, "Invalid count in XRef stream" ); } @@ -182,8 +198,6 @@ //printf("Exp: nFirstObj=%i nFirstObjOrg + nCount=%i\n", nFirstObj - 1, nFirstObjOrg + nCountOrg - 1 ); //printf("===\n"); } - podofo_free( pStart ); - } void PdfXRefStreamParserObject::GetIndeces( std::vector<pdf_int64> & rvecIndeces, pdf_int64 size ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-08-12 08:25:03
|
Revision: 2013 http://sourceforge.net/p/podofo/code/2013 Author: mc-zyx Date: 2020-08-12 08:25:00 +0000 (Wed, 12 Aug 2020) Log Message: ----------- Patch by Ferdinand Oeinck: Correct standard encoding vector See https://sourceforge.net/p/podofo/mailman/podofo-users/thread/9821DCE99A4E4D3CB05F4576E0FCC6CA%40SurfacePro4/#msg37026605 for more information. Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfEncoding.cpp Modified: podofo/trunk/src/podofo/base/PdfEncoding.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfEncoding.cpp 2020-08-12 07:51:02 UTC (rev 2012) +++ podofo/trunk/src/podofo/base/PdfEncoding.cpp 2020-08-12 08:25:00 UTC (rev 2013) @@ -1615,6 +1615,7 @@ 0x0000, // C9 undefined 0x02DA, // CA # RING ABOVE # ring 0x00B8, // CB # CEDILLA # cedilla + 0x0000, // CC undefined 0x02DD, // CD # DOUBLE ACUTE ACCENT # hungarumlaut 0x02DB, // CE # OGONEK # ogonek 0x02C7, // CF # CARON # caron This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-08-12 07:51:08
|
Revision: 2012 http://sourceforge.net/p/podofo/code/2012 Author: mc-zyx Date: 2020-08-12 07:51:02 +0000 (Wed, 12 Aug 2020) Log Message: ----------- Patch by Michal Sudolsky: Use GetStream() const where possible to avoid marking objects dirty unnecessarily Closes https://sourceforge.net/p/podofo/tickets/91/ Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfContentsTokenizer.cpp podofo/trunk/src/podofo/base/PdfContentsTokenizer.h podofo/trunk/src/podofo/base/PdfEncoding.h podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp podofo/trunk/src/podofo/base/PdfParser.cpp podofo/trunk/src/podofo/doc/PdfCMapEncoding.cpp podofo/trunk/src/podofo/doc/PdfDocument.cpp Modified: podofo/trunk/src/podofo/base/PdfContentsTokenizer.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfContentsTokenizer.cpp 2020-06-15 07:10:17 UTC (rev 2011) +++ podofo/trunk/src/podofo/base/PdfContentsTokenizer.cpp 2020-08-12 07:51:02 UTC (rev 2012) @@ -108,15 +108,16 @@ } } -void PdfContentsTokenizer::SetCurrentContentsStream( PdfObject* pObject ) +void PdfContentsTokenizer::SetCurrentContentsStream( const PdfObject* pObject ) { PODOFO_RAISE_LOGIC_IF( pObject == NULL, "Content stream object == NULL!" ); - PdfStream* pStream = pObject->GetStream(); + const PdfStream* pStream = pObject->GetStream(); - PdfRefCountedBuffer buffer; + PdfRefCountedBuffer buffer(0); PdfBufferOutputStream stream( &buffer ); - pStream->GetFilteredCopy( &stream ); + if( pStream ) + pStream->GetFilteredCopy( &stream ); m_device = PdfRefCountedInputDevice( buffer.GetBuffer(), buffer.GetSize() ); } Modified: podofo/trunk/src/podofo/base/PdfContentsTokenizer.h =================================================================== --- podofo/trunk/src/podofo/base/PdfContentsTokenizer.h 2020-06-15 07:10:17 UTC (rev 2011) +++ podofo/trunk/src/podofo/base/PdfContentsTokenizer.h 2020-08-12 07:51:02 UTC (rev 2012) @@ -119,7 +119,7 @@ * * \param pObject use the stream of this object for parsing */ - void SetCurrentContentsStream( PdfObject* pObject ); + void SetCurrentContentsStream( const PdfObject* pObject ); bool ReadInlineImgData(EPdfContentsType& reType, const char*& rpszKeyword, PoDoFo::PdfVariant & rVariant); private: Modified: podofo/trunk/src/podofo/base/PdfEncoding.h =================================================================== --- podofo/trunk/src/podofo/base/PdfEncoding.h 2020-06-15 07:10:17 UTC (rev 2011) +++ podofo/trunk/src/podofo/base/PdfEncoding.h 2020-08-12 07:51:02 UTC (rev 2012) @@ -226,7 +226,7 @@ private: int m_nFirstChar; ///< The first defined character code int m_nLastChar; ///< The last defined character code - PdfObject* m_pToUnicode; ///< Pointer to /ToUnicode object, if any + const PdfObject* m_pToUnicode; ///< Pointer to /ToUnicode object, if any protected: std::map<pdf_utf16be, pdf_utf16be> m_toUnicode; Modified: podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp 2020-06-15 07:10:17 UTC (rev 2011) +++ podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp 2020-08-12 07:51:02 UTC (rev 2012) @@ -70,7 +70,6 @@ try { this->ReadObjectsFromStream( pBuffer, lBufferLen, lNum, lFirst, list ); - podofo_free( pBuffer ); // the object stream is not needed anymore in the final PDF delete m_vecObjects->RemoveObject( m_pParser->Reference() ); @@ -80,6 +79,8 @@ podofo_free( pBuffer ); throw rError; } + + podofo_free( pBuffer ); } void PdfObjectStreamParserObject::ReadObjectsFromStream( char* pBuffer, pdf_long lBufferLen, pdf_int64 lNum, pdf_int64 lFirst, ObjectIdList const & list) Modified: podofo/trunk/src/podofo/base/PdfParser.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfParser.cpp 2020-06-15 07:10:17 UTC (rev 2011) +++ podofo/trunk/src/podofo/base/PdfParser.cpp 2020-08-12 07:51:02 UTC (rev 2012) @@ -1252,7 +1252,7 @@ itObjects != m_vecObjects->end(); ++itObjects) { - pObject = dynamic_cast<PdfParserObject*>(*itObjects); + const PdfParserObject* pObject = dynamic_cast<PdfParserObject*>(*itObjects); // only parse streams for objects that have not yet parsed // their streams if( pObject && pObject->HasStreamToParse() && !pObject->HasStream() ) Modified: podofo/trunk/src/podofo/doc/PdfCMapEncoding.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfCMapEncoding.cpp 2020-06-15 07:10:17 UTC (rev 2011) +++ podofo/trunk/src/podofo/doc/PdfCMapEncoding.cpp 2020-08-12 07:51:02 UTC (rev 2012) @@ -74,7 +74,7 @@ pdf_uint16 range_end = 0; pdf_uint16 i = 0; pdf_utf16be firstvalue = 0; - const PdfStream *CIDStreamdata = pObject->GetStream (); + const PdfStream *CIDStreamdata = static_cast<const PdfObject*>(pObject)->GetStream (); CIDStreamdata->GetFilteredCopy (&streamBuffer, &streamBufferLen); PdfContentsTokenizer streamTokenizer (streamBuffer, streamBufferLen); Modified: podofo/trunk/src/podofo/doc/PdfDocument.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfDocument.cpp 2020-06-15 07:10:17 UTC (rev 2011) +++ podofo/trunk/src/podofo/doc/PdfDocument.cpp 2020-08-12 07:51:02 UTC (rev 2012) @@ -302,7 +302,7 @@ m_vecObjects.push_back( pObj ); if( (*it)->IsDictionary() && (*it)->HasStream() ) - *(pObj->GetStream()) = *((*it)->GetStream()); + *(pObj->GetStream()) = *(static_cast<const PdfObject*>(*it)->GetStream()); PdfError::LogMessage( eLogSeverity_Information, "Fixing references in %i %i R by %i\n", pObj->Reference().ObjectNumber(), pObj->Reference().GenerationNumber(), difference ); @@ -401,7 +401,7 @@ m_vecObjects.push_back( pObj ); if( (*it)->IsDictionary() && (*it)->HasStream() ) - *(pObj->GetStream()) = *((*it)->GetStream()); + *(pObj->GetStream()) = *(static_cast<const PdfObject*>(*it)->GetStream()); PdfError::LogMessage( eLogSeverity_Information, "Fixing references in %i %i R by %i\n", pObj->Reference().ObjectNumber(), pObj->Reference().GenerationNumber(), difference ); @@ -504,7 +504,7 @@ if( pObj->IsDictionary() && pObj->GetDictionary().HasKey( "Contents" ) ) { // get direct pointer to contents - PdfObject* pContents = pObj->MustGetIndirectKey( "Contents" ); + const PdfObject* pContents = pObj->MustGetIndirectKey( "Contents" ); if( pContents->IsArray() ) { @@ -524,7 +524,7 @@ if ( it->IsReference() ) { // TODO: not very efficient !! - PdfObject* pObj = GetObjects()->GetObject( it->GetReference() ); + const PdfObject* pObj = GetObjects()->GetObject( it->GetReference() ); while (pObj!=NULL) { @@ -534,7 +534,7 @@ } else if (pObj->HasStream()) { - PdfStream* pcontStream = pObj->GetStream(); + const PdfStream* pcontStream = pObj->GetStream(); char* pcontStreamBuffer; pdf_long pcontStreamLength; @@ -566,7 +566,7 @@ // copy stream to xobject PdfObject* pObj = pXObj->GetContentsForAppending(); PdfStream* pObjStream = pObj->GetStream(); - PdfStream* pcontStream = pContents->GetStream(); + const PdfStream* pcontStream = pContents->GetStream(); char* pcontStreamBuffer; pdf_long pcontStreamLength; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-06-15 07:10:18
|
Revision: 2011 http://sourceforge.net/p/podofo/code/2011 Author: mc-zyx Date: 2020-06-15 07:10:17 +0000 (Mon, 15 Jun 2020) Log Message: ----------- Patch by Andreas Brzesowsky: Fix png transparency and gray scale Modified Paths: -------------- podofo/trunk/src/podofo/doc/PdfImage.cpp Modified: podofo/trunk/src/podofo/doc/PdfImage.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfImage.cpp 2020-05-26 17:56:12 UTC (rev 2010) +++ podofo/trunk/src/podofo/doc/PdfImage.cpp 2020-06-15 07:10:17 UTC (rev 2011) @@ -853,36 +853,8 @@ } #endif // _WIN32 -void PdfImage::LoadFromPngHandle( PdfFileInputStream* pInStream ) +static void LoadFromPngContent(png_structp pPng, png_infop pInfo, PdfImage *image) { - FILE* hFile = pInStream->GetHandle(); - png_byte header[8]; - if( fread( header, 1, 8, hFile ) != 8 || - png_sig_cmp( header, 0, 8 ) ) - { - PODOFO_RAISE_ERROR_INFO( ePdfError_UnsupportedImageFormat, "The file could not be recognized as a PNG file." ); - } - - png_structp pPng = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if( !pPng ) - { - PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); - } - - png_infop pInfo = png_create_info_struct(pPng); - if( !pInfo ) - { - png_destroy_read_struct(&pPng, (png_infopp)NULL, (png_infopp)NULL); - PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); - } - - if( setjmp(png_jmpbuf(pPng)) ) - { - png_destroy_read_struct(&pPng, &pInfo, (png_infopp)NULL); - PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); - } - - png_init_io(pPng, hFile); png_set_sig_bytes(pPng, 8); png_read_info(pPng, pInfo); @@ -898,12 +870,6 @@ &color_type, &interlace, NULL, NULL); /* convert palette/gray image to rgb */ - if (color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(pPng); - - if (color_type & PNG_COLOR_MASK_ALPHA) - png_set_strip_alpha(pPng); -#if 0 /* expand gray bit depth if needed */ if (color_type == PNG_COLOR_TYPE_GRAY) { #if PNG_LIBPNG_VER >= 10209 @@ -911,25 +877,17 @@ #else png_set_gray_1_2_4_to_8 (pPng); #endif + } else if (color_type != PNG_COLOR_TYPE_PALETTE && depth < 8) { + png_set_packing(pPng); } -#endif + /* transform transparency to alpha */ - if (png_get_valid (pPng, pInfo, PNG_INFO_tRNS)) + if (color_type != PNG_COLOR_TYPE_PALETTE && png_get_valid (pPng, pInfo, PNG_INFO_tRNS)) png_set_tRNS_to_alpha (pPng); if (depth == 16) png_set_strip_16(pPng); - if (depth < 8) - png_set_packing(pPng); -#if 0 - /* convert grayscale to RGB */ - if (color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - png_set_gray_to_rgb (pPng); - } -#endif if (interlace != PNG_INTERLACE_NONE) png_set_interlace_handling(pPng); @@ -949,8 +907,8 @@ PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } - - long lLen = static_cast<long>(png_get_rowbytes(pPng, pInfo) * height); + size_t lRowLen = png_get_rowbytes(pPng, pInfo); + size_t lLen = lRowLen * height; char* pBuffer = static_cast<char*>(podofo_calloc(lLen, sizeof(char))); if (!pBuffer) { @@ -965,51 +923,133 @@ for(unsigned int y=0; y<height; y++) { - pRows[y] = reinterpret_cast<png_bytep>(pBuffer + (y * png_get_rowbytes(pPng, pInfo))); + pRows[y] = reinterpret_cast<png_bytep>(pBuffer + y * lRowLen); } png_read_image(pPng, pRows); - m_rRect.SetWidth( width ); - m_rRect.SetHeight( height ); + png_bytep paletteTrans; + int numTransColors; + if (color_type & PNG_COLOR_MASK_ALPHA || + (color_type == PNG_COLOR_TYPE_PALETTE && png_get_valid(pPng, pInfo, PNG_INFO_tRNS) && png_get_tRNS(pPng, pInfo, &paletteTrans, &numTransColors, NULL))) + { + // Handle alpha channel and create smask + char *smask = static_cast<char*>(podofo_calloc(height, width)); + png_uint_32 smaskIndex = 0; + if (color_type == PNG_COLOR_TYPE_PALETTE) { + for (png_uint_32 r = 0; r < height; r++) { + png_bytep row = pRows[r]; + for (png_uint_32 c = 0; c < width; c++) { + png_byte color; + if (depth == 8) { + color = row[c]; + } else if (depth == 4) { + color = c % 2 ? row[c / 2] >> 4 : row[c / 2] & 0xF; + } else if (depth == 2) { + color = (row[c / 4] >> c % 4 * 2) & 3; + } else if (depth == 1) { + color = (row[c / 4] >> c % 8) & 1; + } + smask[smaskIndex++] = color < numTransColors ? paletteTrans[color] : 0xFF; + } + } + } else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + for (png_uint_32 r = 0; r < height; r++) { + png_bytep row = pRows[r]; + for (png_uint_32 c = 0; c < width; c++) { + memmove(pBuffer + 3 * smaskIndex, row + 4 * c, 3); // 3 byte for rgb + smask[smaskIndex++] = row[c * 4 + 3]; // 4th byte for alpha + } + } + lLen = 3 * width * height; + } else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { + for (png_uint_32 r = 0; r < height; r++) { + png_bytep row = pRows[r]; + for (png_uint_32 c = 0; c < width; c++) { + pBuffer[smaskIndex] = row[c * 2]; // 1 byte for gray + smask[smaskIndex++] = row[c * 2 + 1]; // 2nd byte for alpha + } + } + lLen = width * height; + } + PdfMemoryInputStream smaskstream(smask, width * height); + PdfImage smakeImage(image->GetObject()->GetOwner()); + smakeImage.SetImageColorSpace(ePdfColorSpace_DeviceGray); + smakeImage.SetImageData(width, height, 8, &smaskstream); + image->SetImageSoftmask(&smakeImage); + podofo_free(smask); + } - switch( png_get_channels( pPng, pInfo ) ) - { - case 3: - this->SetImageColorSpace( ePdfColorSpace_DeviceRGB ); - break; - case 4: + // Set color space + if (color_type == PNG_COLOR_TYPE_PALETTE) { + png_color *pColors; + int numColors; + png_get_PLTE(pPng, pInfo, &pColors, &numColors); + + char *datap = new char[numColors * 3]; + for (int i = 0; i < numColors; i++, pColors++) { - this->SetImageColorSpace( ePdfColorSpace_DeviceCMYK ); - // The jpeg-doc ist not specific in this point, but cmyk's seem to be stored - // in a inverted fashion. Fix by attaching a decode array - PdfArray decode; - decode.push_back( 1.0 ); - decode.push_back( 0.0 ); - decode.push_back( 1.0 ); - decode.push_back( 0.0 ); - decode.push_back( 1.0 ); - decode.push_back( 0.0 ); - decode.push_back( 1.0 ); - decode.push_back( 0.0 ); - - this->GetObject()->GetDictionary().AddKey( PdfName("Decode"), decode ); + datap[3 * i + 0] = pColors->red; + datap[3 * i + 1] = pColors->green; + datap[3 * i + 2] = pColors->blue; } - break; - default: - this->SetImageColorSpace( ePdfColorSpace_DeviceGray ); - break; + PdfMemoryInputStream stream(datap, numColors * 3); + PdfObject* pIdxObject = image->GetObject()->GetOwner()->CreateObject(); + pIdxObject->GetStream()->Set(&stream); + + PdfArray array; + array.push_back(PdfName("DeviceRGB")); + array.push_back(static_cast<pdf_int64>(numColors - 1)); + array.push_back(pIdxObject->Reference()); + image->SetImageColorSpace(ePdfColorSpace_Indexed, &array); + } else if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { + image->SetImageColorSpace(ePdfColorSpace_DeviceGray); + } else { + image->SetImageColorSpace(ePdfColorSpace_DeviceRGB); } // Set the image data and flate compress it PdfMemoryInputStream stream( pBuffer, lLen ); - this->SetImageData( width, height, depth, &stream ); + image->SetImageData( width, height, depth, &stream ); podofo_free(pBuffer); podofo_free(pRows); png_destroy_read_struct(&pPng, &pInfo, (png_infopp)NULL); +} +void PdfImage::LoadFromPngHandle( PdfFileInputStream* pInStream ) +{ + FILE* hFile = pInStream->GetHandle(); + png_byte header[8]; + if( fread( header, 1, 8, hFile ) != 8 || + png_sig_cmp( header, 0, 8 ) ) + { + PODOFO_RAISE_ERROR_INFO( ePdfError_UnsupportedImageFormat, "The file could not be recognized as a PNG file." ); + } + + png_structp pPng = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if( !pPng ) + { + PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); + } + + png_infop pInfo = png_create_info_struct(pPng); + if( !pInfo ) + { + png_destroy_read_struct(&pPng, (png_infopp)NULL, (png_infopp)NULL); + PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); + } + + if( setjmp(png_jmpbuf(pPng)) ) + { + png_destroy_read_struct(&pPng, &pInfo, (png_infopp)NULL); + PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); + } + + png_init_io(pPng, hFile); + + LoadFromPngContent(pPng, pInfo, this); } struct pngData @@ -1076,132 +1116,8 @@ } png_set_read_fn(pPng, (png_voidp)&data, pngReadData); - png_set_sig_bytes(pPng, 8); - png_read_info(pPng, pInfo); - // Begin - png_uint_32 width; - png_uint_32 height; - int depth; - int color_type; - int interlace; - - png_get_IHDR (pPng, pInfo, - &width, &height, &depth, - &color_type, &interlace, NULL, NULL); - - /* convert palette/gray image to rgb */ - if (color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(pPng); - - if (color_type & PNG_COLOR_MASK_ALPHA) - png_set_strip_alpha(pPng); -#if 0 - /* expand gray bit depth if needed */ - if (color_type == PNG_COLOR_TYPE_GRAY) { -#if PNG_LIBPNG_VER >= 10209 - png_set_expand_gray_1_2_4_to_8 (pPng); -#else - png_set_gray_1_2_4_to_8 (pPng); -#endif - } -#endif - /* transform transparency to alpha */ - if (png_get_valid (pPng, pInfo, PNG_INFO_tRNS)) - png_set_tRNS_to_alpha (pPng); - - if (depth == 16) - png_set_strip_16(pPng); - - if (depth < 8) - png_set_packing(pPng); -#if 0 - /* convert grayscale to RGB */ - if (color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - png_set_gray_to_rgb (pPng); - } -#endif - if (interlace != PNG_INTERLACE_NONE) - png_set_interlace_handling(pPng); - - //png_set_filler (pPng, 0xff, PNG_FILLER_AFTER); - - /* recheck header after setting EXPAND options */ - png_read_update_info(pPng, pInfo); - png_get_IHDR (pPng, pInfo, - &width, &height, &depth, - &color_type, &interlace, NULL, NULL); - // End // - - // Read the file - if( setjmp(png_jmpbuf(pPng)) ) - { - png_destroy_read_struct(&pPng, &pInfo, (png_infopp)NULL); - PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); - } - - - long lLen = static_cast<long>(png_get_rowbytes(pPng, pInfo) * height); - char* pBuffer = static_cast<char*>(podofo_calloc(lLen, sizeof(char))); - if (!pBuffer) - { - PODOFO_RAISE_ERROR(ePdfError_OutOfMemory); - } - - png_bytepp pRows = static_cast<png_bytepp>(podofo_calloc(height, sizeof(png_bytep))); - if (!pRows) - { - PODOFO_RAISE_ERROR(ePdfError_OutOfMemory); - } - - for(unsigned int y=0; y<height; y++) - { - pRows[y] = reinterpret_cast<png_bytep>(pBuffer + (y * png_get_rowbytes(pPng, pInfo))); - } - - png_read_image(pPng, pRows); - - m_rRect.SetWidth( width ); - m_rRect.SetHeight( height ); - - switch( png_get_channels( pPng, pInfo ) ) - { - case 3: - this->SetImageColorSpace( ePdfColorSpace_DeviceRGB ); - break; - case 4: - { - this->SetImageColorSpace( ePdfColorSpace_DeviceCMYK ); - // The jpeg-doc ist not specific in this point, but cmyk's seem to be stored - // in a inverted fashion. Fix by attaching a decode array - PdfArray decode; - decode.push_back( 1.0 ); - decode.push_back( 0.0 ); - decode.push_back( 1.0 ); - decode.push_back( 0.0 ); - decode.push_back( 1.0 ); - decode.push_back( 0.0 ); - decode.push_back( 1.0 ); - decode.push_back( 0.0 ); - - this->GetObject()->GetDictionary().AddKey( PdfName("Decode"), decode ); - } - break; - default: - this->SetImageColorSpace( ePdfColorSpace_DeviceGray ); - break; - } - - // Set the image data and flate compress it - PdfMemoryInputStream stream( pBuffer, lLen ); - this->SetImageData( width, height, depth, &stream ); - - podofo_free(pBuffer); - podofo_free(pRows); - - png_destroy_read_struct(&pPng, &pInfo, (png_infopp)NULL); + LoadFromPngContent(pPng, pInfo, this); } #endif // PODOFO_HAVE_PNG_LIB This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: zyx <zy...@gm...> - 2020-06-01 05:38:33
|
On Sat, 2020-05-30 at 15:04 +0200, Ferdinand Oeinck wrote: > Hi, > > I'm using the podofo source code since some years. > > In my own copy I fixed this bug in PdfEncoding.cpp in 2013. > > Recently I've update my source code to 0.9.6 and found the bug is > still > present on sourceforge. > > Maybe you could fix it in the main repository? Thanks in advance! > > Ferdinand Oeinck, > Big Roses Software. Hi, you used a wrong list, this one is for svn commits and I'm surprised Source Forge let you send a message there, because it should be an automatic/machine-populated list. Use the user list instead, please. The address is pod...@li... . > Please look at lines 1605 and 1606 of PdfEncoding.cpp: Would you mind to create a patch and attach it to a new message, than to describe what you did, please? That will avoid confusion and unnecessary errors when transforming words into code changes. If you've a svn checkout then 'svn diff' can do it, otherwise make a copy of the file before your change, say with extension ".orig", then make your changes in the file and after it execute: diff -up PdfEncoding.cpp.orig PdfEncoding.cpp >change.patch The best would be with path as well, but if it's only this file, then the above can be fine. Thanks and bye, zyx P.S.: do not write only to me, please, use the public list (the user list), to keep the public in the loop |
From: Ferdinand O. <fe...@bi...> - 2020-05-30 13:22:20
|
Hi, I'm using the podofo source code since some years. In my own copy I fixed this bug in PdfEncoding.cpp in 2013. Recently I've update my source code to 0.9.6 and found the bug is still present on sourceforge. Maybe you could fix it in the main repository? Thanks in advance! Ferdinand Oeinck, Big Roses Software. Please look at lines 1605 and 1606 of PdfEncoding.cpp: 0x00B8, // CB # CEDILLA # cedilla 0x02DD, // CD # DOUBLE ACUTE ACCENT # hungarumlaut I think there is one line missing: 0x00B8, // CB # CEDILLA # cedilla /*--> missing*/ 0x0000, // CC undefined 0x02DD, // CD # DOUBLE ACUTE ACCENT # hungarumlaut When I include this line, subsetted type1 fonts using 'í' will find /dotlessi otherwise they would find /.notdef |
From: <mc...@us...> - 2020-05-26 17:56:16
|
Revision: 2010 http://sourceforge.net/p/podofo/code/2010 Author: mc-zyx Date: 2020-05-26 17:56:12 +0000 (Tue, 26 May 2020) Log Message: ----------- Change 'constexpr' to 'const' to not force C++11 Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfString.cpp Modified: podofo/trunk/src/podofo/base/PdfString.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfString.cpp 2020-05-22 17:45:09 UTC (rev 2009) +++ podofo/trunk/src/podofo/base/PdfString.cpp 2020-05-26 17:56:12 UTC (rev 2010) @@ -133,7 +133,7 @@ { lLen = wcslen( pszString ); } - constexpr bool wchar_t_is_two_bytes = sizeof(wchar_t) == 2; + const bool wchar_t_is_two_bytes = sizeof(wchar_t) == 2; if( wchar_t_is_two_bytes ) { // We have UTF16 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-05-22 17:45:12
|
Revision: 2009 http://sourceforge.net/p/podofo/code/2009 Author: mc-zyx Date: 2020-05-22 17:45:09 +0000 (Fri, 22 May 2020) Log Message: ----------- Change suggested by Olivier Mascia: Questionable language construct in PdfString.cpp See https://sourceforge.net/p/podofo/tickets/18/ for more information. Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfString.cpp Modified: podofo/trunk/src/podofo/base/PdfString.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfString.cpp 2020-05-22 16:23:51 UTC (rev 2008) +++ podofo/trunk/src/podofo/base/PdfString.cpp 2020-05-22 17:45:09 UTC (rev 2009) @@ -133,7 +133,8 @@ { lLen = wcslen( pszString ); } - if( sizeof(wchar_t) == 2 ) + constexpr bool wchar_t_is_two_bytes = sizeof(wchar_t) == 2; + if( wchar_t_is_two_bytes ) { // We have UTF16 lLen *= sizeof(wchar_t); @@ -153,10 +154,10 @@ // Try to convert to UTF8 pdf_long lDest = 5 * lLen; // At max 5 bytes per UTF8 char char* pDest = static_cast<char*>(podofo_malloc( lDest )); - if (!pDest) - { - PODOFO_RAISE_ERROR(ePdfError_OutOfMemory); - } + if (!pDest) + { + PODOFO_RAISE_ERROR(ePdfError_OutOfMemory); + } size_t cnt = wcstombs(pDest, pszString, lDest); if( cnt != static_cast<size_t>(-1) ) @@ -164,7 +165,7 @@ // No error InitFromUtf8( reinterpret_cast<pdf_utf8*>(pDest), cnt ); podofo_free( pDest ); - } + } else { podofo_free( pDest ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-05-22 16:23:52
|
Revision: 2008 http://sourceforge.net/p/podofo/code/2008 Author: mc-zyx Date: 2020-05-22 16:23:51 +0000 (Fri, 22 May 2020) Log Message: ----------- Patch by Michal Sudolsky: Make sure Fields array exists in PdfField::Init() Although Fields array in AcroForm is required there are PDF files which has AcroForm without Fields (one had XFA here "instead"). So new patch adds Fields if it does not exist before trying to add field into this array. Closes https://sourceforge.net/p/podofo/tickets/79/ Modified Paths: -------------- podofo/trunk/src/podofo/doc/PdfField.cpp Modified: podofo/trunk/src/podofo/doc/PdfField.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfField.cpp 2020-03-27 18:34:46 UTC (rev 2007) +++ podofo/trunk/src/podofo/doc/PdfField.cpp 2020-05-22 16:23:51 UTC (rev 2008) @@ -110,6 +110,8 @@ void PdfField::Init( PdfAcroForm* pParent ) { // Insert into the parents kids array + if( !pParent->GetObject()->GetDictionary().HasKey( "Fields" ) ) + pParent->GetObject()->GetDictionary().AddKey( "Fields", PdfArray() ); pParent->GetObject()->MustGetIndirectKey( "Fields" )->GetArray().push_back( m_pObject->Reference() ); switch( m_eField ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-03-27 18:34:48
|
Revision: 2007 http://sourceforge.net/p/podofo/code/2007 Author: mc-zyx Date: 2020-03-27 18:34:46 +0000 (Fri, 27 Mar 2020) Log Message: ----------- Remove std::auto_ptr usage from public API Modified Paths: -------------- podofo/trunk/CMakeLists.txt podofo/trunk/podofo_config.h.in podofo/trunk/src/podofo/base/PdfCompilerCompatPrivate.h podofo/trunk/src/podofo/base/PdfFilter.cpp podofo/trunk/src/podofo/base/PdfFilter.h podofo/trunk/src/podofo/base/PdfMemStream.cpp podofo/trunk/src/podofo/base/PdfStream.cpp podofo/trunk/src/podofo/base/PdfString.cpp podofo/trunk/src/podofo/base/PdfTokenizer.cpp podofo/trunk/src/podofo/doc/PdfFont.cpp podofo/trunk/src/podofo/doc/PdfPainter.cpp podofo/trunk/test/CreationTest/CreationTest.cpp podofo/trunk/test/FilterTest/FilterTest.cpp podofo/trunk/test/PdfTest.h podofo/trunk/test/VariantTest/VariantTest.cpp podofo/trunk/test/unit/FilterTest.cpp Modified: podofo/trunk/CMakeLists.txt =================================================================== --- podofo/trunk/CMakeLists.txt 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/CMakeLists.txt 2020-03-27 18:34:46 UTC (rev 2007) @@ -20,6 +20,7 @@ # # Main includes # +INCLUDE(CheckCXXSourceCompiles) INCLUDE(CheckIncludeFile) INCLUDE(CheckLibraryExists) INCLUDE(TestBigEndian) @@ -92,6 +93,14 @@ ENDIF(DEFINED LIB_SUFFIX) MESSAGE("Will install libraries to ${CMAKE_INSTALL_PREFIX}/${LIBDIRNAME}") +CHECK_CXX_SOURCE_COMPILES("#include <memory> + class Cls { + public: + Cls() {} + ~Cls() {} + }; + int main(void) { std::unique_ptr<Cls> cls; return 0; }" PODOFO_HAVE_UNIQUE_PTR) + # Some headers that tend to vary a bit CHECK_INCLUDE_FILE("strings.h" PODOFO_HAVE_STRINGS_H) CHECK_INCLUDE_FILE("arpa/inet.h" PODOFO_HAVE_ARPA_INET_H) Modified: podofo/trunk/podofo_config.h.in =================================================================== --- podofo/trunk/podofo_config.h.in 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/podofo_config.h.in 2020-03-27 18:34:46 UTC (rev 2007) @@ -16,6 +16,7 @@ #cmakedefine PODOFO_MULTI_THREAD /* somewhat platform-specific headers */ +#cmakedefine PODOFO_HAVE_UNIQUE_PTR 1 #cmakedefine PODOFO_HAVE_STRINGS_H 1 #cmakedefine PODOFO_HAVE_ARPA_INET_H 1 #cmakedefine PODOFO_HAVE_WINSOCK2_H 1 Modified: podofo/trunk/src/podofo/base/PdfCompilerCompatPrivate.h =================================================================== --- podofo/trunk/src/podofo/base/PdfCompilerCompatPrivate.h 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/base/PdfCompilerCompatPrivate.h 2020-03-27 18:34:46 UTC (rev 2007) @@ -245,6 +245,13 @@ #endif // _DEBUG #endif // _MSC_VER +// prefer std::unique_ptr over std::auto_ptr +#ifdef PODOFO_HAVE_UNIQUE_PTR +#define PODOFO_UNIQUEU_PTR std::unique_ptr +#else +#define PODOFO_UNIQUEU_PTR std::auto_ptr +#endif + /** * \page PoDoFo PdfCompilerCompatPrivate Header * Modified: podofo/trunk/src/podofo/base/PdfFilter.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfFilter.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/base/PdfFilter.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -92,16 +92,16 @@ * \param bOwnStream if true pOutputStream will be deleted along with this filter */ PdfFilteredEncodeStream( PdfOutputStream* pOutputStream, const EPdfFilter eFilter, bool bOwnStream ) - : m_pOutputStream( pOutputStream ) + : m_pOutputStream( pOutputStream ), m_pFilter( NULL ) { - m_filter = PdfFilterFactory::Create( eFilter ); + m_pFilter = PdfFilterFactory::Create( eFilter ); - if( !m_filter.get() ) + if( !m_pFilter ) { PODOFO_RAISE_ERROR( ePdfError_UnsupportedFilter ); } - m_filter->BeginEncode( pOutputStream ); + m_pFilter->BeginEncode( pOutputStream ); if( !bOwnStream ) m_pOutputStream = NULL; @@ -110,6 +110,7 @@ virtual ~PdfFilteredEncodeStream() { delete m_pOutputStream; + delete m_pFilter; } /** Write data to the output stream @@ -119,7 +120,7 @@ */ virtual pdf_long Write( const char* pBuffer, pdf_long lLen ) { - m_filter->EncodeBlock( pBuffer, lLen ); + m_pFilter->EncodeBlock( pBuffer, lLen ); return 0; } @@ -126,12 +127,12 @@ virtual void Close() { - m_filter->EndEncode(); + m_pFilter->EndEncode(); } private: - PdfOutputStream* m_pOutputStream; - std::auto_ptr<PdfFilter> m_filter; + PdfOutputStream* m_pOutputStream; + PdfFilter* m_pFilter; }; /** Create a filter that is a PdfOutputStream. @@ -158,15 +159,15 @@ */ PdfFilteredDecodeStream( PdfOutputStream* pOutputStream, const EPdfFilter eFilter, bool bOwnStream, const PdfDictionary* pDecodeParms = NULL ) - : m_pOutputStream( pOutputStream ), m_bFilterFailed( false ) + : m_pOutputStream( pOutputStream ), m_pFilter( NULL ), m_bFilterFailed( false ) { - m_filter = PdfFilterFactory::Create( eFilter ); - if( !m_filter.get() ) + m_pFilter = PdfFilterFactory::Create( eFilter ); + if( !m_pFilter ) { PODOFO_RAISE_ERROR( ePdfError_UnsupportedFilter ); } - m_filter->BeginDecode( pOutputStream, pDecodeParms ); + m_pFilter->BeginDecode( pOutputStream, pDecodeParms ); if( !bOwnStream ) m_pOutputStream = NULL; @@ -175,6 +176,7 @@ virtual ~PdfFilteredDecodeStream() { delete m_pOutputStream; + delete m_pFilter; } /** Write data to the output stream @@ -185,7 +187,7 @@ virtual pdf_long Write( const char* pBuffer, pdf_long lLen ) { try { - m_filter->DecodeBlock( pBuffer, lLen ); + m_pFilter->DecodeBlock( pBuffer, lLen ); } catch( PdfError & e ) { @@ -202,7 +204,7 @@ try { if( !m_bFilterFailed ) { - m_filter->EndDecode(); + m_pFilter->EndDecode(); } } catch( PdfError & e ) @@ -209,7 +211,7 @@ { std::ostringstream oss; oss << "PdfFilter::EndDecode() failed in filter of type " - << PdfFilterFactory::FilterTypeToName( m_filter->GetType() ) << ".\n"; + << PdfFilterFactory::FilterTypeToName( m_pFilter->GetType() ) << ".\n"; e.AddToCallstack( __FILE__, __LINE__, oss.str() ); m_bFilterFailed = true; throw e; @@ -218,9 +220,9 @@ } private: - PdfOutputStream* m_pOutputStream; - std::auto_ptr<PdfFilter> m_filter; - bool m_bFilterFailed; + PdfOutputStream* m_pOutputStream; + PdfFilter* m_pFilter; + bool m_bFilterFailed; }; @@ -277,7 +279,7 @@ { } -std::auto_ptr<PdfFilter> PdfFilterFactory::Create( const EPdfFilter eFilter ) +PdfFilter* PdfFilterFactory::Create( const EPdfFilter eFilter ) { PdfFilter* pFilter = NULL; switch( eFilter ) @@ -329,7 +331,7 @@ break; } - return std::auto_ptr<PdfFilter>(pFilter); + return pFilter; } PdfOutputStream* PdfFilterFactory::CreateEncodeStream( const TVecFilters & filters, PdfOutputStream* pStream ) Modified: podofo/trunk/src/podofo/base/PdfFilter.h =================================================================== --- podofo/trunk/src/podofo/base/PdfFilter.h 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/base/PdfFilter.h 2020-03-27 18:34:46 UTC (rev 2007) @@ -462,9 +462,8 @@ public: /** Create a filter from an enum. * - * Ownership is transferred to the caller, who should let the auto_ptr - * the filter is returned in take care of freeing it when they're done - * with it. + * Ownership is transferred to the caller, whom should delete non-NULL + * PdfFilter instance, when no longer needed. * * \param eFilter return value of GetType() for filter to be created * @@ -471,7 +470,7 @@ * \returns a new PdfFilter allocated using new, or NULL if no * filter is available for this type. */ - static std::auto_ptr<PdfFilter> Create( const EPdfFilter eFilter ); + static PdfFilter* Create( const EPdfFilter eFilter ); /** Create a PdfOutputStream that applies a list of filters * on all data written to it. Modified: podofo/trunk/src/podofo/base/PdfMemStream.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfMemStream.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/base/PdfMemStream.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -245,7 +245,7 @@ if( !m_lLength ) return; - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_FlateDecode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_FlateDecode ) ); if( pFilter.get() ) { pFilter->Encode( m_buffer.GetBuffer(), m_buffer.GetSize(), &pBuffer, &lLen ); Modified: podofo/trunk/src/podofo/base/PdfStream.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfStream.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/base/PdfStream.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -91,11 +91,11 @@ PdfMemoryOutputStream stream; if( vecFilters.size() ) { - // Use std::auto_ptr so that pDecodeStream is deleted + // Use std::uniqueu_ptr so that pDecodeStream is deleted // even in the case of an exception - std::auto_ptr<PdfOutputStream> pDecodeStream( PdfFilterFactory::CreateDecodeStream( vecFilters, &stream, - m_pParent ? - &(m_pParent->GetDictionary()) : NULL ) ); + PODOFO_UNIQUEU_PTR<PdfOutputStream> pDecodeStream( PdfFilterFactory::CreateDecodeStream( vecFilters, &stream, + m_pParent ? + &(m_pParent->GetDictionary()) : NULL ) ); pDecodeStream->Write( this->GetInternalBuffer(), this->GetInternalBufferSize() ); pDecodeStream->Close(); Modified: podofo/trunk/src/podofo/base/PdfString.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfString.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/base/PdfString.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -684,14 +684,12 @@ return *this; else { - std::auto_ptr<PdfFilter> pFilter; - pdf_long lLen = (m_buffer.GetSize() - 1) << 1; PdfString str; PdfRefCountedBuffer buffer( lLen + 1 ); PdfMemoryOutputStream stream( buffer.GetBuffer(), lLen ); - pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ) ); pFilter->BeginEncode( &stream ); pFilter->EncodeBlock( m_buffer.GetBuffer(), (m_buffer.GetSize() - 1) ); pFilter->EndEncode(); @@ -713,14 +711,12 @@ return *this; else { - std::auto_ptr<PdfFilter> pFilter; - pdf_long lLen = m_buffer.GetSize() >> 1; PdfString str; PdfRefCountedBuffer buffer( lLen ); PdfMemoryOutputStream stream( buffer.GetBuffer(), lLen ); - pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ) ); pFilter->BeginDecode( &stream ); pFilter->DecodeBlock( m_buffer.GetBuffer(), m_buffer.GetSize() ); pFilter->EndDecode(); Modified: podofo/trunk/src/podofo/base/PdfTokenizer.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfTokenizer.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/base/PdfTokenizer.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -598,7 +598,7 @@ PdfDictionary dict; EPdfTokenType eType; const char * pszToken; - std::auto_ptr<std::vector<char> > contentsHexBuffer; + PODOFO_UNIQUEU_PTR<std::vector<char> > contentsHexBuffer; for( ;; ) { @@ -626,7 +626,7 @@ { // 'Contents' key in signature dictionaries is an unencrypted Hex string: // save the string buffer for later check if it needed decryption - contentsHexBuffer = std::auto_ptr<std::vector<char> >( new std::vector<char>() ); + contentsHexBuffer = PODOFO_UNIQUEU_PTR<std::vector<char> >( new std::vector<char>() ); ReadHexString( *contentsHexBuffer ); continue; } Modified: podofo/trunk/src/podofo/doc/PdfFont.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfFont.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/doc/PdfFont.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -145,7 +145,7 @@ pdf_long lLen = 0; char* pBuffer = NULL; - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ) ); pFilter->Encode( buffer.GetBuffer(), buffer.GetSize(), &pBuffer, &lLen ); pStream->Append( "<", 1 ); Modified: podofo/trunk/src/podofo/doc/PdfPainter.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfPainter.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/src/podofo/doc/PdfPainter.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -829,7 +829,7 @@ /* char* pBuffer; - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ) ); pFilter->Encode( sString.GetString(), sString.GetLength(), &pBuffer, &lLen ); m_pCanvas->Append( pBuffer, lLen ); Modified: podofo/trunk/test/CreationTest/CreationTest.cpp =================================================================== --- podofo/trunk/test/CreationTest/CreationTest.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/test/CreationTest/CreationTest.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -37,7 +37,7 @@ pdf_long lLen = 0; char* pBuffer = NULL; - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ) ); pFilter->Encode( buffer.GetBuffer(), buffer.GetSize(), &pBuffer, &lLen ); oss << "<"; Modified: podofo/trunk/test/FilterTest/FilterTest.cpp =================================================================== --- podofo/trunk/test/FilterTest/FilterTest.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/test/FilterTest/FilterTest.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -57,7 +57,7 @@ pdf_long lEncoded; pdf_long lDecoded; - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( eFilter ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( eFilter ) ); if( !pFilter.get() ) { printf("!!! Filter %i not implemented.\n", eFilter); @@ -256,7 +256,7 @@ char* pLargeBuffer2 = static_cast<char*>(malloc( strlen(pszInputAscii85Lzw) * 6 )); try { - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_ASCII85Decode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_ASCII85Decode ) ); pFilter->Decode( pszInputAscii85Lzw, strlen(pszInputAscii85Lzw), &pLargeBuffer1, &lLargeBufer1 ); pFilter->Encode( pLargeBuffer1, lLargeBufer1, Modified: podofo/trunk/test/PdfTest.h =================================================================== --- podofo/trunk/test/PdfTest.h 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/test/PdfTest.h 2020-03-27 18:34:46 UTC (rev 2007) @@ -13,3 +13,10 @@ e.AddToCallstack( __FILE__, __LINE__, NULL ); \ e.PrintErrorMsg();\ } + +// prefer std::unique_ptr over std::auto_ptr +#ifdef PODOFO_HAVE_UNIQUE_PTR +#define PODOFO_UNIQUEU_PTR std::unique_ptr +#else +#define PODOFO_UNIQUEU_PTR std::auto_ptr +#endif Modified: podofo/trunk/test/VariantTest/VariantTest.cpp =================================================================== --- podofo/trunk/test/VariantTest/VariantTest.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/test/VariantTest/VariantTest.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -124,7 +124,7 @@ printf("This test tests the PdfVariant class.\n"); printf("---\n"); - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ) ); // testing strings TEST_SAFE_OP( Test( "(Hallo Welt!)", ePdfDataType_String ) ); Modified: podofo/trunk/test/unit/FilterTest.cpp =================================================================== --- podofo/trunk/test/unit/FilterTest.cpp 2020-03-27 17:51:49 UTC (rev 2006) +++ podofo/trunk/test/unit/FilterTest.cpp 2020-03-27 18:34:46 UTC (rev 2007) @@ -24,6 +24,13 @@ #include <stdlib.h> +// prefer std::unique_ptr over std::auto_ptr +#ifdef PODOFO_HAVE_UNIQUE_PTR +#define PODOFO_UNIQUEU_PTR std::unique_ptr +#else +#define PODOFO_UNIQUEU_PTR std::auto_ptr +#endif + using namespace PoDoFo; CPPUNIT_TEST_SUITE_REGISTRATION( FilterTest ); @@ -59,7 +66,7 @@ pdf_long lEncoded; pdf_long lDecoded; - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( eFilter ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( eFilter ) ); if( !pFilter.get() ) { printf("!!! Filter %i not implemented.\n", eFilter); @@ -123,7 +130,7 @@ void FilterTest::testCCITT() { - std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_CCITTFaxDecode ); + PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_CCITTFaxDecode ) ); if( !pFilter.get() ) { printf("!!! ePdfFilter_CCITTFaxDecode not implemented skipping test!\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-03-27 17:51:51
|
Revision: 2006 http://sourceforge.net/p/podofo/code/2006 Author: mc-zyx Date: 2020-03-27 17:51:49 +0000 (Fri, 27 Mar 2020) Log Message: ----------- Patch by Michal Sudolsky: Strings in object streams are decrypted twice for some encryption algorithms Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.h podofo/trunk/src/podofo/base/PdfParser.cpp Modified: podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp 2020-03-27 17:24:54 UTC (rev 2005) +++ podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp 2020-03-27 17:51:49 UTC (rev 2006) @@ -34,7 +34,6 @@ #include "PdfObjectStreamParserObject.h" #include "PdfDictionary.h" -#include "PdfEncrypt.h" #include "PdfInputDevice.h" #include "PdfParserObject.h" #include "PdfStream.h" @@ -49,8 +48,8 @@ namespace PoDoFo { -PdfObjectStreamParserObject::PdfObjectStreamParserObject(PdfParserObject* pParser, PdfVecObjects* pVecObjects, const PdfRefCountedBuffer & rBuffer, PdfEncrypt* pEncrypt ) - : m_pParser( pParser ), m_vecObjects( pVecObjects ), m_buffer( rBuffer ), m_pEncrypt( pEncrypt ) +PdfObjectStreamParserObject::PdfObjectStreamParserObject(PdfParserObject* pParser, PdfVecObjects* pVecObjects, const PdfRefCountedBuffer & rBuffer) + : m_pParser( pParser ), m_vecObjects( pVecObjects ), m_buffer( rBuffer ) { } @@ -107,14 +106,7 @@ // use a second tokenizer here so that anything that gets dequeued isn't left in the tokenizer that reads the offsets and lengths PdfTokenizer variantTokenizer( device, m_buffer ); - if( m_pEncrypt && (m_pEncrypt->GetEncryptAlgorithm() == PdfEncrypt::ePdfEncryptAlgorithm_AESV2 -#ifndef PODOFO_HAVE_OPENSSL_NO_RC4 - || m_pEncrypt->GetEncryptAlgorithm() == PdfEncrypt::ePdfEncryptAlgorithm_RC4V2 -#endif // PODOFO_HAVE_OPENSSL_NO_RC4 - ) ) - variantTokenizer.GetNextVariant( var, 0 ); // Stream is already decrypted - else - variantTokenizer.GetNextVariant( var, m_pEncrypt ); + variantTokenizer.GetNextVariant( var, 0 ); // Stream is already decrypted bool should_read = std::find(list.begin(), list.end(), lObj) != list.end(); #if defined(PODOFO_VERBOSE_DEBUG) std::cerr << "ReadObjectsFromStream STREAM=" << m_pParser->Reference().ToString() << Modified: podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.h =================================================================== --- podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.h 2020-03-27 17:24:54 UTC (rev 2005) +++ podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.h 2020-03-27 17:51:49 UTC (rev 2006) @@ -40,7 +40,6 @@ namespace PoDoFo { -class PdfEncrypt; class PdfParserObject; class PdfVecObjects; @@ -61,9 +60,8 @@ * \param pParser PdfParserObject for an object stream * \param pVecObjects add loaded objecs to this vector of objects * \param rBuffer use this allocated buffer for caching - * \param pEncrypt encryption object used to decrypt streams */ - PdfObjectStreamParserObject(PdfParserObject* pParser, PdfVecObjects* pVecObjects, const PdfRefCountedBuffer & rBuffer, PdfEncrypt* pEncrypt ); + PdfObjectStreamParserObject(PdfParserObject* pParser, PdfVecObjects* pVecObjects, const PdfRefCountedBuffer & rBuffer); ~PdfObjectStreamParserObject(); @@ -76,7 +74,6 @@ PdfParserObject* m_pParser; PdfVecObjects* m_vecObjects; PdfRefCountedBuffer m_buffer; - PdfEncrypt* m_pEncrypt; }; }; Modified: podofo/trunk/src/podofo/base/PdfParser.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfParser.cpp 2020-03-27 17:24:54 UTC (rev 2005) +++ podofo/trunk/src/podofo/base/PdfParser.cpp 2020-03-27 17:51:49 UTC (rev 2006) @@ -1326,7 +1326,7 @@ } } - PdfObjectStreamParserObject pParserObject( pStream, m_vecObjects, m_buffer, m_pEncrypt ); + PdfObjectStreamParserObject pParserObject( pStream, m_vecObjects, m_buffer ); pParserObject.Parse( list ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-03-27 17:24:56
|
Revision: 2005 http://sourceforge.net/p/podofo/code/2005 Author: mc-zyx Date: 2020-03-27 17:24:54 +0000 (Fri, 27 Mar 2020) Log Message: ----------- Patch by Michal Sudolsky: Support indirect references in dictionaries where PoDoFo expects only direct objects Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfCanvas.cpp podofo/trunk/src/podofo/base/PdfFilter.cpp podofo/trunk/src/podofo/base/PdfObject.cpp podofo/trunk/src/podofo/base/PdfObject.h podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp podofo/trunk/src/podofo/base/PdfParser.cpp podofo/trunk/src/podofo/base/PdfParserObject.cpp podofo/trunk/src/podofo/doc/PdfAcroForm.cpp podofo/trunk/src/podofo/doc/PdfAction.cpp podofo/trunk/src/podofo/doc/PdfAnnotation.cpp podofo/trunk/src/podofo/doc/PdfDestination.cpp podofo/trunk/src/podofo/doc/PdfDifferenceEncoding.cpp podofo/trunk/src/podofo/doc/PdfDocument.cpp podofo/trunk/src/podofo/doc/PdfElement.cpp podofo/trunk/src/podofo/doc/PdfField.cpp podofo/trunk/src/podofo/doc/PdfFileSpec.cpp podofo/trunk/src/podofo/doc/PdfFontFactory.cpp podofo/trunk/src/podofo/doc/PdfFontMetricsObject.cpp podofo/trunk/src/podofo/doc/PdfImage.cpp podofo/trunk/src/podofo/doc/PdfInfo.cpp podofo/trunk/src/podofo/doc/PdfNamesTree.cpp podofo/trunk/src/podofo/doc/PdfPage.cpp podofo/trunk/src/podofo/doc/PdfPagesTree.cpp podofo/trunk/src/podofo/doc/PdfPainter.cpp podofo/trunk/src/podofo/doc/PdfSignatureField.cpp podofo/trunk/src/podofo/doc/PdfXObject.cpp Modified: podofo/trunk/src/podofo/base/PdfCanvas.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfCanvas.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/base/PdfCanvas.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -72,7 +72,7 @@ if ( ! pResource->GetDictionary().HasKey( "ColorSpace" ) || - ! pResource->GetDictionary().GetKey( "ColorSpace" )->GetDictionary().HasKey( csPrefix + csName ) + ! pResource->MustGetIndirectKey( "ColorSpace" )->GetDictionary().HasKey( csPrefix + csName ) ) { // Build color-spaces for separation @@ -87,7 +87,7 @@ { if ( ! pResource->GetDictionary().HasKey( "ColorSpace" ) || - ! pResource->GetDictionary().GetKey( "ColorSpace" )->GetDictionary().HasKey( "ColorSpaceLab" ) + ! pResource->MustGetIndirectKey( "ColorSpace" )->GetDictionary().HasKey( "ColorSpaceLab" ) ) { // Build color-spaces for CIE-lab Modified: podofo/trunk/src/podofo/base/PdfFilter.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfFilter.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/base/PdfFilter.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -412,7 +412,7 @@ const PdfObject* pObj = NULL; if( pObject->IsDictionary() && pObject->GetDictionary().HasKey( "Filter" ) ) - pObj = pObject->GetDictionary().GetKey( "Filter" ); + pObj = pObject->GetIndirectKey( "Filter" ); else if( pObject->IsArray() ) pObj = pObject; else if( pObject->IsName() ) Modified: podofo/trunk/src/podofo/base/PdfObject.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfObject.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/base/PdfObject.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -268,6 +268,56 @@ return const_cast<PdfObject*>( this->GetDictionary().FindKey( key ) ); } +pdf_int64 PdfObject::GetIndirectKeyAsLong( const PdfName & key, pdf_int64 lDefault ) const +{ + const PdfObject* pObject = GetIndirectKey( key ); + + if( pObject && pObject->GetDataType() == ePdfDataType_Number ) + { + return pObject->GetNumber(); + } + + return lDefault; +} + +double PdfObject::GetIndirectKeyAsReal( const PdfName & key, double dDefault ) const +{ + const PdfObject* pObject = GetIndirectKey( key ); + + if( pObject && ( + pObject->GetDataType() == ePdfDataType_Real || + pObject->GetDataType() == ePdfDataType_Number)) + { + return pObject->GetReal(); + } + + return dDefault; +} + +bool PdfObject::GetIndirectKeyAsBool( const PdfName & key, bool bDefault ) const +{ + const PdfObject* pObject = GetIndirectKey( key ); + + if( pObject && pObject->GetDataType() == ePdfDataType_Bool ) + { + return pObject->GetBool(); + } + + return bDefault; +} + +PdfName PdfObject::GetIndirectKeyAsName( const PdfName & key ) const +{ + const PdfObject* pObject = GetIndirectKey( key ); + + if( pObject && pObject->GetDataType() == ePdfDataType_Name ) + { + return pObject->GetName(); + } + + return PdfName(""); // return an empty name +} + pdf_long PdfObject::GetObjectLength( EPdfWriteMode eWriteMode ) { PdfOutputDevice device; Modified: podofo/trunk/src/podofo/base/PdfObject.h =================================================================== --- podofo/trunk/src/podofo/base/PdfObject.h 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/base/PdfObject.h 2020-03-27 17:24:54 UTC (rev 2005) @@ -183,6 +183,14 @@ */ inline PdfObject* MustGetIndirectKey( const PdfName & key ) const; + pdf_int64 GetIndirectKeyAsLong( const PdfName & key, pdf_int64 lDefault = 0 ) const; + + double GetIndirectKeyAsReal( const PdfName & key, double dDefault = 0.0 ) const; + + bool GetIndirectKeyAsBool( const PdfName & key, bool bDefault = false ) const; + + PdfName GetIndirectKeyAsName( const PdfName & key ) const; + /** Write the complete object to a file. * \param pDevice write the object to this device * \param pEncrypt an encryption object which is used to encrypt this object Modified: podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/base/PdfObjectStreamParserObject.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -62,8 +62,8 @@ void PdfObjectStreamParserObject::Parse(ObjectIdList const & list) { - pdf_int64 lNum = m_pParser->GetDictionary().GetKeyAsLong( "N", 0 ); - pdf_int64 lFirst = m_pParser->GetDictionary().GetKeyAsLong( "First", 0 ); + pdf_int64 lNum = m_pParser->GetIndirectKeyAsLong( "N", 0 ); + pdf_int64 lFirst = m_pParser->GetIndirectKeyAsLong( "First", 0 ); char* pBuffer; pdf_long lBufferLen; Modified: podofo/trunk/src/podofo/base/PdfParser.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfParser.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/base/PdfParser.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -1445,7 +1445,7 @@ && pCatalog->IsDictionary() && pCatalog->GetDictionary().HasKey( PdfName("Version" ) ) ) { - PdfObject* pVersion = pCatalog->GetDictionary().GetKey( PdfName( "Version" ) ); + PdfObject* pVersion = pCatalog->MustGetIndirectKey( PdfName( "Version" ) ); for(int i=0;i<=MAX_PDF_VERSION_STRING_INDEX;i++) { if( IsStrictParsing() && !pVersion->IsName()) Modified: podofo/trunk/src/podofo/base/PdfParserObject.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfParserObject.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/base/PdfParserObject.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -331,11 +331,16 @@ if( m_pEncrypt && !m_pEncrypt->IsMetadataEncrypted() ) { // If metadata is not encrypted the Filter is set to "Crypt" PdfObject* pFilterObj = this->GetDictionary_NoDL().GetKey( PdfName::KeyFilter ); + if( pFilterObj && pFilterObj->IsReference() ) + pFilterObj = m_pOwner->GetObject( pFilterObj->GetReference() ); if( pFilterObj && pFilterObj->IsArray() ) { PdfArray filters = pFilterObj->GetArray(); for(PdfArray::iterator it = filters.begin(); it != filters.end(); it++) { - if( (*it).IsName() ) - if( (*it).GetName() == "Crypt" ) + PdfObject *filter = &*it; + if( filter->IsReference() ) + filter = m_pOwner->GetObject( filter->GetReference() ); + if( filter && filter->IsName() ) + if( filter->GetName() == "Crypt" ) m_pEncrypt = 0; } } Modified: podofo/trunk/src/podofo/doc/PdfAcroForm.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfAcroForm.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfAcroForm.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -85,15 +85,11 @@ // Create DR key if( !this->GetObject()->GetDictionary().HasKey( PdfName("DR") ) ) this->GetObject()->GetDictionary().AddKey( PdfName("DR"), PdfDictionary() ); - pResource = this->GetObject()->GetDictionary().GetKey( PdfName("DR") ); - if( pResource->IsReference() ) - pResource = m_pDocument->GetObjects()->GetObject( pResource->GetReference() ); + pResource = this->GetObject()->MustGetIndirectKey( PdfName("DR") ); if( !pResource->GetDictionary().HasKey( PdfName("Font") ) ) pResource->GetDictionary().AddKey( PdfName("Font"), PdfDictionary() ); - pFontDict = pResource->GetDictionary().GetKey( PdfName("Font") ); - if( pFontDict->IsReference() ) - pFontDict = m_pDocument->GetObjects()->GetObject( pFontDict->GetReference() ); + pFontDict = pResource->MustGetIndirectKey( PdfName("Font") ); pFontDict->GetDictionary().AddKey( pFont->GetIdentifier(), pFont->GetObject()->Reference() ); @@ -127,7 +123,7 @@ bool PdfAcroForm::GetNeedAppearances() const { - return this->GetObject()->GetDictionary().GetKeyAsBool( PdfName("NeedAppearances"), false ); + return this->GetObject()->GetIndirectKeyAsBool( PdfName("NeedAppearances"), false ); } }; Modified: podofo/trunk/src/podofo/doc/PdfAction.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfAction.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfAction.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -91,13 +91,13 @@ // The typename /Action is optional for PdfActions : PdfElement( NULL, pObject ) { - m_eType = static_cast<EPdfAction>(TypeNameToIndex( this->GetObject()->GetDictionary().GetKeyAsName( "S" ).GetName().c_str(), s_names, s_lNumActions, ePdfAction_Unknown )); + m_eType = static_cast<EPdfAction>(TypeNameToIndex( this->GetObject()->GetIndirectKeyAsName( "S" ).GetName().c_str(), s_names, s_lNumActions, ePdfAction_Unknown )); } PdfAction::PdfAction( const PdfAction & rhs ) : PdfElement( "Action", rhs.GetNonConstObject() ) { - m_eType = static_cast<EPdfAction>(TypeNameToIndex( this->GetObject()->GetDictionary().GetKeyAsName( "S" ).GetName().c_str(), s_names, s_lNumActions, ePdfAction_Unknown )); + m_eType = static_cast<EPdfAction>(TypeNameToIndex( this->GetObject()->GetIndirectKeyAsName( "S" ).GetName().c_str(), s_names, s_lNumActions, ePdfAction_Unknown )); } void PdfAction::SetURI( const PdfString & sUri ) @@ -123,7 +123,7 @@ PdfString PdfAction::GetScript() const { - return this->GetObject()->GetDictionary().GetKey( "JS" )->GetString(); + return this->GetObject()->MustGetIndirectKey( "JS" )->GetString(); } Modified: podofo/trunk/src/podofo/doc/PdfAnnotation.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfAnnotation.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfAnnotation.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -104,7 +104,7 @@ PdfAnnotation::PdfAnnotation( PdfObject* pObject, PdfPage* pPage ) : PdfElement( "Annot", pObject ), m_eAnnotation( ePdfAnnotation_Unknown ), m_pAction( NULL ), m_pFileSpec( NULL ), m_pPage( pPage ) { - m_eAnnotation = static_cast<EPdfAnnotation>(TypeNameToIndex( this->GetObject()->GetDictionary().GetKeyAsName( PdfName::KeySubtype ).GetName().c_str(), s_names, s_lNumActions, ePdfAnnotation_Unknown )); + m_eAnnotation = static_cast<EPdfAnnotation>(TypeNameToIndex( this->GetObject()->GetIndirectKeyAsName( PdfName::KeySubtype ).GetName().c_str(), s_names, s_lNumActions, ePdfAnnotation_Unknown )); } PdfAnnotation::~PdfAnnotation() @@ -116,7 +116,7 @@ PdfRect PdfAnnotation::GetRect() const { if( this->GetObject()->GetDictionary().HasKey( PdfName::KeyRect ) ) - return PdfRect( this->GetObject()->GetDictionary().GetKey( PdfName::KeyRect )->GetArray() ); + return PdfRect( this->GetObject()->MustGetIndirectKey( PdfName::KeyRect )->GetArray() ); return PdfRect(); } @@ -246,7 +246,7 @@ pdf_uint32 PdfAnnotation::GetFlags() const { if( this->GetObject()->GetDictionary().HasKey( "F" ) ) - return static_cast<pdf_uint32>(this->GetObject()->GetDictionary().GetKey( "F" )->GetNumber()); + return static_cast<pdf_uint32>(this->GetObject()->MustGetIndirectKey( "F" )->GetNumber()); return static_cast<pdf_uint32>(0); } @@ -278,7 +278,7 @@ PdfString PdfAnnotation::GetTitle() const { if( this->GetObject()->GetDictionary().HasKey( "T" ) ) - return this->GetObject()->GetDictionary().GetKey( "T" )->GetString(); + return this->GetObject()->MustGetIndirectKey( "T" )->GetString(); return PdfString(); } @@ -291,7 +291,7 @@ PdfString PdfAnnotation::GetContents() const { if( this->GetObject()->GetDictionary().HasKey( "Contents" ) ) - return this->GetObject()->GetDictionary().GetKey( "Contents" )->GetString(); + return this->GetObject()->MustGetIndirectKey( "Contents" )->GetString(); return PdfString(); } @@ -303,7 +303,7 @@ PdfDestination PdfAnnotation::GetDestination( PdfDocument* pDoc ) const { - return PdfDestination( this->GetNonConstObject()->GetDictionary().GetKey( "Dest" ), pDoc ); + return PdfDestination( this->GetNonConstObject()->MustGetIndirectKey( "Dest" ), pDoc ); } bool PdfAnnotation::HasDestination() const @@ -341,7 +341,7 @@ bool PdfAnnotation::GetOpen() const { if( this->GetObject()->GetDictionary().HasKey( "Open" ) ) - return this->GetObject()->GetDictionary().GetKey( "Open" )->GetBool(); + return this->GetObject()->MustGetIndirectKey( "Open" )->GetBool(); return false; } @@ -371,7 +371,7 @@ PdfArray PdfAnnotation::GetQuadPoints() const { if( this->GetObject()->GetDictionary().HasKey( "QuadPoints" ) ) - return PdfArray( this->GetObject()->GetDictionary().GetKey( "QuadPoints" )->GetArray() ); + return PdfArray( this->GetObject()->MustGetIndirectKey( "QuadPoints" )->GetArray() ); return PdfArray(); } @@ -390,7 +390,7 @@ PdfArray PdfAnnotation::GetColor() const { if( this->GetObject()->GetDictionary().HasKey( "C" ) ) - return PdfArray( this->GetObject()->GetDictionary().GetKey( "C" )->GetArray() ); + return PdfArray( this->GetObject()->MustGetIndirectKey( "C" )->GetArray() ); return PdfArray(); } Modified: podofo/trunk/src/podofo/doc/PdfDestination.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfDestination.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfDestination.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -218,7 +218,7 @@ if( pValue->IsArray() ) m_array = pValue->GetArray(); else if( pValue->IsDictionary() ) - m_array = pValue->GetDictionary().GetKey( "D" )->GetArray(); + m_array = pValue->MustGetIndirectKey( "D" )->GetArray(); m_pObject = pValue; } } Modified: podofo/trunk/src/podofo/doc/PdfDifferenceEncoding.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfDifferenceEncoding.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfDifferenceEncoding.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -2388,7 +2388,7 @@ if( this->GetObject()->GetDictionary().HasKey( PdfName("BaseEncoding") ) ) { - const PdfName & rBase = this->GetObject()->GetDictionary().GetKey( PdfName("BaseEncoding") )->GetName(); + const PdfName & rBase = this->GetObject()->MustGetIndirectKey( PdfName("BaseEncoding") )->GetName(); if( rBase == PdfName("WinAnsiEncoding") ) m_baseEncoding = eBaseEncoding_WinAnsi; Modified: podofo/trunk/src/podofo/doc/PdfDocument.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfDocument.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfDocument.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -504,11 +504,7 @@ if( pObj->IsDictionary() && pObj->GetDictionary().HasKey( "Contents" ) ) { // get direct pointer to contents - PdfObject* pContents; - if( pObj->GetDictionary().GetKey( "Contents" )->IsReference() ) - pContents = m_vecObjects.GetObject( pObj->GetDictionary().GetKey( "Contents" )->GetReference() ); - else - pContents = pObj->GetDictionary().GetKey( "Contents" ); + PdfObject* pContents = pObj->MustGetIndirectKey( "Contents" ); if( pContents->IsArray() ) { Modified: podofo/trunk/src/podofo/doc/PdfElement.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfElement.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfElement.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -71,10 +71,10 @@ if( pszType && m_pObject->GetDictionary().HasKey( PdfName::KeyType ) - && m_pObject->GetDictionary().GetKeyAsName( PdfName::KeyType ) != pszType ) + && m_pObject->GetIndirectKeyAsName( PdfName::KeyType ) != pszType ) { PdfError::LogMessage( eLogSeverity_Debug, "Expected key %s but got key %s.", - pszType, m_pObject->GetDictionary().GetKeyAsName( PdfName::KeyType ).GetName().c_str() ); + pszType, m_pObject->GetIndirectKeyAsName( PdfName::KeyType ).GetName().c_str() ); PODOFO_RAISE_ERROR( ePdfError_InvalidDataType ); } Modified: podofo/trunk/src/podofo/doc/PdfField.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfField.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfField.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -149,7 +149,7 @@ : m_pObject( pObject ), m_pWidget( pWidget ), m_eField( ePdfField_Unknown ) { // ISO 32000:2008, Section 12.7.3.1, Table 220, Page #432. - const PdfObject *pFT = m_pObject->GetDictionary().GetKey(PdfName("FT") ); + const PdfObject *pFT = m_pObject->GetIndirectKey(PdfName("FT") ); if (!pFT && m_pObject->GetDictionary().HasKey( PdfName ("Parent") ) ) { @@ -159,7 +159,7 @@ PODOFO_RAISE_ERROR (ePdfError_InvalidDataType); } - pFT = pTemp->GetDictionary().GetKey( PdfName ("FT") ); + pFT = pTemp->GetIndirectKey( PdfName ("FT") ); } if (!pFT) @@ -201,7 +201,7 @@ const_cast<PdfField*>(this)->m_pObject->GetDictionary().AddKey( PdfName("MK"), dictionary ); } - pMK = m_pObject->GetDictionary().GetKey( PdfName("MK") ); + pMK = m_pObject->GetIndirectKey( PdfName("MK") ); return pMK; } @@ -211,7 +211,7 @@ pdf_int64 lCur = 0; if( m_pObject->GetDictionary().HasKey( PdfName("Ff") ) ) - lCur = m_pObject->GetDictionary().GetKey( PdfName("Ff") )->GetNumber(); + lCur = m_pObject->MustGetIndirectKey( PdfName("Ff") )->GetNumber(); if( bSet ) lCur |= lValue; @@ -230,7 +230,7 @@ if( m_pObject->GetDictionary().HasKey( PdfName("Ff") ) ) { - lCur = m_pObject->GetDictionary().GetKey( PdfName("Ff") )->GetNumber(); + lCur = m_pObject->MustGetIndirectKey( PdfName("Ff") )->GetNumber(); return (lCur & lValue) == lValue; } @@ -271,7 +271,7 @@ if( m_pObject->GetDictionary().HasKey( PdfName("H") ) ) { - PdfName value = m_pObject->GetDictionary().GetKey( PdfName("H") )->GetName(); + PdfName value = m_pObject->MustGetIndirectKey( PdfName("H") )->GetName(); if( value == PdfName("N") ) return ePdfHighlightingMode_None; else if( value == PdfName("I") ) @@ -373,7 +373,7 @@ PdfString PdfField::GetFieldName() const { if( m_pObject->GetDictionary().HasKey( PdfName("T" ) ) ) - return m_pObject->GetDictionary().GetKey( PdfName("T" ) )->GetString(); + return m_pObject->MustGetIndirectKey( PdfName("T" ) )->GetString(); return PdfString::StringNull; } @@ -386,7 +386,7 @@ PdfString PdfField::GetAlternateName() const { if( m_pObject->GetDictionary().HasKey( PdfName("TU" ) ) ) - return m_pObject->GetDictionary().GetKey( PdfName("TU" ) )->GetString(); + return m_pObject->MustGetIndirectKey( PdfName("TU" ) )->GetString(); return PdfString::StringNull; } @@ -399,7 +399,7 @@ PdfString PdfField::GetMappingName() const { if( m_pObject->GetDictionary().HasKey( PdfName("TM" ) ) ) - return m_pObject->GetDictionary().GetKey( PdfName("TM" ) )->GetString(); + return m_pObject->MustGetIndirectKey( PdfName("TM" ) )->GetString(); return PdfString::StringNull; } @@ -409,7 +409,7 @@ if( !m_pObject->GetDictionary().HasKey( PdfName("AA") ) ) m_pObject->GetDictionary().AddKey( PdfName("AA"), PdfDictionary() ); - PdfObject* pAA = m_pObject->GetDictionary().GetKey( PdfName("AA") ); + PdfObject* pAA = m_pObject->MustGetIndirectKey( PdfName("AA") ); pAA->GetDictionary().AddKey( rsName, rAction.GetObject()->Reference() ); } @@ -451,7 +451,7 @@ PdfObject* pMK = this->GetAppearanceCharacteristics( false ); if( pMK && pMK->GetDictionary().HasKey( PdfName("CA") ) ) - return pMK->GetDictionary().GetKey( PdfName("CA") )->GetString(); + return pMK->MustGetIndirectKey( PdfName("CA") )->GetString(); return PdfString::StringNull; } @@ -545,7 +545,7 @@ PdfObject* pMK = this->GetAppearanceCharacteristics( false ); if( pMK && pMK->GetDictionary().HasKey( PdfName("RC") ) ) - return pMK->GetDictionary().GetKey( PdfName("RC") )->GetString(); + return pMK->MustGetIndirectKey( PdfName("RC") )->GetString(); return PdfString::StringNull; } @@ -562,7 +562,7 @@ PdfObject* pMK = this->GetAppearanceCharacteristics( false ); if( pMK && pMK->GetDictionary().HasKey( PdfName("AC") ) ) - return pMK->GetDictionary().GetKey( PdfName("AC") )->GetString(); + return pMK->MustGetIndirectKey( PdfName("AC") )->GetString(); return PdfString::StringNull; } @@ -649,11 +649,11 @@ if( !m_pObject->GetDictionary().HasKey( PdfName("AP") ) ) m_pObject->GetDictionary().AddKey( PdfName("AP"), PdfDictionary() ); - if( !m_pObject->GetDictionary().GetKey( PdfName("AP") )->GetDictionary().HasKey( PdfName("N") ) ) - m_pObject->GetDictionary().GetKey( PdfName("AP") )->GetDictionary().AddKey( PdfName("N"), PdfDictionary() ); + if( !m_pObject->MustGetIndirectKey( PdfName("AP") )->GetDictionary().HasKey( PdfName("N") ) ) + m_pObject->MustGetIndirectKey( PdfName("AP") )->GetDictionary().AddKey( PdfName("N"), PdfDictionary() ); - m_pObject->GetDictionary().GetKey( PdfName("AP") )-> - GetDictionary().GetKey( PdfName("N") )->GetDictionary().AddKey( rName, rReference ); + m_pObject->MustGetIndirectKey( PdfName("AP") )-> + MustGetIndirectKey( PdfName("N") )->GetDictionary().AddKey( rName, rReference ); } void PdfCheckBox::SetAppearanceChecked( const PdfXObject & rXObject ) @@ -674,13 +674,11 @@ bool PdfCheckBox::IsChecked() const { - PdfDictionary dic = m_pObject->GetDictionary(); - - if (dic.HasKey(PdfName("V"))) { - PdfName name = dic.GetKey( PdfName("V") )->GetName(); + if (m_pObject->GetDictionary().HasKey(PdfName("V"))) { + PdfName name = m_pObject->MustGetIndirectKey( PdfName("V") )->GetName(); return (name == PdfName("Yes") || name == PdfName("On")); - } else if (dic.HasKey(PdfName("AS"))) { - PdfName name = dic.GetKey( PdfName("AS") )->GetName(); + } else if (m_pObject->GetDictionary().HasKey(PdfName("AS"))) { + PdfName name = m_pObject->MustGetIndirectKey( PdfName("AS") )->GetName(); return (name == PdfName("Yes") || name == PdfName("On")); } @@ -746,7 +744,7 @@ PdfString str; if( m_pObject->GetDictionary().HasKey( key ) ) - str = m_pObject->GetDictionary().GetKey( key )->GetString(); + str = m_pObject->MustGetIndirectKey( key )->GetString(); return str; } @@ -759,7 +757,7 @@ pdf_long PdfTextField::GetMaxLen() const { return static_cast<pdf_long>(m_pObject->GetDictionary().HasKey( PdfName("MaxLen") ) ? - m_pObject->GetDictionary().GetKey( PdfName("MaxLen") )->GetNumber() : -1); + m_pObject->MustGetIndirectKey( PdfName("MaxLen") )->GetNumber() : -1); } ///////////////////////////////////////////////////////////////////////////// @@ -796,7 +794,6 @@ void PdfListField::InsertItem( const PdfString & rsValue, const PdfString & rsDisplayName ) { PdfVariant var; - PdfArray opt; if( rsDisplayName == PdfString::StringNull ) var = rsValue; @@ -809,12 +806,13 @@ var = array; } - if( m_pObject->GetDictionary().HasKey( PdfName("Opt") ) ) - opt = m_pObject->GetDictionary().GetKey( PdfName("Opt") )->GetArray(); + if( !m_pObject->GetDictionary().HasKey( PdfName("Opt") ) ) + m_pObject->GetDictionary().AddKey( PdfName("Opt"), PdfArray() ); + PdfArray &opt = m_pObject->MustGetIndirectKey( PdfName("Opt") )->GetArray(); + // TODO: Sorting opt.push_back( var ); - m_pObject->GetDictionary().AddKey( PdfName("Opt"), opt ); /* m_pObject->GetDictionary().AddKey( PdfName("V"), rsValue ); @@ -827,10 +825,10 @@ void PdfListField::RemoveItem( int nIndex ) { - PdfArray opt; + if( !m_pObject->GetDictionary().HasKey( PdfName("Opt") ) ) + m_pObject->GetDictionary().AddKey( PdfName("Opt"), PdfArray() ); - if( m_pObject->GetDictionary().HasKey( PdfName("Opt") ) ) - opt = m_pObject->GetDictionary().GetKey( PdfName("Opt") )->GetArray(); + PdfArray &opt = m_pObject->MustGetIndirectKey( PdfName("Opt") )->GetArray(); if( nIndex < 0 || nIndex > static_cast<int>(opt.size()) ) { @@ -838,7 +836,6 @@ } opt.erase( opt.begin() + nIndex ); - m_pObject->GetDictionary().AddKey( PdfName("Opt"), opt ); } const PdfString PdfListField::GetItem( int nIndex ) const @@ -846,7 +843,7 @@ PdfArray opt; if( m_pObject->GetDictionary().HasKey( PdfName("Opt") ) ) - opt = m_pObject->GetDictionary().GetKey( PdfName("Opt") )->GetArray(); + opt = m_pObject->MustGetIndirectKey( PdfName("Opt") )->GetArray(); if( nIndex < 0 || nIndex > static_cast<int>(opt.size()) ) { @@ -872,7 +869,7 @@ PdfArray opt; if( m_pObject->GetDictionary().HasKey( PdfName("Opt") ) ) - opt = m_pObject->GetDictionary().GetKey( PdfName("Opt") )->GetArray(); + opt = m_pObject->MustGetIndirectKey( PdfName("Opt") )->GetArray(); if( nIndex < 0 || nIndex >= static_cast<int>(opt.size()) ) { @@ -898,7 +895,7 @@ PdfArray opt; if( m_pObject->GetDictionary().HasKey( PdfName("Opt") ) ) - opt = m_pObject->GetDictionary().GetKey( PdfName("Opt") )->GetArray(); + opt = m_pObject->MustGetIndirectKey( PdfName("Opt") )->GetArray(); return opt.size(); } @@ -914,7 +911,7 @@ { if( m_pObject->GetDictionary().HasKey( PdfName("V") ) ) { - PdfObject* pValue = m_pObject->GetDictionary().GetKey( PdfName("V") ); + PdfObject* pValue = m_pObject->MustGetIndirectKey( PdfName("V") ); if( pValue->IsString() || pValue->IsHexString() ) { PdfString value = pValue->GetString(); Modified: podofo/trunk/src/podofo/doc/PdfFileSpec.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfFileSpec.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfFileSpec.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -335,12 +335,12 @@ { if( canUnicode && this->GetObject()->GetDictionary().HasKey( "UF" ) ) { - return this->GetObject()->GetDictionary().GetKey( "UF" )->GetString(); + return this->GetObject()->MustGetIndirectKey( "UF" )->GetString(); } if( this->GetObject()->GetDictionary().HasKey( "F" ) ) { - return this->GetObject()->GetDictionary().GetKey( "F" )->GetString(); + return this->GetObject()->MustGetIndirectKey( "F" )->GetString(); } PODOFO_RAISE_ERROR( ePdfError_InvalidDataType ); Modified: podofo/trunk/src/podofo/doc/PdfFontFactory.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfFontFactory.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfFontFactory.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -192,7 +192,7 @@ PdfObject* pDescriptor = NULL; PdfObject* pEncoding = NULL; - PdfVariant* pTypeKey = pObject->GetDictionary().GetKey( PdfName::KeyType ); + PdfVariant* pTypeKey = pObject->GetIndirectKey( PdfName::KeyType ); if ( NULL == pTypeKey ) { PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidDataType, "Font: No Type" ); @@ -203,8 +203,7 @@ PODOFO_RAISE_ERROR( ePdfError_InvalidDataType ); } - PdfVariant* pSubTypeKey = pObject->GetDictionary() - .GetKey( PdfName::KeySubtype ); + PdfVariant* pSubTypeKey = pObject->GetIndirectKey( PdfName::KeySubtype ); if ( NULL == pSubTypeKey ) { PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidDataType, "Font: No SubType" ); @@ -307,7 +306,7 @@ // Its extremely complicated to interpret the type1 font programs // so i try to determine if its a symbolic font by reading the FontDescriptor Flags // Flags & 4 --> Symbolic, Flags & 32 --> Nonsymbolic - pdf_int32 lFlags = static_cast<pdf_int32>(pDescriptor->GetDictionary().GetKeyAsLong( "Flags", 0L )); + pdf_int32 lFlags = static_cast<pdf_int32>(pDescriptor->GetIndirectKeyAsLong( "Flags", 0L )); if ( lFlags & 32 ) // Nonsymbolic, otherwise pEncoding remains NULL pPdfEncoding = PdfEncodingFactory::GlobalStandardEncodingInstance(); } Modified: podofo/trunk/src/podofo/doc/PdfFontMetricsObject.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfFontMetricsObject.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfFontMetricsObject.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -48,27 +48,27 @@ { m_missingWidth = NULL; - const PdfName & rSubType = pFont->GetDictionary().GetKey( PdfName::KeySubtype )->GetName(); + const PdfName & rSubType = pFont->MustGetIndirectKey( PdfName::KeySubtype )->GetName(); // OC 15.08.2010 BugFix: /FirstChar /LastChar /Widths are in the Font dictionary and not in the FontDescriptor if ( rSubType == PdfName("Type1") || rSubType == PdfName("Type3") || rSubType == PdfName("TrueType") ) { if ( pDescriptor ) { if (pDescriptor->GetDictionary().HasKey( "FontName" )) - m_sName = pDescriptor->GetIndirectKey( "FontName" )->GetName(); + m_sName = pDescriptor->MustGetIndirectKey( "FontName" )->GetName(); if (pDescriptor->GetDictionary().HasKey( "FontBBox" )) - m_bbox = pDescriptor->GetIndirectKey( "FontBBox" )->GetArray(); + m_bbox = pDescriptor->MustGetIndirectKey( "FontBBox" )->GetArray(); } else { if (pFont->GetDictionary().HasKey( "Name" )) - m_sName = pFont->GetIndirectKey( "Name" )->GetName(); + m_sName = pFont->MustGetIndirectKey( "Name" )->GetName(); if (pFont->GetDictionary().HasKey( "FontBBox" )) - m_bbox = pFont->GetIndirectKey( "FontBBox" )->GetArray(); + m_bbox = pFont->MustGetIndirectKey( "FontBBox" )->GetArray(); } if (pFont->GetDictionary().HasKey( "FontMatrix" )) { // Type3 fonts have a custom FontMatrix - m_matrix = pFont->GetIndirectKey( "FontMatrix" )->GetArray(); + m_matrix = pFont->MustGetIndirectKey( "FontMatrix" )->GetArray(); } - m_nFirst = static_cast<int>(pFont->GetDictionary().GetKeyAsLong( "FirstChar", 0L )); - m_nLast = static_cast<int>(pFont->GetDictionary().GetKeyAsLong( "LastChar", 0L )); + m_nFirst = static_cast<int>(pFont->GetIndirectKeyAsLong( "FirstChar", 0L )); + m_nLast = static_cast<int>(pFont->GetIndirectKeyAsLong( "LastChar", 0L )); // OC 15.08.2010 BugFix: GetIndirectKey() instead of GetDictionary().GetKey() and "Widths" instead of "Width" PdfObject* widths = pFont->GetIndirectKey( "Widths" ); @@ -80,9 +80,9 @@ else { if ( pDescriptor ) { - widths = pDescriptor->GetDictionary().GetKey( "MissingWidth" ); + widths = pDescriptor->GetIndirectKey( "MissingWidth" ); } else { - widths = pFont->GetDictionary().GetKey( "MissingWidth" ); + widths = pFont->GetIndirectKey( "MissingWidth" ); } if( widths == NULL ) { @@ -102,7 +102,7 @@ m_nFirst = 0; m_nLast = 0; - m_dDefWidth = static_cast<double>(pFont->GetDictionary().GetKeyAsLong( "DW", 1000L )); + m_dDefWidth = static_cast<double>(pFont->GetIndirectKeyAsLong( "DW", 1000L )); PdfVariant default_width(m_dDefWidth); PdfObject * pw = pFont->GetIndirectKey( "W" ); @@ -153,10 +153,10 @@ } if ( pDescriptor ) { - m_nWeight = static_cast<unsigned int>(pDescriptor->GetDictionary().GetKeyAsLong( "FontWeight", 400L )); - m_nItalicAngle = static_cast<int>(pDescriptor->GetDictionary().GetKeyAsLong( "ItalicAngle", 0L )); - m_dPdfAscent = pDescriptor->GetDictionary().GetKeyAsReal( "Ascent", 0.0 ); - m_dPdfDescent = pDescriptor->GetDictionary().GetKeyAsReal( "Descent", 0.0 ); + m_nWeight = static_cast<unsigned int>(pDescriptor->GetIndirectKeyAsLong( "FontWeight", 400L )); + m_nItalicAngle = static_cast<int>(pDescriptor->GetIndirectKeyAsLong( "ItalicAngle", 0L )); + m_dPdfAscent = pDescriptor->GetIndirectKeyAsReal( "Ascent", 0.0 ); + m_dPdfDescent = pDescriptor->GetIndirectKeyAsReal( "Descent", 0.0 ); } else { m_nWeight = 400L; m_nItalicAngle = 0L; Modified: podofo/trunk/src/podofo/doc/PdfImage.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfImage.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfImage.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -81,8 +81,8 @@ PdfImage::PdfImage( PdfObject* pObject ) : PdfXObject( "Image", pObject ) { - m_rRect.SetHeight( static_cast<double>(this->GetObject()->GetDictionary().GetKey( "Height" )->GetNumber()) ); - m_rRect.SetWidth ( static_cast<double>(this->GetObject()->GetDictionary().GetKey( "Width" )->GetNumber()) ); + m_rRect.SetHeight( static_cast<double>(this->GetObject()->MustGetIndirectKey( "Height" )->GetNumber()) ); + m_rRect.SetWidth ( static_cast<double>(this->GetObject()->MustGetIndirectKey( "Width" )->GetNumber()) ); } PdfImage::~PdfImage() Modified: podofo/trunk/src/podofo/doc/PdfInfo.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfInfo.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfInfo.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -84,7 +84,7 @@ const PdfString & PdfInfo::GetStringFromInfoDict( const PdfName & rName ) const { - const PdfObject* pObj = this->GetObject()->GetDictionary().GetKey( rName ); + const PdfObject* pObj = this->GetObject()->GetIndirectKey( rName ); return pObj && (pObj->IsString() || pObj->IsHexString()) ? pObj->GetString() : PdfString::StringNull; } @@ -91,7 +91,7 @@ const PdfName & PdfInfo::GetNameFromInfoDict(const PdfName & rName) const { - const PdfObject* pObj = this->GetObject()->GetDictionary().GetKey( rName ); + const PdfObject* pObj = this->GetObject()->GetIndirectKey( rName ); return pObj && pObj->IsName() ? pObj->GetName() : PdfName::KeyNull; } Modified: podofo/trunk/src/podofo/doc/PdfNamesTree.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfNamesTree.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfNamesTree.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -78,7 +78,7 @@ { if( m_bHasKids ) { - const PdfArray & kids = this->GetObject()->GetDictionary().GetKey("Kids")->GetArray(); + const PdfArray & kids = this->GetObject()->MustGetIndirectKey("Kids")->GetArray(); PdfArray::const_iterator it = kids.begin(); PdfObject* pChild = NULL; EPdfNameLimits eLimits = ePdfNameLimits_Before; // RG: TODO Compiler complains that this variable should be initialised @@ -135,7 +135,7 @@ if( this->GetObject()->GetDictionary().HasKey( "Names" ) ) { - PdfArray& array = this->GetObject()->GetDictionary().GetKey("Names")->GetArray(); + PdfArray& array = this->GetObject()->MustGetIndirectKey("Names")->GetArray(); PdfArray::iterator it = array.begin(); while( it != array.end() ) @@ -208,19 +208,19 @@ if( m_bHasKids ) { if( this->GetObject()->GetDictionary().HasKey( PdfName("Kids") ) && - this->GetObject()->GetDictionary().GetKey( PdfName("Kids") )->IsArray() ) + this->GetObject()->MustGetIndirectKey( PdfName("Kids") )->IsArray() ) { - const PdfReference & rRefFirst = (*this->GetObject()->GetDictionary().GetKey("Kids")->GetArray().begin()).GetReference(); + const PdfReference & rRefFirst = (*this->GetObject()->MustGetIndirectKey("Kids")->GetArray().begin()).GetReference(); PdfObject* pChild = this->GetObject()->GetOwner()->GetObject( rRefFirst ); if( pChild && pChild->GetDictionary().HasKey( PdfName("Limits") ) && - pChild->GetDictionary().GetKey( PdfName("Limits") )->IsArray() ) - limits.push_back( *(pChild->GetDictionary().GetKey("Limits")->GetArray().begin()) ); + pChild->MustGetIndirectKey( PdfName("Limits") )->IsArray() ) + limits.push_back( *(pChild->MustGetIndirectKey("Limits")->GetArray().begin()) ); - const PdfReference & rRefLast = this->GetObject()->GetDictionary().GetKey("Kids")->GetArray().back().GetReference(); + const PdfReference & rRefLast = this->GetObject()->MustGetIndirectKey("Kids")->GetArray().back().GetReference(); pChild = this->GetObject()->GetOwner()->GetObject( rRefLast ); if( pChild && pChild->GetDictionary().HasKey( PdfName("Limits") ) && - pChild->GetDictionary().GetKey( PdfName("Limits") )->IsArray() ) - limits.push_back( pChild->GetDictionary().GetKey("Limits")->GetArray().back() ); + pChild->MustGetIndirectKey( PdfName("Limits") )->IsArray() ) + limits.push_back( pChild->MustGetIndirectKey("Limits")->GetArray().back() ); } else PdfError::LogMessage( eLogSeverity_Error, @@ -231,10 +231,10 @@ else // has "Names" { if( this->GetObject()->GetDictionary().HasKey( PdfName("Names") ) && - this->GetObject()->GetDictionary().GetKey( PdfName("Names") )->IsArray() ) + this->GetObject()->MustGetIndirectKey( PdfName("Names") )->IsArray() ) { - limits.push_back( (*this->GetObject()->GetDictionary().GetKey("Names")->GetArray().begin()) ); - limits.push_back( (*(this->GetObject()->GetDictionary().GetKey("Names")->GetArray().end()-2)) ); + limits.push_back( (*this->GetObject()->MustGetIndirectKey("Names")->GetArray().begin()) ); + limits.push_back( (*(this->GetObject()->MustGetIndirectKey("Names")->GetArray().end()-2)) ); } else PdfError::LogMessage( eLogSeverity_Error, @@ -252,8 +252,8 @@ bool PdfNameTreeNode::Rebalance() { - PdfArray* pArray = m_bHasKids ? &(this->GetObject()->GetDictionary().GetKey("Kids")->GetArray()) : - &(this->GetObject()->GetDictionary().GetKey("Names")->GetArray()); + PdfArray* pArray = m_bHasKids ? &(this->GetObject()->MustGetIndirectKey("Kids")->GetArray()) : + &(this->GetObject()->MustGetIndirectKey("Names")->GetArray()); const PdfName& key = m_bHasKids ? PdfName("Kids") : PdfName("Names"); const unsigned int nLength = m_bHasKids ? BALANCE_TREE_MAX : BALANCE_TREE_MAX * 2; @@ -281,7 +281,7 @@ else { pChild1 = this->GetObject(); - kids = m_pParent->GetObject()->GetDictionary().GetKey("Kids")->GetArray(); + kids = m_pParent->GetObject()->MustGetIndirectKey("Kids")->GetArray(); } pChild1->GetDictionary().AddKey( key, first ); @@ -377,7 +377,7 @@ if( pObj->GetDictionary().HasKey("Kids") ) { - const PdfArray & kids = pObj->GetDictionary().GetKey("Kids")->GetArray(); + const PdfArray & kids = pObj->MustGetIndirectKey("Kids")->GetArray(); PdfArray::const_iterator it = kids.begin(); while( it != kids.end() ) @@ -401,7 +401,7 @@ } else { - PdfArray & names = pObj->GetDictionary().GetKey("Names")->GetArray(); + PdfArray & names = pObj->MustGetIndirectKey("Names")->GetArray(); PdfArray::iterator it = names.begin(); // a names array is a set of PdfString/PdfObject pairs @@ -446,7 +446,7 @@ { if( pObj->GetDictionary().HasKey("Limits") ) { - const PdfArray & limits = pObj->GetDictionary().GetKey("Limits")->GetArray(); + const PdfArray & limits = pObj->MustGetIndirectKey("Limits")->GetArray(); if( limits[0].GetString() > key ) return ePdfNameLimits_Before; @@ -476,7 +476,7 @@ { if( pObj->GetDictionary().HasKey("Kids") ) { - const PdfArray & kids = pObj->GetDictionary().GetKey("Kids")->GetArray(); + const PdfArray & kids = pObj->MustGetIndirectKey("Kids")->GetArray(); PdfArray::const_iterator it = kids.begin(); while( it != kids.end() ) @@ -494,7 +494,7 @@ } else if( pObj->GetDictionary().HasKey("Names") ) { - const PdfArray & names = pObj->GetDictionary().GetKey("Names")->GetArray(); + const PdfArray & names = pObj->MustGetIndirectKey("Names")->GetArray(); PdfArray::const_iterator it = names.begin(); // a names array is a set of PdfString/PdfObject pairs Modified: podofo/trunk/src/podofo/doc/PdfPage.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfPage.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfPage.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -225,7 +225,7 @@ // check for it in the object itself if ( inObject->GetDictionary().HasKey( inKey ) ) { - pObj = inObject->GetDictionary().GetKey( inKey ); + pObj = inObject->MustGetIndirectKey( inKey ); if ( !pObj->IsNull() ) return pObj; } @@ -269,13 +269,6 @@ // Take advantage of inherited values - walking up the tree if necessary pObj = GetInheritedKeyFromObject( inBox, this->GetObject() ); - - // Sometime page boxes are defined using reference objects - while ( pObj && pObj->IsReference() ) - { - pObj = this->GetObject()->GetOwner()->GetObject( pObj->GetReference() ); - } - // assign the value of the box from the array if ( pObj && pObj->IsArray() ) { @@ -611,8 +604,8 @@ PODOFO_RAISE_ERROR_INFO( ePdfError_NoObject, oss.str() ); } - if( pNode->GetDictionary().GetKey( PdfName::KeyType ) != NULL - && pNode->GetDictionary().GetKey( PdfName::KeyType )->GetName() == PdfName( "Pages" ) ) + if( pNode->GetDictionary().HasKey( PdfName::KeyType ) + && pNode->MustGetIndirectKey( PdfName::KeyType )->GetName() == PdfName( "Pages" ) ) { PdfObject* pCount = pNode->GetIndirectKey( "Count" ); if( pCount != NULL ) { Modified: podofo/trunk/src/podofo/doc/PdfPagesTree.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfPagesTree.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfPagesTree.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -440,7 +440,7 @@ if( !pObject ) return false; - if( pObject->GetDictionary().GetKeyAsName( PdfName( "Type" ) ) == PdfName( "Page" ) ) + if( pObject->GetIndirectKeyAsName( PdfName( "Type" ) ) == PdfName( "Page" ) ) return true; return false; @@ -451,7 +451,7 @@ if( !pObject ) return false; - if( pObject->GetDictionary().GetKeyAsName( PdfName( "Type" ) ) == PdfName( "Pages" ) ) + if( pObject->GetIndirectKeyAsName( PdfName( "Type" ) ) == PdfName( "Pages" ) ) return true; return false; @@ -479,7 +479,7 @@ return -1; } - const PdfArray & rKids = pPageParent->GetDictionary().GetKey( PdfName("Kids") )->GetArray(); + const PdfArray & rKids = pPageParent->MustGetIndirectKey( PdfName("Kids") )->GetArray(); PdfArray::const_iterator it = rKids.begin(); int index = 0; @@ -513,7 +513,7 @@ // 3. Add Parent key to the page // 1. Add reference - const PdfArray oldKids = pParent->GetDictionary().GetKey( PdfName("Kids") )->GetArray(); + const PdfArray oldKids = pParent->MustGetIndirectKey( PdfName("Kids") )->GetArray(); PdfArray::const_iterator it = oldKids.begin(); PdfArray newKids; @@ -571,7 +571,7 @@ // 3. Add Parent key to the page // 1. Add reference - const PdfArray oldKids = pParent->GetDictionary().GetKey( PdfName("Kids") )->GetArray(); + const PdfArray oldKids = pParent->MustGetIndirectKey( PdfName("Kids") )->GetArray(); PdfArray newKids; newKids.reserve( oldKids.GetSize() + vecPages.size() ); @@ -663,7 +663,7 @@ void PdfPagesTree::DeletePageNode( PdfObject* pParent, int nIndex ) { - PdfArray kids = pParent->GetDictionary().GetKey( PdfName("Kids") )->GetArray(); + PdfArray kids = pParent->MustGetIndirectKey( PdfName("Kids") )->GetArray(); kids.erase( kids.begin() + nIndex ); pParent->GetDictionary().AddKey( PdfName("Kids"), kids ); } @@ -689,7 +689,7 @@ if( pPageNode->GetDictionary().HasKey( PdfName("Kids") ) ) { - bKidsEmpty = pPageNode->GetDictionary().GetKey( PdfName("Kids") )->GetArray().empty(); + bKidsEmpty = pPageNode->MustGetIndirectKey( PdfName("Kids") )->GetArray().empty(); } return ( lCount == 0L || bKidsEmpty ); Modified: podofo/trunk/src/podofo/doc/PdfPainter.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfPainter.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfPainter.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -1246,7 +1246,7 @@ PODOFO_ASSERT( pEncoding != NULL ); // paranoia PdfArray diffs; - diffs = pEncoding->GetDictionary().GetKey( "Differences" )->GetArray(); + diffs = pEncoding->MustGetIndirectKey( "Differences" )->GetArray(); bool foundIt = false; @@ -1284,13 +1284,13 @@ code++; PdfArray diffs; - diffs = pEncoding->GetDictionary().GetKey( "Differences" )->GetArray(); + diffs = pEncoding->MustGetIndirectKey( "Differences" )->GetArray(); diffs.push_back( PdfName( pszGlyphname ) ); pEncoding->GetDictionary().AddKey( "Differences", diffs ); // enter width of glyph - PdfObject* pWidthObj = pGlyphFontObj->GetIndirectKey( "Widths" ); + PdfObject* pWidthObj = pGlyphFontObj->MustGetIndirectKey( "Widths" ); PdfArray & rWidthArr = pWidthObj->GetArray(); rWidthArr[code] = PdfVariant( static_cast<pdf_int64>( width ) ); Modified: podofo/trunk/src/podofo/doc/PdfSignatureField.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfSignatureField.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfSignatureField.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -65,7 +65,7 @@ // do not call Init() here if( this->GetFieldObject()->GetDictionary().HasKey( "V" ) ) { - m_pSignatureObj = this->GetFieldObject()->GetOwner()->GetObject( this->GetFieldObject()->GetDictionary().GetKey( "V" )->GetReference() ); + m_pSignatureObj = GetFieldObject()->GetIndirectKey( "V" ); } } Modified: podofo/trunk/src/podofo/doc/PdfXObject.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfXObject.cpp 2020-03-27 17:12:40 UTC (rev 2004) +++ podofo/trunk/src/podofo/doc/PdfXObject.cpp 2020-03-27 17:24:54 UTC (rev 2005) @@ -347,7 +347,7 @@ ostringstream out; PdfLocaleImbue(out); - if( this->GetObject()->GetDictionary().GetKeyAsName( PdfName::KeySubtype ) != pszSubType ) + if( this->GetObject()->GetIndirectKeyAsName( PdfName::KeySubtype ) != pszSubType ) { PODOFO_RAISE_ERROR( ePdfError_InvalidDataType ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-03-27 17:12:42
|
Revision: 2004 http://sourceforge.net/p/podofo/code/2004 Author: mc-zyx Date: 2020-03-27 17:12:40 +0000 (Fri, 27 Mar 2020) Log Message: ----------- Patch by Michal Sudolsky: Change GetObject to MustGetObject on some places, to avoid NULL dereference Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfVecObjects.cpp podofo/trunk/src/podofo/base/PdfVecObjects.h podofo/trunk/src/podofo/base/PdfWriter.cpp podofo/trunk/src/podofo/doc/PdfContents.cpp podofo/trunk/src/podofo/doc/PdfDocument.cpp podofo/trunk/src/podofo/doc/PdfEncodingObjectFactory.cpp podofo/trunk/src/podofo/doc/PdfFontMetricsObject.cpp podofo/trunk/src/podofo/doc/PdfOutlines.cpp Modified: podofo/trunk/src/podofo/base/PdfVecObjects.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfVecObjects.cpp 2020-03-27 17:04:29 UTC (rev 2003) +++ podofo/trunk/src/podofo/base/PdfVecObjects.cpp 2020-03-27 17:12:40 UTC (rev 2004) @@ -162,6 +162,14 @@ return NULL; } +PdfObject* PdfVecObjects::MustGetObject( const PdfReference & ref ) const +{ + PdfObject* obj = GetObject( ref ); + if (!obj) + PODOFO_RAISE_ERROR( ePdfError_NoObject ); + return obj; +} + size_t PdfVecObjects::GetIndex( const PdfReference & ref ) const { if( !m_bSorted ) Modified: podofo/trunk/src/podofo/base/PdfVecObjects.h =================================================================== --- podofo/trunk/src/podofo/base/PdfVecObjects.h 2020-03-27 17:04:29 UTC (rev 2003) +++ podofo/trunk/src/podofo/base/PdfVecObjects.h 2020-03-27 17:12:40 UTC (rev 2004) @@ -228,6 +228,15 @@ PdfObject* GetObject( const PdfReference & ref ) const; /** Finds the object with the given reference in m_vecOffsets + * and returns a pointer to it if it is found. Throws a PdfError + * exception with error code ePdfError_NoObject if no object was found + * \param ref the object to be found + * \returns the found object + * \throws PdfError(ePdfError_NoObject) + */ + PdfObject* MustGetObject( const PdfReference & ref ) const; + + /** Finds the object with the given reference in m_vecOffsets * and returns the index to it. * \param ref the object to be found * \returns the found object or NULL if no object was found. Modified: podofo/trunk/src/podofo/base/PdfWriter.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfWriter.cpp 2020-03-27 17:04:29 UTC (rev 2003) +++ podofo/trunk/src/podofo/base/PdfWriter.cpp 2020-03-27 17:12:40 UTC (rev 2004) @@ -690,7 +690,7 @@ // indirect as long as the PDF is not encrypted. Handle that // case. if ( idObj->IsReference() ) { - idObj = m_vecObjects->GetObject( idObj->GetReference() ); + idObj = m_vecObjects->MustGetObject( idObj->GetReference() ); } TCIVariantList it = idObj->GetArray().begin(); Modified: podofo/trunk/src/podofo/doc/PdfContents.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfContents.cpp 2020-03-27 17:04:29 UTC (rev 2003) +++ podofo/trunk/src/podofo/doc/PdfContents.cpp 2020-03-27 17:12:40 UTC (rev 2004) @@ -67,7 +67,7 @@ : PdfElement( inObj->GetDataType(), inObj ) { if ( this->GetObject()->GetDataType() == ePdfDataType_Reference ) - mContObj = inObj->GetOwner()->GetObject( this->GetObject()->GetReference() ); + mContObj = inObj->GetOwner()->MustGetObject( this->GetObject()->GetReference() ); else mContObj = this->GetObject(); } Modified: podofo/trunk/src/podofo/doc/PdfDocument.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfDocument.cpp 2020-03-27 17:04:29 UTC (rev 2003) +++ podofo/trunk/src/podofo/doc/PdfDocument.cpp 2020-03-27 17:12:40 UTC (rev 2004) @@ -331,7 +331,7 @@ oss << "No page " << i << " (the first is 0) found."; PODOFO_RAISE_ERROR_INFO( ePdfError_PageNotFound, oss.str() ); } - PdfObject* pObj = m_vecObjects.GetObject( PdfReference( pPage->GetObject()->Reference().ObjectNumber() + difference, pPage->GetObject()->Reference().GenerationNumber() ) ); + PdfObject* pObj = m_vecObjects.MustGetObject( PdfReference( pPage->GetObject()->Reference().ObjectNumber() + difference, pPage->GetObject()->Reference().GenerationNumber() ) ); if( pObj->IsDictionary() && pObj->GetDictionary().HasKey( "Parent" ) ) pObj->GetDictionary().RemoveKey( "Parent" ); @@ -363,7 +363,7 @@ pRoot = pRoot->Next(); PdfReference ref( pAppendRoot->First()->GetObject()->Reference().ObjectNumber() + difference, pAppendRoot->First()->GetObject()->Reference().GenerationNumber() ); - pRoot->InsertChild( new PdfOutlines( m_vecObjects.GetObject( ref ) ) ); + pRoot->InsertChild( new PdfOutlines( m_vecObjects.MustGetObject( ref ) ) ); } } @@ -426,7 +426,7 @@ } PdfPage* pPage = rDoc.GetPage( i ); - PdfObject* pObj = m_vecObjects.GetObject( PdfReference( pPage->GetObject()->Reference().ObjectNumber() + difference, pPage->GetObject()->Reference().GenerationNumber() ) ); + PdfObject* pObj = m_vecObjects.MustGetObject( PdfReference( pPage->GetObject()->Reference().ObjectNumber() + difference, pPage->GetObject()->Reference().GenerationNumber() ) ); if( pObj->IsDictionary() && pObj->GetDictionary().HasKey( "Parent" ) ) pObj->GetDictionary().RemoveKey( "Parent" ); @@ -458,7 +458,7 @@ pRoot = pRoot->Next(); PdfReference ref( pAppendRoot->First()->GetObject()->Reference().ObjectNumber() + difference, pAppendRoot->First()->GetObject()->Reference().GenerationNumber() ); - pRoot->InsertChild( new PdfOutlines( m_vecObjects.GetObject( ref ) ) ); + pRoot->InsertChild( new PdfOutlines( m_vecObjects.MustGetObject( ref ) ) ); } // TODO: merge name trees @@ -486,7 +486,7 @@ { // TODO: remove unused objects: page, ... - PdfObject* pObj = m_vecObjects.GetObject( PdfReference( pPage->GetObject()->Reference().ObjectNumber() + difference, pPage->GetObject()->Reference().GenerationNumber() ) ); + PdfObject* pObj = m_vecObjects.MustGetObject( PdfReference( pPage->GetObject()->Reference().ObjectNumber() + difference, pPage->GetObject()->Reference().GenerationNumber() ) ); PdfRect box = pPage->GetMediaBox(); // intersect with crop-box Modified: podofo/trunk/src/podofo/doc/PdfEncodingObjectFactory.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfEncodingObjectFactory.cpp 2020-03-27 17:04:29 UTC (rev 2003) +++ podofo/trunk/src/podofo/doc/PdfEncodingObjectFactory.cpp 2020-03-27 17:12:40 UTC (rev 2004) @@ -56,7 +56,7 @@ if (pObject->IsReference ()) { // resolve any references - pObject = pObject->GetOwner ()->GetObject (pObject->GetReference ()); + pObject = pObject->GetOwner ()->MustGetObject (pObject->GetReference ()); } if (pObject->IsName ()) Modified: podofo/trunk/src/podofo/doc/PdfFontMetricsObject.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfFontMetricsObject.cpp 2020-03-27 17:04:29 UTC (rev 2003) +++ podofo/trunk/src/podofo/doc/PdfFontMetricsObject.cpp 2020-03-27 17:12:40 UTC (rev 2004) @@ -120,7 +120,7 @@ // Make sure array referenced is available: second->DelayedStreamLoad(); // second do not have an associated owner; use the one in pw - second = pw->GetOwner()->GetObject(second->GetReference()); + second = pw->GetOwner()->MustGetObject(second->GetReference()); PODOFO_ASSERT (!second->IsNull()); } if (second->IsArray()) { Modified: podofo/trunk/src/podofo/doc/PdfOutlines.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfOutlines.cpp 2020-03-27 17:04:29 UTC (rev 2003) +++ podofo/trunk/src/podofo/doc/PdfOutlines.cpp 2020-03-27 17:12:40 UTC (rev 2004) @@ -79,13 +79,13 @@ if( this->GetObject()->GetDictionary().HasKey( "First" ) ) { first = this->GetObject()->GetDictionary().GetKey("First")->GetReference(); - m_pFirst = new PdfOutlineItem( pObject->GetOwner()->GetObject( first ), this, NULL ); + m_pFirst = new PdfOutlineItem( pObject->GetOwner()->MustGetObject( first ), this, NULL ); } if( this->GetObject()->GetDictionary().HasKey( "Next" ) ) { next = this->GetObject()->GetDictionary().GetKey("Next")->GetReference(); - PdfObject* pObj = pObject->GetOwner()->GetObject( next ); + PdfObject* pObj = pObject->GetOwner()->MustGetObject( next ); m_pNext = new PdfOutlineItem( pObj, pParentOutline, this ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-03-27 17:04:32
|
Revision: 2003 http://sourceforge.net/p/podofo/code/2003 Author: mc-zyx Date: 2020-03-27 17:04:29 +0000 (Fri, 27 Mar 2020) Log Message: ----------- Patch by Michal Sudolsky: Change GetIndirectKey to MustGetIndirectKey on some places, to avoid NULL dereference Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfMemStream.cpp podofo/trunk/src/podofo/doc/PdfAction.cpp podofo/trunk/src/podofo/doc/PdfDifferenceEncoding.cpp podofo/trunk/src/podofo/doc/PdfDocument.cpp podofo/trunk/src/podofo/doc/PdfOutlines.cpp podofo/trunk/src/podofo/doc/PdfPainter.cpp Modified: podofo/trunk/src/podofo/base/PdfMemStream.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfMemStream.cpp 2020-03-27 17:00:57 UTC (rev 2002) +++ podofo/trunk/src/podofo/base/PdfMemStream.cpp 2020-03-27 17:04:29 UTC (rev 2003) @@ -153,7 +153,7 @@ // TODO: Handle DecodeParms if( m_pParent->GetDictionary().HasKey( "Filter" ) ) { - pObj = m_pParent->GetIndirectKey( "Filter" ); + pObj = m_pParent->MustGetIndirectKey( "Filter" ); if( pObj->IsName() ) { Modified: podofo/trunk/src/podofo/doc/PdfAction.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfAction.cpp 2020-03-27 17:00:57 UTC (rev 2002) +++ podofo/trunk/src/podofo/doc/PdfAction.cpp 2020-03-27 17:04:29 UTC (rev 2003) @@ -107,7 +107,7 @@ PdfString PdfAction::GetURI() const { - return this->GetObject()->GetIndirectKey( "URI" )->GetString(); + return this->GetObject()->MustGetIndirectKey( "URI" )->GetString(); } bool PdfAction::HasURI() const Modified: podofo/trunk/src/podofo/doc/PdfDifferenceEncoding.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfDifferenceEncoding.cpp 2020-03-27 17:00:57 UTC (rev 2002) +++ podofo/trunk/src/podofo/doc/PdfDifferenceEncoding.cpp 2020-03-27 17:04:29 UTC (rev 2003) @@ -2401,7 +2401,7 @@ // Read the differences key if( this->GetObject()->GetDictionary().HasKey( PdfName("Differences") ) ) { - const PdfArray & rDifferences = this->GetObject()->GetIndirectKey( PdfName("Differences") )->GetArray(); + const PdfArray & rDifferences = this->GetObject()->MustGetIndirectKey( PdfName("Differences") )->GetArray(); PdfArray::const_iterator it = rDifferences.begin(); pdf_int64 curCode = -1; Modified: podofo/trunk/src/podofo/doc/PdfDocument.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfDocument.cpp 2020-03-27 17:00:57 UTC (rev 2002) +++ podofo/trunk/src/podofo/doc/PdfDocument.cpp 2020-03-27 17:04:29 UTC (rev 2003) @@ -714,7 +714,7 @@ // if current mode is anything but "don't care", we need to move that to non-full-screen if ( curMode != ePdfPageModeDontCare ) - SetViewerPreference( PdfName( "NonFullScreenPageMode" ), PdfObject( *(GetCatalog()->GetIndirectKey( PdfName( "PageMode" ) )) ) ); + SetViewerPreference( PdfName( "NonFullScreenPageMode" ), PdfObject( *(GetCatalog()->MustGetIndirectKey( PdfName( "PageMode" ) )) ) ); SetPageMode( ePdfPageModeFullScreen ); } Modified: podofo/trunk/src/podofo/doc/PdfOutlines.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfOutlines.cpp 2020-03-27 17:00:57 UTC (rev 2002) +++ podofo/trunk/src/podofo/doc/PdfOutlines.cpp 2020-03-27 17:04:29 UTC (rev 2003) @@ -335,7 +335,7 @@ const PdfString & PdfOutlineItem::GetTitle() const { - return this->GetObject()->GetIndirectKey( "Title" )->GetString(); + return this->GetObject()->MustGetIndirectKey( "Title" )->GetString(); } void PdfOutlineItem::SetTextFormat( EPdfOutlineFormat eFormat ) @@ -346,7 +346,7 @@ EPdfOutlineFormat PdfOutlineItem::GetTextFormat() const { if( this->GetObject()->GetDictionary().HasKey( "F" ) ) - return static_cast<EPdfOutlineFormat>(this->GetObject()->GetIndirectKey( "F" )->GetNumber()); + return static_cast<EPdfOutlineFormat>(this->GetObject()->MustGetIndirectKey( "F" )->GetNumber()); return ePdfOutlineFormat_Default; } @@ -365,7 +365,7 @@ double PdfOutlineItem::GetTextColorRed() const { if( this->GetObject()->GetDictionary().HasKey( "C" ) ) - return this->GetObject()->GetIndirectKey( "C" )->GetArray()[0].GetReal(); + return this->GetObject()->MustGetIndirectKey( "C" )->GetArray()[0].GetReal(); return 0.0; } @@ -373,7 +373,7 @@ double PdfOutlineItem::GetTextColorGreen() const { if( this->GetObject()->GetDictionary().HasKey( "C" ) ) - return this->GetObject()->GetIndirectKey( "C" )->GetArray()[1].GetReal(); + return this->GetObject()->MustGetIndirectKey( "C" )->GetArray()[1].GetReal(); return 0.0; } @@ -381,7 +381,7 @@ double PdfOutlineItem::GetTextColorBlue() const { if( this->GetObject()->GetDictionary().HasKey( "C" ) ) - return this->GetObject()->GetIndirectKey( "C" )->GetArray()[2].GetReal(); + return this->GetObject()->MustGetIndirectKey( "C" )->GetArray()[2].GetReal(); return 0.0; } Modified: podofo/trunk/src/podofo/doc/PdfPainter.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfPainter.cpp 2020-03-27 17:00:57 UTC (rev 2002) +++ podofo/trunk/src/podofo/doc/PdfPainter.cpp 2020-03-27 17:04:29 UTC (rev 2003) @@ -1227,7 +1227,7 @@ pGlyphFontObj->GetDictionary().AddKey("Encoding", pEncoding->Reference() ); // clear Widths-array and enter width of this glyph - PdfObject* pWidthObj = pGlyphFontObj->GetIndirectKey( "Widths" ); + PdfObject* pWidthObj = pGlyphFontObj->MustGetIndirectKey( "Widths" ); PdfArray & rWidthArr = pWidthObj->GetArray(); for ( unsigned int i = 0; i < rWidthArr.size(); i++ ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-03-27 17:00:59
|
Revision: 2002 http://sourceforge.net/p/podofo/code/2002 Author: mc-zyx Date: 2020-03-27 17:00:57 +0000 (Fri, 27 Mar 2020) Log Message: ----------- Patch by Michal Sudolsky: AcroForm fields array is not updated when it is reference When is created new AcroForm field and "Fields" array in AcroForm dictionary is reference then this new field is not added into it except in specific case when is called specific constructor but this constructor is used only with signature field and unaccessible for all other field types. Modified Paths: -------------- podofo/trunk/src/podofo/doc/PdfField.cpp Modified: podofo/trunk/src/podofo/doc/PdfField.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfField.cpp 2020-03-27 16:53:35 UTC (rev 2001) +++ podofo/trunk/src/podofo/doc/PdfField.cpp 2020-03-27 17:00:57 UTC (rev 2002) @@ -82,16 +82,10 @@ Init( pDoc->GetAcroForm() ); } -PdfField::PdfField( EPdfField eField, PdfAnnotation* pWidget, PdfAcroForm* pParent, PdfDocument* pDoc) +PdfField::PdfField( EPdfField eField, PdfAnnotation* pWidget, PdfAcroForm* pParent, PdfDocument*) : m_pObject( pWidget->GetObject() ), m_pWidget( pWidget ), m_eField( eField ) { Init( pParent ); - PdfObject* pFields = pParent->GetObject()->GetDictionary().GetKey( PdfName("Fields") ); - if( pFields && pFields->IsReference()) { - PdfObject *pRefFld = pDoc->GetObjects()->GetObject(pFields->GetReference()); - if(pRefFld) - pRefFld->GetArray().push_back( m_pObject->Reference() ); - } } PdfField::PdfField( EPdfField eField, PdfPage* pPage, const PdfRect & rRect, PdfDocument* pDoc, bool bAppearanceNone) @@ -116,18 +110,7 @@ void PdfField::Init( PdfAcroForm* pParent ) { // Insert into the parents kids array - PdfObject* pFields = pParent->GetObject()->GetDictionary().GetKey( PdfName("Fields") ); - if( pFields ) - { - if(!pFields->IsReference() ) - { - pFields->GetArray().push_back( m_pObject->Reference() ); - } - } - else - { - PODOFO_RAISE_ERROR( ePdfError_NoObject ); - } + pParent->GetObject()->MustGetIndirectKey( "Fields" )->GetArray().push_back( m_pObject->Reference() ); switch( m_eField ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-03-27 16:53:36
|
Revision: 2001 http://sourceforge.net/p/podofo/code/2001 Author: mc-zyx Date: 2020-03-27 16:53:35 +0000 (Fri, 27 Mar 2020) Log Message: ----------- Patch by John Senneker: Ignore broken objects by default in PdfParser Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfParser.cpp podofo/trunk/src/podofo/base/PdfParser.h Modified: podofo/trunk/src/podofo/base/PdfParser.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfParser.cpp 2020-03-27 16:13:28 UTC (rev 2000) +++ podofo/trunk/src/podofo/base/PdfParser.cpp 2020-03-27 16:53:35 UTC (rev 2001) @@ -72,6 +72,7 @@ namespace PoDoFo { +bool PdfParser::s_bIgnoreBrokenObjects = true; const long nMaxNumIndirectObjects = (1L << 23) - 1L; long PdfParser::s_nMaxObjects = nMaxNumIndirectObjects; @@ -185,7 +186,6 @@ m_nXRefLinearizedOffset = 0; m_lLastEOFOffset = 0; - m_bIgnoreBrokenObjects = false; m_nIncrementalUpdates = 0; m_nRecursionDepth = 0; } @@ -1178,7 +1178,7 @@ << " Index = " << i << std::endl; delete pObject; - if( m_bIgnoreBrokenObjects ) + if( s_bIgnoreBrokenObjects ) { PdfError::LogMessage( eLogSeverity_Error, oss.str().c_str() ); m_vecObjects->AddFreeObject( PdfReference( i, 0 ) ); @@ -1304,7 +1304,15 @@ std::ostringstream oss; oss << "Loading of object " << nObjNo << " 0 R failed!" << std::endl; - PODOFO_RAISE_ERROR_INFO( ePdfError_NoObject, oss.str().c_str() ); + if( s_bIgnoreBrokenObjects ) + { + PdfError::LogMessage( eLogSeverity_Error, oss.str().c_str() ); + return; + } + else + { + PODOFO_RAISE_ERROR_INFO( ePdfError_NoObject, oss.str().c_str() ); + } } Modified: podofo/trunk/src/podofo/base/PdfParser.h =================================================================== --- podofo/trunk/src/podofo/base/PdfParser.h 2020-03-27 16:13:28 UTC (rev 2000) +++ podofo/trunk/src/podofo/base/PdfParser.h 2020-03-27 16:53:35 UTC (rev 2001) @@ -366,7 +366,7 @@ /** * \return if broken objects are ignored while parsing */ - inline bool GetIgnoreBrokenObjects(); + inline static bool GetIgnoreBrokenObjects(); /** * Specify if the parser should ignore broken @@ -373,12 +373,12 @@ * objects, i.e. XRef entries that do not point * to valid objects. * - * Default is to not ignore broken objects and - * throw an exception if one is found. + * Default is to ignore broken objects and + * to not throw an exception if one is found. * * \param bBroken if true broken objects will be ignored */ - inline void SetIgnoreBrokenObjects( bool bBroken ); + inline static void SetIgnoreBrokenObjects( bool bBroken ); /** * \return maximum object count to read @@ -600,11 +600,12 @@ std::set<int> m_setObjectStreams; bool m_bStrictParsing; - bool m_bIgnoreBrokenObjects; int m_nIncrementalUpdates; int m_nRecursionDepth; + static bool s_bIgnoreBrokenObjects; + static long s_nMaxObjects; std::set<pdf_long> m_visitedXRefOffsets; @@ -681,7 +682,7 @@ // ----------------------------------------------------- bool PdfParser::GetIgnoreBrokenObjects() { - return m_bIgnoreBrokenObjects; + return s_bIgnoreBrokenObjects; } // ----------------------------------------------------- @@ -689,7 +690,7 @@ // ----------------------------------------------------- void PdfParser::SetIgnoreBrokenObjects( bool bBroken ) { - m_bIgnoreBrokenObjects = bBroken; + s_bIgnoreBrokenObjects = bBroken; } // ----------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mc...@us...> - 2020-03-27 16:13:30
|
Revision: 2000 http://sourceforge.net/p/podofo/code/2000 Author: mc-zyx Date: 2020-03-27 16:13:28 +0000 (Fri, 27 Mar 2020) Log Message: ----------- Patch by Francesco Pretto: PdfObject automatic ownership handling Modified Paths: -------------- podofo/trunk/CMakeLists.txt podofo/trunk/src/podofo/CMakeLists.txt podofo/trunk/src/podofo/base/PdfArray.cpp podofo/trunk/src/podofo/base/PdfArray.h podofo/trunk/src/podofo/base/PdfDictionary.cpp podofo/trunk/src/podofo/base/PdfDictionary.h podofo/trunk/src/podofo/base/PdfObject.cpp podofo/trunk/src/podofo/base/PdfObject.h podofo/trunk/src/podofo/base/PdfVariant.h podofo/trunk/src/podofo/doc/PdfFontFactory.cpp podofo/trunk/src/podofo/doc/PdfPage.cpp podofo/trunk/src/podofo/doc/PdfShadingPattern.cpp Added Paths: ----------- podofo/trunk/src/podofo/base/PdfOwnedDataType.cpp podofo/trunk/src/podofo/base/PdfOwnedDataType.h Modified: podofo/trunk/CMakeLists.txt =================================================================== --- podofo/trunk/CMakeLists.txt 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/CMakeLists.txt 2020-03-27 16:13:28 UTC (rev 2000) @@ -290,7 +290,7 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual -Wswitch-enum -Wcast-qual -Wwrite-strings -Wredundant-decls -Wreorder -Wno-deprecated-declarations") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual -Wswitch -Wcast-qual -Wwrite-strings -Wredundant-decls -Wreorder -Wno-deprecated-declarations") # # Note that we do not need debug definitions here. Set Modified: podofo/trunk/src/podofo/CMakeLists.txt =================================================================== --- podofo/trunk/src/podofo/CMakeLists.txt 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/CMakeLists.txt 2020-03-27 16:13:28 UTC (rev 2000) @@ -16,6 +16,7 @@ base/PdfContentsTokenizer.cpp base/PdfData.cpp base/PdfDataType.cpp + base/PdfOwnedDataType.cpp base/PdfDate.cpp base/PdfDictionary.cpp base/PdfEncoding.cpp @@ -124,6 +125,7 @@ base/PdfContentsTokenizer.h base/PdfData.h base/PdfDataType.h + base/PdfOwnedDataType.h base/PdfDate.h base/PdfDefines.h base/PdfDefinesPrivate.h Modified: podofo/trunk/src/podofo/base/PdfArray.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfArray.cpp 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/base/PdfArray.cpp 2020-03-27 16:13:28 UTC (rev 2000) @@ -41,33 +41,79 @@ namespace PoDoFo { PdfArray::PdfArray() - : PdfArrayBaseClass(), PdfDataType(), m_bDirty( false ) + : m_bDirty( false ) { } +PdfArray::PdfArray( const PdfObject &var ) + : m_bDirty( false ) +{ + this->push_back( var ); +} + +PdfArray::PdfArray(const PdfArray & rhs) + : PdfOwnedDataType( rhs ), m_bDirty( rhs.m_bDirty ), m_objects( rhs.m_objects ) +{ +} + PdfArray::~PdfArray() { } -PdfArray::PdfArray( const PdfObject & var ) - : PdfArrayBaseClass(), PdfDataType(), m_bDirty( false ) +PdfObject * PdfArray::findAt( size_type idx ) const { - this->push_back( var ); + PdfObject *obj = &const_cast<PdfArray *>( this )->m_objects[idx]; + if ( obj->IsReference() ) + return GetIndirectObject( obj->GetReference() ); + else + return obj; } -PdfArray::PdfArray( const PdfArray & rhs ) - : PdfArrayBaseClass(rhs), PdfDataType(rhs), m_bDirty(rhs.m_bDirty) +void PdfArray::clear() { - this->operator=( rhs ); + AssertMutable(); + if ( m_objects.size() == 0 ) + return; + + m_objects.clear(); + m_bDirty = true; } +PdfArray::iterator PdfArray::insert( const iterator &pos, const PdfObject &val ) +{ + AssertMutable(); + + m_bDirty = true; + iterator ret = m_objects.insert( pos, val ); + PdfVecObjects *pOwner = GetObjectOwner(); + if ( pOwner != NULL ) + ret->SetOwner( pOwner ); + return ret; +} + +void PdfArray::erase( const iterator &pos ) +{ + AssertMutable(); + + m_objects.erase( pos ); + m_bDirty = true; +} + +void PdfArray::erase( const iterator &first, const iterator &last ) +{ + AssertMutable(); + + m_objects.erase( first, last ); + m_bDirty = true; +} -PdfArray& PdfArray::operator=(const PdfArray& rhs) +PdfArray& PdfArray::operator=( const PdfArray &rhs ) { if (this != &rhs) { m_bDirty = rhs.m_bDirty; - PdfArrayBaseClass::operator=( rhs ); + m_objects = rhs.m_objects; + this->PdfOwnedDataType::operator=( rhs ); } else { @@ -77,6 +123,22 @@ return *this; } +void PdfArray::resize( size_t count, value_type val ) +{ + AssertMutable(); + + size_t currentSize = size(); + m_objects.resize( count, val ); + PdfVecObjects *pOwner = GetObjectOwner(); + if ( pOwner != NULL ) + { + for ( size_t i = currentSize; i < count; i++ ) + m_objects[i].SetOwner( pOwner ); + } + + m_bDirty = currentSize != count; +} + void PdfArray::Write( PdfOutputDevice* pDevice, EPdfWriteMode eWriteMode, const PdfEncrypt* pEncrypt ) const { @@ -183,4 +245,18 @@ } } +void PdfArray::SetOwner( PdfObject *pOwner ) +{ + PdfOwnedDataType::SetOwner( pOwner ); + PdfVecObjects *pVecOwner = pOwner->GetOwner(); + if ( pVecOwner != NULL ) + { + // Set owmership for all children + PdfArray::iterator it = this->begin(); + PdfArray::iterator end = this->end(); + for ( ; it != end; it++ ) + it->SetOwner( pVecOwner ); + } +} + }; Modified: podofo/trunk/src/podofo/base/PdfArray.h =================================================================== --- podofo/trunk/src/podofo/base/PdfArray.h 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/base/PdfArray.h 2020-03-27 16:13:28 UTC (rev 2000) @@ -42,13 +42,11 @@ #endif // _WIN32 #include "PdfDefines.h" -#include "PdfDataType.h" +#include "PdfOwnedDataType.h" #include "PdfObject.h" namespace PoDoFo { -typedef std::vector<PdfObject> PdfArrayBaseClass; - /** This class represents a PdfArray * Use it for all arrays that are written to a PDF file. * @@ -56,12 +54,16 @@ * * \see PdfVariant */ -class PODOFO_API PdfArray : private PdfArrayBaseClass, public PdfDataType { +class PODOFO_API PdfArray : public PdfOwnedDataType { public: - typedef PdfArrayBaseClass::iterator iterator; - typedef PdfArrayBaseClass::const_iterator const_iterator; - typedef PdfArrayBaseClass::reverse_iterator reverse_iterator; - typedef PdfArrayBaseClass::const_reverse_iterator const_reverse_iterator; + typedef size_t size_type; + typedef PdfObject value_type; + typedef value_type & reference; + typedef const value_type & const_reference; + typedef std::vector<value_type>::iterator iterator; + typedef std::vector<value_type>::const_iterator const_iterator; + typedef std::vector<value_type>::reverse_iterator reverse_iterator; + typedef std::vector<value_type>::const_reverse_iterator const_reverse_iterator; /** Create an empty array */ @@ -124,6 +126,18 @@ */ size_t GetStringIndex( const std::string& cmpString ) const; + /** Get the object at the given index out of the array. + * + * Lookup in the indirect objects as well, if the shallow object was a reference. + * The returned value is a pointer to the internal object in the dictionary + * so it MUST not be deleted. + * + * \param idx + * \returns pointer to the found value. NULL if the index was out of the boundaries + */ + inline const PdfObject * FindAt( size_type idx ) const; + inline PdfObject * FindAt( size_type idx ); + /** Adds a PdfObject to the array * * \param var add a PdfObject to the array @@ -133,6 +147,10 @@ */ inline void push_back( const PdfObject & var ); + /** Remove all elements from the array + */ + void clear(); + /** * \returns the size of the array */ @@ -148,9 +166,10 @@ /** * Resize the internal vector. - * \param __n new size + * \param count new size + * \param value refernce value */ - inline void resize(size_t __n, value_type __x = PdfArrayBaseClass::value_type()); + void resize( size_t count, value_type val = value_type() ); /** * Returns a read/write iterator that points to the first @@ -219,10 +238,10 @@ const _InputIterator& __last); #endif - inline PdfArray::iterator insert(const iterator& __position, const PdfObject & val ); + iterator insert( const iterator &pos, const PdfObject &val ); - inline void erase( const iterator& pos ); - inline void erase( const iterator& first, const iterator& last ); + void erase( const iterator& pos ); + void erase( const iterator& first, const iterator& last ); inline void reserve(size_type __n); @@ -275,19 +294,31 @@ */ virtual void SetDirty( bool bDirty ); + protected: + void SetOwner( PdfObject* pOwner ); + private: + PdfObject * findAt(size_type idx) const; + + private: bool m_bDirty; ///< Indicates if this object was modified after construction - + std::vector<PdfObject> m_objects; }; // ----------------------------------------------------- -// +// // ----------------------------------------------------- -void PdfArray::Clear() +inline const PdfObject * PdfArray::FindAt( size_type idx ) const { - AssertMutable(); + return findAt( idx ); +} - this->clear(); +// ----------------------------------------------------- +// +// ----------------------------------------------------- +inline PdfObject * PdfArray::FindAt( size_type idx ) +{ + return findAt( idx ); } // ----------------------------------------------------- @@ -295,7 +326,7 @@ // ----------------------------------------------------- size_t PdfArray::GetSize() const { - return this->size(); + return m_objects.size(); } // ----------------------------------------------------- @@ -303,10 +334,15 @@ // ----------------------------------------------------- void PdfArray::push_back( const PdfObject & var ) { - AssertMutable(); + insert( end(), var ); +} - PdfArrayBaseClass::push_back( var ); - m_bDirty = true; +// ----------------------------------------------------- +// +// ----------------------------------------------------- +void PdfArray::Clear() +{ + clear(); } // ----------------------------------------------------- @@ -314,7 +350,7 @@ // ----------------------------------------------------- size_t PdfArray::size() const { - return PdfArrayBaseClass::size(); + return m_objects.size(); } // ----------------------------------------------------- @@ -322,7 +358,7 @@ // ----------------------------------------------------- bool PdfArray::empty() const { - return PdfArrayBaseClass::empty(); + return m_objects.empty(); } // ----------------------------------------------------- @@ -332,7 +368,7 @@ { AssertMutable(); - return PdfArrayBaseClass::operator[](__n); + return m_objects[__n]; } // ----------------------------------------------------- @@ -340,23 +376,15 @@ // ----------------------------------------------------- const PdfObject& PdfArray::operator[](size_type __n) const { - return PdfArrayBaseClass::operator[](__n); + return m_objects[__n]; } // ----------------------------------------------------- // // ----------------------------------------------------- -void PdfArray::resize(size_t __n, value_type __x) -{ - PdfArrayBaseClass::resize(__n, __x); -} - -// ----------------------------------------------------- -// -// ----------------------------------------------------- PdfArray::iterator PdfArray::begin() { - return PdfArrayBaseClass::begin(); + return m_objects.begin(); } // ----------------------------------------------------- @@ -364,7 +392,7 @@ // ----------------------------------------------------- PdfArray::const_iterator PdfArray::begin() const { - return PdfArrayBaseClass::begin(); + return m_objects.begin(); } // ----------------------------------------------------- @@ -372,7 +400,7 @@ // ----------------------------------------------------- PdfArray::iterator PdfArray::end() { - return PdfArrayBaseClass::end(); + return m_objects.end(); } // ----------------------------------------------------- @@ -380,7 +408,7 @@ // ----------------------------------------------------- PdfArray::const_iterator PdfArray::end() const { - return PdfArrayBaseClass::end(); + return m_objects.end(); } // ----------------------------------------------------- @@ -388,7 +416,7 @@ // ----------------------------------------------------- PdfArray::reverse_iterator PdfArray::rbegin() { - return PdfArrayBaseClass::rbegin(); + return m_objects.rbegin(); } // ----------------------------------------------------- @@ -396,7 +424,7 @@ // ----------------------------------------------------- PdfArray::const_reverse_iterator PdfArray::rbegin() const { - return PdfArrayBaseClass::rbegin(); + return m_objects.rbegin(); } // ----------------------------------------------------- @@ -404,7 +432,7 @@ // ----------------------------------------------------- PdfArray::reverse_iterator PdfArray::rend() { - return PdfArrayBaseClass::rend(); + return m_objects.rend(); } // ----------------------------------------------------- @@ -412,7 +440,7 @@ // ----------------------------------------------------- PdfArray::const_reverse_iterator PdfArray::rend() const { - return PdfArrayBaseClass::rend(); + return m_objects.rend(); } // ----------------------------------------------------- @@ -431,57 +459,35 @@ { AssertMutable(); - PdfArrayBaseClass::insert( __position, __first, __last ); - m_bDirty = true; -} + PdfVecObjects *pOwner = GetObjectOwner(); + iterator it1 = __first; + iterator it2 = __position; + for ( ; it1 != __last; it1++, it2++ ) + { + it2 = m_objects.insert( it2, *it1 ); + if ( pOwner != NULL ) + it2->SetOwner( pOwner ); + } -// ----------------------------------------------------- -// -// ----------------------------------------------------- -PdfArray::iterator PdfArray::insert(const iterator& __position, const PdfObject & val ) -{ - AssertMutable(); - m_bDirty = true; - return PdfArrayBaseClass::insert( __position, val ); } // ----------------------------------------------------- // // ----------------------------------------------------- -void PdfArray::erase( const iterator& pos ) +void PdfArray::reserve( size_type __n ) { AssertMutable(); - PdfArrayBaseClass::erase( pos ); - m_bDirty = true; + m_objects.reserve( __n ); } // ----------------------------------------------------- // // ----------------------------------------------------- -void PdfArray::erase( const iterator& first, const iterator& last ) -{ - AssertMutable(); - - PdfArrayBaseClass::erase( first, last ); - m_bDirty = true; -} - -// ----------------------------------------------------- -// -// ----------------------------------------------------- -void PdfArray::reserve(size_type __n) -{ - PdfArrayBaseClass::reserve( __n ); -} - -// ----------------------------------------------------- -// -// ----------------------------------------------------- PdfObject & PdfArray::front() { - return PdfArrayBaseClass::front(); + return m_objects.front(); } // ----------------------------------------------------- @@ -489,7 +495,7 @@ // ----------------------------------------------------- const PdfObject & PdfArray::front() const { - return PdfArrayBaseClass::front(); + return m_objects.front(); } // ----------------------------------------------------- @@ -497,7 +503,7 @@ // ----------------------------------------------------- PdfObject & PdfArray::back() { - return PdfArrayBaseClass::back(); + return m_objects.back(); } // ----------------------------------------------------- @@ -505,7 +511,7 @@ // ----------------------------------------------------- const PdfObject & PdfArray::back() const { - return PdfArrayBaseClass::back(); + return m_objects.back(); } // ----------------------------------------------------- @@ -514,7 +520,7 @@ bool PdfArray::operator==( const PdfArray & rhs ) const { //TODO: This operator does not check for m_bDirty. Add comparison or add explanation why it should not be there - return (static_cast< PdfArrayBaseClass >(*this) == static_cast< PdfArrayBaseClass >(rhs) ); + return m_objects == rhs.m_objects; } // ----------------------------------------------------- @@ -523,7 +529,7 @@ bool PdfArray::operator!=( const PdfArray & rhs ) const { //TODO: This operator does not check for m_bDirty. Add comparison or add explanation why it should not be there - return (static_cast< PdfArrayBaseClass >(*this) != static_cast< PdfArrayBaseClass >(rhs) ); + return m_objects != rhs.m_objects; } typedef PdfArray TVariantList; Modified: podofo/trunk/src/podofo/base/PdfDictionary.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfDictionary.cpp 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/base/PdfDictionary.cpp 2020-03-27 16:13:28 UTC (rev 2000) @@ -44,7 +44,7 @@ } PdfDictionary::PdfDictionary( const PdfDictionary & rhs ) - : PdfDataType() + : PdfOwnedDataType() { this->operator=( rhs ); m_bDirty = false; @@ -68,7 +68,8 @@ m_mapKeys[(*it).first] = new PdfObject( *(*it).second ); ++it; } - + + PdfOwnedDataType::operator=( rhs ); m_bDirty = true; return *this; } @@ -147,6 +148,9 @@ inserted.first->second = objToInsert; } + PdfVecObjects *pOwner = GetObjectOwner(); + if ( pOwner != NULL ) + inserted.first->second->SetOwner( pOwner ); m_bDirty = true; } @@ -155,7 +159,7 @@ this->AddKey( identifier, *pObject ); } -const PdfObject* PdfDictionary::GetKey( const PdfName & key ) const +PdfObject * PdfDictionary::getKey( const PdfName & key ) const { if( !key.GetLength() ) return NULL; @@ -170,19 +174,42 @@ return (*it).second; } -PdfObject* PdfDictionary::GetKey( const PdfName & key ) +PdfObject * PdfDictionary::findKey( const PdfName &key ) const { - if( !key.GetLength() ) - return NULL; + PdfObject *obj = getKey( key ); + if ( obj != NULL ) + { + if ( obj->IsReference() ) + return GetIndirectObject( obj->GetReference() ); + else + return obj; + } - TIKeyMap it; + return NULL; +} - it = m_mapKeys.find( key ); - - if( it == m_mapKeys.end() ) - return NULL; - - return (*it).second; +PdfObject * PdfDictionary::findKeyParent( const PdfName & key ) const +{ + PdfObject *obj = findKey( key ); + if (obj == NULL) + { + PdfObject *parent = findKey( "Parent" ); + if ( parent == NULL ) + { + return NULL; + } + else + { + if ( parent->IsDictionary() ) + return parent->GetDictionary().findKeyParent( key ); + else + return NULL; + } + } + else + { + return obj; + } } pdf_int64 PdfDictionary::GetKeyAsLong( const PdfName & key, pdf_int64 lDefault ) const @@ -367,4 +394,18 @@ return m_mapKeys.end(); } +void PdfDictionary::SetOwner( PdfObject *pOwner ) +{ + PdfOwnedDataType::SetOwner( pOwner ); + PdfVecObjects *pVecOwner = pOwner->GetOwner(); + if ( pVecOwner != NULL ) + { + // Set owmership for all children + TCIKeyMap it = this->begin(); + TCIKeyMap end = this->end(); + for ( ; it != end; it++ ) + it->second->SetOwner( pVecOwner ); + } +} + }; Modified: podofo/trunk/src/podofo/base/PdfDictionary.h =================================================================== --- podofo/trunk/src/podofo/base/PdfDictionary.h 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/base/PdfDictionary.h 2020-03-27 16:13:28 UTC (rev 2000) @@ -35,7 +35,7 @@ #define _PDF_DICTIONARY_H_ #include "PdfDefines.h" -#include "PdfDataType.h" +#include "PdfOwnedDataType.h" #include "PdfName.h" #include "PdfObject.h" @@ -86,7 +86,7 @@ /** The PDF dictionary data type of PoDoFo (inherits from PdfDataType, * the base class for such representations) */ -class PODOFO_API PdfDictionary : public PdfDataType { +class PODOFO_API PdfDictionary : public PdfOwnedDataType { public: /** Create a new, empty dictionary */ @@ -165,7 +165,7 @@ * * \returns pointer to the found value, or 0 if the key was not found. */ - const PdfObject* GetKey( const PdfName & key ) const; + inline const PdfObject* GetKey( const PdfName & key ) const; /** Get the key's value out of the dictionary. This is an overloaded member * function. @@ -178,8 +178,33 @@ * * \returns the found value, or 0 if the key was not found. */ - PdfObject* GetKey( const PdfName & key ); + inline PdfObject* GetKey( const PdfName & key ); + /** Get the keys value out of the dictionary + * + * Lookup in the indirect objects as well, if the shallow object was a reference. + * The returned value is a pointer to the internal object in the dictionary + * so it MUST not be deleted. + * + * \param key look for the key names pszKey in the dictionary + * \returns pointer to the found value or 0 if the key was not found. + */ + inline const PdfObject* FindKey( const PdfName & key ) const; + inline PdfObject* FindKey( const PdfName & key ); + + /** Get the keys value out of the dictionary + * + * Lookup in the indirect objects as well, if the shallow object was a reference. + * Also lookup the parent objects, if /Parent key is found in the dictionary. + * The returned value is a pointer to the internal object in the dictionary + * so it MUST not be deleted. + * + * \param key look for the key names pszKey in the dictionary + * \returns pointer to the found value or 0 if the key was not found. + */ + inline const PdfObject* FindKeyParent( const PdfName & key ) const; + inline PdfObject* FindKeyParent( const PdfName & key ); + /** Get the key's value out of the dictionary. * * The returned value is a reference to the internal object in the dictionary @@ -286,6 +311,14 @@ TCIKeyMap begin() const; TCIKeyMap end() const; + protected: + void SetOwner( PdfObject* pOwner ); + + private: + PdfObject * getKey(const PdfName & key) const; + PdfObject * findKey(const PdfName & key) const; + PdfObject * findKeyParent(const PdfName & key) const; + private: TKeyMap m_mapKeys; @@ -296,6 +329,57 @@ typedef TVecDictionaries::iterator TIVecDictionaries; typedef TVecDictionaries::const_iterator TCIVecDictionaries; +// ----------------------------------------------------- +// +// ----------------------------------------------------- +inline const PdfObject * PdfDictionary::GetKey( const PdfName &key ) const +{ + return getKey(key); +} + +// ----------------------------------------------------- +// +// ----------------------------------------------------- +inline PdfObject * PdfDictionary::GetKey( const PdfName &key ) +{ + return getKey(key); +} + +// ----------------------------------------------------- +// +// ----------------------------------------------------- +inline const PdfObject * PdfDictionary::FindKey( const PdfName &key ) const +{ + return findKey(key); +} + +// ----------------------------------------------------- +// +// ----------------------------------------------------- +inline PdfObject * PdfDictionary::FindKey( const PdfName &key ) +{ + return findKey(key); +} + +// ----------------------------------------------------- +// +// ----------------------------------------------------- +inline const PdfObject* PdfDictionary::FindKeyParent( const PdfName &key ) const +{ + return findKeyParent(key); +} + +// ----------------------------------------------------- +// +// ----------------------------------------------------- +inline PdfObject* PdfDictionary::FindKeyParent( const PdfName &key ) +{ + return findKeyParent(key); +} + +// ----------------------------------------------------- +// +// ----------------------------------------------------- size_t PdfDictionary::GetSize() const { return m_mapKeys.size(); Modified: podofo/trunk/src/podofo/base/PdfObject.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfObject.cpp 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/base/PdfObject.cpp 2020-03-27 16:13:28 UTC (rev 2000) @@ -126,6 +126,8 @@ InitPdfObject(); } +// NOTE: Don't copy owner. Copied objects must be always detached. +// Ownership will be set automatically elsewhere PdfObject::PdfObject( const PdfObject & rhs ) : PdfVariant( rhs ), m_reference( rhs.m_reference ) { @@ -137,8 +139,12 @@ const_cast<PdfObject*>(&rhs)->DelayedStreamLoad(); m_bDelayedStreamLoadDone = rhs.DelayedStreamLoadDone(); - if( rhs.m_pStream && m_pOwner ) - m_pStream = m_pOwner->CreateStream( *(rhs.m_pStream) ); + // FIXME: + // Copying stream is currently broken: + // 1) PdfVecObjects::CreateStream( const PdfStream & ) is broken as it just returns NULL + // 2) Stream should be copyable also when m_pOwner is NULL (which is the case for copy constructor) + //if( rhs.m_pStream && m_pOwner ) + // m_pStream = m_pOwner->CreateStream( *(rhs.m_pStream) ); #if defined(PODOFO_EXTRA_CHECKS) // Must've been demand loaded or already done @@ -153,12 +159,46 @@ m_pStream = NULL; } +void PdfObject::SetOwner( PdfVecObjects* pVecObjects ) +{ + PODOFO_ASSERT( pVecObjects != NULL ); + if ( m_pOwner == pVecObjects ) + { + // The inner owner for variant data objects is guaranteed to be same + return; + } + + m_pOwner = pVecObjects; + if ( DelayedLoadDone() ) + SetVariantOwner( GetDataType() ); +} + +void PdfObject::AfterDelayedLoad( EPdfDataType eDataType ) +{ + SetVariantOwner( eDataType ); +} + +void PdfObject::SetVariantOwner( EPdfDataType eDataType ) +{ + switch ( eDataType ) + { + case ePdfDataType_Dictionary: + static_cast<PdfOwnedDataType &>( GetDictionary_NoDL() ).SetOwner( this ); + break; + case ePdfDataType_Array: + static_cast<PdfOwnedDataType &>( GetArray_NoDL() ).SetOwner( this ); + break; + default: + break; + } +} + void PdfObject::InitPdfObject() { m_pStream = NULL; m_pOwner = NULL; - m_bDelayedStreamLoadDone = true; + SetVariantOwner( GetDataType() ); #if defined(PODOFO_EXTRA_CHECKS) m_bDelayedStreamLoadInProgress = false; @@ -221,26 +261,11 @@ PdfObject* PdfObject::GetIndirectKey( const PdfName & key ) const { - const PdfObject* pObj = NULL; + if ( !this->IsDictionary() ) + return NULL; - if( this->IsDictionary() && this->GetDictionary().HasKey( key ) ) - { - pObj = this->GetDictionary().GetKey( key ); - if( pObj->IsReference() ) - { - if( !m_pOwner ) - { - PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidHandle, "Object is a reference but does not have an owner!" ); - } - - pObj = m_pOwner->GetObject( pObj->GetReference() ); - } - else - const_cast<PdfObject*>(pObj)->SetOwner( GetOwner() );// even directs might want an owner... - } - // DominikS: TODO Remove const on GetIndirectKey - return const_cast<PdfObject*>(pObj); + return const_cast<PdfObject*>( this->GetDictionary().FindKey( key ) ); } pdf_long PdfObject::GetObjectLength( EPdfWriteMode eWriteMode ) @@ -314,15 +339,18 @@ const_cast<PdfObject*>(&rhs)->DelayedStreamLoad(); + // NOTE: Don't copy owner. Objects being assigned always keep current ownership + PdfVariant::operator=(rhs); m_reference = rhs.m_reference; - m_pOwner = rhs.m_pOwner; - - PdfVariant::operator=( rhs ); - m_bDelayedStreamLoadDone = rhs.DelayedStreamLoadDone(); + SetVariantOwner( GetDataType() ); - if( rhs.m_pStream ) - m_pStream = m_pOwner->CreateStream( *(rhs.m_pStream) ); + // FIXME: + // Copying stream is currently broken: + // 1) PdfVecObjects::CreateStream( const PdfStream & ) is broken as it just returns NULL + // 2) Stream should be copyable also when m_pOwner is NULL + //if( rhs.m_pStream ) + // m_pStream = m_pOwner->CreateStream( *(rhs.m_pStream) ); #if defined(PODOFO_EXTRA_CHECKS) // Must've been demand loaded or already done Modified: podofo/trunk/src/podofo/base/PdfObject.h =================================================================== --- podofo/trunk/src/podofo/base/PdfObject.h 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/base/PdfObject.h 2020-03-27 16:13:28 UTC (rev 2000) @@ -48,6 +48,9 @@ class PdfOutputDevice; class PdfStream; class PdfVecObjects; +class PdfDictionary; +class PdfArray; +class PdfDocument; /** * This class represents a PDF indirect Object in memory @@ -63,6 +66,9 @@ */ class PODOFO_API PdfObject : public PdfVariant { friend class PdfVecObjects; + friend class PdfArray; + friend class PdfDictionary; + friend class PdfDocument; public: @@ -234,13 +240,6 @@ */ PODOFO_NOTHROW inline bool operator==( const PdfObject & rhs ) const; - /** Set the owner of this object, i.e. the PdfVecObjects instance to which - * this object belongs. - * - * \param pVecObjects a vector of PDF objects - */ - inline void SetOwner( PdfVecObjects* pVecObjects ); - /** Get the owner of this object. * \return the owner (if it wasn't changed anywhere, creator) of this object */ @@ -318,7 +317,21 @@ */ PdfStream* GetStream_NoDL(); + virtual void AfterDelayedLoad( EPdfDataType eDataType ); + + /** Set the owner of this object variant + */ + void SetVariantOwner( EPdfDataType eDataType ); + private: + /** Set the owner of this object, i.e. the PdfVecObjects to which + * this object belongs. + * + * \param pVecObjects a vector of pdf objects + */ + void SetOwner(PdfVecObjects* pVecObjects); + + private: /* See PdfVariant.h for a detailed explanation of this member, which is * here to prevent accidental construction of a PdfObject of integer type * when passing a pointer. */ @@ -381,14 +394,6 @@ // ----------------------------------------------------- // // ----------------------------------------------------- -inline void PdfObject::SetOwner( PdfVecObjects* pVecObjects ) -{ - m_pOwner = pVecObjects; -} - -// ----------------------------------------------------- -// -// ----------------------------------------------------- inline PdfVecObjects* PdfObject::GetOwner() const { return m_pOwner; Added: podofo/trunk/src/podofo/base/PdfOwnedDataType.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfOwnedDataType.cpp (rev 0) +++ podofo/trunk/src/podofo/base/PdfOwnedDataType.cpp 2020-03-27 16:13:28 UTC (rev 2000) @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (C) 2006 by Dominik Seichter * + * dom...@we... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * * + * In addition, as a special exception, the copyright holders give * + * permission to link the code of portions of this program with the * + * OpenSSL library under certain conditions as described in each * + * individual source file, and distribute linked combinations * + * including the two. * + * You must obey the GNU General Public License in all respects * + * for all of the code used other than OpenSSL. If you modify * + * file(s) with this exception, you may extend this exception to your * + * version of the file(s), but you are not obligated to do so. If you * + * do not wish to do so, delete this exception statement from your * + * version. If you delete this exception statement from all source * + * files in the program, then also delete it here. * + ***************************************************************************/ + +#include "PdfOwnedDataType.h" +#include "PdfObject.h" +#include "PdfVecObjects.h" + +namespace PoDoFo { + +PdfOwnedDataType::PdfOwnedDataType() + : m_pOwner( NULL ) +{ +} + +// NOTE: Don't copy owner. Copied objects must be always detached. +// Ownership will be set automatically elsewhere +PdfOwnedDataType::PdfOwnedDataType( const PdfOwnedDataType &rhs ) + : PdfDataType( rhs ), m_pOwner( NULL ) +{ +} + +PdfObject * PdfOwnedDataType::GetIndirectObject( const PdfReference &rReference ) const +{ + if ( m_pOwner == NULL ) + PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidHandle, "Object is a reference but does not have an owner!" ); + + return m_pOwner->GetOwner()->GetObject( rReference ); +} + +void PdfOwnedDataType::SetOwner( PdfObject* pOwner ) +{ + PODOFO_ASSERT( pOwner != NULL ); + m_pOwner = pOwner; +} + +PdfOwnedDataType & PdfOwnedDataType::operator=( const PdfOwnedDataType & rhs ) +{ + // NOTE: Don't copy owner. Objects being assigned will keep current ownership + PdfDataType::operator=( rhs ); + return *this; +} + +PdfVecObjects * PdfOwnedDataType::GetObjectOwner() +{ + return m_pOwner == NULL ? NULL : m_pOwner->GetOwner(); +} + +}; Added: podofo/trunk/src/podofo/base/PdfOwnedDataType.h =================================================================== --- podofo/trunk/src/podofo/base/PdfOwnedDataType.h (rev 0) +++ podofo/trunk/src/podofo/base/PdfOwnedDataType.h 2020-03-27 16:13:28 UTC (rev 2000) @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (C) 2006 by Dominik Seichter * + * dom...@we... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * * + * In addition, as a special exception, the copyright holders give * + * permission to link the code of portions of this program with the * + * OpenSSL library under certain conditions as described in each * + * individual source file, and distribute linked combinations * + * including the two. * + * You must obey the GNU General Public License in all respects * + * for all of the code used other than OpenSSL. If you modify * + * file(s) with this exception, you may extend this exception to your * + * version of the file(s), but you are not obligated to do so. If you * + * do not wish to do so, delete this exception statement from your * + * version. If you delete this exception statement from all source * + * files in the program, then also delete it here. * + ***************************************************************************/ + +#ifndef _PDF_OWNED_DATATYPE_H_ +#define _PDF_OWNED_DATATYPE_H_ + +#include "PdfDataType.h" + +namespace PoDoFo { + +class PdfObject; +class PdfVecObjects; +class PdfReference; + +/** + * A PdfDataType object with PdfObject owner + */ +class PODOFO_API PdfOwnedDataType : public PdfDataType { + friend class PdfObject; +protected: + /** Create a new PdfDataOwnedType. + * Can only be called by subclasses + */ + PdfOwnedDataType(); + + PdfOwnedDataType( const PdfOwnedDataType &rhs ); + +public: + + /** \returns a pointer to a PdfVecObjects that is the + * owner of this data type. + * Might be NULL if the data type has no owner. + */ + inline const PdfObject* GetOwner() const; + inline PdfObject* GetOwner(); + + PdfOwnedDataType & operator=( const PdfOwnedDataType &rhs ); + +protected: + PdfObject * GetIndirectObject( const PdfReference &rReference ) const; + PdfVecObjects * GetObjectOwner(); + virtual void SetOwner( PdfObject *pOwner ); + +private: + PdfObject *m_pOwner; +}; + +inline const PdfObject* PdfOwnedDataType::GetOwner() const +{ + return m_pOwner; +} + +inline PdfObject* PdfOwnedDataType::GetOwner() +{ + return m_pOwner; +} + +}; // namespace PoDoFo + +#endif /* _PDF_OWNED_DATATYPE_H_ */ Modified: podofo/trunk/src/podofo/base/PdfVariant.h =================================================================== --- podofo/trunk/src/podofo/base/PdfVariant.h 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/base/PdfVariant.h 2020-03-27 16:13:28 UTC (rev 2000) @@ -436,6 +436,11 @@ */ inline virtual void DelayedLoadImpl(); + /** Called after delayed load + * \param eDataType Detected data type + */ + inline virtual void AfterDelayedLoad( EPdfDataType eDataType ); + /** * Returns true if delayed loading is disabled, or if it is enabled * and loading has completed. External callers should never need to @@ -564,6 +569,7 @@ #if defined(PODOFO_EXTRA_CHECKS) m_bDelayedLoadInProgress = false; #endif + const_cast<PdfVariant*>(this)->AfterDelayedLoad( ( EPdfDataType )m_eDataType ); } } @@ -943,6 +949,15 @@ } // ----------------------------------------------------- +// +// ----------------------------------------------------- +void PdfVariant::AfterDelayedLoad( EPdfDataType eDataType ) +{ + ( void )eDataType; + // Do nothing +} + +// ----------------------------------------------------- // // ----------------------------------------------------- bool PdfVariant::operator!=( const PdfVariant & rhs) const Modified: podofo/trunk/src/podofo/doc/PdfFontFactory.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfFontFactory.cpp 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/doc/PdfFontFactory.cpp 2020-03-27 16:13:28 UTC (rev 2000) @@ -212,21 +212,33 @@ const PdfName & rSubType = pSubTypeKey->GetName(); if( rSubType == PdfName("Type0") ) { + // TABLE 5.18 Entries in a Type 0 font dictionary + // The PDF reference states that DescendantFonts must be an array, // some applications (e.g. MS Word) put the array into an indirect object though. - const PdfObject* const pDescendantObj = pObject->GetIndirectKey( "DescendantFonts" ); + PdfObject* const pDescendantObj = pObject->GetIndirectKey( "DescendantFonts" ); if ( NULL == pDescendantObj ) PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidDataType, "Type0 Font: No DescendantFonts" ); - const PdfArray & descendant = pDescendantObj->GetArray(); + PdfArray & descendants = pDescendantObj->GetArray(); PdfObject* pFontObject = NULL; - if (descendant.size() && descendant[0].IsReference()) + if( descendants.size() ) { - pFontObject = pObject->GetOwner()->GetObject( descendant[0].GetReference() ); + // DescendantFonts is a one-element array + PdfObject &descendant = descendants[0]; - pDescriptor = pFontObject->GetIndirectKey( "FontDescriptor" ); + if( descendant.IsReference() ) + { + pFontObject = pObject->GetOwner()->GetObject( descendant.GetReference() ); + pDescriptor = pFontObject->GetIndirectKey( "FontDescriptor" ); + } + else + { + pFontObject = &descendant; + pDescriptor = pFontObject->GetIndirectKey( "FontDescriptor" ); + } } pEncoding = pObject->GetIndirectKey( "Encoding" ); Modified: podofo/trunk/src/podofo/doc/PdfPage.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfPage.cpp 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/doc/PdfPage.cpp 2020-03-27 16:13:28 UTC (rev 2000) @@ -728,11 +728,7 @@ } pObj = pDocument->GetObjects()->GetObject( pObj->GetReference() ); - if(pObj) { - pObj->SetOwner(this->GetObject()->GetOwner()); - } - } else - pObj->SetOwner( this->GetObject()->GetOwner() );// even directs might want an owner... + } } if( pObj && pObj->IsArray() ) Modified: podofo/trunk/src/podofo/doc/PdfShadingPattern.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfShadingPattern.cpp 2019-09-28 22:04:57 UTC (rev 1999) +++ podofo/trunk/src/podofo/doc/PdfShadingPattern.cpp 2020-03-27 16:13:28 UTC (rev 2000) @@ -186,7 +186,6 @@ } else { PdfObject *shadingObject = this->GetObject()->GetOwner()->CreateObject(shading); this->GetObject()->GetDictionary().AddKey(PdfName("Shading"), shadingObject->Reference()); - this->GetObject()->GetDictionary().GetKey(PdfName("Shading"))->SetOwner(this->GetObject()->GetOwner()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2019-09-28 22:04:58
|
Revision: 1999 http://sourceforge.net/p/podofo/code/1999 Author: mabri Date: 2019-09-28 22:04:57 +0000 (Sat, 28 Sep 2019) Log Message: ----------- Fixes issues #64, #65 and #66: podofoimpose resource/XObject handling, legacy plan reading - Now handles inherited resources correctly AFAICS (only tested with PoC for issue #65). - Multiple references to the same object are now handled giving out references (issue #65). - Creation of superfluous indirect objects when migrating direct objects is suppressed now. - The memory leak detected in the patch's line ranges is also fixed, others left for later. - "Legacy" plan reading fixed to to able to test the other issues (the issue #65 PoC). This would be 5 commits normally (five logical changes), but this is the last one before the special revision 2000, which will be used for documenting past, present & future plans. Metadata for the podofo-users mailing list post where the PoC in issue #65 is sourced from: Post-Author: Ryan Bourne Post-Subject: [Podofo-users] PodofoImpose Post-Archive-Date: 2012-07-19 02:10:09 UTC Post-Message-ID: BLU...@ph...l Post-Archive-URL: https://sourceforge.net/p/podofo/mailman/message/29562374/ Revision Links: -------------- http://sourceforge.net/p/podofo/code/2000 Modified Paths: -------------- podofo/trunk/tools/podofoimpose/pdftranslator.cpp podofo/trunk/tools/podofoimpose/pdftranslator.h podofo/trunk/tools/podofoimpose/planreader_legacy.cpp Modified: podofo/trunk/tools/podofoimpose/pdftranslator.cpp =================================================================== --- podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2019-08-13 22:02:14 UTC (rev 1998) +++ podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2019-09-28 22:04:57 UTC (rev 1999) @@ -177,7 +177,7 @@ } - PdfObject* PdfTranslator::migrateResource ( PdfObject * obj ) + PdfObject* PdfTranslator::migrateResource ( const PdfObject * obj ) { // std::cerr<<"PdfTranslator::migrateResource"<<std::endl; PdfObject *ret ( 0 ); @@ -188,8 +188,14 @@ if ( obj->IsDictionary() ) { - ret = targetDoc->GetObjects().CreateObject ( *obj ); - + if ( obj->Reference().IsIndirect() ) + { + ret = targetDoc->GetObjects().CreateObject ( *obj ); + } + else + { + ret = new PdfObject( *obj ); + } TKeyMap resmap = obj->GetDictionary().GetKeys(); for ( TCIKeyMap itres = resmap.begin(); itres != resmap.end(); ++itres ) { @@ -205,7 +211,13 @@ } PdfObject *migrated = migrateResource ( o ); if (NULL != migrated) - ret->GetDictionary().AddKey ( itres->first, migrated ); // 2nd arg non-NULL! + { + ret->GetDictionary().AddKey ( itres->first, migrated ); + if ( !(migrated->Reference().IsIndirect()) ) + { + delete migrated; + } + } } if ( obj->HasStream() ) @@ -223,14 +235,32 @@ if ( NULL == co ) continue; narray.push_back ( *co ); + + if ( !(co->Reference().IsIndirect()) ) + { + delete co; + } } - ret = targetDoc->GetObjects().CreateObject ( narray ); + if ( obj->Reference().IsIndirect() ) + { + ret = targetDoc->GetObjects().CreateObject ( narray ); + } + else + { + ret = new PdfObject( narray ); + } } else if ( obj->IsReference() ) { if ( migrateMap.find ( obj->GetReference().ToString() ) != migrateMap.end() ) { - return migrateMap[obj->GetReference().ToString() ]; + std::ostringstream oss; + oss << "Referenced object " << obj->GetReference().ToString() + << " already migrated." << std::endl; + PdfError::DebugMessage( oss.str().c_str() ); + + const PdfObject* const found = migrateMap[ obj->GetReference().ToString() ]; + return new PdfObject( found->Reference() ); } PdfObject *to_migrate = sourceDoc->GetObjects().GetObject ( obj->GetReference() ); @@ -256,30 +286,27 @@ ret = new PdfObject ( *obj );//targetDoc->GetObjects().CreateObject(*obj); } + if ( obj->Reference().IsIndirect() ) + { + migrateMap.insert ( std::pair<std::string, PdfObject*> ( obj->Reference().ToString(), ret ) ); + } - migrateMap.insert ( std::pair<std::string, PdfObject*> ( obj->Reference().ToString(), ret ) ); - - return ret; - } PdfObject* PdfTranslator::getInheritedResources ( PdfPage* page ) { // std::cerr<<"PdfTranslator::getInheritedResources"<<std::endl; - PdfObject *res ( 0 ); // = new PdfObject; - PdfObject *rparent = page->GetObject(); - while ( rparent && rparent->IsDictionary() ) + PdfObject *res ( 0 ); + // mabri: resources are inherited as whole dict, not at all if the page has the dict + // mabri: specified in PDF32000_2008.pdf section 7.7.3.4 Inheritance of Page Attributes + // mabri: and in section 7.8.3 Resource Dictionaries + const PdfObject *sourceRes = page->GetInheritedKey( PdfName ( "Resources" ) ); + if ( sourceRes ) { - PdfObject *curRes = rparent->GetDictionary().GetKey ( PdfName ( "Resources" ) ); - if ( curRes ) - { - res = migrateResource ( curRes ); - } - rparent = rparent->GetIndirectKey ( "Parent" ); + res = migrateResource( sourceRes ); } return res; - } void PdfTranslator::setTarget ( const std::string & target ) @@ -508,6 +535,7 @@ { PdfObject bb; // DominikS: Fix compilation using Visual Studio on Windows + // mabri: ML post archive URL is https://sourceforge.net/p/podofo/mailman/message/24609746/ // bbIndex->at(resourceIndex).ToVariant( bb ); ((*bbIndex)[resourceIndex]).ToVariant( bb ); xo->GetObject()->GetDictionary().AddKey ( PdfName ( "BBox" ), bb ); @@ -552,6 +580,13 @@ targetDoc->Write ( outFilePath.c_str() ); + // The following is necessary to avoid line 195 being detected as allocation having a memory leak + // without changing other files than this one (thorough leak prevention shall be applied later). + for (std::map<int, PdfObject*>::iterator it = resources.begin(); it != resources.end(); it++) + { + delete (*it).second; + } + resources.clear(); } Modified: podofo/trunk/tools/podofoimpose/pdftranslator.h =================================================================== --- podofo/trunk/tools/podofoimpose/pdftranslator.h 2019-08-13 22:02:14 UTC (rev 1998) +++ podofo/trunk/tools/podofoimpose/pdftranslator.h 2019-09-28 22:04:57 UTC (rev 1999) @@ -117,7 +117,7 @@ bool checkIsPDF ( std::string path ); PdfObject* getInheritedResources ( PdfPage* page ); void mergeResKey ( PdfObject *base, PdfName key, PdfObject *tomerge ); - PdfObject* migrateResource(PdfObject * obj); + PdfObject* migrateResource(const PdfObject * obj); void drawLine ( double x, double y, double xx, double yy, std::ostringstream & a ); void signature ( double x , double y, int sheet, const std::vector<int> & pages, std::ostringstream & a ); Modified: podofo/trunk/tools/podofoimpose/planreader_legacy.cpp =================================================================== --- podofo/trunk/tools/podofoimpose/planreader_legacy.cpp 2019-08-13 22:02:14 UTC (rev 1998) +++ podofo/trunk/tools/podofoimpose/planreader_legacy.cpp 2019-09-28 22:04:57 UTC (rev 1999) @@ -181,18 +181,15 @@ throw runtime_error ( "Failed to open plan file" ); // duplicate = MAX_SOURCE_PAGES; - std::string line; - char cbuffer[MAX_RECORD_SIZE]; - int blen (0); std::vector<std::string> memfile; do { - if ( !in.getline ( cbuffer, MAX_RECORD_SIZE ) ) + std::string buffer; + if ( !std::getline ( in, buffer ) && ( !in.eof() || in.bad() ) ) + { throw runtime_error ( "Failed to read line from plan" ); + } - blen = in.gcount() ; - std::string buffer ( cbuffer, blen ); - #ifdef PODOFO_HAVE_LUA // This was "supposed" to be a legacy file, but if it starts // with two dashes, it must be a lua file, so process it accordingly: @@ -203,7 +200,7 @@ } #endif // PODOFO_HAVE_LUA - if ( blen < 2 ) // Nothing + if ( buffer.length() < 2 ) // Nothing continue; PoDoFo::Impose::Util::trimmed_str(buffer); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2019-08-13 22:02:17
|
Revision: 1998 http://sourceforge.net/p/podofo/code/1998 Author: mabri Date: 2019-08-13 22:02:14 +0000 (Tue, 13 Aug 2019) Log Message: ----------- Fixes issue #58: Assertion !m_pOutputStream failed in PdfFilter destructor This is done by catching PdfError exceptions thrown by PdfOutputStream::Close() or further down the stack (in the case originally reported on the mailing list it's actually PdfFilteredDecodeStream::Close() having called PdfFilter::EndDecode(), that post's metadata is below) in PdfFilter::EndDecode() and setting m_pOutputStream to NULL so the assertion in the PdfFilter destructor holds. This adds some AddToCallstack() debugging code also (to the relevant code path) to make it easier to debug such an issue than it was for me. I've tested with the PoC referenced in issue #58 and one sent to me personally by the original reporter on the mailing list (having a stream with /Filter DCTDecode nested in ASCII85Decode where the former throws: invalid JPEG). Post-Message-ID: CAN+VXVO=ef=4EM...@ma... Post-Subject: [Podofo-users] Segfault PoDoFo::PdfStream::GetFilteredCopy Post-Archive-Date: 2019-06-07 22:52:15 UTC Post-Date: 2019-06-07 22:23:47 UTC Post-Author: Clemens Kolbitsch (lastline.com) Modified Paths: -------------- podofo/trunk/src/podofo/base/PdfFilter.cpp podofo/trunk/src/podofo/base/PdfFilter.h Modified: podofo/trunk/src/podofo/base/PdfFilter.cpp =================================================================== --- podofo/trunk/src/podofo/base/PdfFilter.cpp 2019-07-10 22:50:00 UTC (rev 1997) +++ podofo/trunk/src/podofo/base/PdfFilter.cpp 2019-08-13 22:02:14 UTC (rev 1998) @@ -140,7 +140,7 @@ * filter and written to another PdfOutputStream. * * The passed output stream is owned by this PdfOutputStream - * and deleted along with it. + * and deleted along with it (optionally, see constructor). */ class PdfFilteredDecodeStream : public PdfOutputStream { public: @@ -148,12 +148,12 @@ * * All data written to this stream is decoded using the passed filter type * and written to the passed output stream which will be deleted - * by this PdfFilteredEncodeStream. + * by this PdfFilteredDecodeStream if the parameter bOwnStream is true. * * \param pOutputStream write all data to this output stream after decoding the data. - * The PdfOutputStream is deleted along with this object. + * The PdfOutputStream is deleted along with this object if bOwnStream is true. * \param eFilter use this filter for decoding. - * \param bOwnStream if true pOutputStream will be deleted along with this filter + * \param bOwnStream if true pOutputStream will be deleted along with this stream * \param pDecodeParms additional parameters for decoding */ PdfFilteredDecodeStream( PdfOutputStream* pOutputStream, const EPdfFilter eFilter, bool bOwnStream, @@ -189,6 +189,7 @@ } catch( PdfError & e ) { + e.AddToCallstack( __FILE__, __LINE__ ); m_bFilterFailed = true; throw e; } @@ -198,10 +199,22 @@ virtual void Close() { - if( !m_bFilterFailed ) + try { + if( !m_bFilterFailed ) + { + m_filter->EndDecode(); + } + } + catch( PdfError & e ) { - m_filter->EndDecode(); + std::ostringstream oss; + oss << "PdfFilter::EndDecode() failed in filter of type " + << PdfFilterFactory::FilterTypeToName( m_filter->GetType() ) << ".\n"; + e.AddToCallstack( __FILE__, __LINE__, oss.str() ); + m_bFilterFailed = true; + throw e; } + } private: @@ -348,16 +361,16 @@ if( pDictionary && pDictionary->HasKey( "DecodeParms" ) && pDictionary->GetKey( "DecodeParms" )->IsDictionary() ) pDictionary = &(pDictionary->GetKey( "DecodeParms" )->GetDictionary()); - PdfFilteredDecodeStream* pFilter = new PdfFilteredDecodeStream( pStream, *it, false, pDictionary ); + PdfFilteredDecodeStream* pFilterStream = new PdfFilteredDecodeStream( pStream, *it, false, pDictionary ); ++it; while( it != filters.rend() ) { - pFilter = new PdfFilteredDecodeStream( pFilter, *it, true, pDictionary ); + pFilterStream = new PdfFilteredDecodeStream( pFilterStream, *it, true, pDictionary ); ++it; } - return pFilter; + return pFilterStream; } EPdfFilter PdfFilterFactory::FilterNameToType( const PdfName & name, bool bSupportShortNames ) Modified: podofo/trunk/src/podofo/base/PdfFilter.h =================================================================== --- podofo/trunk/src/podofo/base/PdfFilter.h 2019-07-10 22:50:00 UTC (rev 1997) +++ podofo/trunk/src/podofo/base/PdfFilter.h 2019-08-13 22:02:14 UTC (rev 1998) @@ -404,6 +404,7 @@ // ----------------------------------------------------- // // ----------------------------------------------------- + void PdfFilter::EndDecode() { PODOFO_RAISE_LOGIC_IF( !m_pOutputStream, "EndDecode() without BeginDecode() or on failed filter" ) @@ -411,16 +412,23 @@ try { EndDecodeImpl(); } catch( PdfError & e ) { + e.AddToCallstack( __FILE__, __LINE__ ); // Clean up and close stream this->FailEncodeDecode(); throw e; - } - - if( m_pOutputStream ) - { - m_pOutputStream->Close(); - m_pOutputStream = NULL; - } + } + try { // introduced to fix issue #58 + if( m_pOutputStream ) + { + m_pOutputStream->Close(); + m_pOutputStream = NULL; + } + } catch( PdfError & e ) { + e.AddToCallstack( __FILE__, __LINE__, "Exception caught closing filter's output stream.\n"); + // Closing stream failed, just get rid of it + m_pOutputStream = NULL; + throw e; + } } // ----------------------------------------------------- @@ -429,7 +437,7 @@ void PdfFilter::FailEncodeDecode() { if ( m_pOutputStream != NULL ) // OC 19.08.2010 BugFix: Sometimes FailEncodeDecode() is called twice - m_pOutputStream->Close(); + m_pOutputStream->Close(); // mabri: issue #58 seems fixed without exception safety here ... m_pOutputStream = NULL; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2019-07-10 22:50:05
|
Revision: 1997 http://sourceforge.net/p/podofo/code/1997 Author: mabri Date: 2019-07-10 22:50:00 +0000 (Wed, 10 Jul 2019) Log Message: ----------- Fixes issue #59: SEGV of podofotxtextract in Type0 font handling (by PoDoFo::PdfFontFactory::CreateFont) This is done by splitting the query for DescendantFonts up into the first part giving a pointer, and the second, leading to a C++ reference to a PdfArray, then checking the pointer for NULL, throwing a PdfError exception if it is, with the code ePdfError_InvalidDataType, because the array is mandatory AFAIK. The information given with it specifies what's missing (the DescendantFonts). Modified Paths: -------------- podofo/trunk/src/podofo/doc/PdfFontFactory.cpp Modified: podofo/trunk/src/podofo/doc/PdfFontFactory.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfFontFactory.cpp 2019-07-09 22:03:19 UTC (rev 1996) +++ podofo/trunk/src/podofo/doc/PdfFontFactory.cpp 2019-07-10 22:50:00 UTC (rev 1997) @@ -214,8 +214,12 @@ { // The PDF reference states that DescendantFonts must be an array, // some applications (e.g. MS Word) put the array into an indirect object though. - const PdfArray & descendant = - pObject->GetIndirectKey( "DescendantFonts" )->GetArray(); + const PdfObject* const pDescendantObj = pObject->GetIndirectKey( "DescendantFonts" ); + + if ( NULL == pDescendantObj ) + PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidDataType, "Type0 Font: No DescendantFonts" ); + + const PdfArray & descendant = pDescendantObj->GetArray(); PdfObject* pFontObject = NULL; if (descendant.size() && descendant[0].IsReference()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2019-07-09 22:03:24
|
Revision: 1996 http://sourceforge.net/p/podofo/code/1996 Author: mabri Date: 2019-07-09 22:03:19 +0000 (Tue, 09 Jul 2019) Log Message: ----------- Fixes issue #57: SEGV in podofotxtextract (PoDoFo::PdfFontFactory::CreateFont) This is done by inserting a NULL check in line 255, so if the BaseFont key isn't found, the check triggers, and a PdfError exception with the code ePdfError_NoObject is thrown (with an explanatory message). Modified Paths: -------------- podofo/trunk/src/podofo/doc/PdfFontFactory.cpp Modified: podofo/trunk/src/podofo/doc/PdfFontFactory.cpp =================================================================== --- podofo/trunk/src/podofo/doc/PdfFontFactory.cpp 2019-07-08 21:07:07 UTC (rev 1995) +++ podofo/trunk/src/podofo/doc/PdfFontFactory.cpp 2019-07-09 22:03:19 UTC (rev 1996) @@ -252,6 +252,9 @@ // Check if its a PdfFontType1Base14 PdfObject* pBaseFont = NULL; pBaseFont = pObject->GetIndirectKey( "BaseFont" ); + if ( NULL == pBaseFont ) + PODOFO_RAISE_ERROR_INFO( ePdfError_NoObject, "No BaseFont object found" + " by reference in given object" ); const char* pszBaseFontName = pBaseFont->GetName().GetName().c_str(); const PdfFontMetricsBase14* pMetrics = PODOFO_Base14FontDef_FindBuiltinData(pszBaseFontName); if ( pMetrics != NULL ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2019-07-08 21:07:14
|
Revision: 1995 http://sourceforge.net/p/podofo/code/1995 Author: mabri Date: 2019-07-08 21:07:07 +0000 (Mon, 08 Jul 2019) Log Message: ----------- Fixed issue #56: SEGV in podofoimpose caused by PdfTranslator::migrateResource(PdfObject*) NULL dereference This adds NULL checks in the appropriate places and should have been part of the fix for issue #45 in the previous commit. NULL being returned outside of a loop means that nothing can be done in that call of migrateResource anymore, then NULL is returned from that call also, immediately. That NULL check has been added by me after the publishing of the provisional patch yesterday (UTC) and hasn't been tested with a fresh test case (other than the PoC, I mean) and only tested with the older compiler versions. Modified Paths: -------------- podofo/trunk/tools/podofoimpose/pdftranslator.cpp Modified: podofo/trunk/tools/podofoimpose/pdftranslator.cpp =================================================================== --- podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2019-06-07 21:07:34 UTC (rev 1994) +++ podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2019-07-08 21:07:07 UTC (rev 1995) @@ -220,6 +220,8 @@ for ( unsigned int ci = 0; ci < carray.GetSize(); ++ci ) { PdfObject *co ( migrateResource ( &carray[ci] ) ); + if ( NULL == co ) + continue; narray.push_back ( *co ); } ret = targetDoc->GetObjects().CreateObject ( narray ); @@ -244,7 +246,10 @@ return NULL; // skip this migration } PdfObject * o ( migrateResource ( to_migrate ) ); - ret = new PdfObject ( o->Reference() ) ; + if ( NULL != o ) + ret = new PdfObject ( o->Reference() ); + else + return NULL; // avoid going through rest of method } else { @@ -342,7 +347,10 @@ PoDoFo::PdfName keyname ( *itKey ); if ( page->GetObject()->GetDictionary().HasKey ( keyname ) ) { - xobj->GetObject()->GetDictionary().AddKey ( keyname, migrateResource ( page->GetObject()->GetDictionary().GetKey ( keyname ) ) ); + PdfObject* migObj = migrateResource ( page->GetObject()->GetDictionary().GetKey ( keyname ) ); + if ( NULL == migObj ) + continue; + xobj->GetObject()->GetDictionary().AddKey ( keyname, migObj ); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2019-06-07 21:07:39
|
Revision: 1994 http://sourceforge.net/p/podofo/code/1994 Author: mabri Date: 2019-06-07 21:07:34 +0000 (Fri, 07 Jun 2019) Log Message: ----------- Fixed issue #45 part: infinite recursion in PdfTranslator::migrateResource(PdfObject*) This is done by reference cycle detection (giving warnings on it) & continuing (in an effort to not expressly exclude incorrect documents from podofoimpose). No protection is provided when a document is so large to include a reference cycle large enough to exhaust the stack without going through the whole cycle, because IMHO that's a sufficiently different issue to warrant a separate commit & I don't know how the number in PdfRecursionGuard was arrived at, please tell. Modified Paths: -------------- podofo/trunk/tools/podofoimpose/pdftranslator.cpp podofo/trunk/tools/podofoimpose/pdftranslator.h Modified: podofo/trunk/tools/podofoimpose/pdftranslator.cpp =================================================================== --- podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2019-06-01 23:05:18 UTC (rev 1993) +++ podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2019-06-07 21:07:34 UTC (rev 1994) @@ -194,7 +194,18 @@ for ( TCIKeyMap itres = resmap.begin(); itres != resmap.end(); ++itres ) { PdfObject *o = itres->second; - ret->GetDictionary().AddKey ( itres->first , migrateResource ( o ) ); + std::pair<std::set<PdfObject*>::iterator,bool> res = setMigrationPending.insert( o ); + if (!res.second) + { + std::ostringstream oss; + oss << "Cycle detected: Object with ref " << o->Reference().ToString() + << " is already pending migration to the target.\n"; + PdfError::LogMessage( eLogSeverity_Warning, oss.str().c_str() ); + continue; + } + PdfObject *migrated = migrateResource ( o ); + if (NULL != migrated) + ret->GetDictionary().AddKey ( itres->first, migrated ); // 2nd arg non-NULL! } if ( obj->HasStream() ) @@ -220,10 +231,20 @@ return migrateMap[obj->GetReference().ToString() ]; } - PdfObject * o ( migrateResource ( sourceDoc->GetObjects().GetObject ( obj->GetReference() ) ) ); + PdfObject *to_migrate = sourceDoc->GetObjects().GetObject ( obj->GetReference() ); - ret = new PdfObject ( o->Reference() ) ; - + std::pair<std::set<PdfObject*>::iterator, bool> res + = setMigrationPending.insert( to_migrate ); + if (!res.second) + { + std::ostringstream oss; + oss << "Cycle detected: Object with ref " << obj->GetReference().ToString() + << " is already pending migration to the target.\n"; + PdfError::LogMessage( eLogSeverity_Warning, oss.str().c_str() ); + return NULL; // skip this migration + } + PdfObject * o ( migrateResource ( to_migrate ) ); + ret = new PdfObject ( o->Reference() ) ; } else { Modified: podofo/trunk/tools/podofoimpose/pdftranslator.h =================================================================== --- podofo/trunk/tools/podofoimpose/pdftranslator.h 2019-06-01 23:05:18 UTC (rev 1993) +++ podofo/trunk/tools/podofoimpose/pdftranslator.h 2019-06-07 21:07:34 UTC (rev 1994) @@ -25,6 +25,7 @@ #include <string> #include <map> +#include <set> #include <vector> #include <sstream> #include <istream> @@ -131,6 +132,7 @@ std::vector<std::string> multiSource; std::map<std::string, PdfObject*> migrateMap; + std::set<PdfObject*> setMigrationPending; public: int pcount; double sourceWidth; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |