mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 11:36:25 +00:00
common shape: allow to reset stroke dash.
user may need to reset stroke dash to off, now stroke api allows it.
This commit is contained in:
parent
97302d2983
commit
2fd830c940
3 changed files with 24 additions and 17 deletions
|
@ -799,10 +799,11 @@ public:
|
||||||
*
|
*
|
||||||
* @retval Result::Success When succeed.
|
* @retval Result::Success When succeed.
|
||||||
* @retval Result::FailedAllocation An internal error with a memory allocation for an object to be dashed.
|
* @retval Result::FailedAllocation An internal error with a memory allocation for an object to be dashed.
|
||||||
* @retval Result::InvalidArguments In case a @c nullptr is passed as the @p dashPattern,
|
* @retval Result::InvalidArguments In case that either @p dashPattern is @c nullptr or @p cnt is zero.
|
||||||
* the given length of the array is less than two or any of the @p dashPattern values is zero or less.
|
|
||||||
*
|
*
|
||||||
* @note If any of the dash pattern values is zero, this function has no effect.
|
* @note If any of the dash pattern values is zero, this function has no effect.
|
||||||
|
* @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) noexcept;
|
Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
|
||||||
|
|
||||||
|
|
|
@ -358,7 +358,9 @@ const Fill* Shape::strokeFill() const noexcept
|
||||||
|
|
||||||
Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept
|
Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept
|
||||||
{
|
{
|
||||||
if (cnt < 2 || !dashPattern) return Result::InvalidArguments;
|
if ((cnt == 1) || (!dashPattern && cnt > 0) || (dashPattern && cnt == 0)) {
|
||||||
|
return Result::InvalidArguments;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < cnt; i++)
|
for (uint32_t i = 0; i < cnt; i++)
|
||||||
if (dashPattern[i] < FLT_EPSILON) return Result::InvalidArguments;
|
if (dashPattern[i] < FLT_EPSILON) return Result::InvalidArguments;
|
||||||
|
|
|
@ -330,22 +330,26 @@ struct Shape::Impl
|
||||||
|
|
||||||
bool strokeDash(const float* pattern, uint32_t cnt)
|
bool strokeDash(const float* pattern, uint32_t cnt)
|
||||||
{
|
{
|
||||||
if (!stroke) stroke = new ShapeStroke();
|
//Reset dash
|
||||||
if (!stroke) return false;
|
if (!pattern && cnt == 0) {
|
||||||
|
free(stroke->dashPattern);
|
||||||
if (stroke->dashCnt != cnt) {
|
|
||||||
if (stroke->dashPattern) free(stroke->dashPattern);
|
|
||||||
stroke->dashPattern = nullptr;
|
stroke->dashPattern = nullptr;
|
||||||
|
} else {
|
||||||
|
if (!stroke) stroke = new ShapeStroke();
|
||||||
|
if (!stroke) return false;
|
||||||
|
|
||||||
|
if (stroke->dashCnt != cnt) {
|
||||||
|
free(stroke->dashPattern);
|
||||||
|
stroke->dashPattern = nullptr;
|
||||||
|
}
|
||||||
|
if (!stroke->dashPattern) {
|
||||||
|
stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * cnt));
|
||||||
|
if (!stroke->dashPattern) return false;
|
||||||
|
}
|
||||||
|
for (uint32_t i = 0; i < cnt; ++i) {
|
||||||
|
stroke->dashPattern[i] = pattern[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stroke->dashPattern) {
|
|
||||||
stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * cnt));
|
|
||||||
if (!stroke->dashPattern) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < cnt; ++i)
|
|
||||||
stroke->dashPattern[i] = pattern[i];
|
|
||||||
|
|
||||||
stroke->dashCnt = cnt;
|
stroke->dashCnt = cnt;
|
||||||
flag |= RenderUpdateFlag::Stroke;
|
flag |= RenderUpdateFlag::Stroke;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue