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

void PoDoFo::PdfOutputDevice::Print ( const char *  pszFormat,
  ... 
) [virtual]

Write to the PdfOutputDevice. Usage is as the usage of printf.

WARNING: Do not use this for doubles or floating point values as the output might depend on the current locale.

Parameters:
pszFormata format string as you would use it with printf
Returns:
ErrOk on success
See also:
Write

Definition at line 133 of file PdfOutputDevice.cpp.

References PoDoFo::ePdfError_InvalidHandle, PoDoFo::ePdfError_OutOfMemory, PoDoFo::ePdfError_UnexpectedEOF, PoDoFo::PdfRefCountedBuffer::GetBuffer(), PoDoFo::PdfRefCountedBuffer::GetSize(), PODOFO_RAISE_ERROR, and PoDoFo::PdfRefCountedBuffer::Resize().

Referenced by PoDoFo::PdfXRef::BeginWrite(), PoDoFo::PdfImmediateWriter::Finish(), PoDoFo::PdfImmediateWriter::FinishLastObject(), PoDoFo::PdfWriter::Write(), PoDoFo::PdfVariant::Write(), PoDoFo::PdfString::Write(), PoDoFo::PdfReference::Write(), PoDoFo::PdfName::Write(), PoDoFo::PdfMemStream::Write(), PoDoFo::PdfDictionary::Write(), PoDoFo::PdfArray::Write(), PoDoFo::PdfObject::WriteObject(), PoDoFo::PdfWriter::WritePdfHeader(), and PoDoFo::PdfXRef::WriteSubSection().

{
    va_list args;
    long    lBytes;

    if( !pszFormat )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    if( m_hFile )
    {
        va_start( args, pszFormat );
        if( (lBytes = vfprintf( m_hFile, pszFormat, args )) < 0 )
        {
            perror( NULL );
            PODOFO_RAISE_ERROR( ePdfError_UnexpectedEOF );
        }
        va_end( args );
    }
    else
    {
        va_start( args, pszFormat );
        // OC 17.08.2010: Use new function _vscprintf to get the number of characters:
        // visual c++  8.0 == 1400 (Visual Studio 2005)
        // i am not shure if 1300 is ok here, but who cares this cruel compiler version
#if (defined _MSC_VER && _MSC_VER >= 1400 )
        lBytes = _vscprintf( pszFormat, args );
#elif (defined _MSC_VER || defined __hpux)  // vsnprintf without buffer does not work with MS-VC or HPUX
        int len = 1024;
        do
        {
            char * temp = new char[len+1]; // OC 17.08.2010 BugFix: +1 avoids corrupted heap
            lBytes = vsnprintf( temp, len+1, pszFormat, args );
            delete[] temp;
            len *= 2;
        } while (lBytes < 0 );
#else
        lBytes = vsnprintf( NULL, 0, pszFormat, args );
#endif
        va_end( args );
    }

    va_start( args, pszFormat );

    if( m_pBuffer )
    {
        if( m_ulPosition + lBytes <= m_lBufferLen )
        {
            vsnprintf( m_pBuffer + m_ulPosition, m_lBufferLen - m_ulPosition, pszFormat, args );
        }
        else
        {
            PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );
        }
    }
    else if( m_pStream || m_pRefCountedBuffer )
    {
        ++lBytes;
        // TODO: keep the buffer between subsequent calls!
        char* data = static_cast<char*>(malloc( lBytes * sizeof(char) ));
        if( !data )
        {
            PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );
        }
        
        vsnprintf( data, lBytes, pszFormat, args );
        if( lBytes )
            --lBytes;

        if( m_pStream ) 
        {
            std::string str;
            str.assign( data, lBytes );
            *m_pStream << str;
        }
        else // if( m_pRefCountedBuffer ) 
        {
            if( m_ulPosition + lBytes > static_cast<unsigned long>(m_pRefCountedBuffer->GetSize()) )
                m_pRefCountedBuffer->Resize( m_ulPosition + lBytes );

            memcpy( m_pRefCountedBuffer->GetBuffer() + m_ulPosition, data, lBytes );
        }

        free( data );
    }
    va_end( args );

    m_ulPosition += static_cast<size_t>(lBytes);
    m_ulLength += static_cast<size_t>(lBytes);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index