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 VIEW_OPTIONS_HH
28 #define VIEW_OPTIONS_HH
32 #define DEFAULT_MARGIN 16
33 #define DEFAULT_FORE "#000000"
34 #define DEFAULT_BACK "#FFFFFF"
42 g_free (custom_palette);
45 void add_options (option_parser_t *parser);
49 unsigned int palette = 0;
50 char *custom_palette = nullptr;
51 double line_space = 0;
52 bool have_font_extents = false;
53 struct font_extents_t {
54 double ascent, descent, line_gap;
55 } font_extents = {0., 0., 0.};
58 } margin = {DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN};
59 hb_bool_t show_extents = false;
64 parse_font_extents (const char *name G_GNUC_UNUSED,
67 GError **error G_GNUC_UNUSED)
69 view_options_t *view_opts = (view_options_t *) data;
70 view_options_t::font_extents_t &e = view_opts->font_extents;
71 switch (sscanf (arg, "%lf%*[ ,]%lf%*[ ,]%lf", &e.ascent, &e.descent, &e.line_gap)) {
72 case 1: HB_FALLTHROUGH;
73 case 2: HB_FALLTHROUGH;
75 view_opts->have_font_extents = true;
78 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
79 "%s argument should be one to three space-separated numbers",
86 parse_margin (const char *name G_GNUC_UNUSED,
89 GError **error G_GNUC_UNUSED)
91 view_options_t *view_opts = (view_options_t *) data;
92 view_options_t::margin_t &m = view_opts->margin;
93 switch (sscanf (arg, "%lf%*[ ,]%lf%*[ ,]%lf%*[ ,]%lf", &m.t, &m.r, &m.b, &m.l)) {
94 case 1: m.r = m.t; HB_FALLTHROUGH;
95 case 2: m.b = m.t; HB_FALLTHROUGH;
96 case 3: m.l = m.r; HB_FALLTHROUGH;
99 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
100 "%s argument should be one to four space-separated numbers",
107 view_options_t::add_options (option_parser_t *parser)
109 GOptionEntry entries[] =
111 {"annotate", 0, G_OPTION_FLAG_HIDDEN,
112 G_OPTION_ARG_NONE, &this->show_extents, "Annotate output rendering", nullptr},
113 {"background", 0, 0, G_OPTION_ARG_STRING, &this->back, "Set background color (default: " DEFAULT_BACK ")", "rrggbb/rrggbbaa"},
114 {"foreground", 0, 0, G_OPTION_ARG_STRING, &this->fore, "Set foreground color (default: " DEFAULT_FORE ")", "rrggbb/rrggbbaa"},
115 {"font-palette", 0, 0, G_OPTION_ARG_INT, &this->palette, "Set font palette (default: 0)", "index"},
116 {"custom-palette", 0, 0, G_OPTION_ARG_STRING, &this->custom_palette, "Custom palette", "comma-separated colors"},
117 {"line-space", 0, 0, G_OPTION_ARG_DOUBLE, &this->line_space, "Set space between lines (default: 0)", "units"},
118 {"font-extents", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_font_extents, "Set font ascent/descent/line-gap (default: auto)","one to three numbers"},
119 {"margin", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_margin, "Margin around output (default: " G_STRINGIFY(DEFAULT_MARGIN) ")","one to four numbers"},
120 {"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Draw glyph extents", nullptr},
123 parser->add_group (entries,
126 "Options for output rendering",