|
| 1 | +package imagelabel |
| 2 | + |
| 3 | +// A 3 by 5 pixel font, drawn here rather than taken from a font file. |
| 4 | +// |
| 5 | +// Two reasons. A font file is a dependency with a licence to check, and this |
| 6 | +// project answers that question often enough already. And a bitmap font is |
| 7 | +// exact - the same label renders to the same pixels on every machine and |
| 8 | +// every version, which the byte stability promise needs. |
| 9 | +// |
| 10 | +// Letters are drawn in upper case only. At three pixels wide, lower case is |
| 11 | +// not legible, and the label is metadata rather than content. |
| 12 | +// |
| 13 | +// Each glyph is five rows of three columns. A '#' is a lit pixel. |
| 14 | + |
| 15 | +const ( |
| 16 | + glyphWidth = 3 |
| 17 | + glyphHeight = 5 |
| 18 | +) |
| 19 | + |
| 20 | +var glyphs = map[rune]string{ |
| 21 | + 'A': "###" + "#.#" + "###" + "#.#" + "#.#", |
| 22 | + 'B': "##." + "#.#" + "##." + "#.#" + "##.", |
| 23 | + 'C': "###" + "#.." + "#.." + "#.." + "###", |
| 24 | + 'D': "##." + "#.#" + "#.#" + "#.#" + "##.", |
| 25 | + 'E': "###" + "#.." + "##." + "#.." + "###", |
| 26 | + 'F': "###" + "#.." + "##." + "#.." + "#..", |
| 27 | + 'G': "###" + "#.." + "#.#" + "#.#" + "###", |
| 28 | + 'H': "#.#" + "#.#" + "###" + "#.#" + "#.#", |
| 29 | + 'I': "###" + ".#." + ".#." + ".#." + "###", |
| 30 | + 'J': "..#" + "..#" + "..#" + "#.#" + "###", |
| 31 | + 'K': "#.#" + "#.#" + "##." + "#.#" + "#.#", |
| 32 | + 'L': "#.." + "#.." + "#.." + "#.." + "###", |
| 33 | + 'M': "#.#" + "###" + "###" + "#.#" + "#.#", |
| 34 | + 'N': "#.#" + "###" + "###" + "###" + "#.#", |
| 35 | + 'O': "###" + "#.#" + "#.#" + "#.#" + "###", |
| 36 | + 'P': "###" + "#.#" + "###" + "#.." + "#..", |
| 37 | + 'Q': "###" + "#.#" + "#.#" + "###" + "..#", |
| 38 | + 'R': "###" + "#.#" + "##." + "#.#" + "#.#", |
| 39 | + 'S': "###" + "#.." + "###" + "..#" + "###", |
| 40 | + 'T': "###" + ".#." + ".#." + ".#." + ".#.", |
| 41 | + 'U': "#.#" + "#.#" + "#.#" + "#.#" + "###", |
| 42 | + 'V': "#.#" + "#.#" + "#.#" + "#.#" + ".#.", |
| 43 | + 'W': "#.#" + "#.#" + "###" + "###" + "#.#", |
| 44 | + 'X': "#.#" + "#.#" + ".#." + "#.#" + "#.#", |
| 45 | + 'Y': "#.#" + "#.#" + ".#." + ".#." + ".#.", |
| 46 | + 'Z': "###" + "..#" + ".#." + "#.." + "###", |
| 47 | + |
| 48 | + '0': "###" + "#.#" + "#.#" + "#.#" + "###", |
| 49 | + '1': ".#." + "##." + ".#." + ".#." + "###", |
| 50 | + '2': "###" + "..#" + "###" + "#.." + "###", |
| 51 | + '3': "###" + "..#" + "###" + "..#" + "###", |
| 52 | + '4': "#.#" + "#.#" + "###" + "..#" + "..#", |
| 53 | + '5': "###" + "#.." + "###" + "..#" + "###", |
| 54 | + '6': "###" + "#.." + "###" + "#.#" + "###", |
| 55 | + '7': "###" + "..#" + "..#" + "..#" + "..#", |
| 56 | + '8': "###" + "#.#" + "###" + "#.#" + "###", |
| 57 | + '9': "###" + "#.#" + "###" + "..#" + "###", |
| 58 | + |
| 59 | + ' ': "..." + "..." + "..." + "..." + "...", |
| 60 | + '-': "..." + "..." + "###" + "..." + "...", |
| 61 | + '.': "..." + "..." + "..." + "..." + ".#.", |
| 62 | + ':': "..." + ".#." + "..." + ".#." + "...", |
| 63 | + '_': "..." + "..." + "..." + "..." + "###", |
| 64 | + '/': "..#" + "..#" + ".#." + "#.." + "#..", |
| 65 | + '+': "..." + ".#." + "###" + ".#." + "...", |
| 66 | + '#': "#.#" + "###" + "#.#" + "###" + "#.#", |
| 67 | +} |
| 68 | + |
| 69 | +// unknown stands in for any character with no glyph, so a label never |
| 70 | +// silently loses part of itself. |
| 71 | +const unknown = "###" + "#.#" + "#.#" + "#.#" + "###" |
| 72 | + |
| 73 | +func glyph(r rune) string { |
| 74 | + if r >= 'a' && r <= 'z' { |
| 75 | + r -= 'a' - 'A' |
| 76 | + } |
| 77 | + if g, ok := glyphs[r]; ok { |
| 78 | + return g |
| 79 | + } |
| 80 | + return unknown |
| 81 | +} |
0 commit comments