forked from 4silvertooth/sciter-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDF.h
213 lines (192 loc) · 5.91 KB
/
PDF.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#ifndef PDF_H
#define PDF_H
#include "sciter-x.h"
#include "aux-cvt.h"
#include "hpdf.h"
namespace libharu {
class Image;
class Page : public sciter::om::asset<Page> {
HPDF_Page page;
sciter::value TALIGN_LEFT = HPDF_TALIGN_LEFT;
sciter::value TALIGN_RIGHT = HPDF_TALIGN_RIGHT;
sciter::value TALIGN_CENTER = HPDF_TALIGN_CENTER;
sciter::value TALIGN_JUSTIFY = HPDF_TALIGN_JUSTIFY;
/**
sciter::value TALIGN_TOP = HPDF_TALIGN_TOP;
sciter::value TALIGN_BOTTOM = HPDF_TALIGN_BOTTOM;
sciter::value TALIGN_MIDDLE = HPDF_TALIGN_MIDDLE;
*/
sciter::value SIZE_LETTER = HPDF_PAGE_SIZE_LETTER;
sciter::value SIZE_LEGAL = HPDF_PAGE_SIZE_LEGAL;
sciter::value SIZE_A3 = HPDF_PAGE_SIZE_A3;
sciter::value SIZE_A4 = HPDF_PAGE_SIZE_A4;
sciter::value SIZE_A5 = HPDF_PAGE_SIZE_A5;
sciter::value SIZE_B4 = HPDF_PAGE_SIZE_B4;
sciter::value SIZE_B5 = HPDF_PAGE_SIZE_B5;
sciter::value SIZE_EXECUTIVE = HPDF_PAGE_SIZE_EXECUTIVE;
sciter::value SIZE_US4x6 = HPDF_PAGE_SIZE_US4x6;
sciter::value SIZE_US4x8 = HPDF_PAGE_SIZE_US4x8;
sciter::value SIZE_US5x7 = HPDF_PAGE_SIZE_US5x7;
sciter::value SIZE_COMM10 = HPDF_PAGE_SIZE_COMM10;
sciter::value PORTRAIT = HPDF_PAGE_PORTRAIT;
sciter::value LANDSCAPE = HPDF_PAGE_LANDSCAPE;
public:
Page(HPDF_Doc& pdf) {
page = HPDF_AddPage (pdf);
}
virtual ~Page() {};
HPDF_REAL getWidth();
HPDF_REAL getHeight();
int setWidth(HPDF_REAL);
int setHeight(HPDF_REAL);
int setSize(int, int);
int setLineWidth(HPDF_REAL);
int rectangle(HPDF_REAL, HPDF_REAL, HPDF_REAL, HPDF_REAL);
int stroke();
int beginText();
int textOut(HPDF_REAL, HPDF_REAL, sciter::astring);
int moveTextPos(HPDF_REAL, HPDF_REAL);
int showText(sciter::astring);
int endText();
int setFontAndSize(sciter::value, HPDF_REAL);
int moveTo(HPDF_REAL, HPDF_REAL);
int lineTo(HPDF_REAL, HPDF_REAL);
int measureText(sciter::astring, HPDF_REAL, HPDF_BOOL);
int textRect(sciter::value, sciter::astring, int);
int setRGBStroke(HPDF_REAL, HPDF_REAL, HPDF_REAL);
int setCharSpace(HPDF_REAL);
int setWordSpace(HPDF_REAL);
int setTextLeading(HPDF_REAL);
int drawImage(sciter::value, sciter::value);
int circle(HPDF_REAL, HPDF_REAL, HPDF_REAL);
SOM_PASSPORT_BEGIN(Page)
SOM_PASSPORT_FLAGS(SOM_EXTENDABLE_OBJECT)
SOM_FUNCS(
SOM_FUNC(setWidth),
SOM_FUNC(setHeight),
SOM_FUNC(getWidth),
SOM_FUNC(getHeight),
SOM_FUNC(setSize),
SOM_FUNC(setLineWidth),
SOM_FUNC(rectangle),
SOM_FUNC(stroke),
SOM_FUNC(setFontAndSize),
SOM_FUNC(beginText),
SOM_FUNC(textOut),
SOM_FUNC(textRect),
SOM_FUNC(moveTextPos),
SOM_FUNC(showText),
SOM_FUNC(measureText),
SOM_FUNC(endText),
SOM_FUNC(moveTo),
SOM_FUNC(lineTo),
SOM_FUNC(setRGBStroke),
SOM_FUNC(setCharSpace),
SOM_FUNC(setWordSpace),
SOM_FUNC(setTextLeading),
SOM_FUNC(drawImage),
SOM_FUNC(circle)
)
SOM_PROPS(
SOM_RO_PROP(TALIGN_LEFT),
SOM_RO_PROP(TALIGN_RIGHT),
SOM_RO_PROP(TALIGN_CENTER),
SOM_RO_PROP(TALIGN_JUSTIFY),
/**SOM_RO_PROP(TALIGN_TOP),
SOM_RO_PROP(TALIGN_BOTTOM),
SOM_RO_PROP(TALIGN_MIDDLE),*/
SOM_RO_PROP(SIZE_LETTER),
SOM_RO_PROP(SIZE_LEGAL),
SOM_RO_PROP(SIZE_A3),
SOM_RO_PROP(SIZE_A4),
SOM_RO_PROP(SIZE_A5),
SOM_RO_PROP(SIZE_B4),
SOM_RO_PROP(SIZE_B5),
SOM_RO_PROP(SIZE_EXECUTIVE),
SOM_RO_PROP(SIZE_US4x6),
SOM_RO_PROP(SIZE_US4x8),
SOM_RO_PROP(SIZE_US5x7),
SOM_RO_PROP(SIZE_COMM10),
SOM_RO_PROP(PORTRAIT),
SOM_RO_PROP(LANDSCAPE)
)
SOM_PASSPORT_END
};
class Doc : public sciter::om::asset<Doc> {
HPDF_Doc pdf;
public:
Doc();
~Doc();
int newDoc();
sciter::value addPage();
int save(sciter::astring);
int free();
sciter::value loadTTFontFromFile(sciter::astring, HPDF_BOOL);
int setPassword(sciter::astring, sciter::astring);
sciter::value loadJpegImageFromFile(sciter::astring);
sciter::value loadPngImageFromFile(sciter::astring);
sciter::value getFont(sciter::astring, sciter::value);
SOM_PASSPORT_BEGIN(Doc)
SOM_PASSPORT_FLAGS(SOM_EXTENDABLE_OBJECT)
SOM_FUNCS(
SOM_FUNC(newDoc),
SOM_FUNC(addPage),
SOM_FUNC(save),
SOM_FUNC(free),
SOM_FUNC(loadTTFontFromFile),
SOM_FUNC(setPassword),
SOM_FUNC(loadJpegImageFromFile),
SOM_FUNC(loadPngImageFromFile),
SOM_FUNC(getFont)
)
SOM_PASSPORT_END
};
class Image : public sciter::om::asset<Image> {
HPDF_Image image;
public:
static const int JPEG = 1;
static const int PNG = 2;
Image(HPDF_Doc& pdf, const char* filename, int type) {
if(type == JPEG) {
image = HPDF_LoadJpegImageFromFile(pdf, filename);
} else if(type == PNG) {
image = HPDF_LoadPngImageFromFile(pdf, filename);
}
}
virtual ~Image() {};
sciter::value getSize();
int getWidth();
int getHeight();
int setMaskImage(sciter::value);
HPDF_Image get();
SOM_PASSPORT_BEGIN(Image)
SOM_PASSPORT_FLAGS(SOM_SEALED_OBJECT)
SOM_FUNCS(
SOM_FUNC(getSize),
SOM_FUNC(getWidth),
SOM_FUNC(getHeight),
SOM_FUNC(setMaskImage)
)
SOM_PASSPORT_END
};
class Font : public sciter::om::asset<Image> {
HPDF_Font font;
public:
Font(HPDF_Doc& pdf, const char* name, sciter::value encoding) {
if(encoding.is_null()){
font = HPDF_GetFont(pdf, name, NULL);
}
else {
font = HPDF_GetFont(pdf, name, aux::w2a(encoding.to_string()));
}
}
virtual ~Font() {};
HPDF_Font get() {
return font;
};
SOM_PASSPORT_BEGIN(Font)
SOM_PASSPORT_FLAGS(SOM_SEALED_OBJECT)
SOM_PASSPORT_END
};
}
#endif // PDF_H