Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
text_reassemble.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors: see below
6 *
7 *
8 * Copyright (C) 2017 Authors
9 * Released under GNU GPL v2.0+, read the file 'COPYING' for more information.
10 */
24#ifndef _TEXT_REASSEMBLE_
25#define _TEXT_REASSEMBLE_
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31
32#include <stdlib.h> //NOLINT
33#include <stdio.h> //NOLINT
34#include <math.h> //NOLINT
35#include <stdint.h> //NOLINT
36#include <ctype.h> //NOLINT
37#include <fontconfig/fontconfig.h>
38#include <ft2build.h>
39#include <iconv.h>
40#include FT_FREETYPE_H
41#include FT_GLYPH_H
42
44#define TEREMIN(A,B) (A < B ? A : B)
45#define TEREMAX(A,B) (A > B ? A : B)
46
47#ifndef M_PI
48# define M_PI 3.14159265358979323846 /* pi */
49#endif
50#define ALLOCINFO_CHUNK 32
51#define ALLOCOUT_CHUNK 8192
52#define TRPRINT trinfo_append_out
60#define BKCLR_NONE 0x00
61#define BKCLR_FRAG 0x01
62#define BKCLR_LINE 0x02
63#define BKCLR_ALL 0x03
74#define TXTDECOR_NONE 0x000
75#define TXTDECOR_UNDER 0x001
76#define TXTDECOR_OVER 0x002
77#define TXTDECOR_BLINK 0x004
78#define TXTDECOR_STRIKE 0x008
79#define TXTDECOR_TMASK 0x00F
81#define TXTDECOR_SOLID 0x000
82#define TXTDECOR_DOUBLE 0x010
83#define TXTDECOR_DOTTED 0x020
84#define TXTDECOR_DASHED 0x040
85#define TXTDECOR_WAVY 0x080
86#define TXTDECOR_LMASK 0x0F0
88#define TXTDECOR_CLRSET 0x100
101#define ALILEFT 0x01
102#define ALICENTER 0x02
103#define ALIRIGHT 0x04
104#define ALIHORI 0x07
105#define ALITOP 0x08
106#define ALIBASE 0x10
107#define ALIBOT 0x20
108#define ALIVERT 0x38
114#define LDIR_LR 0x00
115#define LDIR_RL 0x01
116#define LDIR_TB 0x02
122#define TR_EMFBOT 0x01
143typedef struct {
144 uint32_t fi_idx;
145 uint32_t weight;
146} ALT_SPECS;
147
151typedef struct {
152 FcFontSet *fontset;
154 uint32_t space;
155 uint32_t used;
156 FT_Face face;
157 uint8_t *file;
158 uint8_t *fontspec;
159 FcPattern *fpat;
160 double spcadv;
161 double fsize;
162} FNT_SPECS;
163
167typedef struct {
168 FT_Library library;
170 uint32_t space;
171 uint32_t used;
172} FT_INFO;
173
174typedef struct {
175 uint8_t Red;
176 uint8_t Green;
177 uint8_t Blue;
178 uint8_t Reserved;
179} TRCOLORREF;
180
184typedef struct {
185 uint8_t *string;
186 double ori;
187 double fs;
188 double x;
189 double y;
190 double xkern;
191 double ykern;
192 double boff;
193 double vadvance;
196 int taln;
197 int ldir;
199 int weight;
202 int spaces;
204 int co;
206 int fi_idx;
208
213typedef struct {
215 uint32_t space;
216 uint32_t used;
217} TP_INFO;
218
223typedef struct {
224 double xll;
225 double yll;
226 double xur;
227 double yur;
228 double xbearing;
230
234typedef struct {
236 uint32_t space;
237 uint32_t used;
238} BR_INFO;
239
243typedef struct {
244 int *members;
247 uint32_t space;
248 uint32_t used;
250
254typedef struct {
259} CX_SPECS;
260
264typedef struct {
266 uint32_t space;
267 uint32_t used;
268 uint32_t phase1;
269 uint32_t lines;
270 uint32_t paras;
271} CX_INFO;
272
276typedef struct {
281 uint8_t *out;
282 double qe;
283 double esc;
284 double x;
285 double y;
286 int dirty;
290 uint32_t outspace;
291 uint32_t outused;
292 int usebk;
294} TR_INFO;
295
296/* padding added to rectangles before overlap test */
300typedef struct {
301 double up;
302 double down;
303 double left;
304 double right;
305} RT_PAD;
306
308/*
309 iconv() has a funny cast on some older systems, on most recent ones
310 it is just char **. This tries to work around the issue. If you build this
311 on another funky system this code may need to be modified, or define ICONV_CAST
312 on the compile line(but it may be tricky).
313*/
314#ifdef SOL8
315#define ICONV_CAST (const char **)
316#endif //SOL8
317#if !defined(ICONV_CAST)
318#define ICONV_CAST (char **)
319#endif //ICONV_CAST
322/* Prototypes */
323int TR_findcasesub(const char *string, const char *sub);
324char *TR_construct_fontspec(const TCHUNK_SPECS *tsp, const char *fontname);
325char *TR_reconstruct_fontspec(const char *fontspec, const char *fontname);
326int TR_find_alternate_font(FT_INFO *fti, FNT_SPECS **efsp, uint32_t wc);
327int TR_getadvance(FT_INFO *fti, FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int load_flags, int kern_mode, int *ymin, int *ymax);
328int TR_getkern2(FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int kern_mode);
329int TR_kern_gap(FNT_SPECS *fsp, TCHUNK_SPECS *tsp, TCHUNK_SPECS *ptsp, int kern_mode);
330void TR_rt_pad_set(RT_PAD *rt_pad, double up, double down, double left, double right);
331double TR_baseline(TR_INFO *tri, int src, double *AscMax, double *DscMax);
332int TR_check_set_vadvance(TR_INFO *tri, int src, int lines);
336
342int ftinfo_find_loaded_by_spec(const FT_INFO *fti, const uint8_t *fname);
343int ftinfo_find_loaded_by_src(const FT_INFO *fti, const uint8_t *filename);
344int ftinfo_load_fontname(FT_INFO *fti, const char *fontspec);
345void ftinfo_dump(const FT_INFO *fti);
346
348int fsp_alts_insert(FNT_SPECS *fsp, uint32_t fi_idx);
349int fsp_alts_weight(FNT_SPECS *fsp, uint32_t a_idx);
350
352int csp_insert(CHILD_SPECS *csp, int src);
356
359int cxinfo_insert(CX_INFO *cxi, int src, int src_rt_idx, enum tr_classes type);
360int cxinfo_append(CX_INFO *cxi, int src, enum tr_classes type);
361int cxinfo_merge(CX_INFO *cxi, int dst, int src, enum tr_classes type);
364void cxinfo_dump(const TR_INFO *tri);
365
368int tpinfo_insert(TP_INFO *tpi, const TCHUNK_SPECS *tsp);
370
373int brinfo_insert(BR_INFO *bri, const BRECT_SPECS *element);
374int brinfo_merge(BR_INFO *bri, int dst, int src);
375enum tr_classes
376 brinfo_pp_alignment(const BR_INFO *bri, int dst, int src, double slop, enum tr_classes type);
377int brinfo_overlap(const BR_INFO *bri, int dst, int src, RT_PAD *rp_dst, RT_PAD *rp_src);
379
384int trinfo_load_qe(TR_INFO *tri, double qe);
385int trinfo_load_bk(TR_INFO *tri, int usebk, TRCOLORREF bkcolor);
386int trinfo_load_ft_opts(TR_INFO *tri, int use_kern, int load_flags, int kern_mode);
387int trinfo_load_textrec(TR_INFO *tri, const TCHUNK_SPECS *tsp, double escapement, int flags);
388int trinfo_check_bk(TR_INFO *tri, int usebk, TRCOLORREF bkcolor);
389int trinfo_append_out(TR_INFO *tri, const char *src);
390
392
393
394#ifdef __cplusplus
395}
396#endif
397#endif /* _TEXT_REASSEMBLE_ */
int test()
Definition 2junctions.cpp:5
unsigned long weight
Definition quantize.cpp:37
alt font entries.
uint32_t fi_idx
index into FT_INFO fonts, for fonts added for missing glyphs
uint32_t weight
integer weight for alt fonts, kept sorted into descending order
Information for a single bounding rectangle.
double xur
x upper right corner
double xll
x rectangle lower left corner
double xbearing
x bearing of the leftmost character
Information for all bounding rectangles.
uint32_t space
storage slots allocated
uint32_t used
storage slots in use
BRECT_SPECS * rects
bounding rectangles
List of all members of a single complex.
uint32_t space
storage slots allocated
int * members
array of immediate children (for TR_PARA_* these are indices for TR_TEXT or TR_LINE complexes also in...
uint32_t used
storage slots in use
Information for all complexes.
uint32_t used
storage slots in use
uint32_t paras
Number of complexes (paras) entered in phase 2
uint32_t space
storage slots allocated
uint32_t phase1
Number of complexes (lines + text fragments) entered in phase 1
CX_SPECS * cx
complexes
uint32_t lines
Number of lines in phase 1
Information for a single complex.
CHILD_SPECS kids
immediate child nodes of this complex, for type TR_TEXT the idx refers to the tpi data.
enum tr_classes type
classification of the complex
int rt_cidx
index of rectangle that contains all members
Information for a font instance.
uint32_t space
alts storage slots allocated
uint32_t used
alts storage slots in use
uint8_t * fontspec
pointer to a font specification (name:italics, etc.)
FcPattern * fpat
current font, must hang onto this or faces operations break
FcFontSet * fontset
all matching fonts (for fallback on missing glyphs)
double spcadv
advance equal to a space, in points at font's face size
FT_Face face
font face structures (FT_FACE is a pointer!)
double fsize
font's face size in points
uint8_t * file
pointer to font paths to files
ALT_SPECS * alts
index into FT_INFO fonts, for fonts added for missing glyphs
Information for all font instances.
FT_Library library
Fontconfig handle
uint32_t used
storage slots in use
FNT_SPECS * fonts
Array of fontinfo structures
uint32_t space
storage slots allocated
Information for one padding record.
double right
to right
double down
to bottom
double left
to left
double up
to top
Information for a single text object.
int rt_tidx
index of rectangle that contains it
int decoration
text decorations, ignored during assembly, used during output
int weight
weight, as in FontConfig
int taln
text alignment with respect to x,y
double boff
Y LL corner - boff finds baseline
int spaces
count of spaces converted from wide kerning (1 or 2)
double ykern
y kern relative to preceding text chunk in complex (if any)
int co
condensed override, if set Font name included narrow
double ori
Orientation, angle of characters with respect to baseline in degrees.
TRCOLORREF decColor
text decoration color, ignored during assembly, used during output
int fi_idx
index of the font it uses
uint8_t * string
UTF-8 text
double xkern
x kern relative to preceding text chunk in complex (if any)
double fs
font size of text
int ldir
language direction LDIR_*
double vadvance
Line spacing typically 1.25 or 1.2, only set on the first text element in a complex
TRCOLORREF color
RGB
int italics
italics, as in FontConfig
double x
x coordinate, relative to TR_INFO x,y, in points
double y
y coordinate, relative to TR_INFO x,y, in points
int condensed
condensed, as in FontConfig
Information for all text objects.
uint32_t space
storage slots allocated
TCHUNK_SPECS * chunks
text chunks
uint32_t used
storage slots in use
uint8_t Red
Red color (0-255)
uint8_t Green
Green color (0-255)
uint8_t Reserved
Not used.
uint8_t Blue
Blue color (0-255)
Information for the entire text reassembly system.
CX_INFO * cxi
Complex Info storage
double esc
escapement angle in DEGREES
uint8_t * out
buffer to hold formatted output
int use_kern
1 if kerning is used, 0 if not
int dirty
1 if text records are loaded
int load_flags
FT_LOAD_NO_SCALE or FT_LOAD_TARGET_NORMAL
double qe
quantization error in points.
FT_INFO * fti
Font info storage
BR_INFO * bri
Bounding Rectangle Info storage
double x
x coordinate of first text object, in points
int usebk
On output write the background color under the text
double y
y coordinate of first text object, in points
uint32_t outspace
storage in output buffer allocated
uint32_t outused
storage in output buffer in use
TRCOLORREF bkcolor
RGB background color
int kern_mode
FT_KERNING_DEFAULT, FT_KERNING_UNFITTED, or FT_KERNING_UNSCALED
TP_INFO * tpi
Text Info/Position Info storage
void cxinfo_dump(const TR_INFO *tri)
int trinfo_load_qe(TR_INFO *tri, double qe)
tr_classes
classification of complexes
@ TR_PARA_CJ
ditto, center justified
@ TR_PARA_RJ
ditto, right justified
@ TR_TEXT
simple text object
@ TR_LINE
linear assembly of TR_TEXTs
@ TR_PARA_LJ
ditto, left justified
@ TR_PARA_UJ
sequential assembly of TR_LINEs and TR_TEXTs into a paragraph - unknown justification properties
int brinfo_make_insertable(BR_INFO *bri)
void csp_release(CHILD_SPECS *csp)
TR_INFO * trinfo_init(TR_INFO *tri)
char * TR_construct_fontspec(const TCHUNK_SPECS *tsp, const char *fontname)
CX_INFO * cxinfo_init(void)
int TR_layout_analyze(TR_INFO *tri)
int ftinfo_insert(FT_INFO *fti, FNT_SPECS *fsp)
int cxinfo_append(CX_INFO *cxi, int src, enum tr_classes type)
int ftinfo_find_loaded_by_src(const FT_INFO *fti, const uint8_t *filename)
int is_mn_unicode(int test)
int TR_weight_FC_to_SVG(int weight)
FT_INFO * ftinfo_release(FT_INFO *fti)
int fsp_alts_insert(FNT_SPECS *fsp, uint32_t fi_idx)
void ftinfo_dump(const FT_INFO *fti)
int tpinfo_make_insertable(TP_INFO *tpi)
FT_INFO * ftinfo_clear(FT_INFO *fti)
TP_INFO * tpinfo_release(TP_INFO *tpi)
int trinfo_load_bk(TR_INFO *tri, int usebk, TRCOLORREF bkcolor)
int ftinfo_find_loaded_by_spec(const FT_INFO *fti, const uint8_t *fname)
int brinfo_overlap(const BR_INFO *bri, int dst, int src, RT_PAD *rp_dst, RT_PAD *rp_src)
int trinfo_append_out(TR_INFO *tri, const char *src)
int fsp_alts_weight(FNT_SPECS *fsp, uint32_t a_idx)
void TR_layout_2_svg(TR_INFO *tri)
int csp_merge(CHILD_SPECS *dst, CHILD_SPECS *src)
TP_INFO * tpinfo_init(void)
void TR_rt_pad_set(RT_PAD *rt_pad, double up, double down, double left, double right)
int tpinfo_insert(TP_INFO *tpi, const TCHUNK_SPECS *tsp)
enum tr_classes brinfo_pp_alignment(const BR_INFO *bri, int dst, int src, double slop, enum tr_classes type)
TR_INFO * trinfo_clear(TR_INFO *tri)
int TR_getkern2(FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int kern_mode)
int csp_insert(CHILD_SPECS *csp, int src)
int TR_find_alternate_font(FT_INFO *fti, FNT_SPECS **efsp, uint32_t wc)
FT_INFO * ftinfo_init(void)
int TR_getadvance(FT_INFO *fti, FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int load_flags, int kern_mode, int *ymin, int *ymax)
int TR_check_set_vadvance(TR_INFO *tri, int src, int lines)
int TR_kern_gap(FNT_SPECS *fsp, TCHUNK_SPECS *tsp, TCHUNK_SPECS *ptsp, int kern_mode)
int cxinfo_merge(CX_INFO *cxi, int dst, int src, enum tr_classes type)
BR_INFO * brinfo_init(void)
int trinfo_check_bk(TR_INFO *tri, int usebk, TRCOLORREF bkcolor)
TR_INFO * trinfo_release_except_FC(TR_INFO *tri)
char * TR_reconstruct_fontspec(const char *fontspec, const char *fontname)
int trinfo_load_ft_opts(TR_INFO *tri, int use_kern, int load_flags, int kern_mode)
int cxinfo_insert(CX_INFO *cxi, int src, int src_rt_idx, enum tr_classes type)
int TR_findcasesub(const char *string, const char *sub)
int fsp_alts_make_insertable(FNT_SPECS *fsp)
int trinfo_load_textrec(TR_INFO *tri, const TCHUNK_SPECS *tsp, double escapement, int flags)
BR_INFO * brinfo_release(BR_INFO *bri)
void csp_clear(CHILD_SPECS *csp)
int cxinfo_make_insertable(CX_INFO *cxi)
int brinfo_insert(BR_INFO *bri, const BRECT_SPECS *element)
double TR_baseline(TR_INFO *tri, int src, double *AscMax, double *DscMax)
int csp_make_insertable(CHILD_SPECS *csp)
int ftinfo_make_insertable(FT_INFO *fti)
int cxinfo_trim(CX_INFO *cxi)
int ftinfo_load_fontname(FT_INFO *fti, const char *fontspec)
int brinfo_merge(BR_INFO *bri, int dst, int src)
TR_INFO * trinfo_release(TR_INFO *tri)
CX_INFO * cxinfo_release(CX_INFO *cxi)