Skip to content

Commit 590e029

Browse files
committed
Begin font parsing and packing for terminal
1 parent fb0970e commit 590e029

7 files changed

Lines changed: 123 additions & 1 deletion

File tree

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@
8686
[submodule "tools/adabot"]
8787
path = tools/adabot
8888
url = https://github.com/adafruit/adabot.git
89+
[submodule "tools/bitmap_font"]
90+
path = tools/bitmap_font
91+
url = https://github.com/adafruit/Adafruit_CircuitPython_BitmapFont.git
92+
[submodule "tools/Tecate-bitmap-fonts"]
93+
path = tools/Tecate-bitmap-fonts
94+
url = https://github.com/Tecate/bitmap-fonts.git

shared-module/displayio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
#include <string.h>
33
#include "shared-module/displayio/__init__.h"
44

5+
56
#include "shared-bindings/displayio/Bitmap.h"
67
#include "shared-bindings/displayio/Display.h"
78
#include "shared-bindings/displayio/Group.h"
89
#include "shared-bindings/displayio/Palette.h"
910
#include "shared-bindings/displayio/Sprite.h"
11+
#include "supervisor/shared/display.h"
1012
#include "supervisor/usb.h"
1113

1214
primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];

supervisor/shared/display.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_SUPERVISOR_SHARED_DISPLAY_H
28+
#define MICROPY_INCLUDED_SUPERVISOR_SHARED_DISPLAY_H
29+
30+
#include "shared-bindings/displayio/Bitmap.h"
31+
// These are autogenerated resources.
32+
33+
const displayio_bitmap_t terminal_font;
34+
35+
#endif // MICROPY_INCLUDED_SUPERVISOR_SHARED_DISPLAY_H

supervisor/supervisor.mk

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ else
7171
CFLAGS += -DUSB_AVAILABLE
7272
endif
7373

74-
SUPERVISOR_O = $(addprefix $(BUILD)/, $(SRC_SUPERVISOR:.c=.o))
74+
SUPERVISOR_O = $(addprefix $(BUILD)/, $(SRC_SUPERVISOR:.c=.o)) $(BUILD)/autogen_display_resources.o
7575

7676
$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h
7777

@@ -90,3 +90,12 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile
9090
--serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\
9191
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
9292
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h
93+
94+
CIRCUITPY_DISPLAY_FONT = "fonts/test.bdf"
95+
96+
$(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD)
97+
$(STEPECHO) "GEN $@"
98+
$(Q)install -d $(BUILD)/genhdr
99+
$(Q)$(PYTHON3) ../../tools/gen_display_resources.py \
100+
--font $(CIRCUITPY_DISPLAY_FONT) \
101+
--output_c_file $(BUILD)/autogen_display_resources.c

tools/Tecate-bitmap-fonts

Submodule Tecate-bitmap-fonts added at 6f52a7c

tools/bitmap_font

Submodule bitmap_font added at 7320e8f

tools/gen_display_resources.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import argparse
2+
3+
import os
4+
import sys
5+
6+
sys.path.append("bitmap_font")
7+
8+
from adafruit_bitmap_font import bitmap_font
9+
10+
parser = argparse.ArgumentParser(description='Generate USB descriptors.')
11+
parser.add_argument('--font', type=str,
12+
help='manufacturer of the device', required=True)
13+
parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True)
14+
15+
args = parser.parse_args()
16+
17+
args.font
18+
19+
c_file = args.output_c_file
20+
21+
c_file.write("""\
22+
23+
#include "supervisor/shared/display.h"
24+
25+
""")
26+
27+
class BitmapStub:
28+
def __init__(self, width, height, color_depth):
29+
self.width = width
30+
self.rows = [b''] * height
31+
32+
def _load_row(self, y, row):
33+
self.rows[y] = bytes(row)
34+
35+
f = bitmap_font.load_font(args.font, BitmapStub)
36+
f.load_glyphs(range(0x20, 0x7f))
37+
38+
print(f.get_bounding_box())
39+
real_bb = [0, 0]
40+
41+
visible_ascii = bytes(range(0x20, 0x7f)).decode("utf-8")
42+
all_characters = visible_ascii
43+
for c in all_characters:
44+
g = f.get_glyph(ord(c))
45+
x, y, dx, dy = g["bounds"]
46+
print(c, g["bounds"], g["shift"])
47+
if g["shift"][1] != 0:
48+
raise RuntimeError("y shift")
49+
real_bb[0] = max(max(real_bb[0], x - dx), g["shift"][0])
50+
real_bb[1] = max(real_bb[1], y - dy)
51+
52+
real_bb[1] += 1
53+
print(real_bb)
54+
55+
tile_x, tile_y = real_bb
56+
57+
for c in all_characters:
58+
g = f.get_glyph(ord(c))
59+
#print(c, g["bounds"], g["shift"])
60+
for row in g["bitmap"].rows:
61+
for i in range(g["bounds"][0]):
62+
byte = i // 8
63+
bit = i % 8
64+
# if row[byte] & (1 << (7-bit)) != 0:
65+
# print("*",end="")
66+
# else:
67+
# print("_",end="")
68+
#print()

0 commit comments

Comments
 (0)