feat: class border-radius

This commit is contained in:
donglixiaoche 2023-03-06 18:48:00 +08:00
parent fc4ff9c523
commit 22b14dcff7
No known key found for this signature in database
GPG key ID: F235CD35048B3752

View file

@ -3,6 +3,7 @@ package d2svg
import ( import (
"fmt" "fmt"
"io" "io"
"strings"
"oss.terrastruct.com/d2/d2target" "oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/d2/d2themes" "oss.terrastruct.com/d2/d2themes"
@ -18,6 +19,9 @@ func classHeader(shape d2target.Shape, box *geo.Box, text string, textWidth, tex
rectEl.Fill = shape.Fill rectEl.Fill = shape.Fill
rectEl.ClassName = "class_header" rectEl.ClassName = "class_header"
str := rectEl.Render() str := rectEl.Render()
if shape.BorderRadius != 0 {
str = strings.Replace(str, "/>", fmt.Sprintf(`clip-path="url(#%v)" />`, shape.ID), 1)
}
if text != "" { if text != "" {
tl := label.InsideMiddleCenter.GetPointOnBox( tl := label.InsideMiddleCenter.GetPointOnBox(
@ -89,6 +93,8 @@ func drawClass(writer io.Writer, targetShape d2target.Shape) {
el.Height = float64(targetShape.Height) el.Height = float64(targetShape.Height)
el.Fill, el.Stroke = d2themes.ShapeTheme(targetShape) el.Fill, el.Stroke = d2themes.ShapeTheme(targetShape)
el.Style = targetShape.CSSStyle() el.Style = targetShape.CSSStyle()
el.Rx = float64(targetShape.BorderRadius)
el.Ry = float64(targetShape.BorderRadius)
fmt.Fprint(writer, el.Render()) fmt.Fprint(writer, el.Render())
box := geo.NewBox( box := geo.NewBox(