2 * Copyright © 2011 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
24 * Google Author(s): Behdad Esfahbod
27 #ifndef FACE_OPTIONS_HH
28 #define FACE_OPTIONS_HH
39 void set_face (hb_face_t *face_)
42 void add_options (option_parser_t *parser);
44 void post_parse (GError **error);
51 hb_blob_destroy (blob);
52 hb_face_destroy (face);
55 char *font_path = nullptr;
56 hb_blob_t *blob = nullptr;
57 unsigned face_index = (unsigned) -1;
58 hb_face_t *face = nullptr;
61 char *font_file = nullptr;
62 unsigned face_index = 0;
64 hb_blob_t *blob = nullptr;
65 hb_face_t *face = nullptr;
69 face_options_t::cache_t face_options_t::cache {};
72 face_options_t::post_parse (GError **error)
76 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
83 const char *font_path = font_file;
85 if (0 == strcmp (font_path, "-"))
87 #if defined(_WIN32) || defined(__CYGWIN__)
88 setmode (fileno (stdin), O_BINARY);
91 font_path = "/dev/stdin";
95 if (!cache.font_path || 0 != strcmp (cache.font_path, font_path))
97 hb_blob_destroy (cache.blob);
98 cache.blob = hb_blob_create_from_file_or_fail (font_path);
100 free ((char *) cache.font_path);
101 cache.font_path = g_strdup (font_path);
105 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
106 "%s: Failed reading file", font_path);
110 hb_face_destroy (cache.face);
111 cache.face = nullptr;
112 cache.face_index = (unsigned) -1;
115 if (cache.face_index != face_index)
117 hb_face_destroy (cache.face);
118 cache.face = hb_face_create (cache.blob, face_index);
119 cache.face_index = face_index;
127 face_options_t::add_options (option_parser_t *parser)
129 GOptionEntry entries[] =
131 {"font-file", 0, 0, G_OPTION_ARG_STRING, &this->font_file, "Set font file-name", "filename"},
132 {"face-index", 0, 0, G_OPTION_ARG_INT, &this->face_index, "Set face index (default: 0)", "index"},
135 parser->add_group (entries,
137 "Font-face options:",
138 "Options for the font face",