キャンバスにテキストを描きたいのですが、サンプル例はありますか?キャンバスにはすでに描画された図形が含まれています。キャンバス上のその図形の上にテキストを表示したいのですが、どうすればよいですか?
25416 次
3 に答える
11
また、実際にcufonフォントをロードする必要があることにも注意してください。Fabric.jsを使用する場合のデフォルトのフォントはありません。
<script src="fabric.js"></script>
<script src="cufon.calibri.js"></script>
http://www.cufonfonts.com/から入手できるフォントはたくさんあります。
これは、作者がcufonの必要性を取り除くことを計画している場合です。ここで説明:Fabric.js + Google Fonts
ブロックをレンダリングしたい場合は、そのブロック内のテキスト。私はこのようなことをします。
//Render the block
var block = canvas.add(new fabric.Rect({
left: 100,
top: 100,
fill: 'blue'
}));
//Render the text after the block (so that it is in front of the block)
var text = canvas.add(new fabric.Text('I love fabricjs', {
left: block.left, //Take the block's position
top: block.top,
fill: 'white'
}));
//Render the text and block on the canvas
//This is to get the width and height of the text element
canvas.renderAll();
//Set the block to be the same width and height as the text with a bit of padding
block.set({ width: text.width + 15, height: text.height + 10 });
//Update the canvas to see the text and block positioned together,
//with the text neatly fitting inside the block
canvas.renderAll();
于 2012-04-08T11:16:09.677 に答える
4
テキストをレンダリングする方法のチュートリアルをご覧ください。
それは次のように簡単です:
canvas.add(new fabric.Text('foo', {
fontFamily: 'Delicious_500',
left: 100,
top: 100
}));
于 2011-12-07T20:17:31.750 に答える
1
また、テキストを正しく配置するために、CufonのoffsetLeftを調整する必要がある場合があることにも注意してください。何かのようなもの:
Cufon.fonts[your-fontname-in-lowercase-here].offsetLeft = 120;
ファブリックのキッチンシンクのデモでは、これを使用しています:http: //kangax.github.com/fabric.js/lib/font_definitions.js
于 2011-12-18T22:06:08.630 に答える