Begin font parsing and packing for terminal
This commit is contained in:
parent
fb0970ec6e
commit
590e029198
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -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
|
||||
|
@ -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];
|
||||
|
35
supervisor/shared/display.h
Normal file
35
supervisor/shared/display.h
Normal file
@ -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
|
@ -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
|
||||
|
1
tools/Tecate-bitmap-fonts
Submodule
1
tools/Tecate-bitmap-fonts
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 6f52a7ca0838967cc57e9a44d76c6e1f60e62842
|
1
tools/bitmap_font
Submodule
1
tools/bitmap_font
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 7320e8ff94312c791aeed1a6956f8640e1dddc66
|
68
tools/gen_display_resources.py
Normal file
68
tools/gen_display_resources.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user