Debian Codegraph @

dojox/drawing/util/typeset.js

raw symbols SCIP
1 define(["../library/greek"], function(greeks){
2 // summary:
3 // Singleton used for converting characters and typsetting. Required by _base.
4 // description:
5 // Eventually, this is supposed to turn input strings of mathematical
6 // expressions into typeset expressions that can be displayed on the
7 // canvas. For now, we just generate Greek letters based on LaTeX style
8 // entity codes.
9
10
11 //dojox.drawing.util.typeset =
12 return {
13
14 convertHTML: function(inText){
15 if(inText){
16 return inText.replace(/&([^;]+);/g,function(match,code){
17 if(code.charAt(0)=='#'){
18 //coerce remainder of string to int
19 var number=+code.substr(1);
20 if(!isNaN(number)){
21 return String.fromCharCode(number);
22 }
23 }else if(greeks[code]){
24 return String.fromCharCode(greeks[code]);
25 }
26 // This is generally for server code, so there
27 // is no point bothering the user in the case of an error.
28 console.warn("no HTML conversion for ",match);
29 return match;
30 });
31 }
32 return inText;
33 },
34
35 convertLaTeX: function(inText){
36 // console.log("***** convertLaTeX for ",inText);
37 if(inText){
38 return inText.replace(/\\([a-zA-Z]+)/g,function(match,word){
39 if(greeks[word]){
40 return String.fromCharCode(greeks[word]);
41 }else if(word.substr(0,2)=="mu"){
42 // special handling for \mu since it is
43 // a unit prefix for micro.
44 return String.fromCharCode(greeks["mu"])+word.substr(2);
45 }else if(word.substr(0,5)=="theta"){
46 // special handling for \theta since it is
47 // a standard prefix for angle associated with a vector.
48 return String.fromCharCode(greeks["theta"])+word.substr(5);
49 }else if(word.substr(0,3)=="phi"){
50 // special handling for \phi since it is
51 // a standard prefix for angle associated with a z-axis vector.
52 return String.fromCharCode(greeks["phi"])+word.substr(3);
53 }
54 console.log("no match for ",match," in ",inText);
55 console.log("Need user-friendly error handling here!");
56 }).replace(/\\\\/g,'\\');
57 }
58 return inText;
59 }
60
61 };
62
63 });