From 497be71ce81f0849a83378ccb490ad0d1e59b9c1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 19 Nov 2021 02:19:00 -0500 Subject: [PATCH 1/3] Tweak word and sentence attributes The value does not really matter for these, but it looks more natural if they have a value of 1, and not 0. --- pango/pango-attributes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index cfaf9b172..04179fbb7 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -1391,7 +1391,7 @@ pango_attr_word_new (void) pango_attr_int_equal, }; - return pango_attr_int_new (&klass, 0); + return pango_attr_int_new (&klass, 1); } /** @@ -1418,7 +1418,7 @@ pango_attr_sentence_new (void) pango_attr_int_equal, }; - return pango_attr_int_new (&klass, 0); + return pango_attr_int_new (&klass, 1); } /** -- GitLab From 5087dc434ed8e3aa475b30caebce80c1f362f90f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 19 Nov 2021 02:19:43 -0500 Subject: [PATCH 2/3] pango-view: Fix display of char extents --- utils/viewer-pangocairo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c index 9c69647b2..981b93176 100644 --- a/utils/viewer-pangocairo.c +++ b/utils/viewer-pangocairo.c @@ -424,7 +424,7 @@ render_callback (PangoLayout *layout, { PangoRectangle rect; - pango_layout_iter_get_cluster_extents (iter, NULL, &rect); + pango_layout_iter_get_char_extents (iter, &rect); cairo_rectangle (cr, (double)rect.x / PANGO_SCALE - lw / 2, (double)rect.y / PANGO_SCALE - lw / 2, -- GitLab From b3b87f6779eeef17202d0f82f775d142d6a5d60c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 19 Nov 2021 13:18:43 -0500 Subject: [PATCH 3/3] pango-view: Allow loading serialized layouts You can now do pango-view --serialized file All layout-related options will be overwritten by the serialized data. Other options can still be used. --- utils/viewer-render.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/utils/viewer-render.c b/utils/viewer-render.c index 020e308cf..23e13c712 100644 --- a/utils/viewer-render.c +++ b/utils/viewer-render.c @@ -77,6 +77,8 @@ guint16 opt_fg_alpha = 65535; gboolean opt_bg_set = FALSE; PangoColor opt_bg_color = {65535, 65535, 65535}; guint16 opt_bg_alpha = 65535; +gboolean opt_serialized = FALSE; +const char *file_arg; /* Text (or markup) to render */ static char *text; @@ -103,6 +105,23 @@ make_layout(PangoContext *context, PangoAlignment align; PangoLayout *layout; + if (opt_serialized) + { + char *text; + gsize len; + GBytes *bytes; + GError *error = NULL; + + if (!g_file_get_contents (file_arg, &text, &len, &error)) + fail ("%s\n", error->message); + bytes = g_bytes_new_take (text, size); + layout = pango_layout_deserialize (context, bytes, &error); + if (!layout) + fail ("%s\n", error->message); + g_bytes_unref (bytes); + return layout; + } + layout = pango_layout_new (context); if (opt_markup) pango_layout_set_markup (layout, text, -1); @@ -868,6 +887,8 @@ parse_options (int argc, char *argv[]) "Width in points to which to wrap lines or ellipsize", "points"}, {"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}, {NULL} }; GError *error = NULL; @@ -911,6 +932,12 @@ parse_options (int argc, char *argv[]) exit (1); } + if (opt_serialized && argc != 2) + { + g_printerr ("Usage: %s [OPTION...] FILE\n", g_get_prgname ()); + exit (1); + } + /* set up the backend */ if (!opt_viewer) { @@ -921,7 +948,13 @@ parse_options (int argc, char *argv[]) /* Get the text */ - if (opt_text) + if (opt_serialized) + { + file_arg = argv[1]; + text = g_strdup (""); + len = 0; + } + else if (opt_text) { text = g_strdup (opt_text); len = strlen (text); -- GitLab