diff --git a/src/loaders/ttf/tvgTtfLoader.cpp b/src/loaders/ttf/tvgTtfLoader.cpp index c389bdc7..e27a304b 100644 --- a/src/loaders/ttf/tvgTtfLoader.cpp +++ b/src/loaders/ttf/tvgTtfLoader.cpp @@ -209,12 +209,12 @@ void TtfLoader::clear() /************************************************************************/ -bool TtfLoader::resize(Paint* paint, float sx, TVG_UNUSED float sy) +bool TtfLoader::transform(Paint* paint, float fontSize, bool italic) { if (!paint) return false; auto shift = 0.0f; auto dpi = 96.0f / 72.0f; //dpi base? - scale = sx * dpi / reader.metrics.unitsPerEm; + scale = fontSize * dpi / reader.metrics.unitsPerEm; if (italic) shift = -scale * 0.18f; //experimental decision. Matrix m = {scale, shift, -(shift * reader.metrics.minw), 0, scale, 0, 0, 0, 1}; paint->transform(m); @@ -258,11 +258,10 @@ bool TtfLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& r } -bool TtfLoader::request(Shape* shape, char* text, bool italic) +bool TtfLoader::request(Shape* shape, char* text) { this->shape = shape; this->text = text; - this->italic = italic; return true; } diff --git a/src/loaders/ttf/tvgTtfLoader.h b/src/loaders/ttf/tvgTtfLoader.h index e981921b..cdfd76bd 100644 --- a/src/loaders/ttf/tvgTtfLoader.h +++ b/src/loaders/ttf/tvgTtfLoader.h @@ -36,7 +36,6 @@ struct TtfLoader : public FontLoader TtfReader reader; char* text = nullptr; Shape* shape = nullptr; - bool italic = false; bool nomap = false; bool freeData = false; @@ -46,8 +45,8 @@ struct TtfLoader : public FontLoader using FontLoader::open; bool open(const string& path) override; bool open(const char *data, uint32_t size, const string& rpath, bool copy) override; - bool resize(Paint* paint, float w, float h) override; - bool request(Shape* shape, char* text, bool italic = false) override; + bool transform(Paint* paint, float fontSize, bool italic) override; + bool request(Shape* shape, char* text) override; bool read() override; void clear(); }; diff --git a/src/renderer/tvgLoadModule.h b/src/renderer/tvgLoadModule.h index 84d35bc0..c573285c 100644 --- a/src/renderer/tvgLoadModule.h +++ b/src/renderer/tvgLoadModule.h @@ -101,7 +101,8 @@ struct FontLoader : LoadModule FontLoader(FileType type) : LoadModule(type) {} - virtual bool request(Shape* shape, char* text, bool italic = false) = 0; + virtual bool request(Shape* shape, char* text) = 0; + virtual bool transform(Paint* paint, float fontSize, bool italic) = 0; }; #endif //_TVG_LOAD_MODULE_H_ diff --git a/src/renderer/tvgText.h b/src/renderer/tvgText.h index c39446e7..76a1b30e 100644 --- a/src/renderer/tvgText.h +++ b/src/renderer/tvgText.h @@ -26,12 +26,7 @@ #include #include "tvgShape.h" #include "tvgFill.h" - -#ifdef THORVG_TTF_LOADER_SUPPORT - #include "tvgTtfLoader.h" -#else - #include "tvgLoader.h" -#endif +#include "tvgLoader.h" struct Text::Impl { @@ -69,6 +64,11 @@ struct Text::Impl auto loader = LoaderMgr::loader(name); if (!loader) return Result::InsufficientCondition; + if (style && strstr(style, "italic")) italic = true; + else italic = false; + + fontSize = size; + //Same resource has been loaded. if (this->loader == loader) { this->loader->sharing--; //make it sure the reference counting. @@ -78,8 +78,6 @@ struct Text::Impl } this->loader = static_cast(loader); - fontSize = size; - if (style && strstr(style, "italic")) italic = true; changed = true; return Result::Success; } @@ -98,13 +96,13 @@ struct Text::Impl { if (!loader) return false; - loader->request(shape, utf8, italic); + loader->request(shape, utf8); //reload if (changed) { loader->read(); changed = false; } - return loader->resize(shape, fontSize, fontSize); + return loader->transform(shape, fontSize, italic); } RenderData update(RenderMethod* renderer, const Matrix& transform, Array& clips, uint8_t opacity, RenderUpdateFlag pFlag, TVG_UNUSED bool clipper)