mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:47:45 +00:00
LibWeb+WebContent: Add abstraction layer for generic font families
Instead of hard-coding the names of system fonts to use for the CSS generic fonts (like "sans-serif", "monospace", etc.) we now call out to a Platform::FontPlugin and ask for the generic names.
This commit is contained in:
parent
26544f559c
commit
5c2e3d1637
8 changed files with 153 additions and 8 deletions
44
Userland/Services/WebContent/FontPluginSerenity.cpp
Normal file
44
Userland/Services/WebContent/FontPluginSerenity.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "FontPluginSerenity.h"
|
||||
#include <AK/String.h>
|
||||
#include <LibGfx/Font/FontDatabase.h>
|
||||
|
||||
namespace WebContent {
|
||||
|
||||
FontPluginSerenity::FontPluginSerenity()
|
||||
{
|
||||
}
|
||||
|
||||
FontPluginSerenity::~FontPluginSerenity() = default;
|
||||
|
||||
String FontPluginSerenity::generic_font_name(Web::Platform::GenericFont generic_font)
|
||||
{
|
||||
// FIXME: Replace hard-coded font names with a relevant call to FontDatabase.
|
||||
// Currently, we cannot request the default font's name, or request it at a specific size and weight.
|
||||
// So, hard-coded font names it is.
|
||||
switch (generic_font) {
|
||||
case Web::Platform::GenericFont::SansSerif:
|
||||
case Web::Platform::GenericFont::UiSansSerif:
|
||||
case Web::Platform::GenericFont::Cursive:
|
||||
case Web::Platform::GenericFont::UiRounded:
|
||||
return "Katica";
|
||||
case Web::Platform::GenericFont::Monospace:
|
||||
case Web::Platform::GenericFont::UiMonospace:
|
||||
return "Csilla";
|
||||
case Web::Platform::GenericFont::Serif:
|
||||
case Web::Platform::GenericFont::UiSerif:
|
||||
return "Roman";
|
||||
case Web::Platform::GenericFont::Fantasy:
|
||||
return "Comic Book";
|
||||
case Web::Platform::GenericFont::__Count:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue