diff --git a/inc/thorvg.h b/inc/thorvg.h index f515a031..5862553c 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -1493,13 +1493,22 @@ 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. * * @retval Result::InsufficientCondition when the specified @p name cannot be found. * - * @note Experimental API + * @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 7cfac91b..74b529d7 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -2179,16 +2179,25 @@ TVG_API Tvg_Paint* tvg_text_new(void); * This function allows you to define the font characteristics used for text rendering. * It sets the font name, size and optionally the style. * -* \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. -* \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. +* @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. * * \return Tvg_Result enumeration. * \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. * -* \note Experimental API +* @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 9d4529ab..c84615d7 100644 --- a/src/renderer/tvgText.h +++ b/src/renderer/tvgText.h @@ -40,10 +40,7 @@ struct Text::Impl bool italic = false; bool changed = false; - Impl(Text* p) : paint(p), shape(Shape::gen().release()) - { - shape->fill(FillRule::EvenOdd); - } + Impl(Text* p) : paint(p), shape(Shape::gen().release()) {} ~Impl() {