PoDoFo 0.9.20
Public Member Functions | Static Public Member Functions | List of all members
PoDoFo::PdfColor Class Referencefinal

#include <PdfColor.h>

Public Member Functions

 PdfColor ()
 
 PdfColor (double gray)
 
 PdfColor (double red, double green, double blue)
 
 PdfColor (double cyan, double magenta, double yellow, double black)
 
 PdfColor (const PdfColor &rhs)=default
 
bool IsGrayScale () const
 
bool IsRGB () const
 
bool IsCMYK () const
 
bool IsSeparation () const
 
bool IsCieLab () const
 
PdfColorSpace GetColorSpace () const
 
PdfColorSpace GetAlternateColorSpace () const
 
double GetGrayScale () const
 
double GetRed () const
 
double GetGreen () const
 
double GetBlue () const
 
double GetCyan () const
 
double GetMagenta () const
 
double GetYellow () const
 
double GetBlack () const
 
const std::string & GetName () const
 
double GetDensity () const
 
double GetCieL () const
 
double GetCieA () const
 
double GetCieB () const
 
PdfColor ConvertToGrayScale () const
 
PdfColor ConvertToRGB () const
 
PdfColor ConvertToCMYK () const
 
PdfArray ToArray () const
 
PdfObjectBuildColorSpace (PdfDocument &document) const
 
PdfColoroperator= (const PdfColor &rhs)=default
 
bool operator== (const PdfColor &rhs) const
 
bool operator!= (const PdfColor &rhs) const
 

Static Public Member Functions

static bool TryCreateFromObject (const PdfObject &obj, PdfColor &color)
 
static PdfColor CreateCieLab (double cieL, double cieA, double cieB)
 
static PdfColor CreateSeparation (const std::string_view &name, double density, const PdfColor &alternateColor)
 
static PdfColor CreateSeparationNone ()
 
static PdfColor CreateSeparationAll ()
 
static PdfColor FromString (const std::string_view &name)
 

Detailed Description

A color object can represent either a grayscale value, a RGB color, a CMYK color, a separation color or a CieLab color.

All drawing functions in PoDoFo accept a PdfColor object to specify a drawing color in one of these colorspaces.

Derived classes PdfColorGray, PdfColorRGB, PdfColorCMYK, PdfColorSeparation and PdfColorCieLab are available for easy construction

Constructor & Destructor Documentation

◆ PdfColor() [1/5]

PdfColor::PdfColor ( )

Create a PdfColor object that is grayscale black.

◆ PdfColor() [2/5]

PdfColor::PdfColor ( double  gray)
explicit

Create a new PdfColor object with a grayscale value.

Parameters
graya grayscale value between 0.0 and 1.0

◆ PdfColor() [3/5]

PdfColor::PdfColor ( double  red,
double  green,
double  blue 
)

Create a new PdfColor object with a RGB color

Parameters
redthe value of the red component, must be between 0.0 and 1.0
greenthe value of the green component, must be between 0.0 and 1.0
bluethe value of the blue component, must be between 0.0 and 1.0

◆ PdfColor() [4/5]

PdfColor::PdfColor ( double  cyan,
double  magenta,
double  yellow,
double  black 
)

Create a new PdfColor object with a CMYK color

Parameters
cyanthe value of the cyan component, must be between 0.0 and 1.0
magentathe value of the magenta component, must be between 0.0 and 1.0
yellowthe value of the yellow component, must be between 0.0 and 1.0
blackthe value of the black component, must be between 0.0 and 1.0

◆ PdfColor() [5/5]

PoDoFo::PdfColor::PdfColor ( const PdfColor rhs)
default

Copy constructor

Parameters
rhscopy rhs into this object

Member Function Documentation

◆ BuildColorSpace()

PdfObject * PdfColor::BuildColorSpace ( PdfDocument document) const

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

Parameters
documenta pointer to the owner document of the generated object
Returns
a PdfObject pointer, which can be insert into resources, nullptr if not needed

◆ ConvertToCMYK()

PdfColor PdfColor::ConvertToCMYK ( ) const

Converts the color object into a CMYK color object.

This is only a convenience function. It might be useful for on screen display but is in NO WAY suitable to professional printing!

Returns
a CMYK color object
See also
IsCMYK()

◆ ConvertToGrayScale()

PdfColor PdfColor::ConvertToGrayScale ( ) const

Converts the color object into a grayscale color object.

This is only a convenience function. It might be useful for on screen display but is in NO WAY suitable to professional printing!

Returns
a grayscale color object
See also
IsGrayScale()

◆ ConvertToRGB()

PdfColor PdfColor::ConvertToRGB ( ) const

Converts the color object into a RGB color object.

This is only a convenience function. It might be useful for on screen display but is in NO WAY suitable to professional printing!

Returns
a RGB color object
See also
IsRGB()

◆ CreateCieLab()

PdfColor PdfColor::CreateCieLab ( double  cieL,
double  cieA,
double  cieB 
)
static

Create a new PdfColor object with a CIE-LAB-value

Parameters
cieLthe value of the L component, must be between 0.0 and 100.0
cieAthe value of the A component, must be between -128.0 and 127.0
cieBthe value of the B component, must be between -128.0 and 127.0

◆ CreateSeparation()

PdfColor PdfColor::CreateSeparation ( const std::string_view &  name,
double  density,
const PdfColor alternateColor 
)
static

Create a new PdfColor object with a separation-name and an equivalent color

Parameters
nameName of the separation color
densitythe density value of the separation color
alternateColorthe alternate color, must be of type gray, rgb, cmyk or cie

◆ CreateSeparationAll()

PdfColor PdfColor::CreateSeparationAll ( )
static

Create a new PdfColor object with Separation color All.

◆ CreateSeparationNone()

PdfColor PdfColor::CreateSeparationNone ( )
static

Create a new PdfColor object with Separation color None.

◆ FromString()

PdfColor PdfColor::FromString ( const std::string_view &  name)
static

Creates a color object from a string.

Parameters
namea string describing a color.

Supported values are:

  • single gray values as string (e.g. '0.5')
  • a named color (e.g. 'aquamarine' or 'magenta')
  • hex values (e.g. #FF002A (RGB) or #FF12AB3D (CMYK))
  • PdfArray's
Returns
a PdfColor object

◆ GetAlternateColorSpace()

PdfColorSpace PdfColor::GetAlternateColorSpace ( ) const

Get the alternate colorspace of this PdfColor object

Returns
the colorspace of this PdfColor object (must be separation)

◆ GetBlack()

double PdfColor::GetBlack ( ) const

Get the black color value of this object.

Throws an exception if this is no CMYK or separation color object.

Returns
the black color value of this object (between 0.0 and 1.0)
See also
IsCMYK

◆ GetBlue()

double PdfColor::GetBlue ( ) const

Get the blue color value of this object.

Throws an exception if this is no RGB color object.

Returns
the blue color value of this object (between 0.0 and 1.0)
See also
IsRGB

◆ GetCieA()

double PdfColor::GetCieA ( ) const

Get the A color value of this object.

Throws an exception if this is no CIE-Lab color object.

Returns
the A color value of this object (between -128.0 and 127.0)
See also
IsCieLab

◆ GetCieB()

double PdfColor::GetCieB ( ) const

Get the B color value of this object.

Throws an exception if this is no CIE-Lab color object.

Returns
the B color value of this object (between -128.0 and 127.0)
See also
IsCieLab

◆ GetCieL()

double PdfColor::GetCieL ( ) const

Get the L color value of this object.

Throws an exception if this is no CIE-Lab color object.

Returns
the L color value of this object (between 0.0 and 100.0)
See also
IsCieLab

◆ GetColorSpace()

PdfColorSpace PoDoFo::PdfColor::GetColorSpace ( ) const
inline

Get the colorspace of this PdfColor object

Returns
the colorspace of this PdfColor object

◆ GetCyan()

double PdfColor::GetCyan ( ) const

Get the cyan color value of this object.

Throws an exception if this is no CMYK or separation color object.

Returns
the cyan color value of this object (between 0.0 and 1.0)
See also
IsCMYK

◆ GetDensity()

double PdfColor::GetDensity ( ) const

Get the density color value of this object.

Throws an exception if this is no separation color object.

Returns
the density value of this object (between 0.0 and 1.0)
See also
IsSeparation

◆ GetGrayScale()

double PdfColor::GetGrayScale ( ) const

Get the grayscale color value of this object.

Throws an exception if this is no grayscale color object.

Returns
the grayscale color value of this object (between 0.0 and 1.0)
See also
IsGrayScale

◆ GetGreen()

double PdfColor::GetGreen ( ) const

Get the green color value of this object.

Throws an exception if this is no RGB color object.

Returns
the green color value of this object (between 0.0 and 1.0)
See also
IsRGB

◆ GetMagenta()

double PdfColor::GetMagenta ( ) const

Get the magenta color value of this object.

Throws an exception if this is no CMYK or separation color object.

Returns
the magenta color value of this object (between 0.0 and 1.0)
See also
IsCMYK

◆ GetName()

const string & PdfColor::GetName ( ) const

Get the separation name of this object.

Throws an exception if this is no separation color object.

Returns
the name of this object
See also
IsSeparation

◆ GetRed()

double PdfColor::GetRed ( ) const

Get the red color value of this object.

Throws an exception if this is no RGB color object.

Returns
the red color value of this object (between 0.0 and 1.0)
See also
IsRGB

◆ GetYellow()

double PdfColor::GetYellow ( ) const

Get the yellow color value of this object.

Throws an exception if this is no CMYK or separation color object.

Returns
the yellow color value of this object (between 0.0 and 1.0)
See also
IsCMYK

◆ IsCieLab()

bool PdfColor::IsCieLab ( ) const

Test if this is a CIE-Lab color.

Returns
true if this is a lab Color object

◆ IsCMYK()

bool PdfColor::IsCMYK ( ) const

Test if this is a CMYK color.

Returns
true if this is a CMYK PdfColor object

◆ IsGrayScale()

bool PdfColor::IsGrayScale ( ) const

Test if this is a grayscale color.

Returns
true if this is a grayscale PdfColor object

◆ IsRGB()

bool PdfColor::IsRGB ( ) const

Test if this is a RGB color.

Returns
true if this is a RGB PdfColor object

◆ IsSeparation()

bool PdfColor::IsSeparation ( ) const

Test if this is a separation color.

Returns
true if this is a separation PdfColor object

◆ operator!=()

bool PdfColor::operator!= ( const PdfColor rhs) const

Test for inequality of colors.

Parameters
rhscolor to compare to
Returns
true if object color is not equal to rhs

◆ operator=()

PdfColor & PoDoFo::PdfColor::operator= ( const PdfColor rhs)
default

Assignment operator

Parameters
rhscopy rhs into this object
Returns
a reference to this color object

◆ operator==()

bool PdfColor::operator== ( const PdfColor rhs) const

Test for equality of colors.

Parameters
rhscolor to compare to
Returns
true if object color is equal to rhs

◆ ToArray()

PdfArray PdfColor::ToArray ( ) const

Creates a PdfArray which represents a color from a color.

Returns
a PdfArray object

◆ TryCreateFromObject()

bool PdfColor::TryCreateFromObject ( const PdfObject obj,
PdfColor color 
)
static

Creates a color object from a PdfArray which represents a color.

Parameters
objan object that must be a color PdfArray