author | prr |
Fri, 01 Mar 2019 16:59:19 -0800 | |
changeset 54232 | 7c11a7cc7c1d |
parent 50826 | src/java.desktop/share/native/libfontmanager/harfbuzz/hb-buffer-private.hh@f5b95be8b6e2 |
permissions | -rw-r--r-- |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
2 |
* Copyright © 1998-2004 David Turner and Werner Lemberg |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
3 |
* Copyright © 2004,2007,2009,2010 Red Hat, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
4 |
* Copyright © 2011,2012 Google, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
5 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
6 |
* This is part of HarfBuzz, a text shaping library. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
7 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
8 |
* Permission is hereby granted, without written agreement and without |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
9 |
* license or royalty fees, to use, copy, modify, and distribute this |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
10 |
* software and its documentation for any purpose, provided that the |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
11 |
* above copyright notice and the following two paragraphs appear in |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
12 |
* all copies of this software. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
13 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
14 |
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
15 |
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
16 |
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
17 |
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
18 |
* DAMAGE. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
19 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
20 |
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
21 |
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
22 |
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
23 |
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
24 |
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
25 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
26 |
* Red Hat Author(s): Owen Taylor, Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
27 |
* Google Author(s): Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
28 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
29 |
|
54232 | 30 |
#ifndef HB_BUFFER_HH |
31 |
#define HB_BUFFER_HH |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
32 |
|
54232 | 33 |
#include "hb.hh" |
34 |
#include "hb-unicode.hh" |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
35 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
36 |
|
50352 | 37 |
#ifndef HB_BUFFER_MAX_LEN_FACTOR |
38 |
#define HB_BUFFER_MAX_LEN_FACTOR 32 |
|
40435 | 39 |
#endif |
40 |
#ifndef HB_BUFFER_MAX_LEN_MIN |
|
41 |
#define HB_BUFFER_MAX_LEN_MIN 8192 |
|
42 |
#endif |
|
43 |
#ifndef HB_BUFFER_MAX_LEN_DEFAULT |
|
44 |
#define HB_BUFFER_MAX_LEN_DEFAULT 0x3FFFFFFF /* Shaping more than a billion chars? Let us know! */ |
|
45 |
#endif |
|
46 |
||
50352 | 47 |
#ifndef HB_BUFFER_MAX_OPS_FACTOR |
48 |
#define HB_BUFFER_MAX_OPS_FACTOR 64 |
|
49 |
#endif |
|
50 |
#ifndef HB_BUFFER_MAX_OPS_MIN |
|
51 |
#define HB_BUFFER_MAX_OPS_MIN 1024 |
|
52 |
#endif |
|
53 |
#ifndef HB_BUFFER_MAX_OPS_DEFAULT |
|
54 |
#define HB_BUFFER_MAX_OPS_DEFAULT 0x1FFFFFFF /* Shaping more than a billion operations? Let us know! */ |
|
55 |
#endif |
|
56 |
||
48274 | 57 |
static_assert ((sizeof (hb_glyph_info_t) == 20), ""); |
58 |
static_assert ((sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)), ""); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
59 |
|
40435 | 60 |
HB_MARK_AS_FLAG_T (hb_buffer_flags_t); |
61 |
HB_MARK_AS_FLAG_T (hb_buffer_serialize_flags_t); |
|
48274 | 62 |
HB_MARK_AS_FLAG_T (hb_buffer_diff_flags_t); |
40435 | 63 |
|
64 |
enum hb_buffer_scratch_flags_t { |
|
65 |
HB_BUFFER_SCRATCH_FLAG_DEFAULT = 0x00000000u, |
|
66 |
HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII = 0x00000001u, |
|
67 |
HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES = 0x00000002u, |
|
68 |
HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK = 0x00000004u, |
|
69 |
HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT = 0x00000008u, |
|
48274 | 70 |
HB_BUFFER_SCRATCH_FLAG_HAS_UNSAFE_TO_BREAK = 0x00000010u, |
50352 | 71 |
HB_BUFFER_SCRATCH_FLAG_HAS_CGJ = 0x00000020u, |
48274 | 72 |
|
40435 | 73 |
/* Reserved for complex shapers' internal use. */ |
74 |
HB_BUFFER_SCRATCH_FLAG_COMPLEX0 = 0x01000000u, |
|
75 |
HB_BUFFER_SCRATCH_FLAG_COMPLEX1 = 0x02000000u, |
|
76 |
HB_BUFFER_SCRATCH_FLAG_COMPLEX2 = 0x04000000u, |
|
77 |
HB_BUFFER_SCRATCH_FLAG_COMPLEX3 = 0x08000000u, |
|
78 |
}; |
|
79 |
HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t); |
|
80 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
81 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
82 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
83 |
* hb_buffer_t |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
84 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
85 |
|
54232 | 86 |
struct hb_buffer_t |
87 |
{ |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
88 |
hb_object_header_t header; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
89 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
90 |
/* Information about how the text in the buffer should be treated */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
91 |
hb_unicode_funcs_t *unicode; /* Unicode functions */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
92 |
hb_buffer_flags_t flags; /* BOT / EOT / etc. */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
93 |
hb_buffer_cluster_level_t cluster_level; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
94 |
hb_codepoint_t replacement; /* U+FFFD or something else. */ |
54232 | 95 |
hb_codepoint_t invisible; /* 0 or something else. */ |
50352 | 96 |
hb_buffer_scratch_flags_t scratch_flags; /* Have space-fallback, etc. */ |
40435 | 97 |
unsigned int max_len; /* Maximum allowed len. */ |
50352 | 98 |
int max_ops; /* Maximum allowed operations. */ |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
99 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
100 |
/* Buffer contents */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
101 |
hb_buffer_content_type_t content_type; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
102 |
hb_segment_properties_t props; /* Script, language, direction */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
103 |
|
50826 | 104 |
bool successful; /* Allocations successful */ |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
105 |
bool have_output; /* Whether we have an output buffer going on */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
106 |
bool have_positions; /* Whether we have positions */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
107 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
108 |
unsigned int idx; /* Cursor into ->info and ->pos arrays */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
109 |
unsigned int len; /* Length of ->info and ->pos arrays */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
110 |
unsigned int out_len; /* Length of ->out array if have_output */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
111 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
112 |
unsigned int allocated; /* Length of allocated arrays */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
113 |
hb_glyph_info_t *info; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
114 |
hb_glyph_info_t *out_info; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
115 |
hb_glyph_position_t *pos; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
116 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
117 |
unsigned int serial; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
118 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
119 |
/* Text before / after the main buffer contents. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
120 |
* Always in Unicode, and ordered outward. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
121 |
* Index 0 is for "pre-context", 1 for "post-context". */ |
54232 | 122 |
static constexpr unsigned CONTEXT_LENGTH = 5u; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
123 |
hb_codepoint_t context[2][CONTEXT_LENGTH]; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
124 |
unsigned int context_len[2]; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
125 |
|
40435 | 126 |
/* Debugging API */ |
127 |
hb_buffer_message_func_t message_func; |
|
128 |
void *message_data; |
|
129 |
hb_destroy_func_t message_destroy; |
|
130 |
||
131 |
/* Internal debugging. */ |
|
132 |
/* The bits here reflect current allocations of the bytes in glyph_info_t's var1 and var2. */ |
|
133 |
#ifndef HB_NDEBUG |
|
134 |
uint8_t allocated_var_bits; |
|
135 |
#endif |
|
50352 | 136 |
|
137 |
||
138 |
/* Methods */ |
|
139 |
||
54232 | 140 |
bool in_error () const { return !successful; } |
141 |
||
142 |
void allocate_var (unsigned int start, unsigned int count) |
|
40435 | 143 |
{ |
144 |
#ifndef HB_NDEBUG |
|
145 |
unsigned int end = start + count; |
|
146 |
assert (end <= 8); |
|
43232 | 147 |
unsigned int bits = (1u<<end) - (1u<<start); |
40435 | 148 |
assert (0 == (allocated_var_bits & bits)); |
149 |
allocated_var_bits |= bits; |
|
150 |
#endif |
|
151 |
} |
|
54232 | 152 |
void deallocate_var (unsigned int start, unsigned int count) |
40435 | 153 |
{ |
154 |
#ifndef HB_NDEBUG |
|
155 |
unsigned int end = start + count; |
|
156 |
assert (end <= 8); |
|
43232 | 157 |
unsigned int bits = (1u<<end) - (1u<<start); |
40435 | 158 |
assert (bits == (allocated_var_bits & bits)); |
159 |
allocated_var_bits &= ~bits; |
|
160 |
#endif |
|
161 |
} |
|
54232 | 162 |
void assert_var (unsigned int start, unsigned int count) |
40435 | 163 |
{ |
164 |
#ifndef HB_NDEBUG |
|
165 |
unsigned int end = start + count; |
|
166 |
assert (end <= 8); |
|
43232 | 167 |
unsigned int bits = (1u<<end) - (1u<<start); |
40435 | 168 |
assert (bits == (allocated_var_bits & bits)); |
169 |
#endif |
|
170 |
} |
|
54232 | 171 |
void deallocate_var_all () |
40435 | 172 |
{ |
173 |
#ifndef HB_NDEBUG |
|
174 |
allocated_var_bits = 0; |
|
175 |
#endif |
|
176 |
} |
|
177 |
||
54232 | 178 |
hb_glyph_info_t &cur (unsigned int i = 0) { return info[idx + i]; } |
179 |
hb_glyph_info_t cur (unsigned int i = 0) const { return info[idx + i]; } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
180 |
|
54232 | 181 |
hb_glyph_position_t &cur_pos (unsigned int i = 0) { return pos[idx + i]; } |
182 |
hb_glyph_position_t cur_pos (unsigned int i = 0) const { return pos[idx + i]; } |
|
50352 | 183 |
|
54232 | 184 |
hb_glyph_info_t &prev () { return out_info[out_len ? out_len - 1 : 0]; } |
185 |
hb_glyph_info_t prev () const { return out_info[out_len ? out_len - 1 : 0]; } |
|
50352 | 186 |
|
54232 | 187 |
bool has_separate_output () const { return info != out_info; } |
50352 | 188 |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
189 |
|
54232 | 190 |
HB_INTERNAL void reset (); |
191 |
HB_INTERNAL void clear (); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
192 |
|
54232 | 193 |
unsigned int backtrack_len () const { return have_output? out_len : idx; } |
194 |
unsigned int lookahead_len () const { return len - idx; } |
|
195 |
unsigned int next_serial () { return serial++; } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
196 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
197 |
HB_INTERNAL void add (hb_codepoint_t codepoint, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
198 |
unsigned int cluster); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
199 |
HB_INTERNAL void add_info (const hb_glyph_info_t &glyph_info); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
200 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
201 |
HB_INTERNAL void reverse_range (unsigned int start, unsigned int end); |
54232 | 202 |
HB_INTERNAL void reverse (); |
203 |
HB_INTERNAL void reverse_clusters (); |
|
204 |
HB_INTERNAL void guess_segment_properties (); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
205 |
|
54232 | 206 |
HB_INTERNAL void swap_buffers (); |
207 |
HB_INTERNAL void remove_output (); |
|
208 |
HB_INTERNAL void clear_output (); |
|
209 |
HB_INTERNAL void clear_positions (); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
210 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
211 |
HB_INTERNAL void replace_glyphs (unsigned int num_in, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
212 |
unsigned int num_out, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
213 |
const hb_codepoint_t *glyph_data); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
214 |
|
54232 | 215 |
void replace_glyph (hb_codepoint_t glyph_index) |
216 |
{ |
|
217 |
if (unlikely (out_info != info || out_len != idx)) { |
|
218 |
if (unlikely (!make_room_for (1, 1))) return; |
|
219 |
out_info[out_len] = info[idx]; |
|
220 |
} |
|
221 |
out_info[out_len].codepoint = glyph_index; |
|
222 |
||
223 |
idx++; |
|
224 |
out_len++; |
|
225 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
226 |
/* Makes a copy of the glyph at idx to output and replace glyph_index */ |
54232 | 227 |
hb_glyph_info_t & output_glyph (hb_codepoint_t glyph_index) |
228 |
{ |
|
229 |
if (unlikely (!make_room_for (0, 1))) return Crap(hb_glyph_info_t); |
|
230 |
||
231 |
if (unlikely (idx == len && !out_len)) |
|
232 |
return Crap(hb_glyph_info_t); |
|
233 |
||
234 |
out_info[out_len] = idx < len ? info[idx] : out_info[out_len - 1]; |
|
235 |
out_info[out_len].codepoint = glyph_index; |
|
236 |
||
237 |
out_len++; |
|
238 |
||
239 |
return out_info[out_len - 1]; |
|
240 |
} |
|
241 |
void output_info (const hb_glyph_info_t &glyph_info) |
|
242 |
{ |
|
243 |
if (unlikely (!make_room_for (0, 1))) return; |
|
244 |
||
245 |
out_info[out_len] = glyph_info; |
|
246 |
||
247 |
out_len++; |
|
248 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
249 |
/* Copies glyph at idx to output but doesn't advance idx */ |
54232 | 250 |
void copy_glyph () |
251 |
{ |
|
252 |
if (unlikely (!make_room_for (0, 1))) return; |
|
253 |
||
254 |
out_info[out_len] = info[idx]; |
|
255 |
||
256 |
out_len++; |
|
257 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
258 |
/* Copies glyph at idx to output and advance idx. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
259 |
* If there's no output, just advance idx. */ |
54232 | 260 |
void |
261 |
next_glyph () |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
262 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
263 |
if (have_output) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
264 |
{ |
54232 | 265 |
if (out_info != info || out_len != idx) |
266 |
{ |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
267 |
if (unlikely (!make_room_for (1, 1))) return; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
268 |
out_info[out_len] = info[idx]; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
269 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
270 |
out_len++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
271 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
272 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
273 |
idx++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
274 |
} |
54232 | 275 |
/* Copies n glyphs at idx to output and advance idx. |
276 |
* If there's no output, just advance idx. */ |
|
277 |
void |
|
278 |
next_glyphs (unsigned int n) |
|
279 |
{ |
|
280 |
if (have_output) |
|
281 |
{ |
|
282 |
if (out_info != info || out_len != idx) |
|
283 |
{ |
|
284 |
if (unlikely (!make_room_for (n, n))) return; |
|
285 |
memmove (out_info + out_len, info + idx, n * sizeof (out_info[0])); |
|
286 |
} |
|
287 |
out_len += n; |
|
288 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
289 |
|
54232 | 290 |
idx += n; |
291 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
292 |
/* Advance idx without copying to output. */ |
54232 | 293 |
void skip_glyph () { idx++; } |
294 |
void reset_masks (hb_mask_t mask) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
295 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
296 |
for (unsigned int j = 0; j < len; j++) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
297 |
info[j].mask = mask; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
298 |
} |
54232 | 299 |
void add_masks (hb_mask_t mask) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
300 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
301 |
for (unsigned int j = 0; j < len; j++) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
302 |
info[j].mask |= mask; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
303 |
} |
48274 | 304 |
HB_INTERNAL void set_masks (hb_mask_t value, hb_mask_t mask, |
305 |
unsigned int cluster_start, unsigned int cluster_end); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
306 |
|
54232 | 307 |
void merge_clusters (unsigned int start, unsigned int end) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
308 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
309 |
if (end - start < 2) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
310 |
return; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
311 |
merge_clusters_impl (start, end); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
312 |
} |
48274 | 313 |
HB_INTERNAL void merge_clusters_impl (unsigned int start, unsigned int end); |
314 |
HB_INTERNAL void merge_out_clusters (unsigned int start, unsigned int end); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
315 |
/* Merge clusters for deleting current glyph, and skip it. */ |
54232 | 316 |
HB_INTERNAL void delete_glyph (); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
317 |
|
54232 | 318 |
void unsafe_to_break (unsigned int start, |
48274 | 319 |
unsigned int end) |
320 |
{ |
|
321 |
if (end - start < 2) |
|
322 |
return; |
|
323 |
unsafe_to_break_impl (start, end); |
|
324 |
} |
|
325 |
HB_INTERNAL void unsafe_to_break_impl (unsigned int start, unsigned int end); |
|
326 |
HB_INTERNAL void unsafe_to_break_from_outbuffer (unsigned int start, unsigned int end); |
|
327 |
||
328 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
329 |
/* Internal methods */ |
54232 | 330 |
HB_INTERNAL bool move_to (unsigned int i); /* i is output-buffer index. */ |
331 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
332 |
HB_INTERNAL bool enlarge (unsigned int size); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
333 |
|
54232 | 334 |
bool ensure (unsigned int size) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
335 |
{ return likely (!size || size < allocated) ? true : enlarge (size); } |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
336 |
|
54232 | 337 |
bool ensure_inplace (unsigned int size) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
338 |
{ return likely (!size || size < allocated); } |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
339 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
340 |
HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
341 |
HB_INTERNAL bool shift_forward (unsigned int count); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
342 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
343 |
typedef long scratch_buffer_t; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
344 |
HB_INTERNAL scratch_buffer_t *get_scratch_buffer (unsigned int *size); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
345 |
|
54232 | 346 |
void clear_context (unsigned int side) { context_len[side] = 0; } |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
347 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
348 |
HB_INTERNAL void sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *)); |
40435 | 349 |
|
54232 | 350 |
bool messaging () { return unlikely (message_func); } |
351 |
bool message (hb_font_t *font, const char *fmt, ...) HB_PRINTF_FUNC(3, 4) |
|
40435 | 352 |
{ |
353 |
if (!messaging ()) |
|
354 |
return true; |
|
355 |
va_list ap; |
|
356 |
va_start (ap, fmt); |
|
357 |
bool ret = message_impl (font, fmt, ap); |
|
358 |
va_end (ap); |
|
359 |
return ret; |
|
360 |
} |
|
361 |
HB_INTERNAL bool message_impl (hb_font_t *font, const char *fmt, va_list ap) HB_PRINTF_FUNC(3, 0); |
|
48274 | 362 |
|
54232 | 363 |
static void |
50352 | 364 |
set_cluster (hb_glyph_info_t &inf, unsigned int cluster, unsigned int mask = 0) |
48274 | 365 |
{ |
50352 | 366 |
if (inf.cluster != cluster) |
48274 | 367 |
{ |
368 |
if (mask & HB_GLYPH_FLAG_UNSAFE_TO_BREAK) |
|
50352 | 369 |
inf.mask |= HB_GLYPH_FLAG_UNSAFE_TO_BREAK; |
48274 | 370 |
else |
50352 | 371 |
inf.mask &= ~HB_GLYPH_FLAG_UNSAFE_TO_BREAK; |
48274 | 372 |
} |
50352 | 373 |
inf.cluster = cluster; |
48274 | 374 |
} |
375 |
||
54232 | 376 |
int |
50352 | 377 |
_unsafe_to_break_find_min_cluster (const hb_glyph_info_t *infos, |
48274 | 378 |
unsigned int start, unsigned int end, |
379 |
unsigned int cluster) const |
|
380 |
{ |
|
381 |
for (unsigned int i = start; i < end; i++) |
|
50352 | 382 |
cluster = MIN<unsigned int> (cluster, infos[i].cluster); |
48274 | 383 |
return cluster; |
384 |
} |
|
54232 | 385 |
void |
50352 | 386 |
_unsafe_to_break_set_mask (hb_glyph_info_t *infos, |
48274 | 387 |
unsigned int start, unsigned int end, |
388 |
unsigned int cluster) |
|
389 |
{ |
|
390 |
for (unsigned int i = start; i < end; i++) |
|
50352 | 391 |
if (cluster != infos[i].cluster) |
48274 | 392 |
{ |
393 |
scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_UNSAFE_TO_BREAK; |
|
50352 | 394 |
infos[i].mask |= HB_GLYPH_FLAG_UNSAFE_TO_BREAK; |
48274 | 395 |
} |
396 |
} |
|
397 |
||
54232 | 398 |
void unsafe_to_break_all () |
399 |
{ unsafe_to_break_impl (0, len); } |
|
400 |
void safe_to_break_all () |
|
48274 | 401 |
{ |
402 |
for (unsigned int i = 0; i < len; i++) |
|
403 |
info[i].mask &= ~HB_GLYPH_FLAG_UNSAFE_TO_BREAK; |
|
404 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
405 |
}; |
54232 | 406 |
DECLARE_NULL_INSTANCE (hb_buffer_t); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
407 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
408 |
|
48274 | 409 |
/* Loop over clusters. Duplicated in foreach_syllable(). */ |
410 |
#define foreach_cluster(buffer, start, end) \ |
|
411 |
for (unsigned int \ |
|
412 |
_count = buffer->len, \ |
|
413 |
start = 0, end = _count ? _next_cluster (buffer, 0) : 0; \ |
|
414 |
start < _count; \ |
|
415 |
start = end, end = _next_cluster (buffer, start)) |
|
416 |
||
417 |
static inline unsigned int |
|
418 |
_next_cluster (hb_buffer_t *buffer, unsigned int start) |
|
419 |
{ |
|
420 |
hb_glyph_info_t *info = buffer->info; |
|
421 |
unsigned int count = buffer->len; |
|
422 |
||
423 |
unsigned int cluster = info[start].cluster; |
|
424 |
while (++start < count && cluster == info[start].cluster) |
|
425 |
; |
|
426 |
||
427 |
return start; |
|
428 |
} |
|
429 |
||
430 |
||
40435 | 431 |
#define HB_BUFFER_XALLOCATE_VAR(b, func, var) \ |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
432 |
b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ |
40435 | 433 |
sizeof (b->info[0].var)) |
434 |
#define HB_BUFFER_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var ()) |
|
435 |
#define HB_BUFFER_DEALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var ()) |
|
436 |
#define HB_BUFFER_ASSERT_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, assert_var, var ()) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
437 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
438 |
|
54232 | 439 |
#endif /* HB_BUFFER_HH */ |