[hb-view] Move palette options to --help-view

This commit is contained in:
Behdad Esfahbod 2023-01-18 23:33:21 -07:00
parent 253b4cecae
commit e998cec1d9
4 changed files with 12 additions and 10 deletions

View File

@ -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"},

View File

@ -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;

View File

@ -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;

View File

@ -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"},