Skip to content

Commit

Permalink
Added font saving braille
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZoraiz committed Sep 3, 2021
1 parent 26d910f commit d7df581
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 15 deletions.
Binary file added aic_package/DejaVuSans-Oblique.ttf
Binary file not shown.
5 changes: 0 additions & 5 deletions aic_package/convert_gif.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ func pathIsGif(gifPath, urlImgName string, pathIsURl bool, urlImgBytes []byte, l
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 (
asciiArtSet = make([]string, len(originalGif.Image))
gifFramesSlice = make([]GifFrame, len(originalGif.Image))
Expand Down
3 changes: 0 additions & 3 deletions aic_package/convert_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
if saveImagePath != "" {
if braille {
return "", fmt.Errorf("saving braille art as an image is not supported")
}
if err := createImageToSave(
asciiSet,
colored || grayscale,
Expand Down
2 changes: 2 additions & 0 deletions aic_package/convert_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func Convert(filePath string, flags Flags) (string, error) {
if tempFont, err = truetype.Parse(fontFile); err != nil {
return "", fmt.Errorf("unable to parse font file: %v", err)
}
} else if braille {
tempFont, _ = truetype.Parse(embeddedDejaVuObliqueFont)
}

if path.Ext(filePath) == ".gif" {
Expand Down
5 changes: 0 additions & 5 deletions aic_package/create_ascii_gif.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ func createGifFrameToSave(asciiArt [][]imgManip.AsciiChar, img image.Image, colo

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
fontFace := truetype.NewFace(tempFont, &truetype.Options{Size: fontSize * 1.5})

Expand Down
7 changes: 5 additions & 2 deletions aic_package/create_ascii_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ import (
)

//go:embed Hack-Regular.ttf
var embeddedFontFile []byte
var embeddedHackRegularFont []byte

//go:embed DejaVuSans-Oblique.ttf
var embeddedDejaVuObliqueFont []byte

var tempFont *truetype.Font

// Load embedded font
func init() {
tempFont, _ = truetype.Parse(embeddedFontFile)
tempFont, _ = truetype.Parse(embeddedHackRegularFont)
}

/*
Expand Down
3 changes: 3 additions & 0 deletions aic_package/readme.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit d7df581

Please sign in to comment.