fix: should add clipPath

This commit is contained in:
donglixiaoche 2023-03-09 17:51:20 +08:00
parent dd1824c4dc
commit 77e2a23b2b
No known key found for this signature in database
GPG key ID: F235CD35048B3752
3 changed files with 6 additions and 4 deletions

View file

@ -17,7 +17,7 @@ func classHeader(labelMaskID string, shape d2target.Shape, box *geo.Box, text st
rectEl.Width, rectEl.Height = box.Width, box.Height
rectEl.Fill = shape.Fill
rectEl.ClassName = "class_header"
str := rectEl.RenderWithClipPath(fmt.Sprintf("%v-%v", labelMaskID, shape.ID))
str := rectEl.RenderWithClipPath(fmt.Sprintf("%v-%v", labelMaskID, shape.ID), shape.BorderRadius != 0)
if text != "" {
tl := label.InsideMiddleCenter.GetPointOnBox(

View file

@ -46,7 +46,7 @@ func tableHeader(labelMaskID string, shape d2target.Shape, box *geo.Box, text st
rectEl.Width, rectEl.Height = box.Width, box.Height
rectEl.Fill = shape.Fill
rectEl.ClassName = "class_header"
str := rectEl.RenderWithClipPath(fmt.Sprintf("%v-%v", labelMaskID, shape.ID))
str := rectEl.RenderWithClipPath(fmt.Sprintf("%v-%v", labelMaskID, shape.ID), shape.BorderRadius != 0)
if text != "" {
tl := label.InsideMiddleLeft.GetPointOnBox(

View file

@ -101,9 +101,11 @@ func (el *ThemableElement) SetMaskUrl(url string) {
el.Mask = fmt.Sprintf("url(#%s)", url)
}
func (el *ThemableElement) RenderWithClipPath(id string) string {
func (el *ThemableElement) RenderWithClipPath(id string, shouldAddClipPath bool) string {
out := el.Render()
if shouldAddClipPath {
out = strings.Replace(out, "/>", fmt.Sprintf(`clip-path="url(#%v)" />`, id), 1)
}
return out
}