summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-07-01 09:57:35 -0400
committerMatthias Clasen <mclasen@redhat.com>2022-07-04 11:24:16 -0400
commit8ee5fe2707db5013dc53084ec1ac44e91b863f6d (patch)
tree1535b516d1df78b14be71ee84315a3318687d25c /utils
parent9954891c66a241338cc48d2c2236b12dd2368572 (diff)
downloadpango-8ee5fe2707db5013dc53084ec1ac44e91b863f6d.tar.gz
Support color palettes in fonts
Add a pango_context_set_palette to select whether we prefer the default palette, the palette for light background, or the palette for dark background. Also add a palette attribute that can be used to override this. Make the cairo renderer pick up the palette, and apply it when installing the font for a run. Predefined palette names are "default", "light", "dark", "palette0", "palette1", ... Additionally, PangoHbFace can associate custom names with palette indices. To try this, use the new --palette option of pango-view. Fonts to try this with are Amiri Quran Colored or the Bungee Color family.
Diffstat (limited to 'utils')
-rw-r--r--utils/viewer-pangocairo.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c
index d51b2055..b6e906a8 100644
--- a/utils/viewer-pangocairo.c
+++ b/utils/viewer-pangocairo.c
@@ -34,6 +34,7 @@
static int opt_annotate = 0;
static gboolean opt_userfont = 0;
static char **opt_font_file = NULL;
+static char *opt_palette = NULL;
typedef struct
{
@@ -44,6 +45,7 @@ typedef struct
Pango2FontMap *fontmap;
cairo_font_options_t *font_options;
gboolean subpixel_positions;
+ const char *palette;
} CairoViewer;
static gpointer
@@ -66,8 +68,8 @@ pangocairo_view_create (const Pango2Viewer *klass G_GNUC_UNUSED)
Pango2FontFace *face;
face = PANGO2_FONT_FACE (pango2_hb_face_new_from_file (opt_font_file[i],
- 0, -1,
- NULL, NULL));
+ 0, -1,
+ NULL, NULL));
pango2_font_map_add_face (instance->fontmap, face);
@@ -119,6 +121,7 @@ pangocairo_view_create (const Pango2Viewer *klass G_GNUC_UNUSED)
cairo_font_options_set_antialias (instance->font_options, (cairo_antialias_t)opt_antialias);
instance->subpixel_positions = opt_subpixel_positions;
+ instance->palette = opt_palette;
return instance;
}
@@ -146,6 +149,7 @@ pangocairo_view_get_context (gpointer instance)
context = pango2_context_new_with_font_map (c->fontmap);
pango2_cairo_context_set_font_options (context, c->font_options);
pango2_context_set_round_glyph_positions (context, !c->subpixel_positions);
+ pango2_context_set_palette (context, c->palette);
return context;
}
@@ -973,6 +977,7 @@ pangocairo_view_get_option_group (const Pango2Viewer *klass G_GNUC_UNUSED)
{"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" },
{ "userfont", 0, 0, G_OPTION_ARG_NONE, &opt_userfont, "Add userfont" },
+ { "palette", 0, 0, G_OPTION_ARG_STRING, &opt_palette, "Preferred palette", "PALETTE" },
{NULL}
};
GOptionGroup *group;