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 
606 
621  void SetGraphState(const common::GraphState& graph_state);
622 
629  BlendMode GetBlendMode() const;
630 
642  void SetBlendMode(BlendMode blend_mode);
643 
649  int GetClipPathCount() const;
650 
660  common::Path GetClipPath(int index) const;
661 
671  common::FillMode GetClipPathFillMode(int index) const;
672 
685  bool AddClipPath(const common::Path& path, common::FillMode fill_mode);
686 
698  bool RemoveClipPath(int index);
699 
705  int GetClipTextObjectCount() const;
706 
715  TextObject* GetClipTextObject(int index) const;
716 
727  bool AddClipTextObject(TextObject* textobject);
728 
740  bool RemoveClipTextObject(int index);
741 
747  RectF GetClipRect() const;
748 
761  void SetClipRect(const RectF& clip_rect);
762 
771  bool ClearClips();
772 
779 
788  LayerNodeArray GetLayers(const LayerTree& layer_tree);
789 
796  TextObject* GetTextObject() const;
797 
804  FormXObject* GetFormXObject() const;
805 
812  ImageObject* GetImageObject() const;
813 
820  PathObject* GetPathObject() const;
821 
829 
842  void Rotate(int angle);
843  protected:
844  ~GraphicsObject() {}
845 
846  private:
847  GraphicsObject(const GraphicsObject& graphicsobject);
848  GraphicsObject &operator = (const GraphicsObject& graphicsobject);
849 };
850 
853 
855 class TextState FS_FINAL : public Object {
856  public:
862  typedef enum _Mode {
879  } Mode;
880 
881 
899  const PointF& origin_position, float textmatrix[4]) {
900  this->version = version;
901  this->font = font;
902  this->font_size = font_size;
903  this->charspace = charspace;
904  this->wordspace = wordspace;
905  this->textmode = textmode;
906  this->origin_position = origin_position;
907  for (int i=0; i < 4; i++)
908  this->textmatrix[i] = textmatrix[i];
909  }
910 
913  :version(1)
914  , font_size(0.0f)
915  , charspace(0.0f)
916  , wordspace(0.0f)
919  this->textmatrix[0] = 1;
920  this->textmatrix[1] = 0;
921  this->textmatrix[2] = 0;
922  this->textmatrix[3] = 1;
923  }
924 
930  TextState(const TextState& state) {
931  version = state.version;
932  font = state.font;
933  font_size = state.font_size;
934  charspace = state.charspace;
935  wordspace = state.wordspace;
936  textmode = state.textmode;
938  for (int i=0; i < 4; i++)
939  textmatrix[i] = state.textmatrix[i];
940  }
941 
949  TextState &operator = (const TextState& state) {
950  version = state.version;
951  font = state.font;
952  font_size = state.font_size;
953  charspace = state.charspace;
954  wordspace = state.wordspace;
955  textmode = state.textmode;
957  for (int i=0; i < 4; i++)
958  textmatrix[i] = state.textmatrix[i];
959  return (*this);
960  }
961 
978  void Set(uint32 version, const common::Font& font, float font_size, float charspace, float wordspace,
979  Mode textmode, const PointF& origin_position, float textmatrix[4]) {
980  this->version = version;
981  this->font = font;
982  this->font_size = font_size;
983  this->charspace = charspace;
984  this->wordspace = wordspace;
985  this->textmode = textmode;
986  this->origin_position = origin_position;
987  for (int i=0; i < 4; i++)
988  this->textmatrix[i] = textmatrix[i];
989  }
990 
1000 
1006 
1011  float font_size;
1020  float charspace;
1021 
1032  float wordspace;
1033 
1041 
1048 
1054  float textmatrix[4];
1055 };
1056 
1065 class ImageObject FS_FINAL : public GraphicsObject {
1066  public:
1080  static ImageObject* Create(const PDFDoc& document);
1081 
1096  void SetBitmap(const common::Bitmap& bitmap, const common::Bitmap& mask = common::Bitmap());
1097 
1115  void SetImage(const common::Image& image, int frame_index);
1116 
1134  common::Bitmap CloneBitmap(const GraphicsObjects& graphics_objects);
1135 
1143 
1150  objects::PDFStream* GetStream() const;
1151 
1157  bool IsImageMask() const;
1158 
1172  objects::PDFObject* GetMask() const;
1173 
1174  private:
1175  ~ImageObject() {}
1176 
1177  private:
1178  ImageObject(const ImageObject& imageobject);
1179  ImageObject &operator = (const ImageObject& imageobject);
1180 
1181 };
1182 
1191 class TextObject FS_FINAL : public GraphicsObject {
1192  public:
1203  static TextObject* Create();
1204 
1210  WString GetText() const;
1211 
1225  void SetText(const wchar_t* text);
1226 
1234  TextState GetTextState(const PDFPage& page) const;
1235 
1250  void SetTextState(const PDFPage& page, const TextState& text_state, bool is_italic, int weight);
1251 
1257  int GetCharCount() const;
1258 
1267  PointF GetCharPos(int index) const;
1268 
1277  float GetCharWidthByIndex(int index) const;
1278 
1287  float GetCharHeightByIndex(int index) const;
1288 
1289  private:
1290  ~TextObject() {}
1291 
1292  private:
1293  TextObject(const TextObject& textobject);
1294  TextObject &operator = (const TextObject& textobject);
1295 };
1296 
1307 class PathObject FS_FINAL : public GraphicsObject {
1308  public:
1319  static PathObject* Create();
1320 
1332  static PathObject* CreateFromTextObject(const PDFPage& page, TextObject* text_obj);
1333 
1340  common::FillMode GetFillMode() const;
1352  void SetFillMode(common::FillMode fill_mode);
1359  bool GetStrokeState() const;
1371  void SetStrokeState(bool is_stroke);
1378  common::Path GetPathData() const;
1379 
1390  void SetPathData(const common::Path& path_data);
1391 
1392  private:
1393  ~PathObject() {}
1394 
1395  private:
1396  PathObject(const PathObject& pathobject);
1397  PathObject &operator = (const PathObject& pathobject);
1398 };
1399 
1411 class FormXObject FS_FINAL : public GraphicsObject {
1412  public:
1426  static FormXObject* Create(const PDFDoc& document);
1427 
1434  objects::PDFStream* GetStream() const;
1435 
1459  bool ImportPageContent(const PDFPage& source_page, bool is_annots_included);
1460 
1461  private:
1462  ~FormXObject() {}
1463 
1464  private:
1465  FormXObject(const FormXObject& formxobject);
1466  FormXObject &operator = (const FormXObject& formxobject);
1467 
1468 };
1469 
1476 class ShadingObject FS_FINAL : public GraphicsObject {
1477  public:
1485 
1486  private:
1487  ~ShadingObject() {}
1488 
1489  private:
1490  ShadingObject(const ShadingObject& shadingobject);
1491  ShadingObject &operator = (const ShadingObject& shadingobject);
1492 
1493 };
1494 } // namespace graphics
1495 } // namespace pdf
1496 } // namespace foxit
1497 #endif // FS_PDFGRAPHICSOBJECT_H_
1498 
Definition: fs_pdfgraphicsobject.h:146
float GetFillOpacity() const
Get the opacity value for painting operations other than stroking.
Definition: fs_pdfgraphicsobject.h:1411
float textmatrix[4]
Text transformation matrix.
Definition: fs_pdfgraphicsobject.h:1054
Definition: fs_pdflayer.h:38
void Release()
Release a cloned or newly created PDF graphics object which has not been inserted into any PDF page o...
int GetItemCount() const
Get the count of marked content items.
bool RemoveClipTextObject(int index)
Remove a text clip by index for clipping.
void * FS_HANDLE
Handle type.
Definition: fs_basictypes.h:216
RectF GetClipRect() const
Get clip rectangle.
TextObject * GetTextObject() const
Get the text graphics object if current graphics object represents a text 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:898
bool HasTag(const char *tag_name)
Check whether current marked content object has a specified marked content item or not.
Definition: fs_common.h:2355
Darkens backdrop color to reflect the source color.
Definition: fs_pdfgraphicsobject.h:306
Select darker one of backdrop and source colors.
Definition: fs_pdfgraphicsobject.h:278
objects::PDFDictionary * GetItemPropertyDict(int index) const
Get the property dictionary of a marked content item specified by index.
WString GetText() const
Get text string.
int GetClipPathCount() const
Get the count of path clip.
bool RemoveItem(const char *tag_name)
Remove a marked content item by tag name.
Creates a color with the hue of the source color, and the saturation and luminosity of the backdrop c...
Definition: fs_pdfgraphicsobject.h:349
void SetColorState(const ColorState &color_state)
Set color state.
void SetFillMode(common::FillMode fill_mode)
Set fill mode.
static FormXObject * Create(const PDFDoc &document)
Create a new form XObject graphics object.
Darkens or lightens colors, depending on source color value.
Definition: fs_pdfgraphicsobject.h:329
Shading graphics object.
Definition: fs_pdfgraphicsobject.h:388
CFX_Object Object
Object type.
Definition: fs_basictypes.h:219
Definition: fs_common.h:996
Mode textmode
Text rendering mode. Please refer to values starting from TextState::e_ModeFill and this should be on...
Definition: fs_pdfgraphicsobject.h:1040
ImageObject * GetImageObject() const
Get the image graphics object if current graphics object represents an image object.
bool HasTransparency()
Check whether current graphics object has transparency or not.
static PathObject * Create()
Create a new path graphics object.
Type
Enumeration for PDF graphics object type.
Definition: fs_pdfgraphicsobject.h:378
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:978
TextState(const TextState &state)
Constructor, with another text state object.
Definition: fs_pdfgraphicsobject.h:930
float charspace
Character spacing.
Definition: fs_pdfgraphicsobject.h:1020
PointF origin_position
The origin point, in PDF coordinate system.
Definition: fs_pdfgraphicsobject.h:1047
Header file for common definitions and classes.
float GetCharHeightByIndex(int index) const
Get the height of a character specified by index in current text object.
Definition: fs_pdfgraphicsobject.h:1307
Definition: fx_basic.h:1288
static TextObject * Create()
Create a new text graphics object.
common::Path GetClipPath(int index) const
Get a path clip by index.
bool GetStrokeState() const
Get stroke state.
Text mode: fill and stroke text.
Definition: fs_pdfgraphicsobject.h:868
TextState & operator=(const TextState &state)
Assign operator.
Definition: fs_pdfgraphicsobject.h:949
bool IsEmpty() const
Check whether current object is empty or not.
Header file for file operation related definitions and functions.
void SetFillColor(const common::Color &color)
Set fill color.
common::Color GetStrokeColor()
Get stroke color.
~MarkedContent()
Destructor.
Definition: fs_pdfgraphicsobject.h:149
uint32 ARGB
ARGB color type, 32 bits, ((b) | ((g) << 8) | ((r) << 16)) | ((a) << 24)
Definition: fs_basictypes.h:212
Definition: fs_pdfgraphicsobject.h:1476
Brightens backdrop color to reflect source colors.
Definition: fs_pdfgraphicsobject.h:295
Text mode: add text to path for clipping.
Definition: fs_pdfgraphicsobject.h:878
Definition: fs_pdfobject.h:55
PointF GetCharPos(int index) const
Get the position of a character specified by index in current text object.
ColorState GetColorState() const
Get color state.
float GetCharWidthByIndex(int index) const
Get the width of a character specified by index in current text object.
common::Bitmap CloneBitmap(const GraphicsObjects &graphics_objects)
Clone the bitmap from current image graphics object.
Selecting source color and ignoring backdrop color.
Definition: fs_pdfgraphicsobject.h:254
void SetImage(const common::Image &image, int frame_index)
Set one frame of an image to current image graphics object.
bool Transform(const Matrix &matrix, bool need_transform_clippath)
Transform current graphics object.
Definition: fs_common.h:1982
BlendMode GetBlendMode() const
Get the blend mode for transparent imaging model.
void SetClipRect(const RectF &clip_rect)
Set clip rectangle.
Multiply or screens colors, depending on backdrop color value.
Definition: fs_pdfgraphicsobject.h:272
Definition: fs_pdflayer.h:121
RectF GetRect() const
Get the rectangle of current graphics object.
Form XObject graphics object.
Definition: fs_pdfgraphicsobject.h:390
ColorState & operator=(const ColorState &other)
Assign operator.
FormXObject * GetFormXObject() const
Get the form XObject graphics object if current graphics object represents a form XObject object.
Text mode: stroke text.
Definition: fs_pdfgraphicsobject.h:866
ColorSpaceType
Enumeration for color space.
Definition: fs_common.h:448
objects::PDFStream * GetStream() const
Get image stream.
void SetStrokeColor(ARGB color)
Set the stroke color.
Matrix GetMatrix() const
Get matrix.
Image graphics object.
Definition: fs_pdfgraphicsobject.h:386
Subtracts the darker of the two constituent colors from lighter colors.
Definition: fs_pdfgraphicsobject.h:335
BYTE STRING CLASS.
Definition: fx_string.h:317
static ImageObject * Create(const PDFDoc &document)
Create a new image graphics object.
Multiply backdrop by source color values.
Definition: fs_pdfgraphicsobject.h:260
Definition: fs_pdfgraphicsobject.h:52
Creates a color with the luminosity of the source color, and the hue and saturation of the backdrop c...
Definition: fs_pdfgraphicsobject.h:370
Text mode: fill text.
Definition: fs_pdfgraphicsobject.h:864
Definition: fx_coordinates.h:30
Text mode: neither fill nor stroke text, to make it invisible.
Definition: fs_pdfgraphicsobject.h:870
void SetBitmap(const common::Bitmap &bitmap, const common::Bitmap &mask=common::Bitmap())
Set a bitmap to current image graphics object.
Multiply complements of backdrop by source color values, and then complement the result.
Definition: fs_pdfgraphicsobject.h:266
TextState GetTextState(const PDFPage &page) const
Get text state information.
Mode
Enumeration for text mode.
Definition: fs_pdfgraphicsobject.h:862
Definition: fs_pdfgraphicsobject.h:1191
Definition: fs_pdfgraphicsobject.h:241
Text graphics object.
Definition: fs_pdfgraphicsobject.h:382
Creates a color with the hue and saturation of the source color, and the luminosity of the backdrop c...
Definition: fs_pdfgraphicsobject.h:363
void SetFillColor(ARGB color)
Set the fill color.
FillMode
Enumeration for filling mode type, mainly for path graphics object.
Definition: fs_common.h:376
Header file for PDF object related definitions and classes.
bool RemoveClipPath(int index)
Remove a path clip by index.
common::Color GetFillColor()
Get fill color.
bool AddClipPath(const common::Path &path, common::FillMode fill_mode)
Add a path for clipping.
Represents all graphics object types, only used as filter.
Definition: fs_pdfgraphicsobject.h:380
Foxit namespace.
Definition: fs_compare.h:27
TextState()
Constructor.
Definition: fs_pdfgraphicsobject.h:912
int GetClipTextObjectCount() const
Get the count of text clip.
CFX_ArrayTemplate< GraphicsObject * > GraphicsObjectArray
Definition: fs_pdfgraphicsobject.h:852
void SetStrokeState(bool is_stroke)
Set stroke state.
Type GetType() const
Get the type of current graphics object.
bool ImportPageContent(const PDFPage &source_page, bool is_annots_included)
Import page content from a specified PDF page to current form XObject.
common::Font font
A font object.
Definition: fs_pdfgraphicsobject.h:1005
common::Path GetPathData() const
Get the path data.
Multiply or screens colors, depending on source color value.
Definition: fs_pdfgraphicsobject.h:316
Header file for image and bitmap related definitions and classes.
void SetStrokeColor(const common::Color &color)
Set stroke color.
Definition: fs_pdfobject.h:763
PathObject * GetPathObject() const
Get the path graphics object if current graphics object represents a path object.
ARGB GetStrokeColor() const
Get the stroke color.
int AddItem(const char *tag_name, objects::PDFDictionary *property_dict=0)
Add a new marked content item.
LayerNodeArray GetLayers(const LayerTree &layer_tree)
Get all the layers which are associated with current graphics object.
void Rotate(int angle)
Rotate current graphics object from current state with specified angle degree in clockwise.
bool AddClipTextObject(TextObject *textobject)
Add text object for clipping.
void SetMatrix(const Matrix &matrix)
Set matrix.
MarkedContent * GetMarkedContent() const
Get marked content object.
Definition: fs_pdfgraphicsobject.h:1065
#define NULL
The null-pointer value.
Definition: fx_system.h:767
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: fx_coordinates.h:771
int GetItemMCID(int index) const
Get marked-content identifier (MCID) of a marked content item specified by index.
String GetItemTagName(int index) const
Get the tag name of a marked content item specified by index.
Creates a color with the saturation of the source color, and the hue and luminosity of the backdrop c...
Definition: fs_pdfgraphicsobject.h:356
Definition: fs_pdfdoc.h:389
Definition: fs_pdfpage.h:342
Text mode: fill text and add to path for clipping.
Definition: fs_pdfgraphicsobject.h:872
int GetCharCount() const
Get character count in current text object.
float GetStrokeOpacity() const
Get opacity value for stroke painting operations for paths and glyph outlines.
Text mode: fill and stroke text, and add to path for clipping.
Definition: fs_pdfgraphicsobject.h:876
float font_size
Font size. If valid, it should be above 0.
Definition: fs_pdfgraphicsobject.h:1011
static PathObject * CreateFromTextObject(const PDFPage &page, TextObject *text_obj)
Create a path graphics object from a text object.
Definition: fs_image.h:430
bool operator==(const ColorState &other) const
Equal operator.
common::FillMode GetClipPathFillMode(int index) const
Get the fill mode of a path clip by index.
common::GraphState GetGraphState() const
Get graph state.
float wordspace
Word spacing (only apply to space character).
Definition: fs_pdfgraphicsobject.h:1032
GraphicsObjects GetGraphicsObjects() const
Get graphics objects that associated with current form XObject.
CFX_PointF PointF
Point information, in float.
Definition: fs_basictypes.h:419
uint32 version
Version of this class.
Definition: fs_pdfgraphicsobject.h:999
Text mode: stroke text and add to path for clipping.
Definition: fs_pdfgraphicsobject.h:874
Definition: fs_common.h:1418
Definition: fx_coordinates.h:1076
void SetFillOpacity(float opacity)
Set the opacity value for painting operations other than stroking.
objects::PDFObject * GetPDFObject() const
Get the PDF object which represents the shading graphics object in PDF file.
ShadingObject * GetShadingObject() const
Get the shading graphics object if current graphics object represents a shading object.
common::FillMode GetFillMode() const
Get fill mode.
void SetGraphState(const common::GraphState &graph_state)
Set graph state.
bool ClearClips()
Clear all clips.
void SetText(const wchar_t *text)
Set text string.
void SetStrokeOpacity(float opacity)
Set opacity value for stroke painting operations for paths and glyph outlines.
Definition: fs_pdfobject.h:385
void SetTextState(const PDFPage &page, const TextState &text_state, bool is_italic, int weight)
Set text state information.
WIDE STRING CLASS.
Definition: fx_string.h:1452
common::ColorSpaceType GetColorSpace() const
Get color space.
Definition: fs_image.h:36
void SetPathData(const common::Path &path_data)
Set the path data.
Definition: fs_pdfgraphicsobject.h:855
Path graphics object.
Definition: fs_pdfgraphicsobject.h:384
objects::PDFStream * GetStream() const
Get stream.
FX_UINT32 uint32
32-bit unsigned integer.
Definition: fs_basictypes.h:198
Select lighter one of backdrop and source colors.
Definition: fs_pdfgraphicsobject.h:284
bool operator!=(const ColorState &other) const
Not equal operator.
void SetBlendMode(BlendMode blend_mode)
Set the blend mode for transparent imaging model.
Definition: fs_basictypes.h:399
ARGB GetFillColor() const
Get the fill color.
BlendMode
Enumeration for render blend mode.
Definition: fs_pdfgraphicsobject.h:248
GraphicsObject * Clone()
Clone a new graphics object.
objects::PDFObject * GetMask() const
Get the PDF object that represents the mask of current image graphics object.
Definition: fs_pdfpage.h:63
bool IsImageMask() const
Check if current image object is treated as mask.
TextObject * GetClipTextObject(int index) const
Get the text object of a text clip by index.