From 7a748ad4acacd76b8c6285eab013a68813027997 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 10 Dec 2022 19:59:03 -0500 Subject: [PATCH] COLRv1: use ClipBoxes for extents This is a first step; ultimatively, we should compute the extents is ClipBoxes are missing. --- src/hb-ot-color-colr-table.hh | 49 +++++++++++++++++++++++++++++++++++ src/hb-ot-font.cc | 4 +++ 2 files changed, 53 insertions(+) diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 94a17649f..70941f8e9 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -928,6 +928,24 @@ struct ClipBox } } + bool get_extents (hb_glyph_extents_t *extents) const + { + switch (u.format) { + case 1: + extents->x_bearing = u.format1.xMin; + extents->y_bearing = u.format1.yMax; + extents->width = u.format1.xMax - u.format1.xMin; + extents->height = u.format1.yMin - u.format1.yMax; + return true; + case 2: + // TODO + return false; + default: + // This shouldn't happen + return false; + } + } + protected: union { HBUINT8 format; /* Format identifier */ @@ -953,6 +971,11 @@ struct ClipRecord return_trace (c->check_struct (this) && clipBox.sanitize (c, base)); } + bool get_extents (hb_glyph_extents_t *extents, const void *base) const + { + return (base+clipBox).get_extents (extents); + } + public: HBUINT16 startGlyphID; // first gid clip applies to HBUINT16 endGlyphID; // last gid clip applies to, inclusive @@ -1052,6 +1075,17 @@ struct ClipList return_trace (c->check_struct (this) && clips.sanitize (c, this)); } + bool + get_extents (hb_codepoint_t gid, hb_glyph_extents_t *extents) const + { + for (const ClipRecord& record : clips.iter ()) + { + if (record.startGlyphID <= gid && gid <= record.endGlyphID) + return record.get_extents (extents, this); + } + return false; + } + HBUINT8 format; // Set to 1. SortedArray32Of clips; // Clip records, sorted by startGlyphID public: @@ -1513,6 +1547,21 @@ struct COLR return_trace (true); } + bool + get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const + { + if ((this+clipList).get_extents (glyph, extents)) + { + extents->x_bearing = font->em_scale_x (extents->x_bearing); + extents->y_bearing = font->em_scale_x (extents->y_bearing); + extents->width = font->em_scale_x (extents->width); + extents->height = font->em_scale_x (extents->height); + return true; + } + + return false; + } + protected: HBUINT16 version; /* Table version number (starts at 0). */ HBUINT16 numBaseGlyphs; /* Number of Base Glyph Records. */ diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 0c30d5764..840510342 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -45,6 +45,7 @@ #include "hb-ot-vorg-table.hh" #include "hb-ot-color-cbdt-table.hh" #include "hb-ot-color-sbix-table.hh" +#include "hb-ot-color-colr-table.hh" /** @@ -349,6 +350,9 @@ hb_ot_get_glyph_extents (hb_font_t *font, #if !defined(HB_NO_OT_FONT_BITMAP) && !defined(HB_NO_COLOR) if (ot_face->sbix->get_extents (font, glyph, extents)) return true; if (ot_face->CBDT->get_extents (font, glyph, extents)) return true; +#endif +#if !defined(HB_NO_COLOR) + if (ot_face->COLR->get_extents (font, glyph, extents)) return true; #endif if (ot_face->glyf->get_extents (font, glyph, extents)) return true; #ifndef HB_NO_OT_FONT_CFF