More reshuffling
This commit is contained in:
parent
516857eb51
commit
bc4b07b05e
|
@ -149,7 +149,7 @@ draw (void)
|
||||||
cairo_glyph_t *glyphs = NULL;
|
cairo_glyph_t *glyphs = NULL;
|
||||||
unsigned int num_glyphs = 0;
|
unsigned int num_glyphs = 0;
|
||||||
|
|
||||||
const char *end, *p = shape_opts->text;
|
const char *end, *p = text;
|
||||||
double x, y;
|
double x, y;
|
||||||
|
|
||||||
cr= create_context ();
|
cr= create_context ();
|
||||||
|
@ -170,7 +170,7 @@ draw (void)
|
||||||
if (!end)
|
if (!end)
|
||||||
end = p + strlen (p);
|
end = p + strlen (p);
|
||||||
|
|
||||||
if (p != shape_opts->text)
|
if (p != text)
|
||||||
y += view_opts->line_space;
|
y += view_opts->line_space;
|
||||||
|
|
||||||
if (p != end) {
|
if (p != end) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ view_options_t view_opts[1];
|
||||||
shape_options_t shape_opts[1];
|
shape_options_t shape_opts[1];
|
||||||
font_options_t font_opts[1];
|
font_options_t font_opts[1];
|
||||||
|
|
||||||
|
const char *text;
|
||||||
const char *out_file = "/dev/stdout";
|
const char *out_file = "/dev/stdout";
|
||||||
hb_bool_t debug = FALSE;
|
hb_bool_t debug = FALSE;
|
||||||
|
|
||||||
|
@ -38,9 +39,10 @@ hb_bool_t debug = FALSE;
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_margin (const char *name G_GNUC_UNUSED,
|
parse_margin (const char *name G_GNUC_UNUSED,
|
||||||
const char *arg,
|
const char *arg,
|
||||||
gpointer data G_GNUC_UNUSED,
|
gpointer data,
|
||||||
GError **error G_GNUC_UNUSED)
|
GError **error G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
|
view_options_t *view_opts = (view_options_t *) data;
|
||||||
view_options_t::margin_t &m = view_opts->margin;
|
view_options_t::margin_t &m = view_opts->margin;
|
||||||
switch (sscanf (arg, "%lf %lf %lf %lf", &m.t, &m.r, &m.b, &m.l)) {
|
switch (sscanf (arg, "%lf %lf %lf %lf", &m.t, &m.r, &m.b, &m.l)) {
|
||||||
case 1: m.r = m.t;
|
case 1: m.r = m.t;
|
||||||
|
@ -59,9 +61,10 @@ parse_margin (const char *name G_GNUC_UNUSED,
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_shapers (const char *name G_GNUC_UNUSED,
|
parse_shapers (const char *name G_GNUC_UNUSED,
|
||||||
const char *arg,
|
const char *arg,
|
||||||
gpointer data G_GNUC_UNUSED,
|
gpointer data,
|
||||||
GError **error G_GNUC_UNUSED)
|
GError **error G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
|
shape_options_t *shape_opts = (shape_options_t *) data;
|
||||||
shape_opts->shapers = g_strsplit (arg, ",", 0);
|
shape_opts->shapers = g_strsplit (arg, ",", 0);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -191,9 +194,10 @@ skip_one_feature (char **pp)
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_features (const char *name G_GNUC_UNUSED,
|
parse_features (const char *name G_GNUC_UNUSED,
|
||||||
const char *arg,
|
const char *arg,
|
||||||
gpointer data G_GNUC_UNUSED,
|
gpointer data,
|
||||||
GError **error G_GNUC_UNUSED)
|
GError **error G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
|
shape_options_t *shape_opts = (shape_options_t *) data;
|
||||||
char *s = (char *) arg;
|
char *s = (char *) arg;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
|
@ -266,66 +270,66 @@ option_context_add_entries (GOptionContext *context,
|
||||||
GOptionEntry *entries,
|
GOptionEntry *entries,
|
||||||
const gchar *name,
|
const gchar *name,
|
||||||
const gchar *description,
|
const gchar *description,
|
||||||
const gchar *help_description)
|
const gchar *help_description,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
if (0) {
|
GOptionGroup *group = g_option_group_new (name, description, help_description, user_data, NULL);
|
||||||
GOptionGroup *group = g_option_group_new (name, description, help_description, NULL, NULL);
|
|
||||||
g_option_group_add_entries (group, entries);
|
g_option_group_add_entries (group, entries);
|
||||||
g_option_context_add_group (context, group);
|
g_option_context_add_group (context, group);
|
||||||
} else {
|
|
||||||
g_option_context_add_main_entries (context, entries, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
option_context_add_view_opts (GOptionContext *context)
|
view_options_t::add_options (GOptionContext *context)
|
||||||
{
|
{
|
||||||
GOptionEntry entries[] =
|
GOptionEntry entries[] =
|
||||||
{
|
{
|
||||||
{"annotate", 0, 0, G_OPTION_ARG_NONE, &view_opts->annotate, "Annotate output rendering", NULL},
|
{"annotate", 0, 0, G_OPTION_ARG_NONE, &this->annotate, "Annotate output rendering", NULL},
|
||||||
{"background", 0, 0, G_OPTION_ARG_STRING, &view_opts->back, "Set background color (default: "DEFAULT_BACK")", "red/#rrggbb/#rrggbbaa"},
|
{"background", 0, 0, G_OPTION_ARG_STRING, &this->back, "Set background color (default: "DEFAULT_BACK")", "red/#rrggbb/#rrggbbaa"},
|
||||||
{"foreground", 0, 0, G_OPTION_ARG_STRING, &view_opts->fore, "Set foreground color (default: "DEFAULT_FORE")", "red/#rrggbb/#rrggbbaa"},
|
{"foreground", 0, 0, G_OPTION_ARG_STRING, &this->fore, "Set foreground color (default: "DEFAULT_FORE")", "red/#rrggbb/#rrggbbaa"},
|
||||||
{"line-space", 0, 0, G_OPTION_ARG_DOUBLE, &view_opts->line_space, "Set space between lines (default: 0)", "units"},
|
{"line-space", 0, 0, G_OPTION_ARG_DOUBLE, &this->line_space, "Set space between lines (default: 0)", "units"},
|
||||||
{"margin", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_margin, "Margin around output (default: "G_STRINGIFY(DEFAULT_MARGIN)")","one to four numbers"},
|
{"margin", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_margin, "Margin around output (default: "G_STRINGIFY(DEFAULT_MARGIN)")","one to four numbers"},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
option_context_add_entries (context, entries,
|
option_context_add_entries (context, entries,
|
||||||
"view",
|
"view",
|
||||||
"View options:",
|
"View options:",
|
||||||
"Options controlling the output rendering");
|
"Options controlling the output rendering",
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
option_context_add_shape_opts (GOptionContext *context)
|
shape_options_t::add_options (GOptionContext *context)
|
||||||
{
|
{
|
||||||
GOptionEntry entries[] =
|
GOptionEntry entries[] =
|
||||||
{
|
{
|
||||||
{"shapers", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_shapers, "Comma-separated list of shapers", "list"},
|
{"shapers", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_shapers, "Comma-separated list of shapers", "list"},
|
||||||
{"direction", 0, 0, G_OPTION_ARG_STRING, &shape_opts->direction, "Set text direction (default: auto)", "ltr/rtl/ttb/btt"},
|
{"direction", 0, 0, G_OPTION_ARG_STRING, &this->direction, "Set text direction (default: auto)", "ltr/rtl/ttb/btt"},
|
||||||
{"language", 0, 0, G_OPTION_ARG_STRING, &shape_opts->language, "Set text language (default: $LANG)", "langstr"},
|
{"language", 0, 0, G_OPTION_ARG_STRING, &this->language, "Set text language (default: $LANG)", "langstr"},
|
||||||
{"script", 0, 0, G_OPTION_ARG_STRING, &shape_opts->script, "Set text script (default: auto)", "ISO-15924 tag"},
|
{"script", 0, 0, G_OPTION_ARG_STRING, &this->script, "Set text script (default: auto)", "ISO-15924 tag"},
|
||||||
{"features", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_features, "Font features to apply to text", "TODO"},
|
{"features", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer) &parse_features, "Font features to apply to text", "TODO"},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
option_context_add_entries (context, entries,
|
option_context_add_entries (context, entries,
|
||||||
"shape",
|
"shape",
|
||||||
"Shape options:",
|
"Shape options:",
|
||||||
"Options controlling the shaping process");
|
"Options controlling the shaping process",
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
option_context_add_font_opts (GOptionContext *context)
|
font_options_t::add_options (GOptionContext *context)
|
||||||
{
|
{
|
||||||
GOptionEntry entries[] =
|
GOptionEntry entries[] =
|
||||||
{
|
{
|
||||||
{"face-index", 0, 0, G_OPTION_ARG_INT, &font_opts->face_index, "Face index (default: 0)", "index"},
|
{"face-index", 0, 0, G_OPTION_ARG_INT, &this->face_index, "Face index (default: 0)", "index"},
|
||||||
{"font-size", 0, 0, G_OPTION_ARG_DOUBLE, &font_opts->font_size, "Font size (default: "G_STRINGIFY(DEFAULT_FONT_SIZE)")","size"},
|
{"font-size", 0, 0, G_OPTION_ARG_DOUBLE, &this->font_size, "Font size (default: "G_STRINGIFY(DEFAULT_FONT_SIZE)")","size"},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
option_context_add_entries (context, entries,
|
option_context_add_entries (context, entries,
|
||||||
"font",
|
"font",
|
||||||
"Font options:",
|
"Font options:",
|
||||||
"Options controlling the font");
|
"Options controlling the font",
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -345,9 +349,9 @@ parse_options (int argc, char *argv[])
|
||||||
context = g_option_context_new ("- FONT-FILE TEXT");
|
context = g_option_context_new ("- FONT-FILE TEXT");
|
||||||
|
|
||||||
g_option_context_add_main_entries (context, entries, NULL);
|
g_option_context_add_main_entries (context, entries, NULL);
|
||||||
option_context_add_view_opts (context);
|
view_opts->add_options (context);
|
||||||
option_context_add_shape_opts (context);
|
shape_opts->add_options (context);
|
||||||
option_context_add_font_opts (context);
|
font_opts->add_options (context);
|
||||||
|
|
||||||
if (!g_option_context_parse (context, &argc, &argv, &parse_error))
|
if (!g_option_context_parse (context, &argc, &argv, &parse_error))
|
||||||
{
|
{
|
||||||
|
@ -365,5 +369,5 @@ parse_options (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
font_opts->font_file = argv[1];
|
font_opts->font_file = argv[1];
|
||||||
shape_opts->text = argv[2];
|
text = argv[2];
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ extern struct view_options_t
|
||||||
margin.t = margin.r = margin.b = margin.l = DEFAULT_MARGIN;
|
margin.t = margin.r = margin.b = margin.l = DEFAULT_MARGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_options (GOptionContext *context);
|
||||||
|
|
||||||
hb_bool_t annotate;
|
hb_bool_t annotate;
|
||||||
const char *fore;
|
const char *fore;
|
||||||
const char *back;
|
const char *back;
|
||||||
|
@ -63,6 +65,8 @@ extern struct shape_options_t
|
||||||
g_free (shapers);
|
g_free (shapers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_options (GOptionContext *context);
|
||||||
|
|
||||||
void setup_buffer (hb_buffer_t *buffer) {
|
void setup_buffer (hb_buffer_t *buffer) {
|
||||||
hb_buffer_set_direction (buffer, hb_direction_from_string (direction, -1));
|
hb_buffer_set_direction (buffer, hb_direction_from_string (direction, -1));
|
||||||
hb_buffer_set_script (buffer, hb_script_from_string (script, -1));
|
hb_buffer_set_script (buffer, hb_script_from_string (script, -1));
|
||||||
|
@ -74,7 +78,6 @@ extern struct shape_options_t
|
||||||
return hb_shape_full (font, buffer, features, num_features, NULL, shapers);
|
return hb_shape_full (font, buffer, features, num_features, NULL, shapers);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *text;
|
|
||||||
const char *direction;
|
const char *direction;
|
||||||
const char *language;
|
const char *language;
|
||||||
const char *script;
|
const char *script;
|
||||||
|
@ -93,20 +96,18 @@ extern struct font_options_t
|
||||||
font_size = DEFAULT_FONT_SIZE;
|
font_size = DEFAULT_FONT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_options (GOptionContext *context);
|
||||||
|
|
||||||
const char *font_file;
|
const char *font_file;
|
||||||
int face_index;
|
int face_index;
|
||||||
double font_size;
|
double font_size;
|
||||||
} font_opts[1];
|
} font_opts[1];
|
||||||
|
|
||||||
|
|
||||||
|
extern const char *text;
|
||||||
extern const char *out_file;
|
extern const char *out_file;
|
||||||
extern hb_bool_t debug;
|
extern hb_bool_t debug;
|
||||||
|
|
||||||
|
|
||||||
void option_context_add_view_opts (GOptionContext *context);
|
|
||||||
void option_context_add_shape_opts (GOptionContext *context);
|
|
||||||
void option_context_add_font_opts (GOptionContext *context);
|
|
||||||
|
|
||||||
void parse_options (int argc, char *argv[]);
|
void parse_options (int argc, char *argv[]);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue