LibGfx+LibWeb: Update definitions of supported font formats and features

Based very scientifically on what's listed here:
https://harfbuzz.github.io/what-does-harfbuzz-do.html

I've moved the code into LibGfx because including a HarfBuzz header
directly from LibWeb is a little unpleasant. But the Gfx::FontTech enum
follows the CSS definitions for font features for simplicity.

TrueType collections are supported. SVG and Embedded OpenType are not,
but they're not widely supported by other browsers so that's fine.

Most of the features are completely supported by HarfBuzz, so we can
just return true. Graphite support is optional (and it appears we use a
build of HarfBuzz without it) but there's a define we can check.
Incremental Font Transfer is a whole separate thing that we definitely
don't support yet.
This commit is contained in:
Sam Atkins 2025-06-03 15:48:24 +01:00
commit 5a1c73d7e2
Notes: github-actions[bot] 2025-06-05 11:39:09 +00:00
6 changed files with 155 additions and 32 deletions

View file

@ -8,6 +8,7 @@
#include <AK/ByteBuffer.h>
#include <LibCore/Promise.h>
#include <LibGC/Heap.h>
#include <LibGfx/Font/FontSupport.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/Font/WOFF/Loader.h>
#include <LibGfx/Font/WOFF2/Loader.h>
@ -516,54 +517,52 @@ GC::Ref<WebIDL::Promise> FontFace::load()
bool font_format_is_supported(FlyString const& name)
{
// https://drafts.csswg.org/css-fonts-4/#font-format-definitions
// FIXME: Determine this automatically somehow?
if (name.equals_ignoring_ascii_case("collection"sv))
return false;
return Gfx::font_format_is_supported(Gfx::FontFormat::TrueTypeCollection);
if (name.equals_ignoring_ascii_case("embedded-opentype"sv))
return false;
return Gfx::font_format_is_supported(Gfx::FontFormat::EmbeddedOpenType);
if (name.equals_ignoring_ascii_case("opentype"sv))
return true;
return Gfx::font_format_is_supported(Gfx::FontFormat::OpenType);
if (name.equals_ignoring_ascii_case("svg"sv))
return false;
return Gfx::font_format_is_supported(Gfx::FontFormat::SVG);
if (name.equals_ignoring_ascii_case("truetype"sv))
return true;
return Gfx::font_format_is_supported(Gfx::FontFormat::TrueType);
if (name.equals_ignoring_ascii_case("woff"sv))
return true;
return Gfx::font_format_is_supported(Gfx::FontFormat::WOFF);
if (name.equals_ignoring_ascii_case("woff2"sv))
return true;
return Gfx::font_format_is_supported(Gfx::FontFormat::WOFF2);
return false;
}
bool font_tech_is_supported(FontTech font_tech)
{
// https://drafts.csswg.org/css-fonts-4/#font-tech-definitions
// FIXME: Determine this automatically somehow?
switch (font_tech) {
case FontTech::FeaturesOpentype:
return true;
return Gfx::font_tech_is_supported(Gfx::FontTech::FeaturesOpentype);
case FontTech::FeaturesAat:
return false;
return Gfx::font_tech_is_supported(Gfx::FontTech::FeaturesAat);
case FontTech::FeaturesGraphite:
return false;
return Gfx::font_tech_is_supported(Gfx::FontTech::FeaturesGraphite);
case FontTech::Variations:
return true;
return Gfx::font_tech_is_supported(Gfx::FontTech::Variations);
case FontTech::ColorColrv0:
return true;
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorColrv0);
case FontTech::ColorColrv1:
return true;
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorColrv1);
case FontTech::ColorSvg:
return false;
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorSvg);
case FontTech::ColorSbix:
return false;
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorSbix);
case FontTech::ColorCbdt:
return false;
return Gfx::font_tech_is_supported(Gfx::FontTech::ColorCbdt);
case FontTech::Palettes:
return false;
return Gfx::font_tech_is_supported(Gfx::FontTech::Palettes);
case FontTech::Incremental:
return false;
return Gfx::font_tech_is_supported(Gfx::FontTech::Incremental);
// https://drafts.csswg.org/css-fonts-5/#font-tech-definitions
case FontTech::Avar2:
return false;
return Gfx::font_tech_is_supported(Gfx::FontTech::Avar2);
}
return false;
}