summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-06-17 07:07:01 -0400
committerMatthias Clasen <mclasen@redhat.com>2022-06-22 13:57:26 -0400
commit92e2f4056a0322a4229dc7f595da3968b5896a6d (patch)
tree1d7da59faf6dd65bb748c4a3b9b40772e15560db
parentd2d4abe7b95d8f18800a0c0cf0d350989932016c (diff)
downloadpango-92e2f4056a0322a4229dc7f595da3968b5896a6d.tar.gz
pango-view: Add a --font-file option
This option sets up a fontmap with a single (or a few) fonts. This is for testing with specific fonts.
-rw-r--r--utils/viewer-pangocairo.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c
index 070045eb..2851fc08 100644
--- a/utils/viewer-pangocairo.c
+++ b/utils/viewer-pangocairo.c
@@ -30,6 +30,7 @@
#include <hb-ot.h>
static int opt_annotate = 0;
+static char **opt_font_file = NULL;
typedef struct
{
@@ -51,7 +52,40 @@ pangocairo_view_create (const PangoViewer *klass G_GNUC_UNUSED)
instance->backend = cairo_viewer_iface_create (&instance->iface);
- instance->fontmap = pango_font_map_new_default ();
+ if (opt_font_file != NULL)
+ {
+ PangoFontFace *first = NULL;
+
+ instance->fontmap = pango_font_map_new ();
+
+ for (int i = 0; opt_font_file[i]; i++)
+ {
+ PangoFontFace *face;
+
+ face = PANGO_FONT_FACE (pango_hb_face_new_from_file (opt_font_file[i],
+ 0, -1,
+ NULL, NULL));
+
+ pango_font_map_add_face (instance->fontmap, face);
+
+ if (!first)
+ first = face;
+ }
+
+ /* We always need monospace, or Pango will complain */
+ if (!pango_font_map_get_family (instance->fontmap, "monospace"))
+ {
+ PangoGenericFamily *family;
+
+ family = pango_generic_family_new ("monospace");
+ pango_generic_family_add_family (family, pango_font_face_get_family (first));
+ pango_font_map_add_family (instance->fontmap, PANGO_FONT_FAMILY (family));
+ }
+ }
+ else
+ {
+ instance->fontmap = pango_font_map_new_default ();
+ }
pango_font_map_set_resolution (PANGO_FONT_MAP (instance->fontmap), opt_dpi);
instance->font_options = cairo_font_options_create ();
@@ -930,6 +964,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, "Create a fontmap with this font", "FILE" },
{NULL}
};
GOptionGroup *group;