diff --git a/README.md b/README.md index 39a9b15..3b162d4 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Ensure you have your latest graphics card drivers installed before use. - Sixel support - Hints/overlays - Built-in patched fonts for powerline +- Retina display support ## Quick Start diff --git a/glfont/font.go b/glfont/font.go index 3b05f42..fe3c871 100644 --- a/glfont/font.go +++ b/glfont/font.go @@ -2,16 +2,14 @@ package glfont import ( "fmt" - "image" - "image/draw" - "io" - "math" - "github.com/go-gl/gl/all-core/gl" "github.com/golang/freetype" "github.com/golang/freetype/truetype" "golang.org/x/image/font" "golang.org/x/image/math/fixed" + "image" + "image/draw" + "io" ) const DPI = 72 @@ -83,9 +81,6 @@ func (f *Font) LinePadding() float32 { //Printf draws a string to the screen, takes a list of arguments like printf func (f *Font) Print(x, y float32, text string) error { - x = float32(math.Round(float64(x))) - y = float32(math.Round(float64(y))) - indices := []rune(text) if len(indices) == 0 { diff --git a/gui/fonts.go b/gui/fonts.go index 4f21cf1..5582e6d 100644 --- a/gui/fonts.go +++ b/gui/fonts.go @@ -10,12 +10,12 @@ import ( func (gui *GUI) getPackedFont(name string) (*glfont.Font, error) { box := packr.NewBox("./packed-fonts") - fontBytes, err := box.MustBytes(name) + fontBytes, err := box.Find(name) if err != nil { return nil, fmt.Errorf("packaged font '%s' could not be read: %s", name, err) } - font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale, gui.width, gui.height) + font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale/gui.scale(), gui.width, gui.height) if err != nil { return nil, fmt.Errorf("font '%s' failed to load: %v", name, err) } @@ -37,7 +37,13 @@ func (gui *GUI) loadFonts() error { return err } - gui.fontMap = NewFontMap(defaultFont, boldFont) + if gui.fontMap == nil { + gui.fontMap = NewFontMap(defaultFont, boldFont) + }else{ + gui.fontMap.defaultFont = defaultFont + gui.fontMap.defaultBoldFont = boldFont + } + // add special non-ascii fonts here diff --git a/gui/gui.go b/gui/gui.go index 55eaeff..026f41b 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -55,6 +55,12 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared // inspired by https://kylewbanks.com/blog/tutorial-opengl-with-golang-part-1-hello-opengl +func (gui *GUI) scale() float32{ + pw, _ := gui.window.GetFramebufferSize() + ww, _ := gui.window.GetSize() + return float32(ww) / float32(pw) +} + // can only be called on OS thread func (gui *GUI) resize(w *glfw.Window, width int, height int) { @@ -63,16 +69,11 @@ func (gui *GUI) resize(w *glfw.Window, width int, height int) { gui.width = width gui.height = height - ww, wh := w.GetSize() - - hScale := float32(ww) / float32(width) - vScale := float32(wh) / float32(height) - gui.logger.Debugf("Updating font resolutions...") - gui.fontMap.UpdateResolution(int(float32(width)*hScale), int(float32(height)*vScale)) + gui.loadFonts() gui.logger.Debugf("Setting renderer area...") - gui.renderer.SetArea(0, 0, int(float32(width)*hScale), int(float32(height)*vScale)) + gui.renderer.SetArea(0, 0, width, height) gui.logger.Debugf("Calculating size in cols/rows...") cols, rows := gui.renderer.GetTermSize() @@ -245,9 +246,11 @@ func (gui *GUI) Render() error { if gui.terminal.ActiveBuffer().InSelection(uint16(x), uint16(y)) { colour = &gui.config.ColourScheme.Selection } - - gui.renderer.DrawCellBg(cell, uint(x), uint(y), cursor, colour, false) - gui.renderer.DrawCellImage(cell, uint(x), uint(y)) + if cell.Image() != nil { + gui.renderer.DrawCellImage(cell, uint(x), uint(y)) + }else{ + gui.renderer.DrawCellBg(cell, uint(x), uint(y), cursor, colour, false) + } } } for y := 0; y < lineCount; y++ {