Towards normalization
[framework/uifw/harfbuzz.git] / src / hb-buffer-private.hh
1 /*
2  * Copyright © 1998-2004  David Turner and Werner Lemberg
3  * Copyright © 2004,2007,2009,2010  Red Hat, 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): Owen Taylor, Behdad Esfahbod
26  */
27
28 #ifndef HB_BUFFER_PRIVATE_HH
29 #define HB_BUFFER_PRIVATE_HH
30
31 #include "hb-private.hh"
32 #include "hb-buffer.h"
33 #include "hb-object-private.hh"
34 #include "hb-unicode-private.hh"
35
36 HB_BEGIN_DECLS
37
38
39 ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20);
40 ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t));
41
42 typedef struct _hb_segment_properties_t {
43     hb_direction_t      direction;
44     hb_script_t         script;
45     hb_language_t       language;
46 } hb_segment_properties_t;
47
48
49 HB_INTERNAL void
50 _hb_buffer_swap (hb_buffer_t *buffer);
51
52 HB_INTERNAL void
53 _hb_buffer_clear_output (hb_buffer_t *buffer);
54
55 HB_INTERNAL void
56 _hb_buffer_clear_positions (hb_buffer_t *buffer);
57
58 HB_INTERNAL void
59 _hb_buffer_replace_glyphs_be16 (hb_buffer_t *buffer,
60                                 unsigned int num_in,
61                                 unsigned int num_out,
62                                 const uint16_t *glyph_data_be);
63
64 HB_INTERNAL void
65 _hb_buffer_replace_glyph (hb_buffer_t *buffer,
66                           hb_codepoint_t glyph_index);
67
68 HB_INTERNAL void
69 _hb_buffer_output_glyph (hb_buffer_t *buffer,
70                          hb_codepoint_t glyph_index);
71
72 HB_INTERNAL void
73 _hb_buffer_skip_glyph (hb_buffer_t *buffer);
74
75 HB_INTERNAL void
76 _hb_buffer_next_glyph (hb_buffer_t *buffer);
77
78
79 HB_INTERNAL void
80 _hb_buffer_reset_masks (hb_buffer_t *buffer,
81                         hb_mask_t    mask);
82
83 HB_INTERNAL void
84 _hb_buffer_add_masks (hb_buffer_t *buffer,
85                       hb_mask_t    mask);
86
87 HB_INTERNAL void
88 _hb_buffer_set_masks (hb_buffer_t *buffer,
89                       hb_mask_t    value,
90                       hb_mask_t    mask,
91                       unsigned int cluster_start,
92                       unsigned int cluster_end);
93
94
95 struct _hb_buffer_t {
96   hb_object_header_t header;
97
98   /* Information about how the text in the buffer should be treated */
99
100   hb_unicode_funcs_t *unicode; /* Unicode functions */
101   hb_segment_properties_t props; /* Script, language, direction */
102
103   /* Buffer contents */
104
105   bool in_error; /* Allocation failed */
106   bool have_output; /* Whether we have an output buffer going on */
107   bool have_positions; /* Whether we have positions */
108
109   unsigned int i; /* Cursor into ->info and ->pos arrays */
110   unsigned int len; /* Length of ->info and ->pos arrays */
111   unsigned int out_len; /* Length of ->out array if have_output */
112
113   unsigned int serial;
114
115   unsigned int allocated; /* Length of allocated arrays */
116   hb_glyph_info_t     *info;
117   hb_glyph_info_t     *out_info;
118   hb_glyph_position_t *pos;
119
120
121   /* Methods */
122   inline unsigned int backtrack_len (void) const
123   { return this->have_output? this->out_len : this->i; }
124   inline unsigned int next_serial (void) { return serial++; }
125   inline void swap (void) { _hb_buffer_swap (this); }
126   inline void clear_output (void) { _hb_buffer_clear_output (this); }
127   inline void clear_positions (void) { _hb_buffer_clear_positions (this); }
128   inline void next_glyph (void) { _hb_buffer_next_glyph (this); }
129   inline void replace_glyphs_be16 (unsigned int num_in,
130                                    unsigned int num_out,
131                                    const uint16_t *glyph_data_be)
132   { _hb_buffer_replace_glyphs_be16 (this, num_in, num_out, glyph_data_be); }
133   inline void replace_glyph (hb_codepoint_t glyph_index)
134   { _hb_buffer_replace_glyph (this, glyph_index); }
135   inline void output_glyph (hb_codepoint_t glyph_index)
136   { _hb_buffer_output_glyph (this, glyph_index); }
137   inline void skip_glyph (void) { _hb_buffer_skip_glyph (this); }
138
139   inline void reset_masks (hb_mask_t mask)
140   {
141     for (unsigned int j = 0; j < len; j++)
142       info[j].mask = mask;
143   }
144   inline void add_masks (hb_mask_t mask)
145   {
146     for (unsigned int j = 0; j < len; j++)
147       info[j].mask |= mask;
148   }
149   inline void set_masks (hb_mask_t value,
150                          hb_mask_t mask,
151                          unsigned int cluster_start,
152                          unsigned int cluster_end)
153   { _hb_buffer_set_masks (this, value, mask, cluster_start, cluster_end); }
154 };
155
156
157 HB_END_DECLS
158
159 #endif /* HB_BUFFER_PRIVATE_HH */