updated copyright.
[platform/core/graphics/tizenvg.git] / src / lib / sw_engine / tvgSwShape.cpp
index 49bcd12..82d812e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2020 - 2023 the ThorVG project. All rights reserved.
 
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
+
 #include "tvgSwCommon.h"
+#include "tvgBezier.h"
+#include <float.h>
+#include <math.h>
 
 /************************************************************************/
 /* Internal Class Implementation                                        */
@@ -32,17 +36,6 @@ struct Line
 };
 
 
-static SwPoint _transform(const Point* to, const Matrix* transform)
-{
-    if (!transform) return {TO_SWCOORD(to->x), TO_SWCOORD(to->y)};
-
-    auto tx = round(to->x * transform->e11 + to->y * transform->e12 + transform->e13);
-    auto ty = round(to->x * transform->e21 + to->y * transform->e22 + transform->e23);
-
-    return {TO_SWCOORD(tx), TO_SWCOORD(ty)};
-}
-
-
 static float _lineLength(const Point& pt1, const Point& pt2)
 {
     /* approximate sqrt(x*x + y*y) using alpha max plus beta min algorithm.
@@ -68,41 +61,46 @@ static void _lineSplitAt(const Line& cur, float at, Line& left, Line& right)
 }
 
 
-static void _growOutlineContour(SwOutline& outline, uint32_t n)
+static bool _growOutlineContour(SwOutline& outline, uint32_t n)
 {
-    if (outline.reservedCntrsCnt >= outline.cntrsCnt + n) return;
+    if (outline.reservedCntrsCnt >= outline.cntrsCnt + n) return false;
     outline.reservedCntrsCnt = outline.cntrsCnt + n;
     outline.cntrs = static_cast<uint32_t*>(realloc(outline.cntrs, outline.reservedCntrsCnt * sizeof(uint32_t)));
+    return true;
 }
 
 
-static void _growOutlinePoint(SwOutline& outline, uint32_t n)
+static void _reserveOutlineClose(SwOutline& outline)
 {
-    if (outline.reservedPtsCnt >= outline.ptsCnt + n) return;
-    outline.reservedPtsCnt = outline.ptsCnt + n;
-    outline.pts = static_cast<SwPoint*>(realloc(outline.pts, outline.reservedPtsCnt * sizeof(SwPoint)));
-    outline.types = static_cast<uint8_t*>(realloc(outline.types, outline.reservedPtsCnt * sizeof(uint8_t)));
+    //Dash outlines are always opened.
+    //Only normal outlines use this information, it sholud be same to their contour counts.
+    if (outline.closed) free(outline.closed);
+    outline.closed = static_cast<bool*>(calloc(outline.reservedCntrsCnt, sizeof(bool)));
 }
 
 
-static void _delOutline(SwOutline* outline)
+static void _resetOutlineClose(SwOutline& outline)
 {
-    if (!outline) return;
+    memset(outline.closed, 0x0, outline.reservedCntrsCnt * sizeof(bool));
+}
+
 
-    if (outline->cntrs) free(outline->cntrs);
-    if (outline->pts) free(outline->pts);
-    if (outline->types) free(outline->types);
-    free(outline);
+static void _growOutlinePoint(SwOutline& outline, uint32_t n)
+{
+    if (outline.reservedPtsCnt >= outline.ptsCnt + n) return;
+    outline.reservedPtsCnt = outline.ptsCnt + n;
+    outline.pts = static_cast<SwPoint*>(realloc(outline.pts, outline.reservedPtsCnt * sizeof(SwPoint)));
+    outline.types = static_cast<uint8_t*>(realloc(outline.types, outline.reservedPtsCnt * sizeof(uint8_t)));
 }
 
 
 static void _outlineEnd(SwOutline& outline)
 {
+    if (outline.ptsCnt == 0) return;
+
     _growOutlineContour(outline, 1);
-    if (outline.ptsCnt > 0) {
-        outline.cntrs[outline.cntrsCnt] = outline.ptsCnt - 1;
-        ++outline.cntrsCnt;
-    }
+    outline.cntrs[outline.cntrsCnt] = outline.ptsCnt - 1;
+    ++outline.cntrsCnt;
 }
 
 
@@ -110,8 +108,7 @@ static void _outlineMoveTo(SwOutline& outline, const Point* to, const Matrix* tr
 {
     _growOutlinePoint(outline, 1);
 
-    outline.pts[outline.ptsCnt] = _transform(to, transform);
-
+    outline.pts[outline.ptsCnt] = mathTransform(to, transform);
     outline.types[outline.ptsCnt] = SW_CURVE_TYPE_POINT;
 
     if (outline.ptsCnt > 0) {
@@ -128,7 +125,7 @@ static void _outlineLineTo(SwOutline& outline, const Point* to, const Matrix* tr
 {
     _growOutlinePoint(outline, 1);
 
-    outline.pts[outline.ptsCnt] = _transform(to, transform);
+    outline.pts[outline.ptsCnt] = mathTransform(to, transform);
     outline.types[outline.ptsCnt] = SW_CURVE_TYPE_POINT;
     ++outline.ptsCnt;
 }
@@ -138,15 +135,15 @@ static void _outlineCubicTo(SwOutline& outline, const Point* ctrl1, const Point*
 {
     _growOutlinePoint(outline, 3);
 
-    outline.pts[outline.ptsCnt] = _transform(ctrl1, transform);
+    outline.pts[outline.ptsCnt] = mathTransform(ctrl1, transform);
     outline.types[outline.ptsCnt] = SW_CURVE_TYPE_CUBIC;
     ++outline.ptsCnt;
 
-    outline.pts[outline.ptsCnt] = _transform(ctrl2, transform);
+    outline.pts[outline.ptsCnt] = mathTransform(ctrl2, transform);
     outline.types[outline.ptsCnt] = SW_CURVE_TYPE_CUBIC;
     ++outline.ptsCnt;
 
-    outline.pts[outline.ptsCnt] = _transform(to, transform);
+    outline.pts[outline.ptsCnt] = mathTransform(to, transform);
     outline.types[outline.ptsCnt] = SW_CURVE_TYPE_POINT;
     ++outline.ptsCnt;
 }
@@ -163,10 +160,7 @@ static void _outlineClose(SwOutline& outline)
     }
 
     //Make sure there is at least one point in the current path
-    if (outline.ptsCnt == i) {
-        outline.opened = true;
-        return;
-    }
+    if (outline.ptsCnt == i) return;
 
     //Close the path
     _growOutlinePoint(outline, 1);
@@ -174,61 +168,7 @@ static void _outlineClose(SwOutline& outline)
     outline.pts[outline.ptsCnt] = outline.pts[i];
     outline.types[outline.ptsCnt] = SW_CURVE_TYPE_POINT;
     ++outline.ptsCnt;
-
-    outline.opened = false;
-}
-
-
-static void _initBBox(SwBBox& bbox)
-{
-    bbox.min.x = bbox.min.y = 0;
-    bbox.max.x = bbox.max.y = 0;
-}
-
-
-static bool _updateBBox(SwOutline* outline, SwBBox& bbox)
-{
-    if (!outline) return false;
-
-    auto pt = outline->pts;
-
-    if (outline->ptsCnt <= 0) {
-        _initBBox(bbox);
-        return false;
-    }
-
-    auto xMin = pt->x;
-    auto xMax = pt->x;
-    auto yMin = pt->y;
-    auto yMax = pt->y;
-
-    ++pt;
-
-    for(uint32_t i = 1; i < outline->ptsCnt; ++i, ++pt) {
-        if (xMin > pt->x) xMin = pt->x;
-        if (xMax < pt->x) xMax = pt->x;
-        if (yMin > pt->y) yMin = pt->y;
-        if (yMax < pt->y) yMax = pt->y;
-    }
-    bbox.min.x = xMin >> 6;
-    bbox.max.x = (xMax + 63) >> 6;
-    bbox.min.y = yMin >> 6;
-    bbox.max.y = (yMax + 63) >> 6;
-
-    if (xMax - xMin < 1 && yMax - yMin < 1) return false;
-
-    return true;
-}
-
-
-static bool _checkValid(const SwOutline* outline, const SwBBox& bbox, const SwSize& clip)
-{
-    if (outline->ptsCnt == 0 || outline->cntrsCnt <= 0) return false;
-
-    //Check boundary
-    if (bbox.min.x >= clip.w || bbox.min.y >= clip.h || bbox.max.x <= 0 || bbox.max.y <= 0) return false;
-
-    return true;
+    outline.closed[outline.cntrsCnt] = true;
 }
 
 
@@ -267,7 +207,7 @@ static void _dashLineTo(SwDashStroke& dash, const Point* to, const Matrix* trans
             _outlineMoveTo(*dash.outline, &cur.pt1, transform);
             _outlineLineTo(*dash.outline, &cur.pt2, transform);
         }
-        if (dash.curLen < 1) {
+        if (dash.curLen < 1 && TO_SWCOORD(len) > 1) {
             //move to next dash
             dash.curIdx = (dash.curIdx + 1) % dash.cnt;
             dash.curLen = dash.pattern[dash.curIdx];
@@ -283,7 +223,7 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
     _growOutlinePoint(*dash.outline, dash.outline->ptsCnt >> 1);
     _growOutlineContour(*dash.outline, dash.outline->cntrsCnt >> 1);
 
-    Bezier cur = { dash.ptCur, *ctrl1, *ctrl2, *to};
+    Bezier cur = {dash.ptCur, *ctrl1, *ctrl2, *to};
     auto len = bezLength(cur);
 
     if (len < dash.curLen) {
@@ -297,11 +237,14 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
             Bezier left, right;
             len -= dash.curLen;
             bezSplitAt(cur, dash.curLen, left, right);
-            dash.curIdx = (dash.curIdx + 1) % dash.cnt;
             if (!dash.curOpGap) {
-                _outlineMoveTo(*dash.outline, &left.start, transform);
+                // leftovers from a previous command don't require moveTo
+                if (dash.pattern[dash.curIdx] - dash.curLen < FLT_EPSILON) {
+                    _outlineMoveTo(*dash.outline, &left.start, transform);
+                }
                 _outlineCubicTo(*dash.outline, &left.ctrl1, &left.ctrl2, &left.end, transform);
             }
+            dash.curIdx = (dash.curIdx + 1) % dash.cnt;
             dash.curLen = dash.pattern[dash.curIdx];
             dash.curOpGap = !dash.curOpGap;
             cur = right;
@@ -313,7 +256,7 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
             _outlineMoveTo(*dash.outline, &cur.start, transform);
             _outlineCubicTo(*dash.outline, &cur.ctrl1, &cur.ctrl2, &cur.end, transform);
         }
-        if (dash.curLen < 1) {
+        if (dash.curLen < 1 && TO_SWCOORD(len) > 1) {
             //move to next dash
             dash.curIdx = (dash.curIdx + 1) % dash.cnt;
             dash.curLen = dash.pattern[dash.curIdx];
@@ -324,7 +267,7 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
 }
 
 
-SwOutline* _genDashOutline(const Shape* sdata, const Matrix* transform)
+static SwOutline* _genDashOutline(const Shape* sdata, const Matrix* transform)
 {
     const PathCommand* cmds = nullptr;
     auto cmdCnt = sdata->pathCommands(&cmds);
@@ -346,17 +289,16 @@ SwOutline* _genDashOutline(const Shape* sdata, const Matrix* transform)
     dash.cnt = sdata->strokeDash(&pattern);
     if (dash.cnt == 0) return nullptr;
 
-    //Is it safe to mutual exclusive?
+    //OPTMIZE ME: Use mempool???
     dash.pattern = const_cast<float*>(pattern);
     dash.outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
-    dash.outline->opened = true;
 
     //smart reservation
     auto outlinePtsCnt = 0;
     auto outlineCntrsCnt = 0;
 
     for (uint32_t i = 0; i < cmdCnt; ++i) {
-        switch(*(cmds + i)) {
+        switch (*(cmds + i)) {
             case PathCommand::Close: {
                 ++outlinePtsCnt;
                 break;
@@ -380,12 +322,12 @@ SwOutline* _genDashOutline(const Shape* sdata, const Matrix* transform)
     ++outlinePtsCnt;    //for close
     ++outlineCntrsCnt;  //for end
 
-    //Reserve Approximitely 20x...
+    //No idea exact count.... Reserve Approximitely 20x...
     _growOutlinePoint(*dash.outline, outlinePtsCnt * 20);
     _growOutlineContour(*dash.outline, outlineCntrsCnt * 20);
 
     while (cmdCnt-- > 0) {
-        switch(*cmds) {
+        switch (*cmds) {
             case PathCommand::Close: {
                 _dashLineTo(dash, &dash.ptStart, transform);
                 break;
@@ -419,9 +361,9 @@ SwOutline* _genDashOutline(const Shape* sdata, const Matrix* transform)
 }
 
 
-bool _fastTrack(const SwOutline* outline)
+static bool _axisAlignedRect(const SwOutline* outline)
 {
-    //Fast Track: Othogonal rectangle?
+    //Fast Track: axis-aligned rectangle?
     if (outline->ptsCnt != 5) return false;
 
     auto pt1 = outline->pts + 0;
@@ -429,68 +371,17 @@ bool _fastTrack(const SwOutline* outline)
     auto pt3 = outline->pts + 2;
     auto pt4 = outline->pts + 3;
 
-    auto min1 = pt1->y < pt3->y ? pt1 : pt3;
-    auto min2 = pt2->y < pt4->y ? pt2 : pt4;
-    if (min1->y != min2->y) return false;
+    auto a = SwPoint{pt1->x, pt3->y};
+    auto b = SwPoint{pt3->x, pt1->y};
 
-    SwCoord len1 = pow(pt1->x - pt3->x, 2) + pow(pt1->y - pt3->y, 2);
-    SwCoord len2 = pow(pt2->x - pt4->x, 2) + pow(pt2->y - pt4->y, 2);
-    if (len1 == len2) return true;
+    if ((*pt2 == a && *pt4 == b) || (*pt2 == b && *pt4 == a)) return true;
 
     return false;
 }
 
 
-/************************************************************************/
-/* External Class Implementation                                        */
-/************************************************************************/
-
-bool shapePrepare(SwShape* shape, const Shape* sdata, const SwSize& clip, const Matrix* transform)
-{
-    if (!shapeGenOutline(shape, sdata, transform)) return false;
-
-    if (!_updateBBox(shape->outline, shape->bbox)) return false;
-
-    if (!_checkValid(shape->outline, shape->bbox, clip)) return false;
-
-    return true;
-}
-
-
-bool shapeGenRle(SwShape* shape, TVG_UNUSED const Shape* sdata, const SwSize& clip, bool antiAlias)
-{
-    //FIXME: Should we draw it?
-    //Case: Stroke Line
-    //if (shape.outline->opened) return true;
-
-    //Case A: Fast Track Rectangle Drawing
-    if ((shape->rect = _fastTrack(shape->outline))) return true;
-    //Case B: Normale Shape RLE Drawing
-    if ((shape->rle = rleRender(shape->outline, shape->bbox, clip, antiAlias))) return true;
-
-    return false;
-}
-
 
-void shapeDelOutline(SwShape* shape)
-{
-    auto outline = shape->outline;
-    _delOutline(outline);
-    shape->outline = nullptr;
-}
-
-
-void shapeReset(SwShape* shape)
-{
-    shapeDelOutline(shape);
-    rleFree(shape->rle);
-    shape->rle = nullptr;
-    shape->rect = false;
-    _initBBox(shape->bbox);
-}
-
-
-bool shapeGenOutline(SwShape* shape, const Shape* sdata, const Matrix* transform)
+static bool _genOutline(SwShape* shape, const Shape* sdata, const Matrix* transform, SwMpool* mpool, unsigned tid, bool hasComposite)
 {
     const PathCommand* cmds = nullptr;
     auto cmdCnt = sdata->pathCommands(&cmds);
@@ -504,11 +395,13 @@ bool shapeGenOutline(SwShape* shape, const Shape* sdata, const Matrix* transform
     //smart reservation
     auto outlinePtsCnt = 0;
     auto outlineCntrsCnt = 0;
+    auto closeCnt = 0;
 
     for (uint32_t i = 0; i < cmdCnt; ++i) {
-        switch(*(cmds + i)) {
+        switch (*(cmds + i)) {
             case PathCommand::Close: {
                 ++outlinePtsCnt;
+                ++closeCnt;
                 break;
             }
             case PathCommand::MoveTo: {
@@ -527,24 +420,30 @@ bool shapeGenOutline(SwShape* shape, const Shape* sdata, const Matrix* transform
         }
     }
 
+    if (static_cast<uint32_t>(outlinePtsCnt - closeCnt) > ptsCnt) {
+        TVGERR("SW_ENGINE", "Wrong a pair of the commands & points - required(%d), current(%d)", outlinePtsCnt - closeCnt, ptsCnt);
+        return false;
+    }
+
     ++outlinePtsCnt;    //for close
     ++outlineCntrsCnt;  //for end
 
+    shape->outline = mpoolReqOutline(mpool, tid);
     auto outline = shape->outline;
-    if (!outline) outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
-    outline->opened = true;
 
     _growOutlinePoint(*outline, outlinePtsCnt);
-    _growOutlineContour(*outline, outlineCntrsCnt);
 
-    auto closed = false;
+     if (_growOutlineContour(*outline, outlineCntrsCnt)) {
+        _reserveOutlineClose(*outline);
+    } else {
+        _resetOutlineClose(*outline);
+    }
 
     //Generate Outlines
     while (cmdCnt-- > 0) {
-        switch(*cmds) {
+        switch (*cmds) {
             case PathCommand::Close: {
                 _outlineClose(*outline);
-                closed = true;
                 break;
             }
             case PathCommand::MoveTo: {
@@ -568,20 +467,77 @@ bool shapeGenOutline(SwShape* shape, const Shape* sdata, const Matrix* transform
 
     _outlineEnd(*outline);
 
-    if (closed) outline->opened = false;
+    outline->fillRule = sdata->fillRule();
+    shape->outline = outline;
+
+    shape->fastTrack = (!hasComposite && _axisAlignedRect(shape->outline));
+    return true;
+}
+
+
+/************************************************************************/
+/* External Class Implementation                                        */
+/************************************************************************/
+
+bool shapePrepare(SwShape* shape, const Shape* sdata, const Matrix* transform,  const SwBBox& clipRegion, SwBBox& renderRegion, SwMpool* mpool, unsigned tid, bool hasComposite)
+{
+    if (!_genOutline(shape, sdata, transform, mpool, tid, hasComposite)) return false;
+    if (!mathUpdateOutlineBBox(shape->outline, clipRegion, renderRegion, shape->fastTrack)) return false;
 
-    //FIXME:
-    //outline->flags = SwOutline::FillRule::Winding;
+    //Keep it for Rasterization Region
+    shape->bbox = renderRegion;
 
-    shape->outline = outline;
+    //Check valid region
+    if (renderRegion.max.x - renderRegion.min.x < 1 && renderRegion.max.y - renderRegion.min.y < 1) return false;
+
+    //Check boundary
+    if (renderRegion.min.x >= clipRegion.max.x || renderRegion.min.y >= clipRegion.max.y ||
+        renderRegion.max.x <= clipRegion.min.x || renderRegion.max.y <= clipRegion.min.y) return false;
 
     return true;
 }
 
 
+bool shapePrepared(const SwShape* shape)
+{
+    return shape->rle ? true : false;
+}
+
+
+bool shapeGenRle(SwShape* shape, TVG_UNUSED const Shape* sdata, bool antiAlias)
+{
+    //FIXME: Should we draw it?
+    //Case: Stroke Line
+    //if (shape.outline->opened) return true;
+
+    //Case A: Fast Track Rectangle Drawing
+    if (shape->fastTrack) return true;
+
+    //Case B: Normal Shape RLE Drawing
+    if ((shape->rle = rleRender(shape->rle, shape->outline, shape->bbox, antiAlias))) return true;
+
+    return false;
+}
+
+
+void shapeDelOutline(SwShape* shape, SwMpool* mpool, uint32_t tid)
+{
+    mpoolRetOutline(mpool, tid);
+    shape->outline = nullptr;
+}
+
+
+void shapeReset(SwShape* shape)
+{
+    rleReset(shape->rle);
+    rleReset(shape->strokeRle);
+    shape->fastTrack = false;
+    shape->bbox.reset();
+}
+
+
 void shapeFree(SwShape* shape)
 {
-    shapeDelOutline(shape);
     rleFree(shape->rle);
     shapeDelFill(shape);
 
@@ -609,13 +565,11 @@ void shapeResetStroke(SwShape* shape, const Shape* sdata, const Matrix* transfor
     if (!stroke) return;
 
     strokeReset(stroke, sdata, transform);
-
-    rleFree(shape->strokeRle);
-    shape->strokeRle = nullptr;
+    rleReset(shape->strokeRle);
 }
 
 
-bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, const Matrix* transform, const SwSize& clip)
+bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, const Matrix* transform, const SwBBox& clipRegion, SwBBox& renderRegion, SwMpool* mpool, unsigned tid)
 {
     SwOutline* shapeOutline = nullptr;
     SwOutline* strokeOutline = nullptr;
@@ -630,7 +584,7 @@ bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, const Matrix* transfo
     //Normal Style stroke
     } else {
         if (!shape->outline) {
-            if (!shapeGenOutline(shape, sdata, transform)) return false;
+            if (!_genOutline(shape, sdata, transform, mpool, tid, false)) return false;
         }
         shapeOutline = shape->outline;
     }
@@ -640,33 +594,38 @@ bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, const Matrix* transfo
         goto fail;
     }
 
-    strokeOutline = strokeExportOutline(shape->stroke);
-    if (!strokeOutline) {
-        ret = false;
-        goto fail;
-    }
+    strokeOutline = strokeExportOutline(shape->stroke, mpool, tid);
 
-    SwBBox bbox;
-    _updateBBox(strokeOutline, bbox);
-
-    if (!_checkValid(strokeOutline, bbox, clip)) {
+    if (!mathUpdateOutlineBBox(strokeOutline, clipRegion, renderRegion, false)) {
         ret = false;
         goto fail;
     }
 
-    shape->strokeRle = rleRender(strokeOutline, bbox, clip, true);
+    shape->strokeRle = rleRender(shape->strokeRle, strokeOutline, renderRegion, true);
 
 fail:
-    if (freeOutline) _delOutline(shapeOutline);
-    _delOutline(strokeOutline);
+    if (freeOutline) {
+        if (shapeOutline->cntrs) free(shapeOutline->cntrs);
+        if (shapeOutline->pts) free(shapeOutline->pts);
+        if (shapeOutline->types) free(shapeOutline->types);
+        if (shapeOutline->closed) free(shapeOutline->closed);
+        free(shapeOutline);
+    }
+    mpoolRetStrokeOutline(mpool, tid);
 
     return ret;
 }
 
 
-bool shapeGenFillColors(SwShape* shape, const Fill* fill, const Matrix* transform, SwSurface* surface, bool ctable)
+bool shapeGenFillColors(SwShape* shape, const Fill* fill, const Matrix* transform, SwSurface* surface, uint32_t opacity, bool ctable)
 {
-    return fillGenColorTable(shape->fill, fill, transform, surface, ctable);
+    return fillGenColorTable(shape->fill, fill, transform, surface, opacity, ctable);
+}
+
+
+bool shapeGenStrokeFillColors(SwShape* shape, const Fill* fill, const Matrix* transform, SwSurface* surface, uint32_t opacity, bool ctable)
+{
+    return fillGenColorTable(shape->stroke->fill, fill, transform, surface, opacity, ctable);
 }
 
 
@@ -680,9 +639,27 @@ void shapeResetFill(SwShape* shape)
 }
 
 
+void shapeResetStrokeFill(SwShape* shape)
+{
+    if (!shape->stroke->fill) {
+        shape->stroke->fill = static_cast<SwFill*>(calloc(1, sizeof(SwFill)));
+        if (!shape->stroke->fill) return;
+    }
+    fillReset(shape->stroke->fill);
+}
+
+
 void shapeDelFill(SwShape* shape)
 {
     if (!shape->fill) return;
     fillFree(shape->fill);
     shape->fill = nullptr;
-}
\ No newline at end of file
+}
+
+
+void shapeDelStrokeFill(SwShape* shape)
+{
+    if (!shape->stroke->fill) return;
+    fillFree(shape->stroke->fill);
+    shape->stroke->fill = nullptr;
+}