9#include "PdfTextState.h"
10#include "PdfGraphicsState.h"
11#include "PdfPainterPath.h"
12#include "PdfPainterTextObject.h"
13#include "PdfColorSpace.h"
14#include "PdfPattern.h"
15#include "PdfContentStreamOperators.h"
17#include <podofo/auxiliary/StateStack.h>
32 NoSaveRestorePrior = 2,
47enum class PdfDrawTextStyle : uint8_t
54struct PODOFO_API PdfDrawTextMultiLineParams final
56 PdfDrawTextStyle Style = PdfDrawTextStyle::Regular;
59 bool SkipClip =
false;
60 bool PreserveTrailingSpaces =
false;
63struct PODOFO_API PdfPainterState final
67 PdfGraphicsState GraphicsState;
68 PdfTextState TextState;
69 nullable<Vector2> FirstPoint;
70 nullable<Vector2> CurrentPoint;
72 friend class PdfPainter;
74 PdfTextState EmittedTextState;
77using PdfPainterStateStack = StateStack<PdfPainterState>;
79class PODOFO_API PdfGraphicsStateWrapper final
81 friend class PdfPainter;
84 PdfGraphicsStateWrapper(PdfPainter& painter, PdfGraphicsState& state);
89 void ConcatenateTransformationMatrix(
const Matrix& matrix);
90 void SetLineWidth(
double lineWidth);
91 void SetMiterLevel(
double value);
92 void SetLineCapStyle(PdfLineCapStyle capStyle);
93 void SetLineJoinStyle(PdfLineJoinStyle joinStyle);
94 void SetRenderingIntent(
const std::string_view& intent);
96 void SetNonStrokingColorSpace(PdfColorSpaceInitializer&& colorSpace);
98 void SetStrokingColorSpace(PdfColorSpaceInitializer&& color);
100 void SetNonStrokingColor(
const PdfColor& color);
102 void SetStrokingColor(
const PdfColor& color);
104 void SetNonStrokingColor(
const PdfColorRaw& color);
106 void SetStrokingColor(
const PdfColorRaw& color);
107 void SetExtGState(
const PdfExtGState& extGState);
109 void SetStrokingUncolouredTilingPattern(
const PdfUncolouredTilingPattern& pattern,
const PdfColorRaw& color);
112 void SetNonStrokingUncolouredTilingPattern(
const PdfUncolouredTilingPattern& pattern,
const PdfColorRaw& color);
114 void SetStrokingPattern(
const PdfPattern& pattern);
116 void SetNonStrokingPattern(
const PdfPattern& pattern);
118 void SetShadingDictionary(
const PdfShadingDictionary& shading);
122 const Matrix& GetCurrentMatrix() {
return m_state->CTM; }
123 double GetLineWidth()
const {
return m_state->LineWidth; }
124 double GetMiterLevel()
const {
return m_state->MiterLimit; }
125 PdfLineCapStyle GetLineCapStyle()
const {
return m_state->LineCapStyle; }
126 PdfLineJoinStyle GetLineJoinStyle()
const {
return m_state->LineJoinStyle; }
127 const std::string& GetRenderingIntent()
const {
return m_state->RenderingIntent; }
128 const PdfColorRaw& GetNonStrokingColor()
const {
return m_state->NonStrokingColor; }
129 const PdfColorRaw& GetStrokingColor()
const {
return m_state->StrokingColor; }
134 operator const PdfGraphicsState&()
const {
return *m_state; }
137 void SetState(PdfGraphicsState& state) { m_state = &state; }
140 PdfPainter* m_painter;
141 PdfGraphicsState* m_state;
144class PODOFO_API PdfTextStateWrapper final
146 friend class PdfPainter;
149 PdfTextStateWrapper(PdfPainter& painter, PdfTextState& state);
152 void SetFont(
const PdfFont& font,
double fontSize);
157 void SetFontScale(
double scale);
161 void SetCharSpacing(
double charSpacing);
165 void SetWordSpacing(
double wordSpacing);
167 void SetRenderingMode(PdfTextRenderingMode mode);
171 void SetMatrix(
const Matrix& matrix);
174 inline const PdfFont* GetFont()
const {
return m_State->Font; }
178 inline double GetFontSize()
const {
return m_State->FontSize; }
182 inline double GetFontScale()
const {
return m_State->FontScale; }
186 inline double GetCharSpacing()
const {
return m_State->CharSpacing; }
190 inline double GetWordSpacing()
const {
return m_State->WordSpacing; }
195 const PdfTextState& GetState()
const {
return *m_State; }
196 operator const PdfTextState&()
const {
return *m_State; }
199 void SetState(PdfTextState& state) { m_State = &state; }
202 PdfPainter* m_painter;
203 PdfTextState* m_State;
218 friend class PdfGraphicsStateWrapper;
219 friend class PdfTextStateWrapper;
220 friend class PdfPainterPathContext;
246 void FinishDrawing();
276 void SetClipRect(
double x,
double y,
double width,
double height);
288 void DrawLine(
double x1,
double y1,
double x2,
double y2);
299 void DrawCubicBezier(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4);
322 void DrawEllipse(
double x,
double y,
double width,
double height,
332 void DrawRectangle(
double x,
double y,
double width,
double height,
347 void DrawText(
const std::string_view&
str,
double x,
double y,
348 PdfDrawTextStyle
style = PdfDrawTextStyle::Regular);
361 const PdfDrawTextMultiLineParams&
params = { });
371 const PdfDrawTextMultiLineParams&
params = { });
380 void DrawTextAligned(
const std::string_view&
str,
double x,
double y,
382 PdfDrawTextStyle
style = PdfDrawTextStyle::Regular);
411 void BeginMarkedContent(
const std::string_view&
tag);
414 void EndMarkedContent();
435 void SetPrecision(
unsigned short precision);
439 unsigned short GetPrecision()
const;
442 std::string_view GetContent()
const;
445 inline const PdfPainterStateStack& GetStateStack()
const {
return m_StateStack; }
478 void TextMoveTo(
double x,
double y);
479 void AddText(
const std::string_view&
str);
483 void SetLineWidth(
double value);
495 void SetShadingDictionary(
const PdfShadingDictionary&
shading);
496 void SetRenderingIntent(
const std::string_view&
intent);
497 void SetTransformationMatrix(
const Matrix&
matrix);
499 void SetFontScale(
double value);
500 void SetCharSpacing(
double value);
501 void SetWordSpacing(
double value);
503 void SetTextMatrix(
const Matrix&
matrix);
507 void writeTextState();
509 void setFontScale(
double value);
510 void setCharSpacing(
double value);
511 void setWordSpacing(
double value);
513 void setTextMatrix(
const Matrix& value);
524 void drawLines(
const std::vector<std::array<double, 4>>&
lines);
528 void re_Operator(
double x,
double y,
double width,
double height)
override;
529 void m_Operator(
double x,
double y)
override;
530 void l_Operator(
double x,
double y)
override;
531 void c_Operator(
double c1x,
double c1y,
double c2x,
double c2y,
double x,
double y)
override;
532 void v_Operator(
double cx,
double cy,
double x,
double y)
override;
533 void y_Operator(
double cx,
double cy,
double x,
double y)
override;
534 void n_Operator()
override;
535 void h_Operator()
override;
536 void b_Operator()
override;
537 void B_Operator()
override;
538 void bStar_Operator()
override;
539 void BStar_Operator()
override;
540 void s_Operator()
override;
541 void S_Operator()
override;
542 void f_Operator()
override;
543 void fStar_Operator()
override;
544 void W_Operator()
override;
545 void WStar_Operator()
override;
546 void MP_Operator(
const std::string_view&
tag)
override;
548 void DP_Operator(
const std::string_view&
tag,
const std::string_view&
propertyDictName)
override;
549 void BMC_Operator(
const std::string_view&
tag)
override;
551 void BDC_Operator(
const std::string_view&
tag,
const std::string_view&
propertyDictName)
override;
552 void EMC_Operator()
override;
553 void q_Operator()
override;
554 void Q_Operator()
override;
555 void BT_Operator()
override;
556 void ET_Operator()
override;
557 void Td_Operator(
double tx,
double ty)
override;
558 void TD_Operator(
double tx,
double ty)
override;
559 void Tm_Operator(
double a,
double b,
double c,
double d,
double e,
double f)
override;
561 void Ts_Operator(
double rise)
override;
562 void Tc_Operator(
double charSpace)
override;
563 void TL_Operator(
double leading)
override;
564 void Tf_Operator(
const std::string_view&
fontName,
double fontSize)
override;
565 void Tw_Operator(
double wordSpace)
override;
566 void Tz_Operator(
double scale)
override;
567 void Tj_Operator(
const std::string_view&
encoded,
bool hex)
override;
568 void TJ_Operator_Begin()
override;
569 void TJ_Operator_Delta(
double delta)
override;
570 void TJ_Operator_Glyphs(
const std::string_view&
encoded,
bool hex)
override;
571 void TJ_Operator_End()
override;
572 void cm_Operator(
double a,
double b,
double c,
double d,
double e,
double f)
override;
573 void w_Operator(
double lineWidth)
override;
578 void ri_Operator(
const std::string_view&
intent)
override;
579 void i_Operator(
double flatness)
override;
580 void gs_Operator(
const std::string_view&
dictName)
override;
581 void Do_Operator(
const std::string_view&
xobjname)
override;
583 void cs_Operator(
const std::string_view&
name)
override;
585 void CS_Operator(
const std::string_view&
name)
override;
592 void scn_Operator(
const std::string_view&
patternName)
override;
593 void SCN_Operator(
const std::string_view&
patternName)
override;
594 void G_Operator(
double gray)
override;
595 void g_Operator(
double gray)
override;
596 void RG_Operator(
double red,
double green,
double blue)
override;
597 void rg_Operator(
double red,
double green,
double blue)
override;
601 void BX_Operator()
override;
602 void EX_Operator()
override;
609 StatusTextObject = 2,
615 void drawTextAligned(
const std::string_view& str,
double x,
double y,
double width,
616 PdfHorizontalAlignment hAlignment, PdfDrawTextStyle style, std::vector<std::array<double, 4>>& linesToDraw,
617 std::string_view encoded);
619 void drawText(
const std::string_view& str,
double x,
double y,
620 bool isUnderline,
bool isStrikeThrough, std::vector<std::array<double, 4>>& linesToDraw,
621 std::string_view encoded);
623 void drawMultiLineText(
const std::string_view& str,
double x,
double y,
double width,
double height,
624 PdfHorizontalAlignment hAlignment, PdfVerticalAlignment vAlignment,
bool skipClip,
bool preserveTrailingSpaces,
625 PdfDrawTextStyle style);
627 void setLineWidth(
double width);
635 std::string expandTabs(
const std::string_view& str)
const;
637 void openPath(
double x,
double y);
639 void checkPathOpened()
const;
640 void checkFont()
const;
641 void finishDrawing();
642 void checkStatus(
int expectedStatus);
643 void enterTextObject();
644 void exitTextObject();
647 PdfPainter(
const PdfPainter&) =
delete;
648 PdfPainter& operator=(
const PdfPainter&) =
delete;
651 PdfPainterFlags m_flags;
652 PainterStatus m_painterStatus;
653 PdfPainterStateStack m_StateStack;
654 unsigned m_textStackCount;
657 PdfGraphicsStateWrapper GraphicsState;
658 PdfTextStateWrapper TextState;
659 PdfPainterTextObject TextObject;
665 PdfObjectStream* m_objStream;
673 unsigned short m_TabWidth;
676 PdfStringStream m_stream;
678 std::unordered_map<PdfReference, PdfName> m_resNameCache;
684ENABLE_BITMASK_OPERATORS(PoDoFo::PdfDrawTextStyle);
An interface that provides the necessary features for a painter to draw onto a PdfObject.
Definition PdfCanvas.h:25
A class that implements methods to sample colors from a scanline buffer.
Definition PdfColorSpaceFilter.h:27
A color object can represent either a grayscale value, a RGB color, a CMYK color.
Definition PdfColor.h:20
Pdf content stream callble operator interface ISO 32000 - 1:2008 "A.2 PDF Content Stream Operators".
Definition PdfContentStreamOperators.h:17
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such repre...
Definition PdfDictionary.h:77
This class wraps the ExtGState object used in the Resource Dictionary of a Content-supporting element...
Definition PdfExtGState.h:20
Before you can draw text on a PDF document, you have to create a font object first.
Definition PdfFont.h:42
A PdfImage object is needed when ever you want to embed an image file into a PDF document.
Definition PdfImage.h:68
This class represents a PdfName.
Definition PdfName.h:21
A PDF stream can be appended to any PdfObject and can contain arbitrary data.
Definition PdfObjectStream.h:82
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
This class describes PDF paths being written to a PdfPainter.
Definition PdfPainterPath.h:15
This class describes a manually handled PDF text object (content stream operators surrounded by BT .
Definition PdfPainterTextObject.h:18
This class provides an easy to use painter object which allows you to draw on a PDF page object.
Definition PdfPainter.h:217
void SetTabWidth(unsigned short tabWidth)
Set the tab width for the DrawText operation.
Definition PdfPainter.h:455
void DrawTextMultiLine(const std::string_view &str, const Rect &rect, const PdfDrawTextMultiLineParams ¶ms={ })
Draw multiline text into a rectangle doing automatic wordwrapping.
PdfCanvas * GetCanvas() const
Return the current page that is that on the painter.
Definition PdfPainter.h:467
unsigned short GetTabWidth() const
Get the currently set tab width.
Definition PdfPainter.h:462
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.
PdfObjectStream * GetStream() const
Return the current canvas stream that is set on the painter.
Definition PdfPainter.h:472
A reference is a pointer to a object in the PDF file of the form "4 0 R", where 4 is the object numbe...
Definition PdfReference.h:20
A variant data type which supports all data types supported by the PDF standard.
Definition PdfVariant.h:29
A XObject is a content stream with several drawing commands and data which can be used throughout a P...
Definition PdfXObject.h:28
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:17
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
PdfLineJoinStyle
Enum for line join styles when drawing.
Definition PdfDeclarations.h:406
PdfStrokeStyle
Enum for the different stroke styles that can be set when drawing to a PDF file (mostly for line draw...
Definition PdfDeclarations.h:378
PdfPathDrawMode
An enum describing modes to draw paths and figures.
Definition PdfPainter.h:39
@ StrokeFill
Stroke and fill using the the even-odd rule to determine the region to fill.
@ StrokeFillEvenOdd
Stroke and fill using the the even-odd rule to determine the region to fill.
@ FillEvenOdd
Fill using the the even-odd rule to determine the region to fill.
std::shared_ptr< const PdfColorSpaceFilter > PdfColorSpaceFilterPtr
Convenience alias for a constant PdfColorSpaceFilter shared ptr.
Definition PdfColorSpaceFilter.h:71
PdfPainterFlags
Definition PdfPainter.h:29
@ NoSaveRestore
Do not perform a Save/Restore of added content in this painting session.
PdfHorizontalAlignment
Enum for text alignment.
Definition PdfDeclarations.h:422
@ None
Do not add a default appearance.
PdfLineCapStyle
Enum for line cap styles when drawing.
Definition PdfDeclarations.h:398
PdfTextRenderingMode
Enum for text rendering mode (Tr)
Definition PdfDeclarations.h:364
@ Fill
Default mode, fill text.
PdfColorSpaceType
Enum for the colorspaces supported by PDF.
Definition PdfDeclarations.h:333
PdfVerticalAlignment
Enum for vertical text alignment.
Definition PdfDeclarations.h:414