[pango] Bug 582698 - Support CSS-style margin specification



commit 1a36b77ee5030c099eff8a6ac7f0081a4a46d69d
Author: Behdad Esfahbod <behdad behdad org>
Date:   Thu Apr 1 03:33:22 2010 -0400

    Bug 582698 - Support CSS-style margin specification

 pango-view/viewer-render.c |   41 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 34 insertions(+), 7 deletions(-)
---
diff --git a/pango-view/viewer-render.c b/pango-view/viewer-render.c
index e672dcd..8e3cc7f 100644
--- a/pango-view/viewer-render.c
+++ b/pango-view/viewer-render.c
@@ -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,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]