Thanks to visit codestin.com
Credit goes to github.com

Skip to content

svg: Text may overflow legend bounds when monospace font is used - #2674

Merged
alixander merged 1 commit into
d2lang:masterfrom
ocadaruma:fix-legend-width-on-mono
Oct 14, 2025
Merged

svg: Text may overflow legend bounds when monospace font is used#2674
alixander merged 1 commit into
d2lang:masterfrom
ocadaruma:fix-legend-width-on-mono

Conversation

@ocadaruma

@ocadaruma ocadaruma commented Oct 11, 2025

Copy link
Copy Markdown
Contributor

First, thanks a lot for providing great product as an open source!

Summary

  • When we create legend with certainly long text with monospace theme (e.g. Terminal), the text overflows the bound
  • The cause is d2svg doesn't pass font family when calculating text dimensions. As the result, the dimension is calculated based on SourceSansPro font even when mono is used.
  • The screenshot when this fix is applied:
    • image

Note

  • I plan to add e2e test, but I'm not sure about convention e.g. where we should place test and which layout engine should be target... etc.
    • Could you give me some advices about this? Thanks,

@alixander alixander left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clear report and PR!

You can add a test here:

https://github.com/terrastruct/d2/blob/master/e2etests/txtar.txt#L1072

If you use it with Terminal theme (https://github.com/terrastruct/d2/blob/master/e2etests/txtar.txt#L729), it should use the monospace font.

Everything else looks good to me

@ocadaruma
ocadaruma force-pushed the fix-legend-width-on-mono branch from 7b07fe3 to 0abb04f Compare October 12, 2025 11:57
@ocadaruma

Copy link
Copy Markdown
Contributor Author

@alixander Thank you for your advice! I added a test.

@ocadaruma
ocadaruma force-pushed the fix-legend-width-on-mono branch from 0abb04f to 1ade3c2 Compare October 12, 2025 23:46
@ocadaruma
ocadaruma requested a review from alixander October 13, 2025 04:11
@ocadaruma

Copy link
Copy Markdown
Contributor Author

I signed the commit to resolve CI failure. Could you take a look again?

@alixander alixander left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, ty again

@alixander
alixander merged commit 93f9720 into d2lang:master Oct 14, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants