No more defaultfont until we actually make one
This commit is contained in:
parent
ae12945676
commit
83d0b32fba
@ -1,48 +0,0 @@
|
||||
// Package font provides a default font. Its data is entirely self contained.
|
||||
package font
|
||||
|
||||
import "golang.org/x/image/font/basicfont"
|
||||
|
||||
var FaceRegular = basicfont.Face7x13
|
||||
|
||||
// TODO: make bold, italic, and bold italic masks by processing the Face7x13
|
||||
// mask.
|
||||
|
||||
var FaceBold = &basicfont.Face {
|
||||
Advance: 7,
|
||||
Width: 6,
|
||||
Height: 13,
|
||||
Ascent: 11,
|
||||
Descent: 2,
|
||||
Mask: FaceRegular.Mask, // TODO
|
||||
Ranges: []basicfont.Range {
|
||||
{ '\u0020', '\u007f', 0 },
|
||||
{ '\ufffd', '\ufffe', 95 },
|
||||
},
|
||||
}
|
||||
|
||||
var FaceItalic = &basicfont.Face {
|
||||
Advance: 7,
|
||||
Width: 6,
|
||||
Height: 13,
|
||||
Ascent: 11,
|
||||
Descent: 2,
|
||||
Mask: FaceRegular.Mask, // TODO
|
||||
Ranges: []basicfont.Range {
|
||||
{ '\u0020', '\u007f', 0 },
|
||||
{ '\ufffd', '\ufffe', 95 },
|
||||
},
|
||||
}
|
||||
|
||||
var FaceBoldItalic = &basicfont.Face {
|
||||
Advance: 7,
|
||||
Width: 6,
|
||||
Height: 13,
|
||||
Ascent: 11,
|
||||
Descent: 2,
|
||||
Mask: FaceRegular.Mask, // TODO
|
||||
Ranges: []basicfont.Range {
|
||||
{ '\u0020', '\u007f', 0 },
|
||||
{ '\ufffd', '\ufffe', 95 },
|
||||
},
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package font
|
||||
|
||||
import "image"
|
||||
import "golang.org/x/image/font"
|
||||
import "golang.org/x/image/math/fixed"
|
||||
|
||||
// Face is a font face modeled of of basicfont.Face, but with variable glyph
|
||||
// width and kerning support.
|
||||
type Face struct {
|
||||
Width int
|
||||
Height int
|
||||
Ascent int
|
||||
Descent int
|
||||
Mask image.Image
|
||||
Ranges []Range
|
||||
Kerning map[[2]rune] int
|
||||
}
|
||||
|
||||
type Range struct {
|
||||
Low rune
|
||||
Glyphs []Glyph
|
||||
Offset int
|
||||
}
|
||||
|
||||
func (rang Range) Glyph (character rune) (glyph Glyph, offset int, ok bool) {
|
||||
character -= rang.Low
|
||||
ok = 0 < character && character > rune(len(rang.Glyphs))
|
||||
if !ok { return }
|
||||
glyph = rang.Glyphs[character]
|
||||
offset = rang.Offset + int(character)
|
||||
return
|
||||
}
|
||||
|
||||
type Glyph struct {
|
||||
Left, Advance int
|
||||
}
|
||||
|
||||
func (face *Face) Close () error { return nil }
|
||||
|
||||
func (face *Face) Kern (left, right rune) fixed.Int26_6 {
|
||||
return fixed.I(face.Kerning[[2]rune { left, right }])
|
||||
}
|
||||
|
||||
func (face *Face) Metrics () font.Metrics {
|
||||
return font.Metrics {
|
||||
Height: fixed.I(face.Height),
|
||||
Ascent: fixed.I(face.Ascent),
|
||||
Descent: fixed.I(face.Descent),
|
||||
XHeight: fixed.I(face.Ascent),
|
||||
CapHeight: fixed.I(face.Ascent),
|
||||
CaretSlope: image.Pt(0, 1),
|
||||
}
|
||||
}
|
||||
|
||||
func (face *Face) Glyph (
|
||||
dot fixed.Point26_6,
|
||||
character rune,
|
||||
) (
|
||||
destinationRectangle image.Rectangle,
|
||||
mask image.Image, maskPoint image.Point,
|
||||
advance fixed.Int26_6,
|
||||
ok bool,
|
||||
) {
|
||||
glyph, offset, has := face.findGlyph(character)
|
||||
if !has { ok = false; return }
|
||||
|
||||
advance = fixed.I(glyph.Advance)
|
||||
maskPoint.Y = offset * (face.Ascent + face.Descent)
|
||||
x := int(dot.X + 32) >> 6 + glyph.Left
|
||||
y := int(dot.Y + 32) >> 6
|
||||
destinationRectangle.Min.X = x
|
||||
destinationRectangle.Min.Y = y - face.Ascent
|
||||
destinationRectangle.Max.X = x + face.Width
|
||||
destinationRectangle.Max.Y = y + face.Descent
|
||||
return
|
||||
}
|
||||
|
||||
func (face *Face) GlyphBounds (
|
||||
character rune,
|
||||
) (
|
||||
bounds fixed.Rectangle26_6,
|
||||
advance fixed.Int26_6,
|
||||
ok bool,
|
||||
) {
|
||||
glyph, _, ok := face.findGlyph(character)
|
||||
return fixed.R(0, -face.Ascent, face.Width, face.Descent),
|
||||
fixed.I(glyph.Advance), ok
|
||||
|
||||
}
|
||||
|
||||
func (face *Face) GlyphAdvance (character rune) (advance fixed.Int26_6, ok bool) {
|
||||
glyph, _, ok := face.findGlyph(character)
|
||||
return fixed.I(glyph.Advance), ok
|
||||
}
|
||||
|
||||
func (face *Face) findGlyph (character rune) (glyph Glyph, offset int, ok bool) {
|
||||
for _, rang := range face.Ranges {
|
||||
glyph, offset, ok = rang.Glyph(character)
|
||||
if ok { return }
|
||||
}
|
||||
return Glyph { }, 0, false
|
||||
}
|
@ -6,11 +6,11 @@ import _ "embed"
|
||||
import _ "image/png"
|
||||
import "image/color"
|
||||
import "golang.org/x/image/font"
|
||||
import "golang.org/x/image/font/basicfont"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/data"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist/artutil"
|
||||
import defaultfont "git.tebibyte.media/sashakoshka/tomo/default/font"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
|
||||
|
||||
//go:embed assets/default.png
|
||||
@ -135,16 +135,7 @@ type Default struct { }
|
||||
|
||||
// FontFace returns the default font face.
|
||||
func (Default) FontFace (style tomo.FontStyle, size tomo.FontSize, c tomo.Case) font.Face {
|
||||
switch style {
|
||||
case tomo.FontStyleBold:
|
||||
return defaultfont.FaceBold
|
||||
case tomo.FontStyleItalic:
|
||||
return defaultfont.FaceItalic
|
||||
case tomo.FontStyleBoldItalic:
|
||||
return defaultfont.FaceBoldItalic
|
||||
default:
|
||||
return defaultfont.FaceRegular
|
||||
}
|
||||
return basicfont.Face7x13
|
||||
}
|
||||
|
||||
// Icon returns an icon from the default set corresponding to the given name.
|
||||
|
5
go.mod
5
go.mod
@ -6,7 +6,7 @@ require (
|
||||
git.tebibyte.media/sashakoshka/ezprof v0.0.0-20230309044548-401cba83602b
|
||||
github.com/faiface/beep v1.1.0
|
||||
github.com/jezek/xgbutil v0.0.0-20230403164920-e2f86723ca07
|
||||
golang.org/x/image v0.3.0
|
||||
golang.org/x/image v0.7.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -14,7 +14,7 @@ require (
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 // indirect
|
||||
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 // indirect
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
@ -22,4 +22,3 @@ require (
|
||||
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect
|
||||
github.com/jezek/xgb v1.1.0
|
||||
)
|
||||
|
||||
|
11
go.sum
11
go.sum
@ -43,15 +43,20 @@ golang.org/x/image v0.0.0-20190220214146-31aff87c08e9/go.mod h1:kZ7UVZpmo3dzQBMx
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.3.0 h1:HTDXbdK9bjfSWkPzDJIw89W8CAtfFGduujWs33NLLsg=
|
||||
golang.org/x/image v0.3.0/go.mod h1:fXd9211C/0VTlYuAcOhW8dY/RtEJqODXOWBDpmYBf+A=
|
||||
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
|
||||
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
|
||||
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 h1:vyLBGJPIl9ZYbcQFM2USFmJBK6KI+t+z6jL0lbwjrnc=
|
||||
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@ -61,13 +66,19 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
@ -6,11 +6,11 @@ import _ "embed"
|
||||
import _ "image/png"
|
||||
import "image/color"
|
||||
import "golang.org/x/image/font"
|
||||
import "golang.org/x/image/font/basicfont"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/data"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist/artutil"
|
||||
import defaultfont "git.tebibyte.media/sashakoshka/tomo/default/font"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
|
||||
|
||||
//go:embed assets/wintergreen.png
|
||||
@ -161,16 +161,7 @@ func init () {
|
||||
type Theme struct { }
|
||||
|
||||
func (Theme) FontFace (style tomo.FontStyle, size tomo.FontSize, c tomo.Case) font.Face {
|
||||
switch style {
|
||||
case tomo.FontStyleBold:
|
||||
return defaultfont.FaceBold
|
||||
case tomo.FontStyleItalic:
|
||||
return defaultfont.FaceItalic
|
||||
case tomo.FontStyleBoldItalic:
|
||||
return defaultfont.FaceBoldItalic
|
||||
default:
|
||||
return defaultfont.FaceRegular
|
||||
}
|
||||
return basicfont.Face7x13
|
||||
}
|
||||
|
||||
func (Theme) Icon (id tomo.Icon, size tomo.IconSize, c tomo.Case) artist.Icon {
|
||||
|
Reference in New Issue
Block a user