Merge pull request #933 from alixander/sketch-fill
fix sketch overlays, double-border
|
|
@ -155,6 +155,8 @@ func DoubleRect(r *Runner, shape d2target.Shape) (string, error) {
|
||||||
pathEl = d2themes.NewThemableElement("path")
|
pathEl = d2themes.NewThemableElement("path")
|
||||||
pathEl.SetTranslate(float64(shape.Pos.X+d2target.INNER_BORDER_OFFSET), float64(shape.Pos.Y+d2target.INNER_BORDER_OFFSET))
|
pathEl.SetTranslate(float64(shape.Pos.X+d2target.INNER_BORDER_OFFSET), float64(shape.Pos.Y+d2target.INNER_BORDER_OFFSET))
|
||||||
pathEl.Fill, pathEl.Stroke = d2themes.ShapeTheme(shape)
|
pathEl.Fill, pathEl.Stroke = d2themes.ShapeTheme(shape)
|
||||||
|
// No need for inner to double paint
|
||||||
|
pathEl.Fill = "transparent"
|
||||||
pathEl.ClassName = "shape"
|
pathEl.ClassName = "shape"
|
||||||
pathEl.Style = shape.CSSStyle()
|
pathEl.Style = shape.CSSStyle()
|
||||||
for _, p := range pathsSmallRect {
|
for _, p := range pathsSmallRect {
|
||||||
|
|
@ -162,10 +164,16 @@ func DoubleRect(r *Runner, shape d2target.Shape) (string, error) {
|
||||||
output += pathEl.Render()
|
output += pathEl.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
output += fmt.Sprintf(
|
sketchOEl := d2themes.NewThemableElement("rect")
|
||||||
`<rect class="sketch-overlay" transform="translate(%d %d)" width="%d" height="%d" />`,
|
sketchOEl.SetTranslate(float64(shape.Pos.X), float64(shape.Pos.Y))
|
||||||
shape.Pos.X, shape.Pos.Y, shape.Width, shape.Height,
|
sketchOEl.Width = float64(shape.Width)
|
||||||
)
|
sketchOEl.Height = float64(shape.Height)
|
||||||
|
renderedSO, err := d2themes.NewThemableSketchOverlay(sketchOEl, shape.Fill).Render()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
output += renderedSO
|
||||||
|
|
||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,17 +252,27 @@ func DoubleOval(r *Runner, shape d2target.Shape) (string, error) {
|
||||||
pathEl = d2themes.NewThemableElement("path")
|
pathEl = d2themes.NewThemableElement("path")
|
||||||
pathEl.SetTranslate(float64(shape.Pos.X), float64(shape.Pos.Y))
|
pathEl.SetTranslate(float64(shape.Pos.X), float64(shape.Pos.Y))
|
||||||
pathEl.Fill, pathEl.Stroke = d2themes.ShapeTheme(shape)
|
pathEl.Fill, pathEl.Stroke = d2themes.ShapeTheme(shape)
|
||||||
|
// No need for inner to double paint
|
||||||
|
pathEl.Fill = "transparent"
|
||||||
pathEl.ClassName = "shape"
|
pathEl.ClassName = "shape"
|
||||||
pathEl.Style = shape.CSSStyle()
|
pathEl.Style = shape.CSSStyle()
|
||||||
for _, p := range pathsSmallCircle {
|
for _, p := range pathsSmallCircle {
|
||||||
pathEl.D = p
|
pathEl.D = p
|
||||||
output += pathEl.Render()
|
output += pathEl.Render()
|
||||||
}
|
}
|
||||||
|
soElement := d2themes.NewThemableElement("ellipse")
|
||||||
|
soElement.SetTranslate(float64(shape.Pos.X+shape.Width/2), float64(shape.Pos.Y+shape.Height/2))
|
||||||
|
soElement.Rx = float64(shape.Width / 2)
|
||||||
|
soElement.Ry = float64(shape.Height / 2)
|
||||||
|
renderedSO, err := d2themes.NewThemableSketchOverlay(
|
||||||
|
soElement,
|
||||||
|
shape.Fill,
|
||||||
|
).Render()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
output += renderedSO
|
||||||
|
|
||||||
output += fmt.Sprintf(
|
|
||||||
`<ellipse class="sketch-overlay" transform="translate(%d %d)" rx="%d" ry="%d" />`,
|
|
||||||
shape.Pos.X+shape.Width/2, shape.Pos.Y+shape.Height/2, shape.Width/2, shape.Height/2,
|
|
||||||
)
|
|
||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -986,6 +986,23 @@ company Warehouse.explanation: |md
|
||||||
- Staging
|
- Staging
|
||||||
- Dispatch to Site
|
- Dispatch to Site
|
||||||
|
|
|
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "double-border",
|
||||||
|
script: `a: {
|
||||||
|
style.double-border: true
|
||||||
|
b
|
||||||
|
}
|
||||||
|
c: {
|
||||||
|
shape: oval
|
||||||
|
style.double-border: true
|
||||||
|
d
|
||||||
|
}
|
||||||
|
normal: {
|
||||||
|
nested normal
|
||||||
|
}
|
||||||
|
something
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 261 KiB After Width: | Height: | Size: 298 KiB |
|
Before Width: | Height: | Size: 261 KiB After Width: | Height: | Size: 288 KiB |
|
Before Width: | Height: | Size: 247 KiB After Width: | Height: | Size: 284 KiB |
|
Before Width: | Height: | Size: 247 KiB After Width: | Height: | Size: 274 KiB |
|
Before Width: | Height: | Size: 297 KiB After Width: | Height: | Size: 334 KiB |
|
Before Width: | Height: | Size: 297 KiB After Width: | Height: | Size: 325 KiB |
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 227 KiB |
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 218 KiB |
|
Before Width: | Height: | Size: 242 KiB After Width: | Height: | Size: 279 KiB |
|
Before Width: | Height: | Size: 242 KiB After Width: | Height: | Size: 270 KiB |
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 226 KiB |
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 217 KiB |
|
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 276 KiB |
|
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 267 KiB |
|
Before Width: | Height: | Size: 296 KiB After Width: | Height: | Size: 332 KiB |
|
Before Width: | Height: | Size: 296 KiB After Width: | Height: | Size: 323 KiB |
38
d2renderers/d2sketch/testdata/double-border/sketch.exp.svg
vendored
Normal file
|
After Width: | Height: | Size: 289 KiB |
|
Before Width: | Height: | Size: 303 KiB After Width: | Height: | Size: 340 KiB |
|
Before Width: | Height: | Size: 303 KiB After Width: | Height: | Size: 330 KiB |
|
Before Width: | Height: | Size: 228 KiB After Width: | Height: | Size: 228 KiB |
|
Before Width: | Height: | Size: 269 KiB After Width: | Height: | Size: 306 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 400 KiB After Width: | Height: | Size: 418 KiB |
|
Before Width: | Height: | Size: 400 KiB After Width: | Height: | Size: 418 KiB |
|
|
@ -1689,10 +1689,6 @@ func Render(diagram *d2target.Diagram, opts *RenderOpts) ([]byte, error) {
|
||||||
// generate style elements that will be appended to the SVG tag
|
// generate style elements that will be appended to the SVG tag
|
||||||
upperBuf := &bytes.Buffer{}
|
upperBuf := &bytes.Buffer{}
|
||||||
embedFonts(upperBuf, buf.String(), diagram.FontFamily) // embedFonts *must* run before `d2sketch.DefineFillPatterns`, but after all elements are appended to `buf`
|
embedFonts(upperBuf, buf.String(), diagram.FontFamily) // embedFonts *must* run before `d2sketch.DefineFillPatterns`, but after all elements are appended to `buf`
|
||||||
if sketchRunner != nil {
|
|
||||||
d2sketch.DefineFillPatterns(upperBuf)
|
|
||||||
}
|
|
||||||
|
|
||||||
themeStylesheet, err := themeCSS(themeID, darkThemeID)
|
themeStylesheet, err := themeCSS(themeID, darkThemeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -1709,6 +1705,9 @@ func Render(diagram *d2target.Diagram, opts *RenderOpts) ([]byte, error) {
|
||||||
if hasMarkdown {
|
if hasMarkdown {
|
||||||
fmt.Fprintf(upperBuf, `<style type="text/css">%s</style>`, mdCSS)
|
fmt.Fprintf(upperBuf, `<style type="text/css">%s</style>`, mdCSS)
|
||||||
}
|
}
|
||||||
|
if sketchRunner != nil {
|
||||||
|
d2sketch.DefineFillPatterns(upperBuf)
|
||||||
|
}
|
||||||
|
|
||||||
// This shift is for background el to envelop the diagram
|
// This shift is for background el to envelop the diagram
|
||||||
left -= int(math.Ceil(float64(diagram.Root.StrokeWidth) / 2.))
|
left -= int(math.Ceil(float64(diagram.Root.StrokeWidth) / 2.))
|
||||||
|
|
|
||||||