summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-12-17 13:05:05 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-12-17 13:05:05 -0500
commite54d4fd26f6e73a32b89fd8d72ec09103ecd386e (patch)
treeabd65ee1769d094d9a73cb4a0ff103b7b6636377
parent980b7e5b918f4ccee5ccf45806d212aa0fbf8035 (diff)
downloadpango-viewer-serialize-output.tar.gz
pango-view: Add --serialize-to optionviewer-serialize-output
Add an option to produce a serialized output.
-rw-r--r--utils/viewer-render.c19
1 files 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;