Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23940
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? |
| Date | Fri, 25 Apr 2014 12:42:43 +0200 |
| Organization | PointedEars Software (PES) |
| Lines | 108 |
| Message-ID | <2732090.DMPj7CqQq3@PointedEars.de> (permalink) |
| References | <9521275e-7eb0-4d31-adc0-76044b3d33e1@googlegroups.com> <535a21aa$0$6703$9b4e6d93@newsspool2.arcor-online.net> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1398422566 15680 eJwFwYEBwCAIA7CXFNrCzpkC/59gQtfWDYgChyPoyhMVbb6wTNXIIJodjhxDn+P+1b9rjj0B0xCq (25 Apr 2014 10:42:46 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Fri, 25 Apr 2014 10:42:46 +0000 (UTC) |
| User-Agent | KNode/4.11.5 |
| X-User-ID | eJwNycERACEIBLCWEFjwysE96L8E/WUmsFjB9EA4BpOqmH0+F4rIXipPfd5NWZYR6db/9gE50Z7QlqiiYYp1ATp0Fa4= |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjlo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lang.javascript:23940 |
Show key headers only | View raw
Martin Honnen wrote:
> jonas.thornvall@gmail.com wrote:
>> I've tried to assign string func both with and without enclosing
>> brackets. But it just write out the ASCII not the encoding on canvas. So
>> HTML encode chars do not work on canvas. How can i solve this?
>>
>> //Not working arr[j].func = ("∑(1 ≤ n <"+n+")n?");
>> //Not working arr[j].func = "∑(1 ≤ n <"+n+")n?";
>
> You should be able to use any Unicode character literally in your script
> code as long as you use an Unicode encoding like UTF-8 for your script
> files e.g. so use
>
> arr[j].func = "∑(1 ≤ n <100)n?";
[I would type those using AltGr+Shift+S and Shift+AltGr, “<”, “=” :)]
True. However, two things one needs to be aware of:
1. You also need to serve those files declaring the used character
encoding in the Content-Type header field value because ECMAScript
has no way of telling the parser the used character encoding yet,
and there is no default encoding ubiquitously implemented.
A possibility is to add
<IfModule mime_module>
AddType text/javascript;charset=utf-8 .js
</IfModule>
to your .htaccess file if you are using an httpd-compatible
server like Apache.
2. Without a BOM, a text editor cannot tell UTF-8 encoding from
a one-byte encoding like ISO-8859-1. One can support UTF-8-capable
editors by tagging source code. For example, for Vim you can insert
(at the beginning or the end; I recommend the latter to preserve line
numbers)
/* vim:set fileencoding=utf-8 */
which removes the need to issue the command “:set encoding=utf-8”
manually or use “set encoding=utf-8” in one’s vimrc.
Although all my source code is UTF-8 encoded by default (Eclipse
preference), I have begun to tag it like that when I use characters
whose code point is beyond U+007F (characters not in US-ASCII), for
example in JSX:math/complex.js [1]
If using a Unicode encoding, thus using Unicode characters verbatim, is not
an option for you, ECMAScript supports Unicode escape sequences [2]:
arr[j].func = "\u2211(1 \u2264 n <100)n?"; // ¹
Constants or constant-like variables or properties can be used to make such
code easier readable, especially if symbols are used repeatedly:
/* you may use “const” if your target implementations support it */
var CH_SUM = "\u2211";
var CH_LTE = "\u2264";
arr[j].func = CH_SUM + "(1 " + CH_LTE + " n <100)n?";
One should be aware, however, that using escape sequences instead of plain
characters increases the file size (here: 6 or more instead of up to four
8-bit bytes), and requires more parsing, therefore increases the time it
takes to load a document. That applies both to ECMAScript and markup
documents, like HTML.
If you are using HTML5 or XHTML, consider using MathML. Gecko-based
browsers support MathML well [3]; recently a user stylesheet has been
proposed for working around Chromium’s currently disabled MathML
support. [4]
_______
¹ I have obtained this using
"∑(1 ≤ n <100)n?".split("").map(function (char) {
if (char.charCodeAt(0) > 0x7F)
{
return "\\u" + char.charCodeAt(0).toString(16);
}
else
{
return char;
}
}).join("")
(as a one-liner with another identifier) on the script console. It can
be improved to give the correct escape sequence for characters below
U+1000, too. See also <http://mothereff.in/js-escapes> by Mathias Bynens
(@mathias).
[1]
<http://PointedEars.de/wsvn/JSX?op=comp&compare[]=/trunk/@533&compare[]=/trunk/@534>
[2] <http://ecma-international.org/ecma-262/5.1/#sec-7.8.4>
[3] Testcases:
<http://pointedears.de/markup/equation2.html>
<http://pointedears.de/markup/equation2.xhtml>
<http://pointedears.de/markup/xml/SVG/doppler>
[4] <https://code.google.com/p/chromium/issues/detail?id=152430#c94>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? jonas.thornvall@gmail.com - 2014-04-25 01:43 -0700
Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? Martin Honnen <mahotrash@yahoo.de> - 2014-04-25 10:49 +0200
Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? jonas.thornvall@gmail.com - 2014-04-25 02:30 -0700
Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-04-25 12:42 +0200
Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? jonas.thornvall@gmail.com - 2014-04-25 21:26 -0700
Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? jonas.thornvall@gmail.com - 2014-04-25 21:38 -0700
Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? jonas.thornvall@gmail.com - 2014-04-25 21:40 -0700
Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? Richard Damon <Richard@Damon-Family.org> - 2014-04-26 11:02 -0400
Re: I try to write out sigma sign in javascript on a canvas, but HTML encoding do not work, how should i do? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-04-26 18:20 +0200
csiph-web