1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-buffer-deserialize-text.rl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,126 @@ 1.4 +/* 1.5 + * Copyright © 2013 Google, Inc. 1.6 + * 1.7 + * This is part of HarfBuzz, a text shaping library. 1.8 + * 1.9 + * Permission is hereby granted, without written agreement and without 1.10 + * license or royalty fees, to use, copy, modify, and distribute this 1.11 + * software and its documentation for any purpose, provided that the 1.12 + * above copyright notice and the following two paragraphs appear in 1.13 + * all copies of this software. 1.14 + * 1.15 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.16 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.17 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.18 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.19 + * DAMAGE. 1.20 + * 1.21 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.22 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.23 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.24 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.25 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.26 + * 1.27 + * Google Author(s): Behdad Esfahbod 1.28 + */ 1.29 + 1.30 +#ifndef HB_BUFFER_DESERIALIZE_TEXT_HH 1.31 +#define HB_BUFFER_DESERIALIZE_TEXT_HH 1.32 + 1.33 +#include "hb-private.hh" 1.34 + 1.35 +%%{ 1.36 + 1.37 +machine deserialize_text; 1.38 +alphtype unsigned char; 1.39 +write data; 1.40 + 1.41 +action clear_item { 1.42 + memset (&info, 0, sizeof (info)); 1.43 + memset (&pos , 0, sizeof (pos )); 1.44 +} 1.45 + 1.46 +action add_item { 1.47 + buffer->add_info (info); 1.48 + if (buffer->in_error) 1.49 + return false; 1.50 + buffer->pos[buffer->len - 1] = pos; 1.51 + *end_ptr = p; 1.52 +} 1.53 + 1.54 +action tok { 1.55 + tok = p; 1.56 +} 1.57 + 1.58 +action parse_glyph { 1.59 + if (!hb_font_glyph_from_string (font, 1.60 + tok, p - tok, 1.61 + &info.codepoint)) 1.62 + return false; 1.63 +} 1.64 + 1.65 +action parse_cluster { if (!parse_uint (tok, p, &info.cluster )) return false; } 1.66 +action parse_x_offset { if (!parse_int (tok, p, &pos.x_offset )) return false; } 1.67 +action parse_y_offset { if (!parse_int (tok, p, &pos.y_offset )) return false; } 1.68 +action parse_x_advance { if (!parse_int (tok, p, &pos.x_advance)) return false; } 1.69 +action parse_y_advance { if (!parse_int (tok, p, &pos.y_advance)) return false; } 1.70 + 1.71 +unum = '0' | [1-9] digit*; 1.72 +num = '-'? unum; 1.73 + 1.74 +glyph_id = unum; 1.75 +glyph_name = alpha (alnum|'_'|'.'|'-')*; 1.76 + 1.77 +glyph = (glyph_id | glyph_name) >tok %parse_glyph; 1.78 +cluster = '=' (unum >tok %parse_cluster); 1.79 +offsets = '@' (num >tok %parse_x_offset) ',' (num >tok %parse_y_offset ); 1.80 +advances= '+' (num >tok %parse_x_advance) (',' (num >tok %parse_y_advance))?; 1.81 +item = 1.82 + ( 1.83 + glyph 1.84 + cluster? 1.85 + offsets? 1.86 + advances? 1.87 + ) 1.88 + >clear_item 1.89 + %add_item 1.90 + ; 1.91 + 1.92 +main := space* item (space* '|' space* item)* space* ('|'|']')?; 1.93 + 1.94 +}%% 1.95 + 1.96 +static hb_bool_t 1.97 +_hb_buffer_deserialize_glyphs_text (hb_buffer_t *buffer, 1.98 + const char *buf, 1.99 + unsigned int buf_len, 1.100 + const char **end_ptr, 1.101 + hb_font_t *font) 1.102 +{ 1.103 + const char *p = buf, *pe = buf + buf_len; 1.104 + 1.105 + /* Ensure we have positions. */ 1.106 + (void) hb_buffer_get_glyph_positions (buffer, NULL); 1.107 + 1.108 + while (p < pe && ISSPACE (*p)) 1.109 + p++; 1.110 + if (p < pe && *p == (buffer->len ? '|' : '[')) 1.111 + { 1.112 + *end_ptr = ++p; 1.113 + } 1.114 + 1.115 + const char *eof = pe, *tok = NULL; 1.116 + int cs; 1.117 + hb_glyph_info_t info; 1.118 + hb_glyph_position_t pos; 1.119 + %%{ 1.120 + write init; 1.121 + write exec; 1.122 + }%% 1.123 + 1.124 + *end_ptr = p; 1.125 + 1.126 + return p == pe && *(p-1) != ']'; 1.127 +} 1.128 + 1.129 +#endif /* HB_BUFFER_DESERIALIZE_TEXT_HH */