1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibGfx: Add initial font family matching

Fonts following the TypefaceWeightSize naming scheme now associate
with bold weights of the same name and glyph size on construction.
This commit is contained in:
thankyouverycool 2020-08-15 12:41:35 -04:00 committed by Andreas Kling
parent a5fefbf840
commit 126a03f087
2 changed files with 43 additions and 0 deletions

View file

@ -30,8 +30,10 @@
#include <AK/BufferStream.h>
#include <AK/MappedFile.h>
#include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h>
#include <AK/Utf32View.h>
#include <AK/Utf8View.h>
#include <AK/Vector.h>
#include <AK/kmalloc.h>
#include <errno.h>
#include <fcntl.h>
@ -152,6 +154,8 @@ Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_wid
m_min_glyph_width = minimum;
m_max_glyph_width = maximum;
}
set_family_fonts();
}
Font::~Font()
@ -343,4 +347,35 @@ void Font::set_type(FontTypes type)
m_glyph_widths = new_widths;
}
void Font::set_family_fonts()
{
String typeface;
String weight;
StringBuilder size;
auto parts = this->name().split(' ');
if (parts.size() < 2) {
typeface = this->name();
} else {
typeface = parts[0];
weight = parts[1];
}
if (this->is_fixed_width()) {
size.appendf("%d", this->m_max_glyph_width);
size.append("x");
}
size.appendf("%d", this->m_glyph_height);
StringBuilder path;
if (weight != "Bold") {
path.appendf("/res/fonts/%sBold%s.font", &typeface[0], &size.to_string()[0]);
m_bold_family_font = Font::load_from_file(path.to_string());
if (m_bold_family_font)
set_boldface(true);
path.clear();
}
}
}