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

#include <PdfPainter.h>

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

Public Member Functions

 PdfPainter (PdfPainterFlags flags=PdfPainterFlags::None)
 
void SetCanvas (PdfCanvas &page)
 
void FinishDrawing ()
 
void SetStrokingShadingPattern (const PdfShadingPattern &pattern)
 
void SetShadingPattern (const PdfShadingPattern &pattern)
 
void SetStrokingTilingPattern (const PdfTilingPattern &pattern)
 
void SetTilingPattern (const PdfTilingPattern &pattern)
 
void SetStrokeStyle (PdfStrokeStyle strokeStyle, bool inverted=false, double scale=1.0, bool subtractJoinCap=false)
 
void SetClipRect (double x, double y, double width, double height)
 
void SetClipRect (const Rect &rect)
 
void DrawLine (double x1, double y1, double x2, double y2)
 
void DrawCubicBezier (double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
 
void DrawArc (double x, double y, double radius, double startAngle, double endAngle, bool clockwise=false)
 
void DrawCircle (double x, double y, double radius, PdfPathDrawMode mode=PdfPathDrawMode::Stroke)
 
void DrawEllipse (double x, double y, double width, double height, PdfPathDrawMode mode=PdfPathDrawMode::Stroke)
 
void DrawRectangle (double x, double y, double width, double height, PdfPathDrawMode mode=PdfPathDrawMode::Stroke, double roundX=0.0, double roundY=0.0)
 
void DrawRectangle (const Rect &rect, PdfPathDrawMode mode=PdfPathDrawMode::Stroke, double roundX=0.0, double roundY=0.0)
 
void DrawText (const std::string_view &str, double x, double y, PdfDrawTextStyle style=PdfDrawTextStyle::Regular)
 
void DrawTextMultiLine (const std::string_view &str, double x, double y, double width, double height, const PdfDrawTextMultiLineParams &params={ })
 
void DrawTextMultiLine (const std::string_view &str, const Rect &rect, const PdfDrawTextMultiLineParams &params={ })
 
void DrawTextAligned (const std::string_view &str, double x, double y, double width, PdfHorizontalAlignment hAlignment, PdfDrawTextStyle style=PdfDrawTextStyle::Regular)
 
void DrawImage (const PdfImage &obj, double x, double y, double scaleX=1.0, double scaleY=1.0)
 
void DrawXObject (const PdfXObject &obj, double x, double y, double scaleX=1.0, double scaleY=1.0)
 
void DrawPath (const PdfPainterPath &path, PdfPathDrawMode drawMode=PdfPathDrawMode::Stroke)
 
void ClipPath (const PdfPainterPath &path, bool useEvenOddRule=false)
 
void BeginMarkedContent (const std::string_view &tag)
 
void EndMarkedContent ()
 
void Save ()
 
void Restore ()
 
void SetExtGState (const PdfExtGState &inGState)
 
void SetPrecision (unsigned short precision)
 
unsigned short GetPrecision () const
 
std::string_view GetContent () const
 
void SetTabWidth (unsigned short tabWidth)
 
unsigned short GetTabWidth () const
 
PdfCanvasGetCanvas () const
 
PdfObjectStreamGetStream () const
 

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.

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

◆ BeginMarkedContent()

void PdfPainter::BeginMarkedContent ( const std::string_view &  tag)

Begin a marked-content sequence (operator BMC)

◆ 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

◆ DrawPath()

void PdfPainter::DrawPath ( const PdfPainterPath path,
PdfPathDrawMode  drawMode = PdfPathDrawMode::Stroke 
)

Draw the current path with the given

◆ 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

◆ EndMarkedContent()

void PdfPainter::EndMarkedContent ( )

End a marked-content sequence begun by a BMC or BDC operator

◆ 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

◆ GetContent()

string_view PdfPainter::GetContent ( ) const

Get a string view of the current content stream being built

◆ 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

◆ SetExtGState()

void PdfPainter::SetExtGState ( const PdfExtGState inGState)

Sets a specific PdfExtGState as being active

Parameters
inGStatethe specific ExtGState to set

◆ SetPrecision()

void PdfPainter::SetPrecision ( unsigned short  precision)

Set the floating point precision.

Parameters
precisionwrite this many decimal places

◆ SetShadingPattern()

void PdfPainter::SetShadingPattern ( const PdfShadingPattern pattern)

Set the shading pattern for all following non-stroking operations. This operation uses the 'scn' PDF operator.

Parameters
patterna shading pattern

◆ 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

◆ SetStrokingShadingPattern()

void PdfPainter::SetStrokingShadingPattern ( const PdfShadingPattern pattern)

Set the shading pattern for all following stroking operations. This operation uses the 'SCN' PDF operator.

Parameters
patterna shading pattern

◆ SetStrokingTilingPattern()

void PdfPainter::SetStrokingTilingPattern ( const PdfTilingPattern pattern)

Set the tiling pattern for all following stroking operations. This operation uses the 'SCN' PDF operator.

Parameters
patterna tiling pattern

◆ 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

◆ SetTilingPattern()

void PdfPainter::SetTilingPattern ( const PdfTilingPattern pattern)

Set the tiling pattern for all following non-stroking operations. This operation uses the 'scn' PDF operator.

Parameters
patterna tiling pattern