-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperevodchik.html
More file actions
118 lines (99 loc) · 2.75 KB
/
Copy pathperevodchik.html
File metadata and controls
118 lines (99 loc) · 2.75 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
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
<!DOCTYPE HTML>
<html>
<body>
<style>
html {
height: 100%;
overflow: hidden;
}
body {
margin: 0;
height: 200px;
background: linear-gradient(45deg, #EECFBA, #C5DDE8);
background-size: 100% 100%;
background-repeat: no-repeat;
}
textarea {
position: absolute;
background: transparent;
top: 50%;
left: 0;
right: 0;
outline: 0;
width: 100%;
height: 50%;
border: 0;
padding: 16px;
font: 16px Consolas;
max-width: 600px;
margin: auto;
background: linear-gradient(top, #FFFFFF, #EEEEEE 1px, #FFFFFF 25px);
box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px;
}
</style>
<canvas id="myCanvas"></canvas>
<textarea id="textarea">Ïðèìåð</textarea>
<script>
(function() {
function wrapText(context, text, x, y, maxWidth, lineHeight) {
context.clearRect(0, 0, canvas.width, canvas.height);
var words = text.split(' ');
var line = '';
context.font = '20px Consolas';
context.fillStyle = '#333';
for(var n = 0; n < words.length; n++) {
var testLine = line + words[n] + ' ';
var metrics = context.measureText(testLine);
var testWidth = metrics.width;
if (testWidth > maxWidth && n > 0) {
context.fillText(line, x, y);
line = words[n] + ' ';
y += lineHeight;
}
else {
line = testLine;
}
}
context.fillText(line, x, y);
}
var canvas = document.getElementById('myCanvas');
var input = document.getElementById('textarea');
var context = canvas.getContext('2d');
var maxWidth = 400;
var lineHeight = 25;
var text = '';
function onResize() {
canvas.width = innerWidth;
canvas.height = innerHeight / 2;
maxWidth = Math.min(innerWidth, 600);
}
function onInput() {
text = input.value;
wrapText(context, text, (canvas.width - maxWidth) / 2, 60, maxWidth, lineHeight);
}
document.addEventListener("input", onInput);
addEventListener("resize", onResize);
addEventListener("resize", onInput);
onResize();onInput()
})();
</script>
</body>
</html>
<style>
canvas{
border: 3px black solid;
}
#textCanvas{
display: none;
width: 100%;
height: 100%;
border: solid 1px black;
}
textarea {font:normal 51px 'RalewayRegular'; color:#050405;}
@font-face {
font-family: "RalewayRegular";
src: url("Myshkin.ttf") format("truetype");
font-style: normal;
font-weight: normal;
}
</style>