mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 14:41:50 +00:00
renderer/text: fix a missing text update
previously font size & italic style had been ignored even if its attributes are changed. Co-Authored-By: Hermet Park <hermet@lottiefiles.com> issue: https://github.com/thorvg/thorvg/issues/2676
This commit is contained in:
parent
732a2be7e8
commit
c92cf4e139
4 changed files with 15 additions and 18 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -26,12 +26,7 @@
|
|||
#include <cstring>
|
||||
#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<FontLoader*>(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<RenderData>& clips, uint8_t opacity, RenderUpdateFlag pFlag, TVG_UNUSED bool clipper)
|
||||
|
|
Loading…
Add table
Reference in a new issue