我想在畫布上繪製文本,怎樣做它的任何示例示例? 畫布已經包含了一些繪製的形狀,我想在畫布上顯示該形狀的頂部文字 我該怎麼做?使用fabric.js在畫布上繪製文本
1
A
回答
4
另外要注意,你需要實際已加載了的Cufón字體。使用Fabric.js時沒有默認字體。
<script src="fabric.js"></script>
<script src="cufon.calibri.js"></script>
這是筆者上消除了對的Cufón需要規劃的情況下如此多的字體。這裏討論: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();
4
看看How to render text教程。
很簡單:
canvas.add(new fabric.Text('foo', {
fontFamily: 'Delicious_500',
left: 100,
top: 100
}));
1
另外值得一提的是,你可能需要調整的Cufón的offsetLeft幫助正確定位文本。喜歡的東西:
Cufon.fonts[your-fontname-in-lowercase-here].offsetLeft = 120;
織物的廚房水槽演示使用這樣的: http://kangax.github.com/fabric.js/lib/font_definitions.js
相關問題
- 1. 在畫布上繪製文本
- 2. 在畫布上垂直繪製文本
- 3. Html5畫布 - 使用fabric.js繪製完美線條或不使用
- 4. 如何使用Fabric.js在畫布上伸展文本?
- 5. 使用fabric.js在畫布上自由繪圖
- 6. 預先加載將在fabric.js畫布上繪製的圖像
- 7. 如何繪製文本的畫布上
- 8. 在畫布上繪製文本,並使其在屏幕上
- 9. 如何使用DynamicLayout和Ellipsize在畫布上繪製文本框
- 10. 使用fabric.js繪製畫布形狀作爲橢圓形lauout
- 11. 使用WPF在畫布上繪製線
- 12. 使用gpu在畫布上繪製
- 13. 如何在畫布上繪製畫布
- 14. 在畫布上繪製ArcTo
- 15. 在畫布上繪製
- 16. 在畫布上繪製EditText
- 17. 在Scala.js上繪製畫布
- 18. 在畫布上繪製SVG
- 19. 繪製在畫布上
- 20. 在子畫布上繪製
- 21. HTML5 - 畫布:繪製文本在梯度
- 22. 在畫布左上角繪製文字
- 23. Android在畫布上繪製文字
- 24. 在角度上在畫布上繪製文本
- 25. fabric.js顯示畫布文本的鏡像
- 26. 用畫布繪製文字
- 27. 如何使用fabric.js繪製?
- 28. 使用fabric.js繪製虛線
- 29. 使用畫布繪製Rects
- 30. 使用Chrome在本地畫布上繪製圖像