hb-common.h (13195B)
1 /* 2 * Copyright © 2007,2008,2009 Red Hat, Inc. 3 * Copyright © 2011,2012 Google, Inc. 4 * 5 * This is part of HarfBuzz, a text shaping library. 6 * 7 * Permission is hereby granted, without written agreement and without 8 * license or royalty fees, to use, copy, modify, and distribute this 9 * software and its documentation for any purpose, provided that the 10 * above copyright notice and the following two paragraphs appear in 11 * all copies of this software. 12 * 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 * DAMAGE. 18 * 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24 * 25 * Red Hat Author(s): Behdad Esfahbod 26 * Google Author(s): Behdad Esfahbod 27 */ 28 29 #if !defined(HB_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR) 30 #error "Include <hb.h> instead." 31 #endif 32 33 #ifndef HB_COMMON_H 34 #define HB_COMMON_H 35 36 #ifndef HB_EXTERN 37 #define HB_EXTERN extern 38 #endif 39 40 #ifndef HB_BEGIN_DECLS 41 # ifdef __cplusplus 42 # define HB_BEGIN_DECLS extern "C" { 43 # define HB_END_DECLS } 44 # else /* !__cplusplus */ 45 # define HB_BEGIN_DECLS 46 # define HB_END_DECLS 47 # endif /* !__cplusplus */ 48 #endif 49 50 #if defined (_AIX) 51 # include <sys/inttypes.h> 52 #elif defined (_MSC_VER) && _MSC_VER < 1600 53 /* VS 2010 (_MSC_VER 1600) has stdint.h */ 54 typedef __int8 int8_t; 55 typedef unsigned __int8 uint8_t; 56 typedef __int16 int16_t; 57 typedef unsigned __int16 uint16_t; 58 typedef __int32 int32_t; 59 typedef unsigned __int32 uint32_t; 60 typedef __int64 int64_t; 61 typedef unsigned __int64 uint64_t; 62 #elif defined (_MSC_VER) && _MSC_VER < 1800 63 /* VS 2013 (_MSC_VER 1800) has inttypes.h */ 64 # include <stdint.h> 65 #else 66 # include <inttypes.h> 67 #endif 68 #include <stddef.h> 69 70 #if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 71 #define HB_DEPRECATED __attribute__((__deprecated__)) 72 #elif defined(_MSC_VER) && (_MSC_VER >= 1300) 73 #define HB_DEPRECATED __declspec(deprecated) 74 #else 75 #define HB_DEPRECATED 76 #endif 77 78 #if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) 79 #define HB_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead"))) 80 #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) 81 #define HB_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead")) 82 #else 83 #define HB_DEPRECATED_FOR(f) HB_DEPRECATED 84 #endif 85 86 87 HB_BEGIN_DECLS 88 89 /** 90 * hb_bool_t: 91 * 92 * Data type for booleans. 93 * 94 **/ 95 typedef int hb_bool_t; 96 97 /** 98 * hb_codepoint_t: 99 * 100 * Data type for holding Unicode codepoints. Also 101 * used to hold glyph IDs. 102 * 103 **/ 104 typedef uint32_t hb_codepoint_t; 105 106 /** 107 * HB_CODEPOINT_INVALID: 108 * 109 * Unused #hb_codepoint_t value. 110 * 111 * Since: 8.0.0 112 */ 113 #define HB_CODEPOINT_INVALID ((hb_codepoint_t) -1) 114 115 /** 116 * hb_position_t: 117 * 118 * Data type for holding a single coordinate value. 119 * Contour points and other multi-dimensional data are 120 * stored as tuples of #hb_position_t's. 121 * 122 **/ 123 typedef int32_t hb_position_t; 124 /** 125 * hb_mask_t: 126 * 127 * Data type for bitmasks. 128 * 129 **/ 130 typedef uint32_t hb_mask_t; 131 132 typedef union _hb_var_int_t { 133 uint32_t u32; 134 int32_t i32; 135 uint16_t u16[2]; 136 int16_t i16[2]; 137 uint8_t u8[4]; 138 int8_t i8[4]; 139 } hb_var_int_t; 140 141 typedef union _hb_var_num_t { 142 float f; 143 uint32_t u32; 144 int32_t i32; 145 uint16_t u16[2]; 146 int16_t i16[2]; 147 uint8_t u8[4]; 148 int8_t i8[4]; 149 } hb_var_num_t; 150 151 152 /* hb_tag_t */ 153 154 /** 155 * hb_tag_t: 156 * 157 * Data type for tag identifiers. Tags are four 158 * byte integers, each byte representing a character. 159 * 160 * Tags are used to identify tables, design-variation axes, 161 * scripts, languages, font features, and baselines with 162 * human-readable names. 163 * 164 **/ 165 typedef uint32_t hb_tag_t; 166 167 /** 168 * HB_TAG: 169 * @c1: 1st character of the tag 170 * @c2: 2nd character of the tag 171 * @c3: 3rd character of the tag 172 * @c4: 4th character of the tag 173 * 174 * Constructs an #hb_tag_t from four character literals. 175 * 176 **/ 177 #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))) 178 179 /** 180 * HB_UNTAG: 181 * @tag: an #hb_tag_t 182 * 183 * Extracts four character literals from an #hb_tag_t. 184 * 185 * Since: 0.6.0 186 * 187 **/ 188 #define HB_UNTAG(tag) (uint8_t)(((tag)>>24)&0xFF), (uint8_t)(((tag)>>16)&0xFF), (uint8_t)(((tag)>>8)&0xFF), (uint8_t)((tag)&0xFF) 189 190 /** 191 * HB_TAG_NONE: 192 * 193 * Unset #hb_tag_t. 194 */ 195 #define HB_TAG_NONE HB_TAG(0,0,0,0) 196 /** 197 * HB_TAG_MAX: 198 * 199 * Maximum possible unsigned #hb_tag_t. 200 * 201 * Since: 0.9.26 202 */ 203 #define HB_TAG_MAX HB_TAG(0xff,0xff,0xff,0xff) 204 /** 205 * HB_TAG_MAX_SIGNED: 206 * 207 * Maximum possible signed #hb_tag_t. 208 * 209 * Since: 0.9.33 210 */ 211 #define HB_TAG_MAX_SIGNED HB_TAG(0x7f,0xff,0xff,0xff) 212 213 /* len=-1 means str is NUL-terminated. */ 214 HB_EXTERN hb_tag_t 215 hb_tag_from_string (const char *str, int len); 216 217 /* buf should have 4 bytes. */ 218 HB_EXTERN void 219 hb_tag_to_string (hb_tag_t tag, char *buf); 220 221 222 /** 223 * hb_direction_t: 224 * @HB_DIRECTION_INVALID: Initial, unset direction. 225 * @HB_DIRECTION_LTR: Text is set horizontally from left to right. 226 * @HB_DIRECTION_RTL: Text is set horizontally from right to left. 227 * @HB_DIRECTION_TTB: Text is set vertically from top to bottom. 228 * @HB_DIRECTION_BTT: Text is set vertically from bottom to top. 229 * 230 * The direction of a text segment or buffer. 231 * 232 * A segment can also be tested for horizontal or vertical 233 * orientation (irrespective of specific direction) with 234 * HB_DIRECTION_IS_HORIZONTAL() or HB_DIRECTION_IS_VERTICAL(). 235 * 236 */ 237 typedef enum { 238 HB_DIRECTION_INVALID = 0, 239 HB_DIRECTION_LTR = 4, 240 HB_DIRECTION_RTL, 241 HB_DIRECTION_TTB, 242 HB_DIRECTION_BTT 243 } hb_direction_t; 244 245 /* len=-1 means str is NUL-terminated */ 246 HB_EXTERN hb_direction_t 247 hb_direction_from_string (const char *str, int len); 248 249 HB_EXTERN const char * 250 hb_direction_to_string (hb_direction_t direction); 251 252 /** 253 * HB_DIRECTION_IS_VALID: 254 * @dir: #hb_direction_t to test 255 * 256 * Tests whether a text direction is valid. 257 * 258 **/ 259 #define HB_DIRECTION_IS_VALID(dir) ((((unsigned int) (dir)) & ~3U) == 4) 260 /* Direction must be valid for the following */ 261 /** 262 * HB_DIRECTION_IS_HORIZONTAL: 263 * @dir: #hb_direction_t to test 264 * 265 * Tests whether a text direction is horizontal. Requires 266 * that the direction be valid. 267 * 268 **/ 269 #define HB_DIRECTION_IS_HORIZONTAL(dir) ((((unsigned int) (dir)) & ~1U) == 4) 270 /** 271 * HB_DIRECTION_IS_VERTICAL: 272 * @dir: #hb_direction_t to test 273 * 274 * Tests whether a text direction is vertical. Requires 275 * that the direction be valid. 276 * 277 **/ 278 #define HB_DIRECTION_IS_VERTICAL(dir) ((((unsigned int) (dir)) & ~1U) == 6) 279 /** 280 * HB_DIRECTION_IS_FORWARD: 281 * @dir: #hb_direction_t to test 282 * 283 * Tests whether a text direction moves forward (from left to right, or from 284 * top to bottom). Requires that the direction be valid. 285 * 286 **/ 287 #define HB_DIRECTION_IS_FORWARD(dir) ((((unsigned int) (dir)) & ~2U) == 4) 288 /** 289 * HB_DIRECTION_IS_BACKWARD: 290 * @dir: #hb_direction_t to test 291 * 292 * Tests whether a text direction moves backward (from right to left, or from 293 * bottom to top). Requires that the direction be valid. 294 * 295 **/ 296 #define HB_DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 5) 297 /** 298 * HB_DIRECTION_REVERSE: 299 * @dir: #hb_direction_t to reverse 300 * 301 * Reverses a text direction. Requires that the direction 302 * be valid. 303 * 304 **/ 305 #define HB_DIRECTION_REVERSE(dir) ((hb_direction_t) (((unsigned int) (dir)) ^ 1)) 306 307 308 /* hb_language_t */ 309 310 /** 311 * hb_language_t: 312 * 313 * Data type for languages. Each #hb_language_t corresponds to a BCP 47 314 * language tag. 315 * 316 */ 317 typedef const struct hb_language_impl_t *hb_language_t; 318 319 HB_EXTERN hb_language_t 320 hb_language_from_string (const char *str, int len); 321 322 HB_EXTERN const char * 323 hb_language_to_string (hb_language_t language); 324 325 /** 326 * HB_LANGUAGE_INVALID: 327 * 328 * An unset #hb_language_t. 329 * 330 * Since: 0.6.0 331 */ 332 #define HB_LANGUAGE_INVALID ((hb_language_t) 0) 333 334 HB_EXTERN hb_language_t 335 hb_language_get_default (void); 336 337 HB_EXTERN hb_bool_t 338 hb_language_matches (hb_language_t language, 339 hb_language_t specific); 340 341 #include "hb-script-list.h" 342 343 /* Script functions */ 344 345 HB_EXTERN hb_script_t 346 hb_script_from_iso15924_tag (hb_tag_t tag); 347 348 HB_EXTERN hb_script_t 349 hb_script_from_string (const char *str, int len); 350 351 HB_EXTERN hb_tag_t 352 hb_script_to_iso15924_tag (hb_script_t script); 353 354 HB_EXTERN hb_direction_t 355 hb_script_get_horizontal_direction (hb_script_t script); 356 357 358 /* User data */ 359 360 /** 361 * hb_user_data_key_t: 362 * 363 * Data structure for holding user-data keys. 364 * 365 **/ 366 typedef struct hb_user_data_key_t { 367 /*< private >*/ 368 char unused; 369 } hb_user_data_key_t; 370 371 /** 372 * hb_destroy_func_t: 373 * @user_data: the data to be destroyed 374 * 375 * A virtual method for destroy user-data callbacks. 376 * 377 */ 378 typedef void (*hb_destroy_func_t) (void *user_data); 379 380 381 /* Font features and variations. */ 382 383 /** 384 * HB_FEATURE_GLOBAL_START: 385 * 386 * Special setting for #hb_feature_t.start to apply the feature from the start 387 * of the buffer. 388 * 389 * Since: 2.0.0 390 */ 391 #define HB_FEATURE_GLOBAL_START 0 392 393 /** 394 * HB_FEATURE_GLOBAL_END: 395 * 396 * Special setting for #hb_feature_t.end to apply the feature from to the end 397 * of the buffer. 398 * 399 * Since: 2.0.0 400 */ 401 #define HB_FEATURE_GLOBAL_END ((unsigned int) -1) 402 403 /** 404 * hb_feature_t: 405 * @tag: The #hb_tag_t tag of the feature 406 * @value: The value of the feature. 0 disables the feature, non-zero (usually 407 * 1) enables the feature. For features implemented as lookup type 3 (like 408 * 'salt') the @value is a one based index into the alternates. 409 * @start: the cluster to start applying this feature setting (inclusive). 410 * @end: the cluster to end applying this feature setting (exclusive). 411 * 412 * The #hb_feature_t is the structure that holds information about requested 413 * feature application. The feature will be applied with the given value to all 414 * glyphs which are in clusters between @start (inclusive) and @end (exclusive). 415 * Setting start to #HB_FEATURE_GLOBAL_START and end to #HB_FEATURE_GLOBAL_END 416 * specifies that the feature always applies to the entire buffer. 417 */ 418 typedef struct hb_feature_t { 419 hb_tag_t tag; 420 uint32_t value; 421 unsigned int start; 422 unsigned int end; 423 } hb_feature_t; 424 425 HB_EXTERN hb_bool_t 426 hb_feature_from_string (const char *str, int len, 427 hb_feature_t *feature); 428 429 HB_EXTERN void 430 hb_feature_to_string (hb_feature_t *feature, 431 char *buf, unsigned int size); 432 433 /** 434 * hb_variation_t: 435 * @tag: The #hb_tag_t tag of the variation-axis name 436 * @value: The value of the variation axis 437 * 438 * Data type for holding variation data. Registered OpenType 439 * variation-axis tags are listed in 440 * [OpenType Axis Tag Registry](https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxisreg). 441 * 442 * Since: 1.4.2 443 */ 444 typedef struct hb_variation_t { 445 hb_tag_t tag; 446 float value; 447 } hb_variation_t; 448 449 HB_EXTERN hb_bool_t 450 hb_variation_from_string (const char *str, int len, 451 hb_variation_t *variation); 452 453 HB_EXTERN void 454 hb_variation_to_string (hb_variation_t *variation, 455 char *buf, unsigned int size); 456 457 /** 458 * hb_color_t: 459 * 460 * Data type for holding color values. Colors are eight bits per 461 * channel RGB plus alpha transparency. 462 * 463 * Since: 2.1.0 464 */ 465 typedef uint32_t hb_color_t; 466 467 /** 468 * HB_COLOR: 469 * @b: blue channel value 470 * @g: green channel value 471 * @r: red channel value 472 * @a: alpha channel value 473 * 474 * Constructs an #hb_color_t from four integers. 475 * 476 * Since: 2.1.0 477 */ 478 #define HB_COLOR(b,g,r,a) ((hb_color_t) HB_TAG ((b),(g),(r),(a))) 479 480 HB_EXTERN uint8_t 481 hb_color_get_alpha (hb_color_t color); 482 #define hb_color_get_alpha(color) ((color) & 0xFF) 483 484 HB_EXTERN uint8_t 485 hb_color_get_red (hb_color_t color); 486 #define hb_color_get_red(color) (((color) >> 8) & 0xFF) 487 488 HB_EXTERN uint8_t 489 hb_color_get_green (hb_color_t color); 490 #define hb_color_get_green(color) (((color) >> 16) & 0xFF) 491 492 HB_EXTERN uint8_t 493 hb_color_get_blue (hb_color_t color); 494 #define hb_color_get_blue(color) (((color) >> 24) & 0xFF) 495 496 /** 497 * hb_glyph_extents_t: 498 * @x_bearing: Distance from the x-origin to the left extremum of the glyph. 499 * @y_bearing: Distance from the top extremum of the glyph to the y-origin. 500 * @width: Distance from the left extremum of the glyph to the right extremum. 501 * @height: Distance from the top extremum of the glyph to the bottom extremum. 502 * 503 * Glyph extent values, measured in font units. 504 * 505 * Note that @height is negative, in coordinate systems that grow up. 506 **/ 507 typedef struct hb_glyph_extents_t { 508 hb_position_t x_bearing; 509 hb_position_t y_bearing; 510 hb_position_t width; 511 hb_position_t height; 512 } hb_glyph_extents_t; 513 514 /** 515 * hb_font_t: 516 * 517 * Data type for holding fonts. 518 * 519 */ 520 typedef struct hb_font_t hb_font_t; 521 522 /* Not of much use to clients. */ 523 HB_EXTERN void* 524 hb_malloc (size_t size); 525 HB_EXTERN void* 526 hb_calloc (size_t nmemb, size_t size); 527 HB_EXTERN void* 528 hb_realloc (void *ptr, size_t size); 529 HB_EXTERN void 530 hb_free (void *ptr); 531 532 HB_END_DECLS 533 534 #endif /* HB_COMMON_H */