From 569da7bde87dae94e05da29165c57b1464a54103 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 25 Aug 2024 15:26:42 -0600 Subject: [PATCH] d2cli: fix theme passing to gif, fix scale on animated svg --- ci/release/changelogs/next.md | 2 ++ ci/release/template/man/d2.1 | 2 +- d2cli/main.go | 27 +++++++++++++++++---------- d2renderers/d2animate/d2animate.go | 12 ++++++++++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index c6f33954bc..db34c4ad59 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -20,3 +20,5 @@ - Vars: Spread variables are inserted in place instead of appending to end of scope [#2062](https://github.com/terrastruct/d2/pull/2062) - Imports: fix local icon imports from files that are imported [#2066](https://github.com/terrastruct/d2/pull/2066) - CLI: fixes edge case of watch mode links to nested board that had more nested boards not working [#2070](https://github.com/terrastruct/d2/pull/2070) +- CLI: fixes theme flag not being passed to GIF outputs [#2071](https://github.com/terrastruct/d2/pull/2071) +- CLI: fixes scale flag not being passed to animated SVG outputs [#2071](https://github.com/terrastruct/d2/pull/2071) diff --git a/ci/release/template/man/d2.1 b/ci/release/template/man/d2.1 index d1663d7ea1..fa19626fa0 100644 --- a/ci/release/template/man/d2.1 +++ b/ci/release/template/man/d2.1 @@ -96,7 +96,7 @@ Path to .ttf file to use for the bold font. If none provided, Source Sans Pro Bo Pixels padded around the rendered diagram .Ns . .It Fl -animate-interval Ar 0 -If given, multiple boards are packaged as 1 SVG which transitions through each board at the interval (in milliseconds). Can only be used with SVG exports +If given, multiple boards are packaged as 1 SVG which transitions through each board at the interval (in milliseconds). Can only be used with SVG and GIF exports .Ns . .It Fl -browser Ar true Browser executable that watch opens. Setting to 0 opens no browser diff --git a/d2cli/main.go b/d2cli/main.go index 8f9e022a96..a183b5dac2 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -847,9 +847,9 @@ func _render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opts Pad: opts.Pad, Sketch: opts.Sketch, Center: opts.Center, + MasterID: opts.MasterID, ThemeID: opts.ThemeID, DarkThemeID: opts.DarkThemeID, - MasterID: opts.MasterID, ThemeOverrides: opts.ThemeOverrides, DarkThemeOverrides: opts.DarkThemeOverrides, Scale: scale, @@ -936,11 +936,14 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opt } svg, err = d2svg.Render(diagram, &d2svg.RenderOpts{ - Pad: opts.Pad, - Sketch: opts.Sketch, - Center: opts.Center, - Scale: scale, - ThemeID: opts.ThemeID, + Pad: opts.Pad, + Sketch: opts.Sketch, + Center: opts.Center, + Scale: scale, + ThemeID: opts.ThemeID, + DarkThemeID: opts.DarkThemeID, + ThemeOverrides: opts.ThemeOverrides, + DarkThemeOverrides: opts.DarkThemeOverrides, }) if err != nil { return nil, err @@ -1286,10 +1289,14 @@ func renderPNGsForGIF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plug scale = go2.Pointer(1.) } svg, err = d2svg.Render(diagram, &d2svg.RenderOpts{ - Pad: opts.Pad, - Sketch: opts.Sketch, - Center: opts.Center, - Scale: scale, + Pad: opts.Pad, + Sketch: opts.Sketch, + Center: opts.Center, + Scale: scale, + ThemeID: opts.ThemeID, + DarkThemeID: opts.DarkThemeID, + ThemeOverrides: opts.ThemeOverrides, + DarkThemeOverrides: opts.DarkThemeOverrides, }) if err != nil { return nil, nil, err diff --git a/d2renderers/d2animate/d2animate.go b/d2renderers/d2animate/d2animate.go index 460bfa5f38..ac25928aaf 100644 --- a/d2renderers/d2animate/d2animate.go +++ b/d2renderers/d2animate/d2animate.go @@ -54,9 +54,17 @@ func Wrap(rootDiagram *d2target.Diagram, svgs [][]byte, renderOpts d2svg.RenderO width := br.X - tl.X + int(*renderOpts.Pad)*2 height := br.Y - tl.Y + int(*renderOpts.Pad)*2 - fitToScreenWrapperOpening := fmt.Sprintf(``, + var dimensions string + if renderOpts.Scale != nil { + dimensions = fmt.Sprintf(` width="%d" height="%d"`, + int(math.Ceil((*renderOpts.Scale)*float64(width))), + int(math.Ceil((*renderOpts.Scale)*float64(height))), + ) + } + + fitToScreenWrapperOpening := fmt.Sprintf(``, version.Version, - width, height, + width, height, dimensions, ) fmt.Fprint(buf, fitToScreenWrapperOpening)