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

#include <PdfPainter.h>

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 SetStrokingTilingPattern (const std::string_view &patternName)
 
void SetTilingPattern (const PdfTilingPattern &pattern)
 
void SetTilingPattern (const std::string_view &patternName)
 
void SetStrokingColor (const PdfColor &color)
 
void SetColor (const PdfColor &color)
 
void SetStrokeWidth (double width)
 
void SetStrokeStyle (PdfStrokeStyle strokeStyle, const std::string_view &custom={ }, bool inverted=false, double scale=1.0, bool subtractJoinCap=false)
 
void SetLineCapStyle (PdfLineCapStyle capStyle)
 
void SetLineJoinStyle (PdfLineJoinStyle joinStyle)
 
void SetFont (PdfFont *font)
 
void SetTextRenderingMode (PdfTextRenderingMode mode)
 
void SetClipRect (double x, double y, double width, double height)
 
void SetClipRect (const PdfRect &rect)
 
void SetMiterLimit (double value)
 
void DrawLine (double startX, double startY, double endX, double endY)
 
void Rectangle (double x, double y, double width, double height, double roundX=0.0, double roundY=0.0)
 
void Rectangle (const PdfRect &rect, double roundX=0.0, double roundY=0.0)
 
void Ellipse (double x, double y, double width, double height)
 
void Circle (double x, double y, double radius)
 
void DrawText (double x, double y, const std::string_view &str)
 
void DrawMultiLineText (double x, double y, double width, double height, const std::string_view &str, PdfHorizontalAlignment hAlignment=PdfHorizontalAlignment::Left, PdfVerticalAlignment vAlignment=PdfVerticalAlignment::Top, bool clip=true, bool skipSpaces=true)
 
void DrawMultiLineText (const PdfRect &rect, const std::string_view &str, PdfHorizontalAlignment hAlignment=PdfHorizontalAlignment::Left, PdfVerticalAlignment vAlignment=PdfVerticalAlignment::Top, bool clip=true, bool skipSpaces=true)
 
void DrawTextAligned (double x, double y, double width, const std::string_view &str, PdfHorizontalAlignment hAlignment)
 
void BeginText (double x, double y)
 
void AddText (const std::string_view &str)
 
void MoveTextPos (double x, double y)
 
void EndText ()
 
void DrawImage (double x, double y, const PdfImage &obj, double scaleX=1.0, double scaleY=1.0)
 
void DrawXObject (double x, double y, const PdfXObject &obj, double scaleX=1.0, double scaleY=1.0)
 
void ClosePath ()
 
void LineTo (double x, double y)
 
void MoveTo (double x, double y)
 
void CubicBezierTo (double x1, double y1, double x2, double y2, double x3, double y3)
 
void HorizontalLineTo (double x)
 
void VerticalLineTo (double y)
 
void SmoothCurveTo (double x2, double y2, double x3, double y3)
 
void QuadCurveTo (double x1, double y1, double x3, double y3)
 
void SmoothQuadCurveTo (double x3, double y3)
 
void ArcTo (double x, double y, double radiusX, double radiusY, double rotation, bool large, bool sweep)
 
void Close ()
 
void Stroke ()
 
void Fill (bool useEvenOddRule=false)
 
void FillAndStroke (bool useEvenOddRule=false)
 
void Clip (bool useEvenOddRule=false)
 
void EndPath ()
 
void Save ()
 
void Restore ()
 
void SetTransformationMatrix (double a, double b, double c, double d, double e, double f)
 
void SetExtGState (const PdfExtGState &inGState)
 
void SetRenderingIntent (const std::string_view &intent)
 
void SetPrecision (unsigned short precision)
 
unsigned short GetPrecision () const
 
void SetDependICCProfileColor (const PdfColor &color, const std::string_view &csTag)
 
PdfTextRenderingMode GetTextRenderingMode () const
 
PdfFontGetFont () const
 
void SetTabWidth (unsigned short tabWidth)
 
unsigned short GetTabWidth () const
 
PdfCanvasGetCanvas () const
 
PdfStreamGetStream () const
 
std::ostringstream & GetCurrentPath ()
 
std::ostringstream & GetStream ()
 

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

◆ AddText()

void PdfPainter::AddText ( const std::string_view &  str)

Draw a string on a page. You have to call BeginText before the first call of this function and EndText after the last call.

If you want more simpler text output and do not need the advanced text position features of MoveTextPos use DrawText which is easier.

Parameters
sTextthe text string which should be printed
See also
SetFont()
MoveTextPos()
EndText()

◆ ArcTo()

void PdfPainter::ArcTo ( double  x,
double  y,
double  radiusX,
double  radiusY,
double  rotation,
bool  large,
bool  sweep 
)

Append a Arc to the current path Matches the SVG 'A' operator.

Parameters
xx coordinate of the start point
yy coordinate of the start point
dRadiusXx coordinate of the end point, which is the new current point
dRadiusYy coordinate of the end point, which is the new current point
dRotationdegree of rotation in radians
bLargelarge or small portion of the arc
bSweepsweep?

◆ BeginText()

void PdfPainter::BeginText ( double  x,
double  y 
)

Begin drawing multiple text strings on a page using a given font object. You have to call SetFont before calling this function.

If you want more simpler text output and do not need the advanced text position features of MoveTextPos use DrawText which is easier.

Parameters
xthe x coordinate
ythe y coordinate
See also
SetFont()
AddText()
MoveTextPos()
EndText()

◆ Circle()

void PdfPainter::Circle ( double  x,
double  y,
double  radius 
)

Add a circle into the current path

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

◆ Clip()

void PdfPainter::Clip ( bool  useEvenOddRule = false)

Clip the current path. Matches the PDF 'W' operator. This function is useful to construct an own path for drawing or clipping.

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

◆ Close()

void PdfPainter::Close ( )

Close the current path. Matches the PDF 'h' operator.

◆ ClosePath()

void PdfPainter::ClosePath ( )

Closes the current path by drawing a line from the current point to the starting point of the path. Matches the PDF 'h' operator. This function is useful to construct an own path for drawing or clipping.

◆ CubicBezierTo()

void PdfPainter::CubicBezierTo ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)

Append a cubic bezier curve to the current path Matches the PDF 'c' operator.

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

◆ DrawImage()

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

Draw an image on the current page.

Parameters
xthe x coordinate (bottom 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  startX,
double  startY,
double  endX,
double  endY 
)

Draw a line with the current color and line settings.

Parameters
startXx coordinate of the starting point
startYy coordinate of the starting point
endXx coordinate of the ending point
endYy coordinate of the ending point

◆ DrawMultiLineText() [1/2]

void mm::PdfPainter::DrawMultiLineText ( const PdfRect rect,
const std::string_view &  str,
PdfHorizontalAlignment  hAlignment = PdfHorizontalAlignment::Left,
PdfVerticalAlignment  vAlignment = PdfVerticalAlignment::Top,
bool  clip = true,
bool  skipSpaces = true 
)

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
rectbounding rectangle of the text
textthe text which should be drawn
eAlignmentalignment of the individual text lines in the given bounding box
eVerticalvertical alignment of the text in the given bounding box
bClipset the clipping rectangle to the given rect, otherwise no clipping is performed
bSkipSpaceswhether the trailing whitespaces should be skipped, so that next line doesn't start with whitespace

◆ DrawMultiLineText() [2/2]

void mm::PdfPainter::DrawMultiLineText ( double  x,
double  y,
double  width,
double  height,
const std::string_view &  str,
PdfHorizontalAlignment  hAlignment = PdfHorizontalAlignment::Left,
PdfVerticalAlignment  vAlignment = PdfVerticalAlignment::Top,
bool  clip = true,
bool  skipSpaces = true 
)

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
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
textthe text which should be drawn
eAlignmentalignment of the individual text lines in the given bounding box
eVerticalvertical alignment of the text in the given bounding box
bClipset the clipping rectangle to the given rect, otherwise no clipping is performed
bSkipSpaceswhether the trailing whitespaces should be skipped, so that next line doesn't start with whitespace

◆ DrawText()

void PdfPainter::DrawText ( double  x,
double  y,
const std::string_view &  str 
)

Draw a single-line text string on a page using a given font object. You have to call SetFont before calling this function.

Parameters
xthe x coordinate
ythe y coordinate
sTextthe text string which should be printed
See also
SetFont()

◆ DrawTextAligned()

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

Draw a single line of text horizontally aligned.

Parameters
xthe x coordinate of the text line
ythe y coordinate of the text line
widththe width of the text line
textthe text to draw
eAlignmentalignment of the text line

◆ DrawXObject()

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

Draw an XObject on the current page. For PdfImage use DrawImage.

Parameters
xthe x coordinate (bottom 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

◆ Ellipse()

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

Add an ellipse into the current path

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

◆ EndPath()

void PdfPainter::EndPath ( )

End current pathm without filling or stroking it. Matches the PDF 'n' operator.

◆ EndText()

void PdfPainter::EndText ( )

End drawing multiple text strings on a page

If you want more simpler text output and do not need the advanced text position features of MoveTextPos use DrawText which is easier.

See also
BeginText()
AddText()
MoveTextPos()

◆ Fill()

void PdfPainter::Fill ( bool  useEvenOddRule = false)

Fill the current path. Matches the PDF 'f' operator. This function is useful to construct an own path for drawing or clipping.

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

◆ FillAndStroke()

void PdfPainter::FillAndStroke ( bool  useEvenOddRule = false)

Fill then stroke the current path. Matches the PDF 'B' operator.

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

◆ FinishDrawing()

void PdfPainter::FinishDrawing ( )

Finish drawing onto a canvas.

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

◆ GetCanvas()

PdfCanvas * mm::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

◆ GetCurrentPath()

std::ostringstream & mm::PdfPainter::GetCurrentPath ( )
inline

Get current path string stream. Stroke/Fill commands clear current path.

Returns
std::ostringstream representing current path

◆ GetFont()

PdfFont * mm::PdfPainter::GetFont ( ) const
inline

Get the current font:

Returns
a font object or nullptr if no font was 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() [1/2]

std::ostringstream & mm::PdfPainter::GetStream ( )
inline

Get current temporary stream

◆ GetStream() [2/2]

PdfStream * mm::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 mm::PdfPainter::GetTabWidth ( ) const
inline

Get the currently set tab width

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

◆ GetTextRenderingMode()

PdfTextRenderingMode mm::PdfPainter::GetTextRenderingMode ( ) const
inline

Gets current text rendering mode. Default mode is PdfTextRenderingMode::Fill.

◆ HorizontalLineTo()

void PdfPainter::HorizontalLineTo ( double  x)

Append a horizontal line to the current path Matches the SVG 'H' operator

Parameters
xx coordinate to draw the line to

◆ LineTo()

void PdfPainter::LineTo ( double  x,
double  y 
)

Append a line segment to the current path. Matches the PDF 'l' operator. This function is useful to construct an own path for drawing or clipping.

Parameters
xx position
yy position

◆ MoveTextPos()

void PdfPainter::MoveTextPos ( double  x,
double  y 
)

Move position for text drawing on a page. You have to call BeginText before calling this function

If you want more simpler text output and do not need the advanced text position features of MoveTextPos use DrawText which is easier.

Parameters
xthe x offset relative to pos of BeginText or last MoveTextPos
ythe y offset relative to pos of BeginText or last MoveTextPos
See also
BeginText()
AddText()
EndText()

◆ MoveTo()

void PdfPainter::MoveTo ( double  x,
double  y 
)

Begin a new path. Matches the PDF 'm' operator. This function is useful to construct an own path for drawing or clipping.

Parameters
xx position
yy position

◆ QuadCurveTo()

void PdfPainter::QuadCurveTo ( double  x1,
double  y1,
double  x3,
double  y3 
)

Append a quadratic bezier curve to the current path Matches the SVG 'Q' operator.

Parameters
x1x coordinate of the first control point
y1y coordinate of the first control point
x3x coordinate of the end point, which is the new current point
y3y coordinate of the end point, which is the new current point

◆ Rectangle() [1/2]

void PdfPainter::Rectangle ( const PdfRect rect,
double  roundX = 0.0,
double  roundY = 0.0 
)

Add a rectangle into the current path

Parameters
rectthe rectangle area
roundXrounding factor, x direction
roundYrounding factor, y direction
See also
DrawRect

◆ Rectangle() [2/2]

void PdfPainter::Rectangle ( double  x,
double  y,
double  width,
double  height,
double  roundX = 0.0,
double  roundY = 0.0 
)

Add a rectangle into the current path

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

◆ 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 PdfRect 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

◆ SetColor()

void PdfPainter::SetColor ( const PdfColor color)

Set the color for all following non-stroking operations.

Parameters
colora PdfColor object

◆ SetDependICCProfileColor()

void PdfPainter::SetDependICCProfileColor ( const PdfColor color,
const std::string_view &  csTag 
)

Set rgb color that depend on color space setting, "cs" tag.

Parameters
colora PdfColor object
csTaga CS tag used in PdfPage::SetICCProfile
See also
PdfPage::SetICCProfile()

◆ SetExtGState()

void PdfPainter::SetExtGState ( const PdfExtGState inGState)

Sets a specific PdfExtGState as being active

Parameters
inGStatethe specific ExtGState to set

◆ SetFont()

void PdfPainter::SetFont ( PdfFont font)

Set the font for all text drawing operations

Parameters
fonta handle to a valid PdfFont object
See also
DrawText

◆ SetLineCapStyle()

void PdfPainter::SetLineCapStyle ( PdfLineCapStyle  capStyle)

Set the line cap style for all stroking operations.

Parameters
eCapStylethe cap style.

Possible values: PdfLineCapStyle::Butt, PdfLineCapStyle::Round, PdfLineCapStyle::Square

◆ SetLineJoinStyle()

void PdfPainter::SetLineJoinStyle ( PdfLineJoinStyle  joinStyle)

Set the line join style for all stroking operations.

Parameters
eJoinStylethe join style.

Possible values: PdfLineJoinStyle::Miter PdfLineJoinStyle::Round PdfLineJoinStyle::Bevel

◆ SetMiterLimit()

void PdfPainter::SetMiterLimit ( double  value)

Set miter limit.

◆ SetPrecision()

void PdfPainter::SetPrecision ( unsigned short  precision)

Set the floating point precision.

Parameters
precisionwrite this many decimal places

◆ SetRenderingIntent()

void PdfPainter::SetRenderingIntent ( const std::string_view &  intent)

Sets a specific rendering intent

Parameters
intentthe specific intent to set

◆ 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
rPatterna shading pattern

◆ SetStrokeStyle()

void PdfPainter::SetStrokeStyle ( PdfStrokeStyle  strokeStyle,
const std::string_view &  custom = { },
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 PdfStrokeStyle::Custom

◆ SetStrokeWidth()

void PdfPainter::SetStrokeWidth ( double  width)

Set the line width for all stroking operations.

Parameters
widthin PDF User Units.

◆ SetStrokingColor()

void PdfPainter::SetStrokingColor ( const PdfColor color)

Set the color for all following stroking operations.

Parameters
colora PdfColor object

◆ SetStrokingShadingPattern()

void PdfPainter::SetStrokingShadingPattern ( const PdfShadingPattern pattern)

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

Parameters
rPatterna shading pattern

◆ SetStrokingTilingPattern() [1/2]

void PdfPainter::SetStrokingTilingPattern ( const PdfTilingPattern pattern)

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

Parameters
rPatterna tiling pattern

◆ SetStrokingTilingPattern() [2/2]

void mm::PdfPainter::SetStrokingTilingPattern ( const std::string_view &  patternName)

Set the tiling pattern for all following stroking operations by pattern name, Use when it's already in resources. This operation uses the 'SCN' PDF operator.

Parameters
rPatternNamea tiling pattern name

◆ SetTabWidth()

void mm::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

◆ SetTextRenderingMode()

void PdfPainter::SetTextRenderingMode ( PdfTextRenderingMode  mode)

◆ SetTilingPattern() [1/2]

void PdfPainter::SetTilingPattern ( const PdfTilingPattern pattern)

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

Parameters
rPatterna tiling pattern

◆ SetTilingPattern() [2/2]

void PdfPainter::SetTilingPattern ( const std::string_view &  patternName)

Set the tiling pattern for all following non-stroking operations by pattern name. Use when it's already in resources. This operation uses the 'scn' PDF operator.

Parameters
rPatterna tiling pattern

◆ SetTransformationMatrix()

void PdfPainter::SetTransformationMatrix ( double  a,
double  b,
double  c,
double  d,
double  e,
double  f 
)

Set the transformation matrix for the current coordinate system See the operator 'cm' in PDF.

The six parameters are a standard 3x3 transformation matrix where the 3 left parameters are 0 0 1.

Parameters
ascale in x direction
brotation
crotation
dscale in y direction
etranslate in x direction
ftranslate in y direction
See also
Save()
Restore()

◆ SmoothCurveTo()

void PdfPainter::SmoothCurveTo ( double  x2,
double  y2,
double  x3,
double  y3 
)

Append a smooth bezier curve to the current path Matches the SVG 'S' operator.

Parameters
x2x coordinate of the second control point
y2y coordinate of the second control point
x3x coordinate of the end point, which is the new current point
y3y coordinate of the end point, which is the new current point

◆ SmoothQuadCurveTo()

void PdfPainter::SmoothQuadCurveTo ( double  x3,
double  y3 
)

Append a smooth quadratic bezier curve to the current path Matches the SVG 'T' operator.

Parameters
x3x coordinate of the end point, which is the new current point
y3y coordinate of the end point, which is the new current point

◆ Stroke()

void PdfPainter::Stroke ( )

Stroke the current path. Matches the PDF 'S' operator. This function is useful to construct an own path for drawing or clipping.

◆ VerticalLineTo()

void PdfPainter::VerticalLineTo ( double  y)

Append a vertical line to the current path Matches the SVG 'V' operator

Parameters
yy coordinate to draw the line to