-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
137 lines (127 loc) · 2.98 KB
/
script.js
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
$(document).ready(function() {
var specials = { //Illegal CSS characters
".": "period",
",": "comma",
":": "colon",
";": "semicolon",
"‘": "leftquote", //Quotes not supported
"'": "rightquote",
"“": "leftquotes",
"”": "rightquotes",
"!": "exclamation",
"?": "question"
};
$("#charInputSubmit").click(function() { //Convert text to handwriting
$("#preview").text("");
$input = $("#charInput").val();
$output = "";
$charArray = $input.split("");
$spaces = [];
//Line wrap handler
$array2 = [];
$mx = $charArray.length;
$temp=0;
$location=0;
$x=0;
while($x<$mx)
{
if ($location==23)
{
$location=0;
}
if($charArray[$x]==" ")
{
$array2.push(" ");
$temp=0;
$location++;
}
else if($temp==0)
{
if($location!=0)
{
$z=-1;
for($y=$x+1;$y<$mx;$y++)
{
if($charArray[$y]==" ")
{
$z=$y-$x+1;
$y=$mx+1;
}
}
if($z<0)
{
$z=$mx-$x;
}
if($location+$z>23)
{
for($y=$location+1;$y<=23;$y++)
{
$array2.push(" ");
}
$array2.push($charArray[$x]);
$location=1;
temp=1;
}
else
{
$array2.push($charArray[$x]);
$temp=1;
$location++;
}
}
else
{
$array2.push($charArray[$x]);
$temp=1;
$location++;
}
}
else
{
$array2.push($charArray[$x]);
$location++;
}
$x++;
}
console.log($array2);
//Display Preview
for(i=0; i<$array2.length; i++) {
$rand = randBetween(1,5);
if ($array2[i] == " " || $array2[i] == `
`) {
$output += `<div class="char char-space"></div>`; //Check if char is a space, tab, or newline
}
else if (!!$array2[i].match(/^[.,:;?!']/)) {
$char = specials[$array2[i]];
$output += `<div class="char char-${$char}${$rand}"></div>`;
}
else {
$char = $array2[i];
$output += `<div class="char char-${$char}${$rand}"></div>`;
}
}
console.log("Successfully converted file.");
$("#preview").append($output);
});
function randBetween(a, b) {
return Math.floor(Math.random() * b) + a;
}
$("#genPDF").click(function() {
$("#preview").print();
});
});
//Print Function
function printElem(elem)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><link rel="stylesheet" href="hack.css"><link rel="stylesheet" href="main.css"><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
}