-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path_bidi.js
More file actions
67 lines (59 loc) · 1.64 KB
/
_bidi.js
File metadata and controls
67 lines (59 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
define(["dojo/_base/lang", "dbidi/string/TextLayoutEngine"], function (lang, BidiEngine) {
function validateTextDir(textDir) {
var validValues = ["ltr", "rtl", "auto"];
if (textDir) {
textDir = textDir.toLowerCase();
if (validValues.indexOf(textDir) < 0) {
return null;
}
}
return textDir;
}
return {
LRM: "\u200E",
LRE: "\u202A",
PDF: "\u202C",
RLM: "\u200f",
RLE: "\u202B",
// the object that performs text transformations.
bidiEngine: new BidiEngine(),
bidiPreprocess: function (newText) {
if (newText) {
if (newText.textDir) {
newText.textDir = validateTextDir(newText.textDir);
}
if (newText.text && (newText.text instanceof Array)) {
newText.text = newText.text.join(",");
}
}
if (newText && (newText.text !== undefined || newText.textDir) &&
(this.textDir !== newText.textDir || newText.text !== this.origText)) {
// store the original text.
this.origText = (newText.text !== undefined) ? newText.text : this.origText;
if (newText.textDir) {
this.textDir = newText.textDir;
}
newText.text = this.formatText(this.origText, this.textDir);
}
return this.bidiPreprocess(newText);
},
restoreText: function (origObj) {
var obj = lang.clone(origObj);
if (obj && this.origText) {
obj.text = this.origText;
}
return obj;
},
textDirPreprocess: function (text) {
// inherit from surface / group if textDir is defined there
if (text) {
var textDir = text.textDir ? validateTextDir(text.textDir) : this.textDir;
if (textDir) {
text.textDir = textDir;
}
}
return text;
},
validateTextDir: validateTextDir
};
});