Merge pull request #710 from kevin-david/fonts
render: fonts: add bold + italic styles for Source Code Pro
This commit is contained in:
commit
b05ec48843
7 changed files with 56 additions and 1 deletions
|
|
@ -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 {
|
||||
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{}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
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 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),
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue