From 4690ba0cc66338b1f00e08fb6054ee95c1c0dcc6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 23 Sep 2020 23:45:21 +0200 Subject: Fallback to cjk font, change font to system noto sans --- include/Body.hpp | 12 ++++++++++-- include/QuickMedia.hpp | 5 +++-- include/Text.hpp | 18 ++++++++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/Body.hpp b/include/Body.hpp index e4c21fc..235de72 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -36,17 +36,23 @@ namespace QuickMedia { dirty_description = true; } + void set_author(std::string str) { + author = std::move(str); + dirty_author = true; + } + const std::string& get_title() const { return title; } const std::string& get_description() const { return description; } + const std::string& get_author() const { return author; } // TODO: Use a list of strings instead, not all plugins need all of these fields std::string url; std::string thumbnail_url; std::string attached_content_url; // TODO: Remove and use |url| instead - std::string author; bool visible; bool dirty; bool dirty_description; + bool dirty_author; bool thumbnail_is_local; std::unique_ptr title_text; std::unique_ptr description_text; @@ -57,13 +63,14 @@ namespace QuickMedia { private: std::string title; std::string description; + std::string author; }; using BodyItems = std::vector>; class Body { public: - Body(Program *program, sf::Font *font, sf::Font *bold_font); + Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font); // Select previous item, ignoring invisible items. Returns true if the item was changed. This can be used to check if the top was hit when wrap_around is set to false bool select_previous_item(); @@ -97,6 +104,7 @@ namespace QuickMedia { sf::Font *font; sf::Font *bold_font; + sf::Font *cjk_font; sf::Text progress_text; sf::Text author_text; sf::Text replies_text; diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 18f3a6b..03bfcb9 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -82,8 +82,9 @@ namespace QuickMedia { sf::RenderWindow window; int monitor_hz; sf::Vector2f window_size; - sf::Font font; - sf::Font bold_font; + std::unique_ptr font; + std::unique_ptr bold_font; + std::unique_ptr cjk_font; Body *body; Plugin *current_plugin; sf::Texture plugin_logo; diff --git a/include/Text.hpp b/include/Text.hpp index 8b6c0b9..d70f356 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -35,21 +35,22 @@ namespace QuickMedia }; TextElement() {} - TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type), ownLine(false) {} + TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type), is_japanese(false) {} StringViewUtf32 text; sf::Vector2f position; Type type; - bool ownLine; // Currently only used for emoji, to make emoji bigger when it's the only thing on a line + //bool ownLine; // Currently only used for emoji, to make emoji bigger when it's the only thing on a line + bool is_japanese; }; class Text { public: - Text(const sf::Font *font); - Text(const sf::String &str, const sf::Font *font, unsigned int characterSize, float maxWidth, bool plainText = true); + Text(const sf::Font *font, const sf::Font *cjk_font); + Text(sf::String str, const sf::Font *font, const sf::Font *cjk_font, unsigned int characterSize, float maxWidth, bool plainText = true); - void setString(const sf::String &str); + void setString(sf::String str); const sf::String& getString() const; void setPosition(float x, float y); @@ -89,6 +90,7 @@ namespace QuickMedia END }; +#if 0 void updateCaret(); bool isCaretAtEnd() const; int getStartOfLine(int startIndex) const; @@ -97,11 +99,15 @@ namespace QuickMedia int getPreviousLineClosestPosition(int startIndex) const; int getNextLineClosestPosition(int startIndex) const; +#endif + + void splitTextByFont(); private: sf::String str; const sf::Font *font; + const sf::Font *cjk_font; unsigned int characterSize; - sf::VertexArray vertices; + sf::VertexArray vertices[2]; float maxWidth; sf::Vector2f position; sf::Color color; -- cgit v1.2.3