2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-10-11 23:45:57 +02:00
|
|
|
#include "Font.h"
|
2020-02-06 12:07:05 +01:00
|
|
|
#include "Bitmap.h"
|
2020-03-08 12:05:14 +01:00
|
|
|
#include "Emoji.h"
|
2019-04-03 13:51:49 +02:00
|
|
|
#include <AK/MappedFile.h>
|
2019-06-07 11:46:55 +02:00
|
|
|
#include <AK/StdLibExtras.h>
|
2020-08-15 12:41:35 -04:00
|
|
|
#include <AK/StringBuilder.h>
|
2020-05-17 20:02:31 +02:00
|
|
|
#include <AK/Utf32View.h>
|
2020-02-06 11:56:38 +01:00
|
|
|
#include <AK/Utf8View.h>
|
2020-08-15 12:41:35 -04:00
|
|
|
#include <AK/Vector.h>
|
2019-06-07 11:46:55 +02:00
|
|
|
#include <AK/kmalloc.h>
|
2020-09-19 18:38:24 +02:00
|
|
|
#include <LibCore/FileStream.h>
|
2020-11-04 21:20:10 +01:00
|
|
|
#include <LibGfx/FontDatabase.h>
|
2020-01-30 17:57:43 -06:00
|
|
|
#include <stdio.h>
|
2020-03-08 12:05:14 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2020-02-06 11:56:38 +01:00
|
|
|
#include <sys/mman.h>
|
2020-01-30 17:57:43 -06:00
|
|
|
#include <unistd.h>
|
2020-02-06 11:56:38 +01:00
|
|
|
|
|
|
|
|
namespace Gfx {
|
2019-01-25 15:12:23 +01:00
|
|
|
|
2019-06-07 11:46:55 +02:00
|
|
|
struct [[gnu::packed]] FontFileHeader
|
|
|
|
|
{
|
2019-02-05 06:43:33 +01:00
|
|
|
char magic[4];
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 glyph_width;
|
|
|
|
|
u8 glyph_height;
|
|
|
|
|
u8 type;
|
|
|
|
|
u8 is_variable_width;
|
2019-12-30 11:36:55 +01:00
|
|
|
u8 glyph_spacing;
|
2020-09-19 18:01:32 +02:00
|
|
|
u8 baseline;
|
2020-10-05 16:19:37 +01:00
|
|
|
u8 mean_line;
|
2020-10-24 17:03:39 +02:00
|
|
|
u8 presentation_size;
|
|
|
|
|
u16 weight;
|
|
|
|
|
char name[32];
|
|
|
|
|
char family[32];
|
2019-02-15 12:30:48 +01:00
|
|
|
};
|
2019-02-05 06:43:33 +01:00
|
|
|
|
2019-01-16 17:54:06 +01:00
|
|
|
Font& Font::default_font()
|
2018-10-11 23:45:57 +02:00
|
|
|
{
|
2020-11-04 21:20:10 +01:00
|
|
|
static Font* font;
|
|
|
|
|
if (!font) {
|
|
|
|
|
font = FontDatabase::the().get_by_name("Katica 10 400");
|
|
|
|
|
ASSERT(font);
|
2019-02-02 23:13:12 +01:00
|
|
|
}
|
2020-11-04 21:20:10 +01:00
|
|
|
return *font;
|
2019-02-04 11:37:15 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-06 14:06:40 +01:00
|
|
|
Font& Font::default_fixed_width_font()
|
|
|
|
|
{
|
2020-11-04 21:20:10 +01:00
|
|
|
static Font* font;
|
|
|
|
|
if (!font) {
|
|
|
|
|
font = FontDatabase::the().get_by_name("Csilla 10 400");
|
|
|
|
|
ASSERT(font);
|
2019-03-06 14:06:40 +01:00
|
|
|
}
|
2020-11-04 21:20:10 +01:00
|
|
|
return *font;
|
2019-03-06 14:06:40 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-04 08:14:53 +02:00
|
|
|
Font& Font::default_bold_fixed_width_font()
|
|
|
|
|
{
|
|
|
|
|
static Font* font;
|
|
|
|
|
if (!font) {
|
2020-11-04 21:20:10 +01:00
|
|
|
font = FontDatabase::the().get_by_name("Csilla 10 700");
|
2019-08-04 08:14:53 +02:00
|
|
|
ASSERT(font);
|
|
|
|
|
}
|
|
|
|
|
return *font;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 11:37:15 +01:00
|
|
|
Font& Font::default_bold_font()
|
|
|
|
|
{
|
2020-11-04 21:20:10 +01:00
|
|
|
static Font* font;
|
|
|
|
|
if (!font) {
|
|
|
|
|
font = FontDatabase::the().get_by_name("Katica 10 700");
|
|
|
|
|
ASSERT(font);
|
2019-02-04 11:37:15 +01:00
|
|
|
}
|
2020-11-04 21:20:10 +01:00
|
|
|
return *font;
|
2018-10-11 23:45:57 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-22 21:59:05 +01:00
|
|
|
NonnullRefPtr<Font> Font::clone() const
|
2019-02-02 08:05:14 +01:00
|
|
|
{
|
2019-07-03 21:17:35 +02:00
|
|
|
size_t bytes_per_glyph = sizeof(u32) * glyph_height();
|
2019-02-02 08:05:14 +01:00
|
|
|
// FIXME: This is leaked!
|
2020-05-20 22:48:22 +03:00
|
|
|
auto* new_rows = static_cast<unsigned*>(kmalloc(bytes_per_glyph * m_glyph_count));
|
|
|
|
|
memcpy(new_rows, m_rows, bytes_per_glyph * m_glyph_count);
|
|
|
|
|
auto* new_widths = static_cast<u8*>(kmalloc(m_glyph_count));
|
2019-03-06 12:52:41 +01:00
|
|
|
if (m_glyph_widths)
|
2020-05-20 22:48:22 +03:00
|
|
|
memcpy(new_widths, m_glyph_widths, m_glyph_count);
|
2019-03-06 12:52:41 +01:00
|
|
|
else
|
2020-05-20 22:48:22 +03:00
|
|
|
memset(new_widths, m_glyph_width, m_glyph_count);
|
2020-10-24 17:03:39 +02:00
|
|
|
return adopt(*new Font(m_name, m_family, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height, m_glyph_spacing, m_type, m_baseline, m_mean_line, m_presentation_size, m_weight));
|
2020-02-22 21:59:05 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-20 22:48:22 +03:00
|
|
|
NonnullRefPtr<Font> Font::create(u8 glyph_height, u8 glyph_width, bool fixed, FontTypes type)
|
2020-02-22 21:59:05 +01:00
|
|
|
{
|
|
|
|
|
size_t bytes_per_glyph = sizeof(u32) * glyph_height;
|
|
|
|
|
// FIXME: This is leaked!
|
2020-05-20 22:48:22 +03:00
|
|
|
size_t count = glyph_count_by_type(type);
|
|
|
|
|
auto* new_rows = static_cast<unsigned*>(malloc(bytes_per_glyph * count));
|
|
|
|
|
memset(new_rows, 0, bytes_per_glyph * count);
|
|
|
|
|
auto* new_widths = static_cast<u8*>(malloc(count));
|
|
|
|
|
memset(new_widths, glyph_width, count);
|
2020-10-24 17:03:39 +02:00
|
|
|
return adopt(*new Font("Untitled", "Untitled", new_rows, new_widths, fixed, glyph_width, glyph_height, 1, type, 0, 0, 0, 400));
|
2019-02-02 08:05:14 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-24 17:03:39 +02:00
|
|
|
Font::Font(String name, String family, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, FontTypes type, u8 baseline, u8 mean_line, u8 presentation_size, u16 weight)
|
2019-02-02 23:13:12 +01:00
|
|
|
: m_name(name)
|
2020-10-24 17:03:39 +02:00
|
|
|
, m_family(family)
|
2020-05-20 22:48:22 +03:00
|
|
|
, m_type(type)
|
2019-02-05 06:43:33 +01:00
|
|
|
, m_rows(rows)
|
2019-03-06 12:52:41 +01:00
|
|
|
, m_glyph_widths(widths)
|
2019-01-16 17:54:06 +01:00
|
|
|
, m_glyph_width(glyph_width)
|
|
|
|
|
, m_glyph_height(glyph_height)
|
2019-03-06 11:03:10 +01:00
|
|
|
, m_min_glyph_width(glyph_width)
|
|
|
|
|
, m_max_glyph_width(glyph_width)
|
2019-12-30 11:36:55 +01:00
|
|
|
, m_glyph_spacing(glyph_spacing)
|
2020-09-19 18:01:32 +02:00
|
|
|
, m_baseline(baseline)
|
2020-10-05 16:19:37 +01:00
|
|
|
, m_mean_line(mean_line)
|
2020-10-24 17:03:39 +02:00
|
|
|
, m_presentation_size(presentation_size)
|
|
|
|
|
, m_weight(weight)
|
2019-03-06 12:52:41 +01:00
|
|
|
, m_fixed_width(is_fixed_width)
|
2018-10-11 23:45:57 +02:00
|
|
|
{
|
2020-10-05 16:19:37 +01:00
|
|
|
update_x_height();
|
2020-08-07 20:29:32 +02:00
|
|
|
|
2020-05-20 22:48:22 +03:00
|
|
|
m_glyph_count = glyph_count_by_type(m_type);
|
|
|
|
|
|
2019-03-06 11:03:10 +01:00
|
|
|
if (!m_fixed_width) {
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 maximum = 0;
|
|
|
|
|
u8 minimum = 255;
|
2020-05-20 22:48:22 +03:00
|
|
|
for (size_t i = 0; i < m_glyph_count; ++i) {
|
2019-03-06 11:03:10 +01:00
|
|
|
minimum = min(minimum, m_glyph_widths[i]);
|
2019-03-06 12:52:41 +01:00
|
|
|
maximum = max(maximum, m_glyph_widths[i]);
|
|
|
|
|
}
|
2019-03-06 11:03:10 +01:00
|
|
|
m_min_glyph_width = minimum;
|
2019-03-06 12:52:41 +01:00
|
|
|
m_max_glyph_width = maximum;
|
2019-03-06 11:03:10 +01:00
|
|
|
}
|
2020-08-15 12:41:35 -04:00
|
|
|
|
|
|
|
|
set_family_fonts();
|
2018-10-11 23:45:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Font::~Font()
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-02-02 23:13:12 +01:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
RefPtr<Font> Font::load_from_memory(const u8* data)
|
2019-02-02 23:13:12 +01:00
|
|
|
{
|
2019-02-03 01:36:25 +01:00
|
|
|
auto& header = *reinterpret_cast<const FontFileHeader*>(data);
|
2019-02-02 23:13:12 +01:00
|
|
|
if (memcmp(header.magic, "!Fnt", 4)) {
|
2019-02-03 01:36:25 +01:00
|
|
|
dbgprintf("header.magic != '!Fnt', instead it's '%c%c%c%c'\n", header.magic[0], header.magic[1], header.magic[2], header.magic[3]);
|
2019-02-02 23:13:12 +01:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2020-10-24 17:03:39 +02:00
|
|
|
if (header.name[sizeof(header.name) - 1] != '\0') {
|
2019-02-02 23:13:12 +01:00
|
|
|
dbgprintf("Font name not fully null-terminated\n");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 17:03:39 +02:00
|
|
|
if (header.family[sizeof(header.family) - 1] != '\0') {
|
|
|
|
|
dbgprintf("Font family not fully null-terminated\n");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 22:48:22 +03:00
|
|
|
FontTypes type;
|
|
|
|
|
if (header.type == 0)
|
|
|
|
|
type = FontTypes::Default;
|
|
|
|
|
else if (header.type == 1)
|
|
|
|
|
type = FontTypes::LatinExtendedA;
|
|
|
|
|
else
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
|
|
|
|
|
size_t count = glyph_count_by_type(type);
|
2019-03-06 12:52:41 +01:00
|
|
|
size_t bytes_per_glyph = sizeof(unsigned) * header.glyph_height;
|
|
|
|
|
|
2019-06-22 14:41:11 +02:00
|
|
|
auto* rows = const_cast<unsigned*>((const unsigned*)(data + sizeof(FontFileHeader)));
|
2019-07-03 21:17:35 +02:00
|
|
|
u8* widths = nullptr;
|
2019-03-06 12:52:41 +01:00
|
|
|
if (header.is_variable_width)
|
2020-05-20 22:48:22 +03:00
|
|
|
widths = (u8*)(rows) + count * bytes_per_glyph;
|
2020-10-24 17:03:39 +02:00
|
|
|
return adopt(*new Font(String(header.name), String(header.family), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height, header.glyph_spacing, type, header.baseline, header.mean_line, header.presentation_size, header.weight));
|
2020-05-20 22:48:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t Font::glyph_count_by_type(FontTypes type)
|
|
|
|
|
{
|
|
|
|
|
if (type == FontTypes::Default)
|
|
|
|
|
return 256;
|
|
|
|
|
|
|
|
|
|
if (type == FontTypes::LatinExtendedA)
|
|
|
|
|
return 384;
|
|
|
|
|
|
|
|
|
|
dbg() << "Unknown font type:" << type;
|
|
|
|
|
ASSERT_NOT_REACHED();
|
2019-02-02 23:13:12 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<Font> Font::load_from_file(const StringView& path)
|
2019-02-03 01:36:25 +01:00
|
|
|
{
|
2019-04-03 13:51:49 +02:00
|
|
|
MappedFile mapped_file(path);
|
|
|
|
|
if (!mapped_file.is_valid())
|
2019-02-03 01:36:25 +01:00
|
|
|
return nullptr;
|
2019-02-03 08:17:35 +01:00
|
|
|
|
2019-09-30 08:57:01 +02:00
|
|
|
auto font = load_from_memory((const u8*)mapped_file.data());
|
2020-03-11 18:18:03 +01:00
|
|
|
if (!font)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2019-04-03 13:51:49 +02:00
|
|
|
font->m_mapped_file = move(mapped_file);
|
2019-02-03 01:36:25 +01:00
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-02 14:58:02 +02:00
|
|
|
bool Font::write_to_file(const StringView& path)
|
2019-02-02 23:13:12 +01:00
|
|
|
{
|
|
|
|
|
FontFileHeader header;
|
|
|
|
|
memset(&header, 0, sizeof(FontFileHeader));
|
|
|
|
|
memcpy(header.magic, "!Fnt", 4);
|
|
|
|
|
header.glyph_width = m_glyph_width;
|
|
|
|
|
header.glyph_height = m_glyph_height;
|
2020-05-20 22:48:22 +03:00
|
|
|
header.type = m_type;
|
2020-09-19 18:01:32 +02:00
|
|
|
header.baseline = m_baseline;
|
2020-10-05 16:19:37 +01:00
|
|
|
header.mean_line = m_mean_line;
|
2019-03-06 12:52:41 +01:00
|
|
|
header.is_variable_width = !m_fixed_width;
|
2019-12-30 11:36:55 +01:00
|
|
|
header.glyph_spacing = m_glyph_spacing;
|
2020-10-24 17:03:39 +02:00
|
|
|
header.presentation_size = m_presentation_size;
|
|
|
|
|
header.weight = m_weight;
|
|
|
|
|
memcpy(header.name, m_name.characters(), min(m_name.length(), sizeof(header.name) - 1));
|
|
|
|
|
memcpy(header.family, m_family.characters(), min(m_family.length(), sizeof(header.family) - 1));
|
2019-02-02 23:13:12 +01:00
|
|
|
|
|
|
|
|
size_t bytes_per_glyph = sizeof(unsigned) * m_glyph_height;
|
2020-05-20 22:48:22 +03:00
|
|
|
size_t count = glyph_count_by_type(m_type);
|
2019-02-02 23:13:12 +01:00
|
|
|
|
2020-09-19 18:38:24 +02:00
|
|
|
auto stream_result = Core::OutputFileStream::open_buffered(path);
|
|
|
|
|
if (stream_result.is_error())
|
|
|
|
|
return false;
|
|
|
|
|
auto& stream = stream_result.value();
|
|
|
|
|
|
|
|
|
|
stream << ReadonlyBytes { &header, sizeof(header) };
|
|
|
|
|
stream << ReadonlyBytes { m_rows, count * bytes_per_glyph };
|
|
|
|
|
stream << ReadonlyBytes { m_glyph_widths, count };
|
2019-02-02 23:13:12 +01:00
|
|
|
|
2020-09-19 18:38:24 +02:00
|
|
|
stream.flush();
|
|
|
|
|
if (stream.handle_any_error())
|
|
|
|
|
return false;
|
2019-02-02 23:13:12 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-03-06 11:03:10 +01:00
|
|
|
|
2020-08-05 16:31:20 -04:00
|
|
|
GlyphBitmap Font::glyph_bitmap(u32 code_point) const
|
2020-05-20 22:48:22 +03:00
|
|
|
{
|
2020-08-05 16:31:20 -04:00
|
|
|
return GlyphBitmap(&m_rows[code_point * m_glyph_height], { glyph_width(code_point), m_glyph_height });
|
2020-05-20 22:48:22 +03:00
|
|
|
}
|
|
|
|
|
|
2020-08-05 16:31:20 -04:00
|
|
|
int Font::glyph_or_emoji_width(u32 code_point) const
|
2019-03-06 11:03:10 +01:00
|
|
|
{
|
2020-08-05 16:31:20 -04:00
|
|
|
if (code_point < m_glyph_count)
|
|
|
|
|
return glyph_width(code_point);
|
2019-03-25 13:35:24 +01:00
|
|
|
|
2019-03-06 11:03:10 +01:00
|
|
|
if (m_fixed_width)
|
2019-09-04 23:45:55 +03:00
|
|
|
return m_glyph_width;
|
|
|
|
|
|
2020-08-05 16:31:20 -04:00
|
|
|
auto* emoji = Emoji::emoji_for_code_point(code_point);
|
2019-09-04 23:45:55 +03:00
|
|
|
if (emoji == nullptr)
|
|
|
|
|
return glyph_width('?');
|
2019-10-19 18:36:45 +02:00
|
|
|
return emoji->size().width();
|
2019-09-04 23:45:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Font::width(const StringView& string) const
|
|
|
|
|
{
|
|
|
|
|
Utf8View utf8 { string };
|
|
|
|
|
return width(utf8);
|
|
|
|
|
}
|
2019-03-06 11:03:10 +01:00
|
|
|
|
2019-09-04 23:45:55 +03:00
|
|
|
int Font::width(const Utf8View& utf8) const
|
|
|
|
|
{
|
|
|
|
|
bool first = true;
|
2019-03-06 11:03:10 +01:00
|
|
|
int width = 0;
|
2019-03-25 13:35:24 +01:00
|
|
|
|
2020-08-05 16:31:20 -04:00
|
|
|
for (u32 code_point : utf8) {
|
2019-09-04 23:45:55 +03:00
|
|
|
if (!first)
|
|
|
|
|
width += glyph_spacing();
|
|
|
|
|
first = false;
|
2020-08-05 16:31:20 -04:00
|
|
|
width += glyph_or_emoji_width(code_point);
|
2019-09-04 23:45:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return width;
|
2019-03-06 11:03:10 +01:00
|
|
|
}
|
2020-02-06 11:56:38 +01:00
|
|
|
|
2020-05-17 20:02:31 +02:00
|
|
|
int Font::width(const Utf32View& view) const
|
2020-05-17 17:45:12 +02:00
|
|
|
{
|
2020-05-17 20:02:31 +02:00
|
|
|
if (view.length() == 0)
|
2020-05-17 17:45:12 +02:00
|
|
|
return 0;
|
2020-05-17 20:02:31 +02:00
|
|
|
int width = (view.length() - 1) * glyph_spacing();
|
|
|
|
|
for (size_t i = 0; i < view.length(); ++i)
|
2020-08-05 16:31:20 -04:00
|
|
|
width += glyph_or_emoji_width(view.code_points()[i]);
|
2020-05-17 17:45:12 +02:00
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 22:48:22 +03:00
|
|
|
void Font::set_type(FontTypes type)
|
|
|
|
|
{
|
|
|
|
|
if (type == m_type)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (type == FontTypes::Default)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
size_t new_glyph_count = glyph_count_by_type(type);
|
|
|
|
|
if (new_glyph_count <= m_glyph_count) {
|
|
|
|
|
m_glyph_count = new_glyph_count;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int item_count_to_copy = min(m_glyph_count, new_glyph_count);
|
|
|
|
|
|
|
|
|
|
size_t bytes_per_glyph = sizeof(u32) * glyph_height();
|
|
|
|
|
|
|
|
|
|
auto* new_rows = static_cast<unsigned*>(kmalloc(bytes_per_glyph * new_glyph_count));
|
|
|
|
|
memset(new_rows, (unsigned)0, bytes_per_glyph * new_glyph_count);
|
|
|
|
|
memcpy(new_rows, m_rows, bytes_per_glyph * item_count_to_copy);
|
|
|
|
|
|
|
|
|
|
auto* new_widths = static_cast<u8*>(kmalloc(new_glyph_count));
|
|
|
|
|
memset(new_widths, (u8)0, new_glyph_count);
|
|
|
|
|
memcpy(new_widths, m_glyph_widths, item_count_to_copy);
|
|
|
|
|
|
|
|
|
|
kfree(m_rows);
|
|
|
|
|
kfree(m_glyph_widths);
|
|
|
|
|
|
|
|
|
|
m_type = type;
|
|
|
|
|
m_glyph_count = new_glyph_count;
|
|
|
|
|
m_rows = new_rows;
|
|
|
|
|
m_glyph_widths = new_widths;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 12:41:35 -04:00
|
|
|
void Font::set_family_fonts()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder path;
|
|
|
|
|
|
2020-10-24 17:03:39 +02:00
|
|
|
if (weight() != 700) {
|
|
|
|
|
path.appendff("/res/fonts/{}Bold{}.font", family(), presentation_size());
|
|
|
|
|
auto spath = path.to_string();
|
2020-08-15 12:41:35 -04:00
|
|
|
m_bold_family_font = Font::load_from_file(path.to_string());
|
|
|
|
|
if (m_bold_family_font)
|
|
|
|
|
set_boldface(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 19:28:06 +01:00
|
|
|
String Font::qualified_name() const
|
|
|
|
|
{
|
|
|
|
|
return String::formatted("{} {} {}", family(), presentation_size(), weight());
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
}
|