SVG text element with Unicode characters

后端 未结 2 1808
清歌不尽
清歌不尽 2021-01-11 10:43

First - a short description of a problem. I write a JavaScript function to put some text label\'s in SVG canvas. Here it is:



        
2条回答
  •  抹茶落季
    2021-01-11 11:28

    Replace

    set_label (10,50,'QamÚraj')
    

    with

    set_lavel(10, 50, "Qam\u00DAraj");
    

    "\u00DA" is four hex digits for Codepoint 218.

    Similarly, your other label would be

    set_label (10,50,'\u0398\u03b1\u03c1\u03c3\u03b1\u03bd\u03b4\u03b1\u03bb\u03b1')
    

    If you want to find the hex for a Greek character, you can go to http://www.squarefree.com/shell/shell.html and type something like

    var hex = "Α".charCodeAt(0).toString(16);
    [, "\\x0", "\\x", "\\u0", "\\u"][hex.length] + hex;
    

    which for "Α" produces

    \u0391
    

提交回复
热议问题