void PdfFontMetricsFreetype::GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast ) const { unsigned int i; PdfArray list; if( !m_pFace ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } for( i=nFirst;i<=nLast;i++ ) { if( i < PODOFO_WIDTH_CACHE_SIZE ) list.push_back( PdfVariant( m_vecWidth[i] ) ); else { if( !FT_Load_Char( m_pFace, i, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP ) ) // | FT_LOAD_NO_RENDER { //PODOFO_RAISE_ERROR( ePdfError_FreeType ); list.push_back( PdfVariant( 0.0 ) ); continue; } list.push_back( PdfVariant( m_pFace->glyph->metrics.horiAdvance * 1000.0 / m_pFace->units_per_EM ) ); } } var = PdfVariant( list ); }
void PdfAnnotation::SetColor( double r, double g, double b ) { PdfArray c; c.push_back( PdfVariant( r ) ); c.push_back( PdfVariant( g ) ); c.push_back( PdfVariant( b ) ); m_pObject->GetDictionary().AddKey( "C", c ); }
void PdfSignOutputDevice::AdjustByteRange() { if(!m_bBeaconFound) { PODOFO_RAISE_ERROR( ePdfError_InternalLogic ); } // Get final position size_t sFileEnd = GetLength(); PdfArray arr; arr.push_back( PdfVariant(static_cast<pdf_int64>(0)) ); arr.push_back( PdfVariant(static_cast<pdf_int64>(m_sBeaconPos)) ); arr.push_back( PdfVariant(static_cast<pdf_int64>(m_sBeaconPos+m_pSignatureBeacon->data().size()+2) ) ); arr.push_back( PdfVariant(static_cast<pdf_int64>(sFileEnd-(m_sBeaconPos+m_pSignatureBeacon->data().size()+2)) ) ); std::string sPosition; PdfVariant(arr).ToString(sPosition, ePdfWriteMode_Compact); // Fill padding unsigned int sPosSize = sizeof("[ 0 1234567890 1234567890 1234567890]")-1; if(sPosition.size()<sPosSize) { // drop last ']' sPosition.resize(sPosition.size()-1); while(sPosition.size()<(sPosSize-1)) { sPosition+=' '; } sPosition+=']'; } m_pRealDevice->Seek(m_sBeaconPos-sPosition.size()-9); m_pRealDevice->Write(sPosition.c_str(), sPosition.size()); }
void PdfAnnotation::SetColor( double C, double M, double Y, double K ) { PdfArray c; c.push_back( PdfVariant( C ) ); c.push_back( PdfVariant( M ) ); c.push_back( PdfVariant( Y ) ); c.push_back( PdfVariant( K ) ); m_pObject->GetDictionary().AddKey( "C", c ); }
void PdfFontSimple::Init( bool bEmbed, const PdfName & rsSubType ) { PdfObject* pWidth; PdfObject* pDescriptor; PdfVariant var; PdfArray array; pWidth = this->GetObject()->GetOwner()->CreateObject(); if( !pWidth ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } m_pMetrics->GetWidthArray( *pWidth, m_pEncoding->GetFirstChar(), m_pEncoding->GetLastChar(), m_pEncoding ); pDescriptor = this->GetObject()->GetOwner()->CreateObject( "FontDescriptor" ); if( !pDescriptor ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } std::string name; if ( m_bIsSubsetting ) name = this->GetObject()->GetOwner()->GetNextSubsetPrefix(); name += this->GetBaseFont().GetName(); this->GetObject()->GetDictionary().AddKey( PdfName::KeySubtype, rsSubType ); this->GetObject()->GetDictionary().AddKey("BaseFont", PdfName( name ) ); this->GetObject()->GetDictionary().AddKey("FirstChar", PdfVariant( static_cast<pdf_int64>(m_pEncoding->GetFirstChar()) ) ); this->GetObject()->GetDictionary().AddKey("LastChar", PdfVariant( static_cast<pdf_int64>(m_pEncoding->GetLastChar()) ) ); m_pEncoding->AddToDictionary( this->GetObject()->GetDictionary() ); // Add encoding key this->GetObject()->GetDictionary().AddKey("Widths", pWidth->Reference() ); this->GetObject()->GetDictionary().AddKey( "FontDescriptor", pDescriptor->Reference() ); m_pMetrics->GetBoundingBox( array ); pDescriptor->GetDictionary().AddKey( "FontName", PdfName( name ) ); //pDescriptor->GetDictionary().AddKey( "FontWeight", (long)m_pMetrics->Weight() ); pDescriptor->GetDictionary().AddKey( PdfName::KeyFlags, PdfVariant( static_cast<pdf_int64>(PODOFO_LL_LITERAL(32)) ) ); // TODO: 0 ???? pDescriptor->GetDictionary().AddKey( "FontBBox", array ); pDescriptor->GetDictionary().AddKey( "ItalicAngle", PdfVariant( static_cast<pdf_int64>(m_pMetrics->GetItalicAngle()) ) ); pDescriptor->GetDictionary().AddKey( "Ascent", m_pMetrics->GetPdfAscent() ); pDescriptor->GetDictionary().AddKey( "Descent", m_pMetrics->GetPdfDescent() ); pDescriptor->GetDictionary().AddKey( "CapHeight", m_pMetrics->GetPdfAscent() ); // m_pMetrics->CapHeight() ); pDescriptor->GetDictionary().AddKey( "StemV", PdfVariant( static_cast<pdf_int64>(PODOFO_LL_LITERAL(1)) ) ); // m_pMetrics->StemV() ); // Peter Petrov 24 September 2008 m_pDescriptor = pDescriptor; if( bEmbed ) { this->EmbedFontFile( pDescriptor ); m_bWasEmbedded = true; } }
void PdfExtGState::SetFrequency( double frequency ) { PdfDictionary halftoneDict; halftoneDict.AddKey( "HalftoneType", PdfVariant( 1LL ) ); halftoneDict.AddKey( "Frequency", PdfVariant( frequency ) ); halftoneDict.AddKey( "Angle", PdfVariant( 45.0 ) ); halftoneDict.AddKey( "SpotFunction", PdfName( "SimpleDot" ) ); m_pObject->GetDictionary().AddKey( "HT", halftoneDict); }
void PdfExtGState::SetFrequency( double frequency ) { PdfDictionary halftoneDict; halftoneDict.AddKey( "HalftoneType", PdfVariant( static_cast<pdf_int64>(PODOFO_LL_LITERAL(1)) ) ); halftoneDict.AddKey( "Frequency", PdfVariant( frequency ) ); halftoneDict.AddKey( "Angle", PdfVariant( 45.0 ) ); halftoneDict.AddKey( "SpotFunction", PdfName( "SimpleDot" ) ); this->GetObject()->GetDictionary().AddKey( "HT", halftoneDict); }
void PdfFontMetricsFreetype::GetBoundingBox( PdfArray & array ) const { if( !m_pFace ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } array.Clear(); array.push_back( PdfVariant( m_pFace->bbox.xMin * 1000.0 / m_pFace->units_per_EM ) ); array.push_back( PdfVariant( m_pFace->bbox.yMin * 1000.0 / m_pFace->units_per_EM ) ); array.push_back( PdfVariant( m_pFace->bbox.xMax * 1000.0 / m_pFace->units_per_EM ) ); array.push_back( PdfVariant( m_pFace->bbox.yMax * 1000.0 / m_pFace->units_per_EM ) ); }
PdfXObject::PdfXObject( const PdfMemDocument & rDoc, int nPage, PdfDocument* pParent ) : PdfElement( "XObject", pParent ), PdfCanvas() { m_rRect = PdfRect(); InitXObject( m_rRect, "XObInd" ); // Implementation note: source document must be different from distination if ( pParent == reinterpret_cast<const PdfDocument*>(&rDoc) ) { PODOFO_RAISE_ERROR( ePdfError_InternalLogic ); } // After filling set correct BBox m_rRect = pParent->FillXObjectFromDocumentPage( this, rDoc, nPage ); PdfVariant var; m_rRect.ToVariant( var ); m_pObject->GetDictionary().AddKey( "BBox", var ); PdfArray matrix; matrix.push_back( PdfVariant( 1LL ) ); matrix.push_back( PdfVariant( 0LL ) ); matrix.push_back( PdfVariant( 0LL ) ); matrix.push_back( PdfVariant( 1LL ) ); if( m_rRect.GetLeft() != 0 ) matrix.push_back( PdfVariant( m_rRect.GetLeft() * (-1.0) ) ); else matrix.push_back( PdfVariant( 0LL ) ); if( m_rRect.GetBottom() != 0 ) matrix.push_back( PdfVariant( m_rRect.GetBottom() * (-1.0) ) ); else matrix.push_back( PdfVariant( 0LL ) ); m_pObject->GetDictionary().AddKey( "Matrix", matrix ); }
PdfFileStream::PdfFileStream( PdfObject* pParent, PdfOutputDevice* pDevice ) : PdfStream( pParent ), m_pDevice( pDevice ), m_pStream( NULL ), m_pDeviceStream( NULL ), m_pEncryptStream( NULL ), m_lLenInitial( 0 ), m_lLength( 0 ), m_pCurEncrypt( NULL ) { m_pLength = pParent->GetOwner()->CreateObject( PdfVariant(static_cast<pdf_int64>(PODOFO_LL_LITERAL(0))) ); m_pParent->GetDictionary().AddKey( PdfName::KeyLength, m_pLength->Reference() ); }
void PdfFontTrueType::EmbedFontFile( PdfObject* pDescriptor ) { PdfObject* pContents; pdf_long lSize = 0; m_bWasEmbedded = true; pContents = this->GetObject()->GetOwner()->CreateObject(); if( !pContents ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } pDescriptor->GetDictionary().AddKey( "FontFile2", pContents->Reference() ); // if the data was loaded from memory - use it from there // otherwise, load from disk if ( m_pMetrics->GetFontDataLen() && m_pMetrics->GetFontData() ) { // FIXME const_cast<char*> is dangerous if string literals may ever be passed char* pBuffer = const_cast<char*>( m_pMetrics->GetFontData() ); lSize = m_pMetrics->GetFontDataLen(); // Set Length1 before creating the stream // as PdfStreamedDocument does not allow // adding keys to an object after a stream was written pContents->GetDictionary().AddKey( "Length1", PdfVariant( static_cast<pdf_int64>(lSize) ) ); pContents->GetStream()->Set( pBuffer, lSize ); } else { PdfFileInputStream stream( m_pMetrics->GetFilename() ); lSize = stream.GetFileLength(); // Set Length1 before creating the stream // as PdfStreamedDocument does not allow // adding keys to an object after a stream was written pContents->GetDictionary().AddKey( "Length1", PdfVariant( static_cast<pdf_int64>(lSize) ) ); pContents->GetStream()->Set( &stream ); } }
int PdfPagesTree::ChangePagesCount( PdfObject* pPageObj, int nDelta ) { // Increment or decrement inPagesDict's Count by inDelta, and return the new count. // Simply return the current count if inDelta is 0. int cnt = GetChildCount( pPageObj ); if( 0 != nDelta ) { cnt += nDelta ; pPageObj->GetDictionary().AddKey( "Count", PdfVariant( static_cast<pdf_int64>(cnt) ) ); } return cnt ; }
const PdfStream & PdfMemStream::operator=( const PdfStream & rhs ) { const PdfMemStream* pStream = dynamic_cast<const PdfMemStream*>(&rhs); if( pStream ) m_buffer = pStream->m_buffer; else return PdfStream::operator=( rhs ); m_lLength = rhs.GetLength(); if( m_pParent ) m_pParent->GetDictionary().AddKey( PdfName::KeyLength, PdfVariant( static_cast<pdf_int64>(m_lLength) ) ); return *this; }
void PdfXObject::InitXObject( const PdfRect & rRect, const char* pszPrefix ) { PdfVariant var; ostringstream out; PdfLocaleImbue(out); // Initialize static data if( s_matrix.empty() ) { // This matrix is the same for all PdfXObjects so cache it s_matrix.push_back( PdfVariant( 1LL ) ); s_matrix.push_back( PdfVariant( 0LL ) ); s_matrix.push_back( PdfVariant( 0LL ) ); s_matrix.push_back( PdfVariant( 1LL ) ); s_matrix.push_back( PdfVariant( 0LL ) ); s_matrix.push_back( PdfVariant( 0LL ) ); } rRect.ToVariant( var ); m_pObject->GetDictionary().AddKey( "BBox", var ); m_pObject->GetDictionary().AddKey( PdfName::KeySubtype, PdfName("Form") ); m_pObject->GetDictionary().AddKey( "FormType", PdfVariant( 1LL ) ); // only 1 is only defined in the specification. m_pObject->GetDictionary().AddKey( "Matrix", s_matrix ); // The PDF specification suggests that we send all available PDF Procedure sets m_pObject->GetDictionary().AddKey( "Resources", PdfObject( PdfDictionary() ) ); m_pResources = m_pObject->GetDictionary().GetKey( "Resources" ); m_pResources->GetDictionary().AddKey( "ProcSet", PdfCanvas::GetProcSet() ); // Implementation note: the identifier is always // Prefix+ObjectNo. Prefix is /XOb for XObject. if ( pszPrefix == NULL ) out << "XOb" << m_pObject->Reference().ObjectNumber(); else out << pszPrefix << m_pObject->Reference().ObjectNumber(); m_Identifier = PdfName( out.str().c_str() ); m_Reference = m_pObject->Reference(); }
void PdfMemStream::EndAppendImpl() { if( m_pStream ) { m_pStream->Close(); if( !m_pBufferStream ) m_lLength = dynamic_cast<PdfBufferOutputStream*>(m_pStream)->GetLength(); delete m_pStream; m_pStream = NULL; } if( m_pBufferStream ) { m_pBufferStream->Close(); m_lLength = m_pBufferStream->GetLength(); delete m_pBufferStream; m_pBufferStream = NULL; } if( m_pParent ) m_pParent->GetDictionary().AddKey( PdfName::KeyLength, PdfVariant(static_cast<pdf_int64>(m_lLength) ) ); }
void PdfFontType1::EmbedFontFile( PdfObject* pDescriptor ) { pdf_long lSize = 0; pdf_long lLength1 = 0L; pdf_long lLength2 = 0L; pdf_long lLength3 = 0L; PdfObject* pContents; const char* pBuffer; char* pAllocated = NULL; m_bWasEmbedded = true; pContents = m_pObject->GetOwner()->CreateObject(); if( !pContents ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } pDescriptor->GetDictionary().AddKey( "FontFile", pContents->Reference() ); // if the data was loaded from memory - use it from there // otherwise, load from disk if ( m_pMetrics->GetFontDataLen() && m_pMetrics->GetFontData() ) { pBuffer = m_pMetrics->GetFontData(); lSize = m_pMetrics->GetFontDataLen(); } else { FILE* hFile = fopen( m_pMetrics->GetFilename(), "rb" ); if( !hFile ) { PODOFO_RAISE_ERROR_INFO( ePdfError_FileNotFound, m_pMetrics->GetFilename() ); } fseek( hFile, 0L, SEEK_END ); lSize = ftell( hFile ); fseek( hFile, 0L, SEEK_SET ); pAllocated = static_cast<char*>(malloc( sizeof(char) * lSize )); if( !pAllocated ) { fclose( hFile ); PODOFO_RAISE_ERROR( ePdfError_OutOfMemory ); } fread( pAllocated, sizeof(char), lSize, hFile ); fclose( hFile ); pBuffer = pAllocated; } // Remove binary segment headers from pfb unsigned char *pBinary = reinterpret_cast<unsigned char*>(const_cast<char*>(pBuffer)); while( *pBinary == 0x80 ) // binary segment header { const int cHeaderLength = 6; int iSegmentType = pBinary[1]; // binary segment type long lSegmentLength = 0L; long lSegmentDelta = static_cast<long>(&pBuffer[lSize] - reinterpret_cast<const char*>(pBinary) ); switch( iSegmentType ) { case 1: // ASCII text lSegmentLength = pBinary[2] + // little endian pBinary[3] * 256L + pBinary[4] * 65536L + pBinary[5] * 16777216L; if( lLength1 == 0L ) lLength1 = lSegmentLength; else lLength3 = lSegmentLength; lSize -= cHeaderLength; memmove( pBinary, &pBinary[cHeaderLength], lSegmentDelta ); pBinary = &pBinary[lSegmentLength]; break; case 2: // binary data lSegmentLength = pBinary[2] + // little endian pBinary[3] * 256L + pBinary[4] * 65536L + pBinary[5] * 16777216L; lLength2 = lSegmentLength; lSize -= cHeaderLength; memmove( pBinary, &pBinary[cHeaderLength], lSegmentDelta ); pBinary = &pBinary[lSegmentLength]; break; case 3: // end-of-file pContents->GetStream()->Set( pBuffer, lSize - 2L ); if( pAllocated ) free( pAllocated ); pContents->GetDictionary().AddKey( "Length1", PdfVariant( static_cast<long long>(lLength1) ) ); pContents->GetDictionary().AddKey( "Length2", PdfVariant( static_cast<long long>(lLength2) ) ); pContents->GetDictionary().AddKey( "Length3", PdfVariant( static_cast<long long>(lLength3) ) ); return; default: break; } } // Parse the font data buffer to get the values for length1, length2 and length3 lLength1 = FindInBuffer( "eexec", pBuffer, lSize ); if( lLength1 > 0 ) lLength1 += 6; // 6 == eexec + lf else lLength1 = 0; if( lLength1 ) { lLength2 = FindInBuffer( "cleartomark", pBuffer, lSize ); if( lLength2 > 0 ) lLength2 = lSize - lLength1 - 520; // 520 == 512 + strlen(cleartomark) else lLength1 = 0; } lLength3 = lSize - lLength2 - lLength1; // TODO: Pdf Supports only Type1 fonts with binary encrypted sections and not the hex format pContents->GetStream()->Set( pBuffer, lSize ); if( pAllocated ) free( pAllocated ); pContents->GetDictionary().AddKey( "Length1", PdfVariant( static_cast<long long>(lLength1) ) ); pContents->GetDictionary().AddKey( "Length2", PdfVariant( static_cast<long long>(lLength2) ) ); pContents->GetDictionary().AddKey( "Length3", PdfVariant( static_cast<long long>(lLength3) ) ); }
void PdfFontCID::Init( bool bEmbed ) { PdfObject* pDescriptor; PdfObject* pDescendantFonts; PdfObject* pCIDSystemInfo; PdfObject* pUnicode; PdfVariant var; PdfArray array; // The descendant font is a CIDFont: pDescendantFonts = this->GetObject()->GetOwner()->CreateObject("Font"); pCIDSystemInfo = this->GetObject()->GetOwner()->CreateObject(); pDescriptor = this->GetObject()->GetOwner()->CreateObject("FontDescriptor"); pUnicode = this->GetObject()->GetOwner()->CreateObject(); // The ToUnicode CMap // Now setting each of the entries of the font this->GetObject()->GetDictionary().AddKey( PdfName::KeySubtype, PdfName("Type0") ); this->GetObject()->GetDictionary().AddKey( "BaseFont", this->GetBaseFont() ); this->GetObject()->GetDictionary().AddKey( "ToUnicode", pUnicode->Reference() ); // The encoding is here usually a (Predefined) CMap from PdfIdentityEncoding: m_pEncoding->AddToDictionary( this->GetObject()->GetDictionary() ); // The DecendantFonts, should be an indirect object: array.push_back( pDescendantFonts->Reference() ); this->GetObject()->GetDictionary().AddKey( "DescendantFonts", array ); // Setting the DescendantFonts paras // This is a type2 CIDFont, which is also known as TrueType: pDescendantFonts->GetDictionary().AddKey( PdfName::KeySubtype, PdfName("CIDFontType2") ); // Same base font as the owner font: pDescendantFonts->GetDictionary().AddKey( "BaseFont", this->GetBaseFont() ); // The CIDSystemInfo, should be an indirect object: pDescendantFonts->GetDictionary().AddKey( "CIDSystemInfo", pCIDSystemInfo->Reference() ); // The FontDescriptor, should be an indirect object: pDescendantFonts->GetDictionary().AddKey( "FontDescriptor", pDescriptor->Reference() ); pDescendantFonts->GetDictionary().AddKey( "CIDToGIDMap", PdfName("Identity") ); // Add the width keys this->CreateWidth( pDescendantFonts ); // Create the ToUnicode CMap this->CreateCMap( pUnicode ); // Setting the CIDSystemInfo paras: pCIDSystemInfo->GetDictionary().AddKey( "Registry", PdfString("Adobe") ); pCIDSystemInfo->GetDictionary().AddKey( "Ordering", PdfString("Identity") ); pCIDSystemInfo->GetDictionary().AddKey( "Supplement", PdfVariant(static_cast<pdf_int64>(0LL)) ); // Setting the FontDescriptor paras: array.Clear(); m_pMetrics->GetBoundingBox( array ); pDescriptor->GetDictionary().AddKey( "FontName", this->GetBaseFont() ); pDescriptor->GetDictionary().AddKey( PdfName::KeyFlags, PdfVariant( static_cast<pdf_int64>(32LL) ) ); // TODO: 0 ???? pDescriptor->GetDictionary().AddKey( "FontBBox", array ); pDescriptor->GetDictionary().AddKey( "ItalicAngle", PdfVariant( static_cast<pdf_int64>(m_pMetrics->GetItalicAngle()) ) ); pDescriptor->GetDictionary().AddKey( "Ascent", m_pMetrics->GetPdfAscent() ); pDescriptor->GetDictionary().AddKey( "Descent", m_pMetrics->GetPdfDescent() ); pDescriptor->GetDictionary().AddKey( "CapHeight", m_pMetrics->GetPdfAscent() ); // m_pMetrics->CapHeight() ); pDescriptor->GetDictionary().AddKey( "StemV", PdfVariant( static_cast<pdf_int64>(1LL) ) ); // m_pMetrics->StemV() ); // Peter Petrov 24 September 2008 m_pDescriptor = pDescriptor; if( bEmbed ) { this->EmbedFont( pDescriptor ); m_bWasEmbedded = true; } }
void PdfExtGState::SetStrokeOverprint( bool enable ) { m_pObject->GetDictionary().AddKey( "OP", PdfVariant( enable ) ); }
void PdfExtGState::SetBlendMode( char* blendMode ) { m_pObject->GetDictionary().AddKey( "BM", PdfVariant( PdfName( blendMode ) ) ); }
void PdfExtGState::SetStrokeOpacity( float opac ) { m_pObject->GetDictionary().AddKey( "CA", PdfVariant( opac ) ); }
void PdfExtGState::SetFillOpacity( float opac ) { m_pObject->GetDictionary().AddKey( "ca", PdfVariant( static_cast<double>(opac) ) ); }
void PdfExtGState::SetBlendMode( const char* blendMode ) { this->GetObject()->GetDictionary().AddKey( "BM", PdfVariant( PdfName( blendMode ) ) ); }
void PdfExtGState::SetRenderingIntent( char* intent ) { m_pObject->GetDictionary().AddKey( "RI", PdfVariant( PdfName( intent ) ) ); }
void PdfExtGState::SetNonZeroOverprint( bool enable ) { m_pObject->GetDictionary().AddKey( "OPM", PdfVariant( (enable ? 1LL : 0LL) ) ); }
void PdfAcroForm::SetNeedAppearances( bool bNeedAppearances ) { this->GetObject()->GetDictionary().AddKey( PdfName("NeedAppearances"), PdfVariant(bNeedAppearances) ); }
void PdfMemStream::FlateCompress() { PdfObject* pObj; PdfVariant vFilter( PdfName("FlateDecode" ) ); PdfVariant vFilterList; PdfArray tFilters; PdfArray::const_iterator tciFilters; if( !m_lLength ) return; // ePdfError_ErrOk // TODO: Handle DecodeParms if( m_pParent->GetDictionary().HasKey( "Filter" ) ) { pObj = m_pParent->GetIndirectKey( "Filter" ); if( pObj->IsName() ) { if( pObj->GetName() != "DCTDecode" && pObj->GetName() != "FlateDecode" ) { tFilters.push_back( vFilter ); tFilters.push_back( *pObj ); } } else if( pObj->IsArray() ) { tciFilters = pObj->GetArray().begin(); while( tciFilters != pObj->GetArray().end() ) { if( (*tciFilters).IsName() ) { // do not compress DCTDecoded are already FlateDecoded streams again if( (*tciFilters).GetName() == "DCTDecode" || (*tciFilters).GetName() == "FlateDecode" ) { return; } } ++tciFilters; } tFilters.push_back( vFilter ); tciFilters = pObj->GetArray().begin(); while( tciFilters != pObj->GetArray().end() ) { tFilters.push_back( (*tciFilters) ); ++tciFilters; } } else return; vFilterList = PdfVariant( tFilters ); m_pParent->GetDictionary().AddKey( "Filter", vFilterList ); FlateCompressStreamData(); // throws an exception on error } else { m_pParent->GetDictionary().AddKey( "Filter", PdfName( "FlateDecode" ) ); FlateCompressStreamData(); } }
void PdfExtGState::SetRenderingIntent( const char* intent ) { this->GetObject()->GetDictionary().AddKey( "RI", PdfVariant( PdfName( intent ) ) ); }
PdfFontMetricsObject::PdfFontMetricsObject( PdfObject* pFont, PdfObject* pDescriptor, const PdfEncoding* const pEncoding ) : PdfFontMetrics( ePdfFontType_Unknown, "", NULL ), m_pEncoding( pEncoding ), m_dDefWidth(0.0) { if( !pDescriptor ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } const PdfName & rSubType = pFont->GetDictionary().GetKey( 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("TrueType") ) { m_sName = pDescriptor->GetIndirectKey( "FontName" )->GetName(); m_bbox = pDescriptor->GetIndirectKey( "FontBBox" )->GetArray(); m_nFirst = static_cast<int>(pFont->GetDictionary().GetKeyAsLong( "FirstChar", 0L )); m_nLast = static_cast<int>(pFont->GetDictionary().GetKeyAsLong( "LastChar", 0L )); // OC 15.08.2010 BugFix: GetIndirectKey() instead of GetDictionary().GetKey() and "Widths" instead of "Width" PdfObject* widths = pFont->GetIndirectKey( "Widths" ); if( widths != NULL ) { m_width = widths->GetArray(); m_missingWidth = NULL; } else { widths = pDescriptor->GetDictionary().GetKey( "MissingWidth" ); if( widths == NULL ) { PODOFO_RAISE_ERROR_INFO( ePdfError_NoObject, "Font object defines neither Widths, nor MissingWidth values!" ); m_missingWidth = widths; } } } else if ( rSubType == PdfName("CIDFontType0") || rSubType == PdfName("CIDFontType2") ) { PdfObject *pObj = pDescriptor->GetIndirectKey( "FontName" ); if (pObj) { m_sName = pObj->GetName(); } pObj = pDescriptor->GetIndirectKey( "FontBBox" ); if (pObj) { m_bbox = pObj->GetArray(); } m_nFirst = 0; m_nLast = 0; m_dDefWidth = static_cast<double>(pFont->GetDictionary().GetKeyAsLong( "DW", 1000L )); PdfVariant default_width(m_dDefWidth); PdfObject * pw = pFont->GetIndirectKey( "W" ); for (int i = m_nFirst; i <= m_nLast; ++i) { m_width.push_back(default_width); } if (pw) { PdfArray w = pw->GetArray(); int pos = 0; while (pos < static_cast<int>(w.GetSize())) { int start = static_cast<int>(w[pos++].GetNumber()); PODOFO_ASSERT (start >= 0); if (w[pos].IsArray()) { PdfArray widths = w[pos++].GetArray(); int length = start + static_cast<int>(widths.GetSize()); PODOFO_ASSERT (length >= start); if (length > static_cast<int>(m_width.GetSize())) { m_width.resize(length, default_width); } for (int i = 0; i < static_cast<int>(widths.GetSize()); ++i) { m_width[start + i] = widths[i]; } } else { int end = static_cast<int>(w[pos++].GetNumber()); int length = start + end; PODOFO_ASSERT (length >= start); if (length > static_cast<int>(m_width.GetSize())) { m_width.resize(length, default_width); } pdf_int64 width = w[pos++].GetNumber(); for (int i = start; i <= end; ++i) m_width[i] = PdfVariant(width); } } } m_nLast = m_width.GetSize() - 1; } else { PODOFO_RAISE_ERROR_INFO( ePdfError_UnsupportedFontFormat, rSubType.GetEscapedName().c_str() ); } 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_dAscent = m_dPdfAscent / 1000.0; m_dPdfDescent = pDescriptor->GetDictionary().GetKeyAsReal( "Descent", 0.0 ); m_dDescent = m_dPdfDescent / 1000.0; m_dLineSpacing = m_dAscent + m_dDescent; // Try to fine some sensible values m_dUnderlineThickness = 1.0; m_dUnderlinePosition = 0.0; m_dStrikeOutThickness = m_dUnderlinePosition; m_dStrikeOutPosition = m_dAscent / 2.0; m_bSymbol = false; // TODO }
void PdfAnnotation::SetFlags( pdf_uint32 uiFlags ) { m_pObject->GetDictionary().AddKey( "F", PdfVariant( static_cast<long long>(uiFlags) ) ); }
void PdfExtGState::SetNonZeroOverprint( bool enable ) { this->GetObject()->GetDictionary().AddKey( "OPM", PdfVariant( static_cast<pdf_int64>(enable ? PODOFO_LL_LITERAL(1) : PODOFO_LL_LITERAL(0)) ) ); }