mirror of
https://gitlab.com/MisterBiggs/bdfparse.git
synced 2025-06-16 14:36:40 +00:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
0e82fef264 | |||
5eefdb3ce1 | |||
4eeaecf193 | |||
65e188c764 | |||
a49ce715cc | |||
83c3284e91 | |||
217ff46bd7 | |||
295c9207a5 | |||
7df856e3d6 | |||
7c587789ec | |||
77f1ac9696 |
42
README.md
42
README.md
@ -5,20 +5,42 @@ This project takes a .bdf file and turns it into a [NumPy](https://www.numpy.org
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import numpy as np
|
from bdfparse import Font
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
font = parse_chars("9x18.bdf")
|
font = Font('9x18.bdf')
|
||||||
matrix = font["A"]
|
|
||||||
text = "nson"
|
|
||||||
|
|
||||||
for letter in text:
|
print(font.word('Hi'))
|
||||||
matrix = np.concatenate((matrix, font[letter]), axis=1)
|
|
||||||
|
|
||||||
plt.imshow(matrix)
|
|
||||||
plt.show()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Which outputs:
|
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'))
|
||||||
|
```
|
||||||
|
|
||||||

|

|
||||||
|
@ -1 +0,0 @@
|
|||||||
name = "bdf_to_numpy"
|
|
1
bdfparse/__init__.py
Normal file
1
bdfparse/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .bdfparse import Font
|
@ -7,6 +7,35 @@ class Font:
|
|||||||
self.chars = self.parse_chars(bdfFile)
|
self.chars = self.parse_chars(bdfFile)
|
||||||
self.cols = self.properties["FONTBOUNDINGBOX"][0]
|
self.cols = self.properties["FONTBOUNDINGBOX"][0]
|
||||||
self.rows = self.properties["FONTBOUNDINGBOX"][1]
|
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):
|
def parse_properties(self, bdfFile):
|
||||||
|
|
||||||
@ -190,9 +219,14 @@ class Font:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def word(self, word: str):
|
def word(self, word: str):
|
||||||
matrix = self.chars[word[0]]
|
matrix = np.zeros(self.shape)
|
||||||
for char in word[1:]:
|
for char in word:
|
||||||
matrix = np.concatenate((matrix, self.chars[char]), axis=1)
|
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 :]
|
||||||
|
|
8
setup.py
8
setup.py
@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2019 albig
|
# Copyright (c) 2019 Anson Biggs
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
@ -9,14 +9,14 @@ with open("README.md", "r") as fh:
|
|||||||
long_description = fh.read()
|
long_description = fh.read()
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="bdf-to-numpy",
|
name="bdfparse",
|
||||||
version="2019.2",
|
version="2019.8",
|
||||||
author="Anson Biggs",
|
author="Anson Biggs",
|
||||||
author_email="anson@ansonbiggs.com",
|
author_email="anson@ansonbiggs.com",
|
||||||
description="A package for reading .bdf files into NumPy arrays.",
|
description="A package for reading .bdf files into NumPy arrays.",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
url="https://gitlab.com/MisterBiggs/bdf-to-numpy",
|
url="https://gitlab.com/MisterBiggs/bdfparse",
|
||||||
packages=setuptools.find_packages(),
|
packages=setuptools.find_packages(),
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Programming Language :: Python :: 3.7",
|
"Programming Language :: Python :: 3.7",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user