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

void PoDoFo::PdfFunctionBaseShadingPattern::Init ( const PdfColor rLL,
const PdfColor rUL,
const PdfColor rLR,
const PdfColor rUR,
const PdfArray rMatrix 
) [private]

Initialize an 2D shading pattern

Parameters:
rLLthe color on lower left corner
rULthe color on upper left corner
rLRthe color on lower right corner
rURthe color on upper right corner
rMatrixthe transformation matrix mapping the coordinate space specified by the Domain entry into the shading’s target coordinate space

Definition at line 263 of file PdfShadingPattern.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::PdfColor::BuildColorSpace(), PoDoFo::ePdfColorSpace_CieLab, PoDoFo::ePdfColorSpace_DeviceCMYK, PoDoFo::ePdfColorSpace_DeviceGray, PoDoFo::ePdfColorSpace_DeviceRGB, PoDoFo::ePdfColorSpace_Separation, PoDoFo::ePdfError_InvalidDataType, PoDoFo::PdfColor::GetBlack(), PoDoFo::PdfColor::GetBlue(), PoDoFo::PdfColor::GetCieA(), PoDoFo::PdfColor::GetCieB(), PoDoFo::PdfColor::GetCieL(), PoDoFo::PdfColor::GetColorSpace(), PoDoFo::PdfColor::GetCyan(), PoDoFo::PdfColor::GetDensity(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfColor::GetGrayScale(), PoDoFo::PdfColor::GetGreen(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfColor::GetMagenta(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfColor::GetRed(), PoDoFo::PdfColor::GetYellow(), PODOFO_RAISE_ERROR_INFO, PoDoFo::PdfArray::push_back(), and PoDoFo::PdfObject::Reference().

Referenced by PdfFunctionBaseShadingPattern().

{
    if( rLL.GetColorSpace() != rUL.GetColorSpace() || rUL.GetColorSpace() != rLR.GetColorSpace() || rLR.GetColorSpace() != rUR.GetColorSpace() )
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidDataType, "Colorspace of start and end color in PdfFunctionBaseShadingPattern does not match." );
    }

    PdfArray domain;
    domain.push_back( 0.0 );
    domain.push_back( 1.0 );
    domain.push_back( 0.0 );
    domain.push_back( 1.0 );

    PdfDictionary & shading = this->GetObject()->GetDictionary().GetKey( PdfName("Shading") )->GetDictionary();
      PdfArray range;
      PdfSampledFunction::Sample samples;

      switch ( rLL.GetColorSpace() )
      {
            case ePdfColorSpace_DeviceRGB:
            {
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );
      
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetRed() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetGreen() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetBlue() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetRed() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetGreen() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetBlue() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetRed() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetGreen() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetBlue() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetRed() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetGreen() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetBlue() *255.0 ) );
      
              shading.AddKey( PdfName("ColorSpace"), PdfName("DeviceRGB") );
            }
            break;

            case ePdfColorSpace_DeviceCMYK:
            {
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );
      
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetCyan() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetMagenta() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetYellow() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetBlack() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetCyan() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetMagenta() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetYellow() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetBlack() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetCyan() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetMagenta() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetYellow() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetBlack() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetCyan() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetMagenta() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetYellow() *255.0 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetBlack() *255.0 ) );
      
              shading.AddKey( PdfName("ColorSpace"), PdfName("DeviceCMYK") );
            }
            break;

            case ePdfColorSpace_DeviceGray:
            {
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );
      
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetGrayScale() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetGrayScale() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetGrayScale() *255.0 ) );
      
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetGrayScale() *255.0 ) );
      
              shading.AddKey( PdfName("ColorSpace"), PdfName("DeviceGray") );
            }
            break;

            case ePdfColorSpace_CieLab:
            {
                  range.push_back( 0.0 );
                  range.push_back( 100.0 );
                  range.push_back( -128.0 );
                  range.push_back( 127.0 );
                  range.push_back( -128.0 );
                  range.push_back( 127.0 );

                  samples.insert( samples.end(), static_cast<char> ( rLL.GetCieL() *2.55 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetCieA() +128 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLL.GetCieB() +128 ) );

                  samples.insert( samples.end(), static_cast<char> ( rLR.GetCieL() *2.55 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetCieA() +128 ) );
                  samples.insert( samples.end(), static_cast<char> ( rLR.GetCieB() +128 ) );

                  samples.insert( samples.end(), static_cast<char> ( rUL.GetCieL() *2.55 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetCieA() +128 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUL.GetCieB() +128 ) );

                  samples.insert( samples.end(), static_cast<char> ( rUR.GetCieL() *2.55 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetCieA() +128 ) );
                  samples.insert( samples.end(), static_cast<char> ( rUR.GetCieB() +128 ) );

                  PdfObject * csp = rLL.BuildColorSpace( this->GetObject()->GetOwner() );

                  shading.AddKey( PdfName("ColorSpace"), csp->Reference() );
            }
            break;

            case ePdfColorSpace_Separation:
            {
                  range.push_back( 0.0 );
                  range.push_back( 1.0 );

                  samples.insert( samples.end(), static_cast<char> ( rLL.GetDensity() *255.0 ) );

                  samples.insert( samples.end(), static_cast<char> ( rLR.GetDensity() *255.0 ) );

                  samples.insert( samples.end(), static_cast<char> ( rUL.GetDensity() *255.0 ) );

                  samples.insert( samples.end(), static_cast<char> ( rUR.GetDensity() *255.0 ) );

                  PdfObject * csp = rLL.BuildColorSpace( this->GetObject()->GetOwner() );

                  shading.AddKey( PdfName("ColorSpace"), csp->Reference() );
            }
            break;

            default:
              PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidDataType, "Colorspace not supported in PdfFunctionBaseShadingPattern." );
            break;
      }

    PdfSampledFunction function( domain, range, samples, this->GetObject()->GetOwner() );
    shading.AddKey( PdfName("Function"), function.GetObject()->Reference() );
    shading.AddKey( PdfName("Domain"), domain );
    shading.AddKey( PdfName("Matrix"), rMatrix );
}

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