[util] Move font-size and upem to be extern variables

This commit is contained in:
Behdad Esfahbod 2021-08-05 13:48:59 -06:00
parent fc0339eef0
commit 71440dbd90
7 changed files with 25 additions and 25 deletions

View File

@ -26,6 +26,9 @@
#include "main-font-text.hh"
const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_NONE;
const unsigned SUBPIXEL_BITS = 0;
#ifdef HAVE_FREETYPE
#include <hb-ft.h>
#endif
@ -108,6 +111,6 @@ struct shape_closure_consumer_t
int
main (int argc, char **argv)
{
main_font_text_t<shape_closure_consumer_t, FONT_SIZE_NONE, 0> driver;
main_font_text_t<shape_closure_consumer_t> driver;
return driver.main (argc, argv);
}

View File

@ -28,6 +28,9 @@
#include "main-font-text.hh"
#include "shape-consumer.hh"
const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM;
const unsigned SUBPIXEL_BITS = 0;
struct output_buffer_t
{
void add_options (option_parser_t *parser)
@ -155,7 +158,7 @@ struct output_buffer_t
int
main (int argc, char **argv)
{
using driver_t = main_font_text_t<shape_consumer_t<output_buffer_t>, FONT_SIZE_UPEM, 0>;
using driver_t = main_font_text_t<shape_consumer_t<output_buffer_t>>;
if (argc == 2 && !strcmp (argv[1], "--batch"))
{

View File

@ -30,6 +30,9 @@
#include "main-font-text.hh"
#include "hb-subset.h"
const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_NONE;
const unsigned SUBPIXEL_BITS = 0;
/*
* Command line interface to the harfbuzz font subsetter.
*/
@ -131,7 +134,7 @@ struct subset_consumer_t
int
main (int argc, char **argv)
{
using driver_t = main_font_text_t<subset_consumer_t, FONT_SIZE_UPEM, 0>;
using driver_t = main_font_text_t<subset_consumer_t>;
if (argc == 2 && !strcmp (argv[1], "--batch"))
{

View File

@ -29,12 +29,12 @@
#include "shape-consumer.hh"
#include "view-cairo.hh"
#define DEFAULT_FONT_SIZE 256
#define SUBPIXEL_BITS 6
const unsigned DEFAULT_FONT_SIZE = 256;
const unsigned SUBPIXEL_BITS = 6;
int
main (int argc, char **argv)
{
main_font_text_t<shape_consumer_t<view_cairo_t>, DEFAULT_FONT_SIZE, SUBPIXEL_BITS> driver;
main_font_text_t<shape_consumer_t<view_cairo_t>> driver;
return driver.main (argc, argv);
}

View File

@ -47,13 +47,9 @@ locale_to_utf8 (char *s)
return t;
}
template <typename consumer_t, int default_font_size, int subpixel_bits>
template <typename consumer_t>
struct main_font_text_t
{
main_font_text_t ()
: font_opts (default_font_size, subpixel_bits)
{}
void add_options (option_parser_t *parser)
{
font_opts.add_options (parser);

View File

@ -547,11 +547,11 @@ font_options_t::add_options (option_parser_t *parser)
}
char *font_size_text;
if (default_font_size == FONT_SIZE_UPEM)
if (DEFAULT_FONT_SIZE == FONT_SIZE_UPEM)
font_size_text = (char *) "Font size (default: upem)";
else
{
font_size_text = g_strdup_printf ("Font size (default: %d)", default_font_size);
font_size_text = g_strdup_printf ("Font size (default: %d)", DEFAULT_FONT_SIZE);
parser->free_later (font_size_text);
}
@ -559,7 +559,7 @@ font_options_t::add_options (option_parser_t *parser)
{
{"font-file", 0, 0, G_OPTION_ARG_STRING, &this->font_file, "Set font file-name", "filename"},
{"face-index", 0, 0, G_OPTION_ARG_INT, &this->face_index, "Set face index (default: 0)", "index"},
{"font-size", 0, default_font_size ? 0 : G_OPTION_FLAG_HIDDEN,
{"font-size", 0, DEFAULT_FONT_SIZE ? 0 : G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_CALLBACK, (gpointer) &parse_font_size, font_size_text, "1/2 integers or 'upem'"},
{"font-ppem", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_font_ppem, "Set x,y pixels per EM (default: 0; disabled)", "1/2 integers"},
{"font-ptem", 0, 0, G_OPTION_ARG_DOUBLE, &this->ptem, "Set font point-size (default: 0; disabled)", "point-size"},

View File

@ -130,6 +130,9 @@ struct option_parser_t
#define FONT_SIZE_UPEM 0x7FFFFFFF
#define FONT_SIZE_NONE 0
extern const unsigned DEFAULT_FONT_SIZE;
extern const unsigned SUBPIXEL_BITS;
struct view_options_t
{
~view_options_t ()
@ -440,13 +443,6 @@ struct shape_options_t
struct font_options_t
{
font_options_t (int default_font_size_,
unsigned int subpixel_bits_)
: default_font_size (default_font_size_),
subpixel_bits (subpixel_bits_),
font_size_x (default_font_size_),
font_size_y (default_font_size_)
{}
~font_options_t ()
{
g_free (font_file);
@ -464,13 +460,12 @@ struct font_options_t
unsigned face_index = 0;
hb_variation_t *variations = nullptr;
unsigned int num_variations = 0;
int default_font_size = FONT_SIZE_UPEM;
int x_ppem = 0;
int y_ppem = 0;
double ptem = 0.;
unsigned int subpixel_bits = 0;
mutable double font_size_x = FONT_SIZE_UPEM;
mutable double font_size_y = FONT_SIZE_UPEM;
unsigned int subpixel_bits = SUBPIXEL_BITS;
mutable double font_size_x = DEFAULT_FONT_SIZE;
mutable double font_size_y = DEFAULT_FONT_SIZE;
char *font_funcs = nullptr;
int ft_load_flags = 2;