2 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009,2010 Red Hat, Inc.
4 * Copyright © 2011 Google, Inc.
6 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
26 * Red Hat Author(s): Owen Taylor, Behdad Esfahbod
27 * Google Author(s): Behdad Esfahbod
30 #ifndef HB_BUFFER_PRIVATE_HH
31 #define HB_BUFFER_PRIVATE_HH
33 #include "hb-private.hh"
34 #include "hb-buffer.h"
35 #include "hb-object-private.hh"
36 #include "hb-unicode-private.hh"
40 ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20);
41 ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t));
45 * hb_segment_properties_t
48 typedef struct hb_segment_properties_t {
49 hb_direction_t direction;
51 hb_language_t language;
53 } hb_segment_properties_t;
55 #define _HB_BUFFER_PROPS_DEFAULT { HB_DIRECTION_INVALID, HB_SCRIPT_INVALID, HB_LANGUAGE_INVALID }
57 static inline hb_bool_t
58 hb_segment_properties_equal (const hb_segment_properties_t *a,
59 const hb_segment_properties_t *b)
61 return a->direction == b->direction &&
62 a->script == b->script &&
63 a->language == b->language;
68 static inline unsigned int
69 hb_segment_properties_hash (const hb_segment_properties_t *p)
72 return (unsigned int) p->direction +
73 (unsigned int) p->script +
74 (intptr_t) (p->language);
85 hb_object_header_t header;
88 /* Information about how the text in the buffer should be treated */
90 hb_unicode_funcs_t *unicode; /* Unicode functions */
91 hb_segment_properties_t props; /* Script, language, direction */
95 bool in_error; /* Allocation failed */
96 bool have_output; /* Whether we have an output buffer going on */
97 bool have_positions; /* Whether we have positions */
99 unsigned int idx; /* Cursor into ->info and ->pos arrays */
100 unsigned int len; /* Length of ->info and ->pos arrays */
101 unsigned int out_len; /* Length of ->out array if have_output */
103 unsigned int allocated; /* Length of allocated arrays */
104 hb_glyph_info_t *info;
105 hb_glyph_info_t *out_info;
106 hb_glyph_position_t *pos;
108 inline hb_glyph_info_t &cur (unsigned int i = 0) { return info[idx + i]; }
109 inline hb_glyph_info_t cur (unsigned int i = 0) const { return info[idx + i]; }
111 inline hb_glyph_position_t &cur_pos (unsigned int i = 0) { return pos[idx + i]; }
112 inline hb_glyph_position_t cur_pos (unsigned int i = 0) const { return pos[idx + i]; }
114 inline hb_glyph_info_t &prev (void) { return out_info[out_len - 1]; }
115 inline hb_glyph_info_t prev (void) const { return info[out_len - 1]; }
118 uint8_t allocated_var_bytes[8];
119 const char *allocated_var_owner[8];
124 HB_INTERNAL void reset (void);
126 inline unsigned int backtrack_len (void) const
127 { return have_output? out_len : idx; }
128 inline unsigned int next_serial (void) { return serial++; }
130 HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const char *owner);
131 HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, const char *owner);
132 HB_INTERNAL void deallocate_var_all (void);
134 HB_INTERNAL void add (hb_codepoint_t codepoint,
136 unsigned int cluster);
138 HB_INTERNAL void reverse_range (unsigned int start, unsigned int end);
139 HB_INTERNAL void reverse (void);
140 HB_INTERNAL void reverse_clusters (void);
141 HB_INTERNAL void guess_properties (void);
143 HB_INTERNAL void swap_buffers (void);
144 HB_INTERNAL void clear_output (void);
145 HB_INTERNAL void clear_positions (void);
147 HB_INTERNAL void replace_glyphs (unsigned int num_in,
148 unsigned int num_out,
149 const hb_codepoint_t *glyph_data);
151 HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index);
152 /* Makes a copy of the glyph at idx to output and replace glyph_index */
153 HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index);
154 /* Copies glyph at idx to output but doesn't advance idx */
155 HB_INTERNAL void copy_glyph (void);
156 /* Copies glyph at idx to output and advance idx.
157 * If there's no output, just advance idx. */
158 HB_INTERNAL void next_glyph (void);
159 /* Advance idx without copying to output. */
160 inline void skip_glyph (void) { idx++; }
162 inline void reset_masks (hb_mask_t mask)
164 for (unsigned int j = 0; j < len; j++)
167 inline void add_masks (hb_mask_t mask)
169 for (unsigned int j = 0; j < len; j++)
170 info[j].mask |= mask;
172 HB_INTERNAL void set_masks (hb_mask_t value,
174 unsigned int cluster_start,
175 unsigned int cluster_end);
177 HB_INTERNAL void merge_clusters (unsigned int start,
179 HB_INTERNAL void merge_out_clusters (unsigned int start,
182 /* Internal methods */
183 HB_INTERNAL bool enlarge (unsigned int size);
185 inline bool ensure (unsigned int size)
186 { return likely (size < allocated) ? true : enlarge (size); }
188 HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out);
190 HB_INTERNAL void *get_scratch_buffer (unsigned int *size);
194 #define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \
195 b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
196 sizeof (b->info[0].var), owner)
197 #define HB_BUFFER_ALLOCATE_VAR(b, var) \
198 HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var)
199 #define HB_BUFFER_DEALLOCATE_VAR(b, var) \
200 HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var)
203 #endif /* HB_BUFFER_PRIVATE_HH */