mirror of https://github.com/liamg/aminal.git
Merge pull request #36 from liamg/improve-font-rendering
improve font rendering
This commit is contained in:
commit
650bac81d4
File diff suppressed because one or more lines are too long
23
gui/gui.go
23
gui/gui.go
|
@ -25,6 +25,7 @@ type GUI struct {
|
||||||
width int //window width in pixels
|
width int //window width in pixels
|
||||||
height int //window height in pixels
|
height int //window height in pixels
|
||||||
font *glfont.Font
|
font *glfont.Font
|
||||||
|
boldFont *glfont.Font
|
||||||
fontScale float32
|
fontScale float32
|
||||||
renderer *OpenGLRenderer
|
renderer *OpenGLRenderer
|
||||||
colourAttr uint32
|
colourAttr uint32
|
||||||
|
@ -38,7 +39,7 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared
|
||||||
width: 600,
|
width: 600,
|
||||||
height: 300,
|
height: 300,
|
||||||
terminal: terminal,
|
terminal: terminal,
|
||||||
fontScale: 15.0,
|
fontScale: 14.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +57,9 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) {
|
||||||
if gui.font != nil {
|
if gui.font != nil {
|
||||||
gui.font.UpdateResolution((width), (height))
|
gui.font.UpdateResolution((width), (height))
|
||||||
}
|
}
|
||||||
|
if gui.boldFont != nil {
|
||||||
|
gui.boldFont.UpdateResolution((width), (height))
|
||||||
|
}
|
||||||
|
|
||||||
gui.logger.Debugf("Setting renderer area...")
|
gui.logger.Debugf("Setting renderer area...")
|
||||||
gui.renderer.SetArea(0, 0, gui.width, gui.height)
|
gui.renderer.SetArea(0, 0, gui.width, gui.height)
|
||||||
|
@ -123,7 +127,7 @@ func (gui *GUI) Render() error {
|
||||||
|
|
||||||
titleChan := make(chan bool, 1)
|
titleChan := make(chan bool, 1)
|
||||||
|
|
||||||
gui.renderer = NewOpenGLRenderer(gui.config, gui.font, 0, 0, gui.width, gui.height, gui.colourAttr, program)
|
gui.renderer = NewOpenGLRenderer(gui.config, gui.font, gui.boldFont, 0, 0, gui.width, gui.height, gui.colourAttr, program)
|
||||||
|
|
||||||
gui.window.SetFramebufferSizeCallback(gui.resize)
|
gui.window.SetFramebufferSizeCallback(gui.resize)
|
||||||
gui.window.SetKeyCallback(gui.key)
|
gui.window.SetKeyCallback(gui.key)
|
||||||
|
@ -250,6 +254,21 @@ func (gui *GUI) loadDefaultFont() error {
|
||||||
return fmt.Errorf("LoadFont: %v", err)
|
return fmt.Errorf("LoadFont: %v", err)
|
||||||
}
|
}
|
||||||
gui.font = font
|
gui.font = font
|
||||||
|
|
||||||
|
{
|
||||||
|
fontBytes, err := box.MustBytes("Hack-Bold.ttf")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Packaged font could not be read: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale, gui.width, gui.height)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("LoadFont: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.boldFont = font
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
type OpenGLRenderer struct {
|
type OpenGLRenderer struct {
|
||||||
font *glfont.Font
|
font *glfont.Font
|
||||||
|
boldFont *glfont.Font
|
||||||
areaWidth int
|
areaWidth int
|
||||||
areaHeight int
|
areaHeight int
|
||||||
areaX int
|
areaX int
|
||||||
|
@ -126,7 +127,7 @@ func (rect *rectangle) Free() {
|
||||||
gl.DeleteBuffers(1, &rect.cv)
|
gl.DeleteBuffers(1, &rect.cv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOpenGLRenderer(config *config.Config, font *glfont.Font, areaX int, areaY int, areaWidth int, areaHeight int, colourAttr uint32, program uint32) *OpenGLRenderer {
|
func NewOpenGLRenderer(config *config.Config, font *glfont.Font, boldFont *glfont.Font, areaX int, areaY int, areaWidth int, areaHeight int, colourAttr uint32, program uint32) *OpenGLRenderer {
|
||||||
r := &OpenGLRenderer{
|
r := &OpenGLRenderer{
|
||||||
areaWidth: areaWidth,
|
areaWidth: areaWidth,
|
||||||
areaHeight: areaHeight,
|
areaHeight: areaHeight,
|
||||||
|
@ -138,7 +139,7 @@ func NewOpenGLRenderer(config *config.Config, font *glfont.Font, areaX int, area
|
||||||
colourAttr: colourAttr,
|
colourAttr: colourAttr,
|
||||||
program: program,
|
program: program,
|
||||||
}
|
}
|
||||||
r.SetFont(font)
|
r.SetFont(font, boldFont)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,11 +152,12 @@ func (r *OpenGLRenderer) SetArea(areaX int, areaY int, areaWidth int, areaHeight
|
||||||
r.areaHeight = areaHeight
|
r.areaHeight = areaHeight
|
||||||
r.areaX = areaX
|
r.areaX = areaX
|
||||||
r.areaY = areaY
|
r.areaY = areaY
|
||||||
r.SetFont(r.font)
|
r.SetFont(r.font, r.boldFont)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *OpenGLRenderer) SetFont(font *glfont.Font) { // @todo check for monospace and return error if not?
|
func (r *OpenGLRenderer) SetFont(font *glfont.Font, bold *glfont.Font) { // @todo check for monospace and return error if not?
|
||||||
r.font = font
|
r.font = font
|
||||||
|
r.boldFont = bold
|
||||||
r.cellWidth, _ = font.Size("X")
|
r.cellWidth, _ = font.Size("X")
|
||||||
r.cellHeight = font.LineHeight() // vertical padding
|
r.cellHeight = font.LineHeight() // vertical padding
|
||||||
r.termCols = uint(math.Floor(float64(float32(r.areaWidth) / r.cellWidth)))
|
r.termCols = uint(math.Floor(float64(float32(r.areaWidth) / r.cellWidth)))
|
||||||
|
@ -229,8 +231,15 @@ func (r *OpenGLRenderer) DrawCellText(cell buffer.Cell, col uint, row uint) {
|
||||||
y := (float32(row+1) * r.cellHeight) - (r.font.LinePadding())
|
y := (float32(row+1) * r.cellHeight) - (r.font.LinePadding())
|
||||||
|
|
||||||
if cell.Attr().Bold { // bold means draw text again one pixel to right, so it's fatter
|
if cell.Attr().Bold { // bold means draw text again one pixel to right, so it's fatter
|
||||||
|
if r.boldFont != nil {
|
||||||
|
y := (float32(row+1) * r.cellHeight) - (r.boldFont.LinePadding())
|
||||||
|
r.boldFont.SetColor(fg[0], fg[1], fg[2], alpha)
|
||||||
|
r.boldFont.Print(x, y, string(cell.Rune()))
|
||||||
|
return
|
||||||
|
}
|
||||||
r.font.Print(x+1, y, string(cell.Rune()))
|
r.font.Print(x+1, y, string(cell.Rune()))
|
||||||
}
|
}
|
||||||
|
|
||||||
r.font.Print(x, y, string(cell.Rune()))
|
r.font.Print(x, y, string(cell.Rune()))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue