-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfont.gs
More file actions
127 lines (120 loc) · 3.69 KB
/
font.gs
File metadata and controls
127 lines (120 loc) · 3.69 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
119
120
121
122
123
124
125
126
127
# Usage:
# copy font.txt to your project directory
# include the font data in the font_data list
# list font_data = file ```font.txt```;
# generate your own font using font.py
# in inkscape, use these options:
# Input/Output > SVG output > Path data > Path string format = Absolute
# Input/Output > SVG output > Path data > Force repeat commands = Checked
var font_offset = 0;
var font_x = 0;
var font_y = 0;
var font_scale = 1;
var font_x1 = 0;
var font_x2 = 240;
var font_char_spacing = 0;
var font_line_spacing = 0;
var font_linelen = 0;
%define FONT_NAME font_data[font_offset+1]
%define FONT_CREATOR font_data[font_offset+2]
%define FONT_RIGHTS font_data[font_offset+3]
%define FONT_WIDTH font_data[font_offset+4]
%define FONT_HEIGHT font_data[font_offset+5]
%define FONT_CALCULATE_WIDTH_FROM_LENGTH(LENGTH) \
(LENGTH*(FONT_WIDTH+2+font_char_spacing)-(2+font_char_spacing))*font_scale
%define FONT_CALCULATE_WIDTH(TEXT) FONT_CALCULATE_WIDTH_FROM_LENGTH(length(TEXT))
proc font_render_char char {
switch_costume $char;
local x = "";
local y = "";
local i = font_offset+font_data[5+font_offset+costume_number()];
forever {
if font_data[i] == "M" {
pen_up;
goto font_x+font_scale*font_data[i+1], font_y-font_scale*font_data[i+2];
i += 3;
if x == "" {
x = x_position();
y = y_position();
}
} elif font_data[i] == "L" {
pen_down;
goto font_x+font_scale*font_data[i+1], font_y-font_scale*font_data[i+2];
i += 3;
} elif font_data[i] == "H" {
pen_down;
set_x font_x+font_scale*font_data[i+1];
i += 2;
} elif font_data[i] == "V" {
pen_down;
set_y font_y-font_scale*font_data[i+1];
i += 2;
} elif font_data[i] == "Z" {
pen_down;
goto x, y;
i += 1;
} else {
pen_up;
stop_this_script;
}
}
}
proc font_render_begin {
font_x = font_x1;
font_linelen = 0;
}
proc font_render_text text {
local i = 1;
repeat length($text) {
font_render_char $text[i];
font_x += (FONT_WIDTH+2+font_char_spacing)*font_scale;
i++;
}
}
proc font_render_text_softwrap text {
local maxlen = (font_x2 - font_x1) // ((FONT_WIDTH+2+font_char_spacing)*font_scale);
local i = 1;
local font_linelen = 0;
local word = "";
until i > length($text) {
until $text[i] == " " or i > length($text) {
word &= $text[i];
i++;
}
if font_linelen + length(word) > maxlen {
font_y -= (FONT_HEIGHT+4+font_line_spacing)*font_scale;
font_x = font_x1;
font_linelen = 0;
}
local j = 1;
repeat length(word) {
font_render_char word[j];
font_x += (FONT_WIDTH+2+font_char_spacing)*font_scale;
font_linelen += 1;
if font_x > font_x2 {
font_y -= (FONT_HEIGHT+4+font_line_spacing)*font_scale;
font_x = font_x1;
font_linelen = 0;
}
j++;
}
word = "";
until $text[i] != " " or i > length($text) {
word &= $text[i];
i++;
}
local j = 1;
repeat length(word) {
font_render_char word[j];
font_x += (FONT_WIDTH+2+font_char_spacing)*font_scale;
font_linelen += 1;
if font_x > font_x2 {
font_y -= (FONT_HEIGHT+4+font_line_spacing)*font_scale;
font_x = font_x1;
font_linelen = 0;
}
j++;
}
word = "";
}
}