来自画布文本项目中@ font-face的自定义字体

时间:2011-07-12 13:04:47

标签: jquery font-face html5-canvas

我想用自定义字体在画布上绘制文字。所以,我试过这个:

         行              

    <style type = "text/css">
        @font-face
        {
            font-family: "Itt";
            src: url('42936.ttf') format("truetype"); 
        }

    </style>

    <script type = "text/javascript">

        function drawText()
                {

                    var canvas = $('#canvas');                        
                    var ctx = canvas[0].getContext('2d');

                    ctx.font = 'bold 22px Itt';
                    ctx.fillStyle = 'black';
                    ctx.fillText('Hello, world!', 100, 100);   
                }

        $(document).ready(function(){
                                drawText();
                            });
    </script>

    

它没有任何吸引力。字体已加载,因为如果尝试smth就像这样

<div style = "font-family: 'Itt'">some text</div>

一切都很完美。

0 个答案:

没有答案