summaryrefslogtreecommitdiff
path: root/pango/pangocairo-fcfont.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-02-13 13:19:45 -0600
committerMatthias Clasen <mclasen@redhat.com>2022-02-13 13:19:45 -0600
commitd4cf0b1c8dcdef31644879d6fbae11002828b927 (patch)
treecdf42ee36f3f1802aa6dbcd104633d8af94607da /pango/pangocairo-fcfont.c
parent9cb392f306e96534337b177eeee4e1239e8ab337 (diff)
downloadpango-font-palette-api.tar.gz
wip: Add an api to select palettes for color glyphsfont-palette-api
This commit adds a light-background attribute that can be used to influence which palette will be used to render COLRv0 layered glyphs with color fonts that have multiple palettes. This needs a way for cairo to invalidate its glyph cache when the selected palette changes, which needs new freetype api.
Diffstat (limited to 'pango/pangocairo-fcfont.c')
-rw-r--r--pango/pangocairo-fcfont.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c
index 4453b5ab..1e5b8c3e 100644
--- a/pango/pangocairo-fcfont.c
+++ b/pango/pangocairo-fcfont.c
@@ -35,6 +35,7 @@
#include <hb-ot.h>
#include <freetype/ftmm.h>
+#include <freetype/ftcolor.h>
#define PANGO_TYPE_CAIRO_FC_FONT (pango_cairo_fc_font_get_type ())
#define PANGO_CAIRO_FC_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_CAIRO_FC_FONT, PangoCairoFcFont))
@@ -275,3 +276,45 @@ _pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap,
return (PangoFcFont *) cffont;
}
+
+void
+pango_cairo_fc_font_install (PangoFcFont *font,
+ cairo_t *cr,
+ gboolean has_light_background)
+{
+ FT_Face face = pango_fc_font_lock_face (font);
+ FT_Palette_Data palettes;
+ int index = 0;
+ FT_Color *palette;
+
+ FT_Palette_Data_Get (face, &palettes);
+ for (int i = 0; i < palettes.num_palettes; i++)
+ {
+ if (has_light_background)
+ {
+ if (palettes.palette_flags[i] & FT_PALETTE_FOR_LIGHT_BACKGROUND)
+ {
+ index = i;
+ break;
+ }
+ }
+ else
+ {
+ if (palettes.palette_flags[i] & FT_PALETTE_FOR_DARK_BACKGROUND)
+ {
+ index = i;
+ break;
+ }
+ }
+ }
+
+ FT_Palette_Select (face, index, &palette);
+}
+
+void
+pango_cairo_fc_font_uninstall (PangoFcFont *font,
+ cairo_t *cr)
+{
+ pango_fc_font_unlock_face (font);
+}
+