forked from tchapi/Adafruit-GFX-Font-Customiser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1175 lines (1025 loc) · 39.7 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<meta charset="utf-8">
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<style>
html, body {
margin: 0 10px;
}
textarea {
font-family: "Courier", monotype;
font-size: 0.9em !important;
}
.explanation ul {
list-style-type: circle;
margin: 0;
padding-left: 14px;
}
.explanation h5 {
margin-bottom: 4px;
margin-top: 4px;
}
#glyphs div.inner {
padding: 10px 0;
position: relative;
}
#glyphs .centered.inner {
padding: 10px;
text-align: center;
}
#glyphs h2.inner {
font-size: 2em;
padding: 0.3em;
text-align: center;
}
#glyphs div.table {
user-select: none;
position: relative;
width: max-content;
margin: auto;
}
#glyphs div.table div.row {
height: 10px;
position: relative;
}
#glyphs div.table div.row:first-child div.cell {
height: 10px;
border-top: 1px solid lightgrey;
}
#glyphs div.table div.cell {
border-bottom: 1px solid lightgrey;
border-right: 1px solid lightgrey;
width: 10px;
height: 10px;
display: inline-block;
cursor: pointer;
}
#glyphs div.table div.cell:first-child {
border-left: 1px solid lightgrey;
}
#glyphs div.table div.cell.fill {
background: black;
}
#glyphs div.table div.cell:hover {
background: #999;
}
#glyphs div.table div.cell.fill.over {
box-shadow: 0 0 9px #D00 inset;
}
#glyphs div.table div.cell.dead {
background: #DDD;
}
#loader {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
color: white;
font-weight: bold;
font-size: 2em;
display: flex;
justify-content: center;
align-items: center;
z-index: 10;
display: flex;
flex-direction: column;
}
.advance-wrapper {
width: 300px;
position: relative;
border: 1px solid lightgray;
height: 30px;
margin-bottom: 20px;
}
.advance {
opacity: 0.7;
background: white;
width: 10px;
height: 24px;
margin: 2px;
}
.baseline {
position:absolute;
left:0px;
width:100%;
height:1px;
background-color:#090;
opacity:0.6;
pointer-events: none;
}
.limit {
position: absolute;
top: 0px;
width: 2px;
height: 100%;
opacity: 0.4;
pointer-events: none;
background-color: #900;
}
#add {
margin-top: 10px;
}
span.np {
font-size: 0.5em;
color: #CCC;
font-style: italic;
}
.glyph-grid {
display: flex;
flex-wrap: wrap;
align-items: stretch;
justify-content: center;
}
.glyph-grid > div {
padding-left: 1rem;
padding-right: 1rem;
}
</style>
</head>
<body>
<a href="https://github.com/tchapi/Adafruit-GFX-Font-Customiser"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
<h1 class="ui header">Adafruit GFX Pixel font customiser</h1>
<p>
<em>Created by <a href="https://github.com/tchapi">tchapi</a>, major improvements by <a href="https://github.com/cmarrin">cmarrin</a> and <a href="https://github.com/charno">charno</a> - Source code available on <a href="https://github.com/tchapi/Adafruit-GFX-Font-Customiser">Github</a>.</em>
</p>
<div class="ui divider"></div>
<div class="ui grid">
<div class="eight wide column">
<div class="ui teal segment">
<div class="ui form">
<div class="field">
<label>Extract font from source</label>
<textarea id="source"></textarea>
</div>
<button class="ui button teal" id="extract"><i class="icon upload"></i> Extract</button>
<button class="ui button red right floated" id="reset" disabled><i class="icon undo"></i> Reset</button>
<button class="ui button blue right floated" id="createFont"><i class="icon file outline"></i> Create a new font</button>
</div>
</div>
</div>
<div class="ui small modal choose">
<div class="header">Add a new character</div>
<div class="content">
<p>The character will be added to the set (<em>either at the end or at the beginning, depending on its code</em>), and if it is not contiguous with the previous set, <strong>the interval characters will be added too</strong>, but disabled, so that they do not take much space in the exported glyphs</p>
<form class="ui form">
<div class="field">
<div class="ui toggle checkbox use-charcode">
<input type="checkbox" name="charcode" tabindex="0" class="hidden">
<label>Use char code (hex)</label>
</div>
</div>
</form>
<div class="ui right labeled input">
<input type="text" id="new-character" placeholder="Character to add" maxlength="1">
<a class="ui label">
Char Code: <kbd class="charcode">N/A</kbd>
</a>
</div>
<div class="ui right labeled input">
<input type="text" id="new-character-code" placeholder="Character code to add (hex)" maxlength="4">
<a class="ui label">
Character: <kbd class="character">N/A</kbd>
</a>
</div>
</div>
<div class="actions">
<div class="ui cancel red button">Cancel</div>
<div class="ui approve green button">Add</div>
</div>
</div>
<div class="ui small modal newfont">
<div class="header">Create a new font</div>
<div class="content">
<p>To create a new font, you need to provide some details.</p>
<form class="ui form">
<div class="field">
<label>Font name</label>
<input type="text" id="newfont-name" placeholder="Name of the new font">
</div>
<div class="field">
<label>Font height</label>
<p>Font height in pixels</p>
<input id="newfont-height" type="number" value="1" min="1" placeholder="Height of the new font">
</div>
<div class="field">
<label>First character</label>
<p>The new font will be created with one character. You can add more characters later.</p>
<div class="ui toggle checkbox newfont-use-charcode">
<input type="checkbox" name="newfontCharcode" tabindex="0" class="hidden">
<label>Use char code (hex)</label>
</div>
</div>
</form>
<div class="ui right labeled input">
<input type="text" id="newfont-new-character" placeholder="Character to add" maxlength="1">
<a class="ui label">
Char Code: <kbd class="newfontCharcode">N/A</kbd>
</a>
</div>
<div class="ui right labeled input">
<input type="text" id="newfont-new-character-code" placeholder="Character code to add (hex)" maxlength="4">
<a class="ui label">
Character: <kbd class="newfontCharacter">N/A</kbd>
</a>
</div>
</div>
<div class="actions">
<div class="ui cancel red button">Cancel</div>
<div class="ui approve green button">Create</div>
</div>
</div>
<div class="ui small modal message">
<div class="header">⚠️ Warning</div>
<div class="content">
<p></p>
</div>
<div class="actions">
<div class="ui approve blue button">Ok</div>
</div>
</div>
<div class="ui small modal confirmation">
<div class="header">⚠️ Warning</div>
<div class="content">
<p></p>
</div>
<div class="actions">
<div class="ui cancel blue button">Cancel</div>
<div class="ui approve red button">Reset</div>
</div>
</div>
<div class="eight wide column">
<div class="ui green segment" id="resultWrapper">
<div class="ui form">
<div class="field">
<label>Output</label>
<textarea id="result" readonly></textarea>
</div>
<div class="two fields">
<div class="field">
<label>First glyph to export</label>
<input type="text" id="firstglyph" value="0x00" />
</div>
<div class="field">
<label>Last glyph to export</label>
<input type="text" id="lastglyph" value="0x00" />
</div>
</div>
<button class="ui button green" id="export" disabled="disabled"><i class="icon download"></i> Process and create file</button>
</div>
</div>
</div>
</div>
<div class="ui divider"></div>
<h2 class="ui header">How to use it</h2>
<div class="ui grid">
<div class="five wide column">
<div class="ui explanation">
<h5>Importing or creating a font:</h5>
You can either:
<ul>
<li>Extract a font by copying & pasting the existing font source (a <kbd>.h</kbd> file) in the textarea above</li>
<li>Create a new font with a single character</li>
</ul>
<h5>Adding characters:</h5>
<p>You can easily add new characters to the font afterwards. Interval characters will be added automatically <em>as disabled glyphs</em>.</p>
</div>
</div>
<div class="eleven wide column">
<div class="ui explanation">
<h5>Editing glyphs:</h5>
Glyphs can be edited individually. You can:
<ul>
<li>Enable or disable the glyph</li>
<li>Edit each pixel of the glyph</li>
<li>Edit all values present in the GFXglyph data structure (See <a href="https://learn.adafruit.com/creating-custom-symbol-font-for-adafruit-gfx-library/understanding-the-font-specification">Adafruit documentation</a> for more information)</li>
</ul>
<h5>When exporting, you can either :</h5>
<ul>
<li>Select a range of characters to include in the output. Characters outside of this range will <strong>not</strong> be included in the bitmap nor in the glyphs table.</li>
<li>Disable individual characters. The disabled characters get all values set to <kbd>0</kbd>. There still are entries for the disabled characters in the glyphs table, but no data in the bitmap for them — this keeps the characters in their correct places in the ASCII table.</li>
</ul>
</div>
</div>
</div>
<div class="ui divider"></div>
<h2 class="ui header">Glyphs <em class="fontname" style="display: none;">FontName unknown</em></h2>
<p><button class="ui small button violet" id="add" disabled="disabled"><i class="icon add"></i> Add a new character</button></p>
<div id="loader">
<div class="advance-wrapper"><div class="advance"></div></div>
<span>Loading and extracting font ...</span>
</div>
<div id="glyphs" class="ui glyph-grid"><em>Please open or create a font first.</em></div>
</body>
<script>
function makeUpDownButton (name, func, color, width) {
const button = $('<div class="ui mini compact buttons" style="margin:1px"></div>')
const style = 'ui compact button ' + func + '-handler ' + color
button.append('<button id="' + func + '-remove" class="' + style + '">-</button>')
button.append('<button id="' + func + '-value" class="ui compact disabled button ' + color + '" style="width:' + width + '">' + name + '</button>')
button.append('<button id="' + func + '-add" class="' + style + '">+</button>')
return button
}
function makeCheckButton (name, func, color, width, disabled) {
const button = $('<span class="ui mini compact" style="margin:1px"></span>')
button.append('<label class="ui '+color+' label" disabled style="width:' + width + '""><input type="checkbox" class="'+func+'-handler" id="'+func+'"' + (disabled ? ' checked="checked"' : '') + '> '+name+'</label>')
return button
}
function makeGlyphItem (n, w, h, char, adv, ow, oh, disabled) {
const charCode = char.charCodeAt(0)
const table = $('<div class="table"></div>')
.addClass('glyph')
.attr('data-pixels', n)
.attr('data-w', w)
.attr('data-h', h)
.attr('data-char', char)
.attr('data-adv', adv)
.attr('data-ow', ow)
.attr('data-oh', oh)
.attr('data-dis', disabled ? 1 : 0)
.css('opacity', disabled ? 0.1 : 1)
const min_glyph_width = (window['max_advance'] * 11 + 30 /* some margin */)
const grid = $(`<div style="width: ${min_glyph_width}px"></div>`)
const div = $('<div class="ui attached segment inner"></div>')
div.append(table)
if (char == ' ') {
grid.append('<h2 class="ui top attached segment inner"><span class="np">space</span></h2>')
} else {
// Display a specific text for non-printable characters
grid.append('<h2 class="ui top attached segment inner">' + char.replace(/[\x00-\x1F\x7F-\x9F\xAD]/g, '<span class="np">non-printable</span>') + '</h2>')
}
grid.append('<div class="ui attached segment inner secondary centered">' + '0x' + charCode.toString(16).toUpperCase() + '</div>')
grid.append(div)
const buttonBar = $('<div class="ui bottom attached warning message inner centered"></div>')
buttonBar.append(makeUpDownButton('Rows', 'row', 'purple', 50))
buttonBar.append(makeUpDownButton('Cols', 'col', 'violet', 50))
buttonBar.append(makeUpDownButton('Base', 'base', 'green', 50))
buttonBar.append(makeUpDownButton('XOff', 'xoff', 'blue', 50))
buttonBar.append(makeUpDownButton('XAdv', 'xadv', 'teal', 50))
buttonBar.append(makeCheckButton('Disable', 'dis', 'yellow', 110, disabled))
grid.append(buttonBar)
return grid
}
function setGlyphTable (table) {
const xadvance = parseInt(table.attr('data-adv'))
const yadvance = parseInt(window['yAdvance'])
const xoffset = parseInt(table.attr('data-ow'))
const yoffset = parseInt(table.attr('data-oh'))
const width = parseInt(table.attr('data-w'))
const height = parseInt(table.attr('data-h'))
const pixels = table.attr('data-pixels')
const maxBaseline = window['maxBaseline']
const left = xoffset
const right = width + xoffset
const top = maxBaseline + yoffset
const bottom = top + height
// Set the table
table.empty()
for (let i = 0; i < yadvance; i++) {
const row = $('<div></div>').addClass('row')
for (let j = Math.min(0, xoffset); j <= Math.max(xadvance, right); j++) {
const cell = $('<div></div>').addClass('cell').attr('data-x', j).attr('data-y', i)
// These classes are used to position the "limits" vertical lines
if (i === 0 && j === 0) {
cell.addClass('before_xoffset')
}
if (i === 0 && j === xadvance) {
cell.addClass('before_xadvance')
}
// Now draw the actual pixels
if (i < top || i >= bottom || j < left || j >= right) {
cell.addClass('dead')
} else if (pixels.charAt((i - top) * width + (j - left)) == '1') {
cell.addClass('fill')
}
// If the pixel is after xadvance, or before xoffset
if (j >= xadvance || j < Math.max(0, xoffset)) {
cell.addClass('over')
}
row.append(cell)
}
table.append(row)
}
// Draw the xadvance/xoffset limits
// (We need to get the actual cell position before hand)
const left_xoffset = table.find('div.before_xoffset')[0].offsetLeft
xoffset_limit = $('<div class="xoffset_limit limit"></div>').css('left', (left_xoffset - 1) + 'px') // -1 accounts for first border of table
table.append(xoffset_limit)
const left_xadvance = table.find('div.before_xadvance')[0].offsetLeft
xadvance_limit = $('<div class="xadvance_limit limit"></div>').css('left', (left_xadvance - 1) + 'px')
table.append(xadvance_limit)
// Set the baseline
baseline = $('<div class="baseline"></div>').css('top', ((maxBaseline + 1) * 10 - 1) + 'px')
table.append(baseline)
}
function updatePixels (table, newWidth, newHeight, x, y, fill) {
const dataPixels = table.attr('data-pixels')
const width = parseInt(table.attr('data-w'))
const height = parseInt(table.attr('data-h'))
const xoff = parseInt(table.attr('data-ow'))
const base = parseInt(table.attr('data-oh'))
const xAdjust = xoff * -1
const yAdjust = (window['maxBaseline'] + base) * -1
if (newWidth < 0) {
newWidth = width
}
if (newHeight < 0) {
newHeight = height
}
if (x >= 0 && y >= 0) {
x += xAdjust
y += yAdjust
}
// Store the pixels into a 2D bool array
const array = []
let pixelIndex = 0
for (let i = 0; i < height; ++i) {
const rowArray = []
for (let j = 0; j < width; ++j) {
if(x == j && y == i) {
rowArray.push(fill)
} else {
rowArray.push(dataPixels.charAt(pixelIndex))
}
++pixelIndex
}
array.push(rowArray)
}
// Write out to a string newWidth x newHeight
let newPixels = ''
for (let i = 0; i < newHeight; ++i) {
for (let j = 0; j < newWidth; ++j) {
if (i >= height || j >= width) {
newPixels += '0'
} else {
newPixels += array[i][j]
}
}
}
// Pad out to a multiple of 8
const pad = newPixels.length % 8
for (let i = 0; i < pad; ++i) {
newPixels += '0'
}
table.attr('data-pixels', newPixels)
}
function advanceLoading (percent) {
const element = document.querySelector('#loader .advance')
element.style.width = Math.floor(294 * percent)
}
function extractFont () {
let data = $('#source').val()
// Extract name
const re = /const\ uint8\_t\ (.*)Bitmaps\[\]/
const found = data.match(re)
if (found != null && found.length > 1) {
window['name'] = found[1]
} else {
alert('No correct font file found, please paste the content of an Adafruit GFX font file first.')
$("#loader").hide()
return
}
$('#glyphs').empty()
// extract GFXFont part
const last_part_re = /const\ GFXfont([\s\S]*)/g
const last_part = data.match(last_part_re)
window['last_part'] = last_part[0]
// Get first, last and yOffset
let parts = last_part[0].split(',')
const number_re = /0[xX][0-9a-fA-F]+|[0-9]+/gi
window['first'] = parts[2].match(number_re)[0]
window['last'] = parts[3].match(number_re)[0]
window['yAdvance'] = parts[4].match(number_re)[0]
data = data.replace(last_part[0], '')
data = data.replace(/\{/gi, '[').replace(/\}/gi, ']')
data = data.replace('const GFXglyph ', '').replace('const uint8_t ', '').replace(/\[\]\ PROGMEM/gi, '')
eval(data)
/*
// Tada 🎉
console.log(window["name"])
console.log(window["size"])
console.log(window["first"])
console.log(window["last"])
console.log(window["last_part"])
console.log(window[name + "Bitmaps"])
console.log(window[name + "Glyphs"])
*/
$('.fontname').text('(' + window['name'].slice(0, window['name'].length - 1) + ')').show()
$('#firstglyph').val(window["first"])
$('#lastglyph').val(window["last"])
$('#add').attr('disabled', false)
const glyphsArray = window[name + 'Glyphs']
// Calculate the max yAdv to scale the table columns for the glyphs
let maxXAdv = 0
for (ind in glyphsArray) {
maxXAdv = Math.max(maxXAdv, glyphsArray[ind][3])
}
window['max_advance'] = maxXAdv
// Space from the baseline to the top of the character cell is determined by the character with the
// largest negative yOffset.
let maxBaseline = 0
// Display tables
for (ind in glyphsArray) {
// for each glyph
const char = String.fromCharCode(parseInt(window['first'], 16) + parseInt(ind))
const w = glyphsArray[ind][1]
const h = glyphsArray[ind][2]
const adv = glyphsArray[ind][3]
const ow = glyphsArray[ind][4]
const oh = glyphsArray[ind][5]
let n = ''
maxBaseline = Math.max(maxBaseline, -oh)
// extract numbers
currentOffset = glyphsArray[parseInt(ind)][0]
if (parseInt(ind) + 1 < glyphsArray.length) {
nextOffset = glyphsArray[parseInt(ind) + 1][0]
} else {
nextOffset = window[name + 'Bitmaps'].length
}
for (let k = 0; k < (nextOffset - currentOffset); k++) {
n += ('000000000' + window[name + 'Bitmaps'][currentOffset + k].toString(2)).substr(-8)
}
let disabled = (w == 0 || h == 0) && adv == 0
grid = makeGlyphItem (n, w, h, char, adv, ow, oh, disabled)
function glyphAppendClosure(el, adv, maxBaseline) {
setTimeout(function () {
advanceLoading(0.2 * adv)
$('#glyphs').append(el)
if (adv === 1) {
// Run the setGlyphTable function now
displayGlyphTable(maxBaseline)
}
}, 1)
}
glyphAppendClosure(grid, (parseInt(ind) + 1) / glyphsArray.length, maxBaseline)
}
$('#export').prop( "disabled", false )
$('#reset').prop("disabled", false)
$('#createFont').prop( "disabled", true )
$('#extract').prop( "disabled", true )
}
function displayGlyphTable (maxBaseline) {
window['maxBaseline'] = maxBaseline
const l = $('#glyphs').children().length
$('#glyphs').children().each(function (i) {
function setGlyphTableClosure(el, adv) {
setTimeout(function () {
advanceLoading(0.2 + 0.8 * adv)
setGlyphTable(el.children().find('.glyph'))
if (adv === 1) {
$('#loader').hide()
}
}, 1)
}
setGlyphTableClosure($(this), (i + 1) / l)
})
}
$(document).ready(function () {
$('#new-character-code').parent().hide()
$('#add').attr('disabled', 'disabled')
$('#export').attr('disabled', 'disabled')
$('#reset').prop("disabled", 'disabled')
$('.ui.checkbox.use-charcode').checkbox()
$(document).on('change', '.ui.checkbox.use-charcode input', function (e) {
$('#new-character').parent().toggle()
$('#new-character-code').parent().toggle()
if ($('input[name=charcode]').is(':checked')) {
if ($('#new-character-code').val() == '') {
$('.character').text('N/A')
} else {
$('.character').text(String.fromCharCode(parseInt($('#new-character-code').val(), 16)))
}
} else {
if ($('#new-character').val() == '') {
$('.charcode').text('N/A')
} else {
$('.charcode').text('0x' + $('#new-character').val().charCodeAt(0).toString(16).toUpperCase())
}
}
})
$('#newfont-new-character-code').parent().hide()
$('.ui.checkbox.newfont-use-charcode').checkbox()
$(document).on('change', '.ui.checkbox.newfont-use-charcode input', function (e) {
$('#newfont-new-character').parent().toggle()
$('#newfont-new-character-code').parent().toggle()
if ($('input[name=newfontCharcode]').is(':checked')) {
if ($('#newfont-new-character-code').val() == '') {
$('.newfontCharacter').text('N/A')
} else {
$('.newfontCharacter').text(String.fromCharCode(parseInt($('#newfont-new-character-code').val(), 16)))
}
} else {
if ($('#newfont-new-character').val() == '') {
$('.newfontCharcode').text('N/A')
} else {
$('.newfontCharcode').text('0x' + $('#newfont-new-character').val().charCodeAt(0).toString(16).toUpperCase())
}
}
})
$('#loader').hide()
window['name'] = null
window['last_part'] = null
$('#extract').click(function () {
advanceLoading(0)
$('#loader').fadeIn(function() {
extractFont()
})
})
$('#reset').click(function () {
$('.ui.modal.confirmation p').text('The reset will close the font and discard any changes you made.')
$('.ui.modal.confirmation').modal({
closable: false,
onApprove: function() {
$('#glyphs').empty()
$('#source').val('')
$('#createFont').prop("disabled", false)
$('#extract').prop("disabled", false)
$('#add').prop("disabled", "disabled")
$('#export').prop("disabled", "disabled")
$('#reset').prop("disabled", "disabled")
$('.fontname').text('Fontname unknown').hide()
}
}).modal('show')
})
const fillPixel = (target, fill) => {
fill === '1' ? target.addClass('fill') : target.removeClass('fill')
const table = target.parent().parent().parent().find('.table.glyph')
updatePixels(table, -1, -1, parseInt(target.attr('data-x')), parseInt(target.attr('data-y')), fill)
}
let isFilling = false;
let fillingMode = '1';
$(document).on('mousedown', '.cell:not(.dead)', function (e) {
isFilling = true;
fillingMode = $(e.target).hasClass('fill') ? '0' : '1'
fillPixel($(e.target), fillingMode)
})
$(document).on('mouseup', '.cell:not(.dead)', function (e) {
isFilling = false;
})
$(document).on('mouseenter', '.cell:not(.dead)', function (e) {
if (isFilling) {
fillPixel($(e.target), fillingMode)
}
})
$(document).on('click', '.row-handler', function (e) {
const targetID = $(e.target).attr('id')
const table = $(e.target).parent().parent().parent().find('.table.glyph')
let height = parseInt(table.attr('data-h'))
if (targetID === 'row-add') {
height++
} else if (targetID === 'row-remove') {
height--
}
updatePixels(table, -1, height, -1, -1, false)
table.attr('data-h', height)
setGlyphTable(table)
return false
})
$(document).on('click', '.col-handler', function (e) {
const targetID = $(e.target).attr('id')
const table = $(e.target).parent().parent().parent().find('.table.glyph')
let width = parseInt(table.attr('data-w'))
if (targetID === 'col-add') {
width++
} else if (targetID === 'col-remove') {
width--
}
updatePixels(table, width, -1, -1, -1, false)
table.attr('data-w', width)
setGlyphTable(table)
return false
})
$(document).on('click', '.base-handler', function (e) {
const targetID = $(e.target).attr('id')
const table = $(e.target).parent().parent().parent().find('.table.glyph')
if (targetID === 'base-add') {
table.attr('data-oh', parseInt(table.attr('data-oh')) + 1)
} else if (targetID === 'base-remove') {
table.attr('data-oh', parseInt(table.attr('data-oh')) - 1)
}
setGlyphTable(table)
return false
})
$(document).on('click', '.xadv-handler', function (e) {
const targetID = $(e.target).attr('id')
const table = $(e.target).parent().parent().parent().find('.table.glyph')
if (targetID === 'xadv-add') {
table.attr('data-adv', parseInt(table.attr('data-adv')) + 1)
} else if (targetID === 'xadv-remove') {
table.attr('data-adv', parseInt(table.attr('data-adv')) - 1)
}
setGlyphTable(table)
return false
})
$(document).on('click', '.xoff-handler', function (e) {
const targetID = $(e.target).attr('id')
const table = $(e.target).parent().parent().parent().find('.table.glyph')
if (targetID === 'xoff-add') {
table.attr('data-ow', parseInt(table.attr('data-ow')) + 1)
} else if (targetID === 'xoff-remove') {
table.attr('data-ow', parseInt(table.attr('data-ow')) - 1)
}
setGlyphTable(table)
return false
})
$(document).on('change', '.dis-handler', function (e) {
const table = $(e.target).parent().parent().parent().parent().find('.table.glyph')
table.attr('data-dis', 1 - parseInt(table.attr('data-dis')))
table.fadeTo('fast', 1 - 0.9 * table.attr('data-dis'))
return false
})
$(document).on('keyup', '#new-character', function (e) {
if ($('#new-character').val() == '') {
$('.charcode').text('N/A')
} else {
$('.charcode').text('0x' + $('#new-character').val().charCodeAt(0).toString(16).toUpperCase())
}
})
$(document).on('keyup', '#new-character-code', function (e) {
if ($('#new-character-code').val() == '') {
$('.character').text('N/A')
} else {
$('.character').text(String.fromCharCode(parseInt($('#new-character-code').val(), 16)))
}
})
$(document).on('keyup', '#newfont-new-character', function (e) {
if ($('#newfont-new-character').val() == '') {
$('.newfontCharcode').text('N/A')
} else {
$('.newfontCharcode').text('0x' + $('#newfont-new-character').val().charCodeAt(0).toString(16).toUpperCase())
}
})
$(document).on('keyup', '#newfont-new-character-code', function (e) {
if ($('#newfont-new-character-code').val() == '') {
$('.newfontCharacter').text('N/A')
} else {
$('.newfontCharacter').text(String.fromCharCode(parseInt($('#newfont-new-character-code').val(), 16)))
}
})
$('#createFont').click(function () {
$('input[name=newfontCharcode]').prop('checked', false)
$('#newfont-new-character').parent().show()
$('#newfont-new-character-code').parent().hide()
if ($('#newfont-new-character').val() == '') {
$('.charcode').text('N/A')
} else {
$('.charcode').text('0x' + $('#newfont-new-character').val().charCodeAt(0).toString(16).toUpperCase())
}
if ($('#newfont-new-character-code').val() == '') {
$('.character').text('N/A')
} else {
$('.character').text(String.fromCharCode($('#newfont-new-character-code').val()))
}
$('.ui.modal.newfont').modal({
closable: false,
onApprove: function() {
let name = $('#newfont-name').val()
if (name.length < 1) {
$('.ui.modal.message p').text('The font must have a name, I\'m not creating a new font with it.')
$('.ui.modal.message').modal('show')
return
}
let newfontHeight = parseInt($('#newfont-height').val())
if (newfontHeight < 1) {
$('.ui.modal.message p').text('The font height must be greater than 0, I\'m not creating a new font with it.')
$('.ui.modal.message').modal('show')
return
}
// Get new character data
let newChar
let newCharCode
if ($('input[name=newfontCharcode]').is(':checked')) {
newCharCode = parseInt($('#newfont-new-character-code').val(), 16)
newChar = String.fromCharCode(newCharCode)
} else {
newChar = $('#newfont-new-character').val()
newCharCode = $('#newfont-new-character').val().charCodeAt(0)
}
// Check character validity
if (newChar == '') {
$('.ui.modal.message p').text('This character is either blank or incorrect, I\'m not creating a new font with it.')
$('.ui.modal.message').modal('show')
return
}
if (newCharCode < 1) {
$('.ui.modal.message p').text('This is a special control character, I\'m not creating a new font with it.')
$('.ui.modal.message').modal('show')
return
}
if (newCharCode > 65535) {
$('.ui.modal.message p').text('This character is out of range, I\'m not creating a new font with it.')
$('.ui.modal.message').modal('show')
return
}
// Set the font parameters
window['first'] = newCharCode
window['last'] = newCharCode
window['yAdvance'] = newfontHeight
window['name'] = name + '_'
window[name + '_Bitmaps'] = [] // This is otherwise created by the eval() in extract font
window['maxBaseline'] = newfontHeight
window['last_part'] = 'const GFXfont ' + name + ' PROGMEM = {(uint8_t *) ' + name + '_Bitmaps, (GFXglyph *)' + name + '_Glyphs, 0x00, 0x00, ' + newfontHeight + '};'
// Show the data
$('.fontname').text('(' + name + ')').show()
$('#firstglyph').val('0x' + window["first"].toString(16))
$('#lastglyph').val('0x' + window["last"].toString(16))
$('#glyphs').empty()
// Change button states
$('#add').attr('disabled', false)
$('#export').prop( "disabled", false )
$('#createFont').prop( "disabled", true )
$('#extract').prop( "disabled", true )
$('#reset').prop("disabled", false)
// Add the new character
const grid = makeGlyphItem (' ' , 1, 1, newChar, 4, 0, -newfontHeight, false)
$('#glyphs').append(grid)
setGlyphTable(grid.find('.glyph'))
}
})
.modal('show')
})
$('#add').click(function () {
$('input[name=charcode]').prop('checked', false)
$('#new-character').parent().show()
$('#new-character-code').parent().hide()
if ($('#new-character').val() == '') {
$('.charcode').text('N/A')
} else {
$('.charcode').text('0x' + $('#new-character').val().charCodeAt(0).toString(16).toUpperCase())
}
if ($('#new-character-code').val() == '') {
$('.character').text('N/A')
} else {
$('.character').text(String.fromCharCode($('#new-character-code').val()))
}
// Choose a character
$('.ui.modal.choose').modal({
closable: false,
onApprove: function() {
const firstglyph = parseInt($('#firstglyph').val(), 16)
const lastglyph = parseInt($('#lastglyph').val(), 16)
let newChar
let newCharCode
if ($('input[name=charcode]').is(':checked')) {
newCharCode = parseInt($('#new-character-code').val(), 16)
newChar = String.fromCharCode(newCharCode)
} else {
newChar = $('#new-character').val()
newCharCode = $('#new-character').val().charCodeAt(0)