1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-buffer-private.hh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,206 @@ 1.4 +/* 1.5 + * Copyright © 1998-2004 David Turner and Werner Lemberg 1.6 + * Copyright © 2004,2007,2009,2010 Red Hat, Inc. 1.7 + * Copyright © 2011,2012 Google, Inc. 1.8 + * 1.9 + * This is part of HarfBuzz, a text shaping library. 1.10 + * 1.11 + * Permission is hereby granted, without written agreement and without 1.12 + * license or royalty fees, to use, copy, modify, and distribute this 1.13 + * software and its documentation for any purpose, provided that the 1.14 + * above copyright notice and the following two paragraphs appear in 1.15 + * all copies of this software. 1.16 + * 1.17 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.18 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.19 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.20 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.21 + * DAMAGE. 1.22 + * 1.23 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.24 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.25 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.26 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.27 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.28 + * 1.29 + * Red Hat Author(s): Owen Taylor, Behdad Esfahbod 1.30 + * Google Author(s): Behdad Esfahbod 1.31 + */ 1.32 + 1.33 +#ifndef HB_BUFFER_PRIVATE_HH 1.34 +#define HB_BUFFER_PRIVATE_HH 1.35 + 1.36 +#include "hb-private.hh" 1.37 +#include "hb-object-private.hh" 1.38 +#include "hb-unicode-private.hh" 1.39 + 1.40 + 1.41 +ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); 1.42 +ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); 1.43 + 1.44 + 1.45 +/* 1.46 + * hb_buffer_t 1.47 + */ 1.48 + 1.49 +struct hb_buffer_t { 1.50 + hb_object_header_t header; 1.51 + ASSERT_POD (); 1.52 + 1.53 + /* Information about how the text in the buffer should be treated */ 1.54 + 1.55 + hb_unicode_funcs_t *unicode; /* Unicode functions */ 1.56 + hb_segment_properties_t props; /* Script, language, direction */ 1.57 + hb_buffer_flags_t flags; /* BOT / EOT / etc. */ 1.58 + 1.59 + /* Buffer contents */ 1.60 + 1.61 + hb_buffer_content_type_t content_type; 1.62 + 1.63 + bool in_error; /* Allocation failed */ 1.64 + bool have_output; /* Whether we have an output buffer going on */ 1.65 + bool have_positions; /* Whether we have positions */ 1.66 + 1.67 + unsigned int idx; /* Cursor into ->info and ->pos arrays */ 1.68 + unsigned int len; /* Length of ->info and ->pos arrays */ 1.69 + unsigned int out_len; /* Length of ->out array if have_output */ 1.70 + 1.71 + unsigned int allocated; /* Length of allocated arrays */ 1.72 + hb_glyph_info_t *info; 1.73 + hb_glyph_info_t *out_info; 1.74 + hb_glyph_position_t *pos; 1.75 + 1.76 + inline hb_glyph_info_t &cur (unsigned int i = 0) { return info[idx + i]; } 1.77 + inline hb_glyph_info_t cur (unsigned int i = 0) const { return info[idx + i]; } 1.78 + 1.79 + inline hb_glyph_position_t &cur_pos (unsigned int i = 0) { return pos[idx + i]; } 1.80 + inline hb_glyph_position_t cur_pos (unsigned int i = 0) const { return pos[idx + i]; } 1.81 + 1.82 + inline hb_glyph_info_t &prev (void) { return out_info[out_len - 1]; } 1.83 + inline hb_glyph_info_t prev (void) const { return info[out_len - 1]; } 1.84 + 1.85 + inline bool has_separate_output (void) const { return info != out_info; } 1.86 + 1.87 + unsigned int serial; 1.88 + 1.89 + /* These reflect current allocations of the bytes in glyph_info_t's var1 and var2. */ 1.90 + uint8_t allocated_var_bytes[8]; 1.91 + const char *allocated_var_owner[8]; 1.92 + 1.93 + /* Text before / after the main buffer contents. 1.94 + * Always in Unicode, and ordered outward. 1.95 + * Index 0 is for "pre-context", 1 for "post-context". */ 1.96 + static const unsigned int CONTEXT_LENGTH = 5; 1.97 + hb_codepoint_t context[2][CONTEXT_LENGTH]; 1.98 + unsigned int context_len[2]; 1.99 + 1.100 + 1.101 + /* Methods */ 1.102 + 1.103 + HB_INTERNAL void reset (void); 1.104 + HB_INTERNAL void clear (void); 1.105 + 1.106 + inline unsigned int backtrack_len (void) const 1.107 + { return have_output? out_len : idx; } 1.108 + inline unsigned int lookahead_len (void) const 1.109 + { return len - idx; } 1.110 + inline unsigned int next_serial (void) { return serial++; } 1.111 + 1.112 + HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const char *owner); 1.113 + HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, const char *owner); 1.114 + HB_INTERNAL void assert_var (unsigned int byte_i, unsigned int count, const char *owner); 1.115 + HB_INTERNAL void deallocate_var_all (void); 1.116 + 1.117 + HB_INTERNAL void add (hb_codepoint_t codepoint, 1.118 + unsigned int cluster); 1.119 + HB_INTERNAL void add_info (const hb_glyph_info_t &glyph_info); 1.120 + 1.121 + HB_INTERNAL void reverse_range (unsigned int start, unsigned int end); 1.122 + HB_INTERNAL void reverse (void); 1.123 + HB_INTERNAL void reverse_clusters (void); 1.124 + HB_INTERNAL void guess_segment_properties (void); 1.125 + 1.126 + HB_INTERNAL void swap_buffers (void); 1.127 + HB_INTERNAL void remove_output (void); 1.128 + HB_INTERNAL void clear_output (void); 1.129 + HB_INTERNAL void clear_positions (void); 1.130 + 1.131 + HB_INTERNAL void replace_glyphs (unsigned int num_in, 1.132 + unsigned int num_out, 1.133 + const hb_codepoint_t *glyph_data); 1.134 + 1.135 + HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index); 1.136 + /* Makes a copy of the glyph at idx to output and replace glyph_index */ 1.137 + HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index); 1.138 + HB_INTERNAL void output_info (const hb_glyph_info_t &glyph_info); 1.139 + /* Copies glyph at idx to output but doesn't advance idx */ 1.140 + HB_INTERNAL void copy_glyph (void); 1.141 + HB_INTERNAL bool move_to (unsigned int i); /* i is output-buffer index. */ 1.142 + /* Copies glyph at idx to output and advance idx. 1.143 + * If there's no output, just advance idx. */ 1.144 + inline void 1.145 + next_glyph (void) 1.146 + { 1.147 + if (have_output) 1.148 + { 1.149 + if (unlikely (out_info != info || out_len != idx)) { 1.150 + if (unlikely (!make_room_for (1, 1))) return; 1.151 + out_info[out_len] = info[idx]; 1.152 + } 1.153 + out_len++; 1.154 + } 1.155 + 1.156 + idx++; 1.157 + } 1.158 + 1.159 + /* Advance idx without copying to output. */ 1.160 + inline void skip_glyph (void) { idx++; } 1.161 + 1.162 + inline void reset_masks (hb_mask_t mask) 1.163 + { 1.164 + for (unsigned int j = 0; j < len; j++) 1.165 + info[j].mask = mask; 1.166 + } 1.167 + inline void add_masks (hb_mask_t mask) 1.168 + { 1.169 + for (unsigned int j = 0; j < len; j++) 1.170 + info[j].mask |= mask; 1.171 + } 1.172 + HB_INTERNAL void set_masks (hb_mask_t value, 1.173 + hb_mask_t mask, 1.174 + unsigned int cluster_start, 1.175 + unsigned int cluster_end); 1.176 + 1.177 + HB_INTERNAL void merge_clusters (unsigned int start, 1.178 + unsigned int end); 1.179 + HB_INTERNAL void merge_out_clusters (unsigned int start, 1.180 + unsigned int end); 1.181 + 1.182 + /* Internal methods */ 1.183 + HB_INTERNAL bool enlarge (unsigned int size); 1.184 + 1.185 + inline bool ensure (unsigned int size) 1.186 + { return likely (!size || size < allocated) ? true : enlarge (size); } 1.187 + 1.188 + HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); 1.189 + HB_INTERNAL bool shift_forward (unsigned int count); 1.190 + 1.191 + typedef long scratch_buffer_t; 1.192 + HB_INTERNAL scratch_buffer_t *get_scratch_buffer (unsigned int *size); 1.193 + 1.194 + inline void clear_context (unsigned int side) { context_len[side] = 0; } 1.195 +}; 1.196 + 1.197 + 1.198 +#define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \ 1.199 + b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ 1.200 + sizeof (b->info[0].var), owner) 1.201 +#define HB_BUFFER_ALLOCATE_VAR(b, var) \ 1.202 + HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var) 1.203 +#define HB_BUFFER_DEALLOCATE_VAR(b, var) \ 1.204 + HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var) 1.205 +#define HB_BUFFER_ASSERT_VAR(b, var) \ 1.206 + HB_BUFFER_XALLOCATE_VAR (b, assert_var, var (), #var) 1.207 + 1.208 + 1.209 +#endif /* HB_BUFFER_PRIVATE_HH */