1
0
mirror of https://gitlab.com/MisterBiggs/bdfparse.git synced 2025-06-16 14:36:40 +00:00

Compare commits

..

11 Commits

Author SHA1 Message Date
0e82fef264 update repo address 2019-07-18 19:47:20 -07:00
5eefdb3ce1 updated char list 2019-07-18 19:46:37 -07:00
4eeaecf193 added more characters 2019-07-18 17:42:07 -07:00
65e188c764 Added more chars for word function 2019-07-18 14:27:19 -07:00
a49ce715cc Finally got package working 2019-07-17 00:25:08 -07:00
83c3284e91 updating again 2019-07-16 21:08:57 -07:00
217ff46bd7 added more chars to word function 2019-07-16 21:07:14 -07:00
295c9207a5 updated docs for new version 2019-07-16 20:12:48 -07:00
7df856e3d6 renaming package 2019-07-16 19:46:59 -07:00
7c587789ec init can just be an empty file 2019-07-16 19:46:03 -07:00
77f1ac9696 Fixed name in copyright 2019-07-16 19:38:56 -07:00
5 changed files with 75 additions and 19 deletions

View File

@ -5,20 +5,42 @@ This project takes a .bdf file and turns it into a [NumPy](https://www.numpy.org
## Usage
```python
import numpy as np
import matplotlib.pyplot as plt
from bdfparse import Font
font = parse_chars("9x18.bdf")
matrix = font["A"]
text = "nson"
font = Font('9x18.bdf')
for letter in text:
matrix = np.concatenate((matrix, font[letter]), axis=1)
plt.imshow(matrix)
plt.show()
print(font.word('Hi'))
```
Which outputs:
```python
[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0]
[0 0 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0]
[0 0 1 0 0 0 0 0 1 0 0 0 1 1 1 1 1 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]
```
Or you can use matplotlib to make the output a bit prettier.
```python
import matplotlib.pyplot as plt
plt.imshow(font.word('Anson'))
```
![Example of code output that reads Anson.](example.png)

View File

@ -1 +0,0 @@
name = "bdf_to_numpy"

1
bdfparse/__init__.py Normal file
View File

@ -0,0 +1 @@
from .bdfparse import Font

View File

@ -7,6 +7,35 @@ class Font:
self.chars = self.parse_chars(bdfFile)
self.cols = self.properties["FONTBOUNDINGBOX"][0]
self.rows = self.properties["FONTBOUNDINGBOX"][1]
self.shape = (self.rows, self.cols)
self.charNames = {
" ": "space",
"-": "minus",
"+": "plus",
"0": "zero",
"1": "one",
"2": "two",
"3": "three",
"4": "four",
"5": "five",
"6": "six",
"7": "seven",
"8": "eight",
"9": "nine",
"!": "exclam",
"@": "at",
"#": "numbersign",
"$": "dollar",
"%": "percent",
"&": "ampersand",
"*": "asterisk",
"(": "parenleft",
")": "parenright",
",": "comma",
".": "period",
"/": "slash",
"?": "question",
}
def parse_properties(self, bdfFile):
@ -190,9 +219,14 @@ class Font:
)
def word(self, word: str):
matrix = self.chars[word[0]]
for char in word[1:]:
matrix = np.concatenate((matrix, self.chars[char]), axis=1)
matrix = np.zeros(self.shape)
for char in word:
if char in self.charNames.keys():
arr = self.chars[self.charNames[char]]
else:
arr = self.chars[char]
return matrix
matrix = np.concatenate((matrix, arr), axis=1)
return matrix[:, self.cols :]

View File

@ -1,4 +1,4 @@
# Copyright (c) 2019 albig
# Copyright (c) 2019 Anson Biggs
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
@ -9,14 +9,14 @@ with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="bdf-to-numpy",
version="2019.2",
name="bdfparse",
version="2019.8",
author="Anson Biggs",
author_email="anson@ansonbiggs.com",
description="A package for reading .bdf files into NumPy arrays.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://gitlab.com/MisterBiggs/bdf-to-numpy",
url="https://gitlab.com/MisterBiggs/bdfparse",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3.7",