Skip to content

Latest commit

 

History

History
285 lines (209 loc) · 4.68 KB

api.md

File metadata and controls

285 lines (209 loc) · 4.68 KB

Table of Contents

efont

ALIGN_LEFT

Left alignment

ALIGN_RIGHT

Right alignment

ALIGN_CENTER

Center alignment

FT2 Objects

class FT2(object)

A FreeType2 Wrapper class

Class Attributes: mono for EPD mode

mono

monochrome drawing for EPD

bold

bold style when drawing

italic

italic style when drawing

__init__

def __init__(file: str,
             render: FrameBuffer,
             size: int = 16,
             mono: bool = False,
             bold: bool = False,
             italic: bool = False) -> instance
Load font from file(.ttf, .pcf).
        
Args:
    file: file path to load.
    render: an instance of framebuf.FrameBuffer which pixel() method will be called when drawString().
    size: default size to draw text
    mono: true for loading as mono font for EPD
    bold: bold style to draw text
    italic: italic style to draw text
    
Returns:
    return True if font was loaded

Raises:
    Error - raises an exception

unload

def unload()

Unload font and free resources.

drawString

def drawString(x: int,
               y: int,
               w: int = -1,
               h: int = -1,
               align: int = 0,
               text: str = "",
               size: int = 16) -> int
Draw text string.
        
Args:
    x: x coordinate of text drawing box
    y: y coordinate of text drawing box
    w: width of text drawing box
    h: height of text drawing box
    align: alignment of text, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT
    text: text to draw
    size: optional size to draw text
    
Return:
    next x coordinate after drawing

getStringWidth

def getStringWidth(text: str) -> int
Get text width when drawing.
        
Args:
    text: text for measurement

Return:
    text width

setSize

def setSize(size: int)
Set font size to draw.
        
Args:
    Size, to modify

setColor

def setColor(fg: int, bg: int)
Set the foreground and background color when monochrome mode
        
Args:
    fg: foreground color
    bg: background color

setRender

def setRender(render: FrameBuffer)
Set font new render
        
Args:
    render, new render to use

Image Objects

class Image(object)

PNG, JPG Wrapper Class

__init__

def __init__(width: int,
             height: int) -> instance
Args:
    width, height: container width and height when drawing

load

def load(self,
         file: str, 
         mono: bool = False)
Load image from file(.png, .jpg).
        
Args:
    file: file path to load
    mono: load as mono image for EPD

Return:
    loaded image (width, height)

draw

def draw(self, 
         render:framebuf.FrameBuffer, 
         x: int = 0, 
         y: int = 0, 
         unload: bool = True)
Render image at(render, x, y).
        
Args:
    render: the container to rend, must be a FrameBuffer (derived) instance
    x, y: left-top position to draw
    unload: free image resources after drawing automatically.

unload

def unload()
Unload image, free image resource

setColor

def setColor()
Set the foreground and background color when monochrome mode.
Args:
    fg: foreground color
    bg: background color

'pydoc-markdown -I . -m efont --render-toc > efont.md' 2023/09/09