简体   繁体   English

HTML5画布中的希腊字母

[英]Greek Letters in HTML5 Canvas

Is there a way to print Greek letters on an HTML5 canvas? 有没有办法在HTML5画布上打印希腊字母? I've tried using the html entity name and number, like this 我试过使用html实体名称和数字,就像这样

canvas2.cx.fillText("ξ", 50, 50);

and

canvas2.cx.fillText("ξ", 50, 50);

but it just prints it out literally because the canvas does not know to interpret these symbols. 但它只是字面上打印出来,因为画布不知道解释这些符号。

Simply use UTF-8. 只需使用UTF-8即可。

You don't have to escape chars to write them in HTML or Canvas. 您不必转义字符以在HTML或Canvas中编写它们。

Use the correct header in your document : 在文档中使用正确的标题:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF8">

如果要将JavaScript源限制为ASCII,但仍在字符串中包含非ASCII字符,则可以使用Unicode转义序列:(小xi的代码点为U + 03BE):

canvas2.cx.fillText("\u03be", 50, 50);

Like α and β ? αβ If you're using UTF-8, you may be able to just type the character literals. 如果您使用的是UTF-8,则可以只输入字符文字。 example: 例:

canvas2.cx.fillText("α", 50, 50);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM