Bug 1883518 - Remove a bunch of unused ServoBindings.toml entries. r=firefox-style...
[gecko.git] / gfx / harfbuzz / src / hb-buffer-deserialize-text-glyphs.rl
blob21db14b568bbfd930d6218eb9599e21f5c2c3f60
1 /*
2  * Copyright © 2013  Google, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Google Author(s): Behdad Esfahbod
25  */
27 #ifndef HB_BUFFER_DESERIALIZE_TEXT_GLYPHS_HH
28 #define HB_BUFFER_DESERIALIZE_TEXT_GLYPHS_HH
30 #include "hb.hh"
32 %%{
34 machine deserialize_text_glyphs;
35 alphtype unsigned char;
36 write data;
38 action clear_item {
39         hb_memset (&info, 0, sizeof (info));
40         hb_memset (&pos , 0, sizeof (pos ));
43 action add_item {
44         buffer->add_info (info);
45         if (unlikely (!buffer->successful))
46           return false;
47         buffer->pos[buffer->len - 1] = pos;
48         *end_ptr = p;
51 action tok {
52         tok = p;
55 action parse_glyph {
56         /* TODO Unescape delimiters. */
57         if (!hb_font_glyph_from_string (font,
58                                         tok, p - tok,
59                                         &info.codepoint))
60           return false;
63 action parse_cluster    { if (!parse_uint (tok, p, &info.cluster )) return false; }
64 action parse_x_offset   { if (!parse_int  (tok, p, &pos.x_offset )) return false; }
65 action parse_y_offset   { if (!parse_int  (tok, p, &pos.y_offset )) return false; }
66 action parse_x_advance  { if (!parse_int  (tok, p, &pos.x_advance)) return false; }
67 action parse_y_advance  { if (!parse_int  (tok, p, &pos.y_advance)) return false; }
68 action parse_glyph_flags{ if (!parse_uint (tok, p, &info.mask    )) return false; }
70 unum  = '0' | [1-9] digit*;
71 num     = '-'? unum;
73 glyph_id = unum;
74 glyph_name = ([^\\\]=@+,#|] | '\\' [\\\]=@+,|]) *;
76 glyph   = (glyph_id | glyph_name) >tok %parse_glyph;
77 cluster = '=' (unum >tok %parse_cluster);
78 offsets = '@' (num >tok %parse_x_offset)   ',' (num >tok %parse_y_offset );
79 advances= '+' (num >tok %parse_x_advance) (',' (num >tok %parse_y_advance))?;
80 glyphflags= '#' (unum >tok %parse_glyph_flags);
82 glyph_item      =
83         (
84                 glyph
85                 cluster?
86                 offsets?
87                 advances?
88                 glyphflags?
89         )
90         >clear_item
91         %add_item
92         ;
94 glyphs = glyph_item (space* '|' space* glyph_item)* space*;
96 main := space* glyphs;
98 }%%
100 static hb_bool_t
101 _hb_buffer_deserialize_text_glyphs (hb_buffer_t *buffer,
102                                     const char *buf,
103                                     unsigned int buf_len,
104                                     const char **end_ptr,
105                                     hb_font_t *font)
107   const char *p = buf, *pe = buf + buf_len, *eof = pe, *orig_pe = pe;
109   /* Ensure we have positions. */
110   (void) hb_buffer_get_glyph_positions (buffer, nullptr);
112   while (p < pe && ISSPACE (*p))
113     p++;
114   if (p < pe && *p == (buffer->len ? '|' : '['))
115     *end_ptr = ++p;
117   const char *end = strchr ((char *) p, ']');
118   if (end)
119     pe = eof = end;
120   else
121   {
122     end = strrchr ((char *) p, '|');
123     if (end)
124       pe = eof = end;
125     else
126       pe = eof = p;
127   }
129   const char *tok = nullptr;
130   int cs;
131   hb_glyph_info_t info = {0};
132   hb_glyph_position_t pos = {0};
133   %%{
134     write init;
135     write exec;
136   }%%
138   if (pe < orig_pe && *pe == ']')
139   {
140     pe++;
141     if (p == pe)
142       p++;
143   }
145   *end_ptr = p;
147   return p == pe;
150 #endif /* HB_BUFFER_DESERIALIZE_TEXT_GLYPHS_HH */