mirror of
https://gitlab.com/MisterBiggs/bdfparse.git
synced 2025-06-16 22:46:40 +00:00
Compare commits
No commits in common. "master" and "2019.2" have entirely different histories.
42
README.md
42
README.md
@ -5,42 +5,20 @@ This project takes a .bdf file and turns it into a [NumPy](https://www.numpy.org
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from bdfparse import Font
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
font = Font('9x18.bdf')
|
font = parse_chars("9x18.bdf")
|
||||||
|
matrix = font["A"]
|
||||||
|
text = "nson"
|
||||||
|
|
||||||
print(font.word('Hi'))
|
for letter in text:
|
||||||
|
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
__init__.py
Normal file
1
__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
name = "bdf_to_numpy"
|
@ -7,35 +7,6 @@ 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):
|
||||||
|
|
||||||
@ -219,14 +190,9 @@ class Font:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def word(self, word: str):
|
def word(self, word: str):
|
||||||
matrix = np.zeros(self.shape)
|
matrix = self.chars[word[0]]
|
||||||
for char in word:
|
for char in word[1:]:
|
||||||
if char in self.charNames.keys():
|
matrix = np.concatenate((matrix, self.chars[char]), axis=1)
|
||||||
arr = self.chars[self.charNames[char]]
|
|
||||||
else:
|
|
||||||
arr = self.chars[char]
|
|
||||||
|
|
||||||
matrix = np.concatenate((matrix, arr), axis=1)
|
return matrix
|
||||||
|
|
||||||
return matrix[:, self.cols :]
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
from .bdfparse import Font
|
|
8
setup.py
8
setup.py
@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2019 Anson Biggs
|
# Copyright (c) 2019 albig
|
||||||
#
|
#
|
||||||
# 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="bdfparse",
|
name="bdf-to-numpy",
|
||||||
version="2019.8",
|
version="2019.2",
|
||||||
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/bdfparse",
|
url="https://gitlab.com/MisterBiggs/bdf-to-numpy",
|
||||||
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