Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/neoray/context_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func (menu *ContextMenu) SetFontKit(kit *fontkit.FontKit) {
MarkForceDraw()
}

func (menu *ContextMenu) SetFallbackFontKit(kit *fontkit.FontKit) {
menu.renderer.SetFallbackFontKit(kit)
MarkForceDraw()
}

func (menu *ContextMenu) SetFontSize(size float64) {
menu.renderer.SetFontSize(size, Editor.window.DPI())
MarkForceDraw()
Expand Down
4 changes: 4 additions & 0 deletions cmd/neoray/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (grid *Grid) SetFontKit(kit *fontkit.FontKit) {
grid.renderer.SetFontKit(kit)
}

func (grid *Grid) SetFontFallbackKit(kit *fontkit.FontKit) {
grid.renderer.SetFallbackFontKit(kit)
}

func (grid *Grid) SetFontSize(fontSize, dpi float64) {
grid.renderer.SetFontSize(fontSize, dpi)
}
Expand Down
19 changes: 19 additions & 0 deletions cmd/neoray/grid_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type GridManager struct {
// These are used for creating new grids
totalGridsCreated int // total number of grids created (including deleted ones)
kit *fontkit.FontKit // last globally set font kit
fallbackKit *fontkit.FontKit // last globally set font fallback
fontSize float64 // last globally set font size
// style information
attributes map[int]HighlightAttribute
Expand Down Expand Up @@ -52,6 +53,24 @@ func (manager *GridManager) SetGridFontKit(id int, kit *fontkit.FontKit) {
MarkForceDraw()
}

func (manager *GridManager) SetGridFallbackFontKit(id int, kit *fontkit.FontKit) {
if id == 1 {
for _, grid := range manager.grids {
grid.SetFontFallbackKit(kit)
}
manager.fallbackKit = kit
manager.CheckDefaultGridSize()
} else {
grid := manager.Grid(id)
if grid != nil {
prevSize := grid.Size()
grid.SetFontFallbackKit(kit)
manager.CheckGridSize(grid, prevSize)
}
}
MarkForceDraw()
}

func (manager *GridManager) ResetFontSize() {
for _, grid := range manager.grids {
grid.SetFontSize(grid.renderer.FontSize(), Editor.window.DPI())
Expand Down
5 changes: 5 additions & 0 deletions cmd/neoray/grid_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func (renderer *GridRenderer) SetFontKit(kit *fontkit.FontKit) {
renderer.UpdatePositions()
}

func (renderer *GridRenderer) SetFallbackFontKit(kit *fontkit.FontKit) {
renderer.atlas.SetFallbackFontKit(kit)
renderer.UpdatePositions()
}

func (renderer *GridRenderer) FontSize() float64 {
return renderer.atlas.FontSize()
}
Expand Down
31 changes: 30 additions & 1 deletion cmd/neoray/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ func (options *UIOptions) setGuiFont(guifont string) {
guifont = strings.ReplaceAll(guifont, "_", " ")
// parse font options
fontOptions := strings.Split(guifont, ":")
name := fontOptions[0]
fontNames := strings.Split(fontOptions[0], ",")
name := fontNames[0]
fallbackName := ""
if len(fontNames) >= 2 {
fallbackName = fontNames[1]
}
for _, opt := range fontOptions[1:] {
if len(opt) > 1 && opt[0] == 'h' {
// Font size
Expand Down Expand Up @@ -82,6 +87,30 @@ func (options *UIOptions) setGuiFont(guifont string) {
Editor.contextMenu.SetFontKit(kit)
}
}
if fallbackName != "" {
logger.Log(logger.TRACE, "Loading fallback font", fallbackName)
kit, err := fontkit.CreateKit(fallbackName)
if err != nil {
Editor.nvim.EchoError("Fallback font %s not found", fallbackName)
} else {
// Log some info
if kit.Regular() != nil {
logger.Log(logger.TRACE, "Regular:", kit.Regular().FilePath())
}
if kit.Bold() != nil {
logger.Log(logger.TRACE, "Bold:", kit.Bold().FilePath())
}
if kit.Italic() != nil {
logger.Log(logger.TRACE, "Italic:", kit.Italic().FilePath())
}
if kit.BoldItalic() != nil {
logger.Log(logger.TRACE, "BoldItalic:", kit.BoldItalic().FilePath())
}
// Set fallback font
Editor.gridManager.SetGridFallbackFontKit(1, kit)
Editor.contextMenu.SetFallbackFontKit(kit)
}
}
// Always set font size to default if user not set
Editor.gridManager.SetGridFontSize(1, size)
Editor.contextMenu.SetFontSize(size)
Expand Down
7 changes: 4 additions & 3 deletions pkg/fontfinder/fontfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func init() {
// Because of this we are doing this in initilization and in another
// goroutine. Updates systemFontListReady value to true when finished.
// And Find() will wait for this to be done only for first time.
systemFontListGuard.Lock()
go func() {
systemFontListGuard.Lock()
defer systemFontListGuard.Unlock()
finder := sysfont.NewFinder(&sysfont.FinderOpts{
Extensions: []string{".ttf", ".otf"},
Expand Down Expand Up @@ -153,8 +153,9 @@ func sortFileNameLen(fonts *[]fontSearchInfo) {

// Splits string to words according to delimiters and casing.
// Example:
// This: "HelloWorld_from-Turkey"
// Turns to this: [Hello, World, from, Turkey]
//
// This: "HelloWorld_from-Turkey"
// Turns to this: [Hello, World, from, Turkey]
func splitWords(str string) []string {
// CamelCase pascalCase and "-_ "
arr := []string{}
Expand Down
18 changes: 18 additions & 0 deletions pkg/opengl/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (

type Atlas struct {
kit *fontkit.FontKit
fallback *fontkit.FontKit
fontSize, dpi float64
useBoxDrawing bool
useBlockDrawing bool
Expand Down Expand Up @@ -74,6 +75,17 @@ func (atlas *Atlas) SetFontKit(kit *fontkit.FontKit) {
atlas.Reset()
}

func (atlas *Atlas) FallbackFontKit() *fontkit.FontKit {
if atlas.fallback != nil {
return atlas.fallback
}
return fontkit.Default()
}

func (atlas *Atlas) SetFallbackFontKit(kit *fontkit.FontKit) {
atlas.fallback = kit
}

func (atlas *Atlas) FontSize() float64 {
return atlas.fontSize
}
Expand Down Expand Up @@ -169,6 +181,12 @@ func (atlas *Atlas) suitableFont(char rune, bold, italic bool) (*fontkit.Font, b
if atlas.FontKit().DefaultFont().ContainsGlyph(char) {
return atlas.FontKit().DefaultFont(), true
}
if atlas.FallbackFontKit().SuitableFont(bold, italic).ContainsGlyph(char) {
return atlas.FallbackFontKit().SuitableFont(bold, italic), true
}
if atlas.FallbackFontKit().DefaultFont().ContainsGlyph(char) {
return atlas.FallbackFontKit().DefaultFont(), true
}
if fontkit.Default().SuitableFont(bold, italic).ContainsGlyph(char) {
return fontkit.Default().SuitableFont(bold, italic), true
}
Expand Down