Merge pull request #933 from alixander/sketch-fill

fix sketch overlays, double-border
This commit is contained in:
Alexander Wang 2023-02-27 19:31:05 -08:00 committed by GitHub
commit ead2850fc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 304 additions and 76 deletions

View file

@ -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
} }

View file

@ -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
`, `,
}, },
} }

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 261 KiB

After

Width:  |  Height:  |  Size: 298 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 261 KiB

After

Width:  |  Height:  |  Size: 288 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 247 KiB

After

Width:  |  Height:  |  Size: 284 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 247 KiB

After

Width:  |  Height:  |  Size: 274 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 297 KiB

After

Width:  |  Height:  |  Size: 334 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 297 KiB

After

Width:  |  Height:  |  Size: 325 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 227 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 218 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 242 KiB

After

Width:  |  Height:  |  Size: 279 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 242 KiB

After

Width:  |  Height:  |  Size: 270 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 226 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 217 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 276 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 267 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 296 KiB

After

Width:  |  Height:  |  Size: 332 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 296 KiB

After

Width:  |  Height:  |  Size: 323 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 289 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 303 KiB

After

Width:  |  Height:  |  Size: 340 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 303 KiB

After

Width:  |  Height:  |  Size: 330 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 228 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 269 KiB

After

Width:  |  Height:  |  Size: 306 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 114 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 105 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 400 KiB

After

Width:  |  Height:  |  Size: 418 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 400 KiB

After

Width:  |  Height:  |  Size: 418 KiB

View file

@ -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.))