[util] Move output options into output-options.hh
This commit is contained in:
parent
af9d2495dc
commit
93bc62e9b2
|
@ -8,6 +8,7 @@ HB_VIEW_sources = \
|
|||
main-font-text.hh \
|
||||
options.cc \
|
||||
options.hh \
|
||||
output-options.hh \
|
||||
shape-consumer.hh \
|
||||
shape-options.hh \
|
||||
view-cairo.hh \
|
||||
|
@ -21,11 +22,22 @@ HB_SHAPE_sources = \
|
|||
main-font-text.hh \
|
||||
options.cc \
|
||||
options.hh \
|
||||
output-options.hh \
|
||||
shape-consumer.hh \
|
||||
shape-format.hh \
|
||||
shape-options.hh \
|
||||
$(NULL)
|
||||
|
||||
HB_SUBSET_CLI_sources = \
|
||||
face-options.hh \
|
||||
hb-subset.cc \
|
||||
main-font-text.hh \
|
||||
options.cc \
|
||||
options.hh \
|
||||
output-options.hh \
|
||||
subset-options.hh \
|
||||
$(NULL)
|
||||
|
||||
HB_OT_SHAPE_CLOSURE_sources = \
|
||||
face-options.hh \
|
||||
font-options.hh \
|
||||
|
@ -34,12 +46,3 @@ HB_OT_SHAPE_CLOSURE_sources = \
|
|||
options.cc \
|
||||
options.hh \
|
||||
$(NULL)
|
||||
|
||||
HB_SUBSET_CLI_sources = \
|
||||
face-options.hh \
|
||||
hb-subset.cc \
|
||||
main-font-text.hh \
|
||||
options.cc \
|
||||
options.hh \
|
||||
subset-options.hh \
|
||||
$(NULL)
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "shape-consumer.hh"
|
||||
#include "shape-format.hh"
|
||||
#include "output-options.hh"
|
||||
#include "main-font-text.hh"
|
||||
|
||||
const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "subset-options.hh"
|
||||
#include "output-options.hh"
|
||||
#include "face-options.hh"
|
||||
#include "main-font-text.hh"
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#ifndef HELPER_CAIRO_HH
|
||||
#define HELPER_CAIRO_HH
|
||||
|
||||
#include "hb.hh"
|
||||
#include "options.hh"
|
||||
#include "view-options.hh"
|
||||
#include "output-options.hh"
|
||||
|
||||
#include <cairo-ft.h>
|
||||
#include <hb-ft.h>
|
||||
|
|
|
@ -121,34 +121,6 @@ text_options_t::add_options (option_parser_t *parser)
|
|||
this);
|
||||
}
|
||||
|
||||
void
|
||||
output_options_t::add_options (option_parser_t *parser,
|
||||
const char **supported_formats)
|
||||
{
|
||||
const char *text = nullptr;
|
||||
|
||||
if (supported_formats)
|
||||
{
|
||||
char *items = g_strjoinv ("/", const_cast<char **> (supported_formats));
|
||||
text = g_strdup_printf ("Set output format\n\n Supported output formats are: %s", items);
|
||||
g_free (items);
|
||||
parser->free_later ((char *) text);
|
||||
}
|
||||
|
||||
GOptionEntry entries[] =
|
||||
{
|
||||
{"output-file", 'o', 0, G_OPTION_ARG_STRING, &this->output_file, "Set output file-name (default: stdout)","filename"},
|
||||
{"output-format", 'O', supported_formats ? 0 : G_OPTION_FLAG_HIDDEN,
|
||||
G_OPTION_ARG_STRING, &this->output_format, text, "format"},
|
||||
{nullptr}
|
||||
};
|
||||
parser->add_group (entries,
|
||||
"output",
|
||||
"Output destination & format options:",
|
||||
"Options for the destination & form of the output",
|
||||
this);
|
||||
}
|
||||
|
||||
const char *
|
||||
text_options_t::get_line (unsigned int *len, int eol)
|
||||
{
|
||||
|
@ -217,25 +189,3 @@ text_options_t::get_line (unsigned int *len, int eol)
|
|||
*len = gs->len;
|
||||
return !*len && feof (fp) ? nullptr : gs->str;
|
||||
}
|
||||
|
||||
|
||||
FILE *
|
||||
output_options_t::get_file_handle ()
|
||||
{
|
||||
if (fp)
|
||||
return fp;
|
||||
|
||||
if (output_file)
|
||||
fp = fopen (output_file, "wb");
|
||||
else {
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
setmode (fileno (stdout), O_BINARY);
|
||||
#endif
|
||||
fp = stdout;
|
||||
}
|
||||
if (!fp)
|
||||
fail (false, "Cannot open output file `%s': %s",
|
||||
g_filename_display_name (output_file), strerror (errno));
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
|
|
@ -261,46 +261,6 @@ struct text_options_t
|
|||
unsigned int line_len = UINT_MAX;
|
||||
};
|
||||
|
||||
struct output_options_t
|
||||
{
|
||||
~output_options_t ()
|
||||
{
|
||||
g_free (output_file);
|
||||
g_free (output_format);
|
||||
if (fp && fp != stdout)
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
void add_options (option_parser_t *parser,
|
||||
const char **supported_formats = nullptr);
|
||||
|
||||
void post_parse (GError **error G_GNUC_UNUSED)
|
||||
{
|
||||
if (output_format)
|
||||
explicit_output_format = true;
|
||||
|
||||
if (output_file && !output_format) {
|
||||
output_format = strrchr (output_file, '.');
|
||||
if (output_format)
|
||||
{
|
||||
output_format++; /* skip the dot */
|
||||
output_format = g_strdup (output_format);
|
||||
}
|
||||
}
|
||||
|
||||
if (output_file && 0 == strcmp (output_file, "-"))
|
||||
output_file = nullptr; /* STDOUT */
|
||||
}
|
||||
|
||||
FILE *get_file_handle ();
|
||||
|
||||
char *output_file = nullptr;
|
||||
char *output_format = nullptr;
|
||||
bool explicit_output_format = false;
|
||||
|
||||
mutable FILE *fp = nullptr;
|
||||
};
|
||||
|
||||
|
||||
/* fallback implementation for scalbn()/scalbnf() for pre-2013 MSVC */
|
||||
#if defined (_MSC_VER) && (_MSC_VER < 1800)
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright © 2011 Google, Inc.
|
||||
*
|
||||
* This is part of HarfBuzz, a text shaping library.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that the
|
||||
* above copyright notice and the following two paragraphs appear in
|
||||
* all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*
|
||||
* Google Author(s): Behdad Esfahbod
|
||||
*/
|
||||
|
||||
#ifndef OUTPUT_OPTIONS_HH
|
||||
#define OUTPUT_OPTIONS_HH
|
||||
|
||||
#include "options.hh"
|
||||
|
||||
struct output_options_t
|
||||
{
|
||||
~output_options_t ()
|
||||
{
|
||||
g_free (output_file);
|
||||
g_free (output_format);
|
||||
if (fp && fp != stdout)
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
void add_options (option_parser_t *parser,
|
||||
const char **supported_formats = nullptr);
|
||||
|
||||
void post_parse (GError **error G_GNUC_UNUSED)
|
||||
{
|
||||
if (output_format)
|
||||
explicit_output_format = true;
|
||||
|
||||
if (output_file && !output_format) {
|
||||
output_format = strrchr (output_file, '.');
|
||||
if (output_format)
|
||||
{
|
||||
output_format++; /* skip the dot */
|
||||
output_format = g_strdup (output_format);
|
||||
}
|
||||
}
|
||||
|
||||
if (output_file && 0 == strcmp (output_file, "-"))
|
||||
output_file = nullptr; /* STDOUT */
|
||||
}
|
||||
|
||||
FILE *get_file_handle ();
|
||||
|
||||
char *output_file = nullptr;
|
||||
char *output_format = nullptr;
|
||||
bool explicit_output_format = false;
|
||||
|
||||
mutable FILE *fp = nullptr;
|
||||
};
|
||||
|
||||
|
||||
FILE *
|
||||
output_options_t::get_file_handle ()
|
||||
{
|
||||
if (fp)
|
||||
return fp;
|
||||
|
||||
if (output_file)
|
||||
fp = fopen (output_file, "wb");
|
||||
else {
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
setmode (fileno (stdout), O_BINARY);
|
||||
#endif
|
||||
fp = stdout;
|
||||
}
|
||||
if (!fp)
|
||||
fail (false, "Cannot open output file `%s': %s",
|
||||
g_filename_display_name (output_file), strerror (errno));
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
output_options_t::add_options (option_parser_t *parser,
|
||||
const char **supported_formats)
|
||||
{
|
||||
const char *text = nullptr;
|
||||
|
||||
if (supported_formats)
|
||||
{
|
||||
char *items = g_strjoinv ("/", const_cast<char **> (supported_formats));
|
||||
text = g_strdup_printf ("Set output format\n\n Supported output formats are: %s", items);
|
||||
g_free (items);
|
||||
parser->free_later ((char *) text);
|
||||
}
|
||||
|
||||
GOptionEntry entries[] =
|
||||
{
|
||||
{"output-file", 'o', 0, G_OPTION_ARG_STRING, &this->output_file, "Set output file-name (default: stdout)","filename"},
|
||||
{"output-format", 'O', supported_formats ? 0 : G_OPTION_FLAG_HIDDEN,
|
||||
G_OPTION_ARG_STRING, &this->output_format, text, "format"},
|
||||
{nullptr}
|
||||
};
|
||||
parser->add_group (entries,
|
||||
"output",
|
||||
"Output destination & format options:",
|
||||
"Options for the destination & form of the output",
|
||||
this);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -28,6 +28,7 @@
|
|||
#define VIEW_CAIRO_HH
|
||||
|
||||
#include "view-options.hh"
|
||||
#include "output-options.hh"
|
||||
#include "helper-cairo.hh"
|
||||
|
||||
struct view_cairo_t : view_options_t, output_options_t
|
||||
|
|
Loading…
Reference in New Issue