diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 3e7d8091c..6d454b711 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -95,7 +95,8 @@ public: font (font_), palette ( #ifndef HB_NO_COLOR - font->face->table.CPAL->get_palette_colors (palette_) + // https://github.com/harfbuzz/harfbuzz/issues/5112 + font->face->table.CPAL->get_palette_colors (palette_ < font->face->table.CPAL->get_palette_count () ? palette_ : 0) #endif ), foreground (foreground_), diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index e33dffc94..64c3f62e1 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -203,7 +203,11 @@ extern "C" fn _hb_fontations_get_glyph_extents( let glyph_id = GlyphId::new(glyph); let x_extents = x_glyph_metrics.bounds(glyph_id); - let y_extents = if x_size == y_size { x_extents } else { y_glyph_metrics.bounds(glyph_id) }; + let y_extents = if x_size == y_size { + x_extents + } else { + y_glyph_metrics.bounds(glyph_id) + }; let (Some(x_extents), Some(y_extents)) = (x_extents, y_extents) else { return false as hb_bool_t; }; @@ -703,6 +707,12 @@ extern "C" fn _hb_fontations_paint_glyph( let num_entries: usize = cpal.num_palette_entries().into(); let color_records = cpal.color_records_array(); let start_index = cpal.color_record_indices().get(palette_index as usize); + let start_index = if start_index.is_some() { + start_index + } else { + // https://github.com/harfbuzz/harfbuzz/issues/5112 + cpal.color_record_indices().get(0 as usize) + }; if let (Some(Ok(color_records)), Some(start_index)) = (color_records, start_index) { let start_index: usize = start_index.get().into(); diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 22ae26f9a..e40b99087 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -491,6 +491,11 @@ hb_ft_paint_glyph_colr (hb_font_t *font, (void) FT_Palette_Data_Get(ft_face, &palette_data); (void) FT_Palette_Select(ft_face, palette_index, &palette); + if (!palette) + { + // https://github.com/harfbuzz/harfbuzz/issues/5112 + (void) FT_Palette_Select(ft_face, 0, &palette); + } auto palette_array = hb_array ((const FT_Color *) palette, palette ? palette_data.num_palette_entries : 0);