Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/harfbuzz/src/hb-buffer-deserialize-text.rl @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 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_HH | |
| 28 #define HB_BUFFER_DESERIALIZE_TEXT_HH | |
| 29 | |
| 30 #include "hb.hh" | |
| 31 | |
| 32 %%{ | |
| 33 | |
| 34 machine deserialize_text; | |
| 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 (info); | |
| 45 if (unlikely (!buffer->successful)) | |
| 46 return false; | |
| 47 buffer->pos[buffer->len - 1] = pos; | |
| 48 *end_ptr = p; | |
| 49 } | |
| 50 | |
| 51 action tok { | |
| 52 tok = p; | |
| 53 } | |
| 54 | |
| 55 action ensure_glyphs { if (unlikely (!buffer->ensure_glyphs ())) return false; } | |
| 56 action ensure_unicode { if (unlikely (!buffer->ensure_unicode ())) return false; } | |
| 57 | |
| 58 action parse_glyph { | |
| 59 /* TODO Unescape delimiters. */ | |
| 60 if (!hb_font_glyph_from_string (font, | |
| 61 tok, p - tok, | |
| 62 &info.codepoint)) | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 action parse_hexdigits {if (!parse_hex (tok, p, &info.codepoint )) return false; } | |
| 67 | |
| 68 action parse_cluster { if (!parse_uint (tok, p, &info.cluster )) return false; } | |
| 69 action parse_x_offset { if (!parse_int (tok, p, &pos.x_offset )) return false; } | |
| 70 action parse_y_offset { if (!parse_int (tok, p, &pos.y_offset )) return false; } | |
| 71 action parse_x_advance { if (!parse_int (tok, p, &pos.x_advance)) return false; } | |
| 72 action parse_y_advance { if (!parse_int (tok, p, &pos.y_advance)) return false; } | |
| 73 action parse_glyph_flags{ if (!parse_uint (tok, p, &info.mask )) return false; } | |
| 74 | |
| 75 unum = '0' | [1-9] digit*; | |
| 76 num = '-'? unum; | |
| 77 | |
| 78 glyph_id = unum; | |
| 79 glyph_name = ([^\\\]=@+,#|] | '\\' [\\\]=@+,|]) *; | |
| 80 | |
| 81 glyph = (glyph_id | glyph_name) >tok %parse_glyph; | |
| 82 cluster = '=' (unum >tok %parse_cluster); | |
| 83 offsets = '@' (num >tok %parse_x_offset) ',' (num >tok %parse_y_offset ); | |
| 84 advances= '+' (num >tok %parse_x_advance) (',' (num >tok %parse_y_advance))?; | |
| 85 glyphflags= '#' (unum >tok %parse_glyph_flags); | |
| 86 | |
| 87 glyph_item = | |
| 88 ( | |
| 89 glyph | |
| 90 cluster? | |
| 91 offsets? | |
| 92 advances? | |
| 93 glyphflags? | |
| 94 ) | |
| 95 >clear_item | |
| 96 @ensure_glyphs | |
| 97 %add_item | |
| 98 ; | |
| 99 | |
| 100 unicode = 'U' '+' xdigit+ >tok %parse_hexdigits; | |
| 101 | |
| 102 unicode_item = | |
| 103 ( | |
| 104 unicode | |
| 105 cluster? | |
| 106 ) | |
| 107 >clear_item | |
| 108 @ensure_unicode | |
| 109 %add_item | |
| 110 ; | |
| 111 | |
| 112 glyphs = glyph_item (space* '|' space* glyph_item)* space* ('|'|']')?; | |
| 113 unicodes = unicode_item (space* '|' space* unicode_item)* space* ('|'|'>')?; | |
| 114 | |
| 115 main := space* ( ('[' glyphs) | ('<' unicodes) ); | |
| 116 | |
| 117 }%% | |
| 118 | |
| 119 static hb_bool_t | |
| 120 _hb_buffer_deserialize_text (hb_buffer_t *buffer, | |
| 121 const char *buf, | |
| 122 unsigned int buf_len, | |
| 123 const char **end_ptr, | |
| 124 hb_font_t *font) | |
| 125 { | |
| 126 const char *p = buf, *pe = buf + buf_len; | |
| 127 | |
| 128 /* Ensure we have positions. */ | |
| 129 (void) hb_buffer_get_glyph_positions (buffer, nullptr); | |
| 130 | |
| 131 while (p < pe && ISSPACE (*p)) | |
| 132 p++; | |
| 133 | |
| 134 const char *eof = pe, *tok = nullptr; | |
| 135 int cs; | |
| 136 hb_glyph_info_t info = {0}; | |
| 137 hb_glyph_position_t pos = {0}; | |
| 138 %%{ | |
| 139 write init; | |
| 140 write exec; | |
| 141 }%% | |
| 142 | |
| 143 *end_ptr = p; | |
| 144 | |
| 145 return p == pe && *(p-1) != ']'; | |
| 146 } | |
| 147 | |
| 148 #endif /* HB_BUFFER_DESERIALIZE_TEXT_HH */ |
