From e998cec1d94f32ac44ff0dca42941b28a4fdd546 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 18 Jan 2023 23:33:21 -0700 Subject: [PATCH] [hb-view] Move palette options to --help-view --- util/font-options.hh | 5 ----- util/helper-cairo.hh | 9 +++++---- util/view-cairo.hh | 3 ++- util/view-options.hh | 5 +++++ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/util/font-options.hh b/util/font-options.hh index 5d569968c..efc5a1a8b 100644 --- a/util/font-options.hh +++ b/util/font-options.hh @@ -49,7 +49,6 @@ struct font_options_t : face_options_t #endif g_free (font_funcs); hb_font_destroy (font); - free (custom_palette); } void add_options (option_parser_t *parser); @@ -70,8 +69,6 @@ struct font_options_t : face_options_t mutable double font_size_y = DEFAULT_FONT_SIZE; char *font_funcs = nullptr; int ft_load_flags = 2; - unsigned int palette = 0; - char *custom_palette = nullptr; unsigned int named_instance = HB_FONT_NO_VAR_NAMED_INSTANCE; hb_font_t *font = nullptr; @@ -291,8 +288,6 @@ font_options_t::add_options (option_parser_t *parser) G_OPTION_ARG_DOUBLE, &this->ptem, "Set font point-size (default: 0; disabled)", "point-size"}, {"font-slant", 0, 0, G_OPTION_ARG_DOUBLE, &this->slant, "Set synthetic slant (default: 0)", "slant ratio; eg. 0.2"}, - {"font-palette", 0, 0, G_OPTION_ARG_INT, &this->palette, "Set font palette (default: 0)", "index"}, - {"custom-palette", 0, 0, G_OPTION_ARG_STRING, &this->custom_palette, "Custom palette", "comma-separated colors"}, {"font-funcs", 0, 0, G_OPTION_ARG_STRING, &this->font_funcs, text, "impl"}, {"sub-font", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &this->sub_font, "Create a sub-font (default: false)", "boolean"}, diff --git a/util/helper-cairo.hh b/util/helper-cairo.hh index 293077a6e..737e70b77 100644 --- a/util/helper-cairo.hh +++ b/util/helper-cairo.hh @@ -88,7 +88,8 @@ helper_cairo_use_hb_draw (const font_options_t *font_opts) } static inline cairo_scaled_font_t * -helper_cairo_create_scaled_font (const font_options_t *font_opts) +helper_cairo_create_scaled_font (const font_options_t *font_opts, + const view_options_t *view_opts) { hb_font_t *font = font_opts->font; bool use_hb_draw = true; @@ -123,12 +124,12 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts) cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE); cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF); #ifdef CAIRO_COLOR_PALETTE_DEFAULT - unsigned palette_index = font_opts->palette; + unsigned palette_index = view_opts->palette; #ifdef CAIRO_COLOR_PALETTE_CUSTOM - if (font_opts->custom_palette) + if (view_opts->custom_palette) { palette_index = HB_PAINT_PALETTE_INDEX_CUSTOM; - char **entries = g_strsplit (font_opts->custom_palette, ",", -1); + char **entries = g_strsplit (view_opts->custom_palette, ",", -1); for (unsigned int i = 0; entries[i]; i++) { unsigned int fr, fg, fb, fa; diff --git a/util/view-cairo.hh b/util/view-cairo.hh index f30905d0d..fbd5e5d9b 100644 --- a/util/view-cairo.hh +++ b/util/view-cairo.hh @@ -131,7 +131,8 @@ view_cairo_t::render (const font_options_t *font_opts) w = MAX (w, x_sign * x_advance); } - cairo_scaled_font_t *scaled_font = helper_cairo_create_scaled_font (font_opts); + cairo_scaled_font_t *scaled_font = helper_cairo_create_scaled_font (font_opts, + this); /* See if font needs color. */ cairo_content_t content = CAIRO_CONTENT_ALPHA; diff --git a/util/view-options.hh b/util/view-options.hh index 322009a1e..731c133a2 100644 --- a/util/view-options.hh +++ b/util/view-options.hh @@ -39,6 +39,7 @@ struct view_options_t { g_free (fore); g_free (back); + g_free (custom_palette); } void add_options (option_parser_t *parser); @@ -46,6 +47,8 @@ struct view_options_t hb_bool_t annotate = false; char *fore = nullptr; char *back = nullptr; + unsigned int palette = 0; + char *custom_palette = nullptr; double line_space = 0; bool have_font_extents = false; struct font_extents_t { @@ -108,6 +111,8 @@ view_options_t::add_options (option_parser_t *parser) {"annotate", 0, 0, G_OPTION_ARG_NONE, &this->annotate, "Annotate output rendering", nullptr}, {"background", 0, 0, G_OPTION_ARG_STRING, &this->back, "Set background color (default: " DEFAULT_BACK ")", "rrggbb/rrggbbaa"}, {"foreground", 0, 0, G_OPTION_ARG_STRING, &this->fore, "Set foreground color (default: " DEFAULT_FORE ")", "rrggbb/rrggbbaa"}, + {"font-palette", 0, 0, G_OPTION_ARG_INT, &this->palette, "Set font palette (default: 0)", "index"}, + {"custom-palette", 0, 0, G_OPTION_ARG_STRING, &this->custom_palette, "Custom palette", "comma-separated colors"}, {"line-space", 0, 0, G_OPTION_ARG_DOUBLE, &this->line_space, "Set space between lines (default: 0)", "units"}, {"font-extents", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_font_extents, "Set font ascent/descent/line-gap (default: auto)","one to three numbers"}, {"margin", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_margin, "Margin around output (default: " G_STRINGIFY(DEFAULT_MARGIN) ")","one to four numbers"},