PoDoFo  1.0.0-dev
Public Member Functions | Static Public Member Functions | List of all members
PoDoFo::PdfColor Class Referencefinal

A color object can represent either a grayscale value, a RGB color, a CMYK color. More...

#include <PdfColor.h>

Public Member Functions

 PdfColor ()
 Create a PdfColor object that is grayscale black.
 
 PdfColor (double gray)
 Create a new PdfColor object with a grayscale value. More...
 
 PdfColor (double red, double green, double blue)
 Create a new PdfColor object with a RGB color. More...
 
 PdfColor (double cyan, double magenta, double yellow, double black)
 Create a new PdfColor object with a CMYK color. More...
 
 PdfColor (const PdfColor &rhs)=default
 Copy constructor. More...
 
bool IsGrayScale () const
 Test if this is a grayscale color. More...
 
bool IsRGB () const
 Test if this is a RGB color. More...
 
bool IsCMYK () const
 Test if this is a CMYK color. More...
 
bool IsTransparent () const
 
PdfColorSpaceType GetColorSpace () const
 Get the colorspace of this PdfColor object. More...
 
double GetGrayScale () const
 Get the grayscale color value of this object. More...
 
double GetRed () const
 Get the red color value of this object. More...
 
double GetGreen () const
 Get the green color value of this object. More...
 
double GetBlue () const
 Get the blue color value of this object. More...
 
double GetCyan () const
 Get the cyan color value of this object. More...
 
double GetMagenta () const
 Get the magenta color value of this object. More...
 
double GetYellow () const
 Get the yellow color value of this object. More...
 
double GetBlack () const
 Get the black color value of this object. More...
 
PdfColor ConvertToGrayScale () const
 Converts the color object into a grayscale color object. More...
 
PdfColor ConvertToRGB () const
 Converts the color object into a RGB color object. More...
 
PdfColor ConvertToCMYK () const
 Converts the color object into a CMYK color object. More...
 
PdfArray ToArray () const
 Creates a PdfArray which represents a color from a color. More...
 
unsigned char GetComponentCount () const
 
const PdfColorRaw & GetRawColor () const
 
PdfColoroperator= (const PdfColor &rhs)=default
 Assignment operator. More...
 
bool operator== (const PdfColor &rhs) const
 Test for equality of colors. More...
 
bool operator!= (const PdfColor &rhs) const
 Test for inequality of colors. More...
 

Static Public Member Functions

static bool TryCreateFromObject (const PdfObject &obj, PdfColor &color)
 Creates a color object from a PdfArray which represents a color. More...
 
static PdfColor CreateFromObject (const PdfObject &obj)
 
static PdfColor CreateTransparent ()
 
static PdfColor CreateFromString (const std::string_view &name)
 Creates a color object from a string. More...
 

Detailed Description

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

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

Constructor & Destructor Documentation

◆ PdfColor() [1/4]

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() [2/4]

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() [3/4]

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() [4/4]

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

Copy constructor.

Parameters
rhscopy rhs into this object

Member Function Documentation

◆ 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()

◆ CreateFromString()

PdfColor PdfColor::CreateFromString ( 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

◆ 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

◆ GetColorSpace()

PdfColorSpaceType 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

◆ 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

◆ 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

◆ 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

◆ 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

The documentation for this class was generated from the following files: