File indexing completed on 2025-02-02 04:11:27
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QByteArray> 0010 #include "model/custom_font.hpp" 0011 #include "model/document.hpp" 0012 0013 namespace glaxnimate::gui::font { 0014 0015 class FontLoader : public QObject 0016 { 0017 Q_OBJECT 0018 0019 public: 0020 FontLoader(); 0021 ~FontLoader(); 0022 0023 /** 0024 * \brief Vector of loaded fonts 0025 */ 0026 const std::vector<model::CustomFont>& fonts() const; 0027 0028 /** 0029 * \brief Queue \p url for download 0030 * \param name_alias Name of the font family (if any) 0031 * \param url Should point to a css, ttf, or otf file 0032 * \param id Custom identifier to recognize when loading has finished 0033 */ 0034 void queue(const QString& name_alias, const QUrl& url, int id = -1); 0035 0036 /** 0037 * \brief Load fonts from the queue 0038 */ 0039 void load_queue(); 0040 0041 /** 0042 * \brief Total number of queued fonts 0043 */ 0044 int queued_total() const; 0045 0046 /** 0047 * \brief Clears all data 0048 */ 0049 void clear(); 0050 0051 /** 0052 * \brief Load from data 0053 * \param name_alias Name of the font family (if any) 0054 * \param data Should be css, ttf, or otf 0055 * \param id Custom identifier to recognize when loading has finished 0056 */ 0057 void queue_data(const QString& name_alias, const QByteArray& data, int id = -1); 0058 0059 /** 0060 * \brief Cancels all loads and clears all data 0061 */ 0062 void cancel(); 0063 0064 /** 0065 * \brief Whether loading is in progress 0066 */ 0067 bool loading() const; 0068 0069 /** 0070 * \brief Queues all pending assets from the document 0071 */ 0072 void queue_pending(model::Document* document, bool reload_loaded = false); 0073 0074 Q_SIGNALS: 0075 /** 0076 * \brief All queued loads have been completed 0077 */ 0078 void finished(); 0079 0080 /** 0081 * \brief Emitted when a font has been loaded 0082 * \param count number of URLs loaded so far 0083 */ 0084 void fonts_loaded(int count); 0085 0086 /** 0087 * \brief Emitted when something is queued 0088 */ 0089 void fonts_queued(int total); 0090 0091 /** 0092 * \brief Error message 0093 */ 0094 void error(const QString& message, int id); 0095 0096 /** 0097 * \brief Success for resource with the given ID 0098 */ 0099 void success(int id); 0100 0101 private: 0102 class Private; 0103 std::unique_ptr<Private> d; 0104 }; 0105 0106 } // namespace glaxnimate::model