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

PdfObject * PoDoFo::PdfColor::BuildColorSpace ( PdfVecObjects pOwner ) const [inherited]

Creates a colorspace object from a color to insert into resources.

Parameters:
pOwnera pointer to the owner of the generated object
Returns:
a PdfObject pointer, which can be insert into resources, NULL if not needed

Definition at line 851 of file PdfColor.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::PdfVecObjects::CreateObject(), PoDoFo::ePdfColorSpace_CieLab, PoDoFo::ePdfColorSpace_DeviceCMYK, PoDoFo::ePdfColorSpace_DeviceGray, PoDoFo::ePdfColorSpace_DeviceRGB, PoDoFo::ePdfColorSpace_Separation, PoDoFo::ePdfError_InvalidEnumValue, PoDoFo::ePdfFunctionType_Sampled, PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfObject::GetStream(), PODOFO_RAISE_ERROR, PoDoFo::PdfArray::push_back(), PoDoFo::PdfObject::Reference(), and PoDoFo::PdfStream::Set().

Referenced by PoDoFo::PdfCanvas::AddColorResource(), PoDoFo::PdfRadialShadingPattern::Init(), PoDoFo::PdfFunctionBaseShadingPattern::Init(), and PoDoFo::PdfAxialShadingPattern::Init().

{
    switch( m_eColorSpace )
    {
        case ePdfColorSpace_Separation:
        {
            // Build color-spaces for separation
            PdfObject* csTintFunc = pOwner->CreateObject();

            csTintFunc->GetDictionary().AddKey( "BitsPerSample", static_cast<pdf_int64>(8) );

            PdfArray decode;
            decode.push_back( static_cast<pdf_int64>(0) );
            decode.push_back( static_cast<pdf_int64>(1) );
            decode.push_back( static_cast<pdf_int64>(0) );
            decode.push_back( static_cast<pdf_int64>(1) );
            decode.push_back( static_cast<pdf_int64>(0) );
            decode.push_back( static_cast<pdf_int64>(1) );
            decode.push_back( static_cast<pdf_int64>(0) );
            decode.push_back( static_cast<pdf_int64>(1) );
            csTintFunc->GetDictionary().AddKey( "Decode", decode );

            PdfArray domain;
            domain.push_back( static_cast<pdf_int64>(0) );
            domain.push_back( static_cast<pdf_int64>(1) );
            csTintFunc->GetDictionary().AddKey( "Domain", domain );

            PdfArray encode;
            encode.push_back( static_cast<pdf_int64>(0) );
            encode.push_back( static_cast<pdf_int64>(1) );
            csTintFunc->GetDictionary().AddKey( "Encode", encode );

            csTintFunc->GetDictionary().AddKey( "Filter", PdfName( "FlateDecode" ) );
            csTintFunc->GetDictionary().AddKey( "FunctionType", PdfVariant( static_cast<pdf_int64>(ePdfFunctionType_Sampled) ) );

            switch ( m_eAlternateColorSpace )
            {
                case ePdfColorSpace_DeviceGray:
                {
                    char data[1*2];
                    data[0] = 0;
                    data[1] = static_cast<char> (m_uColor.gray);

                    PdfMemoryInputStream stream( data, 1*2 );
                    csTintFunc->GetStream()->Set( &stream );

                    PdfArray range;
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    csTintFunc->GetDictionary().AddKey( "Range", range );

                    PdfArray size;
                    size.push_back( static_cast<pdf_int64>(2) );
                    csTintFunc->GetDictionary().AddKey( "Size", size );

                    PdfArray csArr;
                    csArr.push_back( PdfName("Separation") );
                    csArr.push_back( PdfName( m_separationName ) );
                    csArr.push_back( PdfName("DeviceGray") );
                    csArr.push_back( csTintFunc->Reference() );

                    PdfObject* csp = pOwner->CreateObject( csArr );

                    return csp;
                }
                break;

                case ePdfColorSpace_DeviceRGB:
                {
                    char data[3*2];
                    data[0] =
                    data[1] =
                    data[2] = 0;
                    data[3] = static_cast<char> (m_uColor.rgb[0] * 255);
                    data[4] = static_cast<char> (m_uColor.rgb[1] * 255);
                    data[5] = static_cast<char> (m_uColor.rgb[2] * 255);

                    PdfMemoryInputStream stream( data, 3*2 );
                    csTintFunc->GetStream()->Set( &stream );

                    PdfArray range;
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    csTintFunc->GetDictionary().AddKey( "Range", range );

                    PdfArray size;
                    size.push_back( static_cast<pdf_int64>(2) );
                    csTintFunc->GetDictionary().AddKey( "Size", size );

                    PdfArray csArr;
                    csArr.push_back( PdfName("Separation") );
                    csArr.push_back( PdfName( m_separationName ) );
                    csArr.push_back( PdfName("DeviceRGB") );
                    csArr.push_back( csTintFunc->Reference() );

                    PdfObject* csp = pOwner->CreateObject( csArr );

                    return csp;
                }
                break;

                case ePdfColorSpace_DeviceCMYK:
                {
                    char data[4*2];
                    data[0] =
                    data[1] =
                    data[2] = 
                    data[3] = 0;
                    data[4] = static_cast<char> (m_uColor.cmyk[0] * 255);
                    data[5] = static_cast<char> (m_uColor.cmyk[1] * 255);
                    data[6] = static_cast<char> (m_uColor.cmyk[2] * 255);
                    data[7] = static_cast<char> (m_uColor.cmyk[3] * 255);

                    PdfMemoryInputStream stream( data, 4*2 );
                    csTintFunc->GetStream()->Set( &stream );

                    PdfArray range;
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    csTintFunc->GetDictionary().AddKey( "Range", range );

                    PdfArray size;
                    size.push_back( static_cast<pdf_int64>(2) );
                    csTintFunc->GetDictionary().AddKey( "Size", size );

                    PdfArray csArr;
                    csArr.push_back( PdfName("Separation") );
                    csArr.push_back( PdfName( m_separationName ) );
                    csArr.push_back( PdfName("DeviceCMYK") );
                    csArr.push_back( csTintFunc->Reference() );

                    PdfObject* csp = pOwner->CreateObject( csArr );

                    return csp;
                }
                break;

                case ePdfColorSpace_CieLab:
                {
                    char data[3*2];
                    data[0] =
                    data[1] =
                    data[2] = 0;
                    data[3] = static_cast<char> (m_uColor.lab[0] * 255);
                    data[4] = static_cast<char> (m_uColor.lab[1] * 255);
                    data[5] = static_cast<char> (m_uColor.lab[2] * 255);

                    PdfMemoryInputStream stream( data, 3*2 );
                    csTintFunc->GetStream()->Set( &stream );

                    PdfArray range;
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    range.push_back( static_cast<pdf_int64>(0) );
                    range.push_back( static_cast<pdf_int64>(1) );
                    csTintFunc->GetDictionary().AddKey( "Range", range );

                    PdfArray size;
                    size.push_back( static_cast<pdf_int64>(2) );
                    csTintFunc->GetDictionary().AddKey( "Size", size );

                    PdfArray csArr;
                    csArr.push_back( PdfName("Separation") );
                    csArr.push_back( PdfName( m_separationName ) );
                    csArr.push_back( PdfName("Lab") );
                    csArr.push_back( csTintFunc->Reference() );

                    PdfObject* csp = pOwner->CreateObject( csArr );

                    return csp;
                }
                break;

                case ePdfColorSpace_Separation:
                {
                    break;
                }
                default:
                {
                    PODOFO_RAISE_ERROR( ePdfError_InvalidEnumValue );
                    break;
                }
            }
        }
        break;

        case ePdfColorSpace_CieLab:
        {
            // Build color-spaces for CIE-lab
            PdfDictionary labDict;

            // D65-whitepoint
            PdfArray wpArr;
            wpArr.push_back( 0.9505 );
            wpArr.push_back( 1.0000 );
            wpArr.push_back( 1.0890 );
            labDict.AddKey( PdfName("WhitePoint" ), wpArr );

            // Range for A,B, L is implicit 0..100
            PdfArray rangeArr;
            rangeArr.push_back( static_cast<pdf_int64>(-128) );
            rangeArr.push_back( static_cast<pdf_int64>(127) );
            rangeArr.push_back( static_cast<pdf_int64>(-128) );
            rangeArr.push_back( static_cast<pdf_int64>(127) );
            labDict.AddKey( PdfName("Range" ), rangeArr );

            PdfArray labArr;
            labArr.push_back( PdfName("Lab") );
            labArr.push_back( labDict );

            PdfObject* labp = pOwner->CreateObject( labArr );

            return labp;
        }
        break;

        case ePdfColorSpace_DeviceGray:
        case ePdfColorSpace_DeviceRGB:
        case ePdfColorSpace_DeviceCMYK:
        {
            break;
        }
        default:
        {
            PODOFO_RAISE_ERROR( ePdfError_InvalidEnumValue );
            break;
        }
    }

    return NULL;
}

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