[pango/viewer-serialize-output] pango-view: Add --serialize-to option




commit e54d4fd26f6e73a32b89fd8d72ec09103ecd386e
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 17 13:05:05 2021 -0500

    pango-view: Add --serialize-to option
    
    Add an option to produce a serialized output.

 utils/viewer-render.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/utils/viewer-render.c b/utils/viewer-render.c
index 0aee39a6..87b27829 100644
--- a/utils/viewer-render.c
+++ b/utils/viewer-render.c
@@ -78,6 +78,7 @@ gboolean opt_bg_set = FALSE;
 PangoColor opt_bg_color = {65535, 65535, 65535};
 guint16 opt_bg_alpha = 65535;
 gboolean opt_serialized = FALSE;
+const char *opt_serialized_output;
 const char *file_arg;
 
 /* Text (or markup) to render */
@@ -119,7 +120,7 @@ make_layout(PangoContext *context,
       if (!layout)
         fail ("%s\n", error->message);
       g_bytes_unref (bytes);
-      return layout;
+      goto out;
     }
 
   layout = pango_layout_new (context);
@@ -191,6 +192,18 @@ make_layout(PangoContext *context,
 
   pango_font_description_free (font_description);
 
+out:
+  if (opt_serialized_output)
+    {
+      GError *error = NULL;
+
+      if (!pango_layout_write_to_file (layout,
+                                       PANGO_LAYOUT_SERIALIZE_CONTEXT|PANGO_LAYOUT_SERIALIZE_OUTPUT,
+                                       opt_serialized_output,
+                                       &error))
+        fail ("%s\n", error->message);
+    }
+
   return layout;
 }
 
@@ -888,7 +901,9 @@ parse_options (int argc, char *argv[])
     {"wrap",           0, 0, G_OPTION_ARG_CALLBACK,                    &parse_wrap,
      "Text wrapping mode (needs a width to be set)",   "word/char/word-char"},
     {"serialized",       0, 0, G_OPTION_ARG_NONE,                        &opt_serialized,
-     "Create layout from a serialized file",                            NULL},
+     "Create layout from a serialized file",                            "FILE"},
+    {"serialize-to",     0, 0, G_OPTION_ARG_FILENAME,                  &opt_serialized_output,
+     "Serialize result to a file",                                      "FILE"},
     {NULL}
   };
   GError *error = NULL;


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