mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-26 01:11:25 +01:00
[cairo][util/hb-view] Honor --draw / --paint via cairo color mode
hb-cairo's render_color_glyph drops _or_fail in favor of the synthesizing hb_font_paint_glyph, so the paint callback handles every glyph (color or mono) through the paint pipeline instead of returning NOT_IMPLEMENTED on non-color glyphs and forcing cairo to fall through to the outline path. Hb-view's helper-cairo then picks paint vs draw the same way the other utils do — --paint wins over --draw, otherwise auto-detect via the font's color tables — and expresses "draw" by setting CAIRO_COLOR_MODE_NO_COLOR on the font options (which makes cairo skip render_color_glyph entirely, falling through to render_glyph for the cheaper outline path). No new public API. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ffd4772e05
commit
e933f71b0d
2 files changed
+25
-2
No files matched your search
+6
-2
@@ -645,8 +645,12 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font,
|
||||
c.cr = cr;
|
||||
c.color_cache = (hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key);
|
||||
|
||||
if (!hb_font_paint_glyph_or_fail (font, glyph, hb_cairo_paint_get_funcs (), &c, palette, color))
|
||||
return CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED;
|
||||
/* Synthesizing variant: mono glyphs render here too via the
|
||||
* push_clip_glyph + foreground-fill fallback inside
|
||||
* hb_font_paint_glyph. Callers that want the cheaper
|
||||
* outline path for mono fonts set CAIRO_COLOR_MODE_NO_COLOR
|
||||
* on the font options instead. */
|
||||
hb_font_paint_glyph (font, glyph, hb_cairo_paint_get_funcs (), &c, palette, color);
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <cairo.h>
|
||||
#include <hb.h>
|
||||
#include <hb-cairo.h>
|
||||
#include <hb-ot.h>
|
||||
|
||||
#include "helper-cairo-ansi.hh"
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
@@ -119,6 +120,24 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts,
|
||||
font_options = cairo_font_options_create ();
|
||||
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
|
||||
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
|
||||
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,18,0)
|
||||
/* Pick draw vs paint mode. --paint wins over --draw;
|
||||
* otherwise auto-detect: route mono fonts through the
|
||||
* cheaper outline path (NO_COLOR) and color fonts through
|
||||
* the paint pipeline (cairo's default color mode). */
|
||||
hb_face_t *hb_face = hb_font_get_face (font);
|
||||
bool font_has_color = hb_ot_color_has_paint (hb_face) ||
|
||||
hb_ot_color_has_layers (hb_face) ||
|
||||
#ifndef HB_NO_SVG
|
||||
hb_ot_color_has_svg (hb_face) ||
|
||||
#endif
|
||||
hb_ot_color_has_png (hb_face);
|
||||
bool use_paint = view_opts->force_paint ? true
|
||||
: view_opts->force_draw ? false
|
||||
: font_has_color;
|
||||
if (!use_paint)
|
||||
cairo_font_options_set_color_mode (font_options, CAIRO_COLOR_MODE_NO_COLOR);
|
||||
#endif
|
||||
#ifdef CAIRO_COLOR_PALETTE_DEFAULT
|
||||
cairo_font_options_set_color_palette (font_options, view_opts->palette);
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user