set Border-Radius to half of size in case of external clip-path

This commit is contained in:
melsonic 2025-03-30 16:01:56 +05:30
parent 5ce77a1325
commit 42c18cf9f0
No known key found for this signature in database
GPG key ID: DFA426742F621CD7

View file

@ -1329,6 +1329,13 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
if targetShape.BorderRadius != 0 && (targetShape.Type == d2target.ShapeClass || targetShape.Type == d2target.ShapeSQLTable) {
fmt.Fprint(writer, clipPathForBorderRadius(diagramHash, targetShape))
}
var iconClipPathID string
if targetShape.IconBorderRadius != 0 && (targetShape.Type == d2target.ShapeImage) {
// https://www.w3.org/Style/CSS/Tracker/issues/29?changelog
targetShape.IconBorderRadius = min(targetShape.IconBorderRadius, min(targetShape.Width, targetShape.Height)/2)
iconClipPathID = fmt.Sprintf("%v-%v-icon", diagramHash, svg.SVGID(targetShape.ID))
fmt.Fprint(writer, applyIconBorderRadius(iconClipPathID, targetShape))
}
classes := []string{base64.URLEncoding.EncodeToString([]byte(svg.EscapeText(targetShape.ID)))}
if targetShape.Animated {
classes = append(classes, "animated-shape")
@ -1441,9 +1448,7 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
el.Stroke = stroke
el.Style = style
if targetShape.IconBorderRadius != 0 {
clipPathID := fmt.Sprintf("%v-%v-icon", diagramHash, svg.SVGID(targetShape.ID))
fmt.Fprint(writer, applyIconBorderRadius(clipPathID, targetShape))
el.ClipPath = clipPathID
el.ClipPath = iconClipPathID
}
fmt.Fprint(writer, el.Render())