@@ -853,25 +853,18 @@ func drawConnection(writer io.Writer, diagramHash string, connection d2target.Co
853
853
if connection .Icon != nil {
854
854
iconPos := connection .GetIconPosition ()
855
855
if iconPos != nil {
856
+ connectionIconClipPath := ""
856
857
if connection .IconBorderRadius != 0 {
857
- fmt .Fprintf (writer , `<image href="%s" x="%f" y="%f" width="%d" height="%d" clip-path="inset(0 round %fpx)" />` ,
858
- html .EscapeString (connection .Icon .String ()),
859
- iconPos .X ,
860
- iconPos .Y ,
861
- d2target .DEFAULT_ICON_SIZE ,
862
- d2target .DEFAULT_ICON_SIZE ,
863
- connection .IconBorderRadius ,
864
- )
865
- } else {
866
-
867
- fmt .Fprintf (writer , `<image href="%s" x="%f" y="%f" width="%d" height="%d" />` ,
868
- html .EscapeString (connection .Icon .String ()),
869
- iconPos .X ,
870
- iconPos .Y ,
871
- d2target .DEFAULT_ICON_SIZE ,
872
- d2target .DEFAULT_ICON_SIZE ,
873
- )
858
+ connectionIconClipPath = fmt .Sprintf (` clip-path="inset(0 round %fpx)"` , connection .IconBorderRadius )
874
859
}
860
+ fmt .Fprintf (writer , `<image href="%s" x="%f" y="%f" width="%d" height="%d"%s />` ,
861
+ html .EscapeString (connection .Icon .String ()),
862
+ iconPos .X ,
863
+ iconPos .Y ,
864
+ d2target .DEFAULT_ICON_SIZE ,
865
+ d2target .DEFAULT_ICON_SIZE ,
866
+ connectionIconClipPath ,
867
+ )
875
868
}
876
869
}
877
870
@@ -1447,9 +1440,10 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
1447
1440
el .Fill = fill
1448
1441
el .Stroke = stroke
1449
1442
el .Style = style
1450
- if targetShape .IconStyle != nil && targetShape .IconStyle .BorderRadius != 0 {
1451
- fmt .Fprint (writer , clipPathForIconBorderRadius (diagramHash , targetShape ))
1452
- el .ClipPath = fmt .Sprintf ("%v-%v-icon" , diagramHash , targetShape .ID )
1443
+ if targetShape .IconBorderRadius != 0 {
1444
+ clipPathId := fmt .Sprintf ("%v-%v-icon" , diagramHash , svg .SVGID (targetShape .ID ))
1445
+ fmt .Fprint (writer , applyIconBorderRadius (clipPathId , targetShape ))
1446
+ el .ClipPath = clipPathId
1453
1447
}
1454
1448
fmt .Fprint (writer , el .Render ())
1455
1449
@@ -1643,24 +1637,18 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
1643
1637
1644
1638
tl := iconPosition .GetPointOnBox (box , label .PADDING , float64 (iconSize ), float64 (iconSize ))
1645
1639
1646
- if targetShape .IconStyle != nil && targetShape .IconStyle .BorderRadius != 0 {
1647
- fmt .Fprintf (writer , `<image href="%s" x="%f" y="%f" width="%d" height="%d" clip-path="inset(0 round %dpx)" />` ,
1648
- html .EscapeString (targetShape .Icon .String ()),
1649
- tl .X ,
1650
- tl .Y ,
1651
- iconSize ,
1652
- iconSize ,
1653
- targetShape .IconStyle .BorderRadius ,
1654
- )
1655
- } else {
1656
- fmt .Fprintf (writer , `<image href="%s" x="%f" y="%f" width="%d" height="%d" />` ,
1657
- html .EscapeString (targetShape .Icon .String ()),
1658
- tl .X ,
1659
- tl .Y ,
1660
- iconSize ,
1661
- iconSize ,
1662
- )
1663
- }
1640
+ shapeIconClipPath := ""
1641
+ if targetShape .IconBorderRadius != 0 {
1642
+ shapeIconClipPath = fmt .Sprintf (` clip-path="inset(0 round %dpx)"` , targetShape .IconBorderRadius )
1643
+ }
1644
+ fmt .Fprintf (writer , `<image href="%s" x="%f" y="%f" width="%d" height="%d"%s />` ,
1645
+ html .EscapeString (targetShape .Icon .String ()),
1646
+ tl .X ,
1647
+ tl .Y ,
1648
+ iconSize ,
1649
+ iconSize ,
1650
+ shapeIconClipPath ,
1651
+ )
1664
1652
}
1665
1653
1666
1654
if targetShape .Label != "" && targetShape .Opacity != 0 {
@@ -1889,6 +1877,28 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
1889
1877
return labelMask , nil
1890
1878
}
1891
1879
1880
+ func applyIconBorderRadius (clipPathId string , shape d2target.Shape ) string {
1881
+ box := geo .NewBox (
1882
+ geo .NewPoint (float64 (shape .Pos .X ), float64 (shape .Pos .Y )),
1883
+ float64 (shape .Width ),
1884
+ float64 (shape .Height ),
1885
+ )
1886
+ topX , topY := box .TopLeft .X + box .Width , box .TopLeft .Y
1887
+
1888
+ out := fmt .Sprintf (`<clipPath id="%s">` , clipPathId )
1889
+ out += fmt .Sprintf (`<path d="M %f %f L %f %f S %f %f %f %f ` , box .TopLeft .X , box .TopLeft .Y + float64 (shape .IconBorderRadius ), box .TopLeft .X , box .TopLeft .Y + float64 (shape .IconBorderRadius ), box .TopLeft .X , box .TopLeft .Y , box .TopLeft .X + float64 (shape .IconBorderRadius ), box .TopLeft .Y )
1890
+ out += fmt .Sprintf (`L %f %f L %f %f ` , box .TopLeft .X + box .Width - float64 (shape .IconBorderRadius ), box .TopLeft .Y , topX - float64 (shape .IconBorderRadius ), topY )
1891
+
1892
+ out += fmt .Sprintf (`S %f %f %f %f ` , topX , topY , topX , topY + float64 (shape .IconBorderRadius ))
1893
+ out += fmt .Sprintf (`L %f %f ` , topX , topY + box .Height - float64 (shape .IconBorderRadius ))
1894
+ out += fmt .Sprintf (`S %f % f %f %f ` , topX , topY + box .Height , topX - float64 (shape .IconBorderRadius ), topY + box .Height )
1895
+ out += fmt .Sprintf (`L %f %f ` , box .TopLeft .X + float64 (shape .IconBorderRadius ), box .TopLeft .Y + box .Height )
1896
+ out += fmt .Sprintf (`S %f %f %f %f` , box .TopLeft .X , box .TopLeft .Y + box .Height , box .TopLeft .X , box .TopLeft .Y + box .Height - float64 (shape .IconBorderRadius ))
1897
+ out += fmt .Sprintf (`L %f %f` , box .TopLeft .X , box .TopLeft .Y + float64 (shape .IconBorderRadius ))
1898
+ out += fmt .Sprintf (`Z %f %f" ` , box .TopLeft .X , box .TopLeft .Y )
1899
+ return out + `fill="none" /> </clipPath>`
1900
+ }
1901
+
1892
1902
func addAppendixItems (writer io.Writer , diagramHash string , targetShape d2target.Shape , s shape.Shape ) {
1893
1903
var p1 , p2 * geo.Point
1894
1904
if targetShape .Tooltip != "" || targetShape .Link != "" {
0 commit comments