NikLever / CanvasUI

A Three.JS WebXR UI. Enabling easy UI creation for immersive-vr sessions.
canvas-ui-eight.vercel.app
GNU General Public License v3.0
130 stars 22 forks source link

fix custom font (custom shapes example) not working #12

Open eviltik opened 2 years ago

eviltik commented 2 years ago

(master & dev branch)

We can see an Arial font used rather than the targeted one (Gochi Hand)

https://niksgames.com/webxr/dev/CanvasUI/shaped/

eviltik commented 2 years ago

I've tested setTimeout 1s before app initialization, so we are sure the fond is loaded: no change.

The only easy/quick way i found to fix that is to add a div with the font familly and at least one char, after body tag

<div style="font-family: Gochi Hand;position:absolute;z-index:-1">. </div>
eviltik commented 2 years ago

Another test using local font strategy : no change

<link href="https://fonts.googleapis.com/css2?family=Gochi+Hand&display=swap" rel="stylesheet">
<style>
    @font-face {
        font-family: 'Gochi Hand';
        src: local('Gochi Hand');
    }
</style>
eviltik commented 2 years ago

Another way to fix :

<script type="module">

import { App } from './app.js';

document.addEventListener("DOMContentLoaded", function() {

        let myFont = new FontFace(
            "Gochi Hand",
            "url(https://fonts.gstatic.com/s/gochihand/v14/hES06XlsOjtJsgCkx1Pkfon_-w.woff2)"
        );

        myFont.load().then(font => {
            document.fonts.add(font);
            const app = new App();
            window.app = app;
        });

    });

</script>

https://caniuse.com/mdn-api_fontface

eviltik commented 2 years ago

@NikLever Seem's the FontFace API is the cleanest way to fix :)

go PR ?

NikLever commented 2 years ago

Looks like a great suggestion

eviltik commented 2 years ago

merged in dev branch

eviltik commented 2 years ago

reopened because not in master