1 #line 1 "hb-buffer-deserialize-json.rl"
2 /*
3 * Copyright © 2013 Google, Inc.
4 *
5 * This is part of HarfBuzz, a text shaping library.
6 *
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
12 *
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 *
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 *
25 * Google Author(s): Behdad Esfahbod
26 */
27
28 #ifndef HB_BUFFER_DESERIALIZE_JSON_HH
29 #define HB_BUFFER_DESERIALIZE_JSON_HH
30
31 #include "hb.hh"
32
33
34 #line 35 "hb-buffer-deserialize-json.hh"
35 static const unsigned char _deserialize_json_trans_keys[] = {
36 1u, 0u, 0u, 18u, 0u, 2u, 10u, 15u,
37 16u, 17u, 2u, 2u, 0u, 7u, 0u, 6u,
38 5u, 6u, 0u, 19u, 0u, 19u, 0u, 19u,
39 2u, 2u, 0u, 7u, 0u, 6u, 5u, 6u,
40 0u, 19u, 0u, 19u, 14u, 14u, 2u, 2u,
41 0u, 7u, 0u, 6u, 0u, 19u, 0u, 19u,
42 16u, 17u, 2u, 2u, 0u, 7u, 0u, 6u,
43 5u, 6u, 0u, 19u, 0u, 19u, 2u, 2u,
44 0u, 7u, 0u, 6u, 5u, 6u, 0u, 19u,
45 0u, 19u, 2u, 2u, 0u, 7u, 0u, 6u,
46 2u, 8u, 0u, 19u, 2u, 8u, 0u, 19u,
47 0u, 19u, 2u, 2u, 0u, 7u, 0u, 6u,
48 0u, 19u, 0u, 9u, 0u, 18u, 1u, 0u,
49 0u
50 };
51
52 static const signed char _deserialize_json_char_class[] = {
53 0, 0, 0, 0, 0, 1, 1, 1,
54 1, 1, 1, 1, 1, 1, 1, 1,
55 1, 1, 1, 1, 1, 1, 1, 0,
56 1, 2, 1, 1, 1, 1, 1, 1,
57 1, 1, 1, 3, 4, 1, 1, 5,
58 6, 6, 6, 6, 6, 6, 6, 6,
59 6, 7, 1, 1, 1, 1, 1, 1,
60 1, 1, 1, 1, 1, 1, 1, 1,
61 1, 1, 1, 1, 1, 1, 1, 1,
62 1, 1, 1, 1, 1, 1, 1, 1,
63 1, 1, 1, 8, 9, 1, 1, 1,
64 10, 1, 11, 12, 1, 1, 13, 1,
65 1, 1, 1, 14, 1, 1, 1, 1,
66 1, 1, 1, 1, 15, 1, 1, 16,
67 17, 1, 18, 1, 19, 0
68 };
69
70 static const short _deserialize_json_index_offsets[] = {
71 0, 0, 19, 22, 28, 30, 31, 39,
72 46, 48, 68, 88, 108, 109, 117, 124,
73 126, 146, 166, 167, 168, 176, 183, 203,
74 223, 225, 226, 234, 241, 243, 263, 283,
75 284, 292, 299, 301, 321, 341, 342, 350,
76 357, 364, 384, 391, 411, 431, 432, 440,
77 447, 467, 477, 496, 0
78 };
79
80 static const signed char _deserialize_json_indicies[] = {
81 1, 0, 0, 0, 0, 0, 0, 0,
82 0, 0, 0, 0, 0, 0, 0, 0,
83 0, 0, 2, 3, 0, 4, 5, 6,
84 7, 8, 0, 9, 10, 11, 12, 12,
85 0, 0, 0, 0, 0, 0, 13, 13,
86 0, 0, 0, 14, 15, 16, 18, 19,
87 20, 0, 0, 21, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0,
89 0, 0, 0, 22, 23, 0, 0, 3,
90 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 24,
92 20, 0, 0, 21, 0, 19, 19, 0,
93 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 22, 25, 25, 0, 0,
95 0, 0, 0, 0, 26, 26, 0, 0,
96 0, 27, 28, 29, 31, 32, 33, 0,
97 0, 34, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 35, 33, 0, 0, 34, 0, 32,
100 32, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 35, 36, 37,
102 37, 0, 0, 0, 0, 0, 0, 38,
103 38, 0, 0, 0, 0, 39, 40, 42,
104 0, 0, 43, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0,
106 0, 0, 44, 42, 0, 0, 43, 0,
107 45, 45, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 0, 0, 0, 44, 46,
109 47, 48, 48, 0, 0, 0, 0, 0,
110 0, 49, 49, 0, 0, 0, 50, 51,
111 52, 54, 55, 56, 0, 0, 57, 0,
112 0, 0, 0, 0, 0, 0, 0, 0,
113 0, 0, 0, 0, 0, 0, 58, 56,
114 0, 0, 57, 0, 55, 55, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0,
116 0, 0, 58, 59, 59, 0, 0, 0,
117 0, 0, 0, 60, 60, 0, 0, 0,
118 61, 62, 63, 65, 66, 67, 0, 0,
119 68, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0,
121 69, 67, 0, 0, 68, 0, 66, 66,
122 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 69, 70, 70, 0,
124 0, 0, 0, 0, 0, 71, 71, 0,
125 72, 0, 0, 73, 74, 76, 75, 75,
126 75, 75, 75, 77, 79, 0, 0, 80,
127 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 81,
129 75, 0, 0, 0, 0, 0, 75, 83,
130 0, 0, 84, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 85, 83, 0, 0, 84, 0,
133 87, 87, 0, 0, 0, 0, 0, 0,
134 0, 0, 0, 0, 0, 0, 85, 88,
135 88, 0, 0, 0, 0, 0, 0, 89,
136 89, 0, 0, 0, 0, 90, 91, 83,
137 0, 0, 84, 0, 93, 93, 0, 0,
138 0, 0, 0, 0, 0, 0, 0, 0,
139 0, 0, 85, 94, 0, 0, 95, 0,
140 0, 0, 0, 0, 96, 1, 0, 0,
141 0, 0, 0, 0, 0, 0, 0, 0,
142 0, 0, 0, 0, 0, 0, 0, 2,
143 0
144 };
145
146 static const signed char _deserialize_json_index_defaults[] = {
147 0, 0, 0, 0, 0, 0, 0, 0,
148 0, 0, 0, 0, 0, 0, 0, 0,
149 0, 0, 0, 0, 0, 0, 0, 0,
150 0, 0, 0, 0, 0, 0, 0, 0,
151 0, 0, 0, 0, 0, 0, 0, 0,
152 75, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 0, 0
154 };
155
156 static const signed char _deserialize_json_cond_targs[] = {
157 0, 1, 2, 2, 3, 4, 18, 24,
158 37, 45, 5, 12, 6, 7, 8, 9,
159 11, 8, 9, 11, 10, 2, 49, 10,
160 49, 13, 14, 15, 16, 17, 15, 16,
161 17, 10, 2, 49, 19, 20, 21, 22,
162 23, 22, 10, 2, 49, 23, 25, 31,
163 26, 27, 28, 29, 30, 28, 29, 30,
164 10, 2, 49, 32, 33, 34, 35, 36,
165 34, 35, 36, 10, 2, 49, 38, 39,
166 40, 43, 44, 40, 41, 42, 41, 10,
167 2, 49, 43, 10, 2, 49, 44, 44,
168 46, 47, 43, 48, 48, 48, 49, 50,
169 51, 0
170 };
171
172 static const signed char _deserialize_json_cond_actions[] = {
173 0, 0, 1, 0, 0, 0, 0, 0,
174 0, 0, 0, 0, 0, 0, 2, 2,
175 2, 0, 0, 0, 3, 3, 4, 0,
176 5, 0, 0, 2, 2, 2, 0, 0,
177 0, 6, 6, 7, 0, 0, 0, 2,
178 2, 0, 8, 8, 9, 0, 0, 0,
179 0, 0, 2, 2, 2, 0, 0, 0,
180 10, 10, 11, 0, 0, 2, 2, 2,
181 0, 0, 0, 12, 12, 13, 0, 0,
182 2, 14, 14, 0, 15, 0, 0, 16,
183 16, 17, 0, 18, 18, 19, 0, 15,
184 0, 0, 20, 20, 0, 21, 0, 0,
185 0, 0
186 };
187
188 static const int deserialize_json_start = 1;
189 static const int deserialize_json_first_final = 49;
190 static const int deserialize_json_error = 0;
191
192 static const int deserialize_json_en_main = 1;
193
194
195 #line 108 "hb-buffer-deserialize-json.rl"
196
197
198 static hb_bool_t
_hb_buffer_deserialize_json(hb_buffer_t * buffer,const char * buf,unsigned int buf_len,const char ** end_ptr,hb_font_t * font)199 _hb_buffer_deserialize_json (hb_buffer_t *buffer,
200 const char *buf,
201 unsigned int buf_len,
202 const char **end_ptr,
203 hb_font_t *font)
204 {
205 const char *p = buf, *pe = buf + buf_len;
206
207 /* Ensure we have positions. */
208 (void) hb_buffer_get_glyph_positions (buffer, nullptr);
209
210 while (p < pe && ISSPACE (*p))
211 p++;
212 if (p < pe && *p == (buffer->len ? ',' : '['))
213 {
214 *end_ptr = ++p;
215 }
216
217 const char *tok = nullptr;
218 int cs;
219 hb_glyph_info_t info = {0};
220 hb_glyph_position_t pos = {0};
221
222 #line 223 "hb-buffer-deserialize-json.hh"
223 {
224 cs = (int)deserialize_json_start;
225 }
226
227 #line 228 "hb-buffer-deserialize-json.hh"
228 {
229 unsigned int _trans = 0;
230 const unsigned char * _keys;
231 const signed char * _inds;
232 int _ic;
233 _resume: {}
234 if ( p == pe )
235 goto _out;
236 _keys = ( _deserialize_json_trans_keys + ((cs<<1)));
237 _inds = ( _deserialize_json_indicies + (_deserialize_json_index_offsets[cs]));
238
239 if ( ( (*( p))) <= 125 && ( (*( p))) >= 9 ) {
240 _ic = (int)_deserialize_json_char_class[(int)( (*( p))) - 9];
241 if ( _ic <= (int)(*( _keys+1)) && _ic >= (int)(*( _keys)) )
242 _trans = (unsigned int)(*( _inds + (int)( _ic - (int)(*( _keys)) ) ));
243 else
244 _trans = (unsigned int)_deserialize_json_index_defaults[cs];
245 }
246 else {
247 _trans = (unsigned int)_deserialize_json_index_defaults[cs];
248 }
249
250 cs = (int)_deserialize_json_cond_targs[_trans];
251
252 if ( _deserialize_json_cond_actions[_trans] != 0 ) {
253
254 switch ( _deserialize_json_cond_actions[_trans] ) {
255 case 1: {
256 {
257 #line 38 "hb-buffer-deserialize-json.rl"
258
259 memset (&info, 0, sizeof (info));
260 memset (&pos , 0, sizeof (pos ));
261 }
262
263 #line 264 "hb-buffer-deserialize-json.hh"
264
265
266 break;
267 }
268 case 5: {
269 {
270 #line 43 "hb-buffer-deserialize-json.rl"
271
272 buffer->add_info (info);
273 if (unlikely (!buffer->successful))
274 return false;
275 buffer->pos[buffer->len - 1] = pos;
276 *end_ptr = p;
277 }
278
279 #line 280 "hb-buffer-deserialize-json.hh"
280
281
282 break;
283 }
284 case 2: {
285 {
286 #line 51 "hb-buffer-deserialize-json.rl"
287
288 tok = p;
289 }
290
291 #line 292 "hb-buffer-deserialize-json.hh"
292
293
294 break;
295 }
296 case 15: {
297 {
298 #line 55 "hb-buffer-deserialize-json.rl"
299 if (unlikely (!buffer->ensure_glyphs ())) return false; }
300
301 #line 302 "hb-buffer-deserialize-json.hh"
302
303
304 break;
305 }
306 case 21: {
307 {
308 #line 56 "hb-buffer-deserialize-json.rl"
309 if (unlikely (!buffer->ensure_unicode ())) return false; }
310
311 #line 312 "hb-buffer-deserialize-json.hh"
312
313
314 break;
315 }
316 case 16: {
317 {
318 #line 58 "hb-buffer-deserialize-json.rl"
319
320 /* TODO Unescape \" and \\ if found. */
321 if (!hb_font_glyph_from_string (font,
322 tok, p - tok,
323 &info.codepoint))
324 return false;
325 }
326
327 #line 328 "hb-buffer-deserialize-json.hh"
328
329
330 break;
331 }
332 case 18: {
333 {
334 #line 66 "hb-buffer-deserialize-json.rl"
335 if (!parse_uint (tok, p, &info.codepoint)) return false; }
336
337 #line 338 "hb-buffer-deserialize-json.hh"
338
339
340 break;
341 }
342 case 8: {
343 {
344 #line 67 "hb-buffer-deserialize-json.rl"
345 if (!parse_uint (tok, p, &info.cluster )) return false; }
346
347 #line 348 "hb-buffer-deserialize-json.hh"
348
349
350 break;
351 }
352 case 10: {
353 {
354 #line 68 "hb-buffer-deserialize-json.rl"
355 if (!parse_int (tok, p, &pos.x_offset )) return false; }
356
357 #line 358 "hb-buffer-deserialize-json.hh"
358
359
360 break;
361 }
362 case 12: {
363 {
364 #line 69 "hb-buffer-deserialize-json.rl"
365 if (!parse_int (tok, p, &pos.y_offset )) return false; }
366
367 #line 368 "hb-buffer-deserialize-json.hh"
368
369
370 break;
371 }
372 case 3: {
373 {
374 #line 70 "hb-buffer-deserialize-json.rl"
375 if (!parse_int (tok, p, &pos.x_advance)) return false; }
376
377 #line 378 "hb-buffer-deserialize-json.hh"
378
379
380 break;
381 }
382 case 6: {
383 {
384 #line 71 "hb-buffer-deserialize-json.rl"
385 if (!parse_int (tok, p, &pos.y_advance)) return false; }
386
387 #line 388 "hb-buffer-deserialize-json.hh"
388
389
390 break;
391 }
392 case 14: {
393 {
394 #line 51 "hb-buffer-deserialize-json.rl"
395
396 tok = p;
397 }
398
399 #line 400 "hb-buffer-deserialize-json.hh"
400
401 {
402 #line 55 "hb-buffer-deserialize-json.rl"
403 if (unlikely (!buffer->ensure_glyphs ())) return false; }
404
405 #line 406 "hb-buffer-deserialize-json.hh"
406
407
408 break;
409 }
410 case 20: {
411 {
412 #line 51 "hb-buffer-deserialize-json.rl"
413
414 tok = p;
415 }
416
417 #line 418 "hb-buffer-deserialize-json.hh"
418
419 {
420 #line 56 "hb-buffer-deserialize-json.rl"
421 if (unlikely (!buffer->ensure_unicode ())) return false; }
422
423 #line 424 "hb-buffer-deserialize-json.hh"
424
425
426 break;
427 }
428 case 17: {
429 {
430 #line 58 "hb-buffer-deserialize-json.rl"
431
432 /* TODO Unescape \" and \\ if found. */
433 if (!hb_font_glyph_from_string (font,
434 tok, p - tok,
435 &info.codepoint))
436 return false;
437 }
438
439 #line 440 "hb-buffer-deserialize-json.hh"
440
441 {
442 #line 43 "hb-buffer-deserialize-json.rl"
443
444 buffer->add_info (info);
445 if (unlikely (!buffer->successful))
446 return false;
447 buffer->pos[buffer->len - 1] = pos;
448 *end_ptr = p;
449 }
450
451 #line 452 "hb-buffer-deserialize-json.hh"
452
453
454 break;
455 }
456 case 19: {
457 {
458 #line 66 "hb-buffer-deserialize-json.rl"
459 if (!parse_uint (tok, p, &info.codepoint)) return false; }
460
461 #line 462 "hb-buffer-deserialize-json.hh"
462
463 {
464 #line 43 "hb-buffer-deserialize-json.rl"
465
466 buffer->add_info (info);
467 if (unlikely (!buffer->successful))
468 return false;
469 buffer->pos[buffer->len - 1] = pos;
470 *end_ptr = p;
471 }
472
473 #line 474 "hb-buffer-deserialize-json.hh"
474
475
476 break;
477 }
478 case 9: {
479 {
480 #line 67 "hb-buffer-deserialize-json.rl"
481 if (!parse_uint (tok, p, &info.cluster )) return false; }
482
483 #line 484 "hb-buffer-deserialize-json.hh"
484
485 {
486 #line 43 "hb-buffer-deserialize-json.rl"
487
488 buffer->add_info (info);
489 if (unlikely (!buffer->successful))
490 return false;
491 buffer->pos[buffer->len - 1] = pos;
492 *end_ptr = p;
493 }
494
495 #line 496 "hb-buffer-deserialize-json.hh"
496
497
498 break;
499 }
500 case 11: {
501 {
502 #line 68 "hb-buffer-deserialize-json.rl"
503 if (!parse_int (tok, p, &pos.x_offset )) return false; }
504
505 #line 506 "hb-buffer-deserialize-json.hh"
506
507 {
508 #line 43 "hb-buffer-deserialize-json.rl"
509
510 buffer->add_info (info);
511 if (unlikely (!buffer->successful))
512 return false;
513 buffer->pos[buffer->len - 1] = pos;
514 *end_ptr = p;
515 }
516
517 #line 518 "hb-buffer-deserialize-json.hh"
518
519
520 break;
521 }
522 case 13: {
523 {
524 #line 69 "hb-buffer-deserialize-json.rl"
525 if (!parse_int (tok, p, &pos.y_offset )) return false; }
526
527 #line 528 "hb-buffer-deserialize-json.hh"
528
529 {
530 #line 43 "hb-buffer-deserialize-json.rl"
531
532 buffer->add_info (info);
533 if (unlikely (!buffer->successful))
534 return false;
535 buffer->pos[buffer->len - 1] = pos;
536 *end_ptr = p;
537 }
538
539 #line 540 "hb-buffer-deserialize-json.hh"
540
541
542 break;
543 }
544 case 4: {
545 {
546 #line 70 "hb-buffer-deserialize-json.rl"
547 if (!parse_int (tok, p, &pos.x_advance)) return false; }
548
549 #line 550 "hb-buffer-deserialize-json.hh"
550
551 {
552 #line 43 "hb-buffer-deserialize-json.rl"
553
554 buffer->add_info (info);
555 if (unlikely (!buffer->successful))
556 return false;
557 buffer->pos[buffer->len - 1] = pos;
558 *end_ptr = p;
559 }
560
561 #line 562 "hb-buffer-deserialize-json.hh"
562
563
564 break;
565 }
566 case 7: {
567 {
568 #line 71 "hb-buffer-deserialize-json.rl"
569 if (!parse_int (tok, p, &pos.y_advance)) return false; }
570
571 #line 572 "hb-buffer-deserialize-json.hh"
572
573 {
574 #line 43 "hb-buffer-deserialize-json.rl"
575
576 buffer->add_info (info);
577 if (unlikely (!buffer->successful))
578 return false;
579 buffer->pos[buffer->len - 1] = pos;
580 *end_ptr = p;
581 }
582
583 #line 584 "hb-buffer-deserialize-json.hh"
584
585
586 break;
587 }
588 }
589
590 }
591
592 if ( cs != 0 ) {
593 p += 1;
594 goto _resume;
595 }
596 _out: {}
597 }
598
599 #line 136 "hb-buffer-deserialize-json.rl"
600
601
602 *end_ptr = p;
603
604 return p == pe && *(p-1) != ']';
605 }
606
607 #endif /* HB_BUFFER_DESERIALIZE_JSON_HH */
608