Skip to content

Commit f44a71c

Browse files
committed
Font: Add Hack Font back so we have consistent and expectable font rendering
1 parent 981be0c commit f44a71c

3 files changed

Lines changed: 29 additions & 42 deletions

File tree

DEPENDENCIES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Major dependencies includes:
1818
- [iconv-lite](https://github.com/ashtuchkin/iconv-lite), Licensed under MIT license
1919
- [buffer](https://github.com/feross/buffer), Licensed under MIT license
2020
- [fontfaceobserver](https://github.com/bramstein/fontfaceobserver), [View license](https://github.com/bramstein/fontfaceobserver/blob/master/LICENSE)
21-
- [Nerd Font](https://www.nerdfonts.com/), packaged by [@azurity/pure-nerd-font](http://github.com/azurity/pure-nerd-font)
21+
- [Hack Font](https://github.com/source-foundry/Hack), [View license](https://github.com/source-foundry/Hack/blob/master/LICENSE.md)
22+
- [Nerd Fonts](https://www.nerdfonts.com/), packaged by [@azurity/pure-nerd-font](http://github.com/azurity/pure-nerd-font)
2223
includes icons from following fonts:
2324
- [Powerline Extra Symbols](https://github.com/ryanoasis/powerline-extra-symbols), Licensed under MIT license
2425
- [Font Awesome](https://github.com/FortAwesome/Font-Awesome), [View license](https://github.com/FortAwesome/Font-Awesome/blob/6.x/LICENSE.txt)

ui/widgets/screen_console.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@
1919

2020
@charset "utf-8";
2121

22+
@import "~hack-font/build/web/hack.css";
2223
@import "~@azurity/pure-nerd-font/pure-nerd-font.css";
2324

2425
#connector-resource-preload-control-console {
25-
font-family: PureNerdFont;
26+
font-family: PureNerdFont, Hack;
2627
}
2728
#connector-resource-preload-control-console::after {
2829
content: " ";
29-
font-family: PureNerdFont;
30+
font-family: PureNerdFont, Hack;
3031
font-weight: bold;
3132
}
3233
#connector-resource-preload-control-console::before {
3334
content: " ";
34-
font-family: PureNerdFont;
35+
font-family: PureNerdFont, Hack;
3536
font-style: italic;
3637
}
3738

ui/widgets/screen_console.vue

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div class="screen-console">
2222
<div
2323
class="console-console"
24-
:style="'font-family: ' + typeface + ', inherit'"
24+
:style="'font-family: ' + typefaces + ', inherit'"
2525
>
2626
<h2 style="display: none">Console</h2>
2727

@@ -117,15 +117,15 @@ import { consoleScreenKeys } from "./screen_console_keys.js";
117117
import "./screen_console.css";
118118
import "xterm/css/xterm.css";
119119
120-
const termTypeFace = "PureNerdFont";
121-
const termFallbackTypeFace = "monospace";
120+
const termTypeFaces = "PureNerdFont, Hack";
121+
const termFallbackTypeFace = "\"Cascadia Code\" , monospace";
122122
const termTypeFaceLoadTimeout = 3000;
123123
const termTypeFaceLoadError =
124-
'Remote font "' +
125-
termTypeFace +
126-
'" is unavailable, using "' +
124+
'Remote font ' +
125+
termTypeFaces +
126+
' is unavailable, using ' +
127127
termFallbackTypeFace +
128-
'" instead until the remote font is loaded';
128+
' instead until the remote font is loaded';
129129
const termDefaultFontSize = 16;
130130
const termMinFontSize = 8;
131131
const termMaxFontSize = 36;
@@ -142,7 +142,7 @@ class Term {
142142
allowTransparency: false,
143143
cursorBlink: true,
144144
cursorStyle: "block",
145-
fontFamily: termTypeFace + ", " + termFallbackTypeFace,
145+
fontFamily: termTypeFaces + ", " + termFallbackTypeFace,
146146
fontSize: this.fontSize,
147147
logLevel: process.env.NODE_ENV === "development" ? "info" : "off",
148148
theme: {
@@ -416,7 +416,7 @@ export default {
416416
return {
417417
screenKeys: consoleScreenKeys,
418418
term: new Term(this.control),
419-
typeface: termTypeFace,
419+
typefaces: termTypeFaces,
420420
runner: null,
421421
eventHandlers: {
422422
keydown: null,
@@ -456,25 +456,22 @@ export default {
456456
this.deinit();
457457
},
458458
methods: {
459-
loadRemoteFont(typeface, timeout) {
460-
return Promise.all([
461-
new FontFaceObserver(typeface).load(null, timeout),
462-
new FontFaceObserver(typeface, {
459+
loadRemoteFont(typefaces, timeout) {
460+
const tfs = typefaces.split(",");
461+
let observers = [];
462+
for (let v in tfs) {
463+
observers.push(new FontFaceObserver(tfs[v].trim()).load(null, timeout))
464+
observers.push(new FontFaceObserver(tfs[v].trim(), {
463465
weight: "bold",
464-
}).load(null, timeout),
465-
]);
466+
}).load(null, timeout))
467+
}
468+
return Promise.all(observers);
466469
},
467-
async retryLoadRemoteFont(typeface, timeout, onSuccess) {
470+
async retryLoadRemoteFont(typefaces, timeout, onSuccess) {
468471
const self = this;
469-
470472
for (;;) {
471-
if (self.term.destroyed()) {
472-
return;
473-
}
474-
475473
try {
476-
onSuccess(await self.loadRemoteFont(typeface, timeout));
477-
474+
onSuccess(await self.loadRemoteFont(typefaces, timeout));
478475
return;
479476
} catch (e) {
480477
// Retry
@@ -483,41 +480,29 @@ export default {
483480
},
484481
async openTerm(root, callbacks) {
485482
const self = this;
486-
487483
try {
488-
await self.loadRemoteFont(termTypeFace, termTypeFaceLoadTimeout);
489-
484+
await self.loadRemoteFont(termTypeFaces, termTypeFaceLoadTimeout);
490485
if (self.term.destroyed()) {
491486
return;
492487
}
493-
494488
root.innerHTML = "";
495-
496489
self.term.init(root);
497-
498490
return;
499491
} catch (e) {
500492
// Ignore
501493
}
502-
503494
if (self.term.destroyed()) {
504495
return;
505496
}
506-
507497
root.innerHTML = "";
508-
509498
callbacks.warn(termTypeFaceLoadError, false);
510-
511499
self.term.setFont(termFallbackTypeFace);
512500
self.term.init(root);
513-
514-
self.retryLoadRemoteFont(termTypeFace, termTypeFaceLoadTimeout, () => {
501+
self.retryLoadRemoteFont(termTypeFaces, termTypeFaceLoadTimeout, () => {
515502
if (self.term.destroyed()) {
516503
return;
517504
}
518-
519-
self.term.setFont(termTypeFace);
520-
505+
self.term.setFont(termTypeFaces);
521506
callbacks.warn(termTypeFaceLoadError, true);
522507
});
523508
},

0 commit comments

Comments
 (0)