forward declaration for circular dependency
extern const char *fz_glyph_name_from_adobe_standard[256]
Various font encoding tables and lookup functions
extern const char *fz_glyph_name_from_iso8859_7[256]
extern const char *fz_glyph_name_from_koi8u[256]
extern const char *fz_glyph_name_from_mac_expert[256]
extern const char *fz_glyph_name_from_mac_roman[256]
extern const char *fz_glyph_name_from_win_ansi[256]
extern const char *fz_glyph_name_from_windows_1252[256]
extern const unsigned short fz_unicode_from_iso8859_1[256]
extern const unsigned short fz_unicode_from_iso8859_7[256]
extern const unsigned short fz_unicode_from_koi8u[256]
extern const unsigned short fz_unicode_from_pdf_doc_encoding[256]
extern const unsigned short fz_unicode_from_windows_1250[256]
extern const unsigned short fz_unicode_from_windows_1251[256]
extern const unsigned short fz_unicode_from_windows_1252[256]
int
fz_iso8859_1_from_unicode (
int u
)
int
fz_iso8859_7_from_unicode (
int u
)
int
fz_koi8u_from_unicode (
int u
)
int
fz_windows_1250_from_unicode (
int u
)
int
fz_windows_1251_from_unicode (
int u
)
int
fz_windows_1252_from_unicode (
int u
)
int
fz_unicode_from_glyph_name (
const char *name
)
int
fz_unicode_from_glyph_name_strict (
const char *name
)
const char **
fz_duplicate_glyph_names_from_unicode (
int unicode
)
const char *
fz_glyph_name_from_unicode_sc (
int unicode
)
typedef struct fz_text_decoder fz_text_decoder
A text decoder (to read arbitrary encodings and convert to unicode).
struct fz_text_decoder {
// get maximum size estimate of converted text (fast)
size_t (*decode_bound)(fz_text_decoder *dec, unsigned char *input, size_t n);
// get exact size of converted text (slow)
size_t (*decode_size)(fz_text_decoder *dec, unsigned char *input, size_t n);
// convert text into output buffer
void (*decode)(fz_text_decoder *dec, char *output, unsigned char *input, size_t n);
// for internal use only; do not touch!
void *table1;
void *table2;
}
void
fz_init_text_decoder (
fz_context *ctx,
fz_text_decoder *dec,
const char *encoding
)
Initialize a text decoder using an IANA encoding name. See source/fitz/text-decoder.c for the exact list of supported encodings. Will throw an exception if the requested encoding is not available.
The following is a subset of the supported encodings (see source/fitz/text-decoder.c for the full list): iso-8859-1 iso-8859-7 koi8-r euc-jp shift_jis euc-kr euc-cn gb18030 euc-tw big5
typedef struct fz_font fz_font
An abstract font handle.
Fonts come in two variants: Regular fonts are handled by FreeType. Type 3 fonts have callbacks to the interpreter.
void *
fz_font_ft_face (
fz_context *ctx,
fz_font *font
)
Retrieve the FT_Face handle for the font.
Returns the FT_Face handle for the font, or NULL if not a freetype handled font. (Cast to void * to avoid nasty header exposure).
fz_buffer **
fz_font_t3_procs (
fz_context *ctx,
fz_font *font
)
Retrieve the Type3 procs for a font.
Returns the t3_procs pointer. Will be NULL for a non type-3 font.
enum fz_adobe_cjk_collection { FZ_ADOBE_CNS, FZ_ADOBE_GB, FZ_ADOBE_JAPAN, FZ_ADOBE_KOREA }
common CJK font collections
struct fz_font_flags_t
{
unsigned int is_mono : 1;
unsigned int is_serif : 1;
unsigned int is_bold : 1;
unsigned int is_italic : 1;
unsigned int ft_substitute : 1; /* use substitute metrics */
unsigned int ft_stretch : 1; /* stretch to match PDF metrics */
unsigned int fake_bold : 1; /* synthesize bold */
unsigned int fake_italic : 1; /* synthesize italic */
unsigned int has_opentype : 1; /* has opentype shaping tables */
unsigned int invalid_bbox : 1;
unsigned int cjk : 1;
unsigned int cjk_lang : 2; /* CNS, GB, JAPAN, or KOREA */
unsigned int embed : 1;
unsigned int never_embed : 1;
}
Every fz_font carries a set of flags within it, in a fz_font_flags_t structure.
fz_font_flags_t *
fz_font_flags (
fz_font *font
)
Retrieve a pointer to the font flags for a given font. These can then be updated as required.
Returns a pointer to the flags structure (or NULL, if the font is NULL).
struct fz_shaper_data
{
void *shaper_handle;
void (*destroy)(fz_context *ctx, void *); /* Destructor for shape_handle */
}
In order to shape a given font, we need to declare it to a shaper library (harfbuzz, by default, but others are possible). To avoid redeclaring it every time we need to shape, we hold a shaper handle and the destructor for it within the font itself. The handle is initialised by the caller when first required and the destructor is called when the fz_font is destroyed.
fz_shaper_data *
fz_font_shaper_data (
fz_context *ctx,
fz_font *font
)
Retrieve a pointer to the shaper data structure for the given font.
Returns a pointer to the shaper data structure (or NULL if font is NULL).
const char *
fz_font_name (
fz_context *ctx,
fz_font *font
)
Retrieve a pointer to the name of the font.
Returns a pointer to an internal copy of the font name. Will never be NULL, but may be the empty string.
int
fz_font_is_bold (
fz_context *ctx,
fz_font *font
)
Query whether the font flags say that this font is bold.
int
fz_font_is_italic (
fz_context *ctx,
fz_font *font
)
Query whether the font flags say that this font is italic.
int
fz_font_is_serif (
fz_context *ctx,
fz_font *font
)
Query whether the font flags say that this font is serif.
int
fz_font_is_monospaced (
fz_context *ctx,
fz_font *font
)
Query whether the font flags say that this font is monospaced.
fz_rect
fz_font_bbox (
fz_context *ctx,
fz_font *font
)
Retrieve the font bbox.
Returns the font bbox by value; it is valid only if fz_font_flags(font)->invalid_bbox is zero.
typedef fz_font *(fz_load_system_font_fn)(fz_context *ctx, const char *name, int bold, int italic, int needs_exact_metrics)
Type for user supplied system font loading hook.
Returns a new font handle, or NULL if no font found (or on error).
typedef fz_font *(fz_load_system_cjk_font_fn)(fz_context *ctx, const char *name, int ordering, int serif)
Type for user supplied cjk font loading hook.
Returns a new font handle, or NULL if no font found (or on error).
typedef fz_font *(fz_load_system_fallback_font_fn)(fz_context *ctx, int script, int language, int serif, int bold, int italic)
Type for user supplied fallback font loading hook.
Returns a new font handle, or NULL if no font found (or on error).
void
fz_install_load_system_font_funcs (
fz_context *ctx,
fz_load_system_font_fn *f,
fz_load_system_cjk_font_fn *f_cjk,
fz_load_system_fallback_font_fn *f_fallback
)
Install functions to allow MuPDF to request fonts from the system.
Only one set of hooks can be in use at a time.
fz_font *
fz_load_system_font (
fz_context *ctx,
const char *name,
int bold,
int italic,
int needs_exact_metrics
)
Attempt to load a given font from the system.
Returns a new font handle, or NULL if no matching font was found (or on error).
fz_font *
fz_load_system_cjk_font (
fz_context *ctx,
const char *name,
int ordering,
int serif
)
Attempt to load a given font from the system.
Returns a new font handle, or NULL if no matching font was found (or on error).
const unsigned char *
fz_lookup_builtin_font (
fz_context *ctx,
const char *name,
int bold,
int italic,
int *len
)
Search the builtin fonts for a match. Whether a given font is present or not will depend on the configuration in which MuPDF is built.
Returns a pointer to the font file data, or NULL if not present.
const unsigned char *
fz_lookup_base14_font (
fz_context *ctx,
const char *name,
int *len
)
Search the builtin base14 fonts for a match. Whether a given font is present or not will depend on the configuration in which MuPDF is built.
Returns a pointer to the font file data, or NULL if not present.
const unsigned char *
fz_lookup_cjk_font (
fz_context *ctx,
int ordering,
int *len,
int *index
)
Search the builtin cjk fonts for a match. Whether a font is present or not will depend on the configuration in which MuPDF is built.
Returns a pointer to the font file data, or NULL if not present.
const unsigned char *
fz_lookup_cjk_font_by_language (
fz_context *ctx,
const char *lang,
int *len,
int *subfont
)
Search the builtin cjk fonts for a match for a given language. Whether a font is present or not will depend on the configuration in which MuPDF is built.
Returns a pointer to the font file data, or NULL if not present.
int
fz_lookup_cjk_ordering_by_language (
const char *name
)
Return the matching FZ_ADOBE_* ordering for the given language tag, such as “zh-Hant”, “zh-Hans”, “ja”, or “ko”.
Attributes for a font.
const unsigned char *
fz_lookup_noto_font (
fz_context *ctx,
int script,
int lang,
int *len,
int *subfont,
int *attr,
int *index
)
Search the builtin noto fonts for a match. Whether a font is present or not will depend on the configuration in which MuPDF is built.
Returns a pointer to the font file data, or NULL if not present.
const unsigned char *
fz_lookup_noto_math_font (
fz_context *ctx,
int *len
)
Search the builtin noto fonts specific symbol fonts. Whether a font is present or not will depend on the configuration in which MuPDF is built.
const unsigned char *
fz_lookup_noto_music_font (
fz_context *ctx,
int *len
)
const unsigned char *
fz_lookup_noto_symbol1_font (
fz_context *ctx,
int *len
)
const unsigned char *
fz_lookup_noto_symbol2_font (
fz_context *ctx,
int *len
)
const unsigned char *
fz_lookup_noto_emoji_font (
fz_context *ctx,
int *len
)
const unsigned char *
fz_lookup_noto_boxes_font (
fz_context *ctx,
int *len
)
const char *
fz_lookup_noto_stem_from_script (
fz_context *ctx,
int script,
int language
)
Look up the Noto font file name for a given script. From the returned font stem, you can look for Noto fonts on the system in the form: Noto(Sans|Serif)${STEM}-Regular.(otf|ttf)
const char *
fz_lookup_script_name (
fz_context *ctx,
int script,
int language
)
fz_font *
fz_load_fallback_font (
fz_context *ctx,
int script,
int language,
int serif,
int bold,
int italic
)
Try to load a fallback font for the given combination of font attributes. Whether a font is present or not will depend on the configuration in which MuPDF is built.
Returns a new font handle, or NULL if not available.
fz_font *
fz_new_type3_font (
fz_context *ctx,
const char *name,
fz_matrix matrix
)
Create a new (empty) type3 font.
Returns a new font handle, or throws exception on allocation failure.
fz_font *
fz_new_font_from_memory (
fz_context *ctx,
const char *name,
const unsigned char *data,
int len,
int index,
int use_glyph_bbox
)
Create a new font from a font file in memory.
Fonts created in this way, will be eligible for embedding by default.
Returns new font handle, or throws exception on error.
fz_font *
fz_new_font_from_buffer (
fz_context *ctx,
const char *name,
fz_buffer *buffer,
int index,
int use_glyph_bbox
)
Create a new font from a font file in a fz_buffer.
Fonts created in this way, will be eligible for embedding by default.
Returns new font handle, or throws exception on error.
fz_font *
fz_new_font_from_file (
fz_context *ctx,
const char *name,
const char *path,
int index,
int use_glyph_bbox
)
Create a new font from a font file.
Fonts created in this way, will be eligible for embedding by default.
Returns new font handle, or throws exception on error.
fz_font *
fz_new_base14_font (
fz_context *ctx,
const char *name
)
Create a new font from one of the built-in fonts.
fz_font *
fz_new_cjk_font (
fz_context *ctx,
int ordering
)
fz_font *
fz_new_builtin_font (
fz_context *ctx,
const char *name,
int is_bold,
int is_italic
)
void
fz_set_font_embedding (
fz_context *ctx,
fz_font *font,
int embed
)
Control whether a given font should be embedded or not when writing.
fz_font *
fz_keep_font (
fz_context *ctx,
fz_font *font
)
Add a reference to an existing fz_font.
Returns the same font.
void
fz_drop_font (
fz_context *ctx,
fz_font *font
)
Drop a reference to a fz_font, destroying the font when the last reference is dropped.
void
fz_set_font_bbox (
fz_context *ctx,
fz_font *font,
float xmin,
float ymin,
float xmax,
float ymax
)
Set the font bbox.
fz_rect
fz_bound_glyph (
fz_context *ctx,
fz_font *font,
int gid,
fz_matrix trm
)
Return a bbox for a given glyph in a font.
Returns rectangle by value containing the bounds of the given glyph.
int
fz_glyph_cacheable (
fz_context *ctx,
fz_font *font,
int gid
)
Determine if a given glyph in a font is cacheable. Certain glyphs in a type 3 font cannot safely be cached, as their appearance depends on the enclosing graphic state.
Returns non-zero if cacheable, 0 if not.
void
fz_run_t3_glyph (
fz_context *ctx,
fz_font *font,
int gid,
fz_matrix trm,
struct fz_device *dev
)
Run a glyph from a Type3 font to a given device.
float
fz_advance_glyph (
fz_context *ctx,
fz_font *font,
int glyph,
int wmode
)
Return the advance for a given glyph.
Returns the advance for the glyph.
int
fz_encode_character (
fz_context *ctx,
fz_font *font,
int unicode
)
Find the glyph id for a given unicode character within a font.
Returns the glyph id for the given unicode value, or 0 if unknown.
int
fz_encode_character_sc (
fz_context *ctx,
fz_font *font,
int unicode
)
Encode character, preferring small-caps variant if available.
Returns the glyph id for the given unicode value, or 0 if unknown.
int
fz_encode_character_by_glyph_name (
fz_context *ctx,
fz_font *font,
const char *glyphname
)
Encode character.
Either by direct lookup of glyphname within a font, or, failing that, by mapping glyphname to unicode and thence to the glyph index within the given font.
Returns zero for type3 fonts.
int
fz_encode_character_with_fallback (
fz_context *ctx,
fz_font *font,
int unicode,
int script,
int language,
fz_font **out_font
)
Find the glyph id for a given unicode character within a font, falling back to an alternative if not found.
Returns the glyph id for the given unicode value in the supplied font (and sets out_font to font) if it is present. Otherwise an alternative fallback font (based on script/language) is searched for. If the glyph is found therein, out_font is set to this reference, and the glyph reference is returned. If it cannot be found anywhere, the function returns 0.
void
fz_get_glyph_name (
fz_context *ctx,
fz_font *font,
int glyph,
char *buf,
int size
)
Find the name of a glyph
If a font contains a name table, then the name of the glyph will be returned in the supplied buffer. Otherwise a name is synthesised. The name will be truncated to fit in the buffer.
float
fz_font_ascender (
fz_context *ctx,
fz_font *font
)
Retrieve font ascender in ems.
float
fz_font_descender (
fz_context *ctx,
fz_font *font
)
Retrieve font descender in ems.
void
fz_font_digest (
fz_context *ctx,
fz_font *font,
unsigned char digest[16]
)
Retrieve the MD5 digest for the font’s data.
void
fz_decouple_type3_font (
fz_context *ctx,
fz_font *font,
void *t3doc
)
Implementation details: subject to change.
const char *
ft_error_string (
int err
)
map an FT error number to a static string.
Returns a pointer to a static textual representation of a freetype error.
int
ft_char_index (
void *face,
int cid
)
int
ft_name_index (
void *face,
const char *name
)
Internal functions for our Harfbuzz integration to work around the lack of thread safety.
void
fz_hb_lock (
fz_context *ctx
)
Lock against Harfbuzz being called simultaneously in several threads. This reuses FZ_LOCK_FREETYPE.
void
fz_hb_unlock (
fz_context *ctx
)
Unlock after a Harfbuzz call. This reuses FZ_LOCK_FREETYPE.
typedef void (fz_cmap_callback)(fz_context *ctx, void *opaque, unsigned long ucs, unsigned int gid)
Callback for use in font cmap enumeration.
void
fz_enumerate_font_cmap (
fz_context *ctx,
fz_font *font,
fz_cmap_callback *cb,
void *opaque
)
Enumerate a cmap using a callback.
void
fz_calculate_font_ascender_descender (
fz_context *ctx,
fz_font *font
)
Ensure that a font has its ascender/descender values calculated from the actual bbox of the glyphs.
Note, that we combine the declared values from the font (or the default values if those are not present) with the actual bbox to get the final result. So this can only cause ascender/descender to move further apart!
enum fz_ascdesc_source
{
FZ_ASCDESC_FROM_FONT,
FZ_ASCDESC_DEFAULT,
FZ_ASCDESC_FROM_BOUNDS
}
#define FZ_MAX_TRUSTWORTHY_ASCENT 8
#define FZ_MAX_TRUSTWORTHY_DESCENT -3
struct fz_font
{
int refs;
char name[32];
char family[32];
fz_buffer *buffer;
fz_font_flags_t flags;
void *ft_face; /* has an FT_Face if used */
fz_shaper_data shaper_data;
fz_matrix t3matrix;
void *t3resources;
fz_buffer **t3procs; /* has 256 entries if used */
struct fz_display_list **t3lists; /* has 256 entries if used */
float *t3widths; /* has 256 entries if used */
unsigned short *t3flags; /* has 256 entries if used */
void *t3doc; /* a pdf_document for the callback */
void (*t3run)(fz_context *ctx, void *doc, void *resources, fz_buffer *contents, struct fz_device *dev, fz_matrix ctm, void *gstate, fz_default_colorspaces *default_cs, void *fill_gstate, void *stroke_gstate);
void (*t3freeres)(fz_context *ctx, void *doc, void *resources);
int t3loading; /* to detect recursive type3 fonts */
fz_rect bbox; /* font bbox is used only for t3 fonts */
float ascender;
float descender;
fz_ascdesc_source ascdesc_src;
int glyph_count;
/* per glyph bounding box cache. */
fz_rect **bbox_table;
int use_glyph_bbox;
/* substitute metrics */
int width_count;
short width_default; /* in 1000 units */
short *width_table; /* in 1000 units */
/* cached glyph metrics */
float **advance_cache;
/* cached encoding lookup */
uint16_t *encoding_cache[256];
/* cached md5sum for caching */
int has_digest;
unsigned char digest[16];
/* Which font to use in a collection. */
int subfont;
}
void
fz_ft_lock (
fz_context *ctx
)
void
fz_ft_unlock (
fz_context *ctx
)
int
fz_ft_lock_held (
fz_context *ctx
)
Internal function. Must be called with FT_ALLOC_LOCK held. Returns 1 if this thread (context!) already holds the freeetype lock.
fz_buffer *
fz_extract_ttf_from_ttc (
fz_context *ctx,
fz_font *font
)
Internal function: Extract a ttf from the ttc that underlies a given fz_font. Caller takes ownership of the returned buffer.
fz_buffer *
fz_subset_ttf_for_gids (
fz_context *ctx,
fz_buffer *orig,
int *gids,
int num_gids,
int symbolic,
int cidfont
)
Internal function: Given a ttf in a buffer, create a subset ttf in a new buffer that only provides the required gids. Caller takes ownership of the returned buffer.
EXPERIMENTAL AND VERY SUBJECT TO CHANGE.
fz_buffer *
fz_subset_cff_for_gids (
fz_context *ctx,
fz_buffer *orig,
int *gids,
int num_gids,
int symbolic,
int cidfont
)
Internal function: Given a cff in a buffer, create a subset cff in a new buffer that only provides the required gids. Caller takes ownership of the returned buffer.
EXPERIMENTAL AND VERY SUBJECT TO CHANGE.