/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef _PDFCONTENTSTREAM_INCLUDED_ #define _PDFCONTENTSTREAM_INCLUDED_ /*!DOM*// #include "PdfStream.h" #include "PdfIContentCommands.h" namespace TD_PDF { class PDFIStream; class PDFVersion; #define FORMAT_BUF_LEN 512 /** \details A structure that stores data about PDF traits, which depend from graphic stack (q -> Q, /Do etc) */ struct PDFStreamTraits { public: double m_curLW; //lineweight ODCOLORREF m_curRGB_strok; //color for stroking operators ODCOLORREF m_curRGB_n_strok; //color for non-stroking operators OdUInt16 m_curCI_strok; //color index for stroking operators OdUInt16 m_curCI_n_strok; //color index for non-stroking operators PDFLineCap m_curCapStyle; //cap style PDFLineJoin m_curJoinStyle; //join style PDFStreamTraits() {}; PDFStreamTraits(double lw, ODCOLORREF rgb_s, ODCOLORREF rgb_ns, OdUInt16 ci_s, OdUInt16 ci_ns, PDFLineCap capStyle, PDFLineJoin joinStyle) : m_curLW(lw) , m_curRGB_strok(rgb_s) , m_curRGB_n_strok(rgb_ns) , m_curCI_strok(ci_s) , m_curCI_n_strok(ci_ns) , m_curCapStyle(capStyle) , m_curJoinStyle(joinStyle) {}; }; class PDFEXPORT_TOOLKIT PDFContentStream : public PDFStream, public PDFIContentCommands { PDF_DECLARE_OBJECT(PDFContentStream, PDFStream, kContentStream) protected: char m_format_buf[FORMAT_BUF_LEN]; static OdUInt32 format(char* buf, const unsigned int buf_size, OdUInt32 n); static OdUInt32 format(char* buf, const unsigned int buf_size, double d, int cropzeros = CROP_ZEROES_FOR_ALL); static OdUInt32 format(char* buf, const unsigned int buf_size, double d0, double d1, int cropzeros = CROP_ZEROES_FOR_ALL); static OdUInt32 format(char* buf, const unsigned int buf_size, double d0, double d1, double d2, int cropzeros = CROP_ZEROES_FOR_ALL); static OdUInt32 format(char* buf, const unsigned int buf_size, double d0, double d1, double d2, double d3, int cropzeros = CROP_ZEROES_FOR_ALL); static OdUInt32 format(char* buf, const unsigned int buf_size, double d0, double d1, double d2, double d3, double d4, int cropzeros = CROP_ZEROES_FOR_ALL); static OdUInt32 format(char* buf, const unsigned int buf_size, double d0, double d1, double d2, double d3, double d4, double d5, int cropzeros = CROP_ZEROES_FOR_ALL); inline void format_put_string(char* /*buf*/, const unsigned int /*buf_size*/, OdUInt32 n) { OdUInt32 len = PDFContentStream::format(m_format_buf, FORMAT_BUF_LEN, n); getStreamData()->putBytes(m_format_buf, len); } inline void format_put_string(char* /*buf*/, const unsigned int /*buf_size*/, double d, int cropzeros = CROP_ZEROES_FOR_ALL) { OdUInt32 len = PDFContentStream::format(m_format_buf, FORMAT_BUF_LEN, d, cropzeros); getStreamData()->putBytes(m_format_buf, len); } inline void format_put_string(char* /*buf*/, const unsigned int /*buf_size*/, double d0, double d1, int cropzeros = CROP_ZEROES_FOR_ALL) { OdUInt32 len = PDFContentStream::format(m_format_buf, FORMAT_BUF_LEN, d0, d1, cropzeros); getStreamData()->putBytes(m_format_buf, len); } inline void format_put_string(char* /*buf*/, const unsigned int /*buf_size*/, double d0, double d1, double d2, int cropzeros = CROP_ZEROES_FOR_ALL) { OdUInt32 len = PDFContentStream::format(m_format_buf, FORMAT_BUF_LEN, d0, d1, d2, cropzeros); getStreamData()->putBytes(m_format_buf, len); } inline void format_put_string(char* /*buf*/, const unsigned int /*buf_size*/, double d0, double d1, double d2, double d3, int cropzeros = CROP_ZEROES_FOR_ALL) { OdUInt32 len = PDFContentStream::format(m_format_buf, FORMAT_BUF_LEN, d0, d1, d2, d3, cropzeros); getStreamData()->putBytes(m_format_buf, len); } inline void format_put_string(char* /*buf*/, const unsigned int /*buf_size*/, double d0, double d1, double d2, double d3, double d4, int cropzeros = CROP_ZEROES_FOR_ALL) { OdUInt32 len = PDFContentStream::format(m_format_buf, FORMAT_BUF_LEN, d0, d1, d2, d3, d4, cropzeros); getStreamData()->putBytes(m_format_buf, len); } inline void format_put_string(char* /*buf*/, const unsigned int /*buf_size*/, double d0, double d1, double d2, double d3, double d4, double d5, int cropzeros = CROP_ZEROES_FOR_ALL) { OdUInt32 len = PDFContentStream::format(m_format_buf, FORMAT_BUF_LEN, d0, d1, d2, d3, d4, d5, cropzeros); getStreamData()->putBytes(m_format_buf, len); } void putString(const char* val); void putString(const char* val, OdUInt32 size); void InitObject() override; void F() override; // Equivalent to f; included only for compatibility. Although PDF consumer applications // must be able to accept this operator, PDF producer applications should use f // instead. OdArray m_curTraits; //Current traits stack PDFStreamTraits m_newTraits; //Holder for new traits void checkTraits(); void saveGraphicState(); void restoreGraphicState(); public: void setTraits(double lw, ODCOLORREF rgb_s, ODCOLORREF rgb_ns, OdUInt16 ci_s, OdUInt16 ci_ns, PDFLineCap capStyle, PDFLineJoin joinStyle) override; void getTraits(double& lw, ODCOLORREF& rgb_s, ODCOLORREF& rgb_ns, OdUInt16& ci_s, OdUInt16& ci_ns, PDFLineCap& capStyle, PDFLineJoin& joinStyle) override; /////////////////////////////////////////////////////////////////////////////// // XObject operator // void Do(PDFNamePtr pName) override; // Paint the specified XObject. /////////////////////////////////////////////////////////////////////////////// // Graphics State Operators // void q() override; // Save the current graphics state on the graphics state stack void Q() override; // Restore the graphics state void gs(PDFNamePtr pGS) override;//set extended graphics state // Modify the current transformation matrix void cm(double a, double b, double c, double d, double e, double f) override; void w(double lw) override; // Lineweight Operator void J(PDFLineCap linecap) override; // Set the line cap style in the graphics state void j(PDFLineJoin linejoin) override; // Set the line join style in the graphics state void d(PDFArrayPtr dashArray, OdUInt32 phase) override; //line dash pattern /////////////////////////////////////////////////////////////////////////////// // Color Operators // void cs(PDFNamePtr pColorSpace) override; void CS(PDFNamePtr pColorSpace) override; void sc(OdUInt8 indx) override; // color for non-stroking operations (for Indexed color space only) void SC(OdUInt8 indx) override; // color for stroking operations (for Indexed color space only) void RG(double r, double g, double b) override; // color for stroking operations (deprecated) void rg(double r, double g, double b) override; // color for non-stroking operations (deprecated) void RG(ODCOLORREF rgb) override; // color for stroking operations void rg(ODCOLORREF rgb) override; // color for non-stroking operations void g(double g) override; // = /DeviceGray void G(double g) override; // = /DeviceGray void scn(PDFNamePtr pColorSpace) override; void SCN(PDFNamePtr pColorSpace) override; // Path Construction Operators void m(double x, double y, CoordinatesProcessing coordProc = kCastToInt) override; void l(double x, double y, CoordinatesProcessing coordProc = kCastToInt) override; void c(double x1, double y1, double x2, double y2, double x3, double y3, CoordinatesProcessing coordProc = kCastToInt) override; void v(double x2, double y2, double x3, double y3) override; void y(double x2, double y2, double x3, double y3) override; void re(double x, double y, double width, double height) override; void h() override; // Close the current subpath // Path-Painting Operators void S() override; // Stroke the path. void s() override; // Close and stroke the path. This operator has the same effect as the sequence h S. void f() override; // Fill the path, using the nonzero winding number rule to determine the region to fill // Any subpaths that are open are implicitly closed before being filled. void f_odd() override; // "f*" Fill the path, using the even-odd rule to determine the region to fill void B() override; // Fill and then stroke the path, using the nonzero winding number rule to determine // the region to fill. void B_odd() override; // "B*" Fill and then stroke the path, using the even-odd rule to determine the region to fill. void b() override; // Close, fill, and then stroke the path, using the nonzero winding number rule to determine // the region to fill. void b_odd() override; // "b*" Close, fill, and then stroke the path, using the even-odd rule to determine the region // to fill. void n() override; // End the path object without filling or stroking it. This operator is a path-painting // no-op, used primarily for the side effect of changing the current clipping path. // Clipping path operators void W() override; // Modify the current clipping path by intersecting it with the current path void W_odd() override; // .... , using the even-odd rule // Text state operators void Tc(double charSpace) override; // Set the character spacing, Tc, to charSpace void Tw(double wordSpace) override; // Set the word spacing, Tw, to wordSpace void Tz(double scale) override; // Set the horizontal scaling, Th, to (scale . 100) void TL(double leading) override; // Set the text leading, Tl, to leading void Tf(PDFNamePtr font, double size) override; // Set the text font, Tf, to font and the text font size void Tr(OdUInt32 render) override; // Set the text rendering mode void Ts(double rise) override; // Set the text rise // Text object operators void BT() override; // Begin a text object void ET() override; // End a text object // Text-positioning operators void Td(double tx, double ty) override; // Move to the start of the next line void TD(double tx, double ty) override; // Move to the start of the next line void Tm(double a, double b, double c, double d, double e, double f) override; // Set the text matrix, Tm, and the text line matrix, Tlm: void T_star() override; // T* // Move to the start of the next line. This operator has the same effect as the code 0 Tl Td where Tl is the current leading parameter in the text state. void Tj(PDFTextStringPtr pStr) override; // show text void TJ(PDFArrayPtr pStr) override; // show text array // Marked-content operators void BDC(PDFNamePtr pTag, PDFObjectPtr pProperties) override; // Begin a marked-content sequence with an associated property list. void BMC(PDFNamePtr pTag) override; // Begin a marked-content sequence void EMC() override; // End a marked-content sequence begun by a BMC or BDC operator. void sh(PDFNamePtr pName) override; }; class PDFEXPORT_TOOLKIT PDFDummyContentStream : public PDFIContentCommands { void F() override { } public: void setTraits(double, ODCOLORREF, ODCOLORREF, OdUInt16, OdUInt16, PDFLineCap, PDFLineJoin) override {} void getTraits(double&, ODCOLORREF&, ODCOLORREF&, OdUInt16&, OdUInt16&, PDFLineCap&, PDFLineJoin&) override {} void Do(PDFNamePtr ) override { } void q() override { } void Q() override { } void cm(double , double , double , double , double , double ) override { } void w(double ) override { } void J(PDFLineCap ) override { } void d(PDFArrayPtr , OdUInt32 ) override { } void j(PDFLineJoin ) override { } void cs(PDFNamePtr ) override { } void gs(PDFNamePtr) override { } void CS(PDFNamePtr ) override { } void sc(OdUInt8 ) override { } void SC(OdUInt8 ) override { } void RG(double , double , double ) override { } void rg(double , double , double ) override { } void RG(ODCOLORREF) override {} void rg(ODCOLORREF) override {} void g(double ) override { } void G(double ) override { } void m(double , double, CoordinatesProcessing = kCastToInt) override { } void l(double , double, CoordinatesProcessing = kCastToInt) override { } void c(double , double , double , double , double , double, CoordinatesProcessing = kCastToInt) override { } void v(double , double , double , double ) override { } void y(double , double , double , double ) override { } void re(double , double , double , double ) override { } void h() override { } void S() override { } void s() override { } void f() override { } void f_odd() override { } void B() override { } void B_odd() override { } void b() override { } void b_odd() override { } void n() override { } void W() override { } void W_odd() override { } void Tc(double ) override { } void Tw(double ) override { } void Tz(double ) override { } void TL(double ) override { } void Tf(PDFNamePtr , double ) override { } void Tr(OdUInt32 ) override { } void Ts(double ) override { } void BT() override { } void ET() override { } void Td(double , double ) override { } void TD(double , double ) override { } void Tm(double , double , double , double , double , double ) override { } void T_star() override { } void Tj(PDFTextStringPtr ) override { } void TJ(PDFArrayPtr) override {} void BDC(PDFNamePtr , PDFObjectPtr ) override { } void BMC(PDFNamePtr) override {} void EMC() override { } void sh(PDFNamePtr ) override { } void scn(PDFNamePtr ) override {} void SCN(PDFNamePtr ) override {} }; typedef PDFSmartPtr PDFContentStreamPtr; }; #endif //_PDFCONTENTSTREAM_INCLUDED_