From 19999e7abd146b864e590cd1c4054c13f60fa439 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 22 May 2020 16:18:32 +0900 Subject: [PATCH] common stroke: implement stroke interfaces. Change-Id: I28fe5d5df4cde6640b143e67e241c6afc9c6b1fe --- inc/tizenvg.h | 8 +++++ src/lib/tvgRenderCommon.h | 2 +- src/lib/tvgShape.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++ src/lib/tvgShapeImpl.h | 61 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 1 deletion(-) diff --git a/inc/tizenvg.h b/inc/tizenvg.h index 98b6faf..bfaa960 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -136,6 +136,10 @@ public: int appendCircle(float cx, float cy, float radiusW, float radiusH) noexcept; int appendPath(const PathCommand* cmds, size_t cmdCnt, const Point* pts, size_t ptsCnt) noexcept; + int stroke(size_t width) noexcept; + int stroke(size_t r, size_t g, size_t b, size_t a) noexcept; + int stroke(const size_t* dashPattern, size_t cnt) noexcept; + int fill(size_t r, size_t g, size_t b, size_t a) noexcept; int rotate(float degree) noexcept override; @@ -145,6 +149,10 @@ public: size_t pathCommands(const PathCommand** cmds) const noexcept; size_t pathCoords(const Point** pts) const noexcept; int fill(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept; + size_t stroke() const noexcept; + int stroke(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept; + size_t stroke(const size_t** dashPattern) const noexcept; + int bounds(float&x, float& y, float& w, float& h) const noexcept override; static std::unique_ptr gen() noexcept; diff --git a/src/lib/tvgRenderCommon.h b/src/lib/tvgRenderCommon.h index f40639d..61cd655 100644 --- a/src/lib/tvgRenderCommon.h +++ b/src/lib/tvgRenderCommon.h @@ -28,7 +28,7 @@ struct Surface size_t w, h; }; -enum RenderUpdateFlag {None = 0, Path = 1, Fill = 2, Transform = 4, All = 8}; +enum RenderUpdateFlag {None = 0, Path = 1, Fill = 2, Stroke = 4, Transform = 8, All = 16}; struct RenderTransform { diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index 432a8a6..342f456 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -280,4 +280,79 @@ int Shape::bounds(float& x, float& y, float& w, float& h) const noexcept } +int Shape::stroke(size_t width) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + if (!impl->strokeWidth(width)) return -1; + + return 0; +} + + +size_t Shape::stroke() const noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + if (!impl->stroke) return -1; + return impl->stroke->width; +} + + +int Shape::stroke(size_t r, size_t g, size_t b, size_t a) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + if (!impl->strokeColor(r, g, b, a)) return -1; + + return 0; +} + + +int Shape::stroke(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + if (!impl->stroke) return -1; + + if (r) *r = impl->stroke->color[0]; + if (g) *g = impl->stroke->color[1]; + if (b) *b = impl->stroke->color[2]; + if (a) *a = impl->stroke->color[3]; + + return 0; +} + + +int Shape::stroke(const size_t* dashPattern, size_t cnt) noexcept +{ + if (cnt < 2 || !dashPattern) return -1; + + auto impl = pImpl.get(); + assert(impl); + + if (!impl->strokeDash(dashPattern, cnt)) return -1; + + return 0; +} + + +size_t Shape::stroke(const size_t** dashPattern) const noexcept +{ + assert(dashPattern); + + auto impl = pImpl.get(); + assert(impl); + + if (!impl->stroke) return 0; + + *dashPattern = impl->stroke->dashPattern; + return impl->stroke->dashCnt; +} + + #endif //_TVG_SHAPE_CPP_ diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index b7f9927..e2ba294 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -30,6 +30,15 @@ struct ShapeFill struct ShapeStroke { + size_t width = 0; + size_t color[4] = {0, 0, 0, 0}; + size_t* dashPattern = nullptr; + size_t dashCnt = 0; + + ~ShapeStroke() + { + if (dashPattern) free(dashPattern); + } }; @@ -141,6 +150,58 @@ struct Shape::Impl return 0; } + + bool strokeWidth(size_t width) + { + //TODO: Size Exception? + + if (!stroke) stroke = new ShapeStroke(); + assert(stroke); + + stroke->width = width; + flag |= RenderUpdateFlag::Stroke; + + return 0; + } + + bool strokeColor(size_t r, size_t g, size_t b, size_t a) + { + if (!stroke) stroke = new ShapeStroke(); + assert(stroke); + + stroke->color[0] = r; + stroke->color[1] = g; + stroke->color[2] = b; + stroke->color[3] = a; + + flag |= RenderUpdateFlag::Stroke; + + return 0; + } + + bool strokeDash(const size_t* pattern, size_t cnt) + { + assert(pattern); + + if (!stroke) stroke = new ShapeStroke(); + assert(stroke); + + if (stroke->dashCnt != cnt) { + if (stroke->dashPattern) free(stroke->dashPattern); + stroke->dashPattern = nullptr; + } + + if (!stroke->dashPattern) stroke->dashPattern = static_cast(malloc(sizeof(size_t) * cnt)); + assert(stroke->dashPattern); + + memcpy(stroke->dashPattern, pattern, cnt); + stroke->dashCnt = cnt; + + flag |= RenderUpdateFlag::Stroke; + + return 0; + + } }; #endif //_TVG_SHAPE_IMPL_H_ \ No newline at end of file -- 2.7.4