Libraryless. Click here for Pure Java version (4338L/30K/96K).
1 | !752 |
2 | |
3 | sS fontID = "#1004569"; // "Ticketing" |
4 | static float fontSize = 30f; |
5 | |
6 | static int tooLong = 60; // << glyphs with that many unicode chars assigned are usually just empty boxes |
7 | |
8 | sclass Glyph { |
9 | BWImage img; |
10 | new StringBuilder chars; |
11 | } |
12 | |
13 | static Map<S, Glyph> map = litorderedmap(); // key = md5 |
14 | static BWImage img; |
15 | |
16 | p { |
17 | setConsoleDelay(2000); // saves time, 14 instead of 21s |
18 | |
19 | long time = now(); |
20 | for (int uc = 0; uc <= 0xFFFF; uc++) { |
21 | print(intToHex(uc) + " " + l(map)); |
22 | BufferedImage bufImg = renderText(fontID, fontSize, str((char) uc)); |
23 | if (bufImg == null) continue; |
24 | BWImage img = new BWImage(bufImg); |
25 | S md5 = md5OfBWImage(img); |
26 | Glyph g = map.get(md5); |
27 | if (g == null) { |
28 | map.put(md5, g = new Glyph); |
29 | g.img = img; |
30 | } |
31 | g.chars.append((char) uc); |
32 | } |
33 | done_always(time, "Got " + l(map) + " different glyphs!"); |
34 | |
35 | time = now(); |
36 | /*Glyph longest = (Glyph) highest(makeMap( |
37 | func(Glyph g) { l(g.chars) }, values(map)));*/ |
38 | new L<BWImage> images; |
39 | for (Glyph g : values(map)) { |
40 | //S title = g == longest ? "the rest" |
41 | S title = l(g.chars) > tooLong ? "...." |
42 | : formatCharRange(str(g.chars)); |
43 | print(title); |
44 | images.add(subtitle(g.img, title)); |
45 | } |
46 | |
47 | img = clusterImages(images); |
48 | done_always(time, "Making glyph image (" + img.getWidth() + "/" + img.getHeight() + ")"); |
49 | |
50 | final S title = "Glyph Sheet For Font " |
51 | + quote(getSnippetTitle(fontID)) + " (" + fsi(fontID) + ") Size " + fontSize; |
52 | addToWindow(showBWImage(title, img), jbutton("Upload", r { |
53 | messageBox(uploadImage(title, toPNG(img.getBufferedImage()))); |
54 | })); |
55 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004630 |
Snippet name: | Make Glyph Sheet For Learning A Font |
Eternal ID of this version: | #1004630/1 |
Text MD5: | 0e4460efa226f349a269418eba419d2f |
Transpilation MD5: | 938bed75f640246cd4644152bd7c8c0d |
Author: | stefan |
Category: | javax / images |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-24 20:18:16 |
Source code size: | 1675 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 623 / 760 |
Referenced in: | [show references] |