-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
138 lines (121 loc) · 4.21 KB
/
index.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="dipbhi">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container" style="width:100%">
<div class="page-header">
<h2>font-transform</h2>
</div>
<div class="row">
<div class="col-md-6">
<h4>Text to be converted:</h4>
<div class="form-group">
<select id="ddl-src-font" class="form-control">
<option value="">Select source font</option>
</select>
</div>
<div class="form-group">
<textarea class="form-control" id="src" rows="20" cols="80" disabled></textarea>
</div>
</div>
<div class="col-md-6">
<h4>Converted text:</h4>
<textarea id="dst" rows="23" cols="80" readonly></textarea>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script>
var srcFonts = [{
text: "Terafont Kinnari",
value: "static/mapping/terafont-kinnari.json"
}];
$(function() {
for (var i = 0; i < srcFonts.length; i++) {
$("#ddl-src-font").append('<option value="' + srcFonts[i].value + '">' + srcFonts[i].text + '</option>');
}
});
var map;
$("#ddl-src-font").change(function() {
var current = this;
$.getJSON($(current).val(), function(r) {
map = r;
$("#src").removeAttr("disabled");
});
});
$("#src").change(function() {
transform();
});
function transform() {
var txt = $("#src").val(),
newTxt = "",
indexToForward = -1,
forwardChars = map["forwardChars"],
forwardSkipChars = map["forwardSkipChars"],
backwardChars = map["backwardChars"],
comboChars = map["comboChars"];
for (var i = 0; i < txt.length; i++) {
var char = txt[i],
newChar = map[char];
if (!newChar) {
newChar = char;
}
if (backwardChars.indexOf(newChar)>=0) {
var l = newTxt.length;
newTxt = newTxt.substr(0, l - 1) + newChar + newTxt[l - 1];
} else if (startsWithAny(forwardSkipChars, newChar) && endsWithAny(forwardChars, newTxt)) {
var l = newTxt.length;
newTxt = newTxt.substr(0, l - 1) + newChar + newTxt[l - 1];
} else {
newTxt += newChar;
}
var comboKey = endsWithAnyProp(comboChars, newTxt)
if(comboKey){
newTxt = newTxt.replace(new RegExp(comboKey + '$'), comboChars[comboKey]);
}
if (indexToForward >= 0) {
// if new char ends with any forward skip char, need to retain forward char index for next time
if (!endsWithAny(forwardSkipChars, newChar)) {
// var l = newTxt.length;
newTxt = newTxt.substr(0, indexToForward) + newTxt.substr(indexToForward + 1, newTxt.length) + newTxt[indexToForward];
indexToForward = -1;
}
}
if (forwardChars.indexOf(newChar)>=0) {
indexToForward = newTxt.length - 1;
}
}
$("#dst").val(newTxt);
}
function endsWithAny(list, str) {
for (var i = 0; i < list.length; i++) {
if (str.endsWith(list[i])) {
return true;
}
}
}
function endsWithAnyProp(obj, str) {
for(var key in obj){
if (str.endsWith(key)) {
return key;
}
}
}
function startsWithAny(list, str) {
for (var i = 0; i < list.length; i++) {
if (str.startsWith(list[i])) {
return true;
}
}
}
</script>
</body>
</html>