Merge branch 'terrastruct:master' into master
This commit is contained in:
commit
61bf09107a
8 changed files with 57 additions and 1 deletions
|
|
@ -228,6 +228,7 @@ let us know and we'll be happy to include it here!
|
||||||
- **Comparison site**: [https://github.com/terrastruct/text-to-diagram-site](https://github.com/terrastruct/text-to-diagram-site)
|
- **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)
|
- **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)
|
- **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
|
## FAQ
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1090,6 +1090,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 {
|
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 {
|
for _, obj := range g.Objects {
|
||||||
obj.Box = &geo.Box{}
|
obj.Box = &geo.Box{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,12 @@ var sourceSansProItalicBase64 string
|
||||||
//go:embed encoded/SourceCodePro-Regular.txt
|
//go:embed encoded/SourceCodePro-Regular.txt
|
||||||
var sourceCodeProRegularBase64 string
|
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
|
//go:embed encoded/ArchitectsDaughter-Regular.txt
|
||||||
var architectsDaughterRegularBase64 string
|
var architectsDaughterRegularBase64 string
|
||||||
|
|
||||||
|
|
@ -108,6 +114,14 @@ func init() {
|
||||||
Family: SourceCodePro,
|
Family: SourceCodePro,
|
||||||
Style: FONT_STYLE_REGULAR,
|
Style: FONT_STYLE_REGULAR,
|
||||||
}: sourceCodeProRegularBase64,
|
}: sourceCodeProRegularBase64,
|
||||||
|
{
|
||||||
|
Family: SourceCodePro,
|
||||||
|
Style: FONT_STYLE_BOLD,
|
||||||
|
}: sourceCodeProBoldBase64,
|
||||||
|
{
|
||||||
|
Family: SourceCodePro,
|
||||||
|
Style: FONT_STYLE_ITALIC,
|
||||||
|
}: sourceCodeProItalicBase64,
|
||||||
{
|
{
|
||||||
Family: HandDrawn,
|
Family: HandDrawn,
|
||||||
Style: FONT_STYLE_REGULAR,
|
Style: FONT_STYLE_REGULAR,
|
||||||
|
|
@ -144,6 +158,22 @@ func init() {
|
||||||
Family: SourceCodePro,
|
Family: SourceCodePro,
|
||||||
Style: FONT_STYLE_REGULAR,
|
Style: FONT_STYLE_REGULAR,
|
||||||
}] = b
|
}] = 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")
|
b, err = fontFacesFS.ReadFile("ttf/SourceSansPro-Bold.ttf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
1
d2renderers/d2fonts/encoded/SourceCodePro-Bold.txt
Normal file
1
d2renderers/d2fonts/encoded/SourceCodePro-Bold.txt
Normal file
File diff suppressed because one or more lines are too long
1
d2renderers/d2fonts/encoded/SourceCodePro-Italic.txt
Normal file
1
d2renderers/d2fonts/encoded/SourceCodePro-Italic.txt
Normal file
File diff suppressed because one or more lines are too long
BIN
d2renderers/d2fonts/ttf/SourceCodePro-Bold.ttf
Normal file
BIN
d2renderers/d2fonts/ttf/SourceCodePro-Bold.ttf
Normal file
Binary file not shown.
BIN
d2renderers/d2fonts/ttf/SourceCodePro-Italic.ttf
Normal file
BIN
d2renderers/d2fonts/ttf/SourceCodePro-Italic.ttf
Normal file
Binary file not shown.
|
|
@ -15,6 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const TAB_SIZE = 4
|
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.
|
// ASCII is a set of all ASCII runes. These runes are codepoints from 32 to 127 inclusive.
|
||||||
var ASCII []rune
|
var ASCII []rune
|
||||||
|
|
@ -135,9 +136,25 @@ func NewRuler() (*Ruler, error) {
|
||||||
return r, nil
|
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) {
|
func (r *Ruler) addFontSize(font d2fonts.Font) {
|
||||||
sizeless := font
|
sizeless := font
|
||||||
sizeless.Size = 0
|
sizeless.Size = SIZELESS_FONT_SIZE
|
||||||
face := truetype.NewFace(r.ttfs[sizeless], &truetype.Options{
|
face := truetype.NewFace(r.ttfs[sizeless], &truetype.Options{
|
||||||
Size: float64(font.Size),
|
Size: float64(font.Size),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue