[pango/simple-fontmap: 11/18] pango-view: Add a --font-file option




commit 088954c3b70cc91e533beef455f70f7711eed0a4
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Aug 31 07:47:17 2021 -0400

    pango-view: Add a --font-file option
    
    The option can be used multiple times, to create
    a simple fontmap that has exactly the given
    font files, and nothing else.
    
    If the option isn't used, behave as before
    and use a default fontmap.

 utils/viewer-pangocairo.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c
index 9c69647b..1b3d2f80 100644
--- a/utils/viewer-pangocairo.c
+++ b/utils/viewer-pangocairo.c
@@ -27,6 +27,7 @@
 #include <pango/pangocairo.h>
 
 static int opt_annotate = 0;
+static const char **opt_font_file = NULL;
 
 typedef struct
 {
@@ -48,8 +49,18 @@ pangocairo_view_create (const PangoViewer *klass G_GNUC_UNUSED)
 
   instance->backend = cairo_viewer_iface_create (&instance->iface);
 
-  instance->fontmap = pango_cairo_font_map_new ();
-  pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (instance->fontmap), opt_dpi);
+  if (opt_font_file != NULL)
+    {
+      instance->fontmap = PANGO_FONT_MAP (pango_simple_font_map_new ());
+      pango_simple_font_map_set_resolution (PANGO_SIMPLE_FONT_MAP (instance->fontmap), opt_dpi);
+      for (int i = 0; opt_font_file[i]; i++)
+        pango_simple_font_map_add_file (PANGO_SIMPLE_FONT_MAP (instance->fontmap), opt_font_file[i], 0);
+    }
+  else
+    {
+      instance->fontmap = pango_cairo_font_map_new ();
+      pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (instance->fontmap), opt_dpi);
+    }
 
   instance->font_options = cairo_font_options_create ();
   if (opt_hinting != HINT_DEFAULT)
@@ -796,6 +807,7 @@ pangocairo_view_get_option_group (const PangoViewer *klass G_GNUC_UNUSED)
   GOptionEntry entries[] =
   {
     {"annotate", 0, 0, G_OPTION_ARG_CALLBACK, parse_annotate_arg, annotate_arg_help, "FLAGS"},
+    {"font-file", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_font_file, "Font file to use", "FILE"},
     {NULL}
   };
   GOptionGroup *group;


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