OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 1998-2004 David Turner and Werner Lemberg | 2 * Copyright © 1998-2004 David Turner and Werner Lemberg |
3 * Copyright © 2004,2007,2009,2010 Red Hat, Inc. | 3 * Copyright © 2004,2007,2009,2010 Red Hat, Inc. |
4 * Copyright © 2011 Google, Inc. | 4 * Copyright © 2011 Google, Inc. |
5 * | 5 * |
6 * This is part of HarfBuzz, a text shaping library. | 6 * This is part of HarfBuzz, a text shaping library. |
7 * | 7 * |
8 * Permission is hereby granted, without written agreement and without | 8 * Permission is hereby granted, without written agreement and without |
9 * license or royalty fees, to use, copy, modify, and distribute this | 9 * license or royalty fees, to use, copy, modify, and distribute this |
10 * software and its documentation for any purpose, provided that the | 10 * software and its documentation for any purpose, provided that the |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "hb-private.hh" | 33 #include "hb-private.hh" |
34 #include "hb-buffer.h" | 34 #include "hb-buffer.h" |
35 #include "hb-object-private.hh" | 35 #include "hb-object-private.hh" |
36 #include "hb-unicode-private.hh" | 36 #include "hb-unicode-private.hh" |
37 | 37 |
38 | 38 |
39 | 39 |
40 ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); | 40 ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); |
41 ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); | 41 ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); |
42 | 42 |
43 typedef struct _hb_segment_properties_t { | 43 |
| 44 /* |
| 45 * hb_segment_properties_t |
| 46 */ |
| 47 |
| 48 typedef struct hb_segment_properties_t { |
44 hb_direction_t direction; | 49 hb_direction_t direction; |
45 hb_script_t script; | 50 hb_script_t script; |
46 hb_language_t language; | 51 hb_language_t language; |
47 ASSERT_POD (); | 52 ASSERT_POD (); |
48 } hb_segment_properties_t; | 53 } hb_segment_properties_t; |
49 | 54 |
| 55 #define _HB_BUFFER_PROPS_DEFAULT { HB_DIRECTION_INVALID, HB_SCRIPT_INVALID, HB_L
ANGUAGE_INVALID } |
50 | 56 |
51 struct _hb_buffer_t { | 57 static inline hb_bool_t |
| 58 hb_segment_properties_equal (const hb_segment_properties_t *a, |
| 59 » » » const hb_segment_properties_t *b) |
| 60 { |
| 61 return a->direction == b->direction && |
| 62 » a->script == b->script && |
| 63 » a->language == b->language; |
| 64 } |
| 65 |
| 66 |
| 67 #if 0 |
| 68 static inline unsigned int |
| 69 hb_segment_properties_hash (const hb_segment_properties_t *p) |
| 70 { |
| 71 /* TODO improve */ |
| 72 return (unsigned int) p->direction + |
| 73 » (unsigned int) p->script + |
| 74 » (intptr_t) (p->language); |
| 75 } |
| 76 #endif |
| 77 |
| 78 |
| 79 |
| 80 /* |
| 81 * hb_buffer_t |
| 82 */ |
| 83 |
| 84 struct hb_buffer_t { |
52 hb_object_header_t header; | 85 hb_object_header_t header; |
53 ASSERT_POD (); | 86 ASSERT_POD (); |
54 | 87 |
55 /* Information about how the text in the buffer should be treated */ | 88 /* Information about how the text in the buffer should be treated */ |
56 | 89 |
57 hb_unicode_funcs_t *unicode; /* Unicode functions */ | 90 hb_unicode_funcs_t *unicode; /* Unicode functions */ |
58 hb_segment_properties_t props; /* Script, language, direction */ | 91 hb_segment_properties_t props; /* Script, language, direction */ |
59 | 92 |
60 /* Buffer contents */ | 93 /* Buffer contents */ |
61 | 94 |
| 95 hb_buffer_content_type_t content_type; |
| 96 |
62 bool in_error; /* Allocation failed */ | 97 bool in_error; /* Allocation failed */ |
63 bool have_output; /* Whether we have an output buffer going on */ | 98 bool have_output; /* Whether we have an output buffer going on */ |
64 bool have_positions; /* Whether we have positions */ | 99 bool have_positions; /* Whether we have positions */ |
65 | 100 |
66 unsigned int idx; /* Cursor into ->info and ->pos arrays */ | 101 unsigned int idx; /* Cursor into ->info and ->pos arrays */ |
67 unsigned int len; /* Length of ->info and ->pos arrays */ | 102 unsigned int len; /* Length of ->info and ->pos arrays */ |
68 unsigned int out_len; /* Length of ->out array if have_output */ | 103 unsigned int out_len; /* Length of ->out array if have_output */ |
69 | 104 |
70 unsigned int allocated; /* Length of allocated arrays */ | 105 unsigned int allocated; /* Length of allocated arrays */ |
71 hb_glyph_info_t *info; | 106 hb_glyph_info_t *info; |
(...skipping 17 matching lines...) Expand all Loading... |
89 /* Methods */ | 124 /* Methods */ |
90 | 125 |
91 HB_INTERNAL void reset (void); | 126 HB_INTERNAL void reset (void); |
92 | 127 |
93 inline unsigned int backtrack_len (void) const | 128 inline unsigned int backtrack_len (void) const |
94 { return have_output? out_len : idx; } | 129 { return have_output? out_len : idx; } |
95 inline unsigned int next_serial (void) { return serial++; } | 130 inline unsigned int next_serial (void) { return serial++; } |
96 | 131 |
97 HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const
char *owner); | 132 HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const
char *owner); |
98 HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, cons
t char *owner); | 133 HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, cons
t char *owner); |
| 134 HB_INTERNAL void assert_var (unsigned int byte_i, unsigned int count, const ch
ar *owner); |
99 HB_INTERNAL void deallocate_var_all (void); | 135 HB_INTERNAL void deallocate_var_all (void); |
100 | 136 |
101 HB_INTERNAL void add (hb_codepoint_t codepoint, | 137 HB_INTERNAL void add (hb_codepoint_t codepoint, |
102 hb_mask_t mask, | 138 hb_mask_t mask, |
103 unsigned int cluster); | 139 unsigned int cluster); |
104 | 140 |
105 HB_INTERNAL void reverse_range (unsigned int start, unsigned int end); | 141 HB_INTERNAL void reverse_range (unsigned int start, unsigned int end); |
106 HB_INTERNAL void reverse (void); | 142 HB_INTERNAL void reverse (void); |
107 HB_INTERNAL void reverse_clusters (void); | 143 HB_INTERNAL void reverse_clusters (void); |
108 HB_INTERNAL void guess_properties (void); | 144 HB_INTERNAL void guess_properties (void); |
109 | 145 |
110 HB_INTERNAL void swap_buffers (void); | 146 HB_INTERNAL void swap_buffers (void); |
111 HB_INTERNAL void clear_output (void); | 147 HB_INTERNAL void clear_output (void); |
112 HB_INTERNAL void clear_positions (void); | 148 HB_INTERNAL void clear_positions (void); |
113 HB_INTERNAL void replace_glyphs_be16 (unsigned int num_in, | 149 |
114 » » » » » unsigned int num_out, | |
115 » » » » » const char *glyph_data_be); | |
116 HB_INTERNAL void replace_glyphs (unsigned int num_in, | 150 HB_INTERNAL void replace_glyphs (unsigned int num_in, |
117 unsigned int num_out, | 151 unsigned int num_out, |
118 const hb_codepoint_t *glyph_data); | 152 const hb_codepoint_t *glyph_data); |
| 153 |
119 HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index); | 154 HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index); |
120 /* Makes a copy of the glyph at idx to output and replace glyph_index */ | 155 /* Makes a copy of the glyph at idx to output and replace glyph_index */ |
121 HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index); | 156 HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index); |
| 157 HB_INTERNAL void output_info (hb_glyph_info_t &glyph_info); |
122 /* Copies glyph at idx to output but doesn't advance idx */ | 158 /* Copies glyph at idx to output but doesn't advance idx */ |
123 HB_INTERNAL void copy_glyph (void); | 159 HB_INTERNAL void copy_glyph (void); |
124 /* Copies glyph at idx to output and advance idx. | 160 /* Copies glyph at idx to output and advance idx. |
125 * If there's no output, just advance idx. */ | 161 * If there's no output, just advance idx. */ |
126 HB_INTERNAL void next_glyph (void); | 162 inline void |
| 163 next_glyph (void) |
| 164 { |
| 165 if (have_output) |
| 166 { |
| 167 if (unlikely (out_info != info || out_len != idx)) { |
| 168 » if (unlikely (!make_room_for (1, 1))) return; |
| 169 » out_info[out_len] = info[idx]; |
| 170 } |
| 171 out_len++; |
| 172 } |
| 173 |
| 174 idx++; |
| 175 } |
| 176 |
127 /* Advance idx without copying to output. */ | 177 /* Advance idx without copying to output. */ |
128 inline void skip_glyph (void) { idx++; } | 178 inline void skip_glyph (void) { idx++; } |
129 | 179 |
130 inline void reset_masks (hb_mask_t mask) | 180 inline void reset_masks (hb_mask_t mask) |
131 { | 181 { |
132 for (unsigned int j = 0; j < len; j++) | 182 for (unsigned int j = 0; j < len; j++) |
133 info[j].mask = mask; | 183 info[j].mask = mask; |
134 } | 184 } |
135 inline void add_masks (hb_mask_t mask) | 185 inline void add_masks (hb_mask_t mask) |
136 { | 186 { |
137 for (unsigned int j = 0; j < len; j++) | 187 for (unsigned int j = 0; j < len; j++) |
138 info[j].mask |= mask; | 188 info[j].mask |= mask; |
139 } | 189 } |
140 HB_INTERNAL void set_masks (hb_mask_t value, | 190 HB_INTERNAL void set_masks (hb_mask_t value, |
141 hb_mask_t mask, | 191 hb_mask_t mask, |
142 unsigned int cluster_start, | 192 unsigned int cluster_start, |
143 unsigned int cluster_end); | 193 unsigned int cluster_end); |
144 | 194 |
145 HB_INTERNAL void merge_clusters (unsigned int start, | 195 HB_INTERNAL void merge_clusters (unsigned int start, |
146 unsigned int end); | 196 unsigned int end); |
147 HB_INTERNAL void merge_out_clusters (unsigned int start, | 197 HB_INTERNAL void merge_out_clusters (unsigned int start, |
148 unsigned int end); | 198 unsigned int end); |
149 | 199 |
150 /* Internal methods */ | 200 /* Internal methods */ |
151 HB_INTERNAL bool enlarge (unsigned int size); | 201 HB_INTERNAL bool enlarge (unsigned int size); |
152 | 202 |
153 inline bool ensure (unsigned int size) | 203 inline bool ensure (unsigned int size) |
154 { return likely (size <= allocated) ? true : enlarge (size); } | 204 { return likely (size < allocated) ? true : enlarge (size); } |
155 | 205 |
156 HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); | 206 HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); |
157 | 207 |
158 HB_INTERNAL void *get_scratch_buffer (unsigned int *size); | 208 HB_INTERNAL void *get_scratch_buffer (unsigned int *size); |
159 }; | 209 }; |
160 | 210 |
161 | 211 |
162 #define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \ | 212 #define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \ |
163 b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ | 213 b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ |
164 sizeof (b->info[0].var), owner) | 214 sizeof (b->info[0].var), owner) |
165 #define HB_BUFFER_ALLOCATE_VAR(b, var) \ | 215 #define HB_BUFFER_ALLOCATE_VAR(b, var) \ |
166 HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var) | 216 HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var) |
167 #define HB_BUFFER_DEALLOCATE_VAR(b, var) \ | 217 #define HB_BUFFER_DEALLOCATE_VAR(b, var) \ |
168 HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var) | 218 HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var) |
169 | 219 #define HB_BUFFER_ASSERT_VAR(b, var) \ |
| 220 » HB_BUFFER_XALLOCATE_VAR (b, assert_var, var (), #var) |
170 | 221 |
171 | 222 |
172 #endif /* HB_BUFFER_PRIVATE_HH */ | 223 #endif /* HB_BUFFER_PRIVATE_HH */ |
OLD | NEW |