File indexing completed on 2025-02-02 04:11:04
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "embedded_font.hpp" 0008 0009 #include "model/document.hpp" 0010 #include "command/object_list_commands.hpp" 0011 #include "model/assets/assets.hpp" 0012 0013 GLAXNIMATE_OBJECT_IMPL(glaxnimate::model::EmbeddedFont) 0014 0015 0016 glaxnimate::model::EmbeddedFont::EmbeddedFont(model::Document* document) 0017 : Asset(document) 0018 { 0019 } 0020 0021 glaxnimate::model::EmbeddedFont::EmbeddedFont(model::Document* document, CustomFont custom_font) 0022 : Asset(document), custom_font_(std::move(custom_font)) 0023 { 0024 this->data.set(this->custom_font_.data()); 0025 this->source_url.set(this->custom_font_.source_url()); 0026 this->css_url.set(this->custom_font_.css_url()); 0027 } 0028 0029 0030 QIcon glaxnimate::model::EmbeddedFont::instance_icon() const 0031 { 0032 return QIcon::fromTheme("font"); 0033 } 0034 0035 QString glaxnimate::model::EmbeddedFont::object_name() const 0036 { 0037 return custom_font_.family() + " " + custom_font_.style_name(); 0038 } 0039 0040 QString glaxnimate::model::EmbeddedFont::type_name_human() const 0041 { 0042 return i18n("Font"); 0043 } 0044 0045 bool glaxnimate::model::EmbeddedFont::remove_if_unused(bool clean_lists) 0046 { 0047 /// \todo Needs a way to keep track users... 0048 if ( clean_lists && users().empty() ) 0049 { 0050 document()->push_command(new command::RemoveObject( 0051 this, 0052 &document()->assets()->fonts->values 0053 )); 0054 return true; 0055 } 0056 return false; 0057 } 0058 0059 void glaxnimate::model::EmbeddedFont::on_data_changed() 0060 { 0061 custom_font_ = CustomFontDatabase::instance().add_font("", data.get()); 0062 } 0063