michael@0: /* michael@0: * Copyright © 1998-2004 David Turner and Werner Lemberg michael@0: * Copyright © 2004,2007,2009 Red Hat, Inc. michael@0: * Copyright © 2011,2012 Google, Inc. michael@0: * michael@0: * This is part of HarfBuzz, a text shaping library. michael@0: * michael@0: * Permission is hereby granted, without written agreement and without michael@0: * license or royalty fees, to use, copy, modify, and distribute this michael@0: * software and its documentation for any purpose, provided that the michael@0: * above copyright notice and the following two paragraphs appear in michael@0: * all copies of this software. michael@0: * michael@0: * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR michael@0: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES michael@0: * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN michael@0: * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH michael@0: * DAMAGE. michael@0: * michael@0: * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, michael@0: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND michael@0: * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS michael@0: * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO michael@0: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. michael@0: * michael@0: * Red Hat Author(s): Owen Taylor, Behdad Esfahbod michael@0: * Google Author(s): Behdad Esfahbod michael@0: */ michael@0: michael@0: #ifndef HB_H_IN michael@0: #error "Include instead." michael@0: #endif michael@0: michael@0: #ifndef HB_BUFFER_H michael@0: #define HB_BUFFER_H michael@0: michael@0: #include "hb-common.h" michael@0: #include "hb-unicode.h" michael@0: #include "hb-font.h" michael@0: michael@0: HB_BEGIN_DECLS michael@0: michael@0: michael@0: typedef struct hb_glyph_info_t { michael@0: hb_codepoint_t codepoint; michael@0: hb_mask_t mask; michael@0: uint32_t cluster; michael@0: michael@0: /*< private >*/ michael@0: hb_var_int_t var1; michael@0: hb_var_int_t var2; michael@0: } hb_glyph_info_t; michael@0: michael@0: typedef struct hb_glyph_position_t { michael@0: hb_position_t x_advance; michael@0: hb_position_t y_advance; michael@0: hb_position_t x_offset; michael@0: hb_position_t y_offset; michael@0: michael@0: /*< private >*/ michael@0: hb_var_int_t var; michael@0: } hb_glyph_position_t; michael@0: michael@0: michael@0: typedef struct hb_segment_properties_t { michael@0: hb_direction_t direction; michael@0: hb_script_t script; michael@0: hb_language_t language; michael@0: /*< private >*/ michael@0: void *reserved1; michael@0: void *reserved2; michael@0: } hb_segment_properties_t; michael@0: michael@0: #define HB_SEGMENT_PROPERTIES_DEFAULT {HB_DIRECTION_INVALID, \ michael@0: HB_SCRIPT_INVALID, \ michael@0: HB_LANGUAGE_INVALID, \ michael@0: NULL, \ michael@0: NULL} michael@0: michael@0: hb_bool_t michael@0: hb_segment_properties_equal (const hb_segment_properties_t *a, michael@0: const hb_segment_properties_t *b); michael@0: michael@0: unsigned int michael@0: hb_segment_properties_hash (const hb_segment_properties_t *p); michael@0: michael@0: michael@0: michael@0: /* michael@0: * hb_buffer_t michael@0: */ michael@0: michael@0: typedef struct hb_buffer_t hb_buffer_t; michael@0: michael@0: hb_buffer_t * michael@0: hb_buffer_create (void); michael@0: michael@0: hb_buffer_t * michael@0: hb_buffer_get_empty (void); michael@0: michael@0: hb_buffer_t * michael@0: hb_buffer_reference (hb_buffer_t *buffer); michael@0: michael@0: void michael@0: hb_buffer_destroy (hb_buffer_t *buffer); michael@0: michael@0: hb_bool_t michael@0: hb_buffer_set_user_data (hb_buffer_t *buffer, michael@0: hb_user_data_key_t *key, michael@0: void * data, michael@0: hb_destroy_func_t destroy, michael@0: hb_bool_t replace); michael@0: michael@0: void * michael@0: hb_buffer_get_user_data (hb_buffer_t *buffer, michael@0: hb_user_data_key_t *key); michael@0: michael@0: michael@0: typedef enum { michael@0: HB_BUFFER_CONTENT_TYPE_INVALID = 0, michael@0: HB_BUFFER_CONTENT_TYPE_UNICODE, michael@0: HB_BUFFER_CONTENT_TYPE_GLYPHS michael@0: } hb_buffer_content_type_t; michael@0: michael@0: void michael@0: hb_buffer_set_content_type (hb_buffer_t *buffer, michael@0: hb_buffer_content_type_t content_type); michael@0: michael@0: hb_buffer_content_type_t michael@0: hb_buffer_get_content_type (hb_buffer_t *buffer); michael@0: michael@0: michael@0: void michael@0: hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, michael@0: hb_unicode_funcs_t *unicode_funcs); michael@0: michael@0: hb_unicode_funcs_t * michael@0: hb_buffer_get_unicode_funcs (hb_buffer_t *buffer); michael@0: michael@0: void michael@0: hb_buffer_set_direction (hb_buffer_t *buffer, michael@0: hb_direction_t direction); michael@0: michael@0: hb_direction_t michael@0: hb_buffer_get_direction (hb_buffer_t *buffer); michael@0: michael@0: void michael@0: hb_buffer_set_script (hb_buffer_t *buffer, michael@0: hb_script_t script); michael@0: michael@0: hb_script_t michael@0: hb_buffer_get_script (hb_buffer_t *buffer); michael@0: michael@0: void michael@0: hb_buffer_set_language (hb_buffer_t *buffer, michael@0: hb_language_t language); michael@0: michael@0: michael@0: hb_language_t michael@0: hb_buffer_get_language (hb_buffer_t *buffer); michael@0: michael@0: void michael@0: hb_buffer_set_segment_properties (hb_buffer_t *buffer, michael@0: const hb_segment_properties_t *props); michael@0: michael@0: void michael@0: hb_buffer_get_segment_properties (hb_buffer_t *buffer, michael@0: hb_segment_properties_t *props); michael@0: michael@0: void michael@0: hb_buffer_guess_segment_properties (hb_buffer_t *buffer); michael@0: michael@0: michael@0: typedef enum { /*< flags >*/ michael@0: HB_BUFFER_FLAG_DEFAULT = 0x00000000u, michael@0: HB_BUFFER_FLAG_BOT = 0x00000001u, /* Beginning-of-text */ michael@0: HB_BUFFER_FLAG_EOT = 0x00000002u, /* End-of-text */ michael@0: HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES = 0x00000004u michael@0: } hb_buffer_flags_t; michael@0: michael@0: void michael@0: hb_buffer_set_flags (hb_buffer_t *buffer, michael@0: hb_buffer_flags_t flags); michael@0: michael@0: hb_buffer_flags_t michael@0: hb_buffer_get_flags (hb_buffer_t *buffer); michael@0: michael@0: michael@0: /* Resets the buffer. Afterwards it's as if it was just created, michael@0: * except that it has a larger buffer allocated perhaps... */ michael@0: void michael@0: hb_buffer_reset (hb_buffer_t *buffer); michael@0: michael@0: /* Like reset, but does NOT clear unicode_funcs. */ michael@0: void michael@0: hb_buffer_clear_contents (hb_buffer_t *buffer); michael@0: michael@0: /* Returns false if allocation failed */ michael@0: hb_bool_t michael@0: hb_buffer_pre_allocate (hb_buffer_t *buffer, michael@0: unsigned int size); michael@0: michael@0: michael@0: /* Returns false if allocation has failed before */ michael@0: hb_bool_t michael@0: hb_buffer_allocation_successful (hb_buffer_t *buffer); michael@0: michael@0: void michael@0: hb_buffer_reverse (hb_buffer_t *buffer); michael@0: michael@0: void michael@0: hb_buffer_reverse_clusters (hb_buffer_t *buffer); michael@0: michael@0: michael@0: /* Filling the buffer in */ michael@0: michael@0: void michael@0: hb_buffer_add (hb_buffer_t *buffer, michael@0: hb_codepoint_t codepoint, michael@0: unsigned int cluster); michael@0: michael@0: void michael@0: hb_buffer_add_utf8 (hb_buffer_t *buffer, michael@0: const char *text, michael@0: int text_length, michael@0: unsigned int item_offset, michael@0: int item_length); michael@0: michael@0: void michael@0: hb_buffer_add_utf16 (hb_buffer_t *buffer, michael@0: const uint16_t *text, michael@0: int text_length, michael@0: unsigned int item_offset, michael@0: int item_length); michael@0: michael@0: void michael@0: hb_buffer_add_utf32 (hb_buffer_t *buffer, michael@0: const uint32_t *text, michael@0: int text_length, michael@0: unsigned int item_offset, michael@0: int item_length); michael@0: michael@0: michael@0: /* Clears any new items added at the end */ michael@0: hb_bool_t michael@0: hb_buffer_set_length (hb_buffer_t *buffer, michael@0: unsigned int length); michael@0: michael@0: /* Return value valid as long as buffer not modified */ michael@0: unsigned int michael@0: hb_buffer_get_length (hb_buffer_t *buffer); michael@0: michael@0: /* Getting glyphs out of the buffer */ michael@0: michael@0: /* Return value valid as long as buffer not modified */ michael@0: hb_glyph_info_t * michael@0: hb_buffer_get_glyph_infos (hb_buffer_t *buffer, michael@0: unsigned int *length); michael@0: michael@0: /* Return value valid as long as buffer not modified */ michael@0: hb_glyph_position_t * michael@0: hb_buffer_get_glyph_positions (hb_buffer_t *buffer, michael@0: unsigned int *length); michael@0: michael@0: michael@0: /* Reorders a glyph buffer to have canonical in-cluster glyph order / position. michael@0: * The resulting clusters should behave identical to pre-reordering clusters. michael@0: * NOTE: This has nothing to do with Unicode normalization. */ michael@0: void michael@0: hb_buffer_normalize_glyphs (hb_buffer_t *buffer); michael@0: michael@0: michael@0: /* michael@0: * Serialize michael@0: */ michael@0: michael@0: typedef enum { /*< flags >*/ michael@0: HB_BUFFER_SERIALIZE_FLAG_DEFAULT = 0x00000000u, michael@0: HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS = 0x00000001u, michael@0: HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002u, michael@0: HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u michael@0: } hb_buffer_serialize_flags_t; michael@0: michael@0: typedef enum { michael@0: HB_BUFFER_SERIALIZE_FORMAT_TEXT = HB_TAG('T','E','X','T'), michael@0: HB_BUFFER_SERIALIZE_FORMAT_JSON = HB_TAG('J','S','O','N'), michael@0: HB_BUFFER_SERIALIZE_FORMAT_INVALID = HB_TAG_NONE michael@0: } hb_buffer_serialize_format_t; michael@0: michael@0: /* len=-1 means str is NUL-terminated. */ michael@0: hb_buffer_serialize_format_t michael@0: hb_buffer_serialize_format_from_string (const char *str, int len); michael@0: michael@0: const char * michael@0: hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format); michael@0: michael@0: const char ** michael@0: hb_buffer_serialize_list_formats (void); michael@0: michael@0: /* Returns number of items, starting at start, that were serialized. */ michael@0: unsigned int michael@0: hb_buffer_serialize_glyphs (hb_buffer_t *buffer, michael@0: unsigned int start, michael@0: unsigned int end, michael@0: char *buf, michael@0: unsigned int buf_size, michael@0: unsigned int *buf_consumed, /* May be NULL */ michael@0: hb_font_t *font, /* May be NULL */ michael@0: hb_buffer_serialize_format_t format, michael@0: hb_buffer_serialize_flags_t flags); michael@0: michael@0: hb_bool_t michael@0: hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, michael@0: const char *buf, michael@0: int buf_len, /* -1 means nul-terminated */ michael@0: const char **end_ptr, /* May be NULL */ michael@0: hb_font_t *font, /* May be NULL */ michael@0: hb_buffer_serialize_format_t format); michael@0: michael@0: michael@0: HB_END_DECLS michael@0: michael@0: #endif /* HB_BUFFER_H */