Debian Codegraph @

dokidoki/default_font.lua

raw symbols SCIP
1 require 'dokidoki.module' [[ load ]]
2
3 local stb_image = require 'stb_image'
4 local graphics = require 'dokidoki.graphics'
5
6 local data =
7 "\137\80\78\71\13\10\26\10\0\0\0\13\73\72\68\82\0\0\0\64\0\0\0\53\8\4\0\0\0"..
8 "\91\143\37\39\0\0\0\1\115\82\71\66\0\174\206\28\233\0\0\2\64\73\68\65\84\88"..
9 "\195\237\89\219\114\197\32\8\4\166\255\255\203\246\193\82\228\42\38\233\101"..
10 "\230\156\204\164\158\24\53\136\203\178\90\128\239\107\12\254\59\127\233\122"..
11 "\127\113\189\244\187\114\81\246\98\12\109\144\24\198\111\184\29\34\0\0\226"..
12 "\185\9\99\4\6\32\206\123\157\213\90\199\207\186\70\15\122\209\39\182\131"..
13 "\184\120\29\112\12\235\129\108\73\108\59\253\188\53\144\59\72\105\103\24\27"..
14 "\208\247\128\123\239\61\160\103\158\97\160\11\86\111\232\67\87\61\160\117"..
15 "\124\115\1\94\232\194\191\250\240\92\2\100\250\152\37\162\188\144\146\111"..
16 "\91\31\151\241\199\164\222\253\142\194\198\134\156\13\67\75\58\182\77\12\82"..
17 "\29\85\41\19\10\106\125\25\133\97\212\78\127\152\121\19\81\147\246\87\59"..
18 "\235\129\40\198\35\143\100\207\39\30\0\0\248\136\137\194\167\150\156\112"..
19 "\188\99\231\76\215\52\197\179\95\49\176\162\225\71\80\254\166\154\227\52\44"..
20 "\217\47\122\246\217\81\178\100\93\111\1\107\32\27\197\114\7\233\62\61\107"..
21 "\152\250\126\222\176\144\7\114\116\102\193\118\15\108\228\7\202\212\29\155"..
22 "\181\82\105\78\191\126\34\113\59\218\105\188\171\136\234\202\84\66\204\169"..
23 "\85\175\109\173\233\120\77\35\10\139\12\153\244\244\166\128\255\65\67\94"..
24 "\207\103\178\188\119\235\126\126\95\160\17\65\12\155\72\245\240\142\232\4"..
25 "\44\146\247\230\47\9\110\201\145\171\9\116\55\159\121\52\215\232\182\19\34"..
26 "\223\97\62\203\76\118\251\1\214\147\179\159\167\159\122\26\228\29\92\119"..
27 "\121\58\126\41\27\216\46\128\55\43\167\224\93\207\116\95\240\228\220\214\60"..
28 "\177\2\188\151\71\94\82\15\85\217\189\106\19\169\101\189\73\217\68\193\249"..
29 "\217\78\134\20\169\61\89\89\90\79\132\226\244\235\79\195\44\105\215\135\53"..
30 "\185\38\84\146\76\230\37\212\188\18\139\228\123\222\196\234\246\123\79\105"..
31 "\197\197\111\233\10\203\119\219\91\62\104\106\194\120\9\114\229\116\14\244"..
32 "\199\88\167\123\44\245\171\123\191\247\158\48\219\184\59\50\131\1\163\23\5"..
33 "\87\93\170\65\38\49\161\23\137\44\49\216\242\252\174\81\192\92\18\106\66"..
34 "\182\155\137\166\163\9\173\142\16\237\151\125\92\143\70\213\192\245\33\171"..
35 "\150\100\94\210\85\217\194\104\194\108\171\21\173\161\12\110\135\203\254"..
36 "\227\114\0\177\187\17\92\29\95\101\81\240\160\1\215\40\232\19\158\224\92\31"..
37 "\251\141\41\17\0\0\0\0\73\69\78\68\174\66\96\130"
38
39 local chars_per_row = 16
40
41 local char_width = 4
42 local char_height = 9
43
44 local char_size = {4, 9}
45 local char_origin = {0, char_height}
46
47 local start_code = string.byte(' ')
48 local end_code = string.byte('~')
49
50 -- looks like it wasn't such a good idea to pack the characters so tightly...
51 local epsilon = 0.01
52
53 function load()
54 local tex, width, height = graphics.texture_from_string(
55 assert(stb_image.load_from_string(data)))
56
57 local fontmap = {}
58
59 for code = start_code, end_code do
60 local i = code - start_code
61 local x = (i % chars_per_row) * char_width + epsilon
62 local y = math.floor(i / chars_per_row) * char_height + epsilon
63 local rect = {
64 x/width,
65 y/height,
66 (char_width-epsilon*2)/width,
67 (char_height-epsilon*2)/height
68 }
69
70 fontmap[string.char(code)] = graphics.make_sprite(
71 tex, char_size, char_origin, rect)
72 end
73
74 return fontmap
75 end
76
77 return get_module_exports()