Skip to content

Commit a9db03f

Browse files
authored
Merge pull request terrastruct#1614 from gavin-ts/code_font_size
code shape: apply font-size to render
2 parents 2490b44 + da1305b commit a9db03f

File tree

8 files changed

+908
-1
lines changed

8 files changed

+908
-1
lines changed

ci/release/changelogs/next.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
- Fixes error with an empty nested grid [#1594](https://github.com/terrastruct/d2/issues/1594)
2020
- Fixes incorrect `d2fmt` with variable substitution mid-string [#1611](https://github.com/terrastruct/d2/issues/1611)
2121
- Fixes dagre error with child named id [#1610](https://github.com/terrastruct/d2/issues/1610)
22+
- Fixes font-size missing from rendered code shape [#1614](https://github.com/terrastruct/d2/issues/1614)

d2renderers/d2svg/d2svg.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,13 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
12671267
if !isLight {
12681268
class = "dark-code"
12691269
}
1270-
fmt.Fprintf(writer, `<g transform="translate(%f %f)" class="%s">`, box.TopLeft.X, box.TopLeft.Y, class)
1270+
var fontSize string
1271+
if targetShape.FontSize != d2fonts.FONT_SIZE_M {
1272+
fontSize = fmt.Sprintf(` style="font-size:%v"`, targetShape.FontSize)
1273+
}
1274+
fmt.Fprintf(writer, `<g transform="translate(%f %f)" class="%s"%s>`,
1275+
box.TopLeft.X, box.TopLeft.Y, class, fontSize,
1276+
)
12711277
rectEl := d2themes.NewThemableElement("rect")
12721278
rectEl.Width = float64(targetShape.Width)
12731279
rectEl.Height = float64(targetShape.Height)

e2etests/regression_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ cf many required: {
10451045
loadFromFile(t, "arrowhead_font_color"),
10461046
loadFromFile(t, "multiple_constant_nears"),
10471047
loadFromFile(t, "empty_nested_grid"),
1048+
loadFromFile(t, "code_font_size"),
10481049
}
10491050

10501051
runa(t, tcs)
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'Data' -- y
2+
x -- 'Data'
3+
'Data': {
4+
style.fill: "#c8e9ad"
5+
style.stroke: "#c8e9ad"
6+
style.stroke-width: 15
7+
ex: |go
8+
Testing 001: AAA
9+
Testing 002: BBB
10+
Testing 003: CCC
11+
Testing 004: DDD
12+
Testing 005: EEE
13+
Testing 006: FFF
14+
Testing 007: GGG
15+
Testing 008: HHH
16+
Testing 009: III
17+
Testing 010: JJJ
18+
Testing 011: KKK
19+
Testing 012: LLL
20+
Testing 013: MMM
21+
Testing 014: NNN
22+
Testing 015: OOO
23+
|
24+
ex.style.font-size: 10
25+
}

e2etests/testdata/regression/code_font_size/dagre/board.exp.json

+306
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)