Added font saving braille

This commit is contained in:
Zoraiz 2021-09-03 19:39:24 +05:00
parent 26d910fc9d
commit d7df581771
7 changed files with 10 additions and 15 deletions

Binary file not shown.

View File

@ -61,11 +61,6 @@ func pathIsGif(gifPath, urlImgName string, pathIsURl bool, urlImgBytes []byte, l
return fmt.Errorf("can't decode %v: %v", gifPath, err) return fmt.Errorf("can't decode %v: %v", gifPath, err)
} }
// Error handled earlier to save time in case of long gif processing
if braille && saveGifPath != "" {
return fmt.Errorf("saving braille art as a gif is not supported")
}
var ( var (
asciiArtSet = make([]string, len(originalGif.Image)) asciiArtSet = make([]string, len(originalGif.Image))
gifFramesSlice = make([]GifFrame, len(originalGif.Image)) gifFramesSlice = make([]GifFrame, len(originalGif.Image))

View File

@ -58,9 +58,6 @@ func pathIsImage(imagePath, urlImgName string, pathIsURl bool, urlImgBytes []byt
// Save ascii art as .png image before printing it, if --save-img flag is passed // Save ascii art as .png image before printing it, if --save-img flag is passed
if saveImagePath != "" { if saveImagePath != "" {
if braille {
return "", fmt.Errorf("saving braille art as an image is not supported")
}
if err := createImageToSave( if err := createImageToSave(
asciiSet, asciiSet,
colored || grayscale, colored || grayscale,

View File

@ -142,6 +142,8 @@ func Convert(filePath string, flags Flags) (string, error) {
if tempFont, err = truetype.Parse(fontFile); err != nil { if tempFont, err = truetype.Parse(fontFile); err != nil {
return "", fmt.Errorf("unable to parse font file: %v", err) return "", fmt.Errorf("unable to parse font file: %v", err)
} }
} else if braille {
tempFont, _ = truetype.Parse(embeddedDejaVuObliqueFont)
} }
if path.Ext(filePath) == ".gif" { if path.Ext(filePath) == ".gif" {

View File

@ -88,11 +88,6 @@ func createGifFrameToSave(asciiArt [][]imgManip.AsciiChar, img image.Image, colo
dc.DrawImage(tempImg, 0, 0) dc.DrawImage(tempImg, 0, 0)
// Load embedded font
tempFont, err := truetype.Parse(embeddedFontFile)
if err != nil {
return nil, err
}
// Font size increased during assignment to become more visible. This will not affect image drawing // Font size increased during assignment to become more visible. This will not affect image drawing
fontFace := truetype.NewFace(tempFont, &truetype.Options{Size: fontSize * 1.5}) fontFace := truetype.NewFace(tempFont, &truetype.Options{Size: fontSize * 1.5})

View File

@ -28,13 +28,16 @@ import (
) )
//go:embed Hack-Regular.ttf //go:embed Hack-Regular.ttf
var embeddedFontFile []byte var embeddedHackRegularFont []byte
//go:embed DejaVuSans-Oblique.ttf
var embeddedDejaVuObliqueFont []byte
var tempFont *truetype.Font var tempFont *truetype.Font
// Load embedded font // Load embedded font
func init() { func init() {
tempFont, _ = truetype.Parse(embeddedFontFile) tempFont, _ = truetype.Parse(embeddedHackRegularFont)
} }
/* /*

3
aic_package/readme.md Normal file
View File

@ -0,0 +1,3 @@
## Note
The font `DejaVuSans-Oblique.ttf` is used for saving braille art .png images since it supports unicode and gave the best results. `Hack-Regular.ttf` is used for saving normal ascii art .png images.