harfbuzz/src/hb-buffer.h

287 lines
7.3 KiB
C
Raw Normal View History

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