Skip to content

Commit 229119c

Browse files
authored
Merge pull request #573 from akiyosi/improve_font_error
Improve font error display
2 parents 02d7311 + f3f628e commit 229119c

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

editor/editor.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ type Editor struct {
109109
notifyStartPos *core.QPoint
110110
colors *ColorPalette
111111
notify chan *Notify
112-
fontCh chan []*Font
113112
cbChan chan *string
114113
chUiPrepared chan bool
115114
openingFileCh chan string
@@ -126,6 +125,8 @@ type Editor struct {
126125
opts Options
127126
font *Font
128127
fallbackfonts []*Font
128+
fontCh chan []*Font
129+
fontErrors []string
129130
notifications []*Notification
130131
workspaces []*Workspace
131132
args []string
@@ -256,6 +257,8 @@ func InitEditor(options Options, args []string) {
256257
e.app.SetDoubleClickInterval(0)
257258
e.putLog("finished generating the application")
258259

260+
e.initNotifications()
261+
259262
var cerr, lerr error
260263
e.initialColumns, cerr, e.initialLines, lerr = parseLinesAndColumns(args)
261264
if cerr == nil {
@@ -290,8 +293,6 @@ func InitEditor(options Options, args []string) {
290293

291294
e.initColorPalette()
292295

293-
e.initNotifications()
294-
295296
e.initSysTray()
296297

297298
e.initSpecialKeys()
@@ -456,15 +457,34 @@ func parseFont(families string, size int, weight string, stretch, linespace, let
456457
}
457458

458459
for _, f := range strings.Split(families, ",") {
459-
fonts = append(
460-
fonts,
461-
initFontNew(strings.TrimSpace(f), float64(size), fontWeight, stretch, linespace, letterspace),
462-
)
460+
font := initFontNew(strings.TrimSpace(f), float64(size), fontWeight, stretch, linespace, letterspace)
461+
fonts = append(fonts, font)
462+
463+
ok := checkValidFont(f)
464+
if !ok {
465+
editor.fontErrors = append(editor.fontErrors, f)
466+
continue
467+
}
463468
}
464469

465470
return
466471
}
467472

473+
func (e *Editor) showFontErrors() {
474+
if len(e.fontErrors) == 0 {
475+
return
476+
}
477+
for _, fontError := range e.fontErrors {
478+
go e.pushNotification(
479+
NotifyWarn,
480+
5,
481+
fmt.Sprintf("The specified font family '%s' was not found on this system.", fontError),
482+
notifyOptionArg([]*NotifyButton{}),
483+
)
484+
}
485+
486+
}
487+
468488
// setAppDirPath
469489
// set application working directory path
470490
// TODO: This process is problematic and needs a better way to set up CWD

editor/workspace.go

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,7 @@ func (ws *Workspace) guiFont(args string) {
21232123
ws.screen.fallbackfonts = nil
21242124

21252125
ws.parseAndApplyFont(args, &ws.screen.font, &ws.screen.fallbackfonts)
2126+
editor.showFontErrors()
21262127
ws.screen.purgeTextCacheForWins()
21272128

21282129
// When setting up a different font for a workspace other than the neovim drawing screen,
@@ -2182,13 +2183,12 @@ func (ws *Workspace) guiFontWide(args string) {
21822183
}
21832184

21842185
func (ws *Workspace) parseAndApplyFont(str string, font *(*Font), fonts *([]*Font)) {
2185-
errGfns := []string{}
21862186
for i, gfn := range strings.Split(str, ",") {
21872187
fontFamily, fontHeight, fontWeight, fontStretch := getFontFamilyAndHeightAndWeightAndStretch(gfn)
21882188

21892189
ok := checkValidFont(fontFamily)
21902190
if !ok {
2191-
errGfns = append(errGfns, fontFamily)
2191+
editor.fontErrors = append(editor.fontErrors, fontFamily)
21922192
continue
21932193
}
21942194

@@ -2217,23 +2217,6 @@ func (ws *Workspace) parseAndApplyFont(str string, font *(*Font), fonts *([]*Fon
22172217
*fonts = append(*fonts, ff)
22182218
}
22192219
}
2220-
2221-
if len(errGfns) > 0 {
2222-
s := ""
2223-
for k, errgfn := range errGfns {
2224-
s += "'" + errgfn + "'"
2225-
if k < len(errGfns)-1 {
2226-
s += ", "
2227-
}
2228-
}
2229-
editor.pushNotification(
2230-
NotifyWarn,
2231-
4,
2232-
fmt.Sprintf("The specified font family %s was not found on this system.", s),
2233-
notifyOptionArg([]*NotifyButton{}),
2234-
)
2235-
}
2236-
22372220
}
22382221

22392222
func getFontFamilyAndHeightAndWeightAndStretch(s string) (string, float64, gui.QFont__Weight, int) {
@@ -2295,22 +2278,19 @@ func getFontFamilyAndHeightAndWeightAndStretch(s string) (string, float64, gui.Q
22952278
func checkValidFont(family string) bool {
22962279
// f := gui.NewQFont2(family, 10.0, 1, false)
22972280
f := gui.NewQFont()
2298-
if editor.config.Editor.ManualFontFallback {
2299-
f.SetStyleHint(gui.QFont__TypeWriter, gui.QFont__NoFontMerging)
2300-
} else {
2301-
f.SetStyleHint(gui.QFont__TypeWriter, gui.QFont__PreferDefault|gui.QFont__ForceIntegerMetrics)
2302-
}
2303-
2281+
f.SetStyleHint(gui.QFont__TypeWriter, gui.QFont__NoFontMerging)
23042282
f.SetFamily(family)
2305-
f.SetPointSizeF(10.0)
2306-
f.SetWeight(int(gui.QFont__Normal))
2307-
23082283
fi := gui.NewQFontInfo(f)
23092284

23102285
fname1 := fi.Family()
23112286
fname2 := f.Family()
23122287

23132288
ret := strings.EqualFold(fname1, fname2)
2289+
if !ret {
2290+
editor.putLog(
2291+
fmt.Sprintf("The specified font family '%s' was not found on this system.", family),
2292+
)
2293+
}
23142294

23152295
return ret
23162296
}

0 commit comments

Comments
 (0)