Skip to content

Move Glyph and BuiltinFont into fontio #1670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 74 additions & 72 deletions locale/ID.po

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/circuitpython.pot

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/de_DE.po

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/en_US.po

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/en_x_pirate.po

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/es.po

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/fil.po

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/fr.po

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/it_IT.po

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions locale/pt_BR.po

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions py/circuitpy_defns.mk
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ ifeq ($(CIRCUITPY_DIGITALIO),1)
SRC_PATTERNS += digitalio/%
endif
ifeq ($(CIRCUITPY_DISPLAYIO),1)
SRC_PATTERNS += displayio/% terminalio/%
SRC_PATTERNS += displayio/% terminalio/% fontio/%
endif
ifeq ($(CIRCUITPY_FREQUENCYIO),1)
SRC_PATTERNS += frequencyio/%
Expand Down Expand Up @@ -268,7 +268,7 @@ $(filter $(SRC_PATTERNS), \
digitalio/Direction.c \
digitalio/DriveMode.c \
digitalio/Pull.c \
displayio/Glyph.c \
fontio/Glyph.c \
microcontroller/RunMode.c \
math/__init__.c \
supervisor/__init__.c \
Expand Down Expand Up @@ -304,7 +304,6 @@ $(filter $(SRC_PATTERNS), \
bitbangio/__init__.c \
busio/OneWire.c \
displayio/Bitmap.c \
displayio/BuiltinFont.c \
displayio/ColorConverter.c \
displayio/Display.c \
displayio/FourWire.c \
Expand All @@ -314,6 +313,8 @@ $(filter $(SRC_PATTERNS), \
displayio/Shape.c \
displayio/TileGrid.c \
displayio/__init__.c \
fontio/BuiltinFont.c \
fontio/__init__.c \
gamepad/GamePad.c \
gamepad/__init__.c \
os/__init__.c \
Expand Down
6 changes: 5 additions & 1 deletion py/circuitpy_mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,15 @@ extern const struct _mp_obj_module_t digitalio_module;

#if CIRCUITPY_DISPLAYIO
extern const struct _mp_obj_module_t displayio_module;
extern const struct _mp_obj_module_t fontio_module;
extern const struct _mp_obj_module_t terminalio_module;
#define DISPLAYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_displayio), (mp_obj_t)&displayio_module },
#define FONTIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_fontio), (mp_obj_t)&fontio_module },
#define TERMINALIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_terminalio), (mp_obj_t)&terminalio_module },
#define CIRCUITPY_DISPLAY_LIMIT (3)
#else
#define DISPLAYIO_MODULE
#define FONTIO_MODULE
#define TERMINALIO_MODULE
#define CIRCUITPY_DISPLAY_LIMIT (0)
#endif
Expand Down Expand Up @@ -523,8 +526,9 @@ extern const struct _mp_obj_module_t pew_module;
BOARD_MODULE \
BUSIO_MODULE \
DIGITALIO_MODULE \
TERMINALIO_MODULE \
DISPLAYIO_MODULE \
FONTIO_MODULE \
TERMINALIO_MODULE \
ERRNO_MODULE \
FREQUENCYIO_MODULE \
GAMEPAD_MODULE \
Expand Down
6 changes: 0 additions & 6 deletions shared-bindings/displayio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@

#include "shared-bindings/displayio/__init__.h"
#include "shared-bindings/displayio/Bitmap.h"
#include "shared-bindings/displayio/BuiltinFont.h"
#include "shared-bindings/displayio/ColorConverter.h"
#include "shared-bindings/displayio/Display.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-bindings/displayio/Glyph.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/displayio/OnDiskBitmap.h"
#include "shared-bindings/displayio/Palette.h"
Expand All @@ -59,11 +57,9 @@
//| :maxdepth: 3
//|
//| Bitmap
//| BuiltinFont
//| ColorConverter
//| Display
//| FourWire
//| Glyph
//| Group
//| OnDiskBitmap
//| Palette
Expand Down Expand Up @@ -91,10 +87,8 @@ MP_DEFINE_CONST_FUN_OBJ_0(displayio_release_displays_obj, displayio_release_disp
STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_displayio) },
{ MP_ROM_QSTR(MP_QSTR_Bitmap), MP_ROM_PTR(&displayio_bitmap_type) },
{ MP_ROM_QSTR(MP_QSTR_BuiltinFont), MP_ROM_PTR(&displayio_builtinfont_type) },
{ MP_ROM_QSTR(MP_QSTR_ColorConverter), MP_ROM_PTR(&displayio_colorconverter_type) },
{ MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&displayio_display_type) },
{ MP_ROM_QSTR(MP_QSTR_Glyph), MP_ROM_PTR(&displayio_glyph_type) },
{ MP_ROM_QSTR(MP_QSTR_Group), MP_ROM_PTR(&displayio_group_type) },
{ MP_ROM_QSTR(MP_QSTR_OnDiskBitmap), MP_ROM_PTR(&displayio_ondiskbitmap_type) },
{ MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* THE SOFTWARE.
*/

#include "shared-bindings/displayio/BuiltinFont.h"
#include "shared-bindings/fontio/BuiltinFont.h"

#include <stdint.h>

Expand All @@ -36,7 +36,7 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"

//| .. currentmodule:: displayio
//| .. currentmodule:: fontio
//|
//| :class:`BuiltinFont` -- A font built into CircuitPython
//| =========================================================================================
Expand All @@ -56,15 +56,15 @@
//| `get_glyph` in most cases. This is useful for use with `displayio.TileGrid` and
//| `terminalio.Terminal`.
//|
STATIC mp_obj_t displayio_builtinfont_obj_get_bitmap(mp_obj_t self_in) {
displayio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);
return common_hal_displayio_builtinfont_get_bitmap(self);
STATIC mp_obj_t fontio_builtinfont_obj_get_bitmap(mp_obj_t self_in) {
fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);
return common_hal_fontio_builtinfont_get_bitmap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_builtinfont_get_bitmap_obj, displayio_builtinfont_obj_get_bitmap);
MP_DEFINE_CONST_FUN_OBJ_1(fontio_builtinfont_get_bitmap_obj, fontio_builtinfont_obj_get_bitmap);

const mp_obj_property_t displayio_builtinfont_bitmap_obj = {
const mp_obj_property_t fontio_builtinfont_bitmap_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_builtinfont_get_bitmap_obj,
.proxy = {(mp_obj_t)&fontio_builtinfont_get_bitmap_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
Expand All @@ -73,38 +73,38 @@ const mp_obj_property_t displayio_builtinfont_bitmap_obj = {
//|
//| Returns the maximum bounds of all glyphs in the font in a tuple of two values: width, height.
//|
STATIC mp_obj_t displayio_builtinfont_obj_get_bounding_box(mp_obj_t self_in) {
displayio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);
STATIC mp_obj_t fontio_builtinfont_obj_get_bounding_box(mp_obj_t self_in) {
fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);

return common_hal_displayio_builtinfont_get_bounding_box(self);
return common_hal_fontio_builtinfont_get_bounding_box(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_builtinfont_get_bounding_box_obj, displayio_builtinfont_obj_get_bounding_box);
MP_DEFINE_CONST_FUN_OBJ_1(fontio_builtinfont_get_bounding_box_obj, fontio_builtinfont_obj_get_bounding_box);


//| .. method:: get_glyph(codepoint)
//|
//| Returns a `displayio.Glyph` for the given codepoint or None if no glyph is available.
//| Returns a `fontio.Glyph` for the given codepoint or None if no glyph is available.
//|
STATIC mp_obj_t displayio_builtinfont_obj_get_glyph(mp_obj_t self_in, mp_obj_t codepoint_obj) {
displayio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);
STATIC mp_obj_t fontio_builtinfont_obj_get_glyph(mp_obj_t self_in, mp_obj_t codepoint_obj) {
fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);

mp_int_t codepoint;
if (!mp_obj_get_int_maybe(codepoint_obj, &codepoint)) {
mp_raise_ValueError_varg(translate("%q should be an int"), MP_QSTR_codepoint);
}
return common_hal_displayio_builtinfont_get_glyph(self, codepoint);
return common_hal_fontio_builtinfont_get_glyph(self, codepoint);
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_builtinfont_get_glyph_obj, displayio_builtinfont_obj_get_glyph);
MP_DEFINE_CONST_FUN_OBJ_2(fontio_builtinfont_get_glyph_obj, fontio_builtinfont_obj_get_glyph);

STATIC const mp_rom_map_elem_t displayio_builtinfont_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&displayio_builtinfont_bitmap_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_bounding_box), MP_ROM_PTR(&displayio_builtinfont_get_bounding_box_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_glyph), MP_ROM_PTR(&displayio_builtinfont_get_glyph_obj) },
STATIC const mp_rom_map_elem_t fontio_builtinfont_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&fontio_builtinfont_bitmap_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_bounding_box), MP_ROM_PTR(&fontio_builtinfont_get_bounding_box_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_glyph), MP_ROM_PTR(&fontio_builtinfont_get_glyph_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_builtinfont_locals_dict, displayio_builtinfont_locals_dict_table);
STATIC MP_DEFINE_CONST_DICT(fontio_builtinfont_locals_dict, fontio_builtinfont_locals_dict_table);

const mp_obj_type_t displayio_builtinfont_type = {
const mp_obj_type_t fontio_builtinfont_type = {
{ &mp_type_type },
.name = MP_QSTR_BuiltinFont,
.locals_dict = (mp_obj_dict_t*)&displayio_builtinfont_locals_dict,
.locals_dict = (mp_obj_dict_t*)&fontio_builtinfont_locals_dict,
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
* THE SOFTWARE.
*/

#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BUILTINFONT_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BUILTINFONT_H
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_BUILTINFONT_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_BUILTINFONT_H

#include "shared-module/displayio/BuiltinFont.h"
#include "shared-module/fontio/BuiltinFont.h"

extern const mp_obj_type_t displayio_builtinfont_type;
extern const mp_obj_type_t fontio_builtinfont_type;

mp_obj_t common_hal_displayio_builtinfont_get_bitmap(const displayio_builtinfont_t *self);
mp_obj_t common_hal_displayio_builtinfont_get_bounding_box(const displayio_builtinfont_t *self);
mp_obj_t common_hal_displayio_builtinfont_get_glyph(const displayio_builtinfont_t *self, mp_uint_t codepoint);
mp_obj_t common_hal_fontio_builtinfont_get_bitmap(const fontio_builtinfont_t *self);
mp_obj_t common_hal_fontio_builtinfont_get_bounding_box(const fontio_builtinfont_t *self);
mp_obj_t common_hal_fontio_builtinfont_get_glyph(const fontio_builtinfont_t *self, mp_uint_t codepoint);

#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BUILTINFONT_H
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_BUILTINFONT_H
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
* THE SOFTWARE.
*/

#include "shared-bindings/displayio/Glyph.h"
#include "shared-bindings/fontio/Glyph.h"

#include <stdint.h>

//| .. currentmodule:: displayio
//| .. currentmodule:: fontio
//|
//| :class:`Glyph` -- Storage of glyph info
//| ==========================================================================
Expand All @@ -37,7 +37,7 @@
//|
//| Named tuple used to capture a single glyph and its attributes.
//|
//| :param displayio.Bitmap bitmap: the bitmap including the glyph
//| :param fontio.Bitmap bitmap: the bitmap including the glyph
//| :param int tile_index: the tile index within the bitmap
//| :param int width: the width of the glyph's bitmap
//| :param int height: the height of the glyph's bitmap
Expand All @@ -46,7 +46,7 @@
//| :param int shift_x: the x difference to the next glyph
//| :param int shift_y: the y difference to the next glyph
//|
const mp_obj_namedtuple_type_t displayio_glyph_type = {
const mp_obj_namedtuple_type_t fontio_glyph_type = {
.base = {
.base = {
.type = &mp_type_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
* THE SOFTWARE.
*/

#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GLYPH_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GLYPH_H
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_GLYPH_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_GLYPH_H

#include "py/objnamedtuple.h"

extern const mp_obj_namedtuple_type_t displayio_glyph_type;
extern const mp_obj_namedtuple_type_t fontio_glyph_type;

#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GLYPH_H
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_GLYPH_H
65 changes: 65 additions & 0 deletions shared-bindings/fontio/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.
*/

#include <stdint.h>

#include "py/obj.h"
#include "py/runtime.h"

#include "shared-bindings/fontio/__init__.h"
#include "shared-bindings/fontio/BuiltinFont.h"
#include "shared-bindings/fontio/Glyph.h"

//| :mod:`fontio` --- Core font related data structures
//| =========================================================================
//|
//| .. module:: fontio
//| :synopsis: Core font related data structures
//| :platform: SAMD21, SAMD51, nRF52
//|
//| The `fontio` module contains classes to store font related information.
//|
//| Libraries
//|
//| .. toctree::
//| :maxdepth: 3
//|
//| BuiltinFont
//| Glyph
//|

STATIC const mp_rom_map_elem_t fontio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_fontio) },
{ MP_ROM_QSTR(MP_QSTR_BuiltinFont), MP_ROM_PTR(&fontio_builtinfont_type) },
{ MP_ROM_QSTR(MP_QSTR_Glyph), MP_ROM_PTR(&fontio_glyph_type) },
};

STATIC MP_DEFINE_CONST_DICT(fontio_module_globals, fontio_module_globals_table);

const mp_obj_module_t fontio_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&fontio_module_globals,
};
31 changes: 31 additions & 0 deletions shared-bindings/fontio/__init__.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 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_SHARED_BINDINGS_FONTIO___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO___INIT___H


#endif // MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO___INIT___H
8 changes: 4 additions & 4 deletions shared-bindings/terminalio/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "py/objstr.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "shared-bindings/displayio/BuiltinFont.h"
#include "shared-bindings/fontio/BuiltinFont.h"
#include "supervisor/shared/translate.h"


Expand All @@ -46,7 +46,7 @@
//| .. class:: Terminal(tilegrid, font)
//|
//| Terminal manages tile indices and cursor position based on VT100 commands. The font should be
//| a `displayio.BuiltinFont` and the TileGrid's bitmap should match the font's bitmap.
//| a `fontio.BuiltinFont` and the TileGrid's bitmap should match the font's bitmap.
//|

STATIC mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
Expand All @@ -64,8 +64,8 @@ STATIC mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n
}

mp_obj_t font = args[ARG_font].u_obj;
if (!MP_OBJ_IS_TYPE(font, &displayio_builtinfont_type)) {
mp_raise_TypeError_varg(translate("Expected a %q"), displayio_builtinfont_type.name);
if (!MP_OBJ_IS_TYPE(font, &fontio_builtinfont_type)) {
mp_raise_TypeError_varg(translate("Expected a %q"), fontio_builtinfont_type.name);
}
terminalio_terminal_obj_t *self = m_new_obj(terminalio_terminal_obj_t);
self->base.type = &terminalio_terminal_type;
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/terminalio/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
extern const mp_obj_type_t terminalio_terminal_type;

extern void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self,
displayio_tilegrid_t* tilegrid, const displayio_builtinfont_t* font);
displayio_tilegrid_t* tilegrid, const fontio_builtinfont_t* font);

// Write characters. len is in characters NOT bytes!
extern size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self,
Expand Down
Loading