[pango/simple-fontmap: 275/278] pango-view: Add a --font-file option




commit 9afdaee19b934a7871acbb831c34673ce70cc806
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 8fe9db59..f83e3ba3 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, -1);
+    }
+  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)
@@ -794,6 +805,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]