diff --git a/d2cli/main.go b/d2cli/main.go index faab24b1e..b10e7f64e 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -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() { diff --git a/d2renderers/d2fonts/d2fonts.go b/d2renderers/d2fonts/d2fonts.go index 606f2c937..3863444c3 100644 --- a/d2renderers/d2fonts/d2fonts.go +++ b/d2renderers/d2fonts/d2fonts.go @@ -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,