Commit 1a36b77e authored by Behdad Esfahbod's avatar Behdad Esfahbod

Bug 582698 - Support CSS-style margin specification

parent 91d8773a
......@@ -38,7 +38,10 @@ gboolean opt_pixels = FALSE;
const char *opt_font = "";
gboolean opt_header = FALSE;
const char *opt_output = NULL;
int opt_margin = 10;
int opt_margin_t = 10;
int opt_margin_r = 10;
int opt_margin_b = 10;
int opt_margin_l = 10;
int opt_markup = FALSE;
gboolean opt_rtl = FALSE;
double opt_rotate = 0;
......@@ -248,8 +251,8 @@ do_output (PangoContext *context,
PangoMatrix *orig_matrix;
gboolean supports_matrix;
int rotated_width, rotated_height;
int x = opt_margin;
int y = opt_margin;
int x = opt_margin_l;
int y = opt_margin_t;
int width, height;
width = 0;
......@@ -331,8 +334,8 @@ do_output (PangoContext *context,
width = MAX (width, rect.width);
height += rect.height;
width += 2 * opt_margin;
height += 2 * opt_margin;
width += opt_margin_l + opt_margin_r;
height += opt_margin_t + opt_margin_b;
if (width_out)
*width_out = width;
......@@ -543,6 +546,30 @@ parse_background (const char *name,
name, arg, data, error);
}
static gboolean
parse_margin (const char *name G_GNUC_UNUSED,
const char *arg,
gpointer data G_GNUC_UNUSED,
GError **error)
{
switch (sscanf (arg, "%d %d %d %d", &opt_margin_t, &opt_margin_r, &opt_margin_b, &opt_margin_l))
{
case 0:
{
g_set_error(error,
G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE,
"Argument for --margin must be one to four space-separated numbers");
return FALSE;
}
case 1: opt_margin_r = opt_margin_t;
case 2: opt_margin_b = opt_margin_t;
case 3: opt_margin_l = opt_margin_r;
}
return TRUE;
}
static gchar *
backends_to_string (void)
{
......@@ -680,8 +707,8 @@ parse_options (int argc, char *argv[])
"Align paragraph lines to be justified", NULL},
{"language", 0, 0, G_OPTION_ARG_STRING, &opt_language,
"Language to use for font selection", "en_US/etc"},
{"margin", 0, 0, G_OPTION_ARG_INT, &opt_margin,
"Set the margin on the output in pixels", "pixels"},
{"margin", 0, 0, G_OPTION_ARG_CALLBACK, &parse_margin,
"Set the margin on the output in pixels", "CSS-style numbers in pixels"},
{"markup", 0, 0, G_OPTION_ARG_NONE, &opt_markup,
"Interpret text as Pango markup", NULL},
{"output", 'o', 0, G_OPTION_ARG_STRING, &opt_output,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment