Merge remote-tracking branch 'upstream/master' into scenarios-a407

This commit is contained in:
Anmol Sethi 2023-02-02 10:32:20 -08:00
commit 09dc9fd12f
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA
25 changed files with 284 additions and 58 deletions

View file

@ -222,12 +222,16 @@ let us know and we'll be happy to include it here!
- **Python D2 diagram builder**: [https://github.com/MrBlenny/py-d2](https://github.com/MrBlenny/py-d2)
- **Clojure D2 transpiler**: [https://github.com/judepayne/dictim](https://github.com/judepayne/dictim)
- **JavaScript D2 diagram builder**: [https://github.com/Kreshnik/d2lang-js](https://github.com/Kreshnik/d2lang-js)
- **Maven plugin**: [https://github.com/andrinmeier/unofficial-d2lang-maven-plugin](https://github.com/andrinmeier/unofficial-d2lang-maven-plugin)
- **Confluence plugin**: [https://github.com/andrinmeier/unofficial-d2lang-confluence-plugin](https://github.com/andrinmeier/unofficial-d2lang-confluence-plugin)
- **CIL (C#, Visual Basic, F#, C++ CLR) to D2**: [https://github.com/HugoVG/AppDiagram](https://github.com/HugoVG/AppDiagram)
### Misc
- **Comparison site**: [https://github.com/terrastruct/text-to-diagram-site](https://github.com/terrastruct/text-to-diagram-site)
- **Playground**: [https://github.com/terrastruct/d2-playground](https://github.com/terrastruct/d2-playground)
- **Language docs**: [https://github.com/terrastruct/d2-docs](https://github.com/terrastruct/d2-docs)
- **Hosted icons**: [https://icons.terrastruct.com](https://icons.terrastruct.com)
## FAQ

View file

@ -16,6 +16,8 @@
#### Improvements 🧹
- Code snippets use bold and italic font styles as determined by highlighter [#710](https://github.com/terrastruct/d2/issues/710), [#741](https://github.com/terrastruct/d2/issues/741)
#### Bugfixes ⛑️
- Fixes groups overlapping in sequence diagrams when they end in a self loop. [#728](https://github.com/terrastruct/d2/pull/728)

View file

@ -1163,6 +1163,12 @@ func appendTextDedup(texts []*d2target.MText, t *d2target.MText) []*d2target.MTe
}
func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler, fontFamily *d2fonts.FontFamily) error {
if ruler != nil && fontFamily != nil {
if ok := ruler.HasFontFamilyLoaded(fontFamily); !ok {
return fmt.Errorf("ruler does not have entire font family %s loaded, is a style missing?", *fontFamily)
}
}
for _, obj := range g.Objects {
obj.Box = &geo.Box{}

View file

@ -78,6 +78,12 @@ var sourceSansProItalicBase64 string
//go:embed encoded/SourceCodePro-Regular.txt
var sourceCodeProRegularBase64 string
//go:embed encoded/SourceCodePro-Bold.txt
var sourceCodeProBoldBase64 string
//go:embed encoded/SourceCodePro-Italic.txt
var sourceCodeProItalicBase64 string
//go:embed encoded/ArchitectsDaughter-Regular.txt
var architectsDaughterRegularBase64 string
@ -108,6 +114,14 @@ func init() {
Family: SourceCodePro,
Style: FONT_STYLE_REGULAR,
}: sourceCodeProRegularBase64,
{
Family: SourceCodePro,
Style: FONT_STYLE_BOLD,
}: sourceCodeProBoldBase64,
{
Family: SourceCodePro,
Style: FONT_STYLE_ITALIC,
}: sourceCodeProItalicBase64,
{
Family: HandDrawn,
Style: FONT_STYLE_REGULAR,
@ -144,6 +158,22 @@ func init() {
Family: SourceCodePro,
Style: FONT_STYLE_REGULAR,
}] = b
b, err = fontFacesFS.ReadFile("ttf/SourceCodePro-Bold.ttf")
if err != nil {
panic(err)
}
FontFaces[Font{
Family: SourceCodePro,
Style: FONT_STYLE_BOLD,
}] = b
b, err = fontFacesFS.ReadFile("ttf/SourceCodePro-Italic.ttf")
if err != nil {
panic(err)
}
FontFaces[Font{
Family: SourceCodePro,
Style: FONT_STYLE_ITALIC,
}] = b
b, err = fontFacesFS.ReadFile("ttf/SourceSansPro-Bold.ttf")
if err != nil {
panic(err)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View file

@ -47,7 +47,8 @@ func styleAttr(styles map[chroma.TokenType]string, tt chroma.TokenType) string {
}
}
}
return styles[tt]
out := strings.Replace(styles[tt], `font-weight="bold"`, `class="text-mono-bold"`, -1)
return strings.Replace(out, `font-style="italic"`, `class="text-mono-italic"`, -1)
}
// <<< END

View file

@ -1181,6 +1181,44 @@ func embedFonts(buf *bytes.Buffer, fontFamily *d2fonts.FontFamily) {
}
}
triggers = []string{
`class="text-mono-bold"`,
}
for _, t := range triggers {
if strings.Contains(content, t) {
fmt.Fprintf(buf, `
.text-mono-bold {
font-family: "font-mono-bold";
}
@font-face {
font-family: font-mono-bold;
src: url("%s");
}`,
d2fonts.FontEncodings[d2fonts.SourceCodePro.Font(0, d2fonts.FONT_STYLE_BOLD)])
break
}
}
triggers = []string{
`class="text-mono-italic"`,
}
for _, t := range triggers {
if strings.Contains(content, t) {
fmt.Fprintf(buf, `
.text-mono-italic {
font-family: "font-mono-italic";
}
@font-face {
font-family: font-mono-italic;
src: url("%s");
}`,
d2fonts.FontEncodings[d2fonts.SourceCodePro.Font(0, d2fonts.FONT_STYLE_ITALIC)])
break
}
}
buf.WriteString(`]]></style>`)
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 350 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 350 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 512 KiB

After

Width:  |  Height:  |  Size: 601 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 512 KiB

After

Width:  |  Height:  |  Size: 601 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 508 KiB

After

Width:  |  Height:  |  Size: 673 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 508 KiB

After

Width:  |  Height:  |  Size: 673 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 669 KiB

After

Width:  |  Height:  |  Size: 758 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 669 KiB

After

Width:  |  Height:  |  Size: 758 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 513 KiB

After

Width:  |  Height:  |  Size: 602 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 513 KiB

After

Width:  |  Height:  |  Size: 602 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 513 KiB

After

Width:  |  Height:  |  Size: 602 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 513 KiB

After

Width:  |  Height:  |  Size: 602 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 854 KiB

After

Width:  |  Height:  |  Size: 943 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 854 KiB

After

Width:  |  Height:  |  Size: 942 KiB

View file

@ -15,6 +15,7 @@ import (
)
const TAB_SIZE = 4
const SIZELESS_FONT_SIZE = 0
// ASCII is a set of all ASCII runes. These runes are codepoints from 32 to 127 inclusive.
var ASCII []rune
@ -135,9 +136,25 @@ func NewRuler() (*Ruler, error) {
return r, nil
}
func (r *Ruler) HasFontFamilyLoaded(fontFamily *d2fonts.FontFamily) bool {
for _, fontStyle := range d2fonts.FontStyles {
font := d2fonts.Font{
Family: *fontFamily,
Style: fontStyle,
Size: SIZELESS_FONT_SIZE,
}
_, ok := r.ttfs[font]
if !ok {
return false
}
}
return true
}
func (r *Ruler) addFontSize(font d2fonts.Font) {
sizeless := font
sizeless.Size = 0
sizeless.Size = SIZELESS_FONT_SIZE
face := truetype.NewFace(r.ttfs[sizeless], &truetype.Options{
Size: float64(font.Size),
})