Skip to content

Commit f4bf965

Browse files
committed
monospace日本語フォントをNotoSansJPに固定
1 parent 78e4a89 commit f4bf965

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

app/globals.css

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
@import "tailwindcss";
22
@plugin "daisyui";
33

4-
/* inconsolata-latin-wght-normal */
5-
@font-face {
6-
font-family: "Inconsolata Variable";
7-
font-style: normal;
8-
font-display: swap;
9-
font-weight: 200 900;
10-
src: url(https://cdn.jsdelivr.net/fontsource/fonts/inconsolata:vf@latest/latin-wght-normal.woff2)
11-
format("woff2-variations");
12-
unicode-range:
13-
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
14-
U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212,
15-
U+2215, U+FEFF, U+FFFD;
16-
}
17-
4+
/* CDNからダウンロードするURLを指定したらなんかエラー出るので、npmでインストールしてlayout.tsxでimportすることにした */
185
@theme {
19-
--font-mono: "Inconsolata Variable", monospace;
6+
--font-mono: "Inconsolata Variable", "Noto Sans JP Variable", monospace;
207
}

app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { Metadata } from "next";
2+
import "@fontsource-variable/noto-sans-jp";
3+
import "@fontsource-variable/inconsolata";
24
import "./globals.css";
35
import { Navbar } from "./navbar";
46
import { Sidebar } from "./sidebar";

app/terminal/terminal.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,9 @@ export function useTerminal(props: TerminalProps) {
7171
useEffect(() => {
7272
const abortController = new AbortController();
7373

74-
(async () => {
75-
// globals.cssでフォントを指定し読み込んでいるが、
76-
// それが読み込まれる前にterminalを初期化してしまうとバグる。
77-
// なのでここでフォントをfetchし成功するまでterminalの初期化は待つ
78-
try {
79-
await fetch(
80-
"https://cdn.jsdelivr.net/fontsource/fonts/inconsolata:vf@latest/latin-wght-normal.woff2",
81-
{ signal: abortController.signal }
82-
);
83-
} catch {
84-
// ignore
85-
}
86-
74+
// globals.cssでフォントを指定し読み込んでいるが、
75+
// それが読み込まれる前にterminalを初期化してしまうとバグる。
76+
document.fonts.load("0.875rem Inconsolata Variable").then(() => {
8777
if (!abortController.signal.aborted) {
8878
const fromCSS = (varName: string) =>
8979
window.getComputedStyle(document.body).getPropertyValue(varName);
@@ -96,7 +86,7 @@ export function useTerminal(props: TerminalProps) {
9686
fontSize: 14,
9787
lineHeight: 1.4,
9888
letterSpacing: 0,
99-
fontFamily: "Inconsolata Variable",
89+
fontFamily: "'Inconsolata Variable','Noto Sans JP Variable'",
10090
theme: {
10191
// DaisyUIの変数を使用してテーマを設定している
10292
// TODO: ダークテーマ/ライトテーマを切り替えたときに再設定する?
@@ -134,7 +124,7 @@ export function useTerminal(props: TerminalProps) {
134124
setTermReady(true);
135125
onReadyRef.current?.();
136126
}
137-
})();
127+
});
138128

139129
const observer = new ResizeObserver(() => {
140130
// fitAddon.fit();

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"
1515
},
1616
"dependencies": {
17+
"@fontsource-variable/inconsolata": "^5.2.6",
18+
"@fontsource-variable/noto-sans-jp": "^5.2.6",
1719
"@google/generative-ai": "^0.24.1",
1820
"@opennextjs/cloudflare": "^1.6.3",
1921
"@xterm/addon-fit": "^0.11.0-beta.115",

0 commit comments

Comments
 (0)