Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Alexander_Naumov:SLE-12:Update
podofo.34526
r1640-Use-PdfPagesTree-GetChildCount-whenever-p...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File r1640-Use-PdfPagesTree-GetChildCount-whenever-possible.patch of Package podofo.34526
------------------------------------------------------------------------ r1640 | aja_ | 2014-06-15 19:30:42 +0200 (dom 15 de jun de 2014) | 5 líneas ADDED: Patch by Petr Pytelka - Use PdfPagesTree::GetChildCount() whenever possible An extension of previous Petr Pytelka's patch for "Count as reference in page tree", with some code duplication removal. Index: src/doc/PdfPage.cpp =================================================================== --- src/doc/PdfPage.cpp (revisión: 1639) +++ src/doc/PdfPage.cpp (revisión: 1640) @@ -526,7 +526,10 @@ if( pNode->GetDictionary().GetKey( PdfName::KeyType ) != NULL && pNode->GetDictionary().GetKey( PdfName::KeyType )->GetName() == PdfName( "Pages" ) ) { - nPageNumber += static_cast<int>(pNode->GetDictionary().GetKey( "Count" )->GetNumber()); + PdfObject* pCount = pNode->GetIndirectKey( "Count" ); + if( pCount != NULL ) { + nPageNumber += static_cast<int>(pCount->GetNumber()); + } } else { // if we do not have a page tree node, // we most likely have a page object: Index: src/doc/PdfPagesTree.cpp =================================================================== --- src/doc/PdfPagesTree.cpp (revisión: 1639) +++ src/doc/PdfPagesTree.cpp (revisión: 1640) @@ -56,7 +56,7 @@ PdfPagesTree::PdfPagesTree( PdfObject* pPagesRoot ) : PdfElement( "Pages", pPagesRoot ), #- m_cache( static_cast<int>(pPagesRoot->GetDictionary().GetKeyAsLong( "Count", static_cast<pdf_int64>(PODOFO_LL_LITERAL(0)) )) ) - m_cache( static_cast<int>(pPagesRoot->GetDictionary().GetKeyAsLong( "Count", static_cast<pdf_int64>(0LL) )) ) + m_cache( GetChildCount( pPagesRoot ) ) { if( !this->GetObject() ) { @@ -71,8 +71,7 @@ int PdfPagesTree::GetTotalNumberOfPages() const { #- const PdfObject *pObject = GetObject()->GetIndirectKey( "Count" ); #- if ( pObject != NULL ) { #- return (pObject->GetDataType() == ePdfDataType_Number) ? #- static_cast<int>( pObject->GetNumber() ) : 0; #- } else { #- return 0; #- } - return ( ( this->GetObject()->GetDictionary().HasKey( "Count" ) ) ? - static_cast<int>(this->GetObject()->GetDictionary().GetKeyAsLong( "Count", 0LL )) : 0 ); + return GetChildCount( GetObject() ); } PdfPage* PdfPagesTree::GetPage( int nIndex ) @@ -326,7 +325,7 @@ PdfArray::const_iterator it = rKidsArray.begin(); const size_t numDirectKids = rKidsArray.size(); #- const size_t numKids = static_cast<size_t>(pParent->GetDictionary().GetKeyAsLong( "Count", PODOFO_LL_LITERAL(0) )); - const size_t numKids = static_cast<size_t>(pParent->GetDictionary().GetKeyAsLong( "Count", 0LL )); + const size_t numKids = GetChildCount(pParent); if( static_cast<int>(numKids) < nPageNum ) { @@ -374,7 +373,7 @@ if( this->IsTypePages(pChild) ) { - int childCount = this->GetChildCount( pChild ); + int childCount = GetChildCount( pChild ); if( childCount < nPageNum + 1 ) // Pages are 0 based, but count is not { // skip this page node @@ -493,7 +492,13 @@ if( !pNode ) return 0; - return static_cast<int>(pNode->GetDictionary().GetKeyAsLong("Count", 0L)); + const PdfObject *pCount = pNode->GetIndirectKey( "Count" ); + if( pCount != 0 ) { + return (pCount->GetDataType() == PoDoFo::ePdfDataType_Number) ? + static_cast<int>( pCount->GetNumber() ):0; + } else { + return 0; + } } int PdfPagesTree::GetPosInKids( PdfObject* pPageObj, PdfObject* pPageParent ) @@ -697,7 +702,7 @@ { // Increment or decrement inPagesDict's Count by inDelta, and return the new count. // Simply return the current count if inDelta is 0. - int cnt = static_cast<int>(pPageObj->GetDictionary().GetKey( "Count" )->GetNumber()); + int cnt = GetChildCount( pPageObj ); if( 0 != nDelta ) { cnt += nDelta ; @@ -709,7 +714,7 @@ bool PdfPagesTree::IsEmptyPageNode( PdfObject* pPageNode ) { #- long lCount = static_cast<long>(pPageNode->GetDictionary().GetKeyAsLong( PdfName("Count"), static_cast<pdf_int64>(PODOFO_LL_LITERAL(0)) )); - long lCount = static_cast<long>(pPageNode->GetDictionary().GetKeyAsLong( PdfName("Count"), static_cast<pdf_int64>(0LL) )); + long lCount = GetChildCount( pPageNode ); bool bKidsEmpty = true; if( pPageNode->GetDictionary().HasKey( PdfName("Kids") ) ) @@ -736,7 +741,7 @@ PdfArray& kidsArray = pObj->GetArray(); size_t numKids = kidsArray.size(); - size_t kidsCount = pPagesObject->GetDictionary().GetKeyAsLong( "Count", 0 ); + size_t kidsCount = GetChildCount( pPagesObject ); // All parents of the page node will be added to this lists, // so that the PdfPage can later access inherited attributes ------------------------------------------------------------------------
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor