PoDoFo
1.0.0-dev
|
This class provides an easy to use painter object which allows you to draw on a PDF page object. More...
#include <PdfPainter.h>
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 ¶ms={ }) |
Draw multiline text into a rectangle doing automatic wordwrapping. More... | |
void | DrawTextMultiLine (const std::string_view &str, const Rect &rect, const PdfDrawTextMultiLineParams ¶ms={ }) |
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... | |
PdfCanvas * | GetCanvas () const |
Return the current page that is that on the painter. More... | |
PdfObjectStream * | GetStream () 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 | |
PdfContentStreamOperators & | operator= (const PdfContentStreamOperators &)=default |
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.
PdfPainter::PdfPainter | ( | PdfPainterFlags | flags = PdfPainterFlags::None | ) |
Create a new PdfPainter object.
saveRestore | do save/restore state before appending |
void PdfPainter::ClipPath | ( | const PdfPainterPath & | path, |
bool | useEvenOddRule = false |
||
) |
Clip the current path.
Matches the PDF 'W' operator.
useEvenOddRule | select even-odd rule instead of nonzero winding number rule |
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.
x | x coordinate of the center of the arc (left coordinate) |
y | y coordinate of the center of the arc (top coordinate) |
radius | radius |
startAngle | startAngle in radians measured counterclockwise from the origin |
endAngle | endAngle in radians measured counterclockwise from the origin |
clockwise | The arc is drawn clockwise instead |
void PdfPainter::DrawCircle | ( | double | x, |
double | y, | ||
double | radius, | ||
PdfPathDrawMode | mode = PdfPathDrawMode::Stroke |
||
) |
Draw a circle.
x | x center coordinate of the circle |
y | y coordinate of the circle |
radius | radius of the circle |
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.
x1 | x coordinate of the starting point |
y1 | y coordinate of the starting point |
x2 | x coordinate of the first control point |
y2 | y coordinate of the first control point |
x3 | x coordinate of the second control point |
y3 | y coordinate of the second control point |
x4 | x coordinate of the end point, which is the new current point |
y5 | y coordinate of the end point, which is the new current point |
void PdfPainter::DrawEllipse | ( | double | x, |
double | y, | ||
double | width, | ||
double | height, | ||
PdfPathDrawMode | mode = PdfPathDrawMode::Stroke |
||
) |
Draw an ellipse to the given coordinates.
x | x coordinate of the ellipse (left coordinate) |
y | y coordinate of the ellipse (top coordinate) |
width | width of the ellipse |
height | absolute height of the ellipse |
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.
x | the x coordinate (left position of the image) |
y | the y coordinate (bottom position of the image) |
obj | an PdfXObject |
scaleX | option scaling factor in x direction |
scaleY | option scaling factor in y direction |
void PdfPainter::DrawLine | ( | double | x1, |
double | y1, | ||
double | x2, | ||
double | y2 | ||
) |
Stroke a line with current color and line settings.
x1 | x coordinate of the starting point |
y1 | y coordinate of the starting point |
x2 | x coordinate of the ending point |
y2 | y coordinate of the ending point |
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.
rect | the rectangle area |
roundX | rounding factor, x direction |
roundY | rounding factor, y direction |
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.
x | x coordinate of the rectangle (left coordinate) |
y | y coordinate of the rectangle (bottom coordinate) |
width | width of the rectangle |
height | absolute height of the rectangle |
roundX | rounding factor, x direction |
roundY | rounding factor, y direction |
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.
str | the text string which should be printed |
x | the x coordinate |
y | the y coordinate |
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.
str | the text to draw |
x | the x coordinate of the text line |
y | the y coordinate of the text line |
width | the width of the text line |
hAlignment | alignment of the text line |
style | style of the draw text operation |
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
str | the text which should be drawn |
rect | bounding rectangle of the text |
params | parameters of the draw operation |
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
str | the text which should be drawn |
x | the x coordinate of the text area (left) |
y | the y coordinate of the text area (bottom) |
width | width of the text area |
height | height of the text area |
params | parameters of the draw operation |
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.
x | the x coordinate (left position of the XObject) |
y | the y coordinate (bottom position of the XObject) |
obj | an PdfXObject |
scaleX | option scaling factor in x direction |
scaleY | option scaling factor in y direction |
void PdfPainter::FinishDrawing | ( | ) |
Finish drawing onto a canvas.
This has to be called whenever a page has been drawn complete.
|
inline |
Return the current page that is that on the painter.
unsigned short PdfPainter::GetPrecision | ( | ) | const |
Get the currently set floating point precision.
|
inline |
Return the current canvas stream that is set on the painter.
|
inline |
Get the currently set tab width.
void PdfPainter::Restore | ( | ) |
void PdfPainter::Save | ( | ) |
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.
page | a PdfCanvas object (most likely a PdfPage or PdfXObject). |
void PdfPainter::SetClipRect | ( | const Rect & | rect | ) |
Set a clipping rectangle.
rect | rectangle |
void PdfPainter::SetClipRect | ( | double | x, |
double | y, | ||
double | width, | ||
double | height | ||
) |
Set a clipping rectangle.
x | x coordinate of the rectangle (left coordinate) |
y | y coordinate of the rectangle (bottom coordinate) |
width | width of the rectangle |
height | absolute height of the rectangle |
void PdfPainter::SetPrecision | ( | unsigned short | precision | ) |
Set the floating point precision.
precision | write this many decimal places |
void PdfPainter::SetStrokeStyle | ( | PdfStrokeStyle | strokeStyle, |
bool | inverted = false , |
||
double | scale = 1.0 , |
||
bool | subtractJoinCap = false |
||
) |
Set the stoke style for all stroking operations.
strokeStyle | style of the stroking operations |
custom | a custom stroking style which is used when strokeStyle == PdfStrokeStyle::Custom. |
inverted | inverted dash style (gaps for drawn spaces), it is ignored for None, Solid and Custom styles |
scale | scale factor of the stroke style it is ignored for None, Solid and Custom styles |
subtractJoinCap | if 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
|
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
tabWidth | replace every tabulator by this much spaces |