Skip to content

Commit 235c34a

Browse files
committed
raster: add pure-Go export rendering
1 parent 0d69dca commit 235c34a

249 files changed

Lines changed: 68145 additions & 2379 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/release-archives.yml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ jobs:
186186
if (-not (Select-String -LiteralPath $outputFile -Pattern '<svg' -Quiet)) {
187187
throw "d2 SVG smoke render did not produce SVG"
188188
}
189+
$pngFile = Join-Path $destination "smoke.png"
190+
& $binary $inputFile $pngFile
191+
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $pngFile -PathType Leaf)) {
192+
throw "d2 PNG smoke render failed"
193+
}
194+
$png = [System.IO.File]::ReadAllBytes($pngFile)
195+
if ($png.Length -lt 24 -or [BitConverter]::ToString($png[0..7]) -cne "89-50-4E-47-0D-0A-1A-0A") {
196+
throw "d2 PNG smoke render did not produce a PNG signature"
197+
}
198+
if ([Text.Encoding]::ASCII.GetString($png, 12, 4) -cne "IHDR") {
199+
throw "d2 PNG smoke render is missing its IHDR chunk"
200+
}
201+
$width = [Net.IPAddress]::NetworkToHostOrder([BitConverter]::ToInt32($png, 16))
202+
$height = [Net.IPAddress]::NetworkToHostOrder([BitConverter]::ToInt32($png, 20))
203+
if ($width -le 0 -or $height -le 0) {
204+
throw "d2 PNG smoke render has invalid dimensions ${width}x${height}"
205+
}
189206
190207
attest:
191208
if: github.event_name == 'push'

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ one, please see [./d2renderers/d2fonts](./d2renderers/d2fonts).
175175

176176
## Export file types
177177

178-
D2 currently supports SVG, PNG and PDF exports. More coming soon.
178+
D2 supports SVG, PNG, GIF, PDF, and PPTX exports.
179179

180180
## Language tooling
181181

‎THIRD_PARTY_NOTICES.txt‎

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,40 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
8181
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
8282
SOFTWARE.
8383

84+
Go image
85+
https://pkg.go.dev/golang.org/x/image
86+
Version 0.45.0
87+
88+
D2 uses the font, OpenType, fixed-point math, and WebP packages.
89+
90+
Copyright 2009 The Go Authors.
91+
92+
Redistribution and use in source and binary forms, with or without
93+
modification, are permitted provided that the following conditions are
94+
met:
95+
96+
* Redistributions of source code must retain the above copyright
97+
notice, this list of conditions and the following disclaimer.
98+
* Redistributions in binary form must reproduce the above
99+
copyright notice, this list of conditions and the following disclaimer
100+
in the documentation and/or other materials provided with the
101+
distribution.
102+
* Neither the name of Google LLC nor the names of its
103+
contributors may be used to endorse or promote products derived from
104+
this software without specific prior written permission.
105+
106+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
107+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
108+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
109+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
110+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
111+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
112+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
113+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
114+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
115+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
116+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
117+
84118
mathjax-go
85119
https://github.com/d2lang/mathjax-go
86120
Copyright 2026 D2 contributors
@@ -134,6 +168,158 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
134168
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
135169
SOFTWARE.
136170

171+
go-text/typesetting
172+
https://github.com/go-text/typesetting
173+
Version 0.3.4
174+
175+
D2 uses go-text's OpenType parser, HarfBuzz-compatible shaper, Unicode
176+
segmenter, and language data to shape scene text in Go.
177+
178+
BSD 3-Clause License
179+
180+
Copyright 2021 The go-text authors
181+
182+
Redistribution and use in source and binary forms, with or without
183+
modification, are permitted provided that the following conditions are met:
184+
185+
1. Redistributions of source code must retain the above copyright notice,
186+
this list of conditions and the following disclaimer.
187+
188+
2. Redistributions in binary form must reproduce the above copyright notice,
189+
this list of conditions and the following disclaimer in the documentation
190+
and/or other materials provided with the distribution.
191+
192+
3. Neither the name of the copyright holder nor the names of its contributors
193+
may be used to endorse or promote products derived from this software
194+
without specific prior written permission.
195+
196+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
197+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
198+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
199+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
200+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
202+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
203+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
204+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
205+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
206+
207+
go-text/typesetting-utils test fonts
208+
https://github.com/go-text/typesetting-utils
209+
Version v0.0.0-20260223113751-2d88ac90dae3
210+
211+
D2's scene-building tests embed gzip-compressed copies of two fonts from this
212+
pinned test corpus in `d2renderers/d2scenebuild/font_script_fallback_test.go`:
213+
214+
Unicode text-rendering-tests TestGVAROne.ttf
215+
Decoded SHA-256: 1846ff7d7d481e9bd6895123f55f73cb952b315e5c5be231ca6983af17e99d1c
216+
Font metadata copyright: Copyright 2016 Monotype Hong Kong Ltd. and
217+
Monotype Imaging Inc.
218+
Corpus copyright: Copyright 2016 Unicode Inc. All rights reserved.
219+
License: Apache License 2.0; the complete text appears below.
220+
221+
HarfBuzz in-house 7bbd3175734d5d291e1c15271ec0cbb97b626ebf.ttf
222+
Decoded SHA-256: f966d806342dc01dc6a1476a09b20f423321a7c6862258489e196965bbbeeff0
223+
Font metadata copyright: Copyright 2010-2022 The Amiri Project Authors.
224+
License: SIL Open Font License 1.1; the complete text appears below.
225+
226+
Noto Color Emoji
227+
https://github.com/googlefonts/noto-emoji
228+
Version 2.051
229+
230+
Upstream license copyright: Copyright 2013 Google LLC
231+
Font metadata copyright: Copyright 2022 Google Inc.
232+
233+
D2 embeds a Brotli stream of `fonts/Noto-COLRv1.ttf` from tag v2.051, commit
234+
8998f5dd683424a73e2314a8c1f1e359c19e8742. Its decoded SHA-256 is
235+
0ae57fe58645638523ba35f388d93739d292539a9acb84df5700c81b1e1a28d2.
236+
237+
Noto Color Emoji is made available under the SIL Open Font License 1.1:
238+
239+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
240+
241+
PREAMBLE
242+
The goals of the Open Font License (OFL) are to stimulate worldwide
243+
development of collaborative font projects, to support the font creation
244+
efforts of academic and linguistic communities, and to provide a free and open
245+
framework in which fonts may be shared and improved in partnership with
246+
others.
247+
248+
The OFL allows the licensed fonts to be used, studied, modified and
249+
redistributed freely as long as they are not sold by themselves. The fonts,
250+
including any derivative works, can be bundled, embedded, redistributed and/or
251+
sold with any software provided that any reserved names are not used by
252+
derivative works. The fonts and derivatives, however, cannot be released under
253+
any other type of license. The requirement for fonts to remain under this
254+
license does not apply to any document created using the fonts or their
255+
derivatives.
256+
257+
DEFINITIONS
258+
"Font Software" refers to the set of files released by the Copyright Holder(s)
259+
under this license and clearly marked as such. This may include source files,
260+
build scripts and documentation.
261+
262+
"Reserved Font Name" refers to any names specified as such after the copyright
263+
statement(s).
264+
265+
"Original Version" refers to the collection of Font Software components as
266+
distributed by the Copyright Holder(s).
267+
268+
"Modified Version" refers to any derivative made by adding to, deleting, or
269+
substituting -- in part or in whole -- any of the components of the Original
270+
Version, by changing formats or by porting the Font Software to a new
271+
environment.
272+
273+
"Author" refers to any designer, engineer, programmer, technical writer or
274+
other person who contributed to the Font Software.
275+
276+
PERMISSION & CONDITIONS
277+
Permission is hereby granted, free of charge, to any person obtaining a copy of
278+
the Font Software, to use, study, copy, merge, embed, modify, redistribute, and
279+
sell modified and unmodified copies of the Font Software, subject to the
280+
following conditions:
281+
282+
1) Neither the Font Software nor any of its individual components, in Original
283+
or Modified Versions, may be sold by itself.
284+
285+
2) Original or Modified Versions of the Font Software may be bundled,
286+
redistributed and/or sold with any software, provided that each copy contains
287+
the above copyright notice and this license. These can be included either as
288+
stand-alone text files, human-readable headers or in the appropriate
289+
machine-readable metadata fields within text or binary files as long as those
290+
fields can be easily viewed by the user.
291+
292+
3) No Modified Version of the Font Software may use the Reserved Font Name(s)
293+
unless explicit written permission is granted by the corresponding Copyright
294+
Holder. This restriction only applies to the primary font name as presented to
295+
the users.
296+
297+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software
298+
shall not be used to promote, endorse or advertise any Modified Version,
299+
except to acknowledge the contribution(s) of the Copyright Holder(s) and the
300+
Author(s) or with their explicit written permission.
301+
302+
5) The Font Software, modified or unmodified, in part or in whole, must be
303+
distributed entirely under this license, and must not be distributed under any
304+
other license. The requirement for fonts to remain under this license does not
305+
apply to any document created using the Font Software.
306+
307+
TERMINATION
308+
This license becomes null and void if any of the above conditions are not met.
309+
310+
DISCLAIMER
311+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
312+
IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
313+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
314+
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR
315+
ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL,
316+
INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF
317+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE
318+
THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
319+
320+
Source distributions also retain the upstream license copy at
321+
`d2renderers/d2fonts/NotoColorEmoji-OFL.txt`.
322+
137323
elk-go
138324
https://github.com/d2lang/elk-go
139325

‎ci/release/changelogs/next.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#### Features 🚀
22

3+
- exports: render PNG, GIF, PDF, and PPTX with the built-in renderer
4+
35
#### Improvements 🧹
46

57
- renders: render Markdown labels as native SVG instead of HTML `foreignObject` content
68

79
#### Bugfixes ⛑️
810

911
- sequence diagrams: keep synthetic lifeline endpoint IDs stable across architectures
10-
- exports: honor `D2_TIMEOUT` during PNG and GIF rendering in Playwright
12+
- exports: honor `D2_TIMEOUT` during PNG and GIF rendering
1113
- compiler: keep recursive globs out of class and variable definitions and report class reference cycles instead of overflowing the stack
1214
- renders: decode gzip, Brotli, and deflate remote images before embedding them
1315

‎ci/release/docker/Dockerfile‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,9 @@ ARG TARGETARCH
55
ARG FIXUID_VERSION=0.6.0
66

77
RUN apt-get update \
8-
&& apt-get install -y --no-install-recommends ca-certificates curl dumb-init sudo \
8+
&& apt-get install -y --no-install-recommends adduser ca-certificates curl dumb-init sudo \
99
&& rm -rf /var/lib/apt/lists/*
1010

11-
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash -s - && \
12-
apt-get install -y --no-install-recommends nodejs && \
13-
rm -rf /var/lib/apt/lists/*
14-
15-
# Install Chromium's system libraries without downloading a browser. The
16-
# non-root d2 init-playwright step below installs the single runtime copy.
17-
RUN npx --yes playwright@1.61.1 install-deps chromium \
18-
&& rm -rf /root/.npm /var/lib/apt/lists/*
19-
2011
RUN adduser --gecos '' --disabled-password debian \
2112
&& echo "debian ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd
2213

@@ -42,7 +33,6 @@ RUN mkdir -p /usr/local/lib/d2 \
4233
&& rm -Rf /tmp/d2-*-linux-"$TARGETARCH".tar.gz
4334

4435
USER debian:debian
45-
RUN CI=1 d2 init-playwright
4636

4737
WORKDIR /home/debian/src
4838
EXPOSE 8080

‎ci/release/docker/prepare_continuity_dockerfile_test.go‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@ func TestPrepareV082DockerfileMakesPlaywrightNonInteractive(t *testing.T) {
2020
}
2121
}
2222

23-
func TestReleaseDockerfileInstallsOnePlaywrightBrowser(t *testing.T) {
23+
func TestReleaseDockerfileKeepsRuntimeDependenciesMinimal(t *testing.T) {
2424
t.Parallel()
2525

2626
dockerfile, err := os.ReadFile("Dockerfile")
2727
if err != nil {
2828
t.Fatal(err)
2929
}
3030
source := string(dockerfile)
31-
if strings.Contains(source, "install --with-deps chromium") {
32-
t.Fatal("release Dockerfile downloads a root-owned Playwright browser")
31+
if !strings.Contains(source, "install -y --no-install-recommends adduser ") {
32+
t.Fatal("release Dockerfile does not install adduser explicitly")
3333
}
34-
if got := strings.Count(source, "install-deps chromium"); got != 1 {
35-
t.Fatalf("release Dockerfile has %d Playwright dependency installs, want 1", got)
36-
}
37-
if got := strings.Count(source, "RUN CI=1 d2 init-playwright"); got != 1 {
38-
t.Fatalf("release Dockerfile has %d runtime Playwright installs, want 1", got)
34+
for _, forbidden := range []string{"nodesource.com", "nodejs", "playwright", "init-playwright"} {
35+
if strings.Contains(strings.ToLower(source), forbidden) {
36+
t.Fatalf("release Dockerfile contains unexpected browser dependency %q", forbidden)
37+
}
3938
}
4039
}
4140

‎d2cli/export.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ func (ex exportExtension) supportsAnimation() bool {
5555
return ex == SVG || ex == GIF
5656
}
5757

58-
func (ex exportExtension) requiresPNGRenderer() bool {
59-
return ex == PNG || ex == PDF || ex == PPTX || ex == GIF
60-
}
61-
6258
func (ex exportExtension) supportsDarkTheme() bool {
6359
return ex == SVG
6460
}

‎d2cli/export_test.go‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func TestOutputFormat(t *testing.T) {
1414
supportsDarkTheme bool
1515
supportsAnimation bool
1616
requiresAnimationInterval bool
17-
requiresPngRender bool
1817
}
1918
testCases := []testCase{
2019
{
@@ -23,7 +22,6 @@ func TestOutputFormat(t *testing.T) {
2322
supportsDarkTheme: true,
2423
supportsAnimation: true,
2524
requiresAnimationInterval: false,
26-
requiresPngRender: false,
2725
},
2826
{
2927
// assumes SVG by default
@@ -32,15 +30,13 @@ func TestOutputFormat(t *testing.T) {
3230
supportsDarkTheme: true,
3331
supportsAnimation: true,
3432
requiresAnimationInterval: false,
35-
requiresPngRender: false,
3633
},
3734
{
3835
outputPath: "-",
3936
extension: SVG,
4037
supportsDarkTheme: true,
4138
supportsAnimation: true,
4239
requiresAnimationInterval: false,
43-
requiresPngRender: false,
4440
},
4541
{
4642
stdoutFormatFlag: "png",
@@ -49,39 +45,34 @@ func TestOutputFormat(t *testing.T) {
4945
supportsDarkTheme: false,
5046
supportsAnimation: false,
5147
requiresAnimationInterval: false,
52-
requiresPngRender: true,
5348
},
5449
{
5550
outputPath: "/out.png",
5651
extension: PNG,
5752
supportsDarkTheme: false,
5853
supportsAnimation: false,
5954
requiresAnimationInterval: false,
60-
requiresPngRender: true,
6155
},
6256
{
6357
outputPath: "/out.pptx",
6458
extension: PPTX,
6559
supportsDarkTheme: false,
6660
supportsAnimation: false,
6761
requiresAnimationInterval: false,
68-
requiresPngRender: true,
6962
},
7063
{
7164
outputPath: "/out.pdf",
7265
extension: PDF,
7366
supportsDarkTheme: false,
7467
supportsAnimation: false,
7568
requiresAnimationInterval: false,
76-
requiresPngRender: true,
7769
},
7870
{
7971
outputPath: "/out.gif",
8072
extension: GIF,
8173
supportsDarkTheme: false,
8274
supportsAnimation: true,
8375
requiresAnimationInterval: true,
84-
requiresPngRender: true,
8576
},
8677
}
8778

@@ -93,7 +84,6 @@ func TestOutputFormat(t *testing.T) {
9384
assert.Equal(t, tc.extension, extension)
9485
assert.Equal(t, tc.supportsAnimation, extension.supportsAnimation())
9586
assert.Equal(t, tc.supportsDarkTheme, extension.supportsDarkTheme())
96-
assert.Equal(t, tc.requiresPngRender, extension.requiresPNGRenderer())
9787
})
9888
}
9989
}

0 commit comments

Comments
 (0)