PdfRect PdfAnnotation::GetRect() const { if( m_pObject->GetDictionary().HasKey( PdfName::KeyRect ) ) return PdfRect( m_pObject->GetDictionary().GetKey( PdfName::KeyRect )->GetArray() ); return PdfRect(); }
void PdfeGlyphType3::computeBBox() { // Reset bounding boxes to zero. m_bboxD1 = PdfRect( 0, 0, 0, 0 ); m_cbox = PdfRect( 0, 0, 0, 0 ); // Analyse contents stream of the glyph. this->analyseContents( this, PdfeGraphicsState(), PdfeResources( m_pResources ) ); }
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 ); }
void PdfeFontType3::init() { // Initialize members to default values. m_fontDescriptor.init(); m_fontBBox = PdfRect( 0.0, 0.0, 0.0, 0.0 ); m_spaceBBox = PdfRect( 0.0, 0.0, 0.0, 0.0 ); m_fontMatrix.init(); // Last CID < First CID to avoid problems. m_firstCID = 1; m_lastCID = 0; m_advanceCID.clear(); m_mapCIDToGID.clear(); m_glyphs.clear(); }
PdfXObject::PdfXObject( PdfObject* pObject ) : PdfElement( "XObject", pObject ), PdfCanvas() { ostringstream out; PdfLocaleImbue(out); // Implementation note: the identifier is always // Prefix+ObjectNo. Prefix is /XOb for XObject. out << "XOb" << m_pObject->Reference().ObjectNumber(); m_pResources = pObject->GetIndirectKey( "Resources" ); m_Identifier = PdfName( out.str().c_str() ); m_rRect = PdfRect( m_pObject->GetIndirectKey( "BBox" )->GetArray() ); m_Reference = m_pObject->Reference(); }
void PdfeGlyphType3::fType3Fonts( const PdfeStreamStateOld& streamState ) { // Update d1 bounding box if possible. if( streamState.gOperator.type() == PdfeGOperator::d1 ) { double left, right, bottom, top; size_t nbvars = streamState.gOperands.size(); // Read bbox coordinates. this->readValue( streamState.gOperands[nbvars-4], left ); this->readValue( streamState.gOperands[nbvars-3], bottom ); this->readValue( streamState.gOperands[nbvars-2], right ); this->readValue( streamState.gOperands[nbvars-1], top ); m_bboxD1 = PdfRect( left, bottom, right-left, top-bottom ); } }
const PdfRect PdfeGlyphType3::GetPageSize() const { // Don't care... return PdfRect( 0, 0, 0, 0 ); }
//**********************************************************// // PdfeFontType3 // //**********************************************************// PdfeFontType3::PdfeFontType3( PoDoFo::PdfObject* pFont, FT_Library ftLibrary ) : PdfeFont( pFont, ftLibrary ) { this->init(); // Subtype of the font. const PdfName& subtype = pFont->GetIndirectKey( PdfName::KeySubtype )->GetName(); if( subtype == PdfName( "Type3" ) ) { this->setType( PdfeFontType::Type3 ); this->setSubtype( PdfeFontSubType::Type3 ); } else { PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidDataType, "The PdfObject is not a Type 3 font." ); } // Need the following entries in the font dictionary. PdfObject* pBBox = pFont->GetIndirectKey( "FontBBox" ); PdfObject* pMatrix = pFont->GetIndirectKey( "FontMatrix" ); PdfObject* pFChar = pFont->GetIndirectKey( "FirstChar" ); PdfObject* pLChar = pFont->GetIndirectKey( "LastChar" ); PdfObject* pWidths = pFont->GetIndirectKey( "Widths" ); PdfObject* pEncoding = pFont->GetIndirectKey( "Encoding" ); // If does not exist: raise exception. if( !( pBBox && pMatrix && pFChar && pLChar && pWidths && pEncoding ) ) { PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidDataType, "Entries missing in the Type 3 font dictionary." ); } // Initialize font BBox from array. m_fontBBox = PdfRect( pBBox->GetArray() ); // Font matrix. const PdfArray& matrixA = pMatrix->GetArray(); m_fontMatrix(0,0) = matrixA[0].GetReal(); m_fontMatrix(0,1) = matrixA[1].GetReal(); m_fontMatrix(1,0) = matrixA[2].GetReal(); m_fontMatrix(1,1) = matrixA[3].GetReal(); m_fontMatrix(2,0) = matrixA[4].GetReal(); m_fontMatrix(2,1) = matrixA[5].GetReal(); // Read char widths. m_firstCID = static_cast<pdfe_cid>( pFChar->GetNumber() ); m_lastCID = static_cast<pdfe_cid>( pLChar->GetNumber() ); const PdfArray& widthsA = pWidths->GetArray(); m_advanceCID.resize( widthsA.size(), PdfeVector() ); for( size_t i = 0 ; i < widthsA.size() ; ++i ) { m_advanceCID[i](0) = widthsA[i].GetReal(); } // Check the size for coherence. if( m_advanceCID.size() != static_cast<size_t>( m_lastCID - m_firstCID + 1 ) ) { m_advanceCID.resize( m_lastCID - m_firstCID + 1, PdfeVector( 1000., 0. ) ); } // Font descriptor (required in Tagged documents). PdfObject* pDescriptor = pFont->GetIndirectKey( "FontDescriptor" ); if( pDescriptor ) { m_fontDescriptor.init( pDescriptor ); } // Font encoding. this->initEncoding( pEncoding ); // Unicode CMap. PdfObject* pUnicodeCMap = pFont->GetIndirectKey( "ToUnicode" ); this->initUnicodeCMap( pUnicodeCMap ); // Space characters vector. this->initSpaceCharacters( m_firstCID, m_lastCID, true ); // Glyph vectors. this->initGlyphs( pFont ); // Default space bounding box. this->initSpaceBBox(); // Log font information. this->initLogInformation(); }
void PdfTable::Draw( double dX, double dY, PdfPainter* pPainter, const PdfRect & rClipRect, double* pdLastX, double* pdLastY ) { if( !pPainter ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } //RG: TODO Should dCurY variable be initialised with 0? (line 257 may fall through without initialisation!) int i = 0; int j = 0; double dCurX = 0.0; double dCurY = 0.0; double dWidth = 0.0; double dHeight = 0.0; double dVertical = 0.0; double* pdColWidths = new double[this->GetCols()]; double* pdRowHeights = new double[this->GetRows()]; bool bBorders = !m_pModel || (m_pModel && m_pModel->HasBorders() ); // Calculate all necessary sizes this->CalculateTableSize( dX, dY, pPainter->GetPage(), pdColWidths, pdRowHeights, &dWidth, &dHeight ); if( !(!static_cast<int>(rClipRect.GetBottom()) && !static_cast<int>(rClipRect.GetLeft()) && !static_cast<int>(rClipRect.GetWidth()) && !static_cast<int>(rClipRect.GetWidth())) ) m_curClipRect = rClipRect; else { m_curClipRect = PdfRect( 0.0, dX, pPainter->GetPage()->GetPageSize().GetWidth() - dX, dY ); } // Draw the table pPainter->Save(); PdfFont* pDefaultFont = pPainter->GetFont(); // get the default font PdfFont* pFont; // draw contents if( m_pModel ) { pPainter->SetStrokeWidth( m_pModel->GetBorderWidth() ); if( bBorders ) // draw top border this->DrawHorizontalBorders( 0, dX, dY, pPainter, pdColWidths ); for( j=0;j<m_nRows;j++ ) { if( this->CheckForNewPage( &dY, &dCurY, pdRowHeights[j], pPainter ) && bBorders ) // draw top border on new page this->DrawHorizontalBorders( j, dX, dY, pPainter, pdColWidths ); dCurX = 0.0; dCurY += pdRowHeights[j]; for( i=0;i<m_nCols;i++ ) { // set a clipping rectangle pPainter->Save(); pPainter->SetClipRect( dX + dCurX, dY - dCurY, pdColWidths[i], pdRowHeights[j] ); // Draw background double dBorder = bBorders ? m_pModel->GetBorderWidth()/2.0 : 0.0; if( m_pModel->HasBackgroundColor( i, j ) ) { pPainter->Save(); pPainter->SetColor( m_pModel->GetBackgroundColor( i, j ) ); // Make sure that FillRect only fills inside the border // rectangle and not over the border. This is necessary // because we draw the border first and than the contents. pPainter->FillRect( dX + dCurX + dBorder, dY - dCurY + dBorder, pdColWidths[i] - 2.0 * dBorder, pdRowHeights[j] - 2.0 * dBorder ); pPainter->Restore(); } // draw an image PdfImage* pImage = m_pModel->GetImage( i, j ); double dImageWidth = 0.0; if( m_pModel->HasImage( i, j ) && pImage ) { double dScaleX = (pdColWidths[i]) / pImage->GetPageSize().GetWidth(); double dScaleY = (pdRowHeights[j] - 2.0 * dBorder) / pImage->GetPageSize().GetHeight(); double dScale = PDF_MIN( dScaleX, dScaleY ); dImageWidth = pImage->GetPageSize().GetWidth() * dScale; pPainter->DrawImage( dX + dCurX, dY - dCurY + dBorder, pImage, dScale, dScale ); } // Set the correct font pFont = m_pModel->GetFont( i, j ); pFont = pFont ? pFont : pDefaultFont; pPainter->SetFont( pFont ); pPainter->SetColor( m_pModel->GetForegroundColor( i, j ) ); // draw text if( m_pModel->HasWordWrap( i, j ) ) { // Make sure we have at least 1 dot free space at each side of the rectangle pPainter->DrawMultiLineText( dX + dCurX + 1.0 + dImageWidth, dY - dCurY, pdColWidths[i] - 2.0 - dImageWidth, pdRowHeights[j], m_pModel->GetText( i, j ), m_pModel->GetAlignment( i, j ), m_pModel->GetVerticalAlignment( i, j ) ); } else { // calculate vertical alignment switch( m_pModel->GetVerticalAlignment( i, j ) ) { default: case ePdfVerticalAlignment_Top: dVertical = 0.0; break; case ePdfVerticalAlignment_Center: dVertical = (pdRowHeights[j] - pFont->GetFontMetrics()->GetLineSpacing()) / 2.0; break; case ePdfVerticalAlignment_Bottom: dVertical = (pdRowHeights[j] - pFont->GetFontMetrics()->GetLineSpacing()); break; } // Make sure we have at least 1 dot free space at each side of the rectangle pPainter->DrawTextAligned( dX + dCurX + 1 + dImageWidth, dY - dCurY + dVertical, pdColWidths[i] - 2.0 - dImageWidth, m_pModel->GetText( i, j ), m_pModel->GetAlignment( i, j ) ); } pPainter->Restore(); if( bBorders ) // draw left x border { // use always the border color of the left to the current cell pPainter->SetStrokingColor( m_pModel->GetBorderColor( i>0 ? i-1 : i, j ) ); pPainter->DrawLine( dX + dCurX, dY - dCurY, dX + dCurX, dY - dCurY + pdRowHeights[j] ); } dCurX += pdColWidths[i]; } if( bBorders ) { // Draw last X border if( i > 0 ) { pPainter->SetStrokingColor( m_pModel->GetBorderColor( i-1, j ) ); pPainter->DrawLine( dX + dCurX, dY - dCurY, dX + dCurX, dY - dCurY + pdRowHeights[j] ); } // draw border below row this->DrawHorizontalBorders( j, dX, dY - dCurY, pPainter, pdColWidths ); } } } pPainter->Restore(); if( pdLastX ) *pdLastX = dX + dWidth; if( pdLastY ) *pdLastY = dY - dCurY; // Free allocated memory delete [] pdColWidths; delete [] pdRowHeights; }