use plan9 fonts

This commit is contained in:
Camille Scholtz 2018-12-24 20:16:42 +01:00
parent 67c68f8a98
commit 99b906b870
76 changed files with 154 additions and 30 deletions

42
bar.go

@ -3,17 +3,20 @@ package main
import (
"fmt"
"image"
"os"
"io/ioutil"
"path"
"strconv"
"sync"
"github.com/BurntSushi/freetype-go/freetype/truetype"
"github.com/BurntSushi/xgb/xproto"
"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/ewmh"
"github.com/BurntSushi/xgbutil/xevent"
"github.com/BurntSushi/xgbutil/xgraphics"
"github.com/BurntSushi/xgbutil/xwindow"
"golang.org/x/image/font"
"golang.org/x/image/font/plan9font"
"golang.org/x/image/math/fixed"
)
// Bar is a struct with information about the bar.
@ -31,8 +34,7 @@ type Bar struct {
xsum int
// The font that should be used.
font *truetype.Font
size float64
face font.Face
// A map with information about the block, see the `Block` type.
block *sync.Map
@ -42,7 +44,7 @@ type Bar struct {
redraw chan *Block
}
func initBar(x, y, w, h int, font string, size float64) (*Bar, error) {
func initBar(x, y, w, h int, fp string) (*Bar, error) {
bar := new(Bar)
var err error
@ -107,19 +109,17 @@ func initBar(x, y, w, h int, font string, size float64) (*Bar, error) {
bar.h = h
// Load font.
// TODO: I don't *really* want to use `ttf` fonts but there doesn't seem to
// be any `pcf` Go library at the moment. I have tried the plan9 fonts,
// which do work, but honestly it's a pain in the ass (read: impossible) to
// convert muh cure font.
f, err := os.Open(font)
fr := func(name string) ([]byte, error) {
return ioutil.ReadFile(path.Join(path.Dir(fp), name))
}
fd, err := fr(path.Base(fp))
if err != nil {
return nil, err
}
bar.font, err = xgraphics.ParseFont(f)
bar.face, err = plan9font.ParseFont(fd, fr)
if err != nil {
return nil, err
}
bar.size = size
bar.block = new(sync.Map)
bar.redraw = make(chan *Block)
@ -133,7 +133,7 @@ func initBar(x, y, w, h int, font string, size float64) (*Bar, error) {
block = i.(*Block)
// XXX: Hack for music block.
if name == "music" {
tw, _ := xgraphics.Extents(bar.font, bar.size, block.txt)
tw := font.MeasureString(bar.face, block.txt).Ceil()
if ev.EventX > int16(block.x+(block.w-tw+(block.xoff*2))) && ev.
EventX < int16(block.x+block.w) {
return false
@ -156,9 +156,15 @@ func initBar(x, y, w, h int, font string, size float64) (*Bar, error) {
}
func (bar *Bar) draw(block *Block) error {
d := &font.Drawer{
Dst: block.img,
Src: image.NewUniform(hexToBGRA(block.fg)),
Face: bar.face,
}
// Calculate the required x coordinate for the different aligments.
tw, _ := xgraphics.Extents(bar.font, bar.size, block.txt)
var x int
tw := d.MeasureString(block.txt).Ceil()
switch block.align {
case 'l':
x = block.x
@ -187,12 +193,10 @@ func (bar *Bar) draw(block *Block) error {
})
// Draw the text.
// TODO: Center text vertically automatically.
if _, _, err := block.img.Text(x, 6, hexToBGRA(block.fg), bar.size, bar.
font, block.txt); err != nil {
return err
}
d.Dot = fixed.P(x, bar.face.Metrics().Ascent.Ceil()+9)
d.DrawString(block.txt)
// Redraw the bar.
block.img.XDraw()
bar.img.XPaint(bar.win.Id)

@ -36,10 +36,10 @@ func (bar *Bar) clockFun() {
}
}
func (bar *Bar) musicFun() error {
func (bar *Bar) musicFun() {
block := bar.initBlock("music", "?", 660, 'r', -13, "#3C4F5B", "#CCCCCC")
block.actions["button1"] = func() {
/*block.actions["button1"] = func() {
if block.popup == nil {
var err error
block.popup, err = bar.initPopup(1920-304-29, 29, 304, 148,
@ -52,7 +52,7 @@ func (bar *Bar) musicFun() error {
} else {
block.popup = block.popup.destroy()
}
}
}*/
block.actions["button3"] = func() {
conn, err := mpd.Dial("tcp", ":6600")
if err != nil {
@ -262,6 +262,11 @@ func (bar *Bar) windowFun() {
txt = "?"
}
}
if len(txt) > 30 {
txt = txt[0:30] + "..."
}
if block.txt == txt {
return
}

16
main.go

@ -6,27 +6,27 @@ import (
)
func main() {
bar, err := initBar(0, 0, 1920, 29, "/home/onodera/.fonts/cure.tff.bak", 11)
bar, err := initBar(0, 0, 1920, 29, "./vendor/font/proggytiny.font")
if err != nil {
log.Fatal(err)
}
// Run bar block functions. Make sure to sleep a millisecond after
// each block, else they won't appear in the right order.
// Run bar block functions. Make sure to sleep a millisecond after each
// block, else they won't appear in the right order.
go bar.windowFun()
time.Sleep(time.Millisecond)
time.Sleep(time.Millisecond * 5)
go bar.workspaceFun()
time.Sleep(time.Millisecond)
time.Sleep(time.Millisecond * 5)
go bar.clockFun()
time.Sleep(time.Millisecond)
time.Sleep(time.Millisecond * 5)
go bar.musicFun()
time.Sleep(time.Millisecond)
time.Sleep(time.Millisecond * 5)
go bar.todoFun()
time.Sleep(time.Millisecond)
time.Sleep(time.Millisecond * 5)
for {
if err := bar.draw(<-bar.redraw); err != nil {

BIN
vendor/font/fixed/6x10.0000 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.0100 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.0200 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.0300 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.0400 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.0500 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.1600 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.1E00 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.1F00 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.2000 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.2100 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.2200 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.2300 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.2400 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.2500 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.2600 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.2800 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.FB00 vendored Normal file

Binary file not shown.

BIN
vendor/font/fixed/6x10.FF00 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.005c vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.0391 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.0401 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.2010 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.2200 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.2500 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.2605 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.3000 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.4e00 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.5005 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.5200 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.5401 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.5606 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.5800 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.5a01 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.5c01 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.5e02 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.600e vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.6200 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.6406 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.6602 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.6802 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.6a02 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.6c08 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.6e05 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.7001 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.7206 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.7403 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.7601 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.7802 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.7a00 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.7c00 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.7e01 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.8000 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.8201 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.8403 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.8602 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.8805 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.8a00 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.8c37 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.8e08 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.9000 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.920d vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.9403 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.961c vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.9801 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.9a01 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.9c04 vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.9e1a vendored Normal file

Binary file not shown.

BIN
vendor/font/naga10/knj10.ff01 vendored Normal file

Binary file not shown.

51
vendor/font/naga10/knj10.font vendored Normal file

@ -0,0 +1,51 @@
10 8
0x005c 0x00f7 knj10.005c
0x0391 0x03c9 knj10.0391
0x0401 0x0451 knj10.0401
0x2010 0x21d4 knj10.2010
0x2200 0x2312 knj10.2200
0x2500 0x25ef knj10.2500
0x2605 0x266f knj10.2605
0x3000 0x30fe knj10.3000
0x4e00 0x4ffe knj10.4e00
0x5005 0x51fe knj10.5005
0x5200 0x53fa knj10.5200
0x5401 0x55fe knj10.5401
0x5606 0x57fc knj10.5606
0x5800 0x59ff knj10.5800
0x5a01 0x5bff knj10.5a01
0x5c01 0x5dfe knj10.5c01
0x5e02 0x5fff knj10.5e02
0x600e 0x61ff knj10.600e
0x6200 0x63fa knj10.6200
0x6406 0x65fb knj10.6406
0x6602 0x67ff knj10.6602
0x6802 0x69ff knj10.6802
0x6a02 0x6bf3 knj10.6a02
0x6c08 0x6dfb knj10.6c08
0x6e05 0x6ffe knj10.6e05
0x7001 0x71ff knj10.7001
0x7206 0x73fe knj10.7206
0x7403 0x75ff knj10.7403
0x7601 0x77fc knj10.7601
0x7802 0x79fb knj10.7802
0x7a00 0x7bf7 knj10.7a00
0x7c00 0x7dfb knj10.7c00
0x7e01 0x7ffc knj10.7e01
0x8000 0x81fe knj10.8000
0x8201 0x83fd knj10.8201
0x8403 0x85fe knj10.8403
0x8602 0x87fe knj10.8602
0x8805 0x89f8 knj10.8805
0x8a00 0x8b9a knj10.8a00
0x8c37 0x8dff knj10.8c37
0x8e08 0x8ffd knj10.8e08
0x9000 0x91ff knj10.9000
0x920d 0x93e8 knj10.920d
0x9403 0x95e5 knj10.9403
0x961c 0x97ff knj10.961c
0x9801 0x99ff knj10.9801
0x9a01 0x9bf5 knj10.9a01
0x9c04 0x9dfd knj10.9c04
0x9e1a 0x9fa0 knj10.9e1a
0xff01 0xffe5 knj10.ff01

BIN
vendor/font/proggytiny.0000-00FE vendored Normal file

Binary file not shown.

BIN
vendor/font/proggytiny.00FF-00FF vendored Normal file

Binary file not shown.

64
vendor/font/proggytiny.font vendored Normal file

@ -0,0 +1,64 @@
10 8
0x0000 0x001F fixed/6x10.2400
0x0000 0x00FE proggytiny.0000-00FE
0x00FF 0x00FF proggytiny.00FF-00FF
0x0100 0x01FF fixed/6x10.0100
0x0200 0x02FF fixed/6x10.0200
0x0300 0x03FF fixed/6x10.0300
0x0400 0x04FF fixed/6x10.0400
0x0500 0x05FF fixed/6x10.0500
0x1600 0x16FF fixed/6x10.1600
0x1E00 0x1EFF fixed/6x10.1E00
0x1F00 0x1FFF fixed/6x10.1F00
0x2000 0x20FF fixed/6x10.2000
0x2100 0x21FF fixed/6x10.2100
0x2200 0x22FF fixed/6x10.2200
0x2300 0x23FF fixed/6x10.2300
0x2400 0x24FF fixed/6x10.2400
0x2500 0x25FF fixed/6x10.2500
0x2600 0x26FF fixed/6x10.2600
0x2800 0x28FF fixed/6x10.2800
0x3000 0x30fe naga10/knj10.3000
0x4e00 0x4ffe naga10/knj10.4e00
0x5005 0x51fe naga10/knj10.5005
0x5200 0x53fa naga10/knj10.5200
0x5401 0x55fe naga10/knj10.5401
0x5606 0x57fc naga10/knj10.5606
0x5800 0x59ff naga10/knj10.5800
0x5a01 0x5bff naga10/knj10.5a01
0x5c01 0x5dfe naga10/knj10.5c01
0x5e02 0x5fff naga10/knj10.5e02
0x600e 0x61ff naga10/knj10.600e
0x6200 0x63fa naga10/knj10.6200
0x6406 0x65fb naga10/knj10.6406
0x6602 0x67ff naga10/knj10.6602
0x6802 0x69ff naga10/knj10.6802
0x6a02 0x6bf3 naga10/knj10.6a02
0x6c08 0x6dfb naga10/knj10.6c08
0x6e05 0x6ffe naga10/knj10.6e05
0x7001 0x71ff naga10/knj10.7001
0x7206 0x73fe naga10/knj10.7206
0x7403 0x75ff naga10/knj10.7403
0x7601 0x77fc naga10/knj10.7601
0x7802 0x79fb naga10/knj10.7802
0x7a00 0x7bf7 naga10/knj10.7a00
0x7c00 0x7dfb naga10/knj10.7c00
0x7e01 0x7ffc naga10/knj10.7e01
0x8000 0x81fe naga10/knj10.8000
0x8201 0x83fd naga10/knj10.8201
0x8403 0x85fe naga10/knj10.8403
0x8602 0x87fe naga10/knj10.8602
0x8805 0x89f8 naga10/knj10.8805
0x8a00 0x8b9a naga10/knj10.8a00
0x8c37 0x8dff naga10/knj10.8c37
0x8e08 0x8ffd naga10/knj10.8e08
0x9000 0x91ff naga10/knj10.9000
0x920d 0x93e8 naga10/knj10.920d
0x9403 0x95e5 naga10/knj10.9403
0x961c 0x97ff naga10/knj10.961c
0x9801 0x99ff naga10/knj10.9801
0x9a01 0x9bf5 naga10/knj10.9a01
0x9c04 0x9dfd naga10/knj10.9c04
0x9e1a 0x9fa0 naga10/knj10.9e1a
0xFB00 0xFBFF fixed/6x10.FB00
0xFF00 0xFFFF fixed/6x10.FF00