Make adding text to the document easier
[ipdf/code.git] / src / document.h
1 #ifndef _DOCUMENT_H
2 #define _DOCUMENT_H
3
4 #include "ipdf.h"
5 #include "quadtree.h"
6
7 #include "../contrib/pugixml-1.4/src/pugixml.hpp"
8 #include "stb_truetype.h"
9
10 typedef struct stbtt_fontinfo stbtt_fontinfo;
11
12 namespace IPDF
13 {
14         class Document
15         {
16                 public:
17                         Document(const std::string & filename = "", const std::string & font_filename = "DejaVuSansMono.ttf") : m_objects(), m_count(0), m_font_data(NULL), m_font()
18                         {
19                                 Load(filename);
20                                 if (font_filename != "")
21                                         SetFont(font_filename);
22                         }
23                         virtual ~Document() 
24                         {
25                                 free(m_font_data);
26                         }
27                         
28                         
29
30                         void Load(const std::string & filename = "");
31                         void Save(const std::string & filename);
32                         void DebugDumpObjects();
33
34                         unsigned ObjectCount() const {return m_count;}
35                         inline const Objects & GetObjects() const {return m_objects;}
36
37                         bool operator==(const Document & equ) const;
38                         bool operator!=(const Document & equ) const {return !(this->operator==(equ));}
39
40                         void Add(ObjectType type, const Rect & bounds, unsigned data_index = 0);
41                         unsigned AddBezierData(const Bezier & bezier);
42                         
43
44                         
45                         /** SVG Related functions **/
46                         
47                         /** Load an SVG text file and add to the document **/
48                         void LoadSVG(const std::string & filename, const Rect & bounds = Rect(0,0,1,1));
49                         
50                         /** Parse an SVG node or SVG-group node, adding children to the document **/
51                         void ParseSVGNode(pugi::xml_node & root, const Rect & bounds, Real & width, Real & height);
52                         /** Parse an SVG path with string **/
53                         void ParseSVGPathData(const std::string & d, const Rect & bounds);
54
55                         /** Font related functions **/
56                         void SetFont(const std::string & font_filename);
57                         void AddText(const std::string & text, Real scale, Real x, Real y);
58                         
59                         void AddFontGlyphAtPoint(stbtt_fontinfo *font, int character, Real scale, Real x, Real y);
60
61 #ifndef QUADTREE_DISABLED
62                         inline const QuadTree& GetQuadTree() { if (m_quadtree.root_id == QUADTREE_EMPTY) { GenBaseQuadtree(); } return m_quadtree; }
63                         QuadTreeIndex GenQuadChild(QuadTreeIndex parent, QuadTreeNodeChildren type);
64                         QuadTreeIndex GenQuadParent(QuadTreeIndex child, QuadTreeNodeChildren mytype);
65 #endif
66
67                 private:
68                         friend class View;
69                         Objects m_objects;
70 #ifndef QUADTREE_DISABLED
71                         QuadTree m_quadtree;
72                         void GenBaseQuadtree();
73 #endif
74                         unsigned m_count;
75                         unsigned char * m_font_data;
76                         stbtt_fontinfo m_font;
77                 
78                         
79
80         };
81 }
82
83 #endif //_DOCUMENT_H

UCC git Repository :: git.ucc.asn.au