13bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod/* 28f8956a55fff95e5ad529d2f124c9528d1f4f81dBehdad Esfahbod * Copyright © 2011,2012 Google, Inc. 33bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * 43bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * This is part of HarfBuzz, a text shaping library. 53bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * 63bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * Permission is hereby granted, without written agreement and without 73bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this 83bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * software and its documentation for any purpose, provided that the 93bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * above copyright notice and the following two paragraphs appear in 103bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * all copies of this software. 113bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * 123bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 133bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 143bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 153bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 163bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * DAMAGE. 173bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * 183bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 193bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 203bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 213bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 223bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 233bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * 243bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * Google Author(s): Behdad Esfahbod 253bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod */ 263bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 273bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod#include "options.hh" 283bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 295ddd9cc499f2470eca239ae357a5c8a3626c0809Behdad Esfahbod#ifdef HAVE_FREETYPE 30b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod#include <hb-ft.h> 31b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod#endif 323bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 333bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 348b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbodvoid 358b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbodfail (hb_bool_t suggest_help, const char *format, ...) 368b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod{ 378b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod const char *msg; 388b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 398b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod va_list vap; 408b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod va_start (vap, format); 418b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod msg = g_strdup_vprintf (format, vap); 428b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod const char *prgname = g_get_prgname (); 438b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod g_printerr ("%s: %s\n", prgname, msg); 448b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod if (suggest_help) 458b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod g_printerr ("Try `%s --help' for more information.\n", prgname); 468b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 478b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod exit (1); 488b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod} 498b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 508b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 510594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbodhb_bool_t debug = false; 52b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 53b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstatic gchar * 54b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodshapers_to_string (void) 55b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 56b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GString *shapers = g_string_new (NULL); 57b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod const char **shaper_list = hb_shape_list_shapers (); 58b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 59b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod for (; *shaper_list; shaper_list++) { 60b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_string_append (shapers, *shaper_list); 61b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_string_append_c (shapers, ','); 62b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 63b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_string_truncate (shapers, MAX (0, (gint)shapers->len - 1)); 64b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 650594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return g_string_free (shapers, false); 66b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 67b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 68b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstatic G_GNUC_NORETURN gboolean 69b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodshow_version (const char *name G_GNUC_UNUSED, 70b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod const char *arg G_GNUC_UNUSED, 71b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod gpointer data G_GNUC_UNUSED, 72b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GError **error G_GNUC_UNUSED) 73b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 74b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_printf ("%s (%s) %s\n", g_get_prgname (), PACKAGE_NAME, PACKAGE_VERSION); 75b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 76b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod char *shapers = shapers_to_string (); 77b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_printf ("Available shapers: %s\n", shapers); 78b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_free (shapers); 79b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod if (strcmp (HB_VERSION_STRING, hb_version_string ())) 80b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_printf ("Linked HarfBuzz library has a different version: %s\n", hb_version_string ()); 81b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 82b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod exit(0); 83b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 84b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 85b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 86b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodvoid 87b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodoption_parser_t::add_main_options (void) 88b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 89b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GOptionEntry entries[] = 90b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod { 91b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod {"version", 0, G_OPTION_FLAG_NO_ARG, 92b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod G_OPTION_ARG_CALLBACK, (gpointer) &show_version, "Show version numbers", NULL}, 93b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod {"debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Free all resources before exit", NULL}, 94b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod {NULL} 95b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod }; 96b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_option_context_add_main_entries (context, entries, NULL); 97b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 98b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 99b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstatic gboolean 100b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodpre_parse (GOptionContext *context G_GNUC_UNUSED, 101b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GOptionGroup *group G_GNUC_UNUSED, 102b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod gpointer data, 103b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GError **error) 104b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 105b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod option_group_t *option_group = (option_group_t *) data; 106b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod option_group->pre_parse (error); 107b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod return *error == NULL; 108b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 109b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 110b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstatic gboolean 111b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodpost_parse (GOptionContext *context G_GNUC_UNUSED, 112b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GOptionGroup *group G_GNUC_UNUSED, 113b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod gpointer data, 114b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GError **error) 115b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 116b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod option_group_t *option_group = static_cast<option_group_t *>(data); 117b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod option_group->post_parse (error); 118b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod return *error == NULL; 119b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 120b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 121b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodvoid 122b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodoption_parser_t::add_group (GOptionEntry *entries, 123b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod const gchar *name, 124b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod const gchar *description, 125b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod const gchar *help_description, 126b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod option_group_t *option_group) 127b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 128b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GOptionGroup *group = g_option_group_new (name, description, help_description, 129b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod static_cast<gpointer>(option_group), NULL); 130b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_option_group_add_entries (group, entries); 131b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_option_group_set_parse_hooks (group, pre_parse, post_parse); 132b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_option_context_add_group (context, group); 133b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 134b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 135b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodvoid 136b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodoption_parser_t::parse (int *argc, char ***argv) 137b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 1388b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod setlocale (LC_ALL, ""); 1398b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 140b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GError *parse_error = NULL; 141b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod if (!g_option_context_parse (context, argc, argv, &parse_error)) 142b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod { 143a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod if (parse_error != NULL) { 1440594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (true, "%s", parse_error->message); 145a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod //g_error_free (parse_error); 146a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod } else 1470594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (true, "Option parse error"); 148b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 149b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 1503bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 1513bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 1523bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbodstatic gboolean 1533bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbodparse_margin (const char *name G_GNUC_UNUSED, 1543bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod const char *arg, 155bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod gpointer data, 1563bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod GError **error G_GNUC_UNUSED) 1573bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod{ 158bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod view_options_t *view_opts = (view_options_t *) data; 1593bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod view_options_t::margin_t &m = view_opts->margin; 16097796453aab56873809a15b5e316cba8acea7449Behdad Esfahbod switch (sscanf (arg, "%lf %lf %lf %lf", &m.t, &m.r, &m.b, &m.l)) { 1613bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod case 1: m.r = m.t; 1623bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod case 2: m.b = m.t; 1633bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod case 3: m.l = m.r; 1640594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod case 4: return true; 1653bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod default: 1663bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, 1673bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod "%s argument should be one to four space-separated numbers", 1683bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod name); 1690594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return false; 1703bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod } 1713bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod} 1723bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 1733bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 1743bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbodstatic gboolean 1753bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbodparse_shapers (const char *name G_GNUC_UNUSED, 1763bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod const char *arg, 177bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod gpointer data, 1783bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod GError **error G_GNUC_UNUSED) 1793bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod{ 180bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod shape_options_t *shape_opts = (shape_options_t *) data; 181ade7459ea7c75b4f33f7cfa43dd5bdfa0c18d6d5Behdad Esfahbod g_strfreev (shape_opts->shapers); 1823bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod shape_opts->shapers = g_strsplit (arg, ",", 0); 1830594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return true; 1843bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod} 1853bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 186fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbodstatic G_GNUC_NORETURN gboolean 187fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbodlist_shapers (const char *name G_GNUC_UNUSED, 188fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod const char *arg G_GNUC_UNUSED, 189fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod gpointer data G_GNUC_UNUSED, 190fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod GError **error G_GNUC_UNUSED) 191fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod{ 192fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod for (const char **shaper = hb_shape_list_shapers (); *shaper; shaper++) 193fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod g_printf ("%s\n", *shaper); 194fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod 195fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod exit(0); 196fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod} 197fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod 198fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod 1993bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbodstatic gboolean 2003bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbodparse_features (const char *name G_GNUC_UNUSED, 2013bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod const char *arg, 202bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod gpointer data, 2033bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod GError **error G_GNUC_UNUSED) 2043bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod{ 205bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod shape_options_t *shape_opts = (shape_options_t *) data; 2063bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod char *s = (char *) arg; 2073bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod char *p; 2083bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 2093bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod shape_opts->num_features = 0; 2108f8956a55fff95e5ad529d2f124c9528d1f4f81dBehdad Esfahbod g_free (shape_opts->features); 2113bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod shape_opts->features = NULL; 2123bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 2133bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod if (!*s) 2140594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return true; 2153bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 2163bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod /* count the features first, so we can allocate memory */ 2173bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod p = s; 2183bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod do { 2193bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod shape_opts->num_features++; 2203bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod p = strchr (p, ','); 2213bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod if (p) 2223bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod p++; 2233bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod } while (p); 2243bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 2253bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod shape_opts->features = (hb_feature_t *) calloc (shape_opts->num_features, sizeof (*shape_opts->features)); 2263bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 2273bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod /* now do the actual parsing */ 2283bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod p = s; 2293bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod shape_opts->num_features = 0; 230e30ebd2794b37bd8ec716a258d5cb017fb1dfadcBehdad Esfahbod while (p && *p) { 231e30ebd2794b37bd8ec716a258d5cb017fb1dfadcBehdad Esfahbod char *end = strchr (p, ','); 232e30ebd2794b37bd8ec716a258d5cb017fb1dfadcBehdad Esfahbod if (hb_feature_from_string (p, end ? end - p : -1, &shape_opts->features[shape_opts->num_features])) 2333bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod shape_opts->num_features++; 234e30ebd2794b37bd8ec716a258d5cb017fb1dfadcBehdad Esfahbod p = end ? end + 1 : NULL; 2353bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod } 2363bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 2370594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return true; 2383bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod} 2393bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 2403bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 2413bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbodvoid 242b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodview_options_t::add_options (option_parser_t *parser) 2433bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod{ 2443bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod GOptionEntry entries[] = 2453bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod { 246bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod {"annotate", 0, 0, G_OPTION_ARG_NONE, &this->annotate, "Annotate output rendering", NULL}, 2479a34a50daac3563464e0031f377e85f0c704f2d6Behdad Esfahbod {"background", 0, 0, G_OPTION_ARG_STRING, &this->back, "Set background color (default: " DEFAULT_BACK ")", "red/#rrggbb/#rrggbbaa"}, 2489a34a50daac3563464e0031f377e85f0c704f2d6Behdad Esfahbod {"foreground", 0, 0, G_OPTION_ARG_STRING, &this->fore, "Set foreground color (default: " DEFAULT_FORE ")", "red/#rrggbb/#rrggbbaa"}, 249bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod {"line-space", 0, 0, G_OPTION_ARG_DOUBLE, &this->line_space, "Set space between lines (default: 0)", "units"}, 2509a34a50daac3563464e0031f377e85f0c704f2d6Behdad Esfahbod {"margin", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_margin, "Margin around output (default: " G_STRINGIFY(DEFAULT_MARGIN) ")","one to four numbers"}, 2519a34a50daac3563464e0031f377e85f0c704f2d6Behdad Esfahbod {"font-size", 0, 0, G_OPTION_ARG_DOUBLE, &this->font_size, "Font size (default: " G_STRINGIFY(DEFAULT_FONT_SIZE) ")","size"}, 252109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod {NULL} 253109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod }; 254b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod parser->add_group (entries, 255b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "view", 256b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "View options:", 25730874b4819a99cc84fa39e794266685e1b8735d2Behdad Esfahbod "Options controlling output rendering", 258b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod this); 259109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod} 2603bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 261109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbodvoid 262b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodshape_options_t::add_options (option_parser_t *parser) 263109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod{ 264109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod GOptionEntry entries[] = 265109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod { 266fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod {"list-shapers", 0, G_OPTION_FLAG_NO_ARG, 267fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod G_OPTION_ARG_CALLBACK, (gpointer) &list_shapers, "List available shapers and quit", NULL}, 2688f8956a55fff95e5ad529d2f124c9528d1f4f81dBehdad Esfahbod {"shaper", 0, G_OPTION_FLAG_HIDDEN, 2698f8956a55fff95e5ad529d2f124c9528d1f4f81dBehdad Esfahbod G_OPTION_ARG_CALLBACK, (gpointer) &parse_shapers, "Hidden duplicate of --shapers", NULL}, 270fd528c17b7b5ac912f1ac980e1d9981f561c3b46Behdad Esfahbod {"shapers", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_shapers, "Comma-separated list of shapers to try","list"}, 271bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod {"direction", 0, 0, G_OPTION_ARG_STRING, &this->direction, "Set text direction (default: auto)", "ltr/rtl/ttb/btt"}, 272bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod {"language", 0, 0, G_OPTION_ARG_STRING, &this->language, "Set text language (default: $LANG)", "langstr"}, 273bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod {"script", 0, 0, G_OPTION_ARG_STRING, &this->script, "Set text script (default: auto)", "ISO-15924 tag"}, 274407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod {"bot", 0, 0, G_OPTION_ARG_NONE, &this->bot, "Treat text as beginning-of-paragraph", NULL}, 275407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod {"eot", 0, 0, G_OPTION_ARG_NONE, &this->eot, "Treat text as end-of-paragraph", NULL}, 276407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod {"preserve-default-ignorables",0, 0, G_OPTION_ARG_NONE, &this->preserve_default_ignorables, "Preserve Default-Ignorable characters", NULL}, 27730874b4819a99cc84fa39e794266685e1b8735d2Behdad Esfahbod {"utf8-clusters", 0, 0, G_OPTION_ARG_NONE, &this->utf8_clusters, "Use UTF8 byte indices, not char indices", NULL}, 27839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod {"normalize-glyphs",0, 0, G_OPTION_ARG_NONE, &this->normalize_glyphs, "Rearrange glyph clusters in nominal order", NULL}, 279109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod {NULL} 280109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod }; 281b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod parser->add_group (entries, 282b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "shape", 283b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "Shape options:", 284b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "Options controlling the shaping process", 285b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod this); 2868750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod 28730874b4819a99cc84fa39e794266685e1b8735d2Behdad Esfahbod const gchar *features_help = "Comma-separated list of font features\n" 2888750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod "\n" 2898750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " Features can be enabled or disabled, either globally or limited to\n" 29095cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod " specific character ranges.\n" 29195cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod "\n" 29295cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod " The range indices refer to the positions between Unicode characters,\n" 29395cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod " unless the --utf8-clusters is provided, in which case range indices\n" 29495cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod " refer to UTF-8 byte indices. The position before the first character\n" 29595cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod " is always 0.\n" 296d5300241680844f5625f32792f7dd7181ed05f9bBehdad Esfahbod "\n" 297d5300241680844f5625f32792f7dd7181ed05f9bBehdad Esfahbod " The format is Python-esque. Here is how it all works:\n" 2988750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod "\n" 2998750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " Syntax: Value: Start: End:\n" 3008750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod "\n" 3018750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " Setting value:\n" 3028750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern\" 1 0 ∞ # Turn feature on\n" 3038750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"+kern\" 1 0 ∞ # Turn feature on\n" 3048750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"-kern\" 0 0 ∞ # Turn feature off\n" 3058750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern=0\" 0 0 ∞ # Turn feature off\n" 3068750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern=1\" 1 0 ∞ # Turn feature on\n" 3078750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"aalt=2\" 2 0 ∞ # Choose 2nd alternate\n" 3088750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod "\n" 3098750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " Setting index:\n" 3108750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern[]\" 1 0 ∞ # Turn feature on\n" 3118750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern[:]\" 1 0 ∞ # Turn feature on\n" 3128750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern[5:]\" 1 5 ∞ # Turn feature on, partial\n" 3138750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern[:5]\" 1 0 5 # Turn feature on, partial\n" 3148750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern[3:5]\" 1 3 5 # Turn feature on, range\n" 3158750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " \"kern[3]\" 1 3 3+1 # Turn feature on, single char\n" 3168750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod "\n" 3178750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod " Mixing it all:\n" 3188750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod "\n" 3193bc22eb7b843c77706bb13fc332009097f247813Behdad Esfahbod " \"aalt[3:5]=2\" 2 3 5 # Turn 2nd alternate on for range"; 3208750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod 3218750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod GOptionEntry entries2[] = 3228750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod { 3238750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod {"features", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_features, features_help, "list"}, 3248750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod {NULL} 3258750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod }; 3268750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod parser->add_group (entries2, 3278750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod "features", 3288750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod "Features options:", 32930874b4819a99cc84fa39e794266685e1b8735d2Behdad Esfahbod "Options controlling font features used", 3308750abaf8410005facbea8c886c592bead7f959bBehdad Esfahbod this); 331109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod} 3323bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 333109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbodvoid 334b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodfont_options_t::add_options (option_parser_t *parser) 335109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod{ 336109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod GOptionEntry entries[] = 337109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod { 338b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod {"font-file", 0, 0, G_OPTION_ARG_STRING, &this->font_file, "Font file-name", "filename"}, 339b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod {"face-index", 0, 0, G_OPTION_ARG_INT, &this->face_index, "Face index (default: 0)", "index"}, 340109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod {NULL} 341109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod }; 342b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod parser->add_group (entries, 343b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "font", 344b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "Font options:", 345b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "Options controlling the font", 346b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod this); 347109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod} 3483bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 349109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbodvoid 350b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodtext_options_t::add_options (option_parser_t *parser) 351109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod{ 352109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod GOptionEntry entries[] = 353109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod { 354b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod {"text", 0, 0, G_OPTION_ARG_STRING, &this->text, "Set input text", "string"}, 35578d41d8d69142ae95928b51215c0c0c5e3f5b3f0Behdad Esfahbod {"text-file", 0, 0, G_OPTION_ARG_STRING, &this->text_file, "Set input text file-name\n\n If no text is provided, standard input is used for input.\n", "filename"}, 356321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod {"text-before", 0, 0, G_OPTION_ARG_STRING, &this->text_before, "Set text context before each line", "string"}, 357321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod {"text-after", 0, 0, G_OPTION_ARG_STRING, &this->text_after, "Set text context after each line", "string"}, 3583bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod {NULL} 3593bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod }; 360b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod parser->add_group (entries, 361b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "text", 362b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "Text options:", 363b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "Options controlling the input text", 364b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod this); 365b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 366b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 367b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodvoid 368b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodoutput_options_t::add_options (option_parser_t *parser) 369b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 3709815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod const char *text; 3719815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod 3729815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod if (NULL == supported_formats) 3739815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod text = "Set output format"; 3749815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod else 3759815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod text = g_strdup_printf ("Set output format\n\n Supported formats are: %s", supported_formats); 3769815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod 377b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod GOptionEntry entries[] = 378b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod { 379b5afd8f78e6b372f1bbed469329c1554adb20eeaBehdad Esfahbod {"output-file", 0, 0, G_OPTION_ARG_STRING, &this->output_file, "Set output file-name (default: stdout)","filename"}, 3809815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod {"output-format", 0, 0, G_OPTION_ARG_STRING, &this->output_format, text, "format"}, 381b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod {NULL} 382b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod }; 383b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod parser->add_group (entries, 384b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "output", 385b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "Output options:", 386b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod "Options controlling the output", 387b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod this); 388b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 3893bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 3903bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 3913bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 392b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodhb_font_t * 393b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodfont_options_t::get_font (void) const 394b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 395b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod if (font) 396b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod return font; 397b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 398b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_blob_t *blob = NULL; 399b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 400b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod /* Create the blob */ 4013bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod { 4024451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod char *font_data; 4034451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod unsigned int len = 0; 404b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_destroy_func_t destroy; 405b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod void *user_data; 406b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_memory_mode_t mm; 407b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 4084451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod /* This is a hell of a lot of code for just reading a file! */ 409b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod if (!font_file) 4100594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (true, "No font file set"); 411b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 4124451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod if (0 == strcmp (font_file, "-")) { 4134451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod /* read it */ 4144451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod GString *gs = g_string_new (NULL); 4154451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod char buf[BUFSIZ]; 416e2aab4b5db88c368c11cee81368b9ad41399e585Behdad Esfahbod#if defined(_WIN32) || defined(__CYGWIN__) 417bc76449f51f20491a4540b4f240f5a3e0dcb20feBehdad Esfahbod setmode (fileno (stdin), _O_BINARY); 4184451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod#endif 4194451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod while (!feof (stdin)) { 4204451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod size_t ret = fread (buf, 1, sizeof (buf), stdin); 4214451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod if (ferror (stdin)) 4220594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (false, "Failed reading font from standard input: %s", 4234451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod strerror (errno)); 4244451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod g_string_append_len (gs, buf, ret); 4254451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod } 4264451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod len = gs->len; 4270594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod font_data = g_string_free (gs, false); 4284451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod user_data = font_data; 4294451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod destroy = (hb_destroy_func_t) g_free; 4304451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod mm = HB_MEMORY_MODE_WRITABLE; 4314451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod } else { 432f51e167436a51b890ffe3f7f7920498fa287acd9Behdad Esfahbod GError *error = NULL; 4330594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod GMappedFile *mf = g_mapped_file_new (font_file, false, &error); 4344451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod if (mf) { 4354451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod font_data = g_mapped_file_get_contents (mf); 4364451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod len = g_mapped_file_get_length (mf); 4374451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod if (len) { 4384451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod destroy = (hb_destroy_func_t) g_mapped_file_unref; 4394451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod user_data = (void *) mf; 4404451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; 4414451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod } else 4424451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod g_mapped_file_unref (mf); 443f51e167436a51b890ffe3f7f7920498fa287acd9Behdad Esfahbod } else { 4440594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (false, "%s", error->message); 445f51e167436a51b890ffe3f7f7920498fa287acd9Behdad Esfahbod //g_error_free (error); 4464451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod } 4474451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod if (!len) { 4484451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod /* GMappedFile is buggy, it doesn't fail if file isn't regular. 4494451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod * Try reading. 4504451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod * https://bugzilla.gnome.org/show_bug.cgi?id=659212 */ 4514451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod GError *error = NULL; 4524451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod gsize l; 4534451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod if (g_file_get_contents (font_file, &font_data, &l, &error)) { 4544451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod len = l; 4554451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod destroy = (hb_destroy_func_t) g_free; 4564451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod user_data = (void *) font_data; 4574451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod mm = HB_MEMORY_MODE_WRITABLE; 4584451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod } else { 4590594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (false, "%s", error->message); 4604451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod //g_error_free (error); 4614451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod } 4624451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod } 4634451168e5d1ea26560899e9a9733b3a3f1853050Behdad Esfahbod } 464b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 465b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod blob = hb_blob_create (font_data, len, mm, user_data, destroy); 466b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 467b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 468b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod /* Create the face */ 469b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_face_t *face = hb_face_create (blob, face_index); 470b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_blob_destroy (blob); 471b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 472b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 473b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod font = hb_font_create (face); 474b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 475b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod unsigned int upem = hb_face_get_upem (face); 4767bf6ecd3bfb1ccf5d9ac6fe274efa74b46885feaBehdad Esfahbod hb_font_set_scale (font, upem, upem); 477b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_face_destroy (face); 478b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 4795ddd9cc499f2470eca239ae357a5c8a3626c0809Behdad Esfahbod#ifdef HAVE_FREETYPE 480b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_ft_font_set_funcs (font); 481b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod#endif 482b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 483b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod return font; 484b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod} 485b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 486b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 487b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodconst char * 488b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodtext_options_t::get_line (unsigned int *len) 489b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 49055aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (text) { 49155aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (text_len == (unsigned int) -1) 49255aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod text_len = strlen (text); 49355aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod 49455aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (!text_len) { 49555aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod *len = 0; 49655aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod return NULL; 49755aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod } 49855aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod 49955aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod const char *ret = text; 50055aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod const char *p = (const char *) memchr (text, '\n', text_len); 50155aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod unsigned int ret_len; 50255aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (!p) { 50355aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod ret_len = text_len; 50455aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod text += ret_len; 50555aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod text_len = 0; 50655aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod } else { 50755aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod ret_len = p - ret; 50855aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod text += ret_len + 1; 50955aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod text_len -= ret_len + 1; 51055aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod } 51155aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod 51255aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod *len = ret_len; 51355aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod return ret; 51455aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod } 51555aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod 51655aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (!fp) { 517b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod if (!text_file) 5180594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (true, "At least one of text or text-file must be set"); 519b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 52055aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (0 != strcmp (text_file, "-")) 52155aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod fp = fopen (text_file, "r"); 52255aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod else 52355aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod fp = stdin; 5243bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 52555aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (!fp) 5260594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (false, "Failed opening text file `%s': %s", 52755aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod text_file, strerror (errno)); 528b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 52955aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod gs = g_string_new (NULL); 530b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 531b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 53255aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod g_string_set_size (gs, 0); 53355aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod char buf[BUFSIZ]; 53455aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod while (fgets (buf, sizeof (buf), fp)) { 53555aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod unsigned int bytes = strlen (buf); 53627c36af411c7c4d75dd25d79fc76dd92c6bb9643Behdad Esfahbod if (bytes && buf[bytes - 1] == '\n') { 53755aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod bytes--; 53855aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod g_string_append_len (gs, buf, bytes); 53955aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod break; 54055aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod } 54155aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod g_string_append_len (gs, buf, bytes); 5423bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod } 54355aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (ferror (fp)) 5440594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (false, "Failed reading text: %s", 54555aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod strerror (errno)); 54655aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod *len = gs->len; 54755aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod return !*len && feof (fp) ? NULL : gs->str; 5483bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod} 549a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod 550a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod 551a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad EsfahbodFILE * 552a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbodoutput_options_t::get_file_handle (void) 553a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod{ 554a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod if (fp) 555a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod return fp; 556a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod 557a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod if (output_file) 558a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod fp = fopen (output_file, "wb"); 559a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod else { 560e2aab4b5db88c368c11cee81368b9ad41399e585Behdad Esfahbod#if defined(_WIN32) || defined(__CYGWIN__) 561ceeae30f47b9d628484ae398bc38f3f60ee8eab4Behdad Esfahbod setmode (fileno (stdout), _O_BINARY); 562a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod#endif 563a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod fp = stdout; 564a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod } 565a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod if (!fp) 5660594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod fail (false, "Cannot open output file `%s': %s", 567a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod g_filename_display_name (output_file), strerror (errno)); 568a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod 569a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod return fp; 570a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod} 5718b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 572c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbodstatic gboolean 573c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbodparse_verbose (const char *name G_GNUC_UNUSED, 574c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbod const char *arg G_GNUC_UNUSED, 575c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbod gpointer data G_GNUC_UNUSED, 576c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbod GError **error G_GNUC_UNUSED) 577c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbod{ 578c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbod format_options_t *format_opts = (format_options_t *) data; 5790594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod format_opts->show_text = format_opts->show_unicode = format_opts->show_line_num = true; 5800594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return true; 581c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbod} 5828b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 5838b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbodvoid 5848b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbodformat_options_t::add_options (option_parser_t *parser) 5858b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod{ 5868b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod GOptionEntry entries[] = 5878b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod { 5888b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod {"no-glyph-names", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_glyph_names, "Use glyph indices instead of names", NULL}, 5898b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod {"no-positions", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_positions, "Do not show glyph positions", NULL}, 5908b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod {"no-clusters", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_clusters, "Do not show cluster mapping", NULL}, 591cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod {"show-text", 0, 0, G_OPTION_ARG_NONE, &this->show_text, "Show input text", NULL}, 592cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod {"show-unicode", 0, 0, G_OPTION_ARG_NONE, &this->show_unicode, "Show input Unicode codepoints", NULL}, 593cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod {"show-line-num", 0, 0, G_OPTION_ARG_NONE, &this->show_line_num, "Show line numbers", NULL}, 594c1885483120d4b686b2fe95b217dce7248e040b1Behdad Esfahbod {"verbose", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,(gpointer) &parse_verbose, "Show everything", NULL}, 5958b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod {NULL} 5968b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod }; 5978b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod parser->add_group (entries, 5988b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod "format", 5998b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod "Format options:", 6008b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod "Options controlling the formatting of buffer contents", 6018b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod this); 6028b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod} 6038b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 6048b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbodvoid 605cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbodformat_options_t::serialize_unicode (hb_buffer_t *buffer, 606cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod GString *gs) 607cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod{ 608cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod unsigned int num_glyphs = hb_buffer_get_length (buffer); 609cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL); 610cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod 611cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod g_string_append_c (gs, '<'); 612cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod for (unsigned int i = 0; i < num_glyphs; i++) 613cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod { 614cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod if (i) 615cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod g_string_append_c (gs, ','); 616cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod g_string_append_printf (gs, "U+%04X", info->codepoint); 617cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod info++; 618cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod } 619cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod g_string_append_c (gs, '>'); 620cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod} 621cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod 622cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbodvoid 623cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbodformat_options_t::serialize_glyphs (hb_buffer_t *buffer, 624cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod hb_font_t *font, 625f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod hb_buffer_serialize_format_t output_format, 626f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod hb_buffer_serialize_flags_t flags, 627cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod GString *gs) 6288b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod{ 629c91c4fa47140c0d6191241a832fc534b1c1514ceBehdad Esfahbod g_string_append_c (gs, '['); 630f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod unsigned int num_glyphs = hb_buffer_get_length (buffer); 631f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod unsigned int start = 0; 632f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod 633f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod while (start < num_glyphs) { 634f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod char buf[1024]; 635f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod unsigned int consumed; 636f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod start += hb_buffer_serialize_glyphs (buffer, start, num_glyphs, 637f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod buf, sizeof (buf), &consumed, 638f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod font, output_format, flags); 639f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod if (!consumed) 640f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod break; 641f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod g_string_append (gs, buf); 6428b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod } 643c91c4fa47140c0d6191241a832fc534b1c1514ceBehdad Esfahbod g_string_append_c (gs, ']'); 6448b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod} 645cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbodvoid 646cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbodformat_options_t::serialize_line_no (unsigned int line_no, 647cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod GString *gs) 648cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod{ 649cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod if (show_line_num) 650cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod g_string_append_printf (gs, "%d: ", line_no); 651cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod} 652cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbodvoid 6535db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbodformat_options_t::serialize_buffer_of_text (hb_buffer_t *buffer, 6545db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod unsigned int line_no, 6555db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod const char *text, 6565db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod unsigned int text_len, 6575db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod hb_font_t *font, 6585db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod GString *gs) 659cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod{ 660cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod if (show_text) { 661cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod serialize_line_no (line_no, gs); 662d8134bc017ca3383e0978ddee57070eb3aab8964Behdad Esfahbod g_string_append_c (gs, '('); 663cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod g_string_append_len (gs, text, text_len); 664d8134bc017ca3383e0978ddee57070eb3aab8964Behdad Esfahbod g_string_append_c (gs, ')'); 665cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod g_string_append_c (gs, '\n'); 666cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod } 667cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod 668cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod if (show_unicode) { 669cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod serialize_line_no (line_no, gs); 670ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod serialize_unicode (buffer, gs); 671cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod g_string_append_c (gs, '\n'); 672cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod } 6735db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod} 6745db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbodvoid 6755db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbodformat_options_t::serialize_message (unsigned int line_no, 6765db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod const char *msg, 6775db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod GString *gs) 6785db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod{ 6795db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod serialize_line_no (line_no, gs); 6805db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod g_string_append_printf (gs, "%s", msg); 6815db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod g_string_append_c (gs, '\n'); 6825db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod} 6835db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbodvoid 6845db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbodformat_options_t::serialize_buffer_of_glyphs (hb_buffer_t *buffer, 6855db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod unsigned int line_no, 6865db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod const char *text, 6875db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod unsigned int text_len, 6885db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod hb_font_t *font, 689f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod hb_buffer_serialize_format_t output_format, 690f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod hb_buffer_serialize_flags_t format_flags, 6915db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod GString *gs) 6925db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod{ 693cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod serialize_line_no (line_no, gs); 694f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod serialize_glyphs (buffer, font, output_format, format_flags, gs); 695cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod g_string_append_c (gs, '\n'); 696cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod} 697