Skip to content

Rumidom/Micropython_Fontlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Micropython Fontlib

A micropython library for displaying 1bit bitmaps as fonts,and displaying 1bit bitmaps sprites, it was first tested on a monocrome screen (pcd8544 nokia screen) but you should work with any monocrome screen through framebuffer

How to use it

Add fontlib.py and a 1bit font .bmp (should follow the same formatting of the bmp files on the Bitmaps folder) file to your micropython device, then use the library to modify a framebuffer:

import framebuf
import fontlib
import ssd1306
from machine import Pin,I2C

screen_width = 128
screen_height = 32

#ESP8266 scl=Pin(4),sda=Pin(5)
#ESP32 C3 scl=Pin(9),sda=Pin(8)
i2c = I2C(scl=Pin(9),sda=Pin(8))
oled = ssd1306.SSD1306_I2C(screen_width, screen_height, i2c)

spce = 1 # characters spacing
pos_x = 0 # X position on the frame buffer to print the text
pos_y = 0 # Y position on the frame buffer to print the text

five = fontlib.font("five (5,5).bmp") # Loads font to ram 

fbuf = framebuf.FrameBuffer(oled.buffer, screen_width, screen_height, framebuf.MONO_VLSB)
fbuf.fill(0)
fontlib.prt("The Quick Gray",pos_x,pos_y,spce,fbuf,five) # prints text using font
oled.show()

see the examples folder on how to use it with diferent displays.

How create new fonts

Most image editors should be able to save files to 1bit bmp, I recommend Paint.net, draw 1 pixel padding around each letters, the file name should include the character size, like the fonts found in the fonts folder. on paint.net if you "save as" and choose bmp it will prompt you with "saving configuration" choose the 1bit option. alternatively you can create the font as a normal bmp file and convert it using Pillow:

from PIL import Image

img = Image.open('input_image.png')
img = img.convert('1')
img.save('output_1bit.bmp')

TODO

  • Load fonts directly from 1bit bitmaps
  • Support for portuguese special characters (ç,á,é,í,ó,ú,â,ê,ô,ã,õ)(Ç,Á,É,Í,Ó,Ú,Â,Ê,Ô,Ã,Õ).
  • Support for color screens

Available fonts:

futuristic :

five:

oldschool :

cellphone :

icons:

IBM BIOS :

LICENSE:

this project is MIT licensed

Support

ko-fi

About

micropython library for using 1bit bitmaps as fonts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages