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

void PoDoFo::PdfVariant::Write ( PdfOutputDevice pDevice,
EPdfWriteMode  eWriteMode,
const PdfEncrypt pEncrypt,
const PdfName keyStop 
) const [virtual, inherited]

Write the complete variant to an output device.

Parameters:
pDevicewrite the object to this device
eWriteModeadditional options for writing this object
pEncryptan encryption object which is used to encrypt this object or NULL to not encrypt this object
keyStopif not KeyNull and a key == keyStop is found writing will stop right before this key! if IsDictionary returns true.

Definition at line 204 of file PdfVariant.cpp.

References PoDoFo::ePdfDataType_Array, PoDoFo::ePdfDataType_Bool, PoDoFo::ePdfDataType_Dictionary, PoDoFo::ePdfDataType_HexString, PoDoFo::ePdfDataType_Name, PoDoFo::ePdfDataType_Null, PoDoFo::ePdfDataType_Number, PoDoFo::ePdfDataType_RawData, PoDoFo::ePdfDataType_Real, PoDoFo::ePdfDataType_Reference, PoDoFo::ePdfDataType_String, PoDoFo::ePdfDataType_Unknown, PoDoFo::ePdfError_InvalidDataType, PoDoFo::ePdfError_InvalidHandle, PoDoFo::ePdfWriteMode_Compact, PoDoFo::PdfLocaleImbue(), PODOFO_RAISE_ERROR, PoDoFo::PdfOutputDevice::Print(), and PoDoFo::PdfOutputDevice::Write().

{
    DelayedLoad(); 

    /* Check all handles first 
     */
    if( (m_eDataType == ePdfDataType_HexString ||
         m_eDataType == ePdfDataType_String ||
         m_eDataType == ePdfDataType_Array ||
         m_eDataType == ePdfDataType_Dictionary ||
         m_eDataType == ePdfDataType_Name || 
         m_eDataType == ePdfDataType_RawData ) && !m_Data.pData )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    switch( m_eDataType ) 
    {
        case ePdfDataType_Bool:
        {
            if( (eWriteMode & ePdfWriteMode_Compact) == ePdfWriteMode_Compact ) 
            {
                pDevice->Write( " ", 1 ); // Write space before true or false
            }

            if( m_Data.bBoolValue )
                pDevice->Write( "true", 4 );
            else
                pDevice->Write( "false", 5 );
            break;
        }
        case ePdfDataType_Number:
        {
            if( (eWriteMode & ePdfWriteMode_Compact) == ePdfWriteMode_Compact ) 
            {
                pDevice->Write( " ", 1 ); // Write space before numbers
            }

#ifdef _WIN64
            pDevice->Print( "%I64i", m_Data.nNumber );
#else
            pDevice->Print( "%lld", m_Data.nNumber );
#endif
            break;
        }
        case ePdfDataType_Real:
            //pDevice->Print( "%g", m_Data.dNumber );
            // DominikS: %g precision might write floating points
            //           numbers in exponential form (with e)
            //           which is not supported in PDF.
            //           %f fixes this but might loose precision as 
            //           it defaults to a precision of 6
            // pDevice->Print( "%f", m_Data.dNumber );
        {
            if( (eWriteMode & ePdfWriteMode_Compact) == ePdfWriteMode_Compact ) 
            {
                pDevice->Write( " ", 1 ); // Write space before numbers
            }

            // Use ostringstream, so that locale does not matter
            std::ostringstream oss;
            PdfLocaleImbue(oss);
            oss << std::fixed << m_Data.dNumber;

            pDevice->Write( oss.str().c_str(), oss.str().size() );
            break;
        }
        case ePdfDataType_HexString:
        case ePdfDataType_String:
        case ePdfDataType_Name:
        case ePdfDataType_Array:
        case ePdfDataType_Reference:
        case ePdfDataType_RawData:
            m_Data.pData->Write( pDevice, eWriteMode, pEncrypt );
            break;
        case ePdfDataType_Dictionary:
            static_cast<PdfDictionary*>(m_Data.pData)->Write( pDevice, eWriteMode, pEncrypt, keyStop );
            break;
        case ePdfDataType_Null:
        {
            if( (eWriteMode & ePdfWriteMode_Compact) == ePdfWriteMode_Compact ) 
            {
                pDevice->Write( " ", 1 ); // Write space before null
            }

            pDevice->Print( "null" );
            break;
        }
        case ePdfDataType_Unknown:
        default:
        {
            PODOFO_RAISE_ERROR( ePdfError_InvalidDataType );
            break;
        }
    };
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index