Initial Commit
This commit is contained in:
BIN
assets/fonts/4x6-font.ttf
Normal file
BIN
assets/fonts/4x6-font.ttf
Normal file
Binary file not shown.
11981
assets/fonts/4x6.bdf
Normal file
11981
assets/fonts/4x6.bdf
Normal file
File diff suppressed because it is too large
Load Diff
BIN
assets/fonts/5by7.regular.ttf
Normal file
BIN
assets/fonts/5by7.regular.ttf
Normal file
Binary file not shown.
25905
assets/fonts/5x7.bdf
Normal file
25905
assets/fonts/5x7.bdf
Normal file
File diff suppressed because it is too large
Load Diff
21422
assets/fonts/5x8.bdf
Normal file
21422
assets/fonts/5x8.bdf
Normal file
File diff suppressed because it is too large
Load Diff
20768
assets/fonts/6x9.bdf
Normal file
20768
assets/fonts/6x9.bdf
Normal file
File diff suppressed because it is too large
Load Diff
9822
assets/fonts/MatrixChunky8.bdf
Normal file
9822
assets/fonts/MatrixChunky8.bdf
Normal file
File diff suppressed because it is too large
Load Diff
10180
assets/fonts/MatrixChunky8X.bdf
Normal file
10180
assets/fonts/MatrixChunky8X.bdf
Normal file
File diff suppressed because it is too large
Load Diff
5236
assets/fonts/MatrixLight6.bdf
Normal file
5236
assets/fonts/MatrixLight6.bdf
Normal file
File diff suppressed because it is too large
Load Diff
5417
assets/fonts/MatrixLight6X.bdf
Normal file
5417
assets/fonts/MatrixLight6X.bdf
Normal file
File diff suppressed because it is too large
Load Diff
10184
assets/fonts/MatrixLight8X.bdf
Normal file
10184
assets/fonts/MatrixLight8X.bdf
Normal file
File diff suppressed because it is too large
Load Diff
BIN
assets/fonts/PressStart2P-Regular.ttf
Normal file
BIN
assets/fonts/PressStart2P-Regular.ttf
Normal file
Binary file not shown.
70
assets/fonts/bdf_font_guide
Normal file
70
assets/fonts/bdf_font_guide
Normal file
@@ -0,0 +1,70 @@
|
||||
""" Pasted from cursor chat to be able to use bdf fonts easier in the future """
|
||||
|
||||
|
||||
|
||||
|
||||
""" Font Loading """
|
||||
import freetype
|
||||
face = freetype.Face("path/to/font.bdf")
|
||||
|
||||
""" rendering the character """
|
||||
# Load the character
|
||||
face.load_char(char)
|
||||
|
||||
# Get the bitmap data
|
||||
bitmap = face.glyph.bitmap
|
||||
|
||||
# The bitmap data is stored in a packed format where:
|
||||
# - Each byte represents 8 pixels
|
||||
# - bitmap.pitch is the number of bytes per row
|
||||
# - bitmap.width is the width in pixels
|
||||
# - bitmap.rows is the height in pixels
|
||||
|
||||
" Drawing the character "
|
||||
#For each row in the bitmap
|
||||
for i in range(bitmap.rows):
|
||||
# For each pixel in the row
|
||||
for j in range(bitmap.width):
|
||||
# Calculate which byte contains this pixel
|
||||
byte_index = i * bitmap.pitch + (j // 8)
|
||||
|
||||
# Get the byte
|
||||
byte = bitmap.buffer[byte_index]
|
||||
|
||||
# Check if the specific bit is set (1 = draw pixel)
|
||||
if byte & (1 << (7 - (j % 8))):
|
||||
# Draw the pixel at (x + j, y + i)
|
||||
draw.point((x + j, y + i), fill=(255, 255, 255))
|
||||
|
||||
" Character Spacing "
|
||||
# Move to next character position using the font's advance
|
||||
x += face.glyph.advance.x >> 6 # Advance is in 1/64th of pixels
|
||||
|
||||
|
||||
""" Key Points:
|
||||
BDF fonts are bitmap fonts, so they have a fixed size
|
||||
The bitmap data is stored in a packed format (8 pixels per byte)
|
||||
Each bit in a byte represents whether a pixel should be drawn (1) or not (0)
|
||||
The pitch value tells you how many bytes are in each row
|
||||
The advance value tells you how far to move for the next character
|
||||
Example Usage: """
|
||||
|
||||
|
||||
def draw_bdf_text(draw, text, x, y, font_path):
|
||||
face = freetype.Face(font_path)
|
||||
|
||||
for char in text:
|
||||
face.load_char(char)
|
||||
bitmap = face.glyph.bitmap
|
||||
|
||||
# Draw the character
|
||||
for i in range(bitmap.rows):
|
||||
for j in range(bitmap.width):
|
||||
byte_index = i * bitmap.pitch + (j // 8)
|
||||
if byte_index < len(bitmap.buffer):
|
||||
byte = bitmap.buffer[byte_index]
|
||||
if byte & (1 << (7 - (j % 8))):
|
||||
draw.point((x + j, y + i), fill=(255, 255, 255))
|
||||
|
||||
# Move to next character
|
||||
x += face.glyph.advance.x >> 6
|
||||
9993
assets/fonts/ic8x8u.bdf
Normal file
9993
assets/fonts/ic8x8u.bdf
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user