/fopix

Simple pixel monospaced font package for golang

Primary LanguageGoGNU General Public License v3.0GPL-3.0

fopix

Simple monospaced pixel font package for golang

Partly idea taken from: pixfont

Installation

go get github.com/toelsiba/fopix

Fonts

Font files are available in the directory fonts. Fonts is saved in JSON format.

Digits 3x3

digits-3x3

Digits 3x4

digits-3x4

Digits 3x5

digits-3x5

font-3x3-ascii

font-3x3-multiline

Victor

victor-ascii

victor-multiline

miniwi-ascii

miniwi-multiline

tom-thumb-ascii

tom-thumb-multiline

Tom Thumb New

tom-thumb-new-ascii

tom-thumb-new-multiline

Pixefon

pixefon-ascii

pixefon-multiline

cp437-table

cp437-text


Examples

using existing font

package main

import (
	"image"
	"log"

	"github.com/toelsiba/fopix"
	"github.com/toelsiba/fopix/imutil"
)

func checkError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {

	filename := "../../fonts/tom-thumb-new.json"

	var fi fopix.FontInfo
	err := fopix.ReadFileJSON(filename, &fi)
	checkError(err)

	d, err := fopix.NewDrawer(fi)
	checkError(err)

	d.SetScale(5)

	text := "Hello, World!"

	m := image.NewRGBA(d.TextBounds(text))

	d.DrawText(m, image.ZP, text)

	err = imutil.ImageSaveToPNG("hello-world.png", m)
	checkError(err)
}

Result image

hello-world

using custom font

package main

import (
	"image"
	"image/color"
	"log"

	"github.com/toelsiba/fopix"
	"github.com/toelsiba/fopix/imutil"
)

// custom font
var gopherFont = fopix.FontInfo{
	Name:        "Go font",
	Author:      "Gopher",
	Description: "something ...",
	Size:        fopix.Point{X: 6, Y: 7},
	AnchorPos:   fopix.Point{X: 0, Y: 0},
	TargetChar:  '0',
	CharSet: []fopix.RuneInfo{
		fopix.RuneInfo{
			Character: 'G',
			Bitmap: []string{
				"-000-",
				"0---0",
				"0----",
				"0-000",
				"0---0",
				"-000-",
			},
		},
		fopix.RuneInfo{
			Character: 'o',
			Bitmap: []string{
				"-----",
				"-----",
				"-000-",
				"0---0",
				"0---0",
				"-000-",
			},
		},
	},
}

func checkError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {

	d, err := fopix.NewDrawer(gopherFont)
	checkError(err)

	d.SetScale(10)
	d.SetColor(color.RGBA{0, 0, 0xFF, 0xFF})

	text := "Go"

	m := image.NewRGBA(d.TextBounds(text))

	imutil.ImageSolidFill(m, color.White)

	d.DrawText(m, image.ZP, text)

	err = imutil.ImageSaveToPNG("go-font.png", m)
	checkError(err)
}

Result image

go-font