api: clean up

promoted offical c++ apis (v0.15)
 - enum class BlendMethod
 - enum class CanvasEngine::Wg
 - virtual Result Canvas::viewport(int32_t x, int32_t y, int32_t w, int32_t h);
 - class Text
 - Result Text::fill(uint8_t r, uint8_t g, uint8_t b)
 - Result Text::fill(std::unique_ptr<Fill> f)
 - static Result Text::unload(const std::string& path)
 - static Result Text::load(const std::string& path)
 - static Result Text::load(const char* name, const char* data, uint32_t size, const std::string& mimeType = "ttf", bool copy = false)
 - static std::unique_ptr<Text> Text::gen()
 - class WgCanvas
 - static std::unique_ptr<WgCanvas> WgCanvas::gen()
 - static const char* Initializer::version(uint32_t* major, uint32_t* minor, uint32_t* micro)
 - class LottieAnimation

promoted official c apis (v0.15)
 - Tvg_Blend_Method
 - Tvg_Result tvg_engine_version(uint32_t* major, uint32_t* minor, uint32_t* micro, const char** version)
 - Tvg_Result tvg_canvas_set_viewport(Tvg_Canvas* canvas, int32_t x, int32_t y, int32_t w, int32_t h)
 - Tvg_Result tvg_paint_set_blend_method(Tvg_Paint* paint, Tvg_Blend_Method method)
 - Tvg_Paint* tvg_text_new(void)
 - Tvg_Result tvg_text_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b)
 - Tvg_Result tvg_text_set_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
 - Tvg_Result tvg_font_load(const char* path)
 - Tvg_Result tvg_font_load_data(const char* name, const char* data, uint32_t size, const char *mimetype, bool copy)
 - Tvg_Result tvg_font_unload(const char* path)
 - Tvg_Animation* tvg_lottie_animation_new(void)

removed experimental apis
 - BlendMethod paint::blend() const
 - bool Shape::strokeTrim(float* begin, float* end) const
 - Tvg_Result tvg_paint_get_blend_method(const Tvg_Paint* paint, Tvg_Blend_Method* method)
 - Tvg_Result tvg_shape_get_stroke_trim(Tvg_Paint* paint, float* begin, float* end, bool* simultaneous)
 - tvg_text_set_linear_gradient(Paint* paint, Tvg_Gradient* gradient)
 - tvg_text_set_radial_gradient(Paint* paint, Tvg_Gradient* gradient)

issue: https://github.com/thorvg/thorvg/issues/1372
This commit is contained in:
Hermet Park 2024-09-20 23:17:21 +09:00 committed by Hermet Park
parent 7ec697aa77
commit 76fb3f3cd9
15 changed files with 67 additions and 206 deletions

View file

@ -272,7 +272,7 @@ void contents()
Tvg_Paint *text = tvg_text_new();
tvg_text_set_font(text, "Arial", 20.0f, "italic");
tvg_text_set_linear_gradient(text, grad);
tvg_text_set_gradient(text, grad);
tvg_text_set_text(text, "ThorVG is the best");
tvg_paint_translate(text, 70.0f, 420.0f);
tvg_canvas_push(canvas, text);

View file

@ -178,7 +178,7 @@ enum class CompositeMethod : uint8_t
*
* @see Paint::blend()
*
* @note Experimental API
* @since 0.15
*/
enum class BlendMethod : uint8_t
{
@ -211,7 +211,7 @@ enum class CanvasEngine : uint8_t
All = 0, ///< All feasible rasterizers. @since 1.0
Sw = (1 << 1), ///< CPU rasterizer.
Gl = (1 << 2), ///< OpenGL rasterizer.
Wg = (1 << 3), ///< WebGPU rasterizer. (Experimental API)
Wg = (1 << 3), ///< WebGPU rasterizer. @since 0.15
};
@ -420,15 +420,6 @@ public:
*/
CompositeMethod composite(const Paint** target) const noexcept;
/**
* @brief Retrieves the current blending method applied to the paint object.
*
* @return The currently set blending method.
*
* @note Experimental API
*/
BlendMethod blend() const noexcept;
/**
* @brief Returns the ID value of this class.
*
@ -661,7 +652,7 @@ public:
* @warning It's not allowed to change the viewport during Canvas::push() - Canvas::sync() or Canvas::update() - Canvas::sync().
*
* @note When resetting the target, the viewport will also be reset to the target size.
* @note Experimental API
* @since 0.15
*/
virtual Result viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept;
@ -1196,18 +1187,6 @@ public:
*/
float strokeMiterlimit() const noexcept;
/**
* @brief Gets the trim of the stroke along the defined path segment.
*
* @param[out] begin The starting point of the segment to display along the path.
* @param[out] end Specifies the end of the segment to display along the path.
*
* @return @c true if trimming is applied simultaneously to all paths of the shape, @c false otherwise.
*
* @note Experimental API
*/
bool strokeTrim(float* begin, float* end) const noexcept;
/**
* @brief Creates a new Shape object.
*
@ -1458,7 +1437,7 @@ public:
*
* @brief A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text.
*
* @note Experimental API
* @since 0.15
*/
class TVG_API Text final : public Paint
{
@ -1503,7 +1482,7 @@ public:
*
* @see Text::font()
*
* @note Experimental API
* @since 0.15
*/
Result fill(uint8_t r, uint8_t g, uint8_t b) noexcept;
@ -1515,9 +1494,9 @@ public:
* @param[in] f The unique pointer to the gradient fill.
*
* @note Either a solid color or a gradient fill is applied, depending on what was set as last.
* @note Experimental API
*
* @see Text::font()
*
* @since 0.15
*/
Result fill(std::unique_ptr<Fill> f) noexcept;
@ -1533,9 +1512,9 @@ public:
* @retval Result::InvalidArguments In case the @p path is invalid.
* @retval Result::NonSupport When trying to load a file with an unknown extension.
*
* @note Experimental API
*
* @see Text::unload(const std::string& path)
*
* @since 0.15
*/
static Result load(const std::string& path) noexcept;
@ -1560,9 +1539,9 @@ public:
*
* @note To unload the font data loaded using this API, pass the proper @p name and @c nullptr as @p data.
* @note If you are unsure about the MIME type, you can provide an empty value like @c "", and thorvg will attempt to figure it out.
* @note Experimental API
*
* @see Text::font(const char* name, float size, const char* style)
*
* @note 0.15
*/
static Result load(const char* name, const char* data, uint32_t size, const std::string& mimeType = "ttf", bool copy = false) noexcept;
@ -1576,9 +1555,9 @@ public:
* @retval Result::InsufficientCondition Fails if the loader is not initialized.
*
* @note If the font data is currently in use, it will not be immediately unloaded.
* @note Experimental API
*
* @see Text::load(const std::string& path)
*
* @since 0.15
*/
static Result unload(const std::string& path) noexcept;
@ -1587,7 +1566,7 @@ public:
*
* @return A new Text object.
*
* @note Experimental API
* @since 0.15
*/
static std::unique_ptr<Text> gen() noexcept;
@ -1747,7 +1726,7 @@ public:
*
* @warning Please do not use it. This class is not fully supported yet.
*
* @note Experimental API
* @since 0.15
*/
class TVG_API WgCanvas final : public Canvas
{
@ -1778,7 +1757,7 @@ public:
*
* @return A new WgCanvas object.
*
* @note Experimental API
* @since 0.15
*/
static std::unique_ptr<WgCanvas> gen() noexcept;
@ -1834,7 +1813,7 @@ public:
*
* @return The version of the engine in the format major.minor.micro, or a @p nullptr in case of an internal error.
*
* @note Experimental API
* @since 0.15
*/
static const char* version(uint32_t* major, uint32_t* minor, uint32_t* micro) noexcept;
@ -1939,6 +1918,7 @@ public:
* @note Animation allows a range from 0.0 to 1.0. @p end should not be higher than @p begin.
* @note If a marker has been specified, its range will be disregarded.
* @see LottieAnimation::segment(const char* marker)
*
* @note Experimental API
*/
Result segment(float begin, float end) noexcept;

View file

@ -150,23 +150,27 @@ typedef enum {
*
* \ingroup ThorVGCapi_Paint
*
* @note Experimental API
* \since 0.15
*/
typedef enum {
TVG_BLEND_METHOD_NORMAL = 0, ///< Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D
TVG_BLEND_METHOD_ADD, ///< Simply adds pixel values of one layer with the other. (S + D)
TVG_BLEND_METHOD_SCREEN, ///< The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D)
TVG_BLEND_METHOD_MULTIPLY, ///< Takes the RGB channel values from 0 to 255 of each pixel in the top layer and multiples them with the values for the corresponding pixel from the bottom layer. (S * D)
TVG_BLEND_METHOD_SCREEN, ///< The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D)
TVG_BLEND_METHOD_OVERLAY, ///< Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)
TVG_BLEND_METHOD_DIFFERENCE, ///< Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S)
TVG_BLEND_METHOD_EXCLUSION, ///< The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d)
TVG_BLEND_METHOD_SRCOVER, ///< Replace the bottom layer with the top layer.
TVG_BLEND_METHOD_DARKEN, ///< Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D)
TVG_BLEND_METHOD_LIGHTEN, ///< Only has the opposite action of Darken Only. max(S, D)
TVG_BLEND_METHOD_COLORDODGE, ///< Divides the bottom layer by the inverted top layer. D / (255 - S)
TVG_BLEND_METHOD_COLORBURN, ///< Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S
TVG_BLEND_METHOD_HARDLIGHT, ///< The same as Overlay but with the color roles reversed. (2 * S * D) if (S < Sa), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)
TVG_BLEND_METHOD_SOFTLIGHT ///< The same as Overlay but with applying pure black or white does not result in pure black or white. (1 - 2 * S) * (D ^ 2) + (2 * S * D)
TVG_BLEND_METHOD_SOFTLIGHT, ///< The same as Overlay but with applying pure black or white does not result in pure black or white. (1 - 2 * S) * (D ^ 2) + (2 * S * D)
TVG_BLEND_METHOD_DIFFERENCE, ///< Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S)
TVG_BLEND_METHOD_EXCLUSION, ///< The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d)
TVG_BLEND_METHOD_HUE, ///< Reserved. Not supported.
TVG_BLEND_METHOD_SATURATION, ///< Reserved. Not supported.
TVG_BLEND_METHOD_COLOR, ///< Reserved. Not supported.
TVG_BLEND_METHOD_LUMINOSITY, ///< Reserved. Not supported.
TVG_BLEND_METHOD_ADD, ///< Simply adds pixel values of one layer with the other. (S + D)
TVG_BLEND_METHOD_HARDMIX ///< Reserved. Not supported.
} Tvg_Blend_Method;
@ -387,7 +391,7 @@ TVG_API Tvg_Result tvg_engine_term(Tvg_Engine engine_method);
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_SUCCESS.
*
* \note Experimental API
* \since 0.15
*/
TVG_API Tvg_Result tvg_engine_version(uint32_t* major, uint32_t* minor, uint32_t* micro, const char** version);
@ -779,8 +783,8 @@ TVG_API Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas);
* \warning It's not allowed to change the viewport during tvg_canvas_update() - tvg_canvas_sync() or tvg_canvas_push() - tvg_canvas_sync().
*
* \note When resetting the target, the viewport will also be reset to the target size.
* \note Experimental API
* \see tvg_swcanvas_set_target()
* \since 0.15
*/
TVG_API Tvg_Result tvg_canvas_set_viewport(Tvg_Canvas* canvas, int32_t x, int32_t y, int32_t w, int32_t h);
@ -1044,29 +1048,11 @@ TVG_DEPRECATED TVG_API Tvg_Result tvg_paint_get_identifier(const Tvg_Paint* pain
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument.
*
* @note Experimental API
* \since 0.15
*/
TVG_API Tvg_Result tvg_paint_set_blend_method(Tvg_Paint* paint, Tvg_Blend_Method method);
/**
* @brief Gets the blending method for the paint object.
*
* The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others.
* its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations.
* The blending operation is determined by the chosen @p BlendMethod, which specifies how the colors or images are combined.
*
* \param[in] paint The Tvg_Paint object of which to get the blend method.
* \param[out] method The blending method of the paint.
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument.
*
* @note Experimental API
*/
TVG_API Tvg_Result tvg_paint_get_blend_method(const Tvg_Paint* paint, Tvg_Blend_Method* method);
/** \} */ // end defgroup ThorVGCapi_Paint
/**
@ -1552,22 +1538,6 @@ TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint* paint, float
TVG_API Tvg_Result tvg_shape_set_stroke_trim(Tvg_Paint* paint, float begin, float end, bool simultaneous);
/*!
* \brief Gets the trim of the stroke along the defined path segment.
*
* \param[in] paint A Tvg_Paint pointer to the shape object.
* \param[out] begin The starting point of the segment to display along the path.
* \param[out] end Specifies the end of the segment to display along the path.
* \param[out] simultaneous Determines how to trim multiple paths within a shape.
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer.
*
* \note Experimental API
*/
TVG_API Tvg_Result tvg_shape_get_stroke_trim(Tvg_Paint* paint, float* begin, float* end, bool* simultaneous);
/*!
* \brief Sets the shape's solid color.
*
@ -2191,7 +2161,7 @@ TVG_API Tvg_Result tvg_scene_clear(Tvg_Paint* scene, bool free);
* \defgroup ThorVGCapi_Text Text
* \brief A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text.
*
* \note Experimental API
* \since 0.15
*
* \{
*/
@ -2204,7 +2174,7 @@ TVG_API Tvg_Result tvg_scene_clear(Tvg_Paint* scene, bool free);
*
* \return A new text object.
*
* \note Experimental API
* \since 0.15
*/
TVG_API Tvg_Paint* tvg_text_new(void);
@ -2258,48 +2228,29 @@ TVG_API Tvg_Result tvg_text_set_text(Tvg_Paint* paint, const char* text);
* \retval TVG_RESULT_INVALID_ARGUMENT A \c nullptr passed as the \p paint argument.
*
* \note Either a solid color or a gradient fill is applied, depending on what was set as last.
* \note Experimental API
*
* \see tvg_text_set_font()
*
* \since 0.15
*/
TVG_API Tvg_Result tvg_text_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b);
/**
* \brief Sets the linear gradient fill for the text.
* \brief Sets the gradient fill for the text.
*
* \param[in] paint A Tvg_Paint pointer to the text object.
* \param[in] grad The linear gradient fill
* \param[in] grad The linear or radial gradient fill
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_INVALID_ARGUMENT A \c nullptr passed as the \p paint argument.
* \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer.
*
* \note Either a solid color or a gradient fill is applied, depending on what was set as last.
* \note Experimental API
*
* \see tvg_text_set_font()
*
* \since 0.15
*/
TVG_API Tvg_Result tvg_text_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient);
/**
* \brief Sets the radial gradient fill for the text.
*
* \param[in] paint A Tvg_Paint pointer to the text object.
* \param[in] grad The radial gradient fill
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_INVALID_ARGUMENT A \c nullptr passed as the \p paint argument.
* \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer.
*
* \note Either a solid color or a gradient fill is applied, depending on what was set as last.
* \note Experimental API
*
* \see tvg_text_set_font()
*/
TVG_API Tvg_Result tvg_text_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient);
TVG_API Tvg_Result tvg_text_set_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient);
/**
* \brief Loads a scalable font data from a file.
@ -2314,9 +2265,9 @@ TVG_API Tvg_Result tvg_text_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient*
* \retval TVG_RESULT_INVALID_ARGUMENT An invalid \p path passed as an argument.
* \retval TVG_RESULT_NOT_SUPPORTED When trying to load a file with an unknown extension.
*
* \note Experimental API
*
* \see tvg_font_unload()
*
* \since 0.15
*/
TVG_API Tvg_Result tvg_font_load(const char* path);
@ -2342,7 +2293,8 @@ TVG_API Tvg_Result tvg_font_load(const char* path);
* \warning: It's the user responsibility to release the \p data memory.
*
* \note To unload the font data loaded using this API, pass the proper \p name and \c nullptr as \p data.
* \note Experimental API
*
* \since 0.15
*/
TVG_API Tvg_Result tvg_font_load_data(const char* name, const char* data, uint32_t size, const char *mimetype, bool copy);
@ -2358,9 +2310,9 @@ TVG_API Tvg_Result tvg_font_load_data(const char* name, const char* data, uint32
* \retval TVG_RESULT_INSUFFICIENT_CONDITION The loader is not initialized.
*
* \note If the font data is currently in use, it will not be immediately unloaded.
* \note Experimental API
*
* \see tvg_font_load()
*
* \since 0.15
*/
TVG_API Tvg_Result tvg_font_unload(const char* path);
@ -2570,8 +2522,6 @@ TVG_API Tvg_Result tvg_animation_get_duration(Tvg_Animation* animation, float* d
* \retval TVG_RESULT_INVALID_ARGUMENT When the given parameters are out of range.
*
* \note Experimental API
*
* \since 0.13
*/
TVG_API Tvg_Result tvg_animation_set_segment(Tvg_Animation* animation, float begin, float end);
@ -2655,7 +2605,7 @@ TVG_API uint32_t tvg_accessor_generate_id(const char* name);
*
* \return Tvg_Animation A new Tvg_LottieAnimation object.
*
* \note Experimental API
* \since 0.15
*/
TVG_API Tvg_Animation* tvg_lottie_animation_new(void);

View file

@ -244,14 +244,6 @@ TVG_API Tvg_Result tvg_paint_set_blend_method(Tvg_Paint* paint, Tvg_Blend_Method
}
TVG_API Tvg_Result tvg_paint_get_blend_method(const Tvg_Paint* paint, Tvg_Blend_Method* method)
{
if (!paint || !method) return TVG_RESULT_INVALID_ARGUMENT;
*method = static_cast<Tvg_Blend_Method>(reinterpret_cast<const Paint*>(paint)->blend());
return TVG_RESULT_SUCCESS;
}
TVG_API Tvg_Result tvg_paint_get_type(const Tvg_Paint* paint, Tvg_Type* type)
{
if (!paint || !type) return TVG_RESULT_INVALID_ARGUMENT;
@ -479,14 +471,6 @@ TVG_API Tvg_Result tvg_shape_set_stroke_trim(Tvg_Paint* paint, float begin, floa
}
TVG_API Tvg_Result tvg_shape_get_stroke_trim(Tvg_Paint* paint, float* begin, float* end, bool* simultaneous)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
if (simultaneous) *simultaneous = reinterpret_cast<Shape*>(paint)->strokeTrim(begin, end);
return TVG_RESULT_SUCCESS;
}
TVG_API Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
@ -774,17 +758,10 @@ TVG_API Tvg_Result tvg_text_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t
}
TVG_API Tvg_Result tvg_text_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
TVG_API Tvg_Result tvg_text_set_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Text*>(paint)->fill(unique_ptr<LinearGradient>((LinearGradient*)(gradient)));
}
TVG_API Tvg_Result tvg_text_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Text*>(paint)->fill(unique_ptr<RadialGradient>((RadialGradient*)(gradient)));
return (Tvg_Result) reinterpret_cast<Text*>(paint)->fill(unique_ptr<Fill>((Fill*)(gradient)));
}

View file

@ -15,7 +15,7 @@ namespace tvg
*
* @see Animation
*
* @note Experimental API
* @since 0.15
*/
class TVG_API LottieAnimation final : public Animation
{
@ -84,7 +84,7 @@ public:
*
* @return A new LottieAnimation object.
*
* @note Experimental API
* @since 0.15
*/
static std::unique_ptr<LottieAnimation> gen() noexcept;
};

View file

@ -507,6 +507,9 @@ TVG_DEPRECATED uint32_t Paint::identifier() const noexcept
Result Paint::blend(BlendMethod method) noexcept
{
//TODO: Remove later
if (method == BlendMethod::Hue || method == BlendMethod::Saturation || method == BlendMethod::Color || method == BlendMethod::Luminosity || method == BlendMethod::HardMix) return Result::NonSupport;
if (pImpl->blendMethod != method) {
pImpl->blendMethod = method;
pImpl->renderFlag |= RenderUpdateFlag::Blend;
@ -514,9 +517,3 @@ Result Paint::blend(BlendMethod method) noexcept
return Result::Success;
}
BlendMethod Paint::blend() const noexcept
{
return pImpl->blendMethod;
}

View file

@ -20,6 +20,7 @@
* SOFTWARE.
*/
#include "tvgPaint.h"
#include "tvgPicture.h"
/************************************************************************/
@ -73,7 +74,7 @@ bool Picture::Impl::needComposition(uint8_t opacity)
bool Picture::Impl::render(RenderMethod* renderer)
{
bool ret = false;
renderer->blend(picture->blend());
renderer->blend(PP(picture)->blendMethod);
if (surface) return renderer->renderImage(rd);
else if (paint) {

View file

@ -88,7 +88,7 @@ struct Scene::Impl
if (compMethod != CompositeMethod::None && compMethod != CompositeMethod::ClipPath) return true;
//Blending may require composition (even if opacity == 255)
if (scene->blend() != BlendMethod::Normal) return true;
if (PP(scene)->blendMethod != BlendMethod::Normal) return true;
//Half translucent requires intermediate composition.
if (opacity == 255) return false;
@ -120,7 +120,7 @@ struct Scene::Impl
RenderCompositor* cmp = nullptr;
auto ret = true;
renderer->blend(scene->blend());
renderer->blend(PP(scene)->blendMethod);
if (needComp) {
cmp = renderer->target(bounds(renderer), renderer->colorSpace());

View file

@ -414,12 +414,6 @@ Result Shape::strokeTrim(float begin, float end, bool simultaneous) noexcept
}
bool Shape::strokeTrim(float* begin, float* end) const noexcept
{
return pImpl->strokeTrim(begin, end);
}
Result Shape::fill(FillRule r) noexcept
{
pImpl->rs.rule = r;

View file

@ -55,7 +55,7 @@ struct Shape::Impl
RenderCompositor* cmp = nullptr;
renderer->blend(shape->blend());
renderer->blend(PP(shape)->blendMethod);
if (needComp) {
cmp = renderer->target(bounds(renderer), renderer->colorSpace());

View file

@ -90,7 +90,7 @@ struct Text::Impl
bool render(RenderMethod* renderer)
{
if (!loader) return true;
renderer->blend(paint->blend());
renderer->blend(PP(paint)->blendMethod);
return PP(shape)->render(renderer);
}

View file

@ -252,19 +252,8 @@ TEST_CASE("Stroke trim", "[capiStrokeTrim]")
Tvg_Paint* paint = tvg_shape_new();
REQUIRE(paint);
float begin, end;
bool simultaneous;
REQUIRE(tvg_shape_get_stroke_trim(NULL, &begin, &end, &simultaneous) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_shape_get_stroke_trim(paint, &begin, &end, &simultaneous) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_shape_set_stroke_trim(NULL, 0.33f, 0.66f, false) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_shape_set_stroke_trim(paint, 0.33f, 0.66f, false) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_shape_get_stroke_trim(paint, &begin, &end, &simultaneous) == TVG_RESULT_SUCCESS);
REQUIRE(begin == Approx(0.33).margin(0.000001));
REQUIRE(end == Approx(0.66).margin(0.000001));
REQUIRE(simultaneous == false);
REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
}

View file

@ -153,17 +153,14 @@ TEST_CASE("Set gradient text fill", "[capiText]")
REQUIRE(tvg_font_load(TEST_DIR"/Arial.ttf") == TVG_RESULT_SUCCESS);
REQUIRE(tvg_text_set_linear_gradient(text, NULL) == TVG_RESULT_MEMORY_CORRUPTION);
REQUIRE(tvg_text_set_radial_gradient(text, NULL) == TVG_RESULT_MEMORY_CORRUPTION);
REQUIRE(tvg_text_set_gradient(text, NULL) == TVG_RESULT_MEMORY_CORRUPTION);
REQUIRE(tvg_text_set_font(text, "Arial", 10.0f, "") == TVG_RESULT_SUCCESS);
REQUIRE(tvg_text_set_linear_gradient(text, NULL) == TVG_RESULT_MEMORY_CORRUPTION);
REQUIRE(tvg_text_set_radial_gradient(text, NULL) == TVG_RESULT_MEMORY_CORRUPTION);
REQUIRE(tvg_text_set_linear_gradient(NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_text_set_radial_gradient(NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_text_set_linear_gradient(text, gradientLin) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_text_set_radial_gradient(text, gradientRad) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_text_set_gradient(text, NULL) == TVG_RESULT_MEMORY_CORRUPTION);
REQUIRE(tvg_text_set_gradient(NULL, NULL) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_text_set_gradient(text, gradientLin) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_text_set_gradient(text, gradientRad) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_paint_del(text) == TVG_RESULT_SUCCESS);
}

View file

@ -256,54 +256,39 @@ TEST_CASE("Blending", "[tvgPaint]")
auto shape = Shape::gen();
REQUIRE(shape);
//Default
REQUIRE(shape->blend() == BlendMethod::Normal);
//Add
REQUIRE(shape->blend(BlendMethod::Add) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::Add);
//Screen
REQUIRE(shape->blend(BlendMethod::Screen) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::Screen);
//Multiply
REQUIRE(shape->blend(BlendMethod::Multiply) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::Multiply);
//Overlay
REQUIRE(shape->blend(BlendMethod::Overlay) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::Overlay);
//Difference
REQUIRE(shape->blend(BlendMethod::Difference) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::Difference);
//Exclusion
REQUIRE(shape->blend(BlendMethod::Exclusion) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::Exclusion);
//Darken
REQUIRE(shape->blend(BlendMethod::Darken) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::Darken);
//Lighten
REQUIRE(shape->blend(BlendMethod::Lighten) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::Lighten);
//ColorDodge
REQUIRE(shape->blend(BlendMethod::ColorDodge) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::ColorDodge);
//ColorBurn
REQUIRE(shape->blend(BlendMethod::ColorBurn) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::ColorBurn);
//HardLight
REQUIRE(shape->blend(BlendMethod::HardLight) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::HardLight);
//SoftLight
REQUIRE(shape->blend(BlendMethod::SoftLight) == Result::Success);
REQUIRE(shape->blend() == BlendMethod::SoftLight);
}

View file

@ -192,16 +192,7 @@ TEST_CASE("Stroking", "[tvgShape]")
REQUIRE(shape->strokeMiterlimit() == 1000.0f);
REQUIRE(shape->strokeMiterlimit(-0.001f) == Result::InvalidArguments);
//Stroke Trim
float begin, end;
REQUIRE(shape->strokeTrim(&begin, &end) == true);
REQUIRE(begin == Approx(0.0).margin(0.000001));
REQUIRE(end == Approx(1.0).margin(0.000001));
REQUIRE(shape->strokeTrim(0.3f, 0.88f, false) == Result::Success);
REQUIRE(shape->strokeTrim(&begin, &end) == false);
REQUIRE(begin == Approx(0.3).margin(0.000001));
REQUIRE(end == Approx(0.88).margin(0.000001));
//Stroke Order After Stroke Setting
REQUIRE(shape->order(true) == Result::Success);