diff --git a/src/freesans.rs b/src/freesans.rs new file mode 100644 index 0000000..514af9c --- /dev/null +++ b/src/freesans.rs @@ -0,0 +1,849 @@ +use st7735::fonts::{FontGlyph, Font}; + +const FREE_SANS_BMP: [u8; 1150] = + [0xFF, 0xFF, 0xF8, 0xC0, 0xDE, 0xF7, 0x20, 0x09, 0x86, 0x41, 0x91, 0xFF, 0x13, 0x04, 0xC3, + 0x20, 0xC8, 0xFF, 0x89, 0x82, 0x61, 0x90, 0x10, 0x1F, 0x14, 0xDA, 0x3D, 0x1E, 0x83, 0x40, + 0x78, 0x17, 0x08, 0xF4, 0x7A, 0x35, 0x33, 0xF0, 0x40, 0x20, 0x38, 0x10, 0xEC, 0x20, 0xC6, + 0x20, 0xC6, 0x40, 0xC6, 0x40, 0x6C, 0x80, 0x39, 0x00, 0x01, 0x3C, 0x02, 0x77, 0x02, 0x63, + 0x04, 0x63, 0x04, 0x77, 0x08, 0x3C, 0x0E, 0x06, 0x60, 0xCC, 0x19, 0x81, 0xE0, 0x18, 0x0F, + 0x03, 0x36, 0xC2, 0xD8, 0x73, 0x06, 0x31, 0xE3, 0xC4, 0xFE, 0x13, 0x26, 0x6C, 0xCC, 0xCC, + 0xC4, 0x66, 0x23, 0x10, 0x8C, 0x46, 0x63, 0x33, 0x33, 0x32, 0x66, 0x4C, 0x80, 0x25, 0x7E, + 0xA5, 0x00, 0x30, 0xC3, 0x3F, 0x30, 0xC3, 0x0C, 0xD6, 0xF0, 0xC0, 0x08, 0x44, 0x21, 0x10, + 0x84, 0x42, 0x11, 0x08, 0x00, 0x3C, 0x66, 0x42, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, + 0x42, 0x66, 0x3C, 0x11, 0x3F, 0x33, 0x33, 0x33, 0x33, 0x30, 0x3E, 0x31, 0xB0, 0x78, 0x30, + 0x18, 0x1C, 0x1C, 0x1C, 0x18, 0x18, 0x10, 0x08, 0x07, 0xF8, 0x3C, 0x66, 0xC3, 0xC3, 0x03, + 0x06, 0x1C, 0x07, 0x03, 0xC3, 0xC3, 0x66, 0x3C, 0x0C, 0x18, 0x71, 0x62, 0xC9, 0xA3, 0x46, + 0xFE, 0x18, 0x30, 0x60, 0xC0, 0x7F, 0x20, 0x10, 0x08, 0x08, 0x07, 0xF3, 0x8C, 0x03, 0x01, + 0x80, 0xF0, 0x6C, 0x63, 0xE0, 0x1E, 0x31, 0x98, 0x78, 0x0C, 0x06, 0xF3, 0x8D, 0x83, 0xC1, + 0xE0, 0xD0, 0x6C, 0x63, 0xE0, 0xFF, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x18, 0x18, 0x18, + 0x10, 0x30, 0x30, 0x3E, 0x31, 0xB0, 0x78, 0x3C, 0x1B, 0x18, 0xF8, 0xC6, 0xC1, 0xE0, 0xF0, + 0x6C, 0x63, 0xE0, 0x3C, 0x66, 0xC2, 0xC3, 0xC3, 0xC3, 0x67, 0x3B, 0x03, 0x03, 0xC2, 0x66, + 0x3C, 0xC0, 0x00, 0x30, 0xC0, 0x00, 0x00, 0x64, 0xA0, 0x00, 0x81, 0xC7, 0x8E, 0x0C, 0x07, + 0x80, 0x70, 0x0E, 0x01, 0x80, 0xFF, 0x80, 0x00, 0x1F, 0xF0, 0x00, 0x70, 0x0E, 0x01, 0xC0, + 0x18, 0x38, 0x71, 0xC0, 0x80, 0x00, 0x3E, 0x31, 0xB0, 0x78, 0x30, 0x18, 0x18, 0x38, 0x18, + 0x18, 0x0C, 0x00, 0x00, 0x01, 0x80, 0x03, 0xF0, 0x06, 0x0E, 0x06, 0x01, 0x86, 0x00, 0x66, + 0x1D, 0xBB, 0x31, 0xCF, 0x18, 0xC7, 0x98, 0x63, 0xCC, 0x31, 0xE6, 0x11, 0xB3, 0x99, 0xCC, + 0xF7, 0x86, 0x00, 0x01, 0x80, 0x00, 0x70, 0x40, 0x0F, 0xE0, 0x06, 0x00, 0xF0, 0x0F, 0x00, + 0x90, 0x19, 0x81, 0x98, 0x10, 0x83, 0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x00, 0x60, 0xC1, 0x81, 0x30, + 0xE1, 0x98, 0x70, 0xCC, 0x28, 0x66, 0x26, 0x21, 0x13, 0x30, 0xC8, 0x98, 0x6C, 0x4C, 0x14, + 0x34, 0x0A, 0x1A, 0x07, 0x07, 0x03, 0x03, 0x80, 0x81, 0x80, 0x60, 0x63, 0x0C, 0x30, 0xC1, + 0x98, 0x0F, 0x00, 0xE0, 0x06, 0x00, 0xF0, 0x19, 0x01, 0x98, 0x30, 0xC6, 0x0E, 0x60, 0x60, + 0xC0, 0x36, 0x06, 0x30, 0xC3, 0x0C, 0x19, 0x81, 0xD8, 0x0F, 0x00, 0x60, 0x06, 0x00, 0x60, + 0x06, 0x00, 0x60, 0x06, 0x00, 0xFF, 0xC0, 0x60, 0x30, 0x0C, 0x06, 0x03, 0x01, 0xC0, 0x60, + 0x30, 0x18, 0x06, 0x03, 0x00, 0xFF, 0xC0, 0xFB, 0x6D, 0xB6, 0xDB, 0x6D, 0xB6, 0xE0, 0x84, + 0x10, 0x84, 0x10, 0x84, 0x10, 0x84, 0x10, 0x80, 0xED, 0xB6, 0xDB, 0x6D, 0xB6, 0xDB, 0xE0, + 0x30, 0x60, 0xA2, 0x44, 0xD8, 0xA1, 0x80, 0xFF, 0xC0, 0xC6, 0x30, 0x7E, 0x71, 0xB0, 0xC0, + 0x60, 0xF3, 0xDB, 0x0D, 0x86, 0xC7, 0x3D, 0xC0, 0xC0, 0x60, 0x30, 0x1B, 0xCE, 0x36, 0x0F, + 0x07, 0x83, 0xC1, 0xE0, 0xF0, 0x7C, 0x6D, 0xE0, 0x3C, 0x66, 0xC3, 0xC0, 0xC0, 0xC0, 0xC0, + 0xC3, 0x66, 0x3C, 0x03, 0x03, 0x03, 0x3B, 0x67, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x67, + 0x3B, 0x3C, 0x66, 0xC3, 0xC3, 0xFF, 0xC0, 0xC0, 0xC3, 0x66, 0x3C, 0x36, 0x6F, 0x66, 0x66,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 0xD3, + 0x16, 0xD0, 0xA6, 0x87, 0x1C, 0x38, 0xC0, 0xC6, 0x00, 0x43, 0x62, 0x36, 0x1C, 0x18, 0x1C, + 0x3C, 0x26, 0x62, 0x43, 0xC1, 0x21, 0x98, 0xCC, 0x42, 0x61, 0xB0, 0xD0, 0x38, 0x1C, 0x0C, + 0x06, 0x03, 0x01, 0x03, 0x00, 0xFE, 0x0C, 0x30, 0xC1, 0x86, 0x18, 0x20, 0xC1, 0xFC, 0x36, + 0x66, 0x66, 0x6E, 0xCE, 0x66, 0x66, 0x66, 0x30, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0xC6, 0x66, + 0x66, 0x67, 0x37, 0x66, 0x66, 0x66, 0xC0, 0x61, 0x24, 0x38]; + +const FREE_SANS_GLYPHS: [FontGlyph; 95] = [FontGlyph { + bitmap_offset: 0, + width: 0, + height: 0, + x_advance: 5, + x_offset: 0, + y_offset: 1, + }, // 0x20 ' ' + FontGlyph { + bitmap_offset: 0, + width: 2, + height: 13, + x_advance: 6, + x_offset: 2, + y_offset: -12, + }, // 0x21 '!' + FontGlyph { + bitmap_offset: 4, + width: 5, + height: 4, + x_advance: 6, + x_offset: 1, + y_offset: -12, + }, // 0x22 '"' + FontGlyph { + bitmap_offset: 7, + width: 10, + height: 12, + x_advance: 10, + x_offset: 0, + y_offset: -11, + }, // 0x23 '#' + FontGlyph { + bitmap_offset: 22, + width: 9, + height: 16, + x_advance: 10, + x_offset: 1, + y_offset: -13, + }, // 0x24 '$' + FontGlyph { + bitmap_offset: 40, + width: 16, + height: 13, + x_advance: 16, + x_offset: 1, + y_offset: -12, + }, // 0x25 '%' + FontGlyph { + bitmap_offset: 66, + width: 11, + height: 13, + x_advance: 12, + x_offset: 1, + y_offset: -12, + }, // 0x26 '&' + FontGlyph { + bitmap_offset: 84, + width: 2, + height: 4, + x_advance: 4, + x_offset: 1, + y_offset: -12, + }, // 0x27 ''' + FontGlyph { + bitmap_offset: 85, + width: 4, + height: 17, + x_advance: 6, + x_offset: 1, + y_offset: -12, + }, // 0x28 '(' + FontGlyph { + bitmap_offset: 94, + width: 4, + height: 17, + x_advance: 6, + x_offset: 1, + y_offset: -12, + }, // 0x29 ')' + FontGlyph { + bitmap_offset: 103, + width: 5, + height: 5, + x_advance: 7, + x_offset: 1, + y_offset: -12, + }, // 0x2A '*' + FontGlyph { + bitmap_offset: 107, + width: 6, + height: 8, + x_advance: 11, + x_offset: 3, + y_offset: -7, + }, // 0x2B '+' + FontGlyph { + bitmap_offset: 113, + width: 2, + height: 4, + x_advance: 5, + x_offset: 2, + y_offset: 0, + }, // 0x2C ',' + FontGlyph { + bitmap_offset: 114, + width: 4, + height: 1, + x_advance: 6, + x_offset: 1, + y_offset: -4, + }, // 0x2D '-' + FontGlyph { + bitmap_offset: 115, + width: 2, + height: 1, + x_advance: 5, + x_offset: 1, + y_offset: 0, + }, // 0x2E '.' + FontGlyph { + bitmap_offset: 116, + width: 5, + height: 13, + x_advance: 5, + x_offset: 0, + y_offset: -12, + }, // 0x2F '/' + FontGlyph { + bitmap_offset: 125, + width: 8, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x30 '0' + FontGlyph { + bitmap_offset: 138, + width: 4, + height: 13, + x_advance: 10, + x_offset: 3, + y_offset: -12, + }, // 0x31 '1' + FontGlyph { + bitmap_offset: 145, + width: 9, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x32 '2' + FontGlyph { + bitmap_offset: 160, + width: 8, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x33 '3' + FontGlyph { + bitmap_offset: 173, + width: 7, + height: 13, + x_advance: 10, + x_offset: 2, + y_offset: -12, + }, // 0x34 '4' + FontGlyph { + bitmap_offset: 185, + width: 9, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x35 '5' + FontGlyph { + bitmap_offset: 200, + width: 9, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x36 '6' + FontGlyph { + bitmap_offset: 215, + width: 8, + height: 13, + x_advance: 10, + x_offset: 0, + y_offset: -12, + }, // 0x37 '7' + FontGlyph { + bitmap_offset: 228, + width: 9, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x38 '8' + FontGlyph { + bitmap_offset: 243, + width: 8, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x39 '9' + FontGlyph { + bitmap_offset: 256, + width: 2, + height: 10, + x_advance: 5, + x_offset: 1, + y_offset: -9, + }, // 0x3A ':' + FontGlyph { + bitmap_offset: 259, + width: 3, + height: 12, + x_advance: 5, + x_offset: 1, + y_offset: -8, + }, // 0x3B ';' + FontGlyph { + bitmap_offset: 264, + width: 9, + height: 9, + x_advance: 11, + x_offset: 1, + y_offset: -8, + }, // 0x3C '<' + FontGlyph { + bitmap_offset: 275, + width: 9, + height: 4, + x_advance: 11, + x_offset: 1, + y_offset: -5, + }, // 0x3D '=' + FontGlyph { + bitmap_offset: 280, + width: 9, + height: 9, + x_advance: 11, + x_offset: 1, + y_offset: -8, + }, // 0x3E '>' + FontGlyph { + bitmap_offset: 291, + width: 9, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x3F '?' + FontGlyph { + bitmap_offset: 306, + width: 17, + height: 16, + x_advance: 18, + x_offset: 1, + y_offset: -12, + }, // 0x40 '@' + FontGlyph { + bitmap_offset: 340, + width: 12, + height: 13, + x_advance: 12, + x_offset: 0, + y_offset: -12, + }, // 0x41 'A' + FontGlyph { + bitmap_offset: 360, + width: 11, + height: 13, + x_advance: 12, + x_offset: 1, + y_offset: -12, + }, // 0x42 'B' + FontGlyph { + bitmap_offset: 378, + width: 11, + height: 13, + x_advance: 13, + x_offset: 1, + y_offset: -12, + }, // 0x43 'C' + FontGlyph { + bitmap_offset: 396, + width: 11, + height: 13, + x_advance: 13, + x_offset: 1, + y_offset: -12, + }, // 0x44 'D' + FontGlyph { + bitmap_offset: 414, + width: 9, + height: 13, + x_advance: 11, + x_offset: 1, + y_offset: -12, + }, // 0x45 'E' + FontGlyph { + bitmap_offset: 429, + width: 8, + height: 13, + x_advance: 11, + x_offset: 1, + y_offset: -12, + }, // 0x46 'F' + FontGlyph { + bitmap_offset: 442, + width: 12, + height: 13, + x_advance: 14, + x_offset: 1, + y_offset: -12, + }, // 0x47 'G' + FontGlyph { + bitmap_offset: 462, + width: 11, + height: 13, + x_advance: 13, + x_offset: 1, + y_offset: -12, + }, // 0x48 'H' + FontGlyph { + bitmap_offset: 480, + width: 2, + height: 13, + x_advance: 5, + x_offset: 2, + y_offset: -12, + }, // 0x49 'I' + FontGlyph { + bitmap_offset: 484, + width: 7, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x4A 'J' + FontGlyph { + bitmap_offset: 496, + width: 11, + height: 13, + x_advance: 12, + x_offset: 1, + y_offset: -12, + }, // 0x4B 'K' + FontGlyph { + bitmap_offset: 514, + width: 8, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x4C 'L' + FontGlyph { + bitmap_offset: 527, + width: 13, + height: 13, + x_advance: 15, + x_offset: 1, + y_offset: -12, + }, // 0x4D 'M' + FontGlyph { + bitmap_offset: 549, + width: 11, + height: 13, + x_advance: 13, + x_offset: 1, + y_offset: -12, + }, // 0x4E 'N' + FontGlyph { + bitmap_offset: 567, + width: 13, + height: 13, + x_advance: 14, + x_offset: 1, + y_offset: -12, + }, // 0x4F 'O' + FontGlyph { + bitmap_offset: 589, + width: 10, + height: 13, + x_advance: 12, + x_offset: 1, + y_offset: -12, + }, // 0x50 'P' + FontGlyph { + bitmap_offset: 606, + width: 13, + height: 14, + x_advance: 14, + x_offset: 1, + y_offset: -12, + }, // 0x51 'Q' + FontGlyph { + bitmap_offset: 629, + width: 12, + height: 13, + x_advance: 13, + x_offset: 1, + y_offset: -12, + }, // 0x52 'R' + FontGlyph { + bitmap_offset: 649, + width: 10, + height: 13, + x_advance: 12, + x_offset: 1, + y_offset: -12, + }, // 0x53 'S' + FontGlyph { + bitmap_offset: 666, + width: 9, + height: 13, + x_advance: 11, + x_offset: 1, + y_offset: -12, + }, // 0x54 'T' + FontGlyph { + bitmap_offset: 681, + width: 11, + height: 13, + x_advance: 13, + x_offset: 1, + y_offset: -12, + }, // 0x55 'U' + FontGlyph { + bitmap_offset: 699, + width: 11, + height: 13, + x_advance: 12, + x_offset: 0, + y_offset: -12, + }, // 0x56 'V' + FontGlyph { + bitmap_offset: 717, + width: 17, + height: 13, + x_advance: 17, + x_offset: 0, + y_offset: -12, + }, // 0x57 'W' + FontGlyph { + bitmap_offset: 745, + width: 12, + height: 13, + x_advance: 12, + x_offset: 0, + y_offset: -12, + }, // 0x58 'X' + FontGlyph { + bitmap_offset: 765, + width: 12, + height: 13, + x_advance: 12, + x_offset: 0, + y_offset: -12, + }, // 0x59 'Y' + FontGlyph { + bitmap_offset: 785, + width: 10, + height: 13, + x_advance: 11, + x_offset: 1, + y_offset: -12, + }, // 0x5A 'Z' + FontGlyph { + bitmap_offset: 802, + width: 3, + height: 17, + x_advance: 5, + x_offset: 1, + y_offset: -12, + }, // 0x5B '[' + FontGlyph { + bitmap_offset: 809, + width: 5, + height: 13, + x_advance: 5, + x_offset: 0, + y_offset: -12, + }, // 0x5C '\' + FontGlyph { + bitmap_offset: 818, + width: 3, + height: 17, + x_advance: 5, + x_offset: 0, + y_offset: -12, + }, // 0x5D ']' + FontGlyph { + bitmap_offset: 825, + width: 7, + height: 7, + x_advance: 8, + x_offset: 1, + y_offset: -12, + }, // 0x5E '^' + FontGlyph { + bitmap_offset: 832, + width: 10, + height: 1, + x_advance: 10, + x_offset: 0, + y_offset: 3, + }, // 0x5F '_' + FontGlyph { + bitmap_offset: 834, + width: 4, + height: 3, + x_advance: 5, + x_offset: 0, + y_offset: -12, + }, // 0x60 '`' + FontGlyph { + bitmap_offset: 836, + width: 9, + height: 10, + x_advance: 10, + x_offset: 1, + y_offset: -9, + }, // 0x61 'a' + FontGlyph { + bitmap_offset: 848, + width: 9, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x62 'b' + FontGlyph { + bitmap_offset: 863, + width: 8, + height: 10, + x_advance: 9, + x_offset: 1, + y_offset: -9, + }, // 0x63 'c' + FontGlyph { + bitmap_offset: 873, + width: 8, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x64 'd' + FontGlyph { + bitmap_offset: 886, + width: 8, + height: 10, + x_advance: 10, + x_offset: 1, + y_offset: -9, + }, // 0x65 'e' + FontGlyph { + bitmap_offset: 896, + width: 4, + height: 13, + x_advance: 5, + x_offset: 1, + y_offset: -12, + }, // 0x66 'f' + FontGlyph { + bitmap_offset: 903, + width: 8, + height: 14, + x_advance: 10, + x_offset: 1, + y_offset: -9, + }, // 0x67 'g' + FontGlyph { + bitmap_offset: 917, + width: 8, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -12, + }, // 0x68 'h' + FontGlyph { + bitmap_offset: 930, + width: 2, + height: 13, + x_advance: 4, + x_offset: 1, + y_offset: -12, + }, // 0x69 'i' + FontGlyph { + bitmap_offset: 934, + width: 4, + height: 17, + x_advance: 4, + x_offset: 0, + y_offset: -12, + }, // 0x6A 'j' + FontGlyph { + bitmap_offset: 943, + width: 9, + height: 13, + x_advance: 9, + x_offset: 1, + y_offset: -12, + }, // 0x6B 'k' + FontGlyph { + bitmap_offset: 958, + width: 2, + height: 13, + x_advance: 4, + x_offset: 1, + y_offset: -12, + }, // 0x6C 'l' + FontGlyph { + bitmap_offset: 962, + width: 13, + height: 10, + x_advance: 15, + x_offset: 1, + y_offset: -9, + }, // 0x6D 'm' + FontGlyph { + bitmap_offset: 979, + width: 8, + height: 10, + x_advance: 10, + x_offset: 1, + y_offset: -9, + }, // 0x6E 'n' + FontGlyph { + bitmap_offset: 989, + width: 8, + height: 10, + x_advance: 10, + x_offset: 1, + y_offset: -9, + }, // 0x6F 'o' + FontGlyph { + bitmap_offset: 999, + width: 9, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -9, + }, // 0x70 'p' + FontGlyph { + bitmap_offset: 1014, + width: 8, + height: 13, + x_advance: 10, + x_offset: 1, + y_offset: -9, + }, // 0x71 'q' + FontGlyph { + bitmap_offset: 1027, + width: 5, + height: 10, + x_advance: 6, + x_offset: 1, + y_offset: -9, + }, // 0x72 'r' + FontGlyph { + bitmap_offset: 1034, + width: 8, + height: 10, + x_advance: 9, + x_offset: 1, + y_offset: -9, + }, // 0x73 's' + FontGlyph { + bitmap_offset: 1044, + width: 4, + height: 12, + x_advance: 5, + x_offset: 1, + y_offset: -11, + }, // 0x74 't' + FontGlyph { + bitmap_offset: 1050, + width: 8, + height: 10, + x_advance: 10, + x_offset: 1, + y_offset: -9, + }, // 0x75 'u' + FontGlyph { + bitmap_offset: 1060, + width: 9, + height: 10, + x_advance: 9, + x_offset: 0, + y_offset: -9, + }, // 0x76 'v' + FontGlyph { + bitmap_offset: 1072, + width: 13, + height: 10, + x_advance: 13, + x_offset: 0, + y_offset: -9, + }, // 0x77 'w' + FontGlyph { + bitmap_offset: 1089, + width: 8, + height: 10, + x_advance: 9, + x_offset: 0, + y_offset: -9, + }, // 0x78 'x' + FontGlyph { + bitmap_offset: 1099, + width: 9, + height: 14, + x_advance: 9, + x_offset: 0, + y_offset: -9, + }, // 0x79 'y' + FontGlyph { + bitmap_offset: 1115, + width: 7, + height: 10, + x_advance: 9, + x_offset: 1, + y_offset: -9, + }, // 0x7A 'z' + FontGlyph { + bitmap_offset: 1124, + width: 4, + height: 17, + x_advance: 6, + x_offset: 1, + y_offset: -12, + }, // 0x7B '{' + FontGlyph { + bitmap_offset: 1133, + width: 2, + height: 17, + x_advance: 4, + x_offset: 2, + y_offset: -12, + }, // 0x7C '|' + FontGlyph { + bitmap_offset: 1138, + width: 4, + height: 17, + x_advance: 6, + x_offset: 1, + y_offset: -12, + }, // 0x7D '}' + FontGlyph { + bitmap_offset: 1147, + width: 7, + height: 3, + x_advance: 9, + x_offset: 1, + y_offset: -7, + }]; // 0x7E '~' + +pub const FREE_SANS_FONT: Font = Font { + bitmap: &FREE_SANS_BMP, + glyphs: &FREE_SANS_GLYPHS, + first: 0x20, + last: 0x7E, + y_advance: 22, +}; diff --git a/src/main.rs b/src/main.rs index 420989c..454c3ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,13 +24,14 @@ mod printer; mod max6675; mod st7735; mod logo; +mod freesans; use printer::UsartPrinter; use st7735::gfx::{PrimitveGFX, GFX}; use st7735::bitmaps::BitmapGFX; use st7735::fonts::FontRenderer; - +use freesans::FREE_SANS_FONT; fn configure_clocks(rcc: &mut rcc::RCC) { rcc.clock_control.set_hse_on(true); @@ -147,6 +148,8 @@ fn run(mut scs: scs::Instance, mut p: hcl::platform::Instance) { st7735io.draw_mono_bitmap(11, 4, &logo::LOGO_BW, st7735::COLOR_WHITE, st7735::COLOR_BLACK); systick::delay_ms(1000); st7735io.draw_color_bitmap(11, 4, &logo::LOGO_COLOR); + systick::delay_ms(1000); + st7735io.draw_text(20, 20, "Hello World", &FREE_SANS_FONT, 1, st7735::COLOR_RED); systick::delay_ms(5000); } let (st7735, mut spi, mut gpio) = st7735io.done(); diff --git a/src/st7735/fonts.rs b/src/st7735/fonts.rs index 390abe3..18905c7 100644 --- a/src/st7735/fonts.rs +++ b/src/st7735/fonts.rs @@ -1,18 +1,18 @@ use st7735::gfx::PrimitveGFX; -pub struct FontGlpyh { +pub struct FontGlyph { pub bitmap_offset: usize, // Offset in glyph bitmap pub width: u8, // Size of glyph pub height: u8, pub x_advance: u8, // Distance to advance along x-axis - pub x_offset: u8, // Distance to upper left coner from cursor pos - pub y_offset: u8, + pub x_offset: i8, // Distance to upper left coner from cursor pos + pub y_offset: i8, } pub struct Font { pub bitmap: &'static [u8], // Glyph bitmaps, concatenated - pub glyphs: &'static [FontGlpyh], // Array of glyph metadata + pub glyphs: &'static [FontGlyph], // Array of glyph metadata pub first: u8, // Start of ASCII extend pub last: u8, // End of ASCII extend pub y_advance: u8, // Line height @@ -20,7 +20,7 @@ pub struct Font { pub trait FontRenderer: PrimitveGFX { - fn draw_glyph(&mut self, x: u8, y: u8, glyph: &FontGlpyh, font: &Font, size: u8, color: u16) { + fn draw_glyph(&mut self, x: u8, y: u8, glyph: &FontGlyph, font: &Font, size: u8, color: u16) { if size == 0 { return; } @@ -66,6 +66,8 @@ pub trait FontRenderer: PrimitveGFX { let w = (set_pixels * size) as u8; let h = size as u8; self.fill_rect(start_x, start_y, w, h, color); + + set_pixels = 0; } } }