[util] Use inheritance for output_options_t
This commit is contained in:
parent
9db0fd4821
commit
af9d2495dc
|
@ -32,38 +32,38 @@
|
||||||
const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM;
|
const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM;
|
||||||
const unsigned SUBPIXEL_BITS = 0;
|
const unsigned SUBPIXEL_BITS = 0;
|
||||||
|
|
||||||
struct output_buffer_t
|
struct output_buffer_t : output_options_t
|
||||||
{
|
{
|
||||||
void add_options (option_parser_t *parser)
|
void add_options (option_parser_t *parser)
|
||||||
{
|
{
|
||||||
options.add_options (parser, hb_buffer_serialize_list_formats ());
|
output_options_t::add_options (parser, hb_buffer_serialize_list_formats ());
|
||||||
format.add_options (parser);
|
format.add_options (parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init (hb_buffer_t *buffer, const font_options_t *font_opts)
|
void init (hb_buffer_t *buffer, const font_options_t *font_opts)
|
||||||
{
|
{
|
||||||
options.get_file_handle ();
|
get_file_handle ();
|
||||||
gs = g_string_new (nullptr);
|
gs = g_string_new (nullptr);
|
||||||
line_no = 0;
|
line_no = 0;
|
||||||
font = hb_font_reference (font_opts->get_font ());
|
font = hb_font_reference (font_opts->get_font ());
|
||||||
|
|
||||||
if (!options.output_format)
|
if (!output_format)
|
||||||
output_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT;
|
serialize_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT;
|
||||||
else
|
else
|
||||||
output_format = hb_buffer_serialize_format_from_string (options.output_format, -1);
|
serialize_format = hb_buffer_serialize_format_from_string (output_format, -1);
|
||||||
/* An empty "output_format" parameter basically skips output generating.
|
/* An empty "output_format" parameter basically skips output generating.
|
||||||
* Useful for benchmarking. */
|
* Useful for benchmarking. */
|
||||||
if ((!options.output_format || *options.output_format) &&
|
if ((!output_format || *output_format) &&
|
||||||
!hb_buffer_serialize_format_to_string (output_format))
|
!hb_buffer_serialize_format_to_string (serialize_format))
|
||||||
{
|
{
|
||||||
if (options.explicit_output_format)
|
if (explicit_output_format)
|
||||||
fail (false, "Unknown output format `%s'; supported formats are: %s",
|
fail (false, "Unknown output format `%s'; supported formats are: %s",
|
||||||
options.output_format,
|
output_format,
|
||||||
g_strjoinv ("/", const_cast<char**> (hb_buffer_serialize_list_formats ())));
|
g_strjoinv ("/", const_cast<char**> (hb_buffer_serialize_list_formats ())));
|
||||||
else
|
else
|
||||||
/* Just default to TEXT if not explicitly requested and the
|
/* Just default to TEXT if not explicitly requested and the
|
||||||
* file extension is not recognized. */
|
* file extension is not recognized. */
|
||||||
output_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT;
|
serialize_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT;
|
unsigned int flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT;
|
||||||
|
@ -79,7 +79,7 @@ struct output_buffer_t
|
||||||
flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS;
|
flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS;
|
||||||
if (format.show_flags)
|
if (format.show_flags)
|
||||||
flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS;
|
flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS;
|
||||||
format_flags = (hb_buffer_serialize_flags_t) flags;
|
serialize_flags = (hb_buffer_serialize_flags_t) flags;
|
||||||
|
|
||||||
if (format.trace)
|
if (format.trace)
|
||||||
hb_buffer_set_message_func (buffer, message_func, this, nullptr);
|
hb_buffer_set_message_func (buffer, message_func, this, nullptr);
|
||||||
|
@ -92,13 +92,13 @@ struct output_buffer_t
|
||||||
{
|
{
|
||||||
g_string_set_size (gs, 0);
|
g_string_set_size (gs, 0);
|
||||||
format.serialize_buffer_of_text (buffer, line_no, text, text_len, font, gs);
|
format.serialize_buffer_of_text (buffer, line_no, text, text_len, font, gs);
|
||||||
fprintf (options.fp, "%s", gs->str);
|
fprintf (fp, "%s", gs->str);
|
||||||
}
|
}
|
||||||
void error (const char *message)
|
void error (const char *message)
|
||||||
{
|
{
|
||||||
g_string_set_size (gs, 0);
|
g_string_set_size (gs, 0);
|
||||||
format.serialize_message (line_no, "error", message, gs);
|
format.serialize_message (line_no, "error", message, gs);
|
||||||
fprintf (options.fp, "%s", gs->str);
|
fprintf (fp, "%s", gs->str);
|
||||||
}
|
}
|
||||||
void consume_glyphs (hb_buffer_t *buffer,
|
void consume_glyphs (hb_buffer_t *buffer,
|
||||||
const char *text,
|
const char *text,
|
||||||
|
@ -107,8 +107,8 @@ struct output_buffer_t
|
||||||
{
|
{
|
||||||
g_string_set_size (gs, 0);
|
g_string_set_size (gs, 0);
|
||||||
format.serialize_buffer_of_glyphs (buffer, line_no, text, text_len, font,
|
format.serialize_buffer_of_glyphs (buffer, line_no, text, text_len, font,
|
||||||
output_format, format_flags, gs);
|
serialize_format, serialize_flags, gs);
|
||||||
fprintf (options.fp, "%s", gs->str);
|
fprintf (fp, "%s", gs->str);
|
||||||
}
|
}
|
||||||
void finish (hb_buffer_t *buffer, const font_options_t *font_opts)
|
void finish (hb_buffer_t *buffer, const font_options_t *font_opts)
|
||||||
{
|
{
|
||||||
|
@ -138,22 +138,21 @@ struct output_buffer_t
|
||||||
g_string_set_size (gs, 0);
|
g_string_set_size (gs, 0);
|
||||||
format.serialize_line_no (line_no, gs);
|
format.serialize_line_no (line_no, gs);
|
||||||
g_string_append_printf (gs, "trace: %s buffer: ", message);
|
g_string_append_printf (gs, "trace: %s buffer: ", message);
|
||||||
format.serialize (buffer, font, output_format, format_flags, gs);
|
format.serialize (buffer, font, serialize_format, serialize_flags, gs);
|
||||||
g_string_append_c (gs, '\n');
|
g_string_append_c (gs, '\n');
|
||||||
fprintf (options.fp, "%s", gs->str);
|
fprintf (fp, "%s", gs->str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
output_options_t options;
|
|
||||||
shape_format_options_t format;
|
shape_format_options_t format;
|
||||||
|
|
||||||
GString *gs = nullptr;
|
GString *gs = nullptr;
|
||||||
unsigned int line_no = 0;
|
unsigned int line_no = 0;
|
||||||
hb_font_t *font = nullptr;
|
hb_font_t *font = nullptr;
|
||||||
hb_buffer_serialize_format_t output_format = HB_BUFFER_SERIALIZE_FORMAT_INVALID;
|
hb_buffer_serialize_format_t serialize_format = HB_BUFFER_SERIALIZE_FORMAT_INVALID;
|
||||||
hb_buffer_serialize_flags_t format_flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT;
|
hb_buffer_serialize_flags_t serialize_flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT;
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -36,12 +36,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
struct subset_consumer_t : subset_options_t
|
struct subset_consumer_t : subset_options_t, output_options_t
|
||||||
{
|
{
|
||||||
void add_options (option_parser_t *parser)
|
void add_options (option_parser_t *parser)
|
||||||
{
|
{
|
||||||
subset_options_t::add_options (parser);
|
subset_options_t::add_options (parser);
|
||||||
output_options.add_options (parser);
|
output_options_t::add_options (parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init (const face_options_t *face_opts)
|
void init (const face_options_t *face_opts)
|
||||||
|
@ -110,7 +110,7 @@ struct subset_consumer_t : subset_options_t
|
||||||
if (!failed)
|
if (!failed)
|
||||||
{
|
{
|
||||||
hb_blob_t *result = hb_face_reference_blob (new_face);
|
hb_blob_t *result = hb_face_reference_blob (new_face);
|
||||||
write_file (output_options.output_file, result);
|
write_file (output_file, result);
|
||||||
hb_blob_destroy (result);
|
hb_blob_destroy (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,9 +122,6 @@ struct subset_consumer_t : subset_options_t
|
||||||
public:
|
public:
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
|
|
||||||
private:
|
|
||||||
output_options_t output_options;
|
|
||||||
|
|
||||||
hb_face_t *face = nullptr;
|
hb_face_t *face = nullptr;
|
||||||
hb_subset_input_t *input = nullptr;
|
hb_subset_input_t *input = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "view-options.hh"
|
#include "view-options.hh"
|
||||||
#include "helper-cairo.hh"
|
#include "helper-cairo.hh"
|
||||||
|
|
||||||
struct view_cairo_t : view_options_t
|
struct view_cairo_t : view_options_t, output_options_t
|
||||||
{
|
{
|
||||||
~view_cairo_t ()
|
~view_cairo_t ()
|
||||||
{
|
{
|
||||||
|
@ -39,8 +39,8 @@ struct view_cairo_t : view_options_t
|
||||||
|
|
||||||
void add_options (option_parser_t *parser)
|
void add_options (option_parser_t *parser)
|
||||||
{
|
{
|
||||||
view_options_t::add_options (parser);
|
view_options_t::add_options (parser);
|
||||||
output_options.add_options (parser, helper_cairo_supported_formats);
|
output_options_t::add_options (parser, helper_cairo_supported_formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init (hb_buffer_t *buffer, const font_options_t *font_opts)
|
void init (hb_buffer_t *buffer, const font_options_t *font_opts)
|
||||||
|
@ -84,8 +84,6 @@ struct view_cairo_t : view_options_t
|
||||||
|
|
||||||
void render (const font_options_t *font_opts);
|
void render (const font_options_t *font_opts);
|
||||||
|
|
||||||
output_options_t output_options;
|
|
||||||
|
|
||||||
hb_direction_t direction = HB_DIRECTION_INVALID; // Remove this, make segment_properties accessible
|
hb_direction_t direction = HB_DIRECTION_INVALID; // Remove this, make segment_properties accessible
|
||||||
GArray *lines = nullptr;
|
GArray *lines = nullptr;
|
||||||
int scale_bits = 0;
|
int scale_bits = 0;
|
||||||
|
@ -142,7 +140,9 @@ view_cairo_t::render (const font_options_t *font_opts)
|
||||||
/* Create surface. */
|
/* Create surface. */
|
||||||
cairo_t *cr = helper_cairo_create_context (w + margin.l + margin.r,
|
cairo_t *cr = helper_cairo_create_context (w + margin.l + margin.r,
|
||||||
h + margin.t + margin.b,
|
h + margin.t + margin.b,
|
||||||
static_cast<view_options_t *> (this), &output_options, content);
|
static_cast<view_options_t *> (this),
|
||||||
|
static_cast<output_options_t *> (this),
|
||||||
|
content);
|
||||||
cairo_set_scaled_font (cr, scaled_font);
|
cairo_set_scaled_font (cr, scaled_font);
|
||||||
|
|
||||||
/* Setup coordinate system. */
|
/* Setup coordinate system. */
|
||||||
|
|
Loading…
Reference in New Issue