Skip to content

Commit 3be53ab

Browse files
committed
fix(timeline): wait for font to be loaded before generating BitmapFont
1 parent bc6fc1d commit 3be53ab

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed
Binary file not shown.

packages/app-frontend/src/assets/style/index.styl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
@import 'imports'
88
@import 'transitions'
99

10-
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;500&display=swap')
11-
1210
@font-face
1311
font-family 'Roboto'
1412
font-style normal
1513
font-weight 400
1614
src local('Roboto'), local('Roboto-Regular'), url(../Roboto-Regular.woff2) format('woff2')
1715

16+
@font-face
17+
font-family 'Roboto Mono'
18+
font-style normal
19+
font-weight 400
20+
src local('Roboto Mono'), local('Roboto-Mono'), url(../Roboto-Mono.ttf) format('truetype')
21+
1822
html, body
1923
margin 0
2024
padding 0

packages/app-frontend/src/features/timeline/Timeline.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { computed, onMounted, ref, watch, defineComponent, onUnmounted } from '@
1212
import { SharedData } from '@vue-devtools/shared-utils'
1313
import { onSharedDataChange } from '@front/util/shared-data'
1414
import { formatTime } from '@front/util/format'
15+
import { useFonts } from '@front/util/fonts'
1516
import {
1617
useTime,
1718
useLayers,
@@ -278,7 +279,12 @@ export default defineComponent({
278279
stopMove()
279280
})
280281
282+
// Fonts
283+
284+
const { loaded: fontsLoaded } = useFonts()
285+
281286
return {
287+
fontsLoaded,
282288
startTime,
283289
endTime,
284290
minTime,
@@ -386,6 +392,7 @@ export default defineComponent({
386392
/>
387393
</div>
388394
<TimelineView
395+
v-if="fontsLoaded"
389396
class="h-full"
390397
/>
391398

packages/app-frontend/src/features/timeline/TimelineView.vue

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ import Vue from 'vue'
3838
PIXI.settings.ROUND_PIXELS = true
3939
PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST
4040
41-
PIXI.BitmapFont.from('Roboto Mono', {
42-
fontFamily: 'Roboto Mono',
43-
fontSize: 9,
44-
}, {
45-
resolution: window.devicePixelRatio,
46-
})
47-
4841
delete Renderer.__plugins.interaction
4942
5043
const LAYER_SIZE = 16
@@ -1064,8 +1057,7 @@ export default defineComponent({
10641057
}
10651058
if (!t) {
10661059
t = event.groupT = new PIXI.BitmapText('', {
1067-
fontName: 'Roboto Mono',
1068-
tint: nonReactiveState.darkMode.value ? 0xffffff : 0,
1060+
fontName: nonReactiveState.darkMode.value ? 'roboto-white' : 'roboto-black',
10691061
})
10701062
t.x = 1
10711063
t.y = Math.round(-t.height / 2)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { ref } from '@vue/composition-api'
2+
import * as PIXI from 'pixi.js-legacy'
3+
4+
let installedFonts = false
5+
6+
export async function installFonts () {
7+
if (installedFonts) return
8+
9+
try {
10+
await document.fonts.load('10px "Roboto Mono"')
11+
} catch (e) {
12+
console.error(e)
13+
}
14+
15+
PIXI.BitmapFont.from('roboto-black', {
16+
fontFamily: 'Roboto Mono',
17+
fontSize: 9,
18+
fill: '#000000',
19+
}, {
20+
resolution: window.devicePixelRatio,
21+
})
22+
23+
PIXI.BitmapFont.from('roboto-white', {
24+
fontFamily: 'Roboto Mono',
25+
fontSize: 9,
26+
fill: '#ffffff',
27+
}, {
28+
resolution: window.devicePixelRatio,
29+
})
30+
31+
installedFonts = true
32+
}
33+
34+
export function useFonts () {
35+
const loaded = ref(installedFonts)
36+
37+
async function _load () {
38+
await installFonts()
39+
loaded.value = true
40+
}
41+
_load()
42+
43+
return {
44+
loaded,
45+
}
46+
}

0 commit comments

Comments
 (0)