remove custom font cli
This commit is contained in:
parent
ffc414260e
commit
e5eeebefde
2 changed files with 0 additions and 61 deletions
|
|
@ -94,10 +94,6 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fontFlag := ms.Opts.String("FONT", "font", "", "", "the font used to render text (default \"Source Sans Pro\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ps, err := d2plugin.ListPlugins(ctx)
|
||||
if err != nil {
|
||||
|
|
@ -252,7 +248,6 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
|
|||
Center: *centerFlag,
|
||||
ThemeID: *themeFlag,
|
||||
DarkThemeID: darkThemeFlag,
|
||||
Font: *fontFlag,
|
||||
}
|
||||
|
||||
if *watchFlag {
|
||||
|
|
@ -297,16 +292,6 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, rende
|
|||
return nil, false, err
|
||||
}
|
||||
|
||||
// load custom fonts before initializing ruler
|
||||
var fontFamily d2fonts.FontFamily
|
||||
if !renderOpts.Sketch {
|
||||
fontFamily, err = d2fonts.AddFont(renderOpts.Font)
|
||||
if err != nil {
|
||||
ms.Log.Error.Printf("failed to load font %v: %v.", renderOpts.Font, err)
|
||||
ms.Log.Info.Printf("rendering with default font.")
|
||||
}
|
||||
}
|
||||
|
||||
ruler, err := textmeasure.NewRuler()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
|
|
@ -320,8 +305,6 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, rende
|
|||
}
|
||||
if renderOpts.Sketch {
|
||||
opts.FontFamily = go2.Pointer(d2fonts.HandDrawn)
|
||||
} else if fontFamily != "" {
|
||||
opts.FontFamily = go2.Pointer(fontFamily)
|
||||
}
|
||||
|
||||
cancel := background.Repeat(func() {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ import (
|
|||
"embed"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
fontlib "oss.terrastruct.com/d2/lib/font"
|
||||
|
|
@ -232,48 +230,6 @@ func init() {
|
|||
}] = b
|
||||
}
|
||||
|
||||
func AddFont(fontLoc string) (FontFamily, error) {
|
||||
if fontLoc == "" {
|
||||
return "", nil
|
||||
}
|
||||
fontFileName := filepath.Base(fontLoc)
|
||||
|
||||
ext := filepath.Ext(fontFileName)
|
||||
if ext != ".ttf" {
|
||||
return "", fmt.Errorf("cannot open non .ttf fonts")
|
||||
}
|
||||
|
||||
fontBuf, err := os.ReadFile(fontLoc)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read font at location %v", err)
|
||||
}
|
||||
|
||||
fontName := strings.TrimSuffix(fontFileName, ext)
|
||||
fontFamily := FontFamily(fontName)
|
||||
woffFont, err := fontlib.Sfnt2Woff(fontBuf)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to convert to woff font: %v", err)
|
||||
}
|
||||
|
||||
encodedWoff := fmt.Sprintf("data:application/font-woff;base64,%v", base64.StdEncoding.EncodeToString(woffFont))
|
||||
|
||||
// Encode all styles for now
|
||||
customFont := fontFamily.Font(0, FONT_STYLE_REGULAR)
|
||||
FontFaces[customFont] = fontBuf
|
||||
FontEncodings[customFont] = encodedWoff
|
||||
|
||||
customFont = fontFamily.Font(0, FONT_STYLE_BOLD)
|
||||
FontFaces[customFont] = fontBuf
|
||||
FontEncodings[customFont] = encodedWoff
|
||||
|
||||
customFont = fontFamily.Font(0, FONT_STYLE_ITALIC)
|
||||
FontFaces[customFont] = fontBuf
|
||||
FontEncodings[customFont] = encodedWoff
|
||||
|
||||
FontFamilies = append(FontFamilies, fontFamily)
|
||||
return fontFamily, nil
|
||||
}
|
||||
|
||||
var D2_FONT_TO_FAMILY = map[string]FontFamily{
|
||||
"default": SourceSansPro,
|
||||
"mono": SourceCodePro,
|
||||
|
|
|
|||
Loading…
Reference in a new issue