mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
82c41cea39
commit
4509f2aee4
@ -108,6 +108,13 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
op.Filter = ebiten.FilterLinear
|
op.Filter = ebiten.FilterLinear
|
||||||
text.DrawWithOptions(screen, sampleText, mplusNormalFont, op)
|
text.DrawWithOptions(screen, sampleText, mplusNormalFont, op)
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const x, y = 160, 240
|
||||||
|
const lineHeight = 80
|
||||||
|
b := text.BoundString(text.FaceWithLineHeight(mplusBigFont, lineHeight), sampleText)
|
||||||
|
ebitenutil.DrawRect(screen, float64(b.Min.X+x), float64(b.Min.Y+y), float64(b.Dx()), float64(b.Dy()), gray)
|
||||||
|
text.Draw(screen, sampleText, text.FaceWithLineHeight(mplusBigFont, lineHeight), x, y, color.White)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||||
|
40
text/text.go
40
text/text.go
@ -352,3 +352,43 @@ func CacheGlyphs(face font.Face, text string) {
|
|||||||
getGlyphImage(face, r)
|
getGlyphImage(face, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FaceWithLineHeight returns a font.Face with the given lineHeight in pixels.
|
||||||
|
// The returned face will otherwise have the same glyphs and metrics as face.
|
||||||
|
func FaceWithLineHeight(face font.Face, lineHeight float64) font.Face {
|
||||||
|
return faceWithLineHeight{
|
||||||
|
face: face,
|
||||||
|
lineHeight: fixed.Int26_6(lineHeight * (1 << 6)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type faceWithLineHeight struct {
|
||||||
|
face font.Face
|
||||||
|
lineHeight fixed.Int26_6
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f faceWithLineHeight) Close() error {
|
||||||
|
return f.face.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f faceWithLineHeight) Glyph(dot fixed.Point26_6, r rune) (dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ok bool) {
|
||||||
|
return f.face.Glyph(dot, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f faceWithLineHeight) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool) {
|
||||||
|
return f.face.GlyphBounds(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f faceWithLineHeight) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool) {
|
||||||
|
return f.face.GlyphAdvance(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f faceWithLineHeight) Kern(r0, r1 rune) fixed.Int26_6 {
|
||||||
|
return f.face.Kern(r0, r1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f faceWithLineHeight) Metrics() font.Metrics {
|
||||||
|
m := f.face.Metrics()
|
||||||
|
m.Height = f.lineHeight
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user