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
|
||||
height int //window height in pixels
|
||||
font *glfont.Font
|
||||
boldFont *glfont.Font
|
||||
fontScale float32
|
||||
renderer *OpenGLRenderer
|
||||
colourAttr uint32
|
||||
|
@ -38,7 +39,7 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared
|
|||
width: 600,
|
||||
height: 300,
|
||||
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 {
|
||||
gui.font.UpdateResolution((width), (height))
|
||||
}
|
||||
if gui.boldFont != nil {
|
||||
gui.boldFont.UpdateResolution((width), (height))
|
||||
}
|
||||
|
||||
gui.logger.Debugf("Setting renderer area...")
|
||||
gui.renderer.SetArea(0, 0, gui.width, gui.height)
|
||||
|
@ -123,7 +127,7 @@ func (gui *GUI) Render() error {
|
|||
|
||||
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.SetKeyCallback(gui.key)
|
||||
|
@ -250,6 +254,21 @@ func (gui *GUI) loadDefaultFont() error {
|
|||
return fmt.Errorf("LoadFont: %v", err)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
type OpenGLRenderer struct {
|
||||
font *glfont.Font
|
||||
boldFont *glfont.Font
|
||||
areaWidth int
|
||||
areaHeight int
|
||||
areaX int
|
||||
|
@ -126,7 +127,7 @@ func (rect *rectangle) Free() {
|
|||
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{
|
||||
areaWidth: areaWidth,
|
||||
areaHeight: areaHeight,
|
||||
|
@ -138,7 +139,7 @@ func NewOpenGLRenderer(config *config.Config, font *glfont.Font, areaX int, area
|
|||
colourAttr: colourAttr,
|
||||
program: program,
|
||||
}
|
||||
r.SetFont(font)
|
||||
r.SetFont(font, boldFont)
|
||||
return r
|
||||
}
|
||||
|
||||
|
@ -151,11 +152,12 @@ func (r *OpenGLRenderer) SetArea(areaX int, areaY int, areaWidth int, areaHeight
|
|||
r.areaHeight = areaHeight
|
||||
r.areaX = areaX
|
||||
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.boldFont = bold
|
||||
r.cellWidth, _ = font.Size("X")
|
||||
r.cellHeight = font.LineHeight() // vertical padding
|
||||
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())
|
||||
|
||||
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, y, string(cell.Rune()))
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue