mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-23 14:48:24 +00:00
Yet we don't break apis, this patch reverts the next:
cb36c25aff
8c0fc2b25a
c1e4e0808a
Those reverted changes sholud be in the bucket, the next issue item: @Issue: https://github.com/thorvg/thorvg/issues/1372
This commit is contained in:
parent
f2e755cdd5
commit
7d797ee548
28 changed files with 99 additions and 102 deletions
12
inc/thorvg.h
12
inc/thorvg.h
|
@ -980,11 +980,11 @@ public:
|
|||
* @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0.
|
||||
* @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0.
|
||||
* @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0.
|
||||
* @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
|
||||
* @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
|
||||
*
|
||||
* @return Result::Success when succeed, Result::FailedAllocation otherwise.
|
||||
*/
|
||||
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
|
||||
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Sets the gradient fill of the stroke for all of the figures from the path.
|
||||
|
@ -1002,7 +1002,6 @@ public:
|
|||
*
|
||||
* @param[in] dashPattern The array of consecutive pair values of the dash length and the gap length.
|
||||
* @param[in] cnt The length of the @p dashPattern array.
|
||||
* @param[in] offset The shift of the starting point within the repeating dash pattern from which the path's dashing begins.
|
||||
*
|
||||
* @retval Result::Success When succeed.
|
||||
* @retval Result::FailedAllocation An internal error with a memory allocation for an object to be dashed.
|
||||
|
@ -1011,7 +1010,7 @@ public:
|
|||
* @note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt.
|
||||
* @warning @p cnt must be greater than 1 if the dash pattern is valid.
|
||||
*/
|
||||
Result stroke(const float* dashPattern, uint32_t cnt, float offset = 0.0f) noexcept;
|
||||
Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Sets the cap style of the stroke in the open sub-paths.
|
||||
|
@ -1158,7 +1157,7 @@ public:
|
|||
*
|
||||
* @return Result::Success when succeed, Result::InsufficientCondition otherwise.
|
||||
*/
|
||||
Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
|
||||
Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Gets the pointer to the gradient fill of the stroke.
|
||||
|
@ -1171,11 +1170,10 @@ public:
|
|||
* @brief Gets the dash pattern of the stroke.
|
||||
*
|
||||
* @param[out] dashPattern The pointer to the memory, where the dash pattern array is stored.
|
||||
* @param[out] offset The shift of the starting point within the repeating dash pattern.
|
||||
*
|
||||
* @return The length of the @p dashPattern array.
|
||||
*/
|
||||
uint32_t strokeDash(const float** dashPattern, float* offset = nullptr) const noexcept;
|
||||
uint32_t strokeDash(const float** dashPattern) const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Gets the cap style used for stroking the path.
|
||||
|
|
|
@ -1316,12 +1316,18 @@ TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gra
|
|||
|
||||
|
||||
/*!
|
||||
* \brief Sets the shape's stroke dash pattern. (BETA_API)
|
||||
* \brief Sets the shape's stroke dash pattern.
|
||||
*
|
||||
* \code
|
||||
* //dash pattern examples
|
||||
* float dashPattern[2] = {20, 10}; // -- -- --
|
||||
* float dashPattern[2] = {40, 20}; // ---- ---- ----
|
||||
* float dashPattern[4] = {10, 20, 30, 40} // - --- - ---
|
||||
* \endcode
|
||||
*
|
||||
* \param[in] paint A Tvg_Paint pointer to the shape object.
|
||||
* \param[in] dashPattern The array of consecutive pair values of the dash length and the gap length.
|
||||
* \param[in] cnt The size of the @p dashPattern array.
|
||||
* \param[in] offset The shift of the starting point within the repeating dash pattern from which the path's dashing begins.
|
||||
*
|
||||
* \return Tvg_Result enumeration.
|
||||
* \retval TVG_RESULT_SUCCESS Succeed.
|
||||
|
@ -1330,24 +1336,23 @@ TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gra
|
|||
*
|
||||
* \note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt.
|
||||
*/
|
||||
TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt, float offset);
|
||||
TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Gets the dash pattern of the stroke. (BETA_API)
|
||||
* \brief Gets the dash pattern of the stroke.
|
||||
*
|
||||
* The function does not allocate any memory.
|
||||
*
|
||||
* \param[in] paint A Tvg_Paint pointer to the shape object.
|
||||
* \param[out] dashPattern The array of consecutive pair values of the dash length and the gap length.
|
||||
* \param[out] cnt The size of the @p dashPattern array.
|
||||
* \param[out] offset The shift of the starting point within the repeating dash pattern.
|
||||
*
|
||||
* \return Tvg_Result enumeration.
|
||||
* \retval TVG_RESULT_SUCCESS Succeed.
|
||||
* \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument.
|
||||
*/
|
||||
TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt, float* offset);
|
||||
TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt);
|
||||
|
||||
|
||||
/*!
|
||||
|
|
|
@ -367,17 +367,17 @@ TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gra
|
|||
}
|
||||
|
||||
|
||||
TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt, float offset)
|
||||
TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt)
|
||||
{
|
||||
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(dashPattern, cnt, offset);
|
||||
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(dashPattern, cnt);
|
||||
}
|
||||
|
||||
|
||||
TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt, float* offset)
|
||||
TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt)
|
||||
{
|
||||
if (!paint || !cnt || !dashPattern || !offset) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
*cnt = reinterpret_cast<const Shape*>(paint)->strokeDash(dashPattern, offset);
|
||||
if (!paint || !cnt || !dashPattern) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
*cnt = reinterpret_cast<const Shape*>(paint)->strokeDash(dashPattern);
|
||||
return TVG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
pMaskShape = maskShape.get();
|
||||
maskShape->appendCircle(180, 180, 75, 75);
|
||||
maskShape->fill(125, 125, 125);
|
||||
maskShape->stroke(25, 25, 25, 255);
|
||||
maskShape->stroke(25, 25, 25);
|
||||
maskShape->stroke(tvg::StrokeJoin::Round);
|
||||
maskShape->stroke(10);
|
||||
canvas->push(std::move(maskShape));
|
||||
|
|
|
@ -33,38 +33,38 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
//Arc Line
|
||||
auto shape1 = tvg::Shape::gen();
|
||||
shape1->appendArc(150, 150, 80, 10, 180, false);
|
||||
shape1->stroke(255, 255, 255, 255);
|
||||
shape1->stroke(255, 255, 255);
|
||||
shape1->stroke(2);
|
||||
if (canvas->push(std::move(shape1)) != tvg::Result::Success) return;
|
||||
|
||||
auto shape2 = tvg::Shape::gen();
|
||||
shape2->appendArc(400, 150, 80, 0, 300, false);
|
||||
shape2->stroke(255, 255, 255, 255);
|
||||
shape2->stroke(255, 255, 255);
|
||||
shape2->stroke(2);
|
||||
if (canvas->push(std::move(shape2)) != tvg::Result::Success) return;
|
||||
|
||||
auto shape3 = tvg::Shape::gen();
|
||||
shape3->appendArc(600, 150, 80, 300, 60, false);
|
||||
shape3->stroke(255, 255, 255, 255);
|
||||
shape3->stroke(255, 255, 255);
|
||||
shape3->stroke(2);
|
||||
if (canvas->push(std::move(shape3)) != tvg::Result::Success) return;
|
||||
|
||||
//Pie Line
|
||||
auto shape4 = tvg::Shape::gen();
|
||||
shape4->appendArc(150, 400, 80, 10, 180, true);
|
||||
shape4->stroke(255, 255, 255, 255);
|
||||
shape4->stroke(255, 255, 255);
|
||||
shape4->stroke(2);
|
||||
if (canvas->push(std::move(shape4)) != tvg::Result::Success) return;
|
||||
|
||||
auto shape5 = tvg::Shape::gen();
|
||||
shape5->appendArc(400, 400, 80, 0, 300, true);
|
||||
shape5->stroke(255, 255, 255, 255);
|
||||
shape5->stroke(255, 255, 255);
|
||||
shape5->stroke(2);
|
||||
if (canvas->push(std::move(shape5)) != tvg::Result::Success) return;
|
||||
|
||||
auto shape6 = tvg::Shape::gen();
|
||||
shape6->appendArc(600, 400, 80, 300, 60, true);
|
||||
shape6->stroke(255, 255, 255, 255);
|
||||
shape6->stroke(255, 255, 255);
|
||||
shape6->stroke(2);
|
||||
if (canvas->push(std::move(shape6)) != tvg::Result::Success) return;
|
||||
|
||||
|
@ -72,21 +72,21 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto shape7 = tvg::Shape::gen();
|
||||
shape7->appendArc(150, 650, 80, 10, 180, true);
|
||||
shape7->fill(255, 255, 255);
|
||||
shape7->stroke(255, 0, 0, 255);
|
||||
shape7->stroke(255, 0, 0);
|
||||
shape7->stroke(2);
|
||||
if (canvas->push(std::move(shape7)) != tvg::Result::Success) return;
|
||||
|
||||
auto shape8 = tvg::Shape::gen();
|
||||
shape8->appendArc(400, 650, 80, 0, 300, true);
|
||||
shape8->fill(255, 255, 255);
|
||||
shape8->stroke(255, 0, 0, 255);
|
||||
shape8->stroke(255, 0, 0);
|
||||
shape8->stroke(2);
|
||||
if (canvas->push(std::move(shape8)) != tvg::Result::Success) return;
|
||||
|
||||
auto shape9 = tvg::Shape::gen();
|
||||
shape9->appendArc(600, 650, 80, 300, 60, true);
|
||||
shape9->fill(255, 255, 255);
|
||||
shape9->stroke(255, 0, 0, 255);
|
||||
shape9->stroke(255, 0, 0);
|
||||
shape9->stroke(2);
|
||||
if (canvas->push(std::move(shape9)) != tvg::Result::Success) return;
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ void testCapi()
|
|||
|
||||
//Prapare a dash for the stroke
|
||||
float dashPattern[4] = {15.0f, 30.0f, 2.0f, 30.0f};
|
||||
tvg_shape_set_stroke_dash(scene_shape2, dashPattern, 4, 0.0f);
|
||||
tvg_shape_set_stroke_dash(scene_shape2, dashPattern, 4);
|
||||
tvg_shape_set_stroke_cap(scene_shape2, TVG_STROKE_CAP_ROUND);
|
||||
tvg_shape_set_stroke_color(scene_shape2, 0, 0, 255, 255);
|
||||
tvg_shape_set_stroke_width(scene_shape2, 15.0f);
|
||||
|
|
|
@ -56,7 +56,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto star1 = tvg::Shape::gen();
|
||||
tvgDrawStar(star1.get());
|
||||
star1->fill(255, 255, 0);
|
||||
star1->stroke(255 ,0, 0, 255);
|
||||
star1->stroke(255 ,0, 0);
|
||||
star1->stroke(10);
|
||||
|
||||
//Move Star1
|
||||
|
@ -72,7 +72,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto star2 = tvg::Shape::gen();
|
||||
tvgDrawStar(star2.get());
|
||||
star2->fill(0, 255, 255);
|
||||
star2->stroke(0 ,255, 0, 255);
|
||||
star2->stroke(0 ,255, 0);
|
||||
star2->stroke(10);
|
||||
star2->opacity(100);
|
||||
|
||||
|
@ -105,7 +105,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
fill->colorStops(colorStops, 2);
|
||||
star3->fill(std::move(fill));
|
||||
|
||||
star3->stroke(255 ,0, 0, 255);
|
||||
star3->stroke(255 ,0, 0);
|
||||
star3->stroke(10);
|
||||
star3->translate(400, 0);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
|
|||
shape->close();
|
||||
shape->fill(0, 0, 255);
|
||||
shape->stroke(3);
|
||||
shape->stroke(255, 255, 255, 255);
|
||||
shape->stroke(255, 255, 255);
|
||||
|
||||
//Transform Matrix
|
||||
tvg::Matrix m = {1, 0, 0, 0, 1, 0, 0, 0, 1};
|
||||
|
|
|
@ -51,7 +51,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
|
||||
//fill property will be retained
|
||||
shape->fill(127, 255, 255);
|
||||
shape->stroke(0, 0, 255, 255);
|
||||
shape->stroke(0, 0, 255);
|
||||
shape->stroke(1);
|
||||
|
||||
if (canvas->push(std::move(shape)) != tvg::Result::Success) return;
|
||||
|
@ -68,7 +68,7 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
|
|||
if (pShape->reset() == tvg::Result::Success) {
|
||||
pShape->appendRect(-100 + (800 * progress), -100 + (800 * progress), 200, 200, (100 * progress), (100 * progress));
|
||||
pShape->fill(127, 255, 255);
|
||||
pShape->stroke(0, 0, 255, 255);
|
||||
pShape->stroke(0, 0, 255);
|
||||
pShape->stroke(30 * progress);
|
||||
|
||||
//Update shape for drawing (this may work asynchronously)
|
||||
|
|
|
@ -39,7 +39,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape1->appendRect(220, 10, 100, 100);
|
||||
|
||||
shape1->stroke(3);
|
||||
shape1->stroke(0, 255, 0, 255);
|
||||
shape1->stroke(0, 255, 0);
|
||||
|
||||
float dashPattern[2] = {4, 4};
|
||||
shape1->stroke(dashPattern, 2);
|
||||
|
|
|
@ -60,7 +60,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape1->lineTo(100, 150);
|
||||
shape1->close();
|
||||
|
||||
shape1->stroke(0, 255, 0, 255);
|
||||
shape1->stroke(0, 255, 0);
|
||||
shape1->stroke(20);
|
||||
shape1->stroke(tvg::StrokeJoin::Miter);
|
||||
shape1->stroke(tvg::StrokeCap::Butt);
|
||||
|
|
|
@ -80,7 +80,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
star->lineTo(546, 143);
|
||||
star->close();
|
||||
star->stroke(10);
|
||||
star->stroke(255, 255, 255, 255);
|
||||
star->stroke(255, 255, 255);
|
||||
|
||||
//Mask3
|
||||
auto mask3 = tvg::Shape::gen();
|
||||
|
|
|
@ -80,7 +80,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
star->lineTo(546, 143);
|
||||
star->close();
|
||||
star->stroke(10);
|
||||
star->stroke(255, 255, 255, 255);
|
||||
star->stroke(255, 255, 255);
|
||||
|
||||
//Mask3
|
||||
auto mask3 = tvg::Shape::gen();
|
||||
|
|
|
@ -80,7 +80,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
star->lineTo(546, 143);
|
||||
star->close();
|
||||
star->stroke(10);
|
||||
star->stroke(255, 255, 255, 255);
|
||||
star->stroke(255, 255, 255);
|
||||
|
||||
//Mask3
|
||||
auto mask3 = tvg::Shape::gen();
|
||||
|
|
|
@ -81,7 +81,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
star->close();
|
||||
star->stroke(30);
|
||||
star->stroke(tvg::StrokeJoin::Miter);
|
||||
star->stroke(255, 255, 255, 255);
|
||||
star->stroke(255, 255, 255);
|
||||
|
||||
//Mask3
|
||||
auto mask3 = tvg::Shape::gen();
|
||||
|
|
|
@ -45,7 +45,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape2->appendRect(450, 100, 200, 200, 50, 50);
|
||||
shape2->fill(0, 255, 0);
|
||||
shape2->stroke(10);
|
||||
shape2->stroke(255, 255, 255, 255);
|
||||
shape2->stroke(255, 255, 255);
|
||||
scene->push(std::move(shape2));
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape3->close();
|
||||
shape3->fill(0, 0, 255);
|
||||
shape3->stroke(10);
|
||||
shape3->stroke(255, 255, 255, 255);
|
||||
shape3->stroke(255, 255, 255);
|
||||
shape3->opacity(127);
|
||||
|
||||
scene2->push(std::move(shape3));
|
||||
|
@ -96,7 +96,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape4->close();
|
||||
shape4->fill(255, 0, 0);
|
||||
shape4->stroke(10);
|
||||
shape4->stroke(0, 0, 255, 255);
|
||||
shape4->stroke(0, 0, 255);
|
||||
shape4->opacity(200);
|
||||
shape4->scale(3);
|
||||
scene2->push(std::move(shape4));
|
||||
|
|
|
@ -55,14 +55,14 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape4->appendCircle(400, 400, 100, 100);
|
||||
shape4->fill(255, 0, 0);
|
||||
shape4->stroke(5);
|
||||
shape4->stroke(255, 255, 255, 255);
|
||||
shape4->stroke(255, 255, 255);
|
||||
scene->push(std::move(shape4));
|
||||
|
||||
auto shape5 = tvg::Shape::gen();
|
||||
shape5->appendCircle(550, 550, 150, 150);
|
||||
shape5->fill(255, 0, 255);
|
||||
shape5->stroke(5);
|
||||
shape5->stroke(255, 255, 255, 255);
|
||||
shape5->stroke(255, 255, 255);
|
||||
scene->push(std::move(shape5));
|
||||
|
||||
if (canvas->push(std::move(scene)) != tvg::Result::Success) return;
|
||||
|
|
|
@ -51,7 +51,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape2->appendRect(450, 100, 200, 200, 50, 50);
|
||||
shape2->fill(0, 255, 0);
|
||||
shape2->stroke(10);
|
||||
shape2->stroke(255, 255, 255, 255);
|
||||
shape2->stroke(255, 255, 255);
|
||||
scene->push(std::move(shape2));
|
||||
|
||||
//Draw the Scene onto the Canvas
|
||||
|
@ -80,7 +80,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape3->close();
|
||||
shape3->fill(0, 0, 255);
|
||||
shape3->stroke(10);
|
||||
shape3->stroke(255, 255, 255, 255);
|
||||
shape3->stroke(255, 255, 255);
|
||||
shape3->opacity(127);
|
||||
|
||||
scene2->push(std::move(shape3));
|
||||
|
@ -102,7 +102,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape4->close();
|
||||
shape4->fill(255, 0, 0);
|
||||
shape4->stroke(10);
|
||||
shape4->stroke(0, 0, 255, 255);
|
||||
shape4->stroke(0, 0, 255);
|
||||
shape4->opacity(200);
|
||||
shape4->scale(3);
|
||||
scene2->push(std::move(shape4));
|
||||
|
|
|
@ -68,7 +68,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
//Source
|
||||
auto shape = tvg::Shape::gen();
|
||||
shape->appendRect(100, 100, 400, 400, 50, 50);
|
||||
shape->stroke(0, 0, 255, 255);
|
||||
shape->stroke(0, 0, 255);
|
||||
shape->stroke(10);
|
||||
shape->fill(255, 255, 255);
|
||||
shape->composite(std::move(clipper), tvg::CompositeMethod::ClipPath);
|
||||
|
|
|
@ -40,7 +40,7 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
|
|||
shape1->appendRect(-235, -250, 400, 400, 50, 50); //x, y, w, h, rx, ry
|
||||
shape1->fill(0, 255, 0); //r, g, b
|
||||
shape1->stroke(5); //width
|
||||
shape1->stroke(255, 255, 255, 255); //r, g, b, a
|
||||
shape1->stroke(255, 255, 255); //r, g, b
|
||||
scene->push(std::move(shape1));
|
||||
|
||||
//Prepare Circle (Scene1)
|
||||
|
@ -79,7 +79,7 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
|
|||
shape4->close();
|
||||
shape4->fill(0, 0, 255, 127);
|
||||
shape4->stroke(3); //width
|
||||
shape4->stroke(0, 0, 255, 255); //r, g, b, a
|
||||
shape4->stroke(0, 0, 255); //r, g, b
|
||||
scene2->push(std::move(shape4));
|
||||
|
||||
//Circle (Scene2)
|
||||
|
|
|
@ -34,7 +34,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto shape1 = tvg::Shape::gen();
|
||||
shape1->appendRect(50, 50, 200, 200);
|
||||
shape1->fill(50, 50, 50);
|
||||
shape1->stroke(255, 255, 255, 255); //color: r, g, b, a
|
||||
shape1->stroke(255, 255, 255); //color: r, g, b
|
||||
shape1->stroke(tvg::StrokeJoin::Bevel); //default is Bevel
|
||||
shape1->stroke(10); //width: 10px
|
||||
|
||||
|
@ -44,7 +44,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto shape2 = tvg::Shape::gen();
|
||||
shape2->appendRect(300, 50, 200, 200);
|
||||
shape2->fill(50, 50, 50);
|
||||
shape2->stroke(255, 255, 255, 255);
|
||||
shape2->stroke(255, 255, 255);
|
||||
shape2->stroke(tvg::StrokeJoin::Round);
|
||||
shape2->stroke(10);
|
||||
|
||||
|
@ -54,7 +54,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto shape3 = tvg::Shape::gen();
|
||||
shape3->appendRect(550, 50, 200, 200);
|
||||
shape3->fill(50, 50, 50);
|
||||
shape3->stroke(255, 255, 255, 255);
|
||||
shape3->stroke(255, 255, 255);
|
||||
shape3->stroke(tvg::StrokeJoin::Miter);
|
||||
shape3->stroke(10);
|
||||
|
||||
|
@ -64,7 +64,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto shape4 = tvg::Shape::gen();
|
||||
shape4->appendCircle(150, 400, 100, 100);
|
||||
shape4->fill(50, 50, 50);
|
||||
shape4->stroke(255, 255, 255, 255);
|
||||
shape4->stroke(255, 255, 255);
|
||||
shape4->stroke(1);
|
||||
|
||||
if (canvas->push(std::move(shape4)) != tvg::Result::Success) return;
|
||||
|
@ -73,7 +73,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto shape5 = tvg::Shape::gen();
|
||||
shape5->appendCircle(400, 400, 100, 100);
|
||||
shape5->fill(50, 50, 50);
|
||||
shape5->stroke(255, 255, 255, 255);
|
||||
shape5->stroke(255, 255, 255);
|
||||
shape5->stroke(2);
|
||||
|
||||
if (canvas->push(std::move(shape5)) != tvg::Result::Success) return;
|
||||
|
@ -82,7 +82,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto shape6 = tvg::Shape::gen();
|
||||
shape6->appendCircle(650, 400, 100, 100);
|
||||
shape6->fill(50, 50, 50);
|
||||
shape6->stroke(255, 255, 255, 255);
|
||||
shape6->stroke(255, 255, 255);
|
||||
shape6->stroke(4);
|
||||
|
||||
if (canvas->push(std::move(shape6)) != tvg::Result::Success) return;
|
||||
|
@ -92,7 +92,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto hline = tvg::Shape::gen();
|
||||
hline->moveTo(50, 550 + (25 * i));
|
||||
hline->lineTo(300, 550 + (25 * i));
|
||||
hline->stroke(255, 255, 255, 255); //color: r, g, b, a
|
||||
hline->stroke(255, 255, 255); //color: r, g, b
|
||||
hline->stroke(i + 1); //stroke width
|
||||
hline->stroke(tvg::StrokeCap::Round); //default is Square
|
||||
if (canvas->push(std::move(hline)) != tvg::Result::Success) return;
|
||||
|
@ -100,7 +100,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto vline = tvg::Shape::gen();
|
||||
vline->moveTo(500 + (25 * i), 550);
|
||||
vline->lineTo(500 + (25 * i), 780);
|
||||
vline->stroke(255, 255, 255, 255); //color: r, g, b, a
|
||||
vline->stroke(255, 255, 255); //color: r, g, b
|
||||
vline->stroke(i + 1); //stroke width
|
||||
vline->stroke(tvg::StrokeCap::Round); //default is Square
|
||||
if (canvas->push(std::move(vline)) != tvg::Result::Success) return;
|
||||
|
@ -110,7 +110,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
auto line1 = tvg::Shape::gen();
|
||||
line1->moveTo(360, 580);
|
||||
line1->lineTo(450, 580);
|
||||
line1->stroke(255, 255, 255, 255); //color: r, g, b, a
|
||||
line1->stroke(255, 255, 255); //color: r, g, b
|
||||
line1->stroke(15);
|
||||
line1->stroke(tvg::StrokeCap::Round);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape1->lineTo(220, 200);
|
||||
shape1->lineTo( 70, 170);
|
||||
shape1->lineTo( 70, 30);
|
||||
shape1->stroke(255, 0, 0, 255);
|
||||
shape1->stroke(255, 0, 0);
|
||||
shape1->stroke(10);
|
||||
shape1->stroke(tvg::StrokeJoin::Round);
|
||||
shape1->stroke(tvg::StrokeCap::Round);
|
||||
|
@ -49,7 +49,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape2->lineTo(470, 200);
|
||||
shape2->lineTo(320, 170);
|
||||
shape2->lineTo(320, 30);
|
||||
shape2->stroke(255, 255, 0, 255);
|
||||
shape2->stroke(255, 255, 0);
|
||||
shape2->stroke(10);
|
||||
shape2->stroke(tvg::StrokeJoin::Bevel);
|
||||
shape2->stroke(tvg::StrokeCap::Square);
|
||||
|
@ -61,7 +61,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape3->lineTo(720, 200);
|
||||
shape3->lineTo(570, 170);
|
||||
shape3->lineTo(570, 30);
|
||||
shape3->stroke(0, 255, 0, 255);
|
||||
shape3->stroke(0, 255, 0);
|
||||
shape3->stroke(10);
|
||||
shape3->stroke(tvg::StrokeJoin::Miter);
|
||||
shape3->stroke(tvg::StrokeCap::Butt);
|
||||
|
@ -74,7 +74,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape4->lineTo(220, 380);
|
||||
shape4->lineTo( 70, 330);
|
||||
shape4->lineTo( 70, 210);
|
||||
shape4->stroke(255, 0, 0, 255);
|
||||
shape4->stroke(255, 0, 0);
|
||||
shape4->stroke(5);
|
||||
shape4->stroke(tvg::StrokeJoin::Round);
|
||||
shape4->stroke(tvg::StrokeCap::Round);
|
||||
|
@ -89,7 +89,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape5->lineTo(470, 380);
|
||||
shape5->lineTo(320, 330);
|
||||
shape5->lineTo(320, 210);
|
||||
shape5->stroke(255, 255, 0, 255);
|
||||
shape5->stroke(255, 255, 0);
|
||||
shape5->stroke(5);
|
||||
shape5->stroke(tvg::StrokeJoin::Bevel);
|
||||
shape5->stroke(tvg::StrokeCap::Square);
|
||||
|
@ -104,7 +104,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape6->lineTo(720, 380);
|
||||
shape6->lineTo(570, 330);
|
||||
shape6->lineTo(570, 210);
|
||||
shape6->stroke(0, 255, 0, 255);
|
||||
shape6->stroke(0, 255, 0);
|
||||
shape6->stroke(5);
|
||||
shape6->stroke(tvg::StrokeJoin::Miter);
|
||||
shape6->stroke(tvg::StrokeCap::Butt);
|
||||
|
@ -116,7 +116,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
//For a comparison with shapes 10-12
|
||||
auto shape7 = tvg::Shape::gen();
|
||||
shape7->appendArc(70, 400, 160, 10, 70, true);
|
||||
shape7->stroke(255, 0, 0, 255);
|
||||
shape7->stroke(255, 0, 0);
|
||||
shape7->stroke(7);
|
||||
shape7->stroke(tvg::StrokeJoin::Round);
|
||||
shape7->stroke(tvg::StrokeCap::Round);
|
||||
|
@ -124,7 +124,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
|
||||
auto shape8 = tvg::Shape::gen();
|
||||
shape8->appendArc(320, 400, 160, 10, 70, false);
|
||||
shape8->stroke(255, 255, 0, 255);
|
||||
shape8->stroke(255, 255, 0);
|
||||
shape8->stroke(7);
|
||||
shape8->stroke(tvg::StrokeJoin::Bevel);
|
||||
shape8->stroke(tvg::StrokeCap::Square);
|
||||
|
@ -132,7 +132,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
|
||||
auto shape9 = tvg::Shape::gen();
|
||||
shape9->appendArc(570, 400, 160, 10, 70, true);
|
||||
shape9->stroke(0, 255, 0, 255);
|
||||
shape9->stroke(0, 255, 0);
|
||||
shape9->stroke(7);
|
||||
shape9->stroke(tvg::StrokeJoin::Miter);
|
||||
shape9->stroke(tvg::StrokeCap::Butt);
|
||||
|
@ -143,7 +143,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape10->appendArc(70, 600, 160, 10, 30, true);
|
||||
shape10->appendCircle(70, 700, 20, 60);
|
||||
shape10->appendRect(130, 710, 100, 40);
|
||||
shape10->stroke(255, 0, 0, 255);
|
||||
shape10->stroke(255, 0, 0);
|
||||
shape10->stroke(5);
|
||||
shape10->stroke(tvg::StrokeJoin::Round);
|
||||
shape10->stroke(tvg::StrokeCap::Round);
|
||||
|
@ -154,7 +154,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape11->appendArc(320, 600, 160, 10, 30, false);
|
||||
shape11->appendCircle(320, 700, 20, 60);
|
||||
shape11->appendRect(380, 710, 100, 40);
|
||||
shape11->stroke(255, 255, 0, 255);
|
||||
shape11->stroke(255, 255, 0);
|
||||
shape11->stroke(5);
|
||||
shape11->stroke(tvg::StrokeJoin::Bevel);
|
||||
shape11->stroke(tvg::StrokeCap::Square);
|
||||
|
@ -165,7 +165,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape12->appendArc(570, 600, 160, 10, 30, true);
|
||||
shape12->appendCircle(570, 700, 20, 60);
|
||||
shape12->appendRect(630, 710, 100, 40);
|
||||
shape12->stroke(0, 255, 0, 255);
|
||||
shape12->stroke(0, 255, 0);
|
||||
shape12->stroke(5);
|
||||
shape12->stroke(tvg::StrokeJoin::Miter);
|
||||
shape12->stroke(tvg::StrokeCap::Butt);
|
||||
|
|
|
@ -53,9 +53,9 @@ void goWild(tvg::Canvas* canvas)
|
|||
path->lineTo(460, top / 2);
|
||||
path->close();
|
||||
|
||||
path->fill(150, 150, 255); // fill color
|
||||
path->stroke(20); // stroke width
|
||||
path->stroke(120, 120, 255, 255); // stroke color
|
||||
path->fill(150, 150, 255); // fill color
|
||||
path->stroke(20); // stroke width
|
||||
path->stroke(120, 120, 255); // stroke color
|
||||
|
||||
// path->stroke(tvg::StrokeJoin::Round);
|
||||
// path->stroke(tvg::StrokeJoin::Bevel);
|
||||
|
|
|
@ -340,24 +340,15 @@ const Fill* Shape::strokeFill() const noexcept
|
|||
}
|
||||
|
||||
|
||||
Result Shape::stroke(const float* dashPattern, uint32_t cnt, float offset) noexcept
|
||||
Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept
|
||||
{
|
||||
if ((cnt == 1) || (!dashPattern && cnt > 0) || (dashPattern && cnt == 0)) {
|
||||
return Result::InvalidArguments;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < cnt; i++)
|
||||
if (dashPattern[i] < FLT_EPSILON) return Result::InvalidArguments;
|
||||
|
||||
if (!pImpl->strokeDash(dashPattern, cnt, offset)) return Result::FailedAllocation;
|
||||
|
||||
return Result::Success;
|
||||
return pImpl->strokeDash(dashPattern, cnt, 0);
|
||||
}
|
||||
|
||||
|
||||
uint32_t Shape::strokeDash(const float** dashPattern, float* offset) const noexcept
|
||||
uint32_t Shape::strokeDash(const float** dashPattern) const noexcept
|
||||
{
|
||||
return pImpl->rs.strokeDash(dashPattern, offset);
|
||||
return pImpl->rs.strokeDash(dashPattern, nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -269,8 +269,16 @@ struct Shape::Impl
|
|||
return Result::Success;
|
||||
}
|
||||
|
||||
bool strokeDash(const float* pattern, uint32_t cnt, float offset)
|
||||
Result strokeDash(const float* pattern, uint32_t cnt, float offset)
|
||||
{
|
||||
if ((cnt == 1) || (!pattern && cnt > 0) || (pattern && cnt == 0)) {
|
||||
return Result::InvalidArguments;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < cnt; i++) {
|
||||
if (pattern[i] < FLT_EPSILON) return Result::InvalidArguments;
|
||||
}
|
||||
|
||||
//Reset dash
|
||||
if (!pattern && cnt == 0) {
|
||||
free(rs.stroke->dashPattern);
|
||||
|
@ -283,7 +291,7 @@ struct Shape::Impl
|
|||
}
|
||||
if (!rs.stroke->dashPattern) {
|
||||
rs.stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * cnt));
|
||||
if (!rs.stroke->dashPattern) return false;
|
||||
if (!rs.stroke->dashPattern) return Result::FailedAllocation;
|
||||
}
|
||||
for (uint32_t i = 0; i < cnt; ++i) {
|
||||
rs.stroke->dashPattern[i] = pattern[i];
|
||||
|
@ -293,7 +301,7 @@ struct Shape::Impl
|
|||
rs.stroke->dashOffset = offset;
|
||||
flag |= RenderUpdateFlag::Stroke;
|
||||
|
||||
return true;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
bool strokeFirst()
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "tvgMath.h" /* to include math.h before cstring */
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include "tvgShapeImpl.h"
|
||||
#include "tvgCompressor.h"
|
||||
#include "tvgPaint.h"
|
||||
#include "tvgSvgLoaderCommon.h"
|
||||
|
@ -349,7 +350,7 @@ static void _applyProperty(SvgLoaderData& loaderData, SvgNode* node, Shape* vg,
|
|||
vg->stroke(style->stroke.join);
|
||||
vg->strokeMiterlimit(style->stroke.miterlimit);
|
||||
if (style->stroke.dash.array.count > 0) {
|
||||
vg->stroke(style->stroke.dash.array.data, style->stroke.dash.array.count, style->stroke.dash.offset);
|
||||
P(vg)->strokeDash(style->stroke.dash.array.data, style->stroke.dash.array.count, style->stroke.dash.offset);
|
||||
}
|
||||
|
||||
//If stroke property is nullptr then do nothing
|
||||
|
@ -789,7 +790,7 @@ static unique_ptr<Scene> _sceneBuildHelper(SvgLoaderData& loaderData, const SvgN
|
|||
uint8_t r, g, b;
|
||||
shape->fillColor(&r, &g, &b);
|
||||
if (shape->fill() || r < 255 || g < 255 || b < 255 || shape->strokeFill() ||
|
||||
(shape->strokeColor(&r, &g, &b, nullptr) == Result::Success && (r < 255 || g < 255 || b < 255))) {
|
||||
(shape->strokeColor(&r, &g, &b) == Result::Success && (r < 255 || g < 255 || b < 255))) {
|
||||
*isMaskWhite = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,15 +189,13 @@ TEST_CASE("Stroke dash", "[capiStrokeDash]")
|
|||
float dash[2] = {20, 10};
|
||||
float* dash_get;
|
||||
uint32_t cnt;
|
||||
float offset;
|
||||
|
||||
REQUIRE(tvg_shape_set_stroke_dash(paint, dash, 2, 4.5f) == TVG_RESULT_SUCCESS);
|
||||
REQUIRE(tvg_shape_get_stroke_dash(paint, (const float**) &dash_get, &cnt, &offset) == TVG_RESULT_SUCCESS);
|
||||
REQUIRE(tvg_shape_set_stroke_dash(paint, dash, 2) == TVG_RESULT_SUCCESS);
|
||||
REQUIRE(tvg_shape_get_stroke_dash(paint, (const float**) &dash_get, &cnt) == TVG_RESULT_SUCCESS);
|
||||
REQUIRE(cnt == 2);
|
||||
for (uint32_t i = 0; i < cnt; i++) {
|
||||
REQUIRE(dash_get[i] == dash[i]);
|
||||
}
|
||||
REQUIRE(offset == 4.5f);
|
||||
|
||||
REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -169,17 +169,13 @@ TEST_CASE("Stroking", "[tvgShape]")
|
|||
|
||||
float dashPattern2[3] = {1.0f, 1.5f, 2.22f};
|
||||
REQUIRE(shape->stroke(dashPattern2, 3) == Result::Success);
|
||||
REQUIRE(shape->stroke(dashPattern2, 3, 4.5) == Result::Success);
|
||||
|
||||
const float* dashPattern3;
|
||||
float offset;
|
||||
REQUIRE(shape->strokeDash(nullptr) == 3);
|
||||
REQUIRE(shape->strokeDash(&dashPattern3) == 3);
|
||||
REQUIRE(shape->strokeDash(&dashPattern3, &offset) == 3);
|
||||
REQUIRE(dashPattern3[0] == 1.0f);
|
||||
REQUIRE(dashPattern3[1] == 1.5f);
|
||||
REQUIRE(dashPattern3[2] == 2.22f);
|
||||
REQUIRE(offset == 4.5f);
|
||||
|
||||
REQUIRE(shape->stroke(nullptr, 0) == Result::Success);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue