LibGfx: Remove static load_from_file() from abstract Font class

This commit is contained in:
Stephan Unverwerth 2021-01-03 17:36:04 +01:00 committed by Andreas Kling
parent 79dfe9846d
commit b8c25bc7ff
Notes: sideshowbarker 2024-07-18 22:17:44 +09:00
6 changed files with 4 additions and 47 deletions

View File

@ -79,7 +79,7 @@ int main(int argc, char** argv)
path = "/tmp/saved.font";
edited_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::FontDatabase::default_font().clone());
} else {
edited_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::Font::load_from_file(path)->clone());
edited_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::BitmapFont::load_from_file(path)->clone());
if (!edited_font) {
String message = String::formatted("Couldn't load font: {}\n", path);
GUI::MessageBox::show(nullptr, message, "Font Editor", GUI::MessageBox::Type::Error);
@ -111,7 +111,7 @@ int main(int argc, char** argv)
if (!open_path.has_value())
return;
RefPtr<Gfx::BitmapFont> new_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::Font::load_from_file(open_path.value())->clone());
RefPtr<Gfx::BitmapFont> new_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::BitmapFont::load_from_file(open_path.value())->clone());
if (!new_font) {
String message = String::formatted("Couldn't load font: {}\n", open_path.value());
GUI::MessageBox::show(window, message, "Font Editor", GUI::MessageBox::Type::Error);

View File

@ -167,7 +167,7 @@ void Canvas::draw()
painter.draw_text({ 520, 450, 240, 20 }, "Normal text (fixed width)", Gfx::FontDatabase::default_fixed_width_font(), Gfx::TextAlignment::CenterLeft, Color::Blue);
painter.draw_text({ 520, 465, 240, 20 }, "Bold text (fixed width)", Gfx::FontDatabase::default_bold_fixed_width_font(), Gfx::TextAlignment::CenterLeft, Color::Yellow);
auto font = Gfx::Font::load_from_file("/res/fonts/PebbletonBold14.font");
auto font = Gfx::BitmapFont::load_from_file("/res/fonts/PebbletonBold14.font");
painter.draw_rect({ 520, 510, 240, 30 }, Color::DarkGray);
painter.draw_text({ 520, 510, 240, 30 }, "Hello friends! :^)", *font, Gfx::TextAlignment::Center, Color::White);

View File

@ -10,7 +10,6 @@ set(SOURCES
Color.cpp
DisjointRectSet.cpp
Emoji.cpp
Font.cpp
FontDatabase.cpp
GIFLoader.cpp
ICOLoader.cpp

View File

@ -1,40 +0,0 @@
/*
* Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de>
* 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.
*/
#include <LibGfx/BitmapFont.h>
#include <LibGfx/Font.h>
namespace Gfx {
RefPtr<Font> Font::load_from_file(const StringView& path)
{
if (path.ends_with(".font")) {
return BitmapFont::load_from_file(path);
}
return {};
}
}

View File

@ -103,8 +103,6 @@ private:
class Font : public RefCounted<Font> {
public:
static RefPtr<Font> load_from_file(const StringView& path);
virtual NonnullRefPtr<Font> clone() const = 0;
virtual ~Font() {};

View File

@ -104,7 +104,7 @@ FontDatabase::FontDatabase()
auto path = String::format("/res/fonts/%s", name.characters());
if (name.ends_with(".font")) {
if (auto font = Gfx::Font::load_from_file(path)) {
if (auto font = Gfx::BitmapFont::load_from_file(path)) {
m_private->full_name_to_font_map.set(font->qualified_name(), font);
auto typeface = get_or_create_typeface(font->family(), font->variant());
typeface->add_bitmap_font(font);