Path: blob/master/thirdparty/graphite/include/graphite2/Font.h
9912 views
/* SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later */1/* Copyright 2010, SIL International, All rights reserved. */2#pragma once34#include "graphite2/Types.h"56#define GR2_VERSION_MAJOR 17#define GR2_VERSION_MINOR 38#define GR2_VERSION_BUGFIX 14910#ifdef __cplusplus11extern "C"12{13#endif1415typedef struct gr_face gr_face;16typedef struct gr_font gr_font;17typedef struct gr_feature_ref gr_feature_ref;18typedef struct gr_feature_val gr_feature_val;1920/**21* Returns version information on this engine22*/23GR2_API void gr_engine_version(int *nMajor, int *nMinor, int *nBugFix);2425/**26* The Face Options allow the application to require that certain tables are27* read during face construction. This may be of concern if the appFaceHandle28* used in the gr_get_table_fn may change.29* The values can be combined30*/31enum gr_face_options {32/** No preload, no cmap caching, fail if the graphite tables are invalid */33gr_face_default = 0,34/** Dumb rendering will be enabled if the graphite tables are invalid. @deprecated Since 1.311 */35gr_face_dumbRendering = 1,36/** preload glyphs at construction time */37gr_face_preloadGlyphs = 2,38/** Cache the lookup from code point to glyph ID at construction time */39gr_face_cacheCmap = 4,40/** Preload everything */41gr_face_preloadAll = gr_face_preloadGlyphs | gr_face_cacheCmap42};4344/** Holds information about a particular Graphite silf table that has been loaded */45struct gr_faceinfo {46gr_uint16 extra_ascent; /**< The extra_ascent in the GDL, in design units */47gr_uint16 extra_descent; /**< The extra_descent in the GDL, in design units */48gr_uint16 upem; /**< The design units for the font */49enum gr_space_contextuals {50gr_space_unknown = 0, /**< no information is known. */51gr_space_none = 1, /**< the space character never occurs in any rules. */52gr_space_left_only = 2, /**< the space character only occurs as the first element in a rule. */53gr_space_right_only = 3, /**< the space character only occurs as the last element in a rule. */54gr_space_either_only = 4, /**< the space character only occurs as the only element in a rule. */55gr_space_both = 5, /**< the space character may occur as the first or last element of a rule. */56gr_space_cross = 6 /**< the space character occurs in a rule not as a first or last element. */57} space_contextuals;58unsigned int has_bidi_pass : 1; /**< the table specifies that a bidirectional pass should run */59unsigned int line_ends : 1; /**< there are line end contextuals somewhere */60unsigned int justifies : 1; /**< there are .justify properties set somewhere on some glyphs */61};6263typedef struct gr_faceinfo gr_faceinfo;6465/** type describing function to retrieve font table information66*67* @return a pointer to the table in memory. The pointed to memory must exist as68* long as the gr_face which makes the call.69* @param appFaceHandle is the unique information passed to gr_make_face()70* @param name is a 32bit tag to the table name.71* @param len returned by this function to say how long the table is in memory.72*/73typedef const void *(*gr_get_table_fn)(const void* appFaceHandle, unsigned int name, size_t *len);7475/** type describing function to release any resources allocated by the above get_table table function76*77* @param appFaceHandle is the unique information passed to gr_make_face()78* @param pointer to table memory returned by get_table.79*/80typedef void (*gr_release_table_fn)(const void* appFaceHandle, const void *table_buffer);8182/** struct housing function pointers to manage font table buffers for the graphite engine. */83struct gr_face_ops84{85/** size in bytes of this structure */86size_t size;87/** a pointer to a function to request a table from the client. */88gr_get_table_fn get_table;89/** is a pointer to a function to notify the client the a table can be released.90* This can be NULL to signify that the client does not wish to do any release handling. */91gr_release_table_fn release_table;92};93typedef struct gr_face_ops gr_face_ops;9495/** Create a gr_face object given application information and a table functions.96*97* @return gr_face or NULL if the font fails to load for some reason.98* @param appFaceHandle This is application specific information that is passed99* to the getTable function. The appFaceHandle must stay100* alive as long as the gr_face is alive.101* @param face_ops Pointer to face specific callback structure for table102* management. Must stay alive for the duration of the103* call only.104* @param faceOptions Bitfield describing various options. See enum gr_face_options for details.105*/106GR2_API gr_face* gr_make_face_with_ops(const void* appFaceHandle/*non-NULL*/, const gr_face_ops *face_ops, unsigned int faceOptions);107108/** @deprecated Since v1.2.0 in favour of gr_make_face_with_ops.109* Create a gr_face object given application information and a getTable function.110*111* @return gr_face or NULL if the font fails to load for some reason.112* @param appFaceHandle This is application specific information that is passed113* to the getTable function. The appFaceHandle must stay114* alive as long as the gr_face is alive.115* @param getTable Callback function to get table data.116* @param faceOptions Bitfield describing various options. See enum gr_face_options for details.117*/118GR2_DEPRECATED_API gr_face* gr_make_face(const void* appFaceHandle/*non-NULL*/, gr_get_table_fn getTable, unsigned int faceOptions);119120/** @deprecated Since 1.3.7 this function is now an alias for gr_make_face_with_ops().121*122* Create a gr_face object given application information, with subsegmental caching support123*124* @return gr_face or NULL if the font fails to load.125* @param appFaceHandle is a pointer to application specific information that is passed to getTable.126* This may not be NULL and must stay alive as long as the gr_face is alive.127* @param face_ops Pointer to face specific callback structure for table management. Must stay128* alive for the duration of the call only.129* @param segCacheMaxSize Unused.130* @param faceOptions Bitfield of values from enum gr_face_options131*/132GR2_DEPRECATED_API gr_face* gr_make_face_with_seg_cache_and_ops(const void* appFaceHandle, const gr_face_ops *face_ops, unsigned int segCacheMaxSize, unsigned int faceOptions);133134/** @deprecated Since 1.3.7 this function is now an alias for gr_make_face().135*136* Create a gr_face object given application information, with subsegmental caching support.137* This function is deprecated as of v1.2.0 in favour of gr_make_face_with_seg_cache_and_ops.138*139* @return gr_face or NULL if the font fails to load.140* @param appFaceHandle is a pointer to application specific information that is passed to getTable.141* This may not be NULL and must stay alive as long as the gr_face is alive.142* @param getTable The function graphite calls to access font table data143* @param segCacheMaxSize How large the segment cache is.144* @param faceOptions Bitfield of values from enum gr_face_options145*/146GR2_DEPRECATED_API gr_face* gr_make_face_with_seg_cache(const void* appFaceHandle, gr_get_table_fn getTable, unsigned int segCacheMaxSize, unsigned int faceOptions);147148/** Convert a tag in a string into a gr_uint32149*150* @return gr_uint32 tag, zero padded151* @param str a nul terminated string of which at most the first 4 characters are read152*/153GR2_API gr_uint32 gr_str_to_tag(const char *str);154155/** Convert a gr_uint32 tag into a string156*157* @param tag contains the tag to convert158* @param str is a pointer to a char array of at least size 4 bytes. The first 4 bytes of this array159* will be overwritten by this function. No nul is appended.160*/161GR2_API void gr_tag_to_str(gr_uint32 tag, char *str);162163/** Get feature values for a given language or default164*165* @return a copy of the default feature values for a given language. The application must call166* gr_featureval_destroy() to free this object when done.167* @param pFace The font face to get feature values from168* @param langname The language tag to get feature values for. If there is no such language or169* langname is 0, the default feature values for the font are returned.170* langname is right 0 padded and assumes lowercase. Thus the en langauge171* would be 0x656E0000. Langname may also be space padded, thus 0x656E2020.172*/173GR2_API gr_feature_val* gr_face_featureval_for_lang(const gr_face* pFace, gr_uint32 langname);174175/** Get feature reference for a given feature id from a face176*177* @return a feature reference corresponding to the given id. This data is part of the gr_face and178* will be freed when the face is destroyed.179* @param pFace Font face to get information on.180* @param featId Feature id tag to get reference to.181*/182GR2_API const gr_feature_ref* gr_face_find_fref(const gr_face* pFace, gr_uint32 featId);183184/** Returns number of feature references in a face **/185GR2_API gr_uint16 gr_face_n_fref(const gr_face* pFace);186187/** Returns feature reference at given index in face **/188GR2_API const gr_feature_ref* gr_face_fref(const gr_face* pFace, gr_uint16 i);189190/** Return number of languages the face knows about **/191GR2_API unsigned short gr_face_n_languages(const gr_face* pFace);192193/** Returns a language id corresponding to a language of given index in the face **/194GR2_API gr_uint32 gr_face_lang_by_index(const gr_face* pFace, gr_uint16 i);195196/** Destroy the given face and free its memory **/197GR2_API void gr_face_destroy(gr_face *face);198199/** Returns the number of glyphs in the face **/200GR2_API unsigned short gr_face_n_glyphs(const gr_face* pFace);201202/** Returns a faceinfo for the face and script **/203GR2_API const gr_faceinfo *gr_face_info(const gr_face *pFace, gr_uint32 script);204205/** Returns whether the font supports a given Unicode character206*207* @return true if the character is supported.208* @param pFace face to test within209* @param usv Unicode Scalar Value of character to test210* @param script Tag of script for selecting which set of pseudo glyphs to test. May be NULL.211*/212GR2_API int gr_face_is_char_supported(const gr_face *pFace, gr_uint32 usv, gr_uint32 script);213214#ifndef GRAPHITE2_NFILEFACE215/** Create gr_face from a font file216*217* @return gr_face that accesses a font file directly. Returns NULL on failure.218* @param filename Full path and filename to font file219* @param faceOptions Bitfile from enum gr_face_options to control face options.220*/221GR2_API gr_face* gr_make_file_face(const char *filename, unsigned int faceOptions);222223/** @deprecated Since 1.3.7. This function is now an alias for gr_make_file_face().224*225* Create gr_face from a font file, with subsegment caching support.226*227* @return gr_face that accesses a font file directly. Returns NULL on failure.228* @param filename Full path and filename to font file229* @param segCacheMaxSize Specifies how big to make the cache in segments.230* @param faceOptions Bitfield from enum gr_face_options to control face options.231*/232GR2_DEPRECATED_API gr_face* gr_make_file_face_with_seg_cache(const char *filename, unsigned int segCacheMaxSize, unsigned int faceOptions);233#endif // !GRAPHITE2_NFILEFACE234235/** Create a font from a face236*237* @return gr_font Call font_destroy to free this font238* @param ppm Resolution of the font in pixels per em239* @param face Face this font corresponds to. This must stay alive as long as the font is alive.240*/241GR2_API gr_font* gr_make_font(float ppm, const gr_face *face);242243/** query function to find the hinted advance of a glyph244*245* @param appFontHandle is the unique information passed to gr_make_font_with_advance()246* @param glyphid is the glyph to retireve the hinted advance for.247*/248typedef float (*gr_advance_fn)(const void* appFontHandle, gr_uint16 glyphid);249250/** struct housing function pointers to manage font hinted metrics for the251* graphite engine. */252struct gr_font_ops253{254/** size of the structure in bytes to allow for future extensibility */255size_t size;256/** a pointer to a function to retrieve the hinted257* advance width of a glyph which the font cannot258* provide without client assistance. This can be259* NULL to signify no horizontal hinted metrics are necessary. */260gr_advance_fn glyph_advance_x;261/** a pointer to a function to retrieve the hinted262* advance height of a glyph which the font cannot263* provide without client assistance. This can be264* NULL to signify no horizontal hinted metrics are necessary. */265gr_advance_fn glyph_advance_y;266};267typedef struct gr_font_ops gr_font_ops;268269/** Creates a font with hinted advance width query functions270*271* @return gr_font to be destroyed via font_destroy272* @param ppm size of font in pixels per em273* @param appFontHandle font specific information that must stay alive as long274* as the font does275* @param font_ops pointer font specific callback structure for hinted metrics.276* Need only stay alive for the duration of the call.277* @param face the face this font corresponds to. Must stay alive as long as278* the font does.279*/280GR2_API gr_font* gr_make_font_with_ops(float ppm, const void* appFontHandle, const gr_font_ops * font_ops, const gr_face *face);281282/** Creates a font with hinted advance width query function.283* This function is deprecated. Use gr_make_font_with_ops instead.284*285* @return gr_font to be destroyed via font_destroy286* @param ppm size of font in pixels per em287* @param appFontHandle font specific information that must stay alive as long288* as the font does289* @param getAdvance callback function reference that returns horizontal advance in pixels for a glyph.290* @param face the face this font corresponds to. Must stay alive as long as291* the font does.292*/293GR2_API gr_font* gr_make_font_with_advance_fn(float ppm, const void* appFontHandle, gr_advance_fn getAdvance, const gr_face *face);294295/** Free a font **/296GR2_API void gr_font_destroy(gr_font *font);297298/** get a feature value299*300* @return value of specific feature or 0 if any problems.301* @param pfeatureref gr_feature_ref to the feature302* @param feats gr_feature_val containing all the values303*/304GR2_API gr_uint16 gr_fref_feature_value(const gr_feature_ref* pfeatureref, const gr_feature_val* feats);305306/** set a feature value307*308* @return false if there were any problems (value out of range, etc.)309* @param pfeatureref gr_feature_ref to the feature310* @param val value to set the feature to311* @param pDest the gr_feature_val containing all the values for all the features312*/313GR2_API int gr_fref_set_feature_value(const gr_feature_ref* pfeatureref, gr_uint16 val, gr_feature_val* pDest);314315/** Returns the id tag for a gr_feature_ref **/316GR2_API gr_uint32 gr_fref_id(const gr_feature_ref* pfeatureref);317318/** Returns number of values a feature may take, given a gr_feature_ref **/319GR2_API gr_uint16 gr_fref_n_values(const gr_feature_ref* pfeatureref);320321/** Returns the value associated with a particular value in a feature322*323* @return value324* @param pfeatureref gr_feature_ref of the feature of interest325* @param settingno Index up to the return value of gr_fref_n_values() of the value326*/327GR2_API gr_int16 gr_fref_value(const gr_feature_ref* pfeatureref, gr_uint16 settingno);328329/** Returns a string of the UI name of a feature330*331* @return string of the UI name, in the encoding form requested. Call gr_label_destroy() after use.332* @param pfeatureref gr_feature_ref of the feature333* @param langId This is a pointer since the face may not support a string in the requested334* language. The actual language of the string is returned in langId335* @param utf Encoding form for the string336* @param length Used to return the length of the string returned in bytes.337*/338GR2_API void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, enum gr_encform utf, gr_uint32 *length);339340/** Return a UI string for a possible value of a feature341*342* @return string of the UI name, in the encoding form requested. nul terminated. Call gr_label_destroy()343* after use.344* @param pfeatureref gr_feature_ref of the feature345* @param settingno Value setting index346* @param langId This is a pointer to the requested language. The requested language id is347* replaced by the actual language id of the string returned.348* @param utf Encoding form for the string349* @param length Returns the length of the string returned in bytes.350*/351GR2_API void* gr_fref_value_label(const gr_feature_ref* pfeatureref, gr_uint16 settingno/*rather than a value*/, gr_uint16 *langId, enum gr_encform utf, gr_uint32 *length);352353/** Destroy a previously returned label string **/354GR2_API void gr_label_destroy(void * label);355356/** Copies a gr_feature_val **/357GR2_API gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures);358359/** Destroys a gr_feature_val **/360GR2_API void gr_featureval_destroy(gr_feature_val *pfeatures);361362#ifdef __cplusplus363}364#endif365366367