Commit graph

9 commits

Author SHA1 Message Date
Gavin Nishizawa
a67c186cae
d2fonts.FontFaces sync.Map 2023-10-24 16:40:56 -07:00
Gavin Nishizawa
14300dc9f8
update leading/trailing accounting 2023-06-19 17:09:36 -07:00
Gavin Nishizawa
14afd8c433
improve code measurement and rendering 2023-06-19 17:09:36 -07:00
Gavin Nishizawa
8fe2eee56d
lint 2023-03-14 11:20:00 -07:00
Alexander Wang
156c974241
unicode tests 2023-02-14 11:41:21 -08:00
Alexander Wang
9cb7e7f396
scale multi-width unicode 2023-02-14 11:40:49 -08:00
Kevin David
9ba1d85d21
d2graph: check that font family is entirely loaded before using it
I tested this by removing the changes I added in `d2fonts`, which led to:
```
[21:23:54] info: compiling GetUniqueColumnName-fix.d2...
[21:23:54] err: failed to compile: ruler does not have entire font family SourceCodePro loaded, is a style missing?
```

The error was also rendered in the UI.
2023-01-24 21:25:01 -05:00
Kevin David
bd7e18395e
d2renderers: d2fonts: add bold + italic styles for Source Code Pro
👋 I've been playing around with changing the entire font of a diagram to something fixed-width, starting by hand-editing `main.go`

I noticed that if I switched over the family to Source Code Pro, d2 crashed with the following stack:

```
[23:38:30] info: compiling GetUniqueColumnName-fix.d2...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x1c4 pc=0x16b562c]

goroutine 43 [running]:
github.com/golang/freetype/truetype.(*Font).Bounds(0xc000669670?, 0x0?)
        /Users/kevin/dev/go/pkg/mod/github.com/golang/freetype@v0.0.0-20170609003504-e2365dfdc4a0/truetype/truetype.go:378 +0xc
github.com/golang/freetype/truetype.NewFace(0x0, 0xc0003276c0)
        /Users/kevin/dev/go/pkg/mod/github.com/golang/freetype@v0.0.0-20170609003504-e2365dfdc4a0/truetype/face.go:199 +0x325
oss.terrastruct.com/d2/lib/textmeasure.(*Ruler).addFontSize(0xc00037c000, {{0x1bb9a34, 0xd}, {0x1b82732, 0x4}, 0x1f})
        /Users/kevin/dev/d2/lib/textmeasure/textmeasure.go:141 +0x112
oss.terrastruct.com/d2/lib/textmeasure.(*Ruler).MeasurePrecise(0xc00037c000, {{0x1bb9a34, 0xd}, {0x1b82732, 0x4}, 0x1f}, {0xc000582100, 0x1f})
        /Users/kevin/dev/d2/lib/textmeasure/textmeasure.go:157 +0xde
oss.terrastruct.com/d2/lib/textmeasure.(*Ruler).Measure(...)
        /Users/kevin/dev/d2/lib/textmeasure/textmeasure.go:151
oss.terrastruct.com/d2/d2graph.GetTextDimensions({0x0, 0x0, 0xc000657860?}, 0xc00037c000, 0xc000620280, 0xc000092020)
```

Which I tracked down to these missing styles, which appear to matter even if they aren't used.

I acquired the `ttf` files from https://fonts.google.com/specimen/Source+Code+Pro

I created the encoded fonts on my Mac with:
```
base64 -i SourceCodePro-Italic.ttf -o ../encoded/SourceCodePro-Italic.txt
```

Hopefully this is correct! Open to all feedback, especially since I think this is the first change I've ever made to a go program :)

Signed-off-by: Kevin David <kevin-david@github.com>
2023-01-23 00:35:19 -05:00
Anmol Sethi
c4ef432daf
Move textmeasure into lib
It's not a d2renderer.
2022-12-01 06:51:17 -08:00
Renamed from d2renderers/textmeasure/textmeasure.go (Browse further)