libTERE
A portable library for reassembling complex formatted text from text fragments.
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
text_reassemble.h
Go to the documentation of this file.
1 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <math.h>
22 #include <stdint.h>
23 #include <ctype.h>
24 #include <fontconfig/fontconfig.h>
25 #include <ft2build.h>
26 #include <iconv.h>
27 #include FT_FREETYPE_H
28 #include FT_GLYPH_H
29 
31 #define TEREMIN(A,B) (A < B ? A : B)
32 #define TEREMAX(A,B) (A > B ? A : B)
33 
34 #ifndef M_PI
35 # define M_PI 3.14159265358979323846 /* pi */
36 #endif
37 #define ALLOCINFO_CHUNK 32
38 #define ALLOCOUT_CHUNK 8192
39 #define TRPRINT trinfo_append_out
40 
47 #define ALILEFT 0x01
48 #define ALICENTER 0x02
49 #define ALIRIGHT 0x04
50 #define ALIHORI 0x07
51 #define ALITOP 0x08
52 #define ALIBASE 0x10
53 #define ALIBOT 0x20
54 #define ALIVERT 0x38
60 #define LDIR_LR 0x00
61 #define LDIR_RL 0x01
62 #define LDIR_TB 0x02
68 #define TR_EMFBOT 0x01
75 enum tr_classes {
83  };
89 typedef struct {
90  FT_Face face;
91  uint8_t *file;
92  uint8_t *fname;
93  FcPattern *fpat;
94  double spcadv;
95  double fsize;
96 } FNT_SPECS;
97 
101 typedef struct {
102  FT_Library library;
104  int space;
105  int used;
106 } FT_INFO;
107 
111 typedef struct {
112  uint8_t *string;
113  double ori;
114  double fs;
115  double x;
116  double y;
117  double boff;
118  double vadvance;
120  uint32_t color;
121  int taln;
122  int ldir;
123  int italics;
124  int weight;
125  int condensed;
126  int co;
127  int rt_tidx;
128  int fi_idx;
129 } TCHUNK_SPECS;
130 
135 typedef struct {
137  int space;
138  int used;
139 } TP_INFO;
140 
145 typedef struct {
146  double xll;
147  double yll;
148  double xur;
149  double yur;
150  double xbearing;
151 } BRECT_SPECS;
152 
156 typedef struct {
158  int space;
159  int used;
160 } BR_INFO;
161 
165 typedef struct {
166  int *members;
169  int space;
170  int used;
171 } CHILD_SPECS;
172 
176 typedef struct {
177  int rt_cidx;
179  CHILD_SPECS kids;
181 } CX_SPECS;
182 
186 typedef struct {
188  int space;
189  int used;
190  int phase1;
191  int lines;
192  int paras;
193 } CX_INFO;
194 
198 typedef struct {
203  uint8_t *out;
204  double qe;
205  double esc;
206  double x;
207  double y;
208  int dirty;
209  int use_kern;
211  int kern_mode;
212  int outspace;
213  int outused;
214 } TR_INFO;
215 
216 /* padding added to rectangles before overlap test */
220 typedef struct {
221  double up;
222  double down;
223  double left;
224  double right;
225 } RT_PAD;
226 
228 /*
229  iconv() has a funny cast on some older systems, on most recent ones
230  it is just char **. This tries to work around the issue. If you build this
231  on another funky system this code may need to be modified, or define ICONV_CAST
232  on the compile line(but it may be tricky).
233 */
234 #ifdef SOL8
235 #define ICONV_CAST (const char **)
236 #endif //SOL8
237 #if !defined(ICONV_CAST)
238 #define ICONV_CAST (char **)
239 #endif //ICONV_CAST
240 
242 /* Prototypes */
243 int TR_findcasesub(char *string, char *sub);
244 int TR_getadvance(FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int load_flags, int kern_mode, int *ymin, int *ymax);
245 int TR_getkern2(FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int kern_mode);
246 int TR_kern_gap(FNT_SPECS *fsp, TCHUNK_SPECS *tsp, TCHUNK_SPECS *ptsp, int kern_mode);
247 void TR_rt_pad_set(RT_PAD *rt_pad, double up, double down, double left, double right);
248 double TR_baseline(TR_INFO *tri, int src, double *AscMax, double *DscMax);
249 int TR_check_set_vadvance(TR_INFO *tri, int src, int lines);
250 int TR_layout_analyze(TR_INFO *tri);
251 void TR_layout_2_svg(TR_INFO *tri);
252 int TR_weight_FC_to_SVG(int weight);
253 
254 FT_INFO *ftinfo_init(void);
256 int ftinfo_insert(FT_INFO *fti, FNT_SPECS *fsp);
259 
261 int csp_insert(CHILD_SPECS *csp, int src);
262 int csp_merge(CHILD_SPECS *dst, CHILD_SPECS *src);
263 void csp_release(CHILD_SPECS *csp);
264 
265 CX_INFO *cxinfo_init(void);
267 int cxinfo_insert(CX_INFO *cxi, int src, int src_rt_idx, enum tr_classes type);
268 int cxinfo_append(CX_INFO *cxi, int src, enum tr_classes type);
269 int cxinfo_merge(CX_INFO *cxi, int dst, int src, enum tr_classes type);
271 void cxinfo_dump(TR_INFO *tri);
272 
273 TP_INFO *tpinfo_init(void);
275 int tpinfo_insert(TP_INFO *tpi, TCHUNK_SPECS *tsp);
277 
278 BR_INFO *brinfo_init(void);
280 int brinfo_insert(BR_INFO *bri, BRECT_SPECS *element);
281 int brinfo_merge(BR_INFO *bri, int dst, int src);
282 enum tr_classes
283  brinfo_pp_alignment(BR_INFO *bri, int dst, int src, double slop, enum tr_classes type);
284 int brinfo_overlap(BR_INFO *bri, int dst, int src, RT_PAD *rp_dst, RT_PAD *rp_src);
286 
291 int trinfo_load_fontname(TR_INFO *tri, uint8_t *fontname, TCHUNK_SPECS *tsp);
292 int trinfo_load_qe(TR_INFO *tri, double qe);
293 int trinfo_load_ft_opts(TR_INFO *tri, int use_kern, int load_flags, int kern_mode);
294 int trinfo_load_textrec(TR_INFO *tri, TCHUNK_SPECS *tsp, double escapement, int flags);
295 int trinfo_append_out(TR_INFO *tri, char *src);
296 
297 #ifdef __cplusplus
298 }
299 #endif