Foxit PDF SDK
fs_pdfgraphicsobject.h
Go to the documentation of this file.
1 
15 #ifndef FS_PDFGRAPHICSOBJECT_H_
16 #define FS_PDFGRAPHICSOBJECT_H_
17 
18 #include "common/fs_common.h"
19 #include "common/file/fs_file.h"
20 #include "common/fs_image.h"
22 
28 namespace foxit {
29 namespace pdf {
30 namespace graphics {
31 class TextObject;
32 class FormXObject;
33 class ImageObject;
34 class PathObject;
35 class ShadingObject;
36 } // namespace graphics
37 class PDFPage;
38 class GraphicsObjects;
39 class LayerNodeArray;
40 class LayerTree;
41 } // namespace pdf
42 
46 namespace pdf {
50 namespace graphics {
52 class ColorState FS_FINAL : public Base {
53  public:
54  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
55  explicit ColorState(FS_HANDLE handle);
56 
58  ~ColorState();
59 
65  ColorState(const ColorState& other);
66 
74  ColorState& operator=(const ColorState& other);
75 
84  bool operator==(const ColorState& other) const;
85 
94  bool operator!=(const ColorState& other) const;
95 
103  bool IsEmpty() const;
104 
111 
119  void SetFillColor(const common::Color& color);
120 
127 
135  void SetStrokeColor(const common::Color& color);
136 };
137 
146 class MarkedContent FS_FINAL : public Object {
147  public:
150 
159  bool HasTag(const char* tag_name);
168  int GetItemCount() const;
180  String GetItemTagName(int index) const;
189  int GetItemMCID(int index) const;
212  int AddItem(const char* tag_name, objects::PDFDictionary* property_dict = NULL);
220  bool RemoveItem(const char* tag_name);
221 
222  private:
223  MarkedContent(const MarkedContent& markedcontent);
224  MarkedContent &operator = (const MarkedContent& markedcontent);
225 };
226 
241 class GraphicsObject : public Object {
242  public:
248  typedef enum _BlendMode {
371  } BlendMode;
372 
378  typedef enum _Type {
391  } Type;
392 
393 
394 #if !defined(_SWIG_IOS_) && !defined(_SWIG_MACOC_)
395 
401  void Release();
402 #endif
403 
410  Type GetType() const;
411 
418  RectF GetRect() const;
419 
425  bool HasTransparency();
426 
435  ARGB GetStrokeColor() const;
436 
445  ARGB GetFillColor() const;
446 
464  void SetStrokeColor(ARGB color);
465 
484  void SetFillColor(ARGB color);
485 
493  ColorState GetColorState() const;
494 
508  void SetColorState(const ColorState& color_state);
509 
521  void SetFillOpacity(float opacity);
522 
534  void SetStrokeOpacity(float opacity);
535 
542  float GetFillOpacity() const;
543 
550  float GetStrokeOpacity()const;
551 
558  Matrix GetMatrix() const;
559 
570  void SetMatrix(const Matrix& matrix);
571 
584  bool Transform(const Matrix& matrix, bool need_transform_clippath);
585 
597 
612  GraphicsObject* Clone(foxit::pdf::GraphicsObjects src_graphicsobjects, foxit::pdf::GraphicsObjects dest_graphicsobjects);
613 
622 
639  void SetGraphState(const common::GraphState& graph_state);
640 
647  BlendMode GetBlendMode() const;
648 
660  void SetBlendMode(BlendMode blend_mode);
661 
667  int GetClipPathCount() const;
668 
678  common::Path GetClipPath(int index) const;
679 
689  common::FillMode GetClipPathFillMode(int index) const;
690 
703  bool AddClipPath(const common::Path& path, common::FillMode fill_mode);
704 
716  bool RemoveClipPath(int index);
717 
723  int GetClipTextObjectCount() const;
724 
733  TextObject* GetClipTextObject(int index) const;
734 
745  bool AddClipTextObject(TextObject* textobject);
746 
758  bool RemoveClipTextObject(int index);
759 
765  RectF GetClipRect() const;
766 
779  void SetClipRect(const RectF& clip_rect);
780 
789  bool ClearClips();
790 
797 
806  LayerNodeArray GetLayers(const LayerTree& layer_tree);
807 
814  TextObject* GetTextObject() const;
815 
822  FormXObject* GetFormXObject() const;
823 
830  ImageObject* GetImageObject() const;
831 
838  PathObject* GetPathObject() const;
839 
847 
860  void Rotate(int angle);
861  protected:
862  ~GraphicsObject() {}
863 
864  private:
865  GraphicsObject(const GraphicsObject& graphicsobject);
866  GraphicsObject &operator = (const GraphicsObject& graphicsobject);
867 };
868 
871 
873 class TextState FS_FINAL : public Object {
874  public:
880  typedef enum _Mode {
897  } Mode;
898 
899 
917  const PointF& origin_position, float textmatrix[4]) {
918  this->version = version;
919  this->font = font;
920  this->font_size = font_size;
921  this->charspace = charspace;
922  this->wordspace = wordspace;
923  this->textmode = textmode;
924  this->origin_position = origin_position;
925  for (int i=0; i < 4; i++)
926  this->textmatrix[i] = textmatrix[i];
927  }
928 
931  :version(1)
932  , font_size(0.0f)
933  , charspace(0.0f)
934  , wordspace(0.0f)
937  this->textmatrix[0] = 1;
938  this->textmatrix[1] = 0;
939  this->textmatrix[2] = 0;
940  this->textmatrix[3] = 1;
941  }
942 
948  TextState(const TextState& state) {
949  version = state.version;
950  font = state.font;
951  font_size = state.font_size;
952  charspace = state.charspace;
953  wordspace = state.wordspace;
954  textmode = state.textmode;
956  for (int i=0; i < 4; i++)
957  textmatrix[i] = state.textmatrix[i];
958  }
959 
967  TextState &operator = (const TextState& state) {
968  version = state.version;
969  font = state.font;
970  font_size = state.font_size;
971  charspace = state.charspace;
972  wordspace = state.wordspace;
973  textmode = state.textmode;
975  for (int i=0; i < 4; i++)
976  textmatrix[i] = state.textmatrix[i];
977  return (*this);
978  }
979 
996  void Set(uint32 version, const common::Font& font, float font_size, float charspace, float wordspace,
997  Mode textmode, const PointF& origin_position, float textmatrix[4]) {
998  this->version = version;
999  this->font = font;
1000  this->font_size = font_size;
1001  this->charspace = charspace;
1002  this->wordspace = wordspace;
1003  this->textmode = textmode;
1004  this->origin_position = origin_position;
1005  for (int i=0; i < 4; i++)
1006  this->textmatrix[i] = textmatrix[i];
1007  }
1008 
1018 
1025 
1031  float font_size;
1040  float charspace;
1041 
1052  float wordspace;
1053 
1061 
1068 
1078  float textmatrix[4];
1079 };
1080 
1089 class ImageObject FS_FINAL : public GraphicsObject {
1090  public:
1104  static ImageObject* Create(const PDFDoc& document);
1105 
1120  void SetBitmap(const common::Bitmap& bitmap, const common::Bitmap& mask = common::Bitmap());
1121 
1139  void SetImage(const common::Image& image, int frame_index);
1140 
1160  common::Bitmap CloneBitmap(const GraphicsObjects& graphics_objects);
1161 
1180  common::Bitmap CloneBitmap(const PDFPage& page, const GraphicsObjects& graphics_objects);
1181 
1193  static ImageObject* CreateFromType3TextObject(const PDFPage& page, TextObject* text_obj);
1194 
1202 
1209  objects::PDFStream* GetStream() const;
1210 
1216  bool IsImageMask() const;
1217 
1231  objects::PDFObject* GetMask() const;
1232 
1233  private:
1234  ~ImageObject() {}
1235 
1236  private:
1237  ImageObject(const ImageObject& imageobject);
1238  ImageObject &operator = (const ImageObject& imageobject);
1239 };
1240 
1249 class TextObject FS_FINAL : public GraphicsObject {
1250  public:
1261  static TextObject* Create();
1262 
1268  WString GetText() const;
1269 
1283  void SetText(const wchar_t* text);
1284 
1298  void SetText(const WString& text);
1299 
1307  TextState GetTextState(const PDFPage& page) const;
1308 
1323  void SetTextState(const PDFPage& page, const TextState& text_state, bool is_italic, int weight);
1324 
1330  int GetCharCount() const;
1331 
1340  PointF GetCharPos(int index) const;
1341 
1350  float GetCharWidthByIndex(int index) const;
1351 
1360  float GetCharHeightByIndex(int index) const;
1361 
1362  private:
1363  ~TextObject() {}
1364 
1365  private:
1366  TextObject(const TextObject& textobject);
1367  TextObject &operator = (const TextObject& textobject);
1368 };
1369 
1380 class PathObject FS_FINAL : public GraphicsObject {
1381  public:
1392  static PathObject* Create();
1393 
1406  static PathObject* CreateFromTextObject(const PDFPage& page, TextObject* text_obj);
1407 
1414  common::FillMode GetFillMode() const;
1426  void SetFillMode(common::FillMode fill_mode);
1433  bool GetStrokeState() const;
1445  void SetStrokeState(bool is_stroke);
1452  common::Path GetPathData() const;
1453 
1464  void SetPathData(const common::Path& path_data);
1465 
1466  private:
1467  ~PathObject() {}
1468 
1469  private:
1470  PathObject(const PathObject& pathobject);
1471  PathObject &operator = (const PathObject& pathobject);
1472 };
1473 
1485 class FormXObject FS_FINAL : public GraphicsObject {
1486  public:
1500  static FormXObject* Create(const PDFDoc& document);
1501 
1508  objects::PDFStream* GetStream() const;
1509 
1516 
1534  bool ImportPageContent(const PDFPage& source_page, bool is_annots_included);
1535 
1536  private:
1537  ~FormXObject() {}
1538 
1539  private:
1540  FormXObject(const FormXObject& formxobject);
1541  FormXObject &operator = (const FormXObject& formxobject);
1542 };
1543 
1550 class ShadingObject FS_FINAL : public GraphicsObject {
1551  public:
1559 
1560  private:
1561  ~ShadingObject() {}
1562 
1563  private:
1564  ShadingObject(const ShadingObject& shadingobject);
1565  ShadingObject &operator = (const ShadingObject& shadingobject);
1566 };
1567 } // namespace graphics
1568 } // namespace pdf
1569 } // namespace foxit
1570 #endif // FS_PDFGRAPHICSOBJECT_H_
1571 
Definition: fs_pdfgraphicsobject.h:241
common::FillMode GetClipPathFillMode(int index) const
Get the fill mode of a path clip by index.
ShadingObject * GetShadingObject() const
Get the shading graphics object if current graphics object represents a shading object.
TextState(uint32 version, const common::Font &font, float font_size, float charspace, float wordspace, Mode textmode, const PointF &origin_position, float textmatrix[4])
Constructor, with parameters.
Definition: fs_pdfgraphicsobject.h:916
float wordspace
Word spacing (only apply to space character).
Definition: fs_pdfgraphicsobject.h:1052
int GetClipPathCount() const
Get the count of path clip.
bool HasTransparency()
Check whether current graphics object has transparency or not.
Definition: fs_pdfobject.h:422
TextState(const TextState &state)
Constructor, with another text state object.
Definition: fs_pdfgraphicsobject.h:948
Definition: fs_pdfpage.h:64
float GetCharHeightByIndex(int index) const
Get the height of a character specified by index in current text object.
ColorState GetColorState() const
Get color state.
void SetClipRect(const RectF &clip_rect)
Set clip rectangle.
Definition: fs_image.h:36
Definition: fs_pdfgraphicsobject.h:873
void SetFillColor(ARGB color)
Set the fill color.
bool GetStrokeState() const
Get stroke state.
Selecting source color and ignoring backdrop color.
Definition: fs_pdfgraphicsobject.h:254
Mode textmode
Text rendering mode. Please refer to values starting from TextState::e_ModeFill and this should be on...
Definition: fs_pdfgraphicsobject.h:1060
void SetBlendMode(BlendMode blend_mode)
Set the blend mode for transparent imaging model.
CFX_Object Object
Object type.
Definition: fs_basictypes.h:221
Type
Enumeration for PDF graphics object type.
Definition: fs_pdfgraphicsobject.h:378
uint32 version
Version of this class.
Definition: fs_pdfgraphicsobject.h:1017
Multiply or screens colors, depending on backdrop color value.
Definition: fs_pdfgraphicsobject.h:272
BlendMode
Enumeration for render blend mode.
Definition: fs_pdfgraphicsobject.h:248
void SetFillColor(const common::Color &color)
Set fill color.
Form XObject graphics object.
Definition: fs_pdfgraphicsobject.h:390
int GetClipTextObjectCount() const
Get the count of text clip.
ColorState & operator=(const ColorState &other)
Assign operator.
static FormXObject * Create(const PDFDoc &document)
Create a new form XObject graphics object.
void SetGraphState(const common::GraphState &graph_state)
Set graph state.
Definition: fx_coordinates.h:30
TextState & operator=(const TextState &state)
Assign operator.
Definition: fs_pdfgraphicsobject.h:967
ARGB GetStrokeColor() const
Get the stroke color.
Definition: fs_pdfgraphicsobject.h:52
Header file for file operation related definitions and functions.
Image graphics object.
Definition: fs_pdfgraphicsobject.h:386
static PathObject * CreateFromTextObject(const PDFPage &page, TextObject *text_obj)
Create a path graphics object from a text object.
LayerNodeArray GetLayers(const LayerTree &layer_tree)
Get all the layers which are associated with current graphics object.
Subtracts the darker of the two constituent colors from lighter colors.
Definition: fs_pdfgraphicsobject.h:335
common::FillMode GetFillMode() const
Get fill mode.
WIDE STRING CLASS.
Definition: fx_string.h:1461
Creates a color with the luminosity of the source color, and the hue and saturation of the backdrop c...
Definition: fs_pdfgraphicsobject.h:370
Definition: fs_pdflayer.h:38
CFX_ArrayTemplate< GraphicsObject * > GraphicsObjectArray
Definition: fs_pdfgraphicsobject.h:870
Darkens or lightens colors, depending on source color value.
Definition: fs_pdfgraphicsobject.h:329
int AddItem(const char *tag_name, objects::PDFDictionary *property_dict=0)
Add a new marked content item.
Definition: fs_pdfdoc.h:648
bool IsEmpty() const
Check whether current object is empty or not.
Definition: fs_common.h:2461
Definition: fs_pdflayer.h:121
Text graphics object.
Definition: fs_pdfgraphicsobject.h:382
static PathObject * Create()
Create a new path graphics object.
GraphicsObject * Clone()
Clone a new graphics object.
bool RemoveClipPath(int index)
Remove a path clip by index.
Header file for image and bitmap related definitions and classes.
Darkens backdrop color to reflect the source color.
Definition: fs_pdfgraphicsobject.h:306
Represents all graphics object types, only used as filter.
Definition: fs_pdfgraphicsobject.h:380
void SetText(const wchar_t *text)
Set text string.
int GetItemMCID(int index) const
Get marked-content identifier (MCID) of a marked content item specified by index.
Text mode: fill and stroke text, and add to path for clipping.
Definition: fs_pdfgraphicsobject.h:894
void Set(uint32 version, const common::Font &font, float font_size, float charspace, float wordspace, Mode textmode, const PointF &origin_position, float textmatrix[4])
Set value.
Definition: fs_pdfgraphicsobject.h:996
common::Path GetPathData() const
Get the path data.
Type GetType() const
Get the type of current graphics object.
Creates a color with the hue and saturation of the source color, and the luminosity of the backdrop c...
Definition: fs_pdfgraphicsobject.h:363
common::Bitmap CloneBitmap(const GraphicsObjects &graphics_objects)
Clone the bitmap from current image graphics object.
bool RemoveClipTextObject(int index)
Remove a text clip by index for clipping.
ARGB GetFillColor() const
Get the fill color.
void SetTextState(const PDFPage &page, const TextState &text_state, bool is_italic, int weight)
Set text state information.
TextObject * GetClipTextObject(int index) const
Get the text object of a text clip by index.
void SetColorState(const ColorState &color_state)
Set color state.
ColorSpaceType
Enumeration for color space.
Definition: fs_common.h:200
uint32 ARGB
ARGB color type, 32 bits, ((b) | ((g) << 8) | ((r) << 16)) | ((a) << 24)
Definition: fs_basictypes.h:210
void SetBitmap(const common::Bitmap &bitmap, const common::Bitmap &mask=common::Bitmap())
Set a bitmap to current image graphics object.
void SetStrokeState(bool is_stroke)
Set stroke state.
void SetMatrix(const Matrix &matrix)
Set matrix.
MarkedContent * GetMarkedContent() const
Get marked content object.
Definition: fs_pdfgraphicsobject.h:146
Brightens backdrop color to reflect source colors.
Definition: fs_pdfgraphicsobject.h:295
common::Font font
A font object.
Definition: fs_pdfgraphicsobject.h:1024
common::Color GetFillColor()
Get fill color.
void SetImage(const common::Image &image, int frame_index)
Set one frame of an image to current image graphics object.
objects::PDFStream * GetStream() const
Get image stream.
void SetPathData(const common::Path &path_data)
Set the path data.
Definition: fs_pdfgraphicsobject.h:1249
CFX_PointF PointF
Point information, in float.
Definition: fs_basictypes.h:463
void Rotate(int angle)
Rotate current graphics object from current state with specified angle degree in clockwise.
FillMode
Enumeration for filling mode type, mainly for path graphics object.
Definition: fs_common.h:108
Text mode: fill text.
Definition: fs_pdfgraphicsobject.h:882
common::Path GetClipPath(int index) const
Get a path clip by index.
float charspace
Character spacing.
Definition: fs_pdfgraphicsobject.h:1040
static ImageObject * Create(const PDFDoc &document)
Create a new image graphics object.
bool HasTag(const char *tag_name)
Check whether current marked content object has a specified marked content item or not.
void SetStrokeColor(ARGB color)
Set the stroke color.
Definition: fs_common.h:1009
FormXObject * GetFormXObject() const
Get the form XObject graphics object if current graphics object represents a form XObject object.
Definition: fs_common.h:2060
bool RemoveItem(const char *tag_name)
Remove a marked content item by tag name.
RectF GetClipRect() const
Get clip rectangle.
ImageObject * GetImageObject() const
Get the image graphics object if current graphics object represents an image object.
Creates a color with the hue of the source color, and the saturation and luminosity of the backdrop c...
Definition: fs_pdfgraphicsobject.h:342
Definition: fs_pdfgraphicsobject.h:1485
Definition: fx_basic.h:1297
common::GraphState GetGraphState() const
Get graph state.
bool ClearClips()
Clear all clips.
FX_UINT32 uint32
32-bit unsigned integer.
Definition: fs_basictypes.h:196
objects::PDFStream * GetStream() const
Get stream.
BlendMode GetBlendMode() const
Get the blend mode for transparent imaging model.
static ImageObject * CreateFromType3TextObject(const PDFPage &page, TextObject *text_obj)
Create an image graphics object from a type3 text object.
Definition: fs_pdfpage.h:412
void * FS_HANDLE
Handle type.
Definition: fs_basictypes.h:214
Header file for common definitions and classes.
float GetFillOpacity() const
Get the opacity value for painting operations other than stroking.
void SetStrokeColor(const common::Color &color)
Set stroke color.
~MarkedContent()
Destructor.
Definition: fs_pdfgraphicsobject.h:149
bool ImportPageContent(const PDFPage &source_page, bool is_annots_included)
Import page content from a specified PDF page to current form XObject.
void SetFillOpacity(float opacity)
Set the opacity value for painting operations other than stroking.
int GetItemCount() const
Get the count of marked content items.
bool AddClipTextObject(TextObject *textobject)
Add text object for clipping.
Path graphics object.
Definition: fs_pdfgraphicsobject.h:384
Header file for PDF object related definitions and classes.
Mode
Enumeration for text mode.
Definition: fs_pdfgraphicsobject.h:880
TextState GetTextState(const PDFPage &page) const
Get text state information.
Definition: fs_basictypes.h:443
void SetFillMode(common::FillMode fill_mode)
Set fill mode.
Definition: fs_pdfgraphicsobject.h:1550
TextObject * GetTextObject() const
Get the text graphics object if current graphics object represents a text object.
Multiply backdrop by source color values.
Definition: fs_pdfgraphicsobject.h:260
PointF origin_position
The origin point, in PDF coordinate system.
Definition: fs_pdfgraphicsobject.h:1067
String GetItemTagName(int index) const
Get the tag name of a marked content item specified by index.
bool AddClipPath(const common::Path &path, common::FillMode fill_mode)
Add a path for clipping.
Text mode: add text to path for clipping.
Definition: fs_pdfgraphicsobject.h:896
Multiply complements of backdrop by source color values, and then complement the result.
Definition: fs_pdfgraphicsobject.h:266
Text mode: fill text and add to path for clipping.
Definition: fs_pdfgraphicsobject.h:890
Definition: fs_common.h:1428
Definition: fs_pdfobject.h:809
Select lighter one of backdrop and source colors.
Definition: fs_pdfgraphicsobject.h:284
Foxit namespace.
Definition: fs_pdf3d.h:27
PointF GetCharPos(int index) const
Get the position of a character specified by index in current text object.
Definition: fs_pdfobject.h:55
Text mode: stroke text.
Definition: fs_pdfgraphicsobject.h:884
bool operator==(const ColorState &other) const
Equal operator.
BYTE STRING CLASS.
Definition: fx_string.h:317
void SetStrokeOpacity(float opacity)
Set opacity value for stroke painting operations for paths and glyph outlines.
Text mode: stroke text and add to path for clipping.
Definition: fs_pdfgraphicsobject.h:892
WString GetText() const
Get text string.
float textmatrix[4]
Text transformation matrix.
Definition: fs_pdfgraphicsobject.h:1078
Text mode: fill and stroke text.
Definition: fs_pdfgraphicsobject.h:886
GraphicsObjects GetGraphicsObjects() const
Get graphics objects that associated with current form XObject.
Matrix GetMatrix() const
Get matrix.
void Release()
Release a cloned or newly created PDF graphics object which has not been inserted into any PDF page o...
Definition: fs_pdfgraphicsobject.h:1380
#define NULL
The null-pointer value.
Definition: fx_system.h:792
Definition: fx_coordinates.h:1076
static TextObject * Create()
Create a new text graphics object.
Multiply or screens colors, depending on source color value.
Definition: fs_pdfgraphicsobject.h:316
objects::PDFObject * GetPDFObject() const
Get the PDF object which represents the shading graphics object in PDF file.
PathObject * GetPathObject() const
Get the path graphics object if current graphics object represents a path object.
float GetStrokeOpacity() const
Get opacity value for stroke painting operations for paths and glyph outlines.
objects::PDFDictionary * GetItemPropertyDict(int index) const
Get the property dictionary of a marked content item specified by index.
float font_size
The font size in "Tf". If valid, it should be above 0.
Definition: fs_pdfgraphicsobject.h:1031
int GetCharCount() const
Get character count in current text object.
Creates a color with the hue of the source color, and the saturation and luminosity of the backdrop c...
Definition: fs_pdfgraphicsobject.h:349
TextState()
Constructor.
Definition: fs_pdfgraphicsobject.h:930
bool IsImageMask() const
Check if current image object is treated as mask.
common::Color GetStrokeColor()
Get stroke color.
objects::PDFObject * GetMask() const
Get the PDF object that represents the mask of current image graphics object.
Select darker one of backdrop and source colors.
Definition: fs_pdfgraphicsobject.h:278
common::ColorSpaceType GetColorSpace() const
Get color space.
Shading graphics object.
Definition: fs_pdfgraphicsobject.h:388
Definition: fs_image.h:448
float GetCharWidthByIndex(int index) const
Get the width of a character specified by index in current text object.
Definition: fs_pdfgraphicsobject.h:1089
RectF GetRect() const
Get the rectangle of current graphics object.
Creates a color with the saturation of the source color, and the hue and luminosity of the backdrop c...
Definition: fs_pdfgraphicsobject.h:356
bool Transform(const Matrix &matrix, bool need_transform_clippath)
Transform current graphics object.
Definition: fx_coordinates.h:771
bool operator!=(const ColorState &other) const
Not equal operator.
Text mode: neither fill nor stroke text, to make it invisible.
Definition: fs_pdfgraphicsobject.h:888