forked from NanoMichael/MicroTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphic_cairo.h
133 lines (80 loc) · 3.11 KB
/
graphic_cairo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "config.h"
#if defined(BUILD_GTK) && !defined(MEM_CHECK)
#ifndef GRAPHIC_CAIRO_H_INCLUDED
#define GRAPHIC_CAIRO_H_INCLUDED
#include "graphic/graphic.h"
#include <cairomm/context.h>
#include <pangomm/fontdescription.h>
#include <pangomm/layout.h>
using namespace std;
namespace tex {
class Font_cairo : public Font {
private:
static map<string, Cairo::RefPtr<Cairo::FtFontFace>> _cairoFtFaces;
static map<string, string> _families;
int _style;
double _size;
string _family;
Cairo::RefPtr<Cairo::FtFontFace> _fface;
void loadFont(const string& file);
public:
explicit Font_cairo(string family = "", int style = PLAIN, float size = 1.f);
Font_cairo(const string& file, float size);
string getFamily() const;
int getStyle() const;
Cairo::RefPtr<Cairo::FtFontFace> getCairoFontFace() const;
float getSize() const override;
sptr<Font> deriveFont(int style) const override;
bool operator==(const Font& f) const override;
bool operator!=(const Font& f) const override;
~Font_cairo() override = default;;
};
/**************************************************************************************************/
class TextLayout_cairo : public TextLayout {
private:
static Cairo::RefPtr<Cairo::Context> _img_context;
Glib::RefPtr<Pango::Layout> _layout;
float _ascent;
public:
TextLayout_cairo(const wstring& src, const sptr<Font_cairo>& font);
void getBounds(Rect& r) override;
void draw(Graphics2D& g2, float x, float y) override;
};
/**************************************************************************************************/
class Graphics2D_cairo : public Graphics2D {
private:
static Font_cairo _default_font;
Cairo::RefPtr<Cairo::Context> _context;
color _color;
Stroke _stroke;
const Font_cairo* _font;
float _sx, _sy;
void roundRect(float x, float y, float w, float h, float rx, float ry);
public:
explicit Graphics2D_cairo(const Cairo::RefPtr<Cairo::Context>& context);
const Cairo::RefPtr<Cairo::Context>& getCairoContext() const;
void setColor(color c) override;
color getColor() const override;
void setStroke(const Stroke& s) override;
const Stroke& getStroke() const override;
void setStrokeWidth(float w) override;
const Font* getFont() const override;
void setFont(const Font* font) override;
void translate(float dx, float dy) override;
void scale(float sx, float sy) override;
void rotate(float angle) override;
void rotate(float angle, float px, float py) override;
void reset() override;
float sx() const override;
float sy() const override;
void drawChar(wchar_t c, float x, float y) override;
void drawText(const wstring& t, float x, float y) override;
void drawLine(float x, float y1, float x2, float y2) override;
void drawRect(float x, float y, float w, float h) override;
void fillRect(float x, float y, float w, float h) override;
void drawRoundRect(float x, float y, float w, float h, float rx, float ry) override;
void fillRoundRect(float x, float y, float w, float h, float rx, float ry) override;
};
} // namespace tex
#endif // GRAPHIC_CAIRO_H_INCLUDED
#endif // BUILD_GTK && !MEM_CHECK