void PdfPagesTree::InsertPageIntoNode( PdfObject* pParent, const PdfObjectList & rlstParents, int nIndex, PdfObject* pPage ) { if( !pParent || !pPage ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } // 1. Add the reference of the new page to the kids array of pParent // 2. Increase count of every node in lstParents (which also includes pParent) // 3. Add Parent key to the page // 1. Add reference const PdfArray oldKids = pParent->GetDictionary().GetKey( PdfName("Kids") )->GetArray(); PdfArray::const_iterator it = oldKids.begin(); PdfArray newKids; newKids.reserve( oldKids.GetSize() + 1 ); if( nIndex < 0 ) { newKids.push_back( pPage->Reference() ); } int i = 0; while( it != oldKids.end() ) { newKids.push_back( *it ); if( i == nIndex ) newKids.push_back( pPage->Reference() ); ++i; ++it; } /* PdfVariant var2( newKids ); std::string str2; var2.ToString(str2); printf("newKids= %s\n", str2.c_str() ); */ pParent->GetDictionary().AddKey( PdfName("Kids"), newKids ); // 2. increase count PdfObjectList::const_reverse_iterator itParents = rlstParents.rbegin(); while( itParents != rlstParents.rend() ) { this->ChangePagesCount( *itParents, 1 ); ++itParents; } // 3. add parent key to the page pPage->GetDictionary().AddKey( PdfName("Parent"), pParent->Reference() ); }
void PdfPagesTree::InsertPagesIntoNode( PdfObject* pParent, const PdfObjectList & rlstParents, int nIndex, const std::vector<PdfObject*>& vecPages ) { if( !pParent || !vecPages.size() ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } // 1. Add the reference of the new page to the kids array of pParent // 2. Increase count of every node in lstParents (which also includes pParent) // 3. Add Parent key to the page // 1. Add reference const PdfArray oldKids = pParent->GetDictionary().GetKey( PdfName("Kids") )->GetArray(); PdfArray newKids; newKids.reserve( oldKids.GetSize() + vecPages.size() ); bool bIsPushedIn = false; int i=0; for (PdfArray::const_iterator it=oldKids.begin(); it!=oldKids.end(); ++it, ++i ) { if ( !bIsPushedIn && (nIndex < i) ) // Pushing before { for (std::vector<PdfObject*>::const_iterator itPages=vecPages.begin(); itPages!=vecPages.end(); ++itPages) { newKids.push_back( (*itPages)->Reference() ); // Push all new kids at once } bIsPushedIn = true; } newKids.push_back( *it ); // Push in the old kids } // If new kids are still not pushed in then they may be appending to the end if ( !bIsPushedIn && ( (nIndex + 1) == static_cast<int>(oldKids.size())) ) { for (std::vector<PdfObject*>::const_iterator itPages=vecPages.begin(); itPages!=vecPages.end(); ++itPages) { newKids.push_back( (*itPages)->Reference() ); // Push all new kids at once } bIsPushedIn = true; } pParent->GetDictionary().AddKey( PdfName("Kids"), newKids ); // 2. increase count for ( PdfObjectList::const_reverse_iterator itParents = rlstParents.rbegin(); itParents != rlstParents.rend(); ++itParents ) { this->ChangePagesCount( *itParents, vecPages.size() ); } // 3. add parent key to each of the pages for (std::vector<PdfObject*>::const_iterator itPages=vecPages.begin(); itPages!=vecPages.end(); ++itPages) { (*itPages)->GetDictionary().AddKey( PdfName("Parent"), pParent->Reference() ); } }
void PdfStitchingFunction::Init( const PdfFunction::List & rlstFunctions, const PdfArray & rBounds, const PdfArray & rEncode ) { PdfArray functions; PdfFunction::List::const_iterator it = rlstFunctions.begin(); functions.reserve( rlstFunctions.size() ); while( it != rlstFunctions.end() ) { functions.push_back( (*it).GetObject()->Reference() ); ++it; } this->GetObject()->GetDictionary().AddKey( PdfName("Functions"), functions ); this->GetObject()->GetDictionary().AddKey( PdfName("Bounds"), rBounds ); this->GetObject()->GetDictionary().AddKey( PdfName("Encode"), rEncode ); }
void PdfFontCID::CreateWidth( PdfObject* pFontDict ) const { const int cAbsoluteMax = 0xffff; int nFirstChar = m_pEncoding->GetFirstChar(); int nLastChar = m_pEncoding->GetLastChar(); int i; // Allocate an initialize an array, large enough to // hold a width value for every possible glyph index double* pdWidth = static_cast<double*>(malloc( sizeof(double) * cAbsoluteMax ) ); if( !pdWidth ) { PODOFO_RAISE_ERROR( ePdfError_OutOfMemory ); } for( i=0;i<cAbsoluteMax;i++ ) pdWidth[i] = 0.0; // Load the width of all requested glyph indeces int nMin = 0xffff; int nMax = 0; long lGlyph = 0; for( i=nFirstChar;i<=nLastChar;i++ ) { lGlyph = m_pMetrics->GetGlyphId( i ); if( lGlyph ) { nMin = PDF_MIN( static_cast<long>(nMin), lGlyph ); nMax = PDF_MAX( static_cast<long>(nMax), lGlyph ); nMax = PDF_MIN( nMax, cAbsoluteMax ); if( lGlyph < cAbsoluteMax ) pdWidth[lGlyph] = m_pMetrics->GetGlyphWidth( lGlyph ); } } if (nMax >= nMin) { // Now compact the array std::ostringstream oss; PdfArray array; array.reserve( nMax - nMin + 1 ); i = nMin; double dCurWidth = pdWidth[i]; pdf_int64 lCurIndex = i++; pdf_int64 lCurLength = 1L; for( ;i<=nMax;i++ ) { if( static_cast<int>(pdWidth[i] - dCurWidth) == 0 ) ++lCurLength; else { if( lCurLength > 1 ) { array.push_back( lCurIndex ); pdf_int64 temp = lCurIndex + lCurLength - 1; array.push_back( temp ); array.push_back( dCurWidth ); } else { if( array.size() && array.back().IsArray() ) { array.back().GetArray().push_back( dCurWidth ); } else { PdfArray tmp; tmp.push_back( dCurWidth ); array.push_back( lCurIndex ); array.push_back( tmp ); } } lCurIndex = i; lCurLength = 1L; dCurWidth = pdWidth[i]; } } if (array.size() == 0) { array.push_back( lCurIndex = nMin ); array.push_back( lCurIndex = nMax ); array.push_back( dCurWidth ); } pFontDict->GetDictionary().AddKey( PdfName("W"), array ); } free( pdWidth ); }