[pango/simple-fontmap: 15/16] pango-view: Add a --font-file option
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/simple-fontmap: 15/16] pango-view: Add a --font-file option
- Date: Thu, 23 Dec 2021 17:20:14 +0000 (UTC)
commit fd479ce6a43665d8e5aa4468d7e0d6b4b13f1dcb
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 | 72 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c
index 8fe9db59..3b450d94 100644
--- a/utils/viewer-pangocairo.c
+++ b/utils/viewer-pangocairo.c
@@ -25,8 +25,11 @@
#include "viewer-cairo.h"
#include <pango/pangocairo.h>
+#include <pango/pangofc-fontmap2.h>
static int opt_annotate = 0;
+static const char **opt_font_file = NULL;
+static const char *opt_fontmap = NULL;
typedef struct
{
@@ -48,8 +51,71 @@ 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 (g_strcmp0 (opt_fontmap, "fc2") == 0)
+ {
+ instance->fontmap = PANGO_FONT_MAP (pango_fc_font_map2_new ());
+ pango_simple_font_map_set_resolution (PANGO_SIMPLE_FONT_MAP (instance->fontmap), opt_dpi);
+ }
+ else if (g_strcmp0 (opt_fontmap, "simple") == 0)
+ {
+ instance->fontmap = PANGO_FONT_MAP (pango_simple_font_map_new ());
+ pango_simple_font_map_set_resolution (PANGO_SIMPLE_FONT_MAP (instance->fontmap), opt_dpi);
+ }
+ else
+ {
+ 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)
+ {
+ PangoFontFamily *fam;
+
+ for (int i = 0; opt_font_file[i]; i++)
+ {
+ if (PANGO_IS_SIMPLE_FONT_MAP (instance->fontmap))
+ pango_simple_font_map_add_file (PANGO_SIMPLE_FONT_MAP (instance->fontmap), opt_font_file[i]);
+ }
+
+ if (g_strcmp0 (opt_fontmap, "simple") == 0)
+ {
+ fam = pango_font_map_get_family (instance->fontmap, "Cantarell");
+ if (fam)
+ {
+ PangoFontFace *face = pango_font_family_get_face (fam, "Regular");
+ PangoHbFace *slanted;
+ PangoMatrix matrix = { 1., -0.2,
+ 0., 1.,
+ 0., 0. };
+
+ slanted = pango_hb_face_new_transformed (PANGO_HB_FACE (face), &matrix, "Italic");
+ pango_simple_font_map_add_face (PANGO_SIMPLE_FONT_MAP (instance->fontmap), slanted);
+ g_object_unref (slanted);
+
+ matrix = (PangoMatrix) { 0.5, 0., 0., 1., 0., 0. };
+
+ slanted = pango_hb_face_new_transformed (PANGO_HB_FACE (face), &matrix, "Condensed");
+ pango_simple_font_map_add_face (PANGO_SIMPLE_FONT_MAP (instance->fontmap), slanted);
+ g_object_unref (slanted);
+ }
+
+ fam = pango_font_map_get_family (instance->fontmap, "Liberation Mono");
+ if (fam)
+ {
+ PangoFontFace *face = pango_font_family_get_face (fam, "Regular");
+ PangoHbFace *alias;
+
+ alias = pango_hb_face_new_alias (PANGO_HB_FACE (face), "Monospace");
+ pango_simple_font_map_add_face (PANGO_SIMPLE_FONT_MAP (instance->fontmap), alias);
+ g_object_unref (alias);
+ }
+ }
+ }
+ 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 +860,8 @@ 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"},
+ {"fontmap", 0, 0, G_OPTION_ARG_STRING, &opt_fontmap, "Fontmap to use, default, simple or fc2 ", "NAME"},
{NULL}
};
GOptionGroup *group;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]