Logo Search packages:      
Sourcecode: libpodofo version File versions  Download package

PoDoFo::PdfXObject::PdfXObject ( const PdfMemDocument rSourceDoc,
int  nPage,
PdfDocument pParent,
const char *  pszPrefix = NULL,
bool  bUseTrimBox = false 
)

Create a new XObject from a page of another document in a given document

Parameters:
rDocthe document to create the XObject from
nPagethe page-number in rDoc to create the XObject from
pParentthe parent document of the XObject
pszPrefixoptional prefix for XObject-name
bUseTrimBoxif true try to use trimbox for size of xobject

Definition at line 55 of file PdfXObject.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::ePdfError_InternalLogic, PoDoFo::PdfDocument::FillXObjectFromDocumentPage(), PoDoFo::PdfRect::GetBottom(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfRect::GetHeight(), PoDoFo::PdfRect::GetLeft(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfDocument::GetPage(), PoDoFo::PdfPage::GetRotation(), PoDoFo::PdfRect::GetWidth(), PODOFO_RAISE_ERROR, PoDoFo::PdfArray::push_back(), PoDoFo::PdfRect::SetBottom(), PoDoFo::PdfRect::SetHeight(), PoDoFo::PdfRect::SetLeft(), PoDoFo::PdfRect::SetWidth(), and PoDoFo::PdfRect::ToVariant().

    : PdfElement( "XObject", pParent ), PdfCanvas()
{
    m_rRect = PdfRect();

    InitXObject( m_rRect, pszPrefix );

    // 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, independent of rotation
    m_rRect = pParent->FillXObjectFromDocumentPage( this, rDoc, nPage, bUseTrimBox );

    PdfVariant    var;
    m_rRect.ToVariant( var );
    this->GetObject()->GetDictionary().AddKey( "BBox", var );

      int rotation = rDoc.GetPage( nPage )->GetRotation();
      // correct negative rotation
      if ( rotation < 0 )
            rotation = 360 + rotation;

      // Swap offsets/width/height for vertical rotation
      switch ( rotation )
      {
            case 90:
            case 270:
            {
                  double temp;
                  
                  temp = m_rRect.GetWidth();
                  m_rRect.SetWidth( m_rRect.GetHeight() );
                  m_rRect.SetHeight( temp );

                  temp = m_rRect.GetLeft();
                  m_rRect.SetLeft( m_rRect.GetBottom() );
                  m_rRect.SetBottom( temp );
            }
            break;
        
            default:
            break;
      }
 
      // Build matrix for rotation and cropping
      double alpha = -rotation / 360.0 * 2.0 * PI;
    
      double a, b, c, d, e, f;
    
      a = cos( alpha );
      b = sin( alpha );
      c = -sin( alpha );
      d = cos( alpha );
 
      switch ( rotation )
      {
            case 90:
                  e = - m_rRect.GetLeft();
                  f = m_rRect.GetBottom() + m_rRect.GetHeight();
            break;
  
            case 180:
                  e = m_rRect.GetLeft() + m_rRect.GetWidth();
                  f = m_rRect.GetBottom() + m_rRect.GetHeight();
            break;
            
            case 270:
                  e = m_rRect.GetLeft() + m_rRect.GetWidth();
                  f = - m_rRect.GetBottom();
            break;
 
            case 0:
            default:
                  e = - m_rRect.GetLeft();
                  f = - m_rRect.GetBottom();
            break;
      }

    PdfArray      matrix;
    matrix.push_back( PdfVariant( a ) );
    matrix.push_back( PdfVariant( b ) );
    matrix.push_back( PdfVariant( c ) );
    matrix.push_back( PdfVariant( d ) );
    matrix.push_back( PdfVariant( e ) );
    matrix.push_back( PdfVariant( f ) );
    
    this->GetObject()->GetDictionary().AddKey( "Matrix", matrix );
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index