2 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009,2010 Red Hat, Inc.
4 * Copyright © 2011,2012 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 hb_buffer_content_type_t content_type
;
97 bool in_error
; /* Allocation failed */
98 bool have_output
; /* Whether we have an output buffer going on */
99 bool have_positions
; /* Whether we have positions */
101 unsigned int idx
; /* Cursor into ->info and ->pos arrays */
102 unsigned int len
; /* Length of ->info and ->pos arrays */
103 unsigned int out_len
; /* Length of ->out array if have_output */
105 unsigned int allocated
; /* Length of allocated arrays */
106 hb_glyph_info_t
*info
;
107 hb_glyph_info_t
*out_info
;
108 hb_glyph_position_t
*pos
;
110 inline hb_glyph_info_t
&cur (unsigned int i
= 0) { return info
[idx
+ i
]; }
111 inline hb_glyph_info_t
cur (unsigned int i
= 0) const { return info
[idx
+ i
]; }
113 inline hb_glyph_position_t
&cur_pos (unsigned int i
= 0) { return pos
[idx
+ i
]; }
114 inline hb_glyph_position_t
cur_pos (unsigned int i
= 0) const { return pos
[idx
+ i
]; }
116 inline hb_glyph_info_t
&prev (void) { return out_info
[out_len
- 1]; }
117 inline hb_glyph_info_t
prev (void) const { return info
[out_len
- 1]; }
121 /* These reflect current allocations of the bytes in glyph_info_t's var1 and var2. */
122 uint8_t allocated_var_bytes
[8];
123 const char *allocated_var_owner
[8];
125 /* Text before / after the main buffer contents.
126 * Always in Unicode, and ordered outward.
127 * Index 0 is for "pre-context", 1 for "post-context". */
128 static const unsigned int CONTEXT_LENGTH
= 5;
129 hb_codepoint_t context
[2][CONTEXT_LENGTH
];
130 unsigned int context_len
[2];
135 HB_INTERNAL
void reset (void);
137 inline unsigned int backtrack_len (void) const
138 { return have_output
? out_len
: idx
; }
139 inline unsigned int next_serial (void) { return serial
++; }
141 HB_INTERNAL
void allocate_var (unsigned int byte_i
, unsigned int count
, const char *owner
);
142 HB_INTERNAL
void deallocate_var (unsigned int byte_i
, unsigned int count
, const char *owner
);
143 HB_INTERNAL
void assert_var (unsigned int byte_i
, unsigned int count
, const char *owner
);
144 HB_INTERNAL
void deallocate_var_all (void);
146 HB_INTERNAL
void add (hb_codepoint_t codepoint
,
148 unsigned int cluster
);
150 HB_INTERNAL
void reverse_range (unsigned int start
, unsigned int end
);
151 HB_INTERNAL
void reverse (void);
152 HB_INTERNAL
void reverse_clusters (void);
153 HB_INTERNAL
void guess_properties (void);
155 HB_INTERNAL
void swap_buffers (void);
156 HB_INTERNAL
void remove_output (void);
157 HB_INTERNAL
void clear_output (void);
158 HB_INTERNAL
void clear_positions (void);
160 HB_INTERNAL
void replace_glyphs (unsigned int num_in
,
161 unsigned int num_out
,
162 const hb_codepoint_t
*glyph_data
);
164 HB_INTERNAL
void replace_glyph (hb_codepoint_t glyph_index
);
165 /* Makes a copy of the glyph at idx to output and replace glyph_index */
166 HB_INTERNAL
void output_glyph (hb_codepoint_t glyph_index
);
167 HB_INTERNAL
void output_info (hb_glyph_info_t
&glyph_info
);
168 /* Copies glyph at idx to output but doesn't advance idx */
169 HB_INTERNAL
void copy_glyph (void);
170 /* Copies glyph at idx to output and advance idx.
171 * If there's no output, just advance idx. */
177 if (unlikely (out_info
!= info
|| out_len
!= idx
)) {
178 if (unlikely (!make_room_for (1, 1))) return;
179 out_info
[out_len
] = info
[idx
];
187 /* Advance idx without copying to output. */
188 inline void skip_glyph (void) { idx
++; }
190 inline void reset_masks (hb_mask_t mask
)
192 for (unsigned int j
= 0; j
< len
; j
++)
195 inline void add_masks (hb_mask_t mask
)
197 for (unsigned int j
= 0; j
< len
; j
++)
198 info
[j
].mask
|= mask
;
200 HB_INTERNAL
void set_masks (hb_mask_t value
,
202 unsigned int cluster_start
,
203 unsigned int cluster_end
);
205 HB_INTERNAL
void merge_clusters (unsigned int start
,
207 HB_INTERNAL
void merge_out_clusters (unsigned int start
,
210 /* Internal methods */
211 HB_INTERNAL
bool enlarge (unsigned int size
);
213 inline bool ensure (unsigned int size
)
214 { return likely (size
< allocated
) ? true : enlarge (size
); }
216 HB_INTERNAL
bool make_room_for (unsigned int num_in
, unsigned int num_out
);
218 HB_INTERNAL
void *get_scratch_buffer (unsigned int *size
);
220 inline void clear_context (unsigned int side
) { context_len
[side
] = 0; }
224 #define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \
225 b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
226 sizeof (b->info[0].var), owner)
227 #define HB_BUFFER_ALLOCATE_VAR(b, var) \
228 HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var)
229 #define HB_BUFFER_DEALLOCATE_VAR(b, var) \
230 HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var)
231 #define HB_BUFFER_ASSERT_VAR(b, var) \
232 HB_BUFFER_XALLOCATE_VAR (b, assert_var, var (), #var)
235 #endif /* HB_BUFFER_PRIVATE_HH */