PoDoFo  1.0.0-dev
Public Member Functions | Public Attributes | Friends | List of all members
PoDoFo::PdfPainter Class Referencefinal

This class provides an easy to use painter object which allows you to draw on a PDF page object. More...

#include <PdfPainter.h>

Inheritance diagram for PoDoFo::PdfPainter:
PoDoFo::PdfContentStreamOperators

Public Member Functions

 PdfPainter (PdfPainterFlags flags=PdfPainterFlags::None)
 Create a new PdfPainter object. More...
 
void SetCanvas (PdfCanvas &page)
 Set the page on which the painter should draw. More...
 
void FinishDrawing ()
 Finish drawing onto a canvas. More...
 
void SetStrokeStyle (PdfStrokeStyle strokeStyle, bool inverted=false, double scale=1.0, bool subtractJoinCap=false)
 Set the stoke style for all stroking operations. More...
 
void SetStrokeStyle (const cspan< double > &dashArray, double phase)
 
void SetClipRect (double x, double y, double width, double height)
 Set a clipping rectangle. More...
 
void SetClipRect (const Rect &rect)
 Set a clipping rectangle. More...
 
void DrawLine (double x1, double y1, double x2, double y2)
 Stroke a line with current color and line settings. More...
 
void DrawCubicBezier (double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
 Stroke a cubic bezier with current color and line settings. More...
 
void DrawArc (double x, double y, double radius, double startAngle, double endAngle, bool clockwise=false)
 Stroke a counterclockwise arc to the given coordinate spanning from given angles and radius This is the equivalent of the "arc"/"arcn" operators in PostScript. More...
 
void DrawCircle (double x, double y, double radius, PdfPathDrawMode mode=PdfPathDrawMode::Stroke)
 Draw a circle. More...
 
void DrawEllipse (double x, double y, double width, double height, PdfPathDrawMode mode=PdfPathDrawMode::Stroke)
 Draw an ellipse to the given coordinates. More...
 
void DrawRectangle (double x, double y, double width, double height, PdfPathDrawMode mode=PdfPathDrawMode::Stroke, double roundX=0.0, double roundY=0.0)
 Draw a rectangle to the given coordinates. More...
 
void DrawRectangle (const Rect &rect, PdfPathDrawMode mode=PdfPathDrawMode::Stroke, double roundX=0.0, double roundY=0.0)
 Draw a rectangle into the current path to the given coordinates. More...
 
void DrawText (const std::string_view &str, double x, double y, PdfDrawTextStyle style=PdfDrawTextStyle::Regular)
 Draw a single-line text string on a page using a given font object. More...
 
void DrawTextMultiLine (const std::string_view &str, double x, double y, double width, double height, const PdfDrawTextMultiLineParams &params={ })
 Draw multiline text into a rectangle doing automatic wordwrapping. More...
 
void DrawTextMultiLine (const std::string_view &str, const Rect &rect, const PdfDrawTextMultiLineParams &params={ })
 Draw multiline text into a rectangle doing automatic wordwrapping. More...
 
void DrawTextAligned (const std::string_view &str, double x, double y, double width, PdfHorizontalAlignment hAlignment, PdfDrawTextStyle style=PdfDrawTextStyle::Regular)
 Draw a single line of text horizontally aligned. More...
 
void DrawImage (const PdfImage &obj, double x, double y, double scaleX=1.0, double scaleY=1.0)
 Draw an image on the current page. More...
 
void DrawXObject (const PdfXObject &obj, double x, double y, double scaleX=1.0, double scaleY=1.0)
 Draw an XObject on the current page. More...
 
void DrawPath (const PdfPainterPath &path, PdfPathDrawMode drawMode=PdfPathDrawMode::Stroke)
 Draw the current path with the given.
 
void ClipPath (const PdfPainterPath &path, bool useEvenOddRule=false)
 Clip the current path. More...
 
void BeginMarkedContent (const std::string_view &tag)
 Begin a marked-content sequence (operator BMC)
 
void EndMarkedContent ()
 End a marked-content sequence begun by a BMC or BDC operator.
 
void Save ()
 Save the current graphics settings onto the graphics stack. More...
 
void Restore ()
 Restore the current graphics settings from the graphics stack. More...
 
void SetPrecision (unsigned short precision)
 Set the floating point precision. More...
 
unsigned short GetPrecision () const
 Get the currently set floating point precision. More...
 
std::string_view GetContent () const
 Get a string view of the current content stream being built.
 
const PdfPainterStateStack & GetStateStack () const
 
void SetTabWidth (unsigned short tabWidth)
 Set the tab width for the DrawText operation. More...
 
unsigned short GetTabWidth () const
 Get the currently set tab width. More...
 
PdfCanvasGetCanvas () const
 Return the current page that is that on the painter. More...
 
PdfObjectStreamGetStream () const
 Return the current canvas stream that is set on the painter. More...
 

Public Attributes

PdfGraphicsStateWrapper GraphicsState
 
PdfTextStateWrapper TextState
 
PdfPainterTextObject TextObject
 

Friends

class PdfGraphicsStateWrapper
 
class PdfTextStateWrapper
 
class PdfPainterPathContext
 
class PdfPainterTextObject
 

Additional Inherited Members

- Protected Member Functions inherited from PoDoFo::PdfContentStreamOperators
 PdfContentStreamOperators (const PdfContentStreamOperators &)=default
 
PdfContentStreamOperatorsoperator= (const PdfContentStreamOperators &)=default
 

Detailed Description

This class provides an easy to use painter object which allows you to draw on a PDF page object.

During all drawing operations, you are still able to access the stream of the object you are drawing on directly.

All functions that take coordinates expect these to be in PDF User Units. Keep in mind that PDF has its coordinate system origin at the bottom left corner.

Remarks
It should not be generally needede but you can cast the instance to PdfContentStreamOperators to access low level PDF operators

Constructor & Destructor Documentation

◆ PdfPainter()

PdfPainter::PdfPainter ( PdfPainterFlags  flags = PdfPainterFlags::None)

Create a new PdfPainter object.

Parameters
saveRestoredo save/restore state before appending

Member Function Documentation

◆ ClipPath()

void PdfPainter::ClipPath ( const PdfPainterPath path,
bool  useEvenOddRule = false 
)

Clip the current path.

Matches the PDF 'W' operator.

Parameters
useEvenOddRuleselect even-odd rule instead of nonzero winding number rule

◆ DrawArc()

void PdfPainter::DrawArc ( double  x,
double  y,
double  radius,
double  startAngle,
double  endAngle,
bool  clockwise = false 
)

Stroke a counterclockwise arc to the given coordinate spanning from given angles and radius This is the equivalent of the "arc"/"arcn" operators in PostScript.

Parameters
xx coordinate of the center of the arc (left coordinate)
yy coordinate of the center of the arc (top coordinate)
radiusradius
startAnglestartAngle in radians measured counterclockwise from the origin
endAngleendAngle in radians measured counterclockwise from the origin
clockwiseThe arc is drawn clockwise instead

◆ DrawCircle()

void PdfPainter::DrawCircle ( double  x,
double  y,
double  radius,
PdfPathDrawMode  mode = PdfPathDrawMode::Stroke 
)

Draw a circle.

Parameters
xx center coordinate of the circle
yy coordinate of the circle
radiusradius of the circle

◆ DrawCubicBezier()

void PdfPainter::DrawCubicBezier ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3,
double  x4,
double  y4 
)

Stroke a cubic bezier with current color and line settings.

Parameters
x1x coordinate of the starting point
y1y coordinate of the starting point
x2x coordinate of the first control point
y2y coordinate of the first control point
x3x coordinate of the second control point
y3y coordinate of the second control point
x4x coordinate of the end point, which is the new current point
y5y coordinate of the end point, which is the new current point

◆ DrawEllipse()

void PdfPainter::DrawEllipse ( double  x,
double  y,
double  width,
double  height,
PdfPathDrawMode  mode = PdfPathDrawMode::Stroke 
)

Draw an ellipse to the given coordinates.

Parameters
xx coordinate of the ellipse (left coordinate)
yy coordinate of the ellipse (top coordinate)
widthwidth of the ellipse
heightabsolute height of the ellipse

◆ DrawImage()

void PdfPainter::DrawImage ( const PdfImage obj,
double  x,
double  y,
double  scaleX = 1.0,
double  scaleY = 1.0 
)

Draw an image on the current page.

Parameters
xthe x coordinate (left position of the image)
ythe y coordinate (bottom position of the image)
objan PdfXObject
scaleXoption scaling factor in x direction
scaleYoption scaling factor in y direction

◆ DrawLine()

void PdfPainter::DrawLine ( double  x1,
double  y1,
double  x2,
double  y2 
)

Stroke a line with current color and line settings.

Parameters
x1x coordinate of the starting point
y1y coordinate of the starting point
x2x coordinate of the ending point
y2y coordinate of the ending point

◆ DrawRectangle() [1/2]

void PdfPainter::DrawRectangle ( const Rect rect,
PdfPathDrawMode  mode = PdfPathDrawMode::Stroke,
double  roundX = 0.0,
double  roundY = 0.0 
)

Draw a rectangle into the current path to the given coordinates.

Parameters
rectthe rectangle area
roundXrounding factor, x direction
roundYrounding factor, y direction

◆ DrawRectangle() [2/2]

void PdfPainter::DrawRectangle ( double  x,
double  y,
double  width,
double  height,
PdfPathDrawMode  mode = PdfPathDrawMode::Stroke,
double  roundX = 0.0,
double  roundY = 0.0 
)

Draw a rectangle to the given coordinates.

Parameters
xx coordinate of the rectangle (left coordinate)
yy coordinate of the rectangle (bottom coordinate)
widthwidth of the rectangle
heightabsolute height of the rectangle
roundXrounding factor, x direction
roundYrounding factor, y direction

◆ DrawText()

void PdfPainter::DrawText ( const std::string_view &  str,
double  x,
double  y,
PdfDrawTextStyle  style = PdfDrawTextStyle::Regular 
)

Draw a single-line text string on a page using a given font object.

You have to call SetFont before calling this function.

Parameters
strthe text string which should be printed
xthe x coordinate
ythe y coordinate

◆ DrawTextAligned()

void PdfPainter::DrawTextAligned ( const std::string_view &  str,
double  x,
double  y,
double  width,
PdfHorizontalAlignment  hAlignment,
PdfDrawTextStyle  style = PdfDrawTextStyle::Regular 
)

Draw a single line of text horizontally aligned.

Parameters
strthe text to draw
xthe x coordinate of the text line
ythe y coordinate of the text line
widththe width of the text line
hAlignmentalignment of the text line
stylestyle of the draw text operation

◆ DrawTextMultiLine() [1/2]

void PoDoFo::PdfPainter::DrawTextMultiLine ( const std::string_view &  str,
const Rect rect,
const PdfDrawTextMultiLineParams &  params = { } 
)

Draw multiline text into a rectangle doing automatic wordwrapping.

The current font is used and SetFont has to be called at least once before using this function

Parameters
strthe text which should be drawn
rectbounding rectangle of the text
paramsparameters of the draw operation

◆ DrawTextMultiLine() [2/2]

void PoDoFo::PdfPainter::DrawTextMultiLine ( const std::string_view &  str,
double  x,
double  y,
double  width,
double  height,
const PdfDrawTextMultiLineParams &  params = { } 
)

Draw multiline text into a rectangle doing automatic wordwrapping.

The current font is used and SetFont has to be called at least once before using this function

Parameters
strthe text which should be drawn
xthe x coordinate of the text area (left)
ythe y coordinate of the text area (bottom)
widthwidth of the text area
heightheight of the text area
paramsparameters of the draw operation

◆ DrawXObject()

void PdfPainter::DrawXObject ( const PdfXObject obj,
double  x,
double  y,
double  scaleX = 1.0,
double  scaleY = 1.0 
)

Draw an XObject on the current page.

For PdfImage use DrawImage.

Parameters
xthe x coordinate (left position of the XObject)
ythe y coordinate (bottom position of the XObject)
objan PdfXObject
scaleXoption scaling factor in x direction
scaleYoption scaling factor in y direction
See also
DrawImage

◆ FinishDrawing()

void PdfPainter::FinishDrawing ( )

Finish drawing onto a canvas.

This has to be called whenever a page has been drawn complete.

◆ GetCanvas()

PdfCanvas* PoDoFo::PdfPainter::GetCanvas ( ) const
inline

Return the current page that is that on the painter.

Returns
the current page of the painter or nullptr if none is set

◆ GetPrecision()

unsigned short PdfPainter::GetPrecision ( ) const

Get the currently set floating point precision.

Returns
how many decimal places will be written out for any floating point value

◆ GetStream()

PdfObjectStream* PoDoFo::PdfPainter::GetStream ( ) const
inline

Return the current canvas stream that is set on the painter.

Returns
the current page canvas stream of the painter or nullptr if none is set

◆ GetTabWidth()

unsigned short PoDoFo::PdfPainter::GetTabWidth ( ) const
inline

Get the currently set tab width.

Returns
by how many spaces a tabulator will be replaced
See also
DrawText
TabWidth

◆ Restore()

void PdfPainter::Restore ( )

Restore the current graphics settings from the graphics stack.

Operator 'Q' in PDF. This call has to be balanced with a corresponding call to Save()!

See also
Save

◆ Save()

void PdfPainter::Save ( )

Save the current graphics settings onto the graphics stack.

Operator 'q' in PDF. This call has to be balanced with a corresponding call to Restore()!

See also
Restore

◆ SetCanvas()

void PdfPainter::SetCanvas ( PdfCanvas page)

Set the page on which the painter should draw.

The painter will draw of course on the pages contents object.

Calls FinishPage() on the last page if it was not yet called.

Parameters
pagea PdfCanvas object (most likely a PdfPage or PdfXObject).
See also
PdfPage
PdfXObject
FinishPage()

◆ SetClipRect() [1/2]

void PdfPainter::SetClipRect ( const Rect rect)

Set a clipping rectangle.

Parameters
rectrectangle

◆ SetClipRect() [2/2]

void PdfPainter::SetClipRect ( double  x,
double  y,
double  width,
double  height 
)

Set a clipping rectangle.

Parameters
xx coordinate of the rectangle (left coordinate)
yy coordinate of the rectangle (bottom coordinate)
widthwidth of the rectangle
heightabsolute height of the rectangle

◆ SetPrecision()

void PdfPainter::SetPrecision ( unsigned short  precision)

Set the floating point precision.

Parameters
precisionwrite this many decimal places

◆ SetStrokeStyle()

void PdfPainter::SetStrokeStyle ( PdfStrokeStyle  strokeStyle,
bool  inverted = false,
double  scale = 1.0,
bool  subtractJoinCap = false 
)

Set the stoke style for all stroking operations.

Parameters
strokeStylestyle of the stroking operations
customa custom stroking style which is used when strokeStyle == PdfStrokeStyle::Custom.
invertedinverted dash style (gaps for drawn spaces), it is ignored for None, Solid and Custom styles
scalescale factor of the stroke style it is ignored for None, Solid and Custom styles
subtractJoinCapif true, subtracts scaled width on filled parts, thus the line capability still draws into the cell; is used only if scale is not 1.0

Possible values: PdfStrokeStyle::None PdfStrokeStyle::Solid PdfStrokeStyle::Dash PdfStrokeStyle::Dot PdfStrokeStyle::DashDot PdfStrokeStyle::DashDotDot

◆ SetTabWidth()

void PoDoFo::PdfPainter::SetTabWidth ( unsigned short  tabWidth)
inline

Set the tab width for the DrawText operation.

Every tab '\t' is replaced with tabWidth spaces before drawing text. Default is a value of 4

Parameters
tabWidthreplace every tabulator by this much spaces
See also
DrawText
TabWidth

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