hb-buffer-private.hh revision 468e9cb25c9bc14781b7013e447d763f93bf76a3
1/*
2 * Copyright © 1998-2004  David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009,2010  Red Hat, Inc.
4 * Copyright © 2011  Google, Inc.
5 *
6 *  This is part of HarfBuzz, a text shaping library.
7 *
8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software.
13 *
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE.
19 *
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 *
26 * Red Hat Author(s): Owen Taylor, Behdad Esfahbod
27 * Google Author(s): Behdad Esfahbod
28 */
29
30#ifndef HB_BUFFER_PRIVATE_HH
31#define HB_BUFFER_PRIVATE_HH
32
33#include "hb-private.hh"
34#include "hb-buffer.h"
35#include "hb-object-private.hh"
36#include "hb-unicode-private.hh"
37
38HB_BEGIN_DECLS
39
40
41ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20);
42ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t));
43
44typedef struct _hb_segment_properties_t {
45    hb_direction_t      direction;
46    hb_script_t         script;
47    hb_language_t       language;
48} hb_segment_properties_t;
49
50
51struct _hb_buffer_t {
52  hb_object_header_t header;
53
54  /* Information about how the text in the buffer should be treated */
55
56  hb_unicode_funcs_t *unicode; /* Unicode functions */
57  hb_segment_properties_t props; /* Script, language, direction */
58
59  /* Buffer contents */
60
61  bool in_error; /* Allocation failed */
62  bool have_output; /* Whether we have an output buffer going on */
63  bool have_positions; /* Whether we have positions */
64
65  unsigned int idx; /* Cursor into ->info and ->pos arrays */
66  unsigned int len; /* Length of ->info and ->pos arrays */
67  unsigned int out_len; /* Length of ->out array if have_output */
68
69  unsigned int serial;
70
71  unsigned int allocated; /* Length of allocated arrays */
72  hb_glyph_info_t     *info;
73  hb_glyph_info_t     *out_info;
74  hb_glyph_position_t *pos;
75
76
77  /* Methods */
78
79  HB_INTERNAL void reset (void);
80
81  inline unsigned int backtrack_len (void) const
82  { return have_output? out_len : idx; }
83  inline unsigned int next_serial (void) { return serial++; }
84
85  HB_INTERNAL void add (hb_codepoint_t  codepoint,
86			hb_mask_t       mask,
87			unsigned int    cluster);
88
89  HB_INTERNAL void reverse_range (unsigned int start, unsigned int end);
90  HB_INTERNAL void reverse (void);
91  HB_INTERNAL void reverse_clusters (void);
92
93  HB_INTERNAL void swap_buffers (void);
94  HB_INTERNAL void clear_output (void);
95  HB_INTERNAL void clear_positions (void);
96  HB_INTERNAL void replace_glyphs_be16 (unsigned int num_in,
97					unsigned int num_out,
98					const uint16_t *glyph_data_be);
99  HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index);
100  /* Makes a copy of the glyph at idx to output and replace glyph_index */
101  HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index);
102  /* Copies glyph at idx to output but doesn't advance idx */
103  HB_INTERNAL void copy_glyph (void);
104  /* Copies glyph at idx to output and advance idx.
105   * If there's no output, just advance idx. */
106  HB_INTERNAL void next_glyph (void);
107  /* Advance idx without copying to output. */
108  inline void skip_glyph (void) { idx++; }
109
110  inline void reset_masks (hb_mask_t mask)
111  {
112    for (unsigned int j = 0; j < len; j++)
113      info[j].mask = mask;
114  }
115  inline void add_masks (hb_mask_t mask)
116  {
117    for (unsigned int j = 0; j < len; j++)
118      info[j].mask |= mask;
119  }
120  HB_INTERNAL void set_masks (hb_mask_t value,
121			      hb_mask_t mask,
122			      unsigned int cluster_start,
123			      unsigned int cluster_end);
124
125  /* Internal methods */
126  HB_INTERNAL bool enlarge (unsigned int size);
127
128  inline bool ensure (unsigned int size)
129  { return likely (size <= allocated) ? TRUE : enlarge (size); }
130
131  HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out);
132};
133
134
135HB_END_DECLS
136
137#endif /* HB_BUFFER_PRIVATE_HH */
138