Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/harfbuzz/util/shape-output.hh @ 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 © 2010 Behdad Esfahbod | |
| 3 * Copyright © 2011,2012 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_SHAPE_OUTPUT_HH | |
| 29 #define HB_SHAPE_OUTPUT_HH | |
| 30 | |
| 31 #include "shape-format.hh" | |
| 32 #include "output-options.hh" | |
| 33 | |
| 34 | |
| 35 struct shape_output_t : output_options_t<> | |
| 36 { | |
| 37 void add_options (option_parser_t *parser) | |
| 38 { | |
| 39 parser->set_summary ("Shape text with given font."); | |
| 40 output_options_t::add_options (parser, hb_buffer_serialize_list_formats ()); | |
| 41 format.add_options (parser); | |
| 42 } | |
| 43 | |
| 44 void init (hb_buffer_t *buffer, const font_options_t *font_opts) | |
| 45 { | |
| 46 gs = g_string_new (nullptr); | |
| 47 line_no = 0; | |
| 48 font = hb_font_reference (font_opts->font); | |
| 49 | |
| 50 if (!output_format) | |
| 51 serialize_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; | |
| 52 else | |
| 53 serialize_format = hb_buffer_serialize_format_from_string (output_format, -1); | |
| 54 /* An empty "output_format" parameter basically skips output generating. | |
| 55 * Useful for benchmarking. */ | |
| 56 if ((!output_format || *output_format) && | |
| 57 !hb_buffer_serialize_format_to_string (serialize_format)) | |
| 58 { | |
| 59 if (explicit_output_format) | |
| 60 fail (false, "Unknown output format `%s'; supported formats are: %s", | |
| 61 output_format, | |
| 62 g_strjoinv ("/", const_cast<char**> (hb_buffer_serialize_list_formats ()))); | |
| 63 else | |
| 64 /* Just default to TEXT if not explicitly requested and the | |
| 65 * file extension is not recognized. */ | |
| 66 serialize_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; | |
| 67 } | |
| 68 | |
| 69 unsigned int flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT; | |
| 70 if (!format.show_glyph_names) | |
| 71 flags |= HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES; | |
| 72 if (!format.show_clusters) | |
| 73 flags |= HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS; | |
| 74 if (!format.show_positions) | |
| 75 flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS; | |
| 76 if (!format.show_advances) | |
| 77 flags |= HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES; | |
| 78 if (format.show_extents) | |
| 79 flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS; | |
| 80 if (format.show_flags) | |
| 81 flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS; | |
| 82 serialize_flags = (hb_buffer_serialize_flags_t) flags; | |
| 83 | |
| 84 if (format.trace) | |
| 85 hb_buffer_set_message_func (buffer, message_func, this, nullptr); | |
| 86 } | |
| 87 void new_line () { line_no++; } | |
| 88 void consume_text (hb_buffer_t *buffer, | |
| 89 const char *text, | |
| 90 unsigned int text_len, | |
| 91 hb_bool_t utf8_clusters) | |
| 92 { | |
| 93 g_string_set_size (gs, 0); | |
| 94 format.serialize_buffer_of_text (buffer, line_no, text, text_len, font, gs); | |
| 95 fprintf (out_fp, "%s", gs->str); | |
| 96 } | |
| 97 void error (const char *message) | |
| 98 { | |
| 99 g_string_set_size (gs, 0); | |
| 100 format.serialize_message (line_no, "error", message, gs); | |
| 101 fprintf (out_fp, "%s", gs->str); | |
| 102 } | |
| 103 void consume_glyphs (hb_buffer_t *buffer, | |
| 104 const char *text, | |
| 105 unsigned int text_len, | |
| 106 hb_bool_t utf8_clusters) | |
| 107 { | |
| 108 g_string_set_size (gs, 0); | |
| 109 format.serialize_buffer_of_glyphs (buffer, line_no, text, text_len, font, | |
| 110 serialize_format, serialize_flags, gs); | |
| 111 fprintf (out_fp, "%s", gs->str); | |
| 112 } | |
| 113 void finish (hb_buffer_t *buffer, const font_options_t *font_opts) | |
| 114 { | |
| 115 hb_buffer_set_message_func (buffer, nullptr, nullptr, nullptr); | |
| 116 hb_font_destroy (font); | |
| 117 g_string_free (gs, true); | |
| 118 gs = nullptr; | |
| 119 font = nullptr; | |
| 120 } | |
| 121 | |
| 122 static hb_bool_t | |
| 123 message_func (hb_buffer_t *buffer, | |
| 124 hb_font_t *font, | |
| 125 const char *message, | |
| 126 void *user_data) | |
| 127 { | |
| 128 shape_output_t *that = (shape_output_t *) user_data; | |
| 129 that->trace (buffer, font, message); | |
| 130 return true; | |
| 131 } | |
| 132 | |
| 133 void | |
| 134 trace (hb_buffer_t *buffer, | |
| 135 hb_font_t *font, | |
| 136 const char *message) | |
| 137 { | |
| 138 g_string_set_size (gs, 0); | |
| 139 format.serialize_line_no (line_no, gs); | |
| 140 g_string_append_printf (gs, "trace: %s buffer: ", message); | |
| 141 format.serialize (buffer, font, serialize_format, serialize_flags, gs); | |
| 142 g_string_append_c (gs, '\n'); | |
| 143 fprintf (out_fp, "%s", gs->str); | |
| 144 } | |
| 145 | |
| 146 | |
| 147 protected: | |
| 148 | |
| 149 shape_format_options_t format; | |
| 150 | |
| 151 GString *gs = nullptr; | |
| 152 unsigned int line_no = 0; | |
| 153 hb_font_t *font = nullptr; | |
| 154 hb_buffer_serialize_format_t serialize_format = HB_BUFFER_SERIALIZE_FORMAT_INVALID; | |
| 155 hb_buffer_serialize_flags_t serialize_flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT; | |
| 156 }; | |
| 157 | |
| 158 | |
| 159 #endif |
