errors that make more sense
This commit is contained in:
parent
c01beb6089
commit
54b501dc92
2 changed files with 14 additions and 7 deletions
|
|
@ -286,7 +286,8 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketc
|
|||
if !sketch {
|
||||
fontFamily, err = d2fonts.AddFont(font)
|
||||
if err != nil {
|
||||
ms.Log.Error.Printf("failed to load font %v, rendering with default font.", font)
|
||||
ms.Log.Error.Printf("failed to load font %v: %v.", font, err)
|
||||
ms.Log.Info.Printf("rendering with default font.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -222,14 +222,20 @@ func AddFont(fontLoc string) (FontFamily, error) {
|
|||
if fontLoc == "" {
|
||||
return "", nil
|
||||
}
|
||||
fontBuf, err := os.ReadFile(fontLoc)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read font: %v", err)
|
||||
}
|
||||
|
||||
splitFont := strings.Split(fontLoc, "/")
|
||||
fontFileName := splitFont[len(splitFont)-1]
|
||||
fontName := strings.TrimSuffix(fontFileName, filepath.Ext(fontFileName))
|
||||
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue