tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

hb-buffer-deserialize-text-glyphs.rl (3442B)


      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 */
     26 
     27 #ifndef HB_BUFFER_DESERIALIZE_TEXT_GLYPHS_HH
     28 #define HB_BUFFER_DESERIALIZE_TEXT_GLYPHS_HH
     29 
     30 #include "hb.hh"
     31 
     32 %%{
     33 
     34 machine deserialize_text_glyphs;
     35 alphtype unsigned char;
     36 write data;
     37 
     38 action clear_item {
     39 hb_memset (&info, 0, sizeof (info));
     40 hb_memset (&pos , 0, sizeof (pos ));
     41 }
     42 
     43 action add_item {
     44 buffer->add_info_and_pos (info, pos);
     45 if (unlikely (!buffer->successful))
     46   return false;
     47 *end_ptr = p;
     48 }
     49 
     50 action tok {
     51 tok = p;
     52 }
     53 
     54 action parse_glyph {
     55 /* TODO Unescape delimiters. */
     56 if (!hb_font_glyph_from_string (font,
     57 				tok, p - tok,
     58 				&info.codepoint))
     59   return false;
     60 }
     61 
     62 action parse_cluster	{ if (!parse_uint (tok, p, &info.cluster )) return false; }
     63 action parse_x_offset	{ if (!parse_int  (tok, p, &pos.x_offset )) return false; }
     64 action parse_y_offset	{ if (!parse_int  (tok, p, &pos.y_offset )) return false; }
     65 action parse_x_advance	{ if (!parse_int  (tok, p, &pos.x_advance)) return false; }
     66 action parse_y_advance	{ if (!parse_int  (tok, p, &pos.y_advance)) return false; }
     67 action parse_glyph_flags{ if (!parse_uint (tok, p, &info.mask    )) return false; }
     68 
     69 unum  = '0' | [1-9] digit*;
     70 num	= '-'? unum;
     71 
     72 glyph_id = unum;
     73 glyph_name = ([^\\\]=@+,#|] | '\\' [\\\]=@+,|]) *;
     74 
     75 glyph	= (glyph_id | glyph_name) >tok %parse_glyph;
     76 cluster	= '=' (unum >tok %parse_cluster);
     77 offsets	= '@' (num >tok %parse_x_offset)   ',' (num >tok %parse_y_offset );
     78 advances= '+' (num >tok %parse_x_advance) (',' (num >tok %parse_y_advance))?;
     79 glyphflags = '#' (unum >tok %parse_glyph_flags);
     80 # Not parsed. Ignored.
     81 glyphextents = '<' (num ',' num ',' num ',' num) '>';
     82 
     83 glyph_item	=
     84 (
     85 	glyph
     86 	cluster?
     87 	offsets?
     88 	advances?
     89 	glyphflags?
     90 	glyphextents?
     91 	( '|' | ']')
     92 )
     93 >clear_item
     94 %add_item
     95 ;
     96 
     97 glyphs = '['? glyph_item* ;
     98 
     99 main := glyphs;
    100 
    101 }%%
    102 
    103 static hb_bool_t
    104 _hb_buffer_deserialize_text_glyphs (hb_buffer_t *buffer,
    105 			    const char *buf,
    106 			    unsigned int buf_len,
    107 			    const char **end_ptr,
    108 			    hb_font_t *font)
    109 {
    110  const char *p = buf, *pe = buf + buf_len, *eof = pe;
    111 
    112  /* Ensure we have positions. */
    113  (void) hb_buffer_get_glyph_positions (buffer, nullptr);
    114 
    115  const char *tok = nullptr;
    116  int cs;
    117  hb_glyph_info_t info = {0};
    118  hb_glyph_position_t pos = {0};
    119  %%{
    120    write init;
    121    write exec;
    122  }%%
    123 
    124  *end_ptr = p;
    125 
    126  return p == pe;
    127 }
    128 
    129 #endif /* HB_BUFFER_DESERIALIZE_TEXT_GLYPHS_HH */