Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: third_party/harfbuzz-ng/src/hb-buffer-serialize.cc

Issue 70193010: Update harfbuzz-ng to 0.9.24 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright © 2012,2013 Google, Inc. 2 * Copyright © 2012,2013 Google, Inc.
3 * 3 *
4 * This is part of HarfBuzz, a text shaping library. 4 * This is part of HarfBuzz, a text shaping library.
5 * 5 *
6 * Permission is hereby granted, without written agreement and without 6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this 7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the 8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in 9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software. 10 * all copies of this software.
(...skipping 15 matching lines...) Expand all
26 26
27 #include "hb-buffer-private.hh" 27 #include "hb-buffer-private.hh"
28 28
29 29
30 static const char *serialize_formats[] = { 30 static const char *serialize_formats[] = {
31 "text", 31 "text",
32 "json", 32 "json",
33 NULL 33 NULL
34 }; 34 };
35 35
36 /**
37 * hb_buffer_serialize_list_formats:
38 *
39 *
40 *
41 * Return value: (transfer none):
42 *
43 * Since: 1.0
44 **/
36 const char ** 45 const char **
37 hb_buffer_serialize_list_formats (void) 46 hb_buffer_serialize_list_formats (void)
38 { 47 {
39 return serialize_formats; 48 return serialize_formats;
40 } 49 }
41 50
51 /**
52 * hb_buffer_serialize_format_from_string:
53 * @str:
54 * @len:
55 *
56 *
57 *
58 * Return value:
59 *
60 * Since: 1.0
61 **/
42 hb_buffer_serialize_format_t 62 hb_buffer_serialize_format_t
43 hb_buffer_serialize_format_from_string (const char *str, int len) 63 hb_buffer_serialize_format_from_string (const char *str, int len)
44 { 64 {
45 /* Upper-case it. */ 65 /* Upper-case it. */
46 return (hb_buffer_serialize_format_t) (hb_tag_from_string (str, len) & ~0x2020 2020); 66 return (hb_buffer_serialize_format_t) (hb_tag_from_string (str, len) & ~0x2020 2020);
47 } 67 }
48 68
69 /**
70 * hb_buffer_serialize_format_to_string:
71 * @format:
72 *
73 *
74 *
75 * Return value:
76 *
77 * Since: 1.0
78 **/
49 const char * 79 const char *
50 hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format) 80 hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format)
51 { 81 {
52 switch (format) 82 switch (format)
53 { 83 {
54 case HB_BUFFER_SERIALIZE_FORMAT_TEXT: return serialize_formats[0]; 84 case HB_BUFFER_SERIALIZE_FORMAT_TEXT: return serialize_formats[0];
55 case HB_BUFFER_SERIALIZE_FORMAT_JSON: return serialize_formats[1]; 85 case HB_BUFFER_SERIALIZE_FORMAT_JSON: return serialize_formats[1];
56 default: 86 default:
57 case HB_BUFFER_SERIALIZE_FORMAT_INVALID: return NULL; 87 case HB_BUFFER_SERIALIZE_FORMAT_INVALID: return NULL;
58 } 88 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 hb_font_glyph_to_string (font, info[i].codepoint, g, sizeof (g)); 123 hb_font_glyph_to_string (font, info[i].codepoint, g, sizeof (g));
94 *p++ = '"'; 124 *p++ = '"';
95 for (char *q = g; *q; q++) { 125 for (char *q = g; *q; q++) {
96 if (*q == '"') 126 if (*q == '"')
97 *p++ = '\\'; 127 *p++ = '\\';
98 *p++ = *q; 128 *p++ = *q;
99 } 129 }
100 *p++ = '"'; 130 *p++ = '"';
101 } 131 }
102 else 132 else
103 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint); 133 p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepo int));
104 134
105 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) { 135 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) {
106 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"cl\":%u", info[i].cluste r); 136 p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"cl\":%u", info[i ].cluster));
107 } 137 }
108 138
109 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS)) 139 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS))
110 { 140 {
111 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"dx\":%d,\"dy\":%d", 141 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"dx\":%d,\"dy\":%d",
112 pos[i].x_offset, pos[i].y_offset); 142 pos[i].x_offset, pos[i].y_offset);
113 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"ax\":%d,\"ay\":%d", 143 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"ax\":%d,\"ay\":%d",
114 pos[i].x_advance, pos[i].y_advance); 144 pos[i].x_advance, pos[i].y_advance);
115 } 145 }
116 146
117 *p++ = '}'; 147 *p++ = '}';
118 148
119 if (buf_size > (p - b)) 149 unsigned int l = p - b;
150 if (buf_size > l)
120 { 151 {
121 unsigned int l = p - b;
122 memcpy (buf, b, l); 152 memcpy (buf, b, l);
123 buf += l; 153 buf += l;
124 buf_size -= l; 154 buf_size -= l;
125 *buf_consumed += l; 155 *buf_consumed += l;
126 *buf = '\0'; 156 *buf = '\0';
127 } else 157 } else
128 return i - start; 158 return i - start;
129 } 159 }
130 160
131 return end - start; 161 return end - start;
(...skipping 22 matching lines...) Expand all
154 184
155 if (i) 185 if (i)
156 *p++ = '|'; 186 *p++ = '|';
157 187
158 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES)) 188 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES))
159 { 189 {
160 hb_font_glyph_to_string (font, info[i].codepoint, p, 128); 190 hb_font_glyph_to_string (font, info[i].codepoint, p, 128);
161 p += strlen (p); 191 p += strlen (p);
162 } 192 }
163 else 193 else
164 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint); 194 p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepo int));
165 195
166 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) { 196 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) {
167 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "=%u", info[i].cluster); 197 p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "=%u", info[i].clust er));
168 } 198 }
169 199
170 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS)) 200 if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS))
171 { 201 {
172 if (pos[i].x_offset || pos[i].y_offset) 202 if (pos[i].x_offset || pos[i].y_offset)
173 » p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "@%d,%d", pos[i].x_offset, pos[i].y_offset); 203 » p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "@%d,%d", pos[i].x _offset, pos[i].y_offset));
174 204
175 *p++ = '+'; 205 *p++ = '+';
176 p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "%d", pos[i].x_advance); 206 p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%d", pos[i].x_advan ce));
177 if (pos->y_advance) 207 if (pos->y_advance)
178 » p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance); 208 » p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_ad vance));
179 } 209 }
180 210
181 if (buf_size > (p - b)) 211 unsigned int l = p - b;
212 if (buf_size > l)
182 { 213 {
183 unsigned int l = p - b;
184 memcpy (buf, b, l); 214 memcpy (buf, b, l);
185 buf += l; 215 buf += l;
186 buf_size -= l; 216 buf_size -= l;
187 *buf_consumed += l; 217 *buf_consumed += l;
188 *buf = '\0'; 218 *buf = '\0';
189 } else 219 } else
190 return i - start; 220 return i - start;
191 } 221 }
192 222
193 return end - start; 223 return end - start;
194 } 224 }
195 225
196 /* Returns number of items, starting at start, that were serialized. */ 226 /* Returns number of items, starting at start, that were serialized. */
227 /**
228 * hb_buffer_serialize_glyphs:
229 * @buffer: a buffer.
230 * @start:
231 * @end:
232 * @buf: (array length=buf_size):
233 * @buf_size:
234 * @buf_consumed: (out):
235 * @font:
236 * @format:
237 * @flags:
238 *
239 *
240 *
241 * Return value:
242 *
243 * Since: 1.0
244 **/
197 unsigned int 245 unsigned int
198 hb_buffer_serialize_glyphs (hb_buffer_t *buffer, 246 hb_buffer_serialize_glyphs (hb_buffer_t *buffer,
199 unsigned int start, 247 unsigned int start,
200 unsigned int end, 248 unsigned int end,
201 char *buf, 249 char *buf,
202 unsigned int buf_size, 250 unsigned int buf_size,
203 unsigned int *buf_consumed, /* May be NULL */ 251 unsigned int *buf_consumed, /* May be NULL */
204 hb_font_t *font, /* May be NULL */ 252 hb_font_t *font, /* May be NULL */
205 hb_buffer_serialize_format_t format, 253 hb_buffer_serialize_format_t format,
206 hb_buffer_serialize_flags_t flags) 254 hb_buffer_serialize_flags_t flags)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 if (errno || p == pend || pend - p != end - pp) 327 if (errno || p == pend || pend - p != end - pp)
280 return false; 328 return false;
281 329
282 *pv = v; 330 *pv = v;
283 return true; 331 return true;
284 } 332 }
285 333
286 #include "hb-buffer-deserialize-json.hh" 334 #include "hb-buffer-deserialize-json.hh"
287 #include "hb-buffer-deserialize-text.hh" 335 #include "hb-buffer-deserialize-text.hh"
288 336
337 /**
338 * hb_buffer_deserialize_glyphs:
339 * @buffer: a buffer.
340 * @buf: (array length=buf_len):
341 * @buf_len:
342 * @end_ptr: (out):
343 * @font:
344 * @format:
345 *
346 *
347 *
348 * Return value:
349 *
350 * Since: 1.0
351 **/
289 hb_bool_t 352 hb_bool_t
290 hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, 353 hb_buffer_deserialize_glyphs (hb_buffer_t *buffer,
291 const char *buf, 354 const char *buf,
292 int buf_len, /* -1 means nul-terminated */ 355 int buf_len, /* -1 means nul-terminated */
293 const char **end_ptr, /* May be NULL */ 356 const char **end_ptr, /* May be NULL */
294 hb_font_t *font, /* May be NULL */ 357 hb_font_t *font, /* May be NULL */
295 hb_buffer_serialize_format_t format) 358 hb_buffer_serialize_format_t format)
296 { 359 {
297 const char *end; 360 const char *end;
298 if (!end_ptr) 361 if (!end_ptr)
(...skipping 28 matching lines...) Expand all
327 return _hb_buffer_deserialize_glyphs_json (buffer, 390 return _hb_buffer_deserialize_glyphs_json (buffer,
328 buf, buf_len, end_ptr, 391 buf, buf_len, end_ptr,
329 font); 392 font);
330 393
331 default: 394 default:
332 case HB_BUFFER_SERIALIZE_FORMAT_INVALID: 395 case HB_BUFFER_SERIALIZE_FORMAT_INVALID:
333 return false; 396 return false;
334 397
335 } 398 }
336 } 399 }
OLDNEW
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-buffer-private.hh ('k') | third_party/harfbuzz-ng/src/hb-common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698