gfx/graphite2/include/graphite2/Font.h

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

michael@0 1 /* GRAPHITE2 LICENSING
michael@0 2
michael@0 3 Copyright 2010, SIL International
michael@0 4 All rights reserved.
michael@0 5
michael@0 6 This library is free software; you can redistribute it and/or modify
michael@0 7 it under the terms of the GNU Lesser General Public License as published
michael@0 8 by the Free Software Foundation; either version 2.1 of License, or
michael@0 9 (at your option) any later version.
michael@0 10
michael@0 11 This program is distributed in the hope that it will be useful,
michael@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
michael@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
michael@0 14 Lesser General Public License for more details.
michael@0 15
michael@0 16 You should also have received a copy of the GNU Lesser General Public
michael@0 17 License along with this library in the file named "LICENSE".
michael@0 18 If not, write to the Free Software Foundation, 51 Franklin Street,
michael@0 19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
michael@0 20 internet at http://www.fsf.org/licenses/lgpl.html.
michael@0 21
michael@0 22 Alternatively, the contents of this file may be used under the terms
michael@0 23 of the Mozilla Public License (http://mozilla.org/MPL) or the GNU
michael@0 24 General Public License, as published by the Free Software Foundation,
michael@0 25 either version 2 of the License or (at your option) any later version.
michael@0 26 */
michael@0 27 #pragma once
michael@0 28
michael@0 29 #include "graphite2/Types.h"
michael@0 30
michael@0 31 #define GR2_VERSION_MAJOR 1
michael@0 32 #define GR2_VERSION_MINOR 2
michael@0 33 #define GR2_VERSION_BUGFIX 4
michael@0 34
michael@0 35 #ifdef __cplusplus
michael@0 36 extern "C"
michael@0 37 {
michael@0 38 #endif
michael@0 39
michael@0 40 typedef struct gr_face gr_face;
michael@0 41 typedef struct gr_font gr_font;
michael@0 42 typedef struct gr_feature_ref gr_feature_ref;
michael@0 43 typedef struct gr_feature_val gr_feature_val;
michael@0 44
michael@0 45 /**
michael@0 46 * Returns version information on this engine
michael@0 47 */
michael@0 48 GR2_API void gr_engine_version(int *nMajor, int *nMinor, int *nBugFix);
michael@0 49
michael@0 50 /**
michael@0 51 * The Face Options allow the application to require that certain tables are
michael@0 52 * read during face construction. This may be of concern if the appFaceHandle
michael@0 53 * used in the gr_get_table_fn may change.
michael@0 54 * The values can be combined
michael@0 55 */
michael@0 56 enum gr_face_options {
michael@0 57 /** No preload, no cmap caching, fail if the graphite tables are invalid */
michael@0 58 gr_face_default = 0,
michael@0 59 /** Dumb rendering will be enabled if the graphite tables are invalid */
michael@0 60 gr_face_dumbRendering = 1,
michael@0 61 /** preload glyphs at construction time */
michael@0 62 gr_face_preloadGlyphs = 2,
michael@0 63 /** Cache the lookup from code point to glyph ID at construction time */
michael@0 64 gr_face_cacheCmap = 4,
michael@0 65 /** Preload everything */
michael@0 66 gr_face_preloadAll = gr_face_preloadGlyphs | gr_face_cacheCmap
michael@0 67 };
michael@0 68
michael@0 69 /** Holds information about a particular Graphite silf table that has been loaded */
michael@0 70 struct gr_faceinfo {
michael@0 71 gr_uint16 extra_ascent; /**< The extra_ascent in the GDL, in design units */
michael@0 72 gr_uint16 extra_descent; /**< The extra_descent in the GDL, in design units */
michael@0 73 gr_uint16 upem; /**< The design units for the font */
michael@0 74 enum gr_space_contextuals {
michael@0 75 gr_space_unknown = 0, /**< no information is known. */
michael@0 76 gr_space_none = 1, /**< the space character never occurs in any rules. */
michael@0 77 gr_space_left_only = 2, /**< the space character only occurs as the first element in a rule. */
michael@0 78 gr_space_right_only = 3, /**< the space character only occurs as the last element in a rule. */
michael@0 79 gr_space_either_only = 4, /**< the space character only occurs as the only element in a rule. */
michael@0 80 gr_space_both = 5, /**< the space character may occur as the first or last element of a rule. */
michael@0 81 gr_space_cross = 6 /**< the space character occurs in a rule not as a first or last element. */
michael@0 82 } space_contextuals;
michael@0 83 unsigned int has_bidi_pass : 1; /**< the table specifies that a bidirectional pass should run */
michael@0 84 unsigned int line_ends : 1; /**< there are line end contextuals somewhere */
michael@0 85 unsigned int justifies : 1; /**< there are .justify properties set somewhere on some glyphs */
michael@0 86 };
michael@0 87
michael@0 88 typedef struct gr_faceinfo gr_faceinfo;
michael@0 89
michael@0 90 /** type describing function to retrieve font table information
michael@0 91 *
michael@0 92 * @return a pointer to the table in memory. The pointed to memory must exist as
michael@0 93 * long as the gr_face which makes the call.
michael@0 94 * @param appFaceHandle is the unique information passed to gr_make_face()
michael@0 95 * @param name is a 32bit tag to the table name.
michael@0 96 * @param len returned by this function to say how long the table is in memory.
michael@0 97 */
michael@0 98 typedef const void *(*gr_get_table_fn)(const void* appFaceHandle, unsigned int name, size_t *len);
michael@0 99
michael@0 100 /** type describing function to release any resources allocated by the above get_table table function
michael@0 101 *
michael@0 102 * @param appFaceHandle is the unique information passed to gr_make_face()
michael@0 103 * @param pointer to table memory returned by get_table.
michael@0 104 */
michael@0 105 typedef void (*gr_release_table_fn)(const void* appFaceHandle, const void *table_buffer);
michael@0 106
michael@0 107 /** struct housing function pointers to manage font table buffers for the graphite engine. */
michael@0 108 struct gr_face_ops
michael@0 109 {
michael@0 110 /** size in bytes of this structure */
michael@0 111 size_t size;
michael@0 112 /** a pointer to a function to request a table from the client. */
michael@0 113 gr_get_table_fn get_table;
michael@0 114 /** is a pointer to a function to notify the client the a table can be released.
michael@0 115 * This can be NULL to signify that the client does not wish to do any release handling. */
michael@0 116 gr_release_table_fn release_table;
michael@0 117 };
michael@0 118 typedef struct gr_face_ops gr_face_ops;
michael@0 119
michael@0 120 /** Create a gr_face object given application information and a table functions.
michael@0 121 *
michael@0 122 * @return gr_face or NULL if the font fails to load for some reason.
michael@0 123 * @param appFaceHandle This is application specific information that is passed
michael@0 124 * to the getTable function. The appFaceHandle must stay
michael@0 125 * alive as long as the gr_face is alive.
michael@0 126 * @param face_ops Pointer to face specific callback structure for table
michael@0 127 * management. Must stay alive for the duration of the
michael@0 128 * call only.
michael@0 129 * @param faceOptions Bitfield describing various options. See enum gr_face_options for details.
michael@0 130 */
michael@0 131 GR2_API gr_face* gr_make_face_with_ops(const void* appFaceHandle/*non-NULL*/, const gr_face_ops *face_ops, unsigned int faceOptions);
michael@0 132
michael@0 133 /** Create a gr_face object given application information and a getTable function. This function is deprecated as of v1.2.0 in
michael@0 134 * favour of gr_make_face_with_ops.
michael@0 135 *
michael@0 136 * @return gr_face or NULL if the font fails to load for some reason.
michael@0 137 * @param appFaceHandle This is application specific information that is passed
michael@0 138 * to the getTable function. The appFaceHandle must stay
michael@0 139 * alive as long as the gr_face is alive.
michael@0 140 * @param getTable Callback function to get table data.
michael@0 141 * @param faceOptions Bitfield describing various options. See enum gr_face_options for details.
michael@0 142 */
michael@0 143 GR2_API gr_face* gr_make_face(const void* appFaceHandle/*non-NULL*/, gr_get_table_fn getTable, unsigned int faceOptions);
michael@0 144
michael@0 145 //#ifndef GRAPHITE2_NSEGCACHE
michael@0 146 /** Create a gr_face object given application information, with subsegmental caching support
michael@0 147 *
michael@0 148 * @return gr_face or NULL if the font fails to load.
michael@0 149 * @param appFaceHandle is a pointer to application specific information that is passed to getTable.
michael@0 150 * This may not be NULL and must stay alive as long as the gr_face is alive.
michael@0 151 * @param face_ops Pointer to face specific callback structure for table management. Must stay
michael@0 152 * alive for the duration of the call only.
michael@0 153 * @param segCacheMaxSize How large the segment cache is.
michael@0 154 * @param faceOptions Bitfield of values from enum gr_face_options
michael@0 155 */
michael@0 156 GR2_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);
michael@0 157
michael@0 158 /** Create a gr_face object given application information, with subsegmental caching support.
michael@0 159 * This function is deprecated as of v1.2.0 in favour of gr_make_face_with_seg_cache_and_ops.
michael@0 160 *
michael@0 161 * @return gr_face or NULL if the font fails to load.
michael@0 162 * @param appFaceHandle is a pointer to application specific information that is passed to getTable.
michael@0 163 * This may not be NULL and must stay alive as long as the gr_face is alive.
michael@0 164 * @param getTable The function graphite calls to access font table data
michael@0 165 * @param segCacheMaxSize How large the segment cache is.
michael@0 166 * @param faceOptions Bitfield of values from enum gr_face_options
michael@0 167 */
michael@0 168 GR2_API gr_face* gr_make_face_with_seg_cache(const void* appFaceHandle, gr_get_table_fn getTable, unsigned int segCacheMaxSize, unsigned int faceOptions);
michael@0 169 //#endif
michael@0 170
michael@0 171 /** Convert a tag in a string into a gr_uint32
michael@0 172 *
michael@0 173 * @return gr_uint32 tag, zero padded
michael@0 174 * @param str a nul terminated string of which at most the first 4 characters are read
michael@0 175 */
michael@0 176 GR2_API gr_uint32 gr_str_to_tag(const char *str);
michael@0 177
michael@0 178 /** Convert a gr_uint32 tag into a string
michael@0 179 *
michael@0 180 * @param tag contains the tag to convert
michael@0 181 * @param str is a pointer to a char array of at least size 4 bytes. The first 4 bytes of this array
michael@0 182 * will be overwritten by this function. No nul is appended.
michael@0 183 */
michael@0 184 GR2_API void gr_tag_to_str(gr_uint32 tag, char *str);
michael@0 185
michael@0 186 /** Get feature values for a given language or default
michael@0 187 *
michael@0 188 * @return a copy of the default feature values for a given language. The application must call
michael@0 189 * gr_featureval_destroy() to free this object when done.
michael@0 190 * @param pFace The font face to get feature values from
michael@0 191 * @param langname The language tag to get feature values for. If there is no such language or
michael@0 192 * langname is 0, the default feature values for the font are returned.
michael@0 193 * langname is right 0 padded and assumes lowercase. Thus the en langauge
michael@0 194 * would be 0x656E0000. Langname may also be space padded, thus 0x656E2020.
michael@0 195 */
michael@0 196 GR2_API gr_feature_val* gr_face_featureval_for_lang(const gr_face* pFace, gr_uint32 langname);
michael@0 197
michael@0 198 /** Get feature reference for a given feature id from a face
michael@0 199 *
michael@0 200 * @return a feature reference corresponding to the given id. This data is part of the gr_face and
michael@0 201 * will be freed when the face is destroyed.
michael@0 202 * @param pFace Font face to get information on.
michael@0 203 * @param featId Feature id tag to get reference to.
michael@0 204 */
michael@0 205 GR2_API const gr_feature_ref* gr_face_find_fref(const gr_face* pFace, gr_uint32 featId);
michael@0 206
michael@0 207 /** Returns number of feature references in a face **/
michael@0 208 GR2_API gr_uint16 gr_face_n_fref(const gr_face* pFace);
michael@0 209
michael@0 210 /** Returns feature reference at given index in face **/
michael@0 211 GR2_API const gr_feature_ref* gr_face_fref(const gr_face* pFace, gr_uint16 i);
michael@0 212
michael@0 213 /** Return number of languages the face knows about **/
michael@0 214 GR2_API unsigned short gr_face_n_languages(const gr_face* pFace);
michael@0 215
michael@0 216 /** Returns a language id corresponding to a language of given index in the face **/
michael@0 217 GR2_API gr_uint32 gr_face_lang_by_index(const gr_face* pFace, gr_uint16 i);
michael@0 218
michael@0 219 /** Destroy the given face and free its memory **/
michael@0 220 GR2_API void gr_face_destroy(gr_face *face);
michael@0 221
michael@0 222 /** Returns the number of glyphs in the face **/
michael@0 223 GR2_API unsigned short gr_face_n_glyphs(const gr_face* pFace);
michael@0 224
michael@0 225 /** Returns a faceinfo for the face and script **/
michael@0 226 GR2_API const gr_faceinfo *gr_face_info(const gr_face *pFace, gr_uint32 script);
michael@0 227
michael@0 228 /** Returns whether the font supports a given Unicode character
michael@0 229 *
michael@0 230 * @return true if the character is supported.
michael@0 231 * @param pFace face to test within
michael@0 232 * @param usv Unicode Scalar Value of character to test
michael@0 233 * @param script Tag of script for selecting which set of pseudo glyphs to test. May be NULL.
michael@0 234 */
michael@0 235 GR2_API int gr_face_is_char_supported(const gr_face *pFace, gr_uint32 usv, gr_uint32 script);
michael@0 236
michael@0 237 #ifndef GRAPHITE2_NFILEFACE
michael@0 238 /** Create gr_face from a font file
michael@0 239 *
michael@0 240 * @return gr_face that accesses a font file directly. Returns NULL on failure.
michael@0 241 * @param filename Full path and filename to font file
michael@0 242 * @param faceOptions Bitfile from enum gr_face_options to control face options.
michael@0 243 */
michael@0 244 GR2_API gr_face* gr_make_file_face(const char *filename, unsigned int faceOptions);
michael@0 245
michael@0 246 //#ifndef GRAPHITE2_NSEGCACHE
michael@0 247 /** Create gr_face from a font file, with subsegment caching support.
michael@0 248 *
michael@0 249 * @return gr_face that accesses a font file directly. Returns NULL on failure.
michael@0 250 * @param filename Full path and filename to font file
michael@0 251 * @param segCacheMaxSize Specifies how big to make the cache in segments.
michael@0 252 * @param faceOptions Bitfield from enum gr_face_options to control face options.
michael@0 253 */
michael@0 254 GR2_API gr_face* gr_make_file_face_with_seg_cache(const char *filename, unsigned int segCacheMaxSize, unsigned int faceOptions);
michael@0 255 //#endif
michael@0 256 #endif // !GRAPHITE2_NFILEFACE
michael@0 257
michael@0 258 /** Create a font from a face
michael@0 259 *
michael@0 260 * @return gr_font Call font_destroy to free this font
michael@0 261 * @param ppm Resolution of the font in pixels per em
michael@0 262 * @param face Face this font corresponds to. This must stay alive as long as the font is alive.
michael@0 263 */
michael@0 264 GR2_API gr_font* gr_make_font(float ppm, const gr_face *face);
michael@0 265
michael@0 266 /** query function to find the hinted advance of a glyph
michael@0 267 *
michael@0 268 * @param appFontHandle is the unique information passed to gr_make_font_with_advance()
michael@0 269 * @param glyphid is the glyph to retireve the hinted advance for.
michael@0 270 */
michael@0 271 typedef float (*gr_advance_fn)(const void* appFontHandle, gr_uint16 glyphid);
michael@0 272
michael@0 273 /** struct housing function pointers to manage font hinted metrics for the
michael@0 274 * graphite engine. */
michael@0 275 struct gr_font_ops
michael@0 276 {
michael@0 277 /** size of the structure in bytes to allow for future extensibility */
michael@0 278 size_t size;
michael@0 279 /** a pointer to a function to retrieve the hinted
michael@0 280 * advance width of a glyph which the font cannot
michael@0 281 * provide without client assistance. This can be
michael@0 282 * NULL to signify no horizontal hinted metrics are necessary. */
michael@0 283 gr_advance_fn glyph_advance_x;
michael@0 284 /** a pointer to a function to retrieve the hinted
michael@0 285 * advance height of a glyph which the font cannot
michael@0 286 * provide without client assistance. This can be
michael@0 287 * NULL to signify no horizontal hinted metrics are necessary. */
michael@0 288 gr_advance_fn glyph_advance_y;
michael@0 289 };
michael@0 290 typedef struct gr_font_ops gr_font_ops;
michael@0 291
michael@0 292 /** Creates a font with hinted advance width query functions
michael@0 293 *
michael@0 294 * @return gr_font to be destroyed via font_destroy
michael@0 295 * @param ppm size of font in pixels per em
michael@0 296 * @param appFontHandle font specific information that must stay alive as long
michael@0 297 * as the font does
michael@0 298 * @param font_ops pointer font specific callback structure for hinted metrics.
michael@0 299 * Need only stay alive for the duration of the call.
michael@0 300 * @param face the face this font corresponds to. Must stay alive as long as
michael@0 301 * the font does.
michael@0 302 */
michael@0 303 GR2_API gr_font* gr_make_font_with_ops(float ppm, const void* appFontHandle, const gr_font_ops * font_ops, const gr_face *face);
michael@0 304
michael@0 305 /** Creates a font with hinted advance width query function.
michael@0 306 * This function is deprecated. Use gr_make_font_with_ops instead.
michael@0 307 *
michael@0 308 * @return gr_font to be destroyed via font_destroy
michael@0 309 * @param ppm size of font in pixels per em
michael@0 310 * @param appFontHandle font specific information that must stay alive as long
michael@0 311 * as the font does
michael@0 312 * @param getAdvance callback function reference that returns horizontal advance in pixels for a glyph.
michael@0 313 * @param face the face this font corresponds to. Must stay alive as long as
michael@0 314 * the font does.
michael@0 315 */
michael@0 316 GR2_API gr_font* gr_make_font_with_advance_fn(float ppm, const void* appFontHandle, gr_advance_fn getAdvance, const gr_face *face);
michael@0 317
michael@0 318 /** Free a font **/
michael@0 319 GR2_API void gr_font_destroy(gr_font *font);
michael@0 320
michael@0 321 /** get a feature value
michael@0 322 *
michael@0 323 * @return value of specific feature or 0 if any problems.
michael@0 324 * @param pfeatureref gr_feature_ref to the feature
michael@0 325 * @param feats gr_feature_val containing all the values
michael@0 326 */
michael@0 327 GR2_API gr_uint16 gr_fref_feature_value(const gr_feature_ref* pfeatureref, const gr_feature_val* feats);
michael@0 328
michael@0 329 /** set a feature value
michael@0 330 *
michael@0 331 * @return false if there were any problems (value out of range, etc.)
michael@0 332 * @param pfeatureref gr_feature_ref to the feature
michael@0 333 * @param val value to set the feature to
michael@0 334 * @param pDest the gr_feature_val containing all the values for all the features
michael@0 335 */
michael@0 336 GR2_API int gr_fref_set_feature_value(const gr_feature_ref* pfeatureref, gr_uint16 val, gr_feature_val* pDest);
michael@0 337
michael@0 338 /** Returns the id tag for a gr_feature_ref **/
michael@0 339 GR2_API gr_uint32 gr_fref_id(const gr_feature_ref* pfeatureref);
michael@0 340
michael@0 341 /** Returns number of values a feature may take, given a gr_feature_ref **/
michael@0 342 GR2_API gr_uint16 gr_fref_n_values(const gr_feature_ref* pfeatureref);
michael@0 343
michael@0 344 /** Returns the value associated with a particular value in a feature
michael@0 345 *
michael@0 346 * @return value
michael@0 347 * @param pfeatureref gr_feature_ref of the feature of interest
michael@0 348 * @param settingno Index up to the return value of gr_fref_n_values() of the value
michael@0 349 */
michael@0 350 GR2_API gr_int16 gr_fref_value(const gr_feature_ref* pfeatureref, gr_uint16 settingno);
michael@0 351
michael@0 352 /** Returns a string of the UI name of a feature
michael@0 353 *
michael@0 354 * @return string of the UI name, in the encoding form requested. Call gr_label_destroy() after use.
michael@0 355 * @param pfeatureref gr_feature_ref of the feature
michael@0 356 * @param langId This is a pointer since the face may not support a string in the requested
michael@0 357 * language. The actual language of the string is returned in langId
michael@0 358 * @param utf Encoding form for the string
michael@0 359 * @param length Used to return the length of the string returned in bytes.
michael@0 360 */
michael@0 361 GR2_API void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, enum gr_encform utf, gr_uint32 *length);
michael@0 362
michael@0 363 /** Return a UI string for a possible value of a feature
michael@0 364 *
michael@0 365 * @return string of the UI name, in the encoding form requested. nul terminated. Call gr_label_destroy()
michael@0 366 * after use.
michael@0 367 * @param pfeatureref gr_feature_ref of the feature
michael@0 368 * @param settingno Value setting index
michael@0 369 * @param langId This is a pointer to the requested language. The requested language id is
michael@0 370 * replaced by the actual language id of the string returned.
michael@0 371 * @param utf Encoding form for the string
michael@0 372 * @param length Returns the length of the string returned in bytes.
michael@0 373 */
michael@0 374 GR2_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);
michael@0 375
michael@0 376 /** Destroy a previously returned label string **/
michael@0 377 GR2_API void gr_label_destroy(void * label);
michael@0 378
michael@0 379 /** Copies a gr_feature_val **/
michael@0 380 GR2_API gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures);
michael@0 381
michael@0 382 /** Destroys a gr_feature_val **/
michael@0 383 GR2_API void gr_featureval_destroy(gr_feature_val *pfeatures);
michael@0 384
michael@0 385 #ifdef __cplusplus
michael@0 386 }
michael@0 387 #endif
michael@0 388

mercurial