mirror of
https://github.com/KevinMidboe/motdGOi.git
synced 2025-10-29 17:50:24 +00:00
add a public interface to load bindata fonts in addition to the built in ones
This commit is contained in:
@@ -122,18 +122,30 @@ func (fm *fontManager) loadBuildInFont() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Get the font
|
// Load the font
|
||||||
font, err := parseFontContent(string(fontStr))
|
err = fm.loadBinDataFont(string(fontStr), name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Register the font object in the fontLib
|
|
||||||
fm.fontLib[name] = font
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load a bindata font
|
||||||
|
func (fm *fontManager) loadBinDataFont(fontStr string, fontName string) error {
|
||||||
|
|
||||||
|
// Get the font
|
||||||
|
font, err := parseFontContent(fontStr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Register the font object in the fontLib
|
||||||
|
fm.fontLib[fontName] = font
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Parse a font from a content string
|
// Parse a font from a content string
|
||||||
// Used to load fonts from disk and the builtin fonts
|
// Used to load fonts from disk and the builtin fonts
|
||||||
func parseFontContent(cont string) (*font, error) {
|
func parseFontContent(cont string) (*font, error) {
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ func (ar *AsciiRender) LoadFont(fontPath string) error {
|
|||||||
return ar.fontMgr.loadFontList(fontPath)
|
return ar.fontMgr.loadFontList(fontPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadBinDataFont loads provided bindata font string
|
||||||
|
func (ar *AsciiRender) LoadBinDataFont(fontStr string, fontName string) error {
|
||||||
|
return ar.fontMgr.loadBinDataFont(fontStr, fontName)
|
||||||
|
}
|
||||||
|
|
||||||
// Render renders a string with the default options
|
// Render renders a string with the default options
|
||||||
// Calls the RenderOpts method with a new RenderOptions object
|
// Calls the RenderOpts method with a new RenderOptions object
|
||||||
func (ar *AsciiRender) Render(str string) (string, error) {
|
func (ar *AsciiRender) Render(str string) (string, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user