libTERE
A portable library for reassembling complex formatted text from text fragments.
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
Data Structures | Macros | Functions
text_reassemble.h File Reference
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <ctype.h>
#include <fontconfig/fontconfig.h>
#include <ft2build.h>
#include <iconv.h>

Go to the source code of this file.

Data Structures

struct  FNT_SPECS
 Information for a font instance. More...
struct  FT_INFO
 Information for all font instances. More...
struct  TCHUNK_SPECS
 Information for a single text object. More...
struct  TP_INFO
 Information for all text objects. Coordinates here are INTERNAL, after offset/rotate using values in TR_INFO. More...
struct  BRECT_SPECS
 Information for a single bounding rectangle. Coordinates here are INTERNAL, after offset/rotate using values in TR_INFO. More...
struct  BR_INFO
 Information for all bounding rectangles. More...
struct  CHILD_SPECS
 List of all members of a single complex. More...
struct  CX_SPECS
 Information for a single complex. More...
struct  CX_INFO
 Information for all complexes. More...
struct  TR_INFO
 Information for the entire text reassembly system. More...
struct  RT_PAD
 Information for one padding record. (Padding is added to bounding rectangles before overlap tests.) More...

Macros

#define ALILEFT   0x01
#define ALICENTER   0x02
#define ALIRIGHT   0x04
#define ALIHORI   0x07
#define ALITOP   0x08
#define ALIBASE   0x10
#define ALIBOT   0x20
#define ALIVERT   0x38
#define LDIR_LR   0x00
#define LDIR_RL   0x01
#define LDIR_TB   0x02
#define TR_EMFBOT   0x01

Enumerations

enum  tr_classes {
  TR_TEXT, TR_LINE, TR_PARA_UJ, TR_PARA_LJ,
  TR_PARA_CJ, TR_PARA_RJ
}

Functions

int TR_findcasesub (char *string, char *sub)
 Find a (sub)string in a caseinvariant manner, used for locating "Narrow" in font name.
int TR_getadvance (FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int load_flags, int kern_mode, int *ymin, int *ymax)
 Get the advance for the 32 bit character.
int TR_getkern2 (FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int kern_mode)
 Get the kerning for a pair of 32 bit characters.
int TR_kern_gap (FNT_SPECS *fsp, TCHUNK_SPECS *tsp, TCHUNK_SPECS *ptsp, int kern_mode)
 Get the kerning for a pair of 32 bit characters, where one is the last charcter in the previous text block, and the other is the first in the current text block.
void TR_rt_pad_set (RT_PAD *rt_pad, double up, double down, double left, double right)
 Set the padding that will be added to bounding rectangles before checking for overlaps in brinfo_overlap().
double TR_baseline (TR_INFO *tri, int src, double *AscMax, double *DscMax)
 Find baseline on Y axis of a complex. If the complex is a TR_TEXT or TR_LINE find its baseline. If the complex is TR_PARA_[UCLR]J find the baseline of the last line. If there are multiple text elements in a TR_LINE, the baseline is that of the element that uses the largest font. This will definitely give the wrong result if that line starts with a super or subscript that is full font size, but they are usually smaller.
int TR_check_set_vadvance (TR_INFO *tri, int src, int lines)
 Check or set vertical advance on the growing complex relative to the current complex. Vadvance is a multiplicative factor like 1.25. The distance between successive baselines is vadvance * max(font_size), where the maximum is over all text elements in src. The growing complex is always the last one in the CX_INFO section of the TR_INFO structure. If an existing vadvance does not match the one which would be required to fit the next complex to add to the growing one, it terminates a growing complex. (Ie, starts a new paragraph.) Find baseline on Y axis of a complex. If the complex is a TR_TEXT or TR_LINE find its baseline. If the complex is TR_PARA+* find the baseline of the last line. If there are multiple text elements in a TR_LINE, the baseline is that of the element that uses the largest font. This will definitely give the wrong result if that line starts with a super or subscript that is full font size, but they are usually smaller.
int TR_layout_analyze (TR_INFO *tri)
 Attempt to figure out the original organization, in lines and paragraphs, of the text objects. The method is:
void TR_layout_2_svg (TR_INFO *tri)
 Convert from analyzed complexes to SVG format.
int TR_weight_FC_to_SVG (int weight)
 Fontweight conversion. Fontconfig units to SVG units. Anything not recognized becomes "normal" == 400. There is no interpolation because a value that mapped to 775, for instance, most likely would not display properly because it is intermediate between 700 and 800, and only those need be supported in SVG viewers.
FT_INFOftinfo_init (void)
 Initialize an FT_INFO structure. Sets up a freetype library to use in this context.
int ftinfo_make_insertable (FT_INFO *fti)
 Make an FT_INFO structure insertable. Adds storage as needed.
int ftinfo_insert (FT_INFO *fti, FNT_SPECS *fsp)
 Insert a copy of a FNT_SPECS structure into the FT_INFO structure.
FT_INFOftinfo_release (FT_INFO *fti)
 Release an FT_INFO structure. Release all associated memory. Use like: fi_ptr = ftinfo_release(fi_ptr)
FT_INFOftinfo_clear (FT_INFO *fti)
 Clear an FT_INFO structure. Release all Freetype memory but does not release Fontconfig. This would be called in preference to ftinfo_release() if some other part of the program needed to continue using Fontconfig. Use like: fi_ptr = ftinfo_clear(fi_ptr)
int csp_make_insertable (CHILD_SPECS *csp)
 Make a CHILD_SPECS structure insertable. Adds storage as needed.
int csp_insert (CHILD_SPECS *csp, int src)
 Add a member to a CHILD_SPECS structure. (Member is an index for either a text object or a complex.)
int csp_merge (CHILD_SPECS *dst, CHILD_SPECS *src)
 Append all the members of one CHILD_SPECS structure to another CHILD_SPECS structure. Member is an index for either a text object or a complex. The donor is not modified.
void csp_release (CHILD_SPECS *csp)
 Release a CHILD_SPECS structure. Release all associated memory.
CX_INFOcxinfo_init (void)
 Initialize an CX_INFO structure. Holds complexes (multiple text objects in known positions and order.)
int cxinfo_make_insertable (CX_INFO *cxi)
 Make a CX_INFO structure insertable. Adds storage as needed.
int cxinfo_insert (CX_INFO *cxi, int src, int src_rt_idx, enum tr_classes type)
 Insert a complex into the CX_INFO structure. (Insert may be either TR_TEXT or TR_LINE.)
int cxinfo_append (CX_INFO *cxi, int src, enum tr_classes type)
 Append a complex to the CX_INFO structure and give it a type.
int cxinfo_merge (CX_INFO *cxi, int dst, int src, enum tr_classes type)
 Merge a complex dst with N members (N>=1) by adding a second complex src, and change the type.
CX_INFOcxinfo_release (CX_INFO *cxi)
 Release a CX_INFO structure. Release all associated memory. use like: cxi = cxiinfo_release(cxi);.
void cxinfo_dump (TR_INFO *tri)
 Dump the contents of the TR_INFO structure to stdout. For debugging purposes,not used in production code.
TP_INFOtpinfo_init (void)
 Initialize an TP_INFO structure. Holds text objects from which complexes are built.
int tpinfo_make_insertable (TP_INFO *tpi)
 Make a TP_INFO structure insertable. Adds storage as needed.
int tpinfo_insert (TP_INFO *tpi, TCHUNK_SPECS *tsp)
 Insert a copy of a TCHUNK_SPECS structure into a TP_INFO structure. (Insert a text object.)
TP_INFOtpinfo_release (TP_INFO *tpi)
 Release a TP_INFO structure. Release all associated memory. use like: tpi = tpinfo_release(tpi);.
BR_INFObrinfo_init (void)
 Initialize an BR_INFO structure. Holds bounding rectangles, for both text objects and complexes.
int brinfo_make_insertable (BR_INFO *bri)
 Make a BR_INFO structure insertable. Adds storage as needed.
int brinfo_insert (BR_INFO *bri, BRECT_SPECS *element)
 Insert a copy of a BRECT_SPEC structure into a BR_INFO structure. (Insert a bounding rectangle.)
int brinfo_merge (BR_INFO *bri, int dst, int src)
 Merge BRECT_SPEC element src into/with BRECT_SPEC element dst. src is unchanged. (Merge two bounding rectangles.)
enum tr_classes brinfo_pp_alignment (BR_INFO *bri, int dst, int src, double slop, enum tr_classes type)
 Try to deduce justification of a paragraph from the bounding rectangles for two successive lines.
int brinfo_overlap (BR_INFO *bri, int dst, int src, RT_PAD *rp_dst, RT_PAD *rp_src)
 Check for an allowable overlap of two bounding rectangles. Allowable overlap is any area overlap of src and dst bounding rectangles, after they have been expanded (padded) by allowed edge expansions. (For instance, if missing spaces must be accounted for.) The method works backwards: look for all reasons they might not overlap, if none are found, then the rectangles do overlap. An overlap here does not count just a line or a point - area must be involved.
BR_INFObrinfo_release (BR_INFO *bri)
 Release a BR_INFO structure. Release all associated memory. use like: bri = brinfo_release(bri);.
TR_INFOtrinfo_init (TR_INFO *tri)
 Initialize an TR_INFO structure. Holds all data for text reassembly.
TR_INFOtrinfo_release (TR_INFO *tri)
 Release a TR_INFO structure completely. Release all associated memory, including FontConfig. See also trinfo_clear() and trinfo_release_except_FC(). use like: tri = trinfo_release(tri);.
TR_INFOtrinfo_release_except_FC (TR_INFO *tri)
 Release a TR_INFO structure mostly. Release all associated memory EXCEPT Fontconfig. Fontconfig may still be needed elsewhere in a program and there is no way to figure that out here. See also trinfo_clear() and trinfo_release(). use like: tri = trinfo_release_except_FC(tri);.
TR_INFOtrinfo_clear (TR_INFO *tri)
 Clear a TR_INFO structure. Releases text and rectangle information, but retains font information, both Freetype information and Fontconfig information. See also trinfo_release() and trinfo_release_except_FC(). Use like: tri = trinfo_clear(tri);.
int trinfo_load_fontname (TR_INFO *tri, uint8_t *fontname, TCHUNK_SPECS *tsp)
 Load a (new) font by name into a TR_INFO structure.
int trinfo_load_qe (TR_INFO *tri, double qe)
 Set the quantization error value for a TR_INFO structure. If coordinates have passed through an integer form limits in accuracy may have been imposed. For instance, if the X coordinate of a point in such a file is 1000, and the conversion factor from those coordinates to points is .04, then eq is .04. This just says that single coordinates are only good to within .04, and two coordinates may differ by as much as .08, just due to quantization error. So if some calculation shows a difference of .02 it may be interpreted as this sort of error and set to 0.0.
int trinfo_load_ft_opts (TR_INFO *tri, int use_kern, int load_flags, int kern_mode)
 Set Freetype parameters and kerning mode (if any) in a TRI_INFO structure.
int trinfo_load_textrec (TR_INFO *tri, TCHUNK_SPECS *tsp, double escapement, int flags)
 Load a text object into a TR_INFO struct.
int trinfo_append_out (TR_INFO *tri, char *src)
 Append text to a TR_INFO struct's output buffer, expanding it if necessary.

Detailed Description

libTERE headers.

See text_reassemble.c for notes

File: text_reassemble.h Version: 0.0.3 Date: 11-DEC-2012 Author: David Mathog, Biology Division, Caltech email: matho.nosp@m.g@ca.nosp@m.ltech.nosp@m..edu Copyright: 2012 David Mathog and California Institute of Technology (Caltech)


Enumeration Type Documentation

enum tr_classes

classification of complexes

Enumerator:
TR_TEXT 

simple text object

TR_LINE 

linear assembly of TR_TEXTs

TR_PARA_UJ 

sequential assembly of TR_LINEs and TR_TEXTs into a paragraph - unknown justification properties

TR_PARA_LJ 

ditto, left justified

TR_PARA_CJ 

ditto, center justified

TR_PARA_RJ 

ditto, right justified


Function Documentation

BR_INFO* brinfo_init ( void  )

Initialize an BR_INFO structure. Holds bounding rectangles, for both text objects and complexes.

Returns:
a pointer to the BR_INFO structure created, or NULL on error.
int brinfo_insert ( BR_INFO bri,
BRECT_SPECS element 
)

Insert a copy of a BRECT_SPEC structure into a BR_INFO structure. (Insert a bounding rectangle.)

Returns:
0 on success, !0 on error.
Parameters:
bripointer to the BR_INFO structure
elementpointer to the BRECT_SPECS structure
int brinfo_make_insertable ( BR_INFO bri)

Make a BR_INFO structure insertable. Adds storage as needed.

Returns:
0 on success, !0 on error.
Parameters:
bripointer to the BR_INFO structure
int brinfo_merge ( BR_INFO bri,
int  dst,
int  src 
)

Merge BRECT_SPEC element src into/with BRECT_SPEC element dst. src is unchanged. (Merge two bounding rectangles.)

Returns:
0 on success, !0 on error.
Parameters:
bripointer to the BR_INFO structure
dstindex of the destination bounding rectangle.
srcindex of the source bounding rectangle.
int brinfo_overlap ( BR_INFO bri,
int  dst,
int  src,
RT_PAD rp_dst,
RT_PAD rp_src 
)

Check for an allowable overlap of two bounding rectangles. Allowable overlap is any area overlap of src and dst bounding rectangles, after they have been expanded (padded) by allowed edge expansions. (For instance, if missing spaces must be accounted for.) The method works backwards: look for all reasons they might not overlap, if none are found, then the rectangles do overlap. An overlap here does not count just a line or a point - area must be involved.

Returns:
0 on success (overlap detected), 1 on no overlap, anything else is an error.
Parameters:
bripointer to the BR_INFO structure
dstindex of the destination bounding rectangle.
srcindex of the source bounding rectangle.
rp_dstPointer to edge padding values for dst.
rp_srcPointer to edge padding values for src.
enum tr_classes brinfo_pp_alignment ( BR_INFO bri,
int  dst,
int  src,
double  slop,
enum tr_classes  type 
)

Try to deduce justification of a paragraph from the bounding rectangles for two successive lines.

Returns:
one of TR_PARA_ UJ (unknown justified), LJ, CJ, or RJ (left, center, or right justified).
Parameters:
bripointer to the BR_INFO structure
dstindex of the destination bounding rectangle.
srcindex of the source bounding rectangle.
slopallowed error in edge alignment.
typePreexisting justification for dst, if any. Justification of dst and src must match this or TR_PARA_UJ is returned even if dst and src have some (other) alignment.
BR_INFO* brinfo_release ( BR_INFO bri)

Release a BR_INFO structure. Release all associated memory. use like: bri = brinfo_release(bri);.

Parameters:
bripointer to the BR_INFO structure.
Returns:
NULL.
int csp_insert ( CHILD_SPECS dst,
int  src 
)

Add a member to a CHILD_SPECS structure. (Member is an index for either a text object or a complex.)

Parameters:
dstpointer to the CHILD_SPECS structure.
srcindex of the member.
Returns:
0 on success, !0 on error.
int csp_make_insertable ( CHILD_SPECS csp)

Make a CHILD_SPECS structure insertable. Adds storage as needed.

Parameters:
csppointer to the CHILD_SPECS structure
Returns:
0 on success, !0 on error.
int csp_merge ( CHILD_SPECS dst,
CHILD_SPECS src 
)

Append all the members of one CHILD_SPECS structure to another CHILD_SPECS structure. Member is an index for either a text object or a complex. The donor is not modified.

Parameters:
dstpointer to the recipient CHILD_SPECS structure.
srcpointer to the donor CHILD_SPECS structure.
Returns:
0 on success, !0 on error.
void csp_release ( CHILD_SPECS csp)

Release a CHILD_SPECS structure. Release all associated memory.

Parameters:
csppointer to the CHILD_SPECS structure.
Returns:
NULL.
int cxinfo_append ( CX_INFO cxi,
int  src,
enum tr_classes  type 
)

Append a complex to the CX_INFO structure and give it a type.

Parameters:
cxipointer to the CX_INFO structure (complexes).
srcindex of the complex to append.
typeTR_LINE (src is an index for tpi->chunks[]) or TR_PARA (src is an index for cxi->kids[]).
Returns:
0 on success, !0 on error.
void cxinfo_dump ( TR_INFO tri)

Dump the contents of the TR_INFO structure to stdout. For debugging purposes,not used in production code.

Parameters:
tripointer to the TR_INFO structure.
CX_INFO* cxinfo_init ( void  )

Initialize an CX_INFO structure. Holds complexes (multiple text objects in known positions and order.)

Returns:
a pointer to the CX_INFO structure created, or NULL on error.
int cxinfo_insert ( CX_INFO cxi,
int  src,
int  src_rt_tidx,
enum tr_classes  type 
)

Insert a complex into the CX_INFO structure. (Insert may be either TR_TEXT or TR_LINE.)

Returns:
0 on success, !0 on error.
Parameters:
cxipointer to the CX_INFO structure (complexes).
srcindex of the the complex to insert.
src_rt_tidxindex of the bounding rectangle
typeTR_TEXT (index is for tpi->chunks[]) or TR_LINE (index is for cxi->kids[])
int cxinfo_make_insertable ( CX_INFO cxi)

Make a CX_INFO structure insertable. Adds storage as needed.

Returns:
0 on success, !0 on error.
Parameters:
cxipointer to the CX_INFO structure
int cxinfo_merge ( CX_INFO cxi,
int  dst,
int  src,
enum tr_classes  type 
)

Merge a complex dst with N members (N>=1) by adding a second complex src, and change the type.

Parameters:
cxipointer to the CX_INFO structure (complexes).
dstindex of the complex to expand.
srcindex of the donor complex (which is not modified).
typeTR_LINE (src is an index for tpi->chunks[]) or TR_PARA (src is an index for cxi->kids[]).
Returns:
0 on success, !0 on error.
CX_INFO* cxinfo_release ( CX_INFO cxi)

Release a CX_INFO structure. Release all associated memory. use like: cxi = cxiinfo_release(cxi);.

Parameters:
cxipointer to the CX_INFO structure.
Returns:
NULL.
FT_INFO* ftinfo_clear ( FT_INFO fti)

Clear an FT_INFO structure. Release all Freetype memory but does not release Fontconfig. This would be called in preference to ftinfo_release() if some other part of the program needed to continue using Fontconfig. Use like: fi_ptr = ftinfo_clear(fi_ptr)

Parameters:
ftipointer to the FT_INFO structure.
Returns:
NULL.
FT_INFO* ftinfo_init ( void  )

Initialize an FT_INFO structure. Sets up a freetype library to use in this context.

Returns:
a pointer to the FT_INFO structure created, or NULL on error.
int ftinfo_insert ( FT_INFO fti,
FNT_SPECS fsp 
)

Insert a copy of a FNT_SPECS structure into the FT_INFO structure.

Parameters:
ftipointer to the FT_INFO structure.
fsppointer to the FNT_SPECS structure.
Returns:
0 on success, !0 on error.
int ftinfo_make_insertable ( FT_INFO fti)

Make an FT_INFO structure insertable. Adds storage as needed.

Parameters:
ftipointer to the FT_INFO structure
Returns:
0 on success, !0 on error.
FT_INFO* ftinfo_release ( FT_INFO fti)

Release an FT_INFO structure. Release all associated memory. Use like: fi_ptr = ftinfo_release(fi_ptr)

Parameters:
ftipointer to the FT_INFO structure.
Returns:
NULL.
TP_INFO* tpinfo_init ( void  )

Initialize an TP_INFO structure. Holds text objects from which complexes are built.

Returns:
a pointer to the TP_INFO structure created, or NULL on error.
int tpinfo_insert ( TP_INFO tpi,
TCHUNK_SPECS tsp 
)

Insert a copy of a TCHUNK_SPECS structure into a TP_INFO structure. (Insert a text object.)

Returns:
0 on success, !0 on error.
Parameters:
tpipointer to the TP_INFO structure
tsppointer to the TCHUNK_SPECS structure
int tpinfo_make_insertable ( TP_INFO tpi)

Make a TP_INFO structure insertable. Adds storage as needed.

Returns:
0 on success, !0 on error.
Parameters:
tpipointer to the TP_INFO structure
TP_INFO* tpinfo_release ( TP_INFO tpi)

Release a TP_INFO structure. Release all associated memory. use like: tpi = tpinfo_release(tpi);.

Returns:
NULL.
Parameters:
tpipointer to the TP_INFO structure.
double TR_baseline ( TR_INFO tri,
int  src,
double *  ymax,
double *  ymin 
)

Find baseline on Y axis of a complex. If the complex is a TR_TEXT or TR_LINE find its baseline. If the complex is TR_PARA_[UCLR]J find the baseline of the last line. If there are multiple text elements in a TR_LINE, the baseline is that of the element that uses the largest font. This will definitely give the wrong result if that line starts with a super or subscript that is full font size, but they are usually smaller.

Returns:
Returns 0 if it cannot determine a baseline, else returns the baseline Y coordinate.
Parameters:
tripointer to the TR_INFO structure holding all TR data
srcindex of the current complex
ymaxIf the pointer is defined, the value is adjusted if ymax of current complex is more than the current value.
yminIf the pointer is defined, the value is adjusted if ymin of current complex is less than the current value.
int TR_check_set_vadvance ( TR_INFO tri,
int  src,
int  lines 
)

Check or set vertical advance on the growing complex relative to the current complex. Vadvance is a multiplicative factor like 1.25. The distance between successive baselines is vadvance * max(font_size), where the maximum is over all text elements in src. The growing complex is always the last one in the CX_INFO section of the TR_INFO structure. If an existing vadvance does not match the one which would be required to fit the next complex to add to the growing one, it terminates a growing complex. (Ie, starts a new paragraph.) Find baseline on Y axis of a complex. If the complex is a TR_TEXT or TR_LINE find its baseline. If the complex is TR_PARA+* find the baseline of the last line. If there are multiple text elements in a TR_LINE, the baseline is that of the element that uses the largest font. This will definitely give the wrong result if that line starts with a super or subscript that is full font size, but they are usually smaller.

Returns:
Returns 0 on success, !0 on failure.
Parameters:
tripointer to the TR_INFO structure holding all TR data
srcindex of the current complex, to be added to the growing complex. This lets the value of "src - lines" determine the weight to give to each new vadvance value as it is merged into the running weighted average. This improves the accuracy of the vertical advance, since there can be some noise introduced when lines have different maximum font sizes.
linesindex of the first text block that was added to the growing complex.
int TR_findcasesub ( char *  string,
char *  sub 
)

Find a (sub)string in a caseinvariant manner, used for locating "Narrow" in font name.

Returns:
Returns -1 if no match, else returns the position (numbered from 0) of the first character of the match.
Parameters:
stringText to search
subText to find
int TR_getadvance ( FNT_SPECS fsp,
uint32_t  wc,
uint32_t  pc,
int  load_flags,
int  kern_mode,
int *  ymin,
int *  ymax 
)

Get the advance for the 32 bit character.

Returns:
Returns -1 on error, or advance in units of 1/64th of a Point.
Parameters:
fspPointer to FNT_SPECS struct.
wcCurrent character (32 bit int)
pcPrevious character
load_flagsControls internal advance: FT_LOAD_NO_SCALE, internal advance is in 1/64th of a point. (kerning values are still scaled) FT_LOAD_TARGET_NORMAL internal advance is in 1/64th of a point. The scale factor seems to be (Font Size in points)*(DPI)/(32.0 pnts)*(72 dpi).
kern_modeFT_KERNING_DEFAULT, FT_KERNING_UNFITTED, or FT_KERNING_UNSCALED. Set to match calling application.
yminIf the pointer is defined, the value is adjusted if ymin of wc character is less than the current value.
ymaxIf the pointer is defined, the value is adjusted if ymin of wc character is more than the current value.
int TR_getkern2 ( FNT_SPECS fsp,
uint32_t  wc,
uint32_t  pc,
int  kern_mode 
)

Get the kerning for a pair of 32 bit characters.

Returns:
Returns 0 on error, or kerning value (which may be 0) for the pair in units of 1/64th of a point.
Parameters:
fspPointer to FNT_SPECS struct.
wcCurrent character (32 bit int)
pcPrevious character
kern_modeFT_KERNING_DEFAULT, FT_KERNING_UNFITTED, or FT_KERNING_UNSCALED. Set to match calling application.
int TR_kern_gap ( FNT_SPECS fsp,
TCHUNK_SPECS tsp,
TCHUNK_SPECS ptsp,
int  kern_mode 
)

Get the kerning for a pair of 32 bit characters, where one is the last charcter in the previous text block, and the other is the first in the current text block.

Returns:
Returns 0 on error, or kerning value (which may be 0) for the pair in units of 1/64th of a point.
Parameters:
fspPointer to FNT_SPECS struct.
tspcurrent text object
ptspprevious text object
kern_modeFT_KERNING_DEFAULT, FT_KERNING_UNFITTED, or FT_KERNING_UNSCALED. Set to match calling application.
void TR_layout_2_svg ( TR_INFO tri)

Convert from analyzed complexes to SVG format.

Returns:
void
Parameters:
tripointer to a TR_INFO struct which will be analyzed. Result is stored in its "out" buffer.
int TR_layout_analyze ( TR_INFO tri)

Attempt to figure out the original organization, in lines and paragraphs, of the text objects. The method is:

  1. Generate complexes from the text objects (strings) by overlaps (optionally allowing up to two spaces to be added) to produce larger rectangles. Complexes that are more or less sequential and have 2 or more text objects are TR_LINEs, therwise they are TR_TEXT.
  2. Group sequential complexes (TR_LINE or TR_TEXT) into TR_PARA_UJ (paragraphs,by smooth progression in vertical position down page).
  3. Analyze the paragraphs to classify them as Left/Center/Right justified (possibly with indentation.) If they do not fall into any of these categories break that one back down into TR_LINE/TR_TEXT.
  4. Return the number of complex text objects.
    Returns:
    Number of complexes. (>=1, <= number of text objects.) <0 is an error.
    Parameters:
    tripointer to the TR_INFO structure holding the data, which will also hold the results.
void TR_rt_pad_set ( RT_PAD rt_pad,
double  up,
double  down,
double  left,
double  right 
)

Set the padding that will be added to bounding rectangles before checking for overlaps in brinfo_overlap().

Returns:
void
Parameters:
rt_padpointer to an RT_PAD structure.
uppadding for the top of a bounding rectangle.
downpadding for the bottom of a bounding rectangle.
leftpadding for the left of a bounding rectangle.
rightpadding for the right of a bounding rectangle.
int TR_weight_FC_to_SVG ( int  weight)

Fontweight conversion. Fontconfig units to SVG units. Anything not recognized becomes "normal" == 400. There is no interpolation because a value that mapped to 775, for instance, most likely would not display properly because it is intermediate between 700 and 800, and only those need be supported in SVG viewers.

Returns:
SVG font weight
Parameters:
weightFontconfig font weight.
int trinfo_append_out ( TR_INFO tri,
char *  src 
)

Append text to a TR_INFO struct's output buffer, expanding it if necessary.

Returns:
0 on success, !0 on error.
Parameters:
tripointer to a TR_INFO structure
srcPointer to a text string.
TR_INFO* trinfo_clear ( TR_INFO tri)

Clear a TR_INFO structure. Releases text and rectangle information, but retains font information, both Freetype information and Fontconfig information. See also trinfo_release() and trinfo_release_except_FC(). Use like: tri = trinfo_clear(tri);.

Parameters:
tripointer to the TR_INFO structure.
Returns:
NULL.
TR_INFO* trinfo_init ( TR_INFO tri)

Initialize an TR_INFO structure. Holds all data for text reassembly.

Returns:
a pointer to the TR_INFO structure created, or NULL on error.
int trinfo_load_fontname ( TR_INFO tri,
uint8_t *  fontname,
TCHUNK_SPECS tsp 
)

Load a (new) font by name into a TR_INFO structure.

Returns:
index of font. If the font was already loaded return the existing index.
Parameters:
tripointer to the TR_INFO structure.
fontnameUTF-8 font name
tsppointer to the TCHUNK_SPECS structure - used to construct a font query string.
int trinfo_load_ft_opts ( TR_INFO tri,
int  use_kern,
int  load_flags,
int  kern_mode 
)

Set Freetype parameters and kerning mode (if any) in a TRI_INFO structure.

Returns:
0 on success, !0 on error.
Parameters:
tripointer to a TR_INFO structure
use_kern0 if kerning is to be employed, !0 otherwise.
load_flagsControls internal advance: FT_LOAD_NO_SCALE, internal advance is in 1/64th of a point. (kerning values are still scaled) FT_LOAD_TARGET_NORMAL internal advance is in 1/64th of a point. The scale factor seems to be (Font Size in points)*(DPI)/(32.0 pnts)*(72 dpi).
kern_modeFT_KERNING_DEFAULT, FT_KERNING_UNFITTED, or FT_KERNING_UNSCALED. Set to match calling application.
int trinfo_load_qe ( TR_INFO tri,
double  qe 
)

Set the quantization error value for a TR_INFO structure. If coordinates have passed through an integer form limits in accuracy may have been imposed. For instance, if the X coordinate of a point in such a file is 1000, and the conversion factor from those coordinates to points is .04, then eq is .04. This just says that single coordinates are only good to within .04, and two coordinates may differ by as much as .08, just due to quantization error. So if some calculation shows a difference of .02 it may be interpreted as this sort of error and set to 0.0.

Returns:
0 on success, !0 on error.
Parameters:
tripointer to TR_INFO structure
qequantization error.
int trinfo_load_textrec ( TR_INFO tri,
TCHUNK_SPECS tsp,
double  escapement,
int  flags 
)

Load a text object into a TR_INFO struct.

Returns:
0 on success, !0 on error. -1 means that the escapement is different from the objects already loaded.
Parameters:
tripointer to a TR_INFO structure
tsppointer to a TCHUNK_SPECS structure (text object to load)
escapementangle in degrees of the text object.
flagsspecial processing flags: TR_EMFBOT calculate Y coordinates of ALIBOT object compatible with EMF files TA_BOTTOM alignment.
TR_INFO* trinfo_release ( TR_INFO tri)

Release a TR_INFO structure completely. Release all associated memory, including FontConfig. See also trinfo_clear() and trinfo_release_except_FC(). use like: tri = trinfo_release(tri);.

Parameters:
tripointer to the TR_INFO structure.
Returns:
NULL.
TR_INFO* trinfo_release_except_FC ( TR_INFO tri)

Release a TR_INFO structure mostly. Release all associated memory EXCEPT Fontconfig. Fontconfig may still be needed elsewhere in a program and there is no way to figure that out here. See also trinfo_clear() and trinfo_release(). use like: tri = trinfo_release_except_FC(tri);.

Parameters:
tripointer to the TR_INFO structure.
Returns:
NULL.