Path: blob/master/thirdparty/harfbuzz/src/hb-common.h
9902 views
/*1* Copyright © 2007,2008,2009 Red Hat, Inc.2* Copyright © 2011,2012 Google, Inc.3*4* This is part of HarfBuzz, a text shaping library.5*6* Permission is hereby granted, without written agreement and without7* license or royalty fees, to use, copy, modify, and distribute this8* software and its documentation for any purpose, provided that the9* above copyright notice and the following two paragraphs appear in10* all copies of this software.11*12* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR13* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES14* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN15* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH16* DAMAGE.17*18* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,19* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND20* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS21* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO22* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.23*24* Red Hat Author(s): Behdad Esfahbod25* Google Author(s): Behdad Esfahbod26*/2728#if !defined(HB_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR)29#error "Include <hb.h> instead."30#endif3132#ifndef HB_COMMON_H33#define HB_COMMON_H3435#ifndef HB_EXTERN36#define HB_EXTERN extern37#endif3839#ifndef HB_BEGIN_DECLS40# ifdef __cplusplus41# define HB_BEGIN_DECLS extern "C" {42# define HB_END_DECLS }43# else /* !__cplusplus */44# define HB_BEGIN_DECLS45# define HB_END_DECLS46# endif /* !__cplusplus */47#endif4849#if defined (_AIX)50# include <sys/inttypes.h>51#elif defined (_MSC_VER) && _MSC_VER < 160052/* VS 2010 (_MSC_VER 1600) has stdint.h */53typedef __int8 int8_t;54typedef unsigned __int8 uint8_t;55typedef __int16 int16_t;56typedef unsigned __int16 uint16_t;57typedef __int32 int32_t;58typedef unsigned __int32 uint32_t;59typedef __int64 int64_t;60typedef unsigned __int64 uint64_t;61#elif defined (_MSC_VER) && _MSC_VER < 180062/* VS 2013 (_MSC_VER 1800) has inttypes.h */63# include <stdint.h>64#else65# include <inttypes.h>66#endif67#include <stddef.h>6869#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))70#define HB_DEPRECATED __attribute__((__deprecated__))71#elif defined(_MSC_VER) && (_MSC_VER >= 1300)72#define HB_DEPRECATED __declspec(deprecated)73#else74#define HB_DEPRECATED75#endif7677#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))78#define HB_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))79#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)80#define HB_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))81#else82#define HB_DEPRECATED_FOR(f) HB_DEPRECATED83#endif848586HB_BEGIN_DECLS8788/**89* hb_bool_t:90*91* Data type for booleans.92*93**/94typedef int hb_bool_t;9596/**97* hb_codepoint_t:98*99* Data type for holding Unicode codepoints. Also100* used to hold glyph IDs.101*102**/103typedef uint32_t hb_codepoint_t;104105/**106* HB_CODEPOINT_INVALID:107*108* Unused #hb_codepoint_t value.109*110* Since: 8.0.0111*/112#define HB_CODEPOINT_INVALID ((hb_codepoint_t) -1)113114/**115* hb_position_t:116*117* Data type for holding a single coordinate value.118* Contour points and other multi-dimensional data are119* stored as tuples of #hb_position_t's.120*121**/122typedef int32_t hb_position_t;123/**124* hb_mask_t:125*126* Data type for bitmasks.127*128**/129typedef uint32_t hb_mask_t;130131typedef union _hb_var_int_t {132uint32_t u32;133int32_t i32;134uint16_t u16[2];135int16_t i16[2];136uint8_t u8[4];137int8_t i8[4];138} hb_var_int_t;139140typedef union _hb_var_num_t {141float f;142uint32_t u32;143int32_t i32;144uint16_t u16[2];145int16_t i16[2];146uint8_t u8[4];147int8_t i8[4];148} hb_var_num_t;149150151/* hb_tag_t */152153/**154* hb_tag_t:155*156* Data type for tag identifiers. Tags are four157* byte integers, each byte representing a character.158*159* Tags are used to identify tables, design-variation axes,160* scripts, languages, font features, and baselines with161* human-readable names.162*163**/164typedef uint32_t hb_tag_t;165166/**167* HB_TAG:168* @c1: 1st character of the tag169* @c2: 2nd character of the tag170* @c3: 3rd character of the tag171* @c4: 4th character of the tag172*173* Constructs an #hb_tag_t from four character literals.174*175**/176#define HB_TAG(c1,c2,c3,c4) ((hb_tag_t)((((uint32_t)(c1)&0xFF)<<24)|(((uint32_t)(c2)&0xFF)<<16)|(((uint32_t)(c3)&0xFF)<<8)|((uint32_t)(c4)&0xFF)))177178/**179* HB_UNTAG:180* @tag: an #hb_tag_t181*182* Extracts four character literals from an #hb_tag_t.183*184* Since: 0.6.0185*186**/187#define HB_UNTAG(tag) (uint8_t)(((tag)>>24)&0xFF), (uint8_t)(((tag)>>16)&0xFF), (uint8_t)(((tag)>>8)&0xFF), (uint8_t)((tag)&0xFF)188189/**190* HB_TAG_NONE:191*192* Unset #hb_tag_t.193*/194#define HB_TAG_NONE HB_TAG(0,0,0,0)195/**196* HB_TAG_MAX:197*198* Maximum possible unsigned #hb_tag_t.199*200* Since: 0.9.26201*/202#define HB_TAG_MAX HB_TAG(0xff,0xff,0xff,0xff)203/**204* HB_TAG_MAX_SIGNED:205*206* Maximum possible signed #hb_tag_t.207*208* Since: 0.9.33209*/210#define HB_TAG_MAX_SIGNED HB_TAG(0x7f,0xff,0xff,0xff)211212/* len=-1 means str is NUL-terminated. */213HB_EXTERN hb_tag_t214hb_tag_from_string (const char *str, int len);215216/* buf should have 4 bytes. */217HB_EXTERN void218hb_tag_to_string (hb_tag_t tag, char *buf);219220221/**222* hb_direction_t:223* @HB_DIRECTION_INVALID: Initial, unset direction.224* @HB_DIRECTION_LTR: Text is set horizontally from left to right.225* @HB_DIRECTION_RTL: Text is set horizontally from right to left.226* @HB_DIRECTION_TTB: Text is set vertically from top to bottom.227* @HB_DIRECTION_BTT: Text is set vertically from bottom to top.228*229* The direction of a text segment or buffer.230*231* A segment can also be tested for horizontal or vertical232* orientation (irrespective of specific direction) with233* HB_DIRECTION_IS_HORIZONTAL() or HB_DIRECTION_IS_VERTICAL().234*235*/236typedef enum {237HB_DIRECTION_INVALID = 0,238HB_DIRECTION_LTR = 4,239HB_DIRECTION_RTL,240HB_DIRECTION_TTB,241HB_DIRECTION_BTT242} hb_direction_t;243244/* len=-1 means str is NUL-terminated */245HB_EXTERN hb_direction_t246hb_direction_from_string (const char *str, int len);247248HB_EXTERN const char *249hb_direction_to_string (hb_direction_t direction);250251/**252* HB_DIRECTION_IS_VALID:253* @dir: #hb_direction_t to test254*255* Tests whether a text direction is valid.256*257**/258#define HB_DIRECTION_IS_VALID(dir) ((((unsigned int) (dir)) & ~3U) == 4)259/* Direction must be valid for the following */260/**261* HB_DIRECTION_IS_HORIZONTAL:262* @dir: #hb_direction_t to test263*264* Tests whether a text direction is horizontal. Requires265* that the direction be valid.266*267**/268#define HB_DIRECTION_IS_HORIZONTAL(dir) ((((unsigned int) (dir)) & ~1U) == 4)269/**270* HB_DIRECTION_IS_VERTICAL:271* @dir: #hb_direction_t to test272*273* Tests whether a text direction is vertical. Requires274* that the direction be valid.275*276**/277#define HB_DIRECTION_IS_VERTICAL(dir) ((((unsigned int) (dir)) & ~1U) == 6)278/**279* HB_DIRECTION_IS_FORWARD:280* @dir: #hb_direction_t to test281*282* Tests whether a text direction moves forward (from left to right, or from283* top to bottom). Requires that the direction be valid.284*285**/286#define HB_DIRECTION_IS_FORWARD(dir) ((((unsigned int) (dir)) & ~2U) == 4)287/**288* HB_DIRECTION_IS_BACKWARD:289* @dir: #hb_direction_t to test290*291* Tests whether a text direction moves backward (from right to left, or from292* bottom to top). Requires that the direction be valid.293*294**/295#define HB_DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 5)296/**297* HB_DIRECTION_REVERSE:298* @dir: #hb_direction_t to reverse299*300* Reverses a text direction. Requires that the direction301* be valid.302*303**/304#define HB_DIRECTION_REVERSE(dir) ((hb_direction_t) (((unsigned int) (dir)) ^ 1))305306307/* hb_language_t */308309/**310* hb_language_t:311*312* Data type for languages. Each #hb_language_t corresponds to a BCP 47313* language tag.314*315*/316typedef const struct hb_language_impl_t *hb_language_t;317318HB_EXTERN hb_language_t319hb_language_from_string (const char *str, int len);320321HB_EXTERN const char *322hb_language_to_string (hb_language_t language);323324/**325* HB_LANGUAGE_INVALID:326*327* An unset #hb_language_t.328*329* Since: 0.6.0330*/331#define HB_LANGUAGE_INVALID ((hb_language_t) 0)332333HB_EXTERN hb_language_t334hb_language_get_default (void);335336HB_EXTERN hb_bool_t337hb_language_matches (hb_language_t language,338hb_language_t specific);339340#include "hb-script-list.h"341342/* Script functions */343344HB_EXTERN hb_script_t345hb_script_from_iso15924_tag (hb_tag_t tag);346347HB_EXTERN hb_script_t348hb_script_from_string (const char *str, int len);349350HB_EXTERN hb_tag_t351hb_script_to_iso15924_tag (hb_script_t script);352353HB_EXTERN hb_direction_t354hb_script_get_horizontal_direction (hb_script_t script);355356357/* User data */358359/**360* hb_user_data_key_t:361*362* Data structure for holding user-data keys.363*364**/365typedef struct hb_user_data_key_t {366/*< private >*/367char unused;368} hb_user_data_key_t;369370/**371* hb_destroy_func_t:372* @user_data: the data to be destroyed373*374* A virtual method for destroy user-data callbacks.375*376*/377typedef void (*hb_destroy_func_t) (void *user_data);378379380/* Font features and variations. */381382/**383* HB_FEATURE_GLOBAL_START:384*385* Special setting for #hb_feature_t.start to apply the feature from the start386* of the buffer.387*388* Since: 2.0.0389*/390#define HB_FEATURE_GLOBAL_START 0391392/**393* HB_FEATURE_GLOBAL_END:394*395* Special setting for #hb_feature_t.end to apply the feature from to the end396* of the buffer.397*398* Since: 2.0.0399*/400#define HB_FEATURE_GLOBAL_END ((unsigned int) -1)401402/**403* hb_feature_t:404* @tag: The #hb_tag_t tag of the feature405* @value: The value of the feature. 0 disables the feature, non-zero (usually406* 1) enables the feature. For features implemented as lookup type 3 (like407* 'salt') the @value is a one based index into the alternates.408* @start: the cluster to start applying this feature setting (inclusive).409* @end: the cluster to end applying this feature setting (exclusive).410*411* The #hb_feature_t is the structure that holds information about requested412* feature application. The feature will be applied with the given value to all413* glyphs which are in clusters between @start (inclusive) and @end (exclusive).414* Setting start to #HB_FEATURE_GLOBAL_START and end to #HB_FEATURE_GLOBAL_END415* specifies that the feature always applies to the entire buffer.416*/417typedef struct hb_feature_t {418hb_tag_t tag;419uint32_t value;420unsigned int start;421unsigned int end;422} hb_feature_t;423424HB_EXTERN hb_bool_t425hb_feature_from_string (const char *str, int len,426hb_feature_t *feature);427428HB_EXTERN void429hb_feature_to_string (hb_feature_t *feature,430char *buf, unsigned int size);431432/**433* hb_variation_t:434* @tag: The #hb_tag_t tag of the variation-axis name435* @value: The value of the variation axis436*437* Data type for holding variation data. Registered OpenType438* variation-axis tags are listed in439* [OpenType Axis Tag Registry](https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxisreg).440*441* Since: 1.4.2442*/443typedef struct hb_variation_t {444hb_tag_t tag;445float value;446} hb_variation_t;447448HB_EXTERN hb_bool_t449hb_variation_from_string (const char *str, int len,450hb_variation_t *variation);451452HB_EXTERN void453hb_variation_to_string (hb_variation_t *variation,454char *buf, unsigned int size);455456/**457* hb_color_t:458*459* Data type for holding color values. Colors are eight bits per460* channel RGB plus alpha transparency.461*462* Since: 2.1.0463*/464typedef uint32_t hb_color_t;465466/**467* HB_COLOR:468* @b: blue channel value469* @g: green channel value470* @r: red channel value471* @a: alpha channel value472*473* Constructs an #hb_color_t from four integers.474*475* Since: 2.1.0476*/477#define HB_COLOR(b,g,r,a) ((hb_color_t) HB_TAG ((b),(g),(r),(a)))478479HB_EXTERN uint8_t480hb_color_get_alpha (hb_color_t color);481#define hb_color_get_alpha(color) ((color) & 0xFF)482483HB_EXTERN uint8_t484hb_color_get_red (hb_color_t color);485#define hb_color_get_red(color) (((color) >> 8) & 0xFF)486487HB_EXTERN uint8_t488hb_color_get_green (hb_color_t color);489#define hb_color_get_green(color) (((color) >> 16) & 0xFF)490491HB_EXTERN uint8_t492hb_color_get_blue (hb_color_t color);493#define hb_color_get_blue(color) (((color) >> 24) & 0xFF)494495/**496* hb_glyph_extents_t:497* @x_bearing: Distance from the x-origin to the left extremum of the glyph.498* @y_bearing: Distance from the top extremum of the glyph to the y-origin.499* @width: Distance from the left extremum of the glyph to the right extremum.500* @height: Distance from the top extremum of the glyph to the bottom extremum.501*502* Glyph extent values, measured in font units.503*504* Note that @height is negative, in coordinate systems that grow up.505**/506typedef struct hb_glyph_extents_t {507hb_position_t x_bearing;508hb_position_t y_bearing;509hb_position_t width;510hb_position_t height;511} hb_glyph_extents_t;512513/**514* hb_font_t:515*516* Data type for holding fonts.517*518*/519typedef struct hb_font_t hb_font_t;520521/* Not of much use to clients. */522HB_EXTERN void*523hb_malloc (size_t size);524HB_EXTERN void*525hb_calloc (size_t nmemb, size_t size);526HB_EXTERN void*527hb_realloc (void *ptr, size_t size);528HB_EXTERN void529hb_free (void *ptr);530531HB_END_DECLS532533#endif /* HB_COMMON_H */534535536