Change font size of Canvas without knowing font family

前端 未结 5 1014
遥遥无期
遥遥无期 2020-12-30 00:06

Is there a way to only change the font size of a canvas context without having to know/write the font family.

 var ctx = document.getElementById(\"canvas\").         


        
5条回答
  •  暖寄归人
    2020-12-30 00:15

    try this (using jquery):

        var span = $('').css('font', context.font).css('visibility', 'hidden');
        $('body').append(span);
        span[0].style.fontWeight = 'bold';
        span[0].style.fontSize = '12px';
        //add more style here.
        var font = span[0].style.font;
        span.remove();
        return font;
    

提交回复
热议问题