mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibGfx: Remove static load_from_file() from abstract Font class
This commit is contained in:
parent
79dfe9846d
commit
b8c25bc7ff
6 changed files with 4 additions and 47 deletions
|
@ -79,7 +79,7 @@ int main(int argc, char** argv)
|
||||||
path = "/tmp/saved.font";
|
path = "/tmp/saved.font";
|
||||||
edited_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::FontDatabase::default_font().clone());
|
edited_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::FontDatabase::default_font().clone());
|
||||||
} else {
|
} 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) {
|
if (!edited_font) {
|
||||||
String message = String::formatted("Couldn't load font: {}\n", path);
|
String message = String::formatted("Couldn't load font: {}\n", path);
|
||||||
GUI::MessageBox::show(nullptr, message, "Font Editor", GUI::MessageBox::Type::Error);
|
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())
|
if (!open_path.has_value())
|
||||||
return;
|
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) {
|
if (!new_font) {
|
||||||
String message = String::formatted("Couldn't load font: {}\n", open_path.value());
|
String message = String::formatted("Couldn't load font: {}\n", open_path.value());
|
||||||
GUI::MessageBox::show(window, message, "Font Editor", GUI::MessageBox::Type::Error);
|
GUI::MessageBox::show(window, message, "Font Editor", GUI::MessageBox::Type::Error);
|
||||||
|
|
|
@ -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, 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);
|
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_rect({ 520, 510, 240, 30 }, Color::DarkGray);
|
||||||
painter.draw_text({ 520, 510, 240, 30 }, "Hello friends! :^)", *font, Gfx::TextAlignment::Center, Color::White);
|
painter.draw_text({ 520, 510, 240, 30 }, "Hello friends! :^)", *font, Gfx::TextAlignment::Center, Color::White);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ set(SOURCES
|
||||||
Color.cpp
|
Color.cpp
|
||||||
DisjointRectSet.cpp
|
DisjointRectSet.cpp
|
||||||
Emoji.cpp
|
Emoji.cpp
|
||||||
Font.cpp
|
|
||||||
FontDatabase.cpp
|
FontDatabase.cpp
|
||||||
GIFLoader.cpp
|
GIFLoader.cpp
|
||||||
ICOLoader.cpp
|
ICOLoader.cpp
|
||||||
|
|
|
@ -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 {};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -103,8 +103,6 @@ private:
|
||||||
|
|
||||||
class Font : public RefCounted<Font> {
|
class Font : public RefCounted<Font> {
|
||||||
public:
|
public:
|
||||||
static RefPtr<Font> load_from_file(const StringView& path);
|
|
||||||
|
|
||||||
virtual NonnullRefPtr<Font> clone() const = 0;
|
virtual NonnullRefPtr<Font> clone() const = 0;
|
||||||
virtual ~Font() {};
|
virtual ~Font() {};
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ FontDatabase::FontDatabase()
|
||||||
|
|
||||||
auto path = String::format("/res/fonts/%s", name.characters());
|
auto path = String::format("/res/fonts/%s", name.characters());
|
||||||
if (name.ends_with(".font")) {
|
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);
|
m_private->full_name_to_font_map.set(font->qualified_name(), font);
|
||||||
auto typeface = get_or_create_typeface(font->family(), font->variant());
|
auto typeface = get_or_create_typeface(font->family(), font->variant());
|
||||||
typeface->add_bitmap_font(font);
|
typeface->add_bitmap_font(font);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue