diff --git a/examples/Text.cpp b/examples/Text.cpp index ee47d259..748ccea0 100644 --- a/examples/Text.cpp +++ b/examples/Text.cpp @@ -41,6 +41,7 @@ struct UserExample : tvgexam::Example //Otherwise, you can immediately unload the font data. //Please check Text::unload() APIs. if (!tvgexam::verify(tvg::Text::load(EXAMPLE_DIR"/font/Arial.ttf"))) return false; + if (!tvgexam::verify(tvg::Text::load(EXAMPLE_DIR"/font/NOTO-SANS-KR.ttf"))) return false; if (!tvgexam::verify(tvg::Text::load(EXAMPLE_DIR"/font/NanumGothicCoding.ttf"))) return false; //Load from memory @@ -98,7 +99,7 @@ struct UserExample : tvgexam::Example canvas->push(text6); auto text7 = tvg::Text::gen(); - text7->font("Arial", 15); + text7->font("NOTO-SANS-KR", 15); text7->text("Transformed Text - 30'"); text7->fill(0, 0, 0); text7->translate(600, 400); @@ -106,7 +107,7 @@ struct UserExample : tvgexam::Example canvas->push(text7); auto text8 = tvg::Text::gen(); - text8->font("Arial", 15); + text8->font("NOTO-SANS-KR", 15); text8->fill(0, 0, 0); text8->text("Transformed Text - 90'"); text8->translate(600, 400); @@ -114,7 +115,7 @@ struct UserExample : tvgexam::Example canvas->push(text8); auto text9 = tvg::Text::gen(); - text9->font("Arial", 15); + text9->font("NOTO-SANS-KR", 15); text9->fill(0, 0, 0); text9->text("Transformed Text - 180'"); text9->translate(800, 400); @@ -125,7 +126,7 @@ struct UserExample : tvgexam::Example float x, y, w2, h2; auto text10 = tvg::Text::gen(); - text10->font("Arial", 50); + text10->font("NOTO-SANS-KR", 50); text10->text("Linear Text"); text10->bounds(&x, &y, &w2, &h2); diff --git a/examples/resources/font/NOTO-SANS-KR.ttf b/examples/resources/font/NOTO-SANS-KR.ttf new file mode 100644 index 00000000..041c8809 Binary files /dev/null and b/examples/resources/font/NOTO-SANS-KR.ttf differ diff --git a/inc/thorvg.h b/inc/thorvg.h index 9dd03f54..f760c812 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -1581,6 +1581,7 @@ public: * It sets the font name, size and optionally the style. * * @param[in] name The name of the font. This should correspond to a font available in the canvas. + * If set to @c nullptr, ThorVG will attempt to select a fallback font available on the system. * @param[in] size The size of the font in points. This determines how large the text will appear. * @param[in] style The style of the font. It can be used to set the font to 'italic'. * If not specified, the default style is used. Only 'italic' style is supported currently. @@ -1589,6 +1590,13 @@ public: * * @note If the @p name is not specified, ThorVG will select any available font candidate. * @since 1.0 + * + * @code + * // Tip for fallback support to use any available font. + * if (text->font("Arial", 24) != tvg::Result::Success) { + * text->font(nullptr, 24); + * } + * @endcode */ Result font(const char* name, float size, const char* style = nullptr) noexcept; diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index ef743286..4fc32a68 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -2136,6 +2136,7 @@ TVG_API Tvg_Paint* tvg_text_new(void); * * @param[in] paint A Tvg_Paint pointer to the text object. * @param[in] name The name of the font. This should correspond to a font available in the canvas. +* If set to @c nullptr, ThorVG will attempt to select a fallback font available on the system. * @param[in] size The size of the font in points. * @param[in] style The style of the font. If empty, the default style is used. Currently only 'italic' style is supported. * @@ -2145,6 +2146,13 @@ TVG_API Tvg_Paint* tvg_text_new(void); * * @note If the @p name is not specified, ThorVG will select any available font candidate. * @since 1.0 +* +* @code +* // Fallback example: Try a specific font, then fallback to any available one. +* if (tvg_text_set_font(text, "Arial", 24, nullptr) != TVG_RESULT_SUCCESS) { +* tvg_text_set_font(text, nullptr, 24, nullptr); +* } +* @endcode */ TVG_API Tvg_Result tvg_text_set_font(Tvg_Paint* paint, const char* name, float size, const char* style); diff --git a/src/renderer/tvgText.h b/src/renderer/tvgText.h index 6cbbaf11..7811ef06 100644 --- a/src/renderer/tvgText.h +++ b/src/renderer/tvgText.h @@ -45,7 +45,6 @@ struct TextImpl : Text TextImpl() : impl(Paint::Impl(this)), shape(Shape::gen()) { PAINT(shape)->parent = this; - shape->fillRule(FillRule::EvenOdd); } ~TextImpl()