1. 程式人生 > >fabric.js自定義字型的引入

fabric.js自定義字型的引入

引入外掛

 <script src="/fontfaceobserver-master/fontfaceobserver.js"></script>

css引入字型

<style>         
        @font-face {
            font-family:博洋草體二;
            src:url('/fonts/art/bycte.ttf') format("truetype");
        }
</style>

映入js

function loadFont(font){
    //canvas.getActiveObject().set("fontFamily","方正小篆體");
var myfont = new FontFaceObserver(font); myfont.load() .then(function() { // when font is loaded, use it. canvas.getActiveObject().set("fontFamily", font); canvas.requestRenderAll(); }).catch(function(e) { console.log(e); }); }