mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 16:40:59 +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:
parent
a5fefbf840
commit
126a03f087
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -110,6 +110,10 @@ public:
|
|||
bool is_fixed_width() const { return m_fixed_width; }
|
||||
void set_fixed_width(bool b) { m_fixed_width = b; }
|
||||
|
||||
const Font& bold_family_font() const { return *m_bold_family_font; }
|
||||
bool has_boldface() const { return m_boldface; }
|
||||
void set_boldface(bool b) { m_boldface = b; }
|
||||
|
||||
u8 glyph_spacing() const { return m_glyph_spacing; }
|
||||
void set_glyph_spacing(u8 spacing) { m_glyph_spacing = spacing; }
|
||||
|
||||
|
@ -130,6 +134,9 @@ private:
|
|||
static RefPtr<Font> load_from_memory(const u8*);
|
||||
static size_t glyph_count_by_type(FontTypes type);
|
||||
|
||||
void set_family_fonts();
|
||||
RefPtr<Font> m_bold_family_font;
|
||||
|
||||
String m_name;
|
||||
FontTypes m_type;
|
||||
size_t m_glyph_count { 256 };
|
||||
|
@ -146,6 +153,7 @@ private:
|
|||
u8 m_glyph_spacing { 0 };
|
||||
|
||||
bool m_fixed_width { false };
|
||||
bool m_boldface { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue