canvas中使用中文字体如何处理?

canvas中使用中文字体如何处理?,第1张

一种方法是用把文字插入到一个限制格式的svg中,然后把这个svg当成图片读入canvas,googlecanvas实现网页截图。

如果大量使用非原生字体的话,可以先把字用ps什么的搞成图片,再以图片方式填入canvas。

必须要设置字号,字体才会生效。

canvas 中可以用 fillText() 绘出文字。

例如:

<html><body>

<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3">

Your browser does not support the HTML5 canvas tag.</canvas>

<script>

var c = document.getElementById("myCanvas")

var ctx = c.getContext("2d")

ctx.font = "20px Georgia"

ctx.fillText("Hello World!", 10, 50)

ctx.font = "30px Verdana"

var gradient = ctx.createLinearGradient(0, 0, c.width, 0)

gradient.addColorStop("0", "magenta")

gradient.addColorStop("0.5", "blue")

gradient.addColorStop("1.0", "red")

ctx.fillStyle = gradient

ctx.fillText("Big smile!", 10, 90)

</script>

<p><strong>Note:</strong>The canvas tag is not supported in Internet

Explorer 8 and earlier versions.</p>

</body>

</html>

====

如果想插入显示一个文件或网页,可以用 <iframe>, 而不是用 画布<canvas>,

例如:

<iframe src="这里写网页的URL"></iframe>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11495947.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存