7 #include "../contrib/pugixml-1.4/src/pugixml.hpp"
8 #include "stb_truetype.h"
10 typedef struct stbtt_fontinfo stbtt_fontinfo;
17 Real c; // skew x by y
18 Real e; // translate x
20 Real b; // skew y by x
22 Real f; // translate y
24 // SVG matrix transforms (x,y) <- (a x' + c y' + e, b x' + d y' + f)
25 // Equivelant to OpenGL 3d matrix transform ((a, c, e) (b, d, f) (0,0,1))
30 Document(const std::string & filename = "", const std::string & font_filename = "DejaVuSansMono.ttf") : m_objects(), m_count(0), m_font_data(NULL), m_font()
33 if (font_filename != "")
34 SetFont(font_filename);
43 void Load(const std::string & filename = "");
44 void Save(const std::string & filename);
45 void DebugDumpObjects();
47 unsigned ObjectCount() const {return m_count;}
48 inline const Objects & GetObjects() const {return m_objects;}
50 bool operator==(const Document & equ) const;
51 bool operator!=(const Document & equ) const {return !(this->operator==(equ));}
53 void Add(ObjectType type, const Rect & bounds, unsigned data_index = 0);
54 unsigned AddBezierData(const Bezier & bezier);
62 /** SVG Related functions **/
64 /** Load an SVG text file and add to the document **/
65 void LoadSVG(const std::string & filename, const Rect & bounds = Rect(0,0,1,1));
67 /** Parse an SVG node or SVG-group node, adding children to the document **/
68 void ParseSVGNode(pugi::xml_node & root, SVGMatrix & transform);
69 /** Parse an SVG path with string **/
70 void ParseSVGPathData(const std::string & d, const SVGMatrix & transform);
72 /** Modify an SVG transformation matrix **/
73 static void ParseSVGTransform(const std::string & s, SVGMatrix & transform);
75 /** Font related functions **/
76 void SetFont(const std::string & font_filename);
77 void AddText(const std::string & text, Real scale, Real x, Real y);
79 void AddFontGlyphAtPoint(stbtt_fontinfo *font, int character, Real scale, Real x, Real y);
81 #ifndef QUADTREE_DISABLED
82 inline const QuadTree& GetQuadTree() { if (m_quadtree.root_id == QUADTREE_EMPTY) { GenBaseQuadtree(); } return m_quadtree; }
83 QuadTreeIndex GenQuadChild(QuadTreeIndex parent, QuadTreeNodeChildren type);
84 QuadTreeIndex GenQuadParent(QuadTreeIndex child, QuadTreeNodeChildren mytype);
85 // Returns the number of objects the current object formed when clipped, the objects in question are added to the end of the document.
86 int ClipObjectToQuadChild(int object_id, QuadTreeNodeChildren type);
92 #ifndef QUADTREE_DISABLED
94 void GenBaseQuadtree();
97 unsigned char * m_font_data;
98 stbtt_fontinfo m_font;