Skip to content

Commit

Permalink
Merge pull request #1614 from gavin-ts/code_font_size
Browse files Browse the repository at this point in the history
code shape: apply font-size to render
  • Loading branch information
gavin-ts authored Sep 25, 2023
2 parents 2490b44 + da1305b commit a9db03f
Show file tree
Hide file tree
Showing 8 changed files with 908 additions and 1 deletion.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- Fixes error with an empty nested grid [#1594](https://github.com/terrastruct/d2/issues/1594)
- Fixes incorrect `d2fmt` with variable substitution mid-string [#1611](https://github.com/terrastruct/d2/issues/1611)
- Fixes dagre error with child named id [#1610](https://github.com/terrastruct/d2/issues/1610)
- Fixes font-size missing from rendered code shape [#1614](https://github.com/terrastruct/d2/issues/1614)
8 changes: 7 additions & 1 deletion d2renderers/d2svg/d2svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,13 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
if !isLight {
class = "dark-code"
}
fmt.Fprintf(writer, `<g transform="translate(%f %f)" class="%s">`, box.TopLeft.X, box.TopLeft.Y, class)
var fontSize string
if targetShape.FontSize != d2fonts.FONT_SIZE_M {
fontSize = fmt.Sprintf(` style="font-size:%v"`, targetShape.FontSize)
}
fmt.Fprintf(writer, `<g transform="translate(%f %f)" class="%s"%s>`,
box.TopLeft.X, box.TopLeft.Y, class, fontSize,
)
rectEl := d2themes.NewThemableElement("rect")
rectEl.Width = float64(targetShape.Width)
rectEl.Height = float64(targetShape.Height)
Expand Down
1 change: 1 addition & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ cf many required: {
loadFromFile(t, "arrowhead_font_color"),
loadFromFile(t, "multiple_constant_nears"),
loadFromFile(t, "empty_nested_grid"),
loadFromFile(t, "code_font_size"),
}

runa(t, tcs)
Expand Down
25 changes: 25 additions & 0 deletions e2etests/testdata/files/code_font_size.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'Data' -- y
x -- 'Data'
'Data': {
style.fill: "#c8e9ad"
style.stroke: "#c8e9ad"
style.stroke-width: 15
ex: |go
Testing 001: AAA
Testing 002: BBB
Testing 003: CCC
Testing 004: DDD
Testing 005: EEE
Testing 006: FFF
Testing 007: GGG
Testing 008: HHH
Testing 009: III
Testing 010: JJJ
Testing 011: KKK
Testing 012: LLL
Testing 013: MMM
Testing 014: NNN
Testing 015: OOO
|
ex.style.font-size: 10
}
306 changes: 306 additions & 0 deletions e2etests/testdata/regression/code_font_size/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a9db03f

Please sign in to comment.