diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-01-24 17:25:08 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2019-01-31 11:42:13 -0800 |
| commit | 590e0291989c8df150b9b8aff960049903b56ac2 (patch) | |
| tree | 65622a83faa0e1519a1ec75dbce5a20b846d3c69 | |
| parent | fb0970ec6e2fee42d748718557c35fe84a4d0ce5 (diff) | |
Begin font parsing and packing for terminal
| -rw-r--r-- | .gitmodules | 6 | ||||
| -rw-r--r-- | shared-module/displayio/__init__.c | 2 | ||||
| -rw-r--r-- | supervisor/shared/display.h | 35 | ||||
| -rw-r--r-- | supervisor/supervisor.mk | 11 | ||||
| m--------- | tools/Tecate-bitmap-fonts | 0 | ||||
| m--------- | tools/bitmap_font | 0 | ||||
| -rw-r--r-- | tools/gen_display_resources.py | 68 |
7 files changed, 121 insertions, 1 deletions
diff --git a/.gitmodules b/.gitmodules index 3a746ccae..b36ad6203 100644 --- a/.gitmodules +++ b/.gitmodules @@ -86,3 +86,9 @@ [submodule "tools/adabot"] path = tools/adabot url = https://github.com/adafruit/adabot.git +[submodule "tools/bitmap_font"] + path = tools/bitmap_font + url = https://github.com/adafruit/Adafruit_CircuitPython_BitmapFont.git +[submodule "tools/Tecate-bitmap-fonts"] + path = tools/Tecate-bitmap-fonts + url = https://github.com/Tecate/bitmap-fonts.git diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index c86e48a12..61228f8d2 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -2,11 +2,13 @@ #include <string.h> #include "shared-module/displayio/__init__.h" + #include "shared-bindings/displayio/Bitmap.h" #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/Group.h" #include "shared-bindings/displayio/Palette.h" #include "shared-bindings/displayio/Sprite.h" +#include "supervisor/shared/display.h" #include "supervisor/usb.h" primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT]; diff --git a/supervisor/shared/display.h b/supervisor/shared/display.h new file mode 100644 index 000000000..5c420e590 --- /dev/null +++ b/supervisor/shared/display.h @@ -0,0 +1,35 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SUPERVISOR_SHARED_DISPLAY_H +#define MICROPY_INCLUDED_SUPERVISOR_SHARED_DISPLAY_H + +#include "shared-bindings/displayio/Bitmap.h" +// These are autogenerated resources. + +const displayio_bitmap_t terminal_font; + +#endif // MICROPY_INCLUDED_SUPERVISOR_SHARED_DISPLAY_H diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 0bbfd9141..174abd9d9 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -71,7 +71,7 @@ else CFLAGS += -DUSB_AVAILABLE endif -SUPERVISOR_O = $(addprefix $(BUILD)/, $(SRC_SUPERVISOR:.c=.o)) +SUPERVISOR_O = $(addprefix $(BUILD)/, $(SRC_SUPERVISOR:.c=.o)) $(BUILD)/autogen_display_resources.o $(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h @@ -90,3 +90,12 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile --serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\ --output_c_file $(BUILD)/autogen_usb_descriptor.c\ --output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h + +CIRCUITPY_DISPLAY_FONT = "fonts/test.bdf" + +$(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD) + $(STEPECHO) "GEN $@" + $(Q)install -d $(BUILD)/genhdr + $(Q)$(PYTHON3) ../../tools/gen_display_resources.py \ + --font $(CIRCUITPY_DISPLAY_FONT) \ + --output_c_file $(BUILD)/autogen_display_resources.c diff --git a/tools/Tecate-bitmap-fonts b/tools/Tecate-bitmap-fonts new file mode 160000 +Subproject 6f52a7ca0838967cc57e9a44d76c6e1f60e6284 diff --git a/tools/bitmap_font b/tools/bitmap_font new file mode 160000 +Subproject 7320e8ff94312c791aeed1a6956f8640e1dddc6 diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py new file mode 100644 index 000000000..3bcdc9952 --- /dev/null +++ b/tools/gen_display_resources.py @@ -0,0 +1,68 @@ +import argparse + +import os +import sys + +sys.path.append("bitmap_font") + +from adafruit_bitmap_font import bitmap_font + +parser = argparse.ArgumentParser(description='Generate USB descriptors.') +parser.add_argument('--font', type=str, + help='manufacturer of the device', required=True) +parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True) + +args = parser.parse_args() + +args.font + +c_file = args.output_c_file + +c_file.write("""\ + +#include "supervisor/shared/display.h" + +""") + +class BitmapStub: + def __init__(self, width, height, color_depth): + self.width = width + self.rows = [b''] * height + + def _load_row(self, y, row): + self.rows[y] = bytes(row) + +f = bitmap_font.load_font(args.font, BitmapStub) +f.load_glyphs(range(0x20, 0x7f)) + +print(f.get_bounding_box()) +real_bb = [0, 0] + +visible_ascii = bytes(range(0x20, 0x7f)).decode("utf-8") +all_characters = visible_ascii +for c in all_characters: + g = f.get_glyph(ord(c)) + x, y, dx, dy = g["bounds"] + print(c, g["bounds"], g["shift"]) + if g["shift"][1] != 0: + raise RuntimeError("y shift") + real_bb[0] = max(max(real_bb[0], x - dx), g["shift"][0]) + real_bb[1] = max(real_bb[1], y - dy) + +real_bb[1] += 1 +print(real_bb) + +tile_x, tile_y = real_bb + +for c in all_characters: + g = f.get_glyph(ord(c)) + #print(c, g["bounds"], g["shift"]) + for row in g["bitmap"].rows: + for i in range(g["bounds"][0]): + byte = i // 8 + bit = i % 8 + # if row[byte] & (1 << (7-bit)) != 0: + # print("*",end="") + # else: + # print("_",end="") + #print() |
