mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
text: allow the unnamed font
If the font name is not specified, ThorVG will select any available font candidate. This could be useful for font fallback mechanism.
This commit is contained in:
parent
bed38a4521
commit
8e5ca40250
7 changed files with 18 additions and 2 deletions
|
@ -72,7 +72,7 @@ struct UserExample : tvgexam::Example
|
||||||
canvas->push(text2);
|
canvas->push(text2);
|
||||||
|
|
||||||
auto text3 = tvg::Text::gen();
|
auto text3 = tvg::Text::gen();
|
||||||
text3->font("Arial", 40);
|
text3->font(nullptr, 40); //Use any font
|
||||||
text3->text("Kerning Test: VA, AV, TJ, JT");
|
text3->text("Kerning Test: VA, AV, TJ, JT");
|
||||||
text3->fill(255, 255, 255);
|
text3->fill(255, 255, 255);
|
||||||
text3->translate(0, 225);
|
text3->translate(0, 225);
|
||||||
|
|
|
@ -1528,6 +1528,7 @@ public:
|
||||||
*
|
*
|
||||||
* @retval Result::InsufficientCondition when the specified @p name cannot be found.
|
* @retval Result::InsufficientCondition when the specified @p name cannot be found.
|
||||||
*
|
*
|
||||||
|
* @note If the @p name is not specified, ThorVG will select any available font candidate.
|
||||||
* @note Experimental API
|
* @note Experimental API
|
||||||
*/
|
*/
|
||||||
Result font(const char* name, float size, const char* style = nullptr) noexcept;
|
Result font(const char* name, float size, const char* style = nullptr) noexcept;
|
||||||
|
|
|
@ -2021,6 +2021,7 @@ TVG_API Tvg_Paint* tvg_text_new(void);
|
||||||
* @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the @p paint argument.
|
* @retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the @p paint argument.
|
||||||
* @retval TVG_RESULT_INSUFFICIENT_CONDITION The specified @p name cannot be found.
|
* @retval TVG_RESULT_INSUFFICIENT_CONDITION The specified @p name cannot be found.
|
||||||
*
|
*
|
||||||
|
* @note If the @p name is not specified, ThorVG will select any available font candidate.
|
||||||
* @note Experimental API
|
* @note Experimental API
|
||||||
*/
|
*/
|
||||||
TVG_API Tvg_Result tvg_text_set_font(Tvg_Paint* paint, const char* name, float size, const char* style);
|
TVG_API Tvg_Result tvg_text_set_font(Tvg_Paint* paint, const char* name, float size, const char* style);
|
||||||
|
|
|
@ -341,6 +341,18 @@ LoadModule* LoaderMgr::loader(const char* key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LoadModule* LoaderMgr::anyfont()
|
||||||
|
{
|
||||||
|
INLIST_FOREACH(_activeLoaders, loader) {
|
||||||
|
if ((loader->type == FileType::Ttf) && loader->pathcache) {
|
||||||
|
++loader->sharing;
|
||||||
|
return loader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const char* mimeType, const char* rpath, bool copy)
|
LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const char* mimeType, const char* rpath, bool copy)
|
||||||
{
|
{
|
||||||
//Note that users could use the same data pointer with the different content.
|
//Note that users could use the same data pointer with the different content.
|
||||||
|
|
|
@ -34,6 +34,7 @@ struct LoaderMgr
|
||||||
static LoadModule* loader(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy);
|
static LoadModule* loader(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy);
|
||||||
static LoadModule* loader(const char* name, const char* data, uint32_t size, const char* mimeType, bool copy);
|
static LoadModule* loader(const char* name, const char* data, uint32_t size, const char* mimeType, bool copy);
|
||||||
static LoadModule* loader(const char* key);
|
static LoadModule* loader(const char* key);
|
||||||
|
static LoadModule* anyfont();
|
||||||
static bool retrieve(const char* filename);
|
static bool retrieve(const char* filename);
|
||||||
static bool retrieve(LoadModule* loader);
|
static bool retrieve(LoadModule* loader);
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,7 @@ struct Text::Impl : Paint::Impl
|
||||||
|
|
||||||
Result font(const char* name, float size, const char* style)
|
Result font(const char* name, float size, const char* style)
|
||||||
{
|
{
|
||||||
auto loader = LoaderMgr::loader(name);
|
auto loader = name ? LoaderMgr::loader(name) : LoaderMgr::anyfont();
|
||||||
if (!loader) return Result::InsufficientCondition;
|
if (!loader) return Result::InsufficientCondition;
|
||||||
|
|
||||||
if (style && strstr(style, "italic")) italic = true;
|
if (style && strstr(style, "italic")) italic = true;
|
||||||
|
|
|
@ -108,6 +108,7 @@ TEST_CASE("Text Font", "[tvgText]")
|
||||||
REQUIRE(text->font("Arial", 80) == tvg::Result::Success);
|
REQUIRE(text->font("Arial", 80) == tvg::Result::Success);
|
||||||
REQUIRE(text->font("Arial", 1) == tvg::Result::Success);
|
REQUIRE(text->font("Arial", 1) == tvg::Result::Success);
|
||||||
REQUIRE(text->font("Arial", 50) == tvg::Result::Success);
|
REQUIRE(text->font("Arial", 50) == tvg::Result::Success);
|
||||||
|
REQUIRE(text->font(nullptr, 50) == tvg::Result::Success);
|
||||||
REQUIRE(text->font("InvalidFont", 80) == tvg::Result::InsufficientCondition);
|
REQUIRE(text->font("InvalidFont", 80) == tvg::Result::InsufficientCondition);
|
||||||
|
|
||||||
Initializer::term();
|
Initializer::term();
|
||||||
|
|
Loading…
Add table
Reference in a new issue