Skip to content

Ran black, updated to pylint 2.x #17

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 1 commit into from
Mar 16, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
27 changes: 16 additions & 11 deletions adafruit_bitmap_font/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"""

import gc

try:
from displayio import Glyph
except ImportError:
Expand All @@ -49,8 +50,10 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"


class BDF(GlyphCache):
"""Loads glyphs from a BDF file in the given bitmap_class."""

def __init__(self, f, bitmap_class):
super().__init__()
self.file = f
Expand Down Expand Up @@ -119,22 +122,24 @@ def load_glyphs(self, code_points):
pass
elif line.startswith(b"STARTCHAR"):
# print(lineno, line.strip())
#_, character_name = line.split()
# _, character_name = line.split()
character = True
elif line.startswith(b"ENDCHAR"):
character = False
if desired_character:
bounds = current_info["bounds"]
shift = current_info["shift"]
gc.collect()
self._glyphs[code_point] = Glyph(current_info["bitmap"],
0,
bounds[0],
bounds[1],
bounds[2],
bounds[3],
shift[0],
shift[1])
self._glyphs[code_point] = Glyph(
current_info["bitmap"],
0,
bounds[0],
bounds[1],
bounds[2],
bounds[3],
shift[0],
shift[1],
)
remaining.remove(code_point)
if not remaining:
return
Expand Down Expand Up @@ -178,7 +183,7 @@ def load_glyphs(self, code_points):
start = current_y * width
x = 0
for i in range(rounded_x):
val = (bits >> ((rounded_x-i-1)*8)) & 0xFF
val = (bits >> ((rounded_x - i - 1) * 8)) & 0xFF
for j in range(7, -1, -1):
if x >= width:
break
Expand All @@ -189,5 +194,5 @@ def load_glyphs(self, code_points):
x += 1
current_y += 1
elif metadata:
#print(lineno, line.strip())
# print(lineno, line.strip())
pass
6 changes: 5 additions & 1 deletion adafruit_bitmap_font/bitmap_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@

def load_font(filename, bitmap=None):
"""Loads a font file. Returns None if unsupported."""
# pylint: disable=import-outside-toplevel
if not bitmap:
import displayio

bitmap = displayio.Bitmap
font_file = open(filename, "rb")
first_four = font_file.read(4)
#print(first_four)
if filename.endswith("bdf") and first_four == b"STAR":
from . import bdf

return bdf.BDF(font_file, bitmap)
if filename.endswith("pcf") and first_four == b"\x01fcp":
import pcf

return pcf.PCF(font_file)
if filename.endswith("ttf") and first_four == b"\x00\x01\x00\x00":
import ttf

return ttf.TTF(font_file)
return None
2 changes: 1 addition & 1 deletion adafruit_bitmap_font/glyph_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@

class GlyphCache:
"""Caches glyphs loaded by a subclass."""

def __init__(self):
self._glyphs = {}

def load_glyphs(self, code_points):
"""Loads displayio.Glyph objects into the GlyphCache from the font."""
pass

def get_glyph(self, code_point):
"""Returns a displayio.Glyph for the given code point or None is unsupported."""
Expand Down
45 changes: 24 additions & 21 deletions adafruit_bitmap_font/pcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@
import displayio
import struct

_PCF_PROPERTIES = (1<<0)
_PCF_ACCELERATORS = (1<<1)
_PCF_METRICS = (1<<2)
_PCF_BITMAPS = (1<<3)
_PCF_INK_METRICS = (1<<4)
_PCF_BDF_ENCODINGS = (1<<5)
_PCF_SWIDTHS = (1<<6)
_PCF_GLYPH_NAMES = (1<<7)
_PCF_BDF_ACCELERATORS = (1<<8)
_PCF_PROPERTIES = 1 << 0
_PCF_ACCELERATORS = 1 << 1
_PCF_METRICS = 1 << 2
_PCF_BITMAPS = 1 << 3
_PCF_INK_METRICS = 1 << 4
_PCF_BDF_ENCODINGS = 1 << 5
_PCF_SWIDTHS = 1 << 6
_PCF_GLYPH_NAMES = 1 << 7
_PCF_BDF_ACCELERATORS = 1 << 8

_PCF_DEFAULT_FORMAT = 0x00000000
_PCF_INKBOUNDS = 0x00000200
_PCF_ACCEL_W_INKBOUNDS = 0x00000100
_PCF_COMPRESSED_METRICS = 0x00000100

_PCF_GLYPH_PAD_MASK = (3<<0) # See the bitmap table for explanation */
_PCF_BYTE_MASK = (1<<2) # If set then Most Sig Byte First */
_PCF_BIT_MASK = (1<<3) # If set then Most Sig Bit First */
_PCF_SCAN_UNIT_MASK = (3<<4)
_PCF_GLYPH_PAD_MASK = 3 << 0 # See the bitmap table for explanation */
_PCF_BYTE_MASK = 1 << 2 # If set then Most Sig Byte First */
_PCF_BIT_MASK = 1 << 3 # If set then Most Sig Bit First */
_PCF_SCAN_UNIT_MASK = 3 << 4

# https://fontforge.github.io/en-US/documentation/reference/pcf-format/


class PCF(GlyphCache):
def __init__(self, f):
super().__init__()
Expand All @@ -47,17 +48,17 @@ def read(self, format):
def get_bounding_box(self):
property_table_offset = self.tables[_PCF_PROPERTIES]["offset"]
self.file.seek(property_table_offset)
format, = self.read("<I")
(format,) = self.read("<I")

if format & _PCF_BYTE_MASK == 0:
raise RuntimeError("Only big endian supported")
nprops, = self.read(">I")
(nprops,) = self.read(">I")
self.file.seek(property_table_offset + 8 + 9 * nprops)

pos = self.file.tell()
if pos % 4 > 0:
self.file.read(4 - pos % 4)
string_size, = self.read(">I")
(string_size,) = self.read(">I")

strings = self.file.read(string_size)
string_map = {}
Expand Down Expand Up @@ -89,7 +90,7 @@ def load_glyphs(self, code_points):

x, _, _, _ = self.get_bounding_box()
# create a scratch bytearray to load pixels into
scratch_row = memoryview(bytearray((((x-1)//32)+1) * 4))
scratch_row = memoryview(bytearray((((x - 1) // 32) + 1) * 4))

self.file.seek(0)
while True:
Expand All @@ -104,7 +105,7 @@ def load_glyphs(self, code_points):
pass
elif line.startswith(b"STARTCHAR"):
# print(lineno, line.strip())
#_, character_name = line.split()
# _, character_name = line.split()
character = True
elif line.startswith(b"ENDCHAR"):
character = False
Expand Down Expand Up @@ -151,10 +152,12 @@ def load_glyphs(self, code_points):
if desired_character:
bits = int(line.strip(), 16)
for i in range(rounded_x):
val = (bits >> ((rounded_x-i-1)*8)) & 0xFF
val = (bits >> ((rounded_x - i - 1) * 8)) & 0xFF
scratch_row[i] = val
current_info["bitmap"]._load_row(current_y, scratch_row[:bytes_per_row])
current_info["bitmap"]._load_row(
current_y, scratch_row[:bytes_per_row]
)
current_y += 1
elif metadata:
#print(lineno, line.strip())
# print(lineno, line.strip())
pass
3 changes: 2 additions & 1 deletion adafruit_bitmap_font/ttf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html


class TTF:
def __init__(self, f):
f.seek(0)
Expand Down Expand Up @@ -41,7 +42,7 @@ def read(format):
while f.tell() < glyf_offset + glyf_length:
numberOfContours, xMin, yMin, xMax, yMax = read(">hhhhh")

if numberOfContours > 0: # Simple
if numberOfContours > 0: # Simple
print(numberOfContours)
ends = []
for _ in range(numberOfContours):
Expand Down
Loading