Newer
Older
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from flask import Flask, request, render_template
import subprocess
import os
import re
import sys
import io
app = Flask(__name__)
title = 'Cobbled paths'
fonts_directory = 'db/'
possible_extensions = [".flf"]
etherpad = 'https://pad.constantvzw.org/p/'
prefix = 'cobbled-pad-'
# VARIABLES
# ------------------------------
# all the character that svgbob understand
spec = [".", ",", "’", "'", "`", "+", "*", "o", "O", "V", "\\-", "|", "~", "_", ":", "!", "<", ">", "v", "^", "/", "\\\\", '\\”', '\\"', "(", ")", "=", "#"]
r_spec = "".join(spec)
r_nspec = "[^" + r_spec + "\€\$\s]"
# autofix regex
autofix = [
# every arrowshead into lines
[re.compile("[<{]"), "("],
[re.compile("[>}L]"), ")"],
[re.compile("[vV]"), "-"],
[re.compile("[\\^]"), "-"],
[";", ":"],
["7", "/"],
[re.compile("[1Tlj\\[\\]]"), "|"],
[re.compile("[Y]"), "+"],
# every not in the spec --> block
[re.compile(r_nspec), "#"],
]
def most_common(lst):
return max(set(lst), key=lst.count)
# ROUTES
# ------------------------------
@app.route("/")
def index():
return render_template(
'index.html',
title = title)
@app.route("/draw.html")
def draw():
params = {
'pad': request.args.get('p') or 'default',
'weight': request.args.get('w') or '3',
}
params['pad-full'] = etherpad + prefix + params['pad']
return render_template(
'draw.html',
title = title,
params = params)
@app.route("/catalogue.html")
def catalogue():
# text and weight as get parameter
params = {
'text': request.args.get('t') or 'Echoes',
'weight': request.args.get('w') or '3',
}
output = {
'stroke': { 'ascii': ' | ' , 'fonts': [] },
'script': { 'ascii': ' _/' , 'fonts': [] },
'block': { 'ascii': '|_|' , 'fonts': [] },
'outline': { 'ascii': '/ /' , 'fonts': [] },
'effect': { 'ascii': ': :' , 'fonts': [] },
'pattern': { 'ascii': ')()' , 'fonts': [] },
# 'fill': { 'ascii': '_/', 'fonts': {} },
# 'directions': { 'ascii': '_/', 'fonts': {} },
# '3d': { 'ascii': '_/', 'fonts': {} },
# 'frame': { 'ascii': '_/', 'fonts': {} },
# 'code': { 'ascii': '_/', 'fonts': {} },
}
databases = {
'default': 'fonts made by the figlet developpers and given with the program, early 1993',
'contributed': 'fonts made by figlet amateurs and submitted to the official figlet ftp, from before 1993 to 2005',
'jave': 'figlet font library of JavE (a free Ascii drawing Editor)',
}
# walk in the figlet font directory
for root, dirs, files in os.walk(fonts_directory):
for name in files:
(basename, ext) = os.path.splitext(name)
if ext in possible_extensions:
path = os.path.join(root, name)
print(path)
# get font category out of last folder
catalogue = root.split('/')[-2]
type = root.split('/')[-1]
if type in output:
f = {}
output[type]['fonts'].append(f)
f['name'] = name
f['catalogue'] = catalogue
figlet = subprocess.run(["figlet", params['text'], "-f", path, "-w", "160"], stdout = subprocess.PIPE, text=True)
f['ascii'] = figlet.stdout
font_info = subprocess.run(["figlet", "-I", path, "-w", "160"], stdout = subprocess.PIPE, text=True)
f['info'] = font_info
svgbob = subprocess.run(["svgbob_cli", '--stroke-width', params['weight']], input = f['ascii'], stdout = subprocess.PIPE, text=True)
f['svg'] = svgbob.stdout
# regex auto_fix
fixed = f['ascii']
for regex, replace in autofix:
fixed = re.sub(regex, replace, fixed)
f['ascii_fix'] = fixed
if f['ascii'] != f['ascii_fix']:
f['autofix'] = True
fix_indication = f['ascii']
for regex, replace in autofix:
# the two markers have to not appear in any regex
fix_indication = re.sub(regex, "$" + replace + "€", fix_indication)
fix_indication = re.sub("[\$]", "<span class='fix'>", fix_indication)
fix_indication = re.sub("[\€]", "</span>", fix_indication)
f['ascii_fix_indication'] = fix_indication
svgbob_fix = subprocess.run(["svgbob_cli", '--stroke-width', params['weight']], input = f['ascii_fix'], stdout = subprocess.PIPE, text=True)
f['svg_fix'] = svgbob_fix.stdout
return render_template(
'catalogue.html',
title = title,
databases = databases,
output = output,
params = params)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')