304 downloads 430 views May 30, 2024
profile

More Fonts by Michiel

Updated May 30, 2024
project thumbnail

Introducing More Fonts: a library to print large text using teletext pixels with various fonts, sizes, and text wrapping and spacing options!


Basic usage

Use the print function to print some text at the current cursor location:

local mf = require("morefonts")

term.clear()
term.setCursorPos(2, 2)
term.setTextColor(colors.yellow)
term.setBackgroundColor(colors.gray)

mf.print("Hey!")

If you don't want it to end on a new line, use write instead of print:

mf.write("Hi!")

If you want to print on a terminal at a specified location (x, y) without it scrolling when it gets to the bottom of the screen, use writeOn instead:

mf.writeOn(term, "Hey!", 3, 7)

Leaving the x and/or y as nil will automatically center it on the terminal:

mf.writeOn(term, "Wow!", nil, 2) -- horizontally centered

Font options

These three functions all have an additional optional parameter for font options, with which you can specify e.g. which font to use, which size to use, and which alignment options to use:

mf.writeOn(term, "MORE FONTS can do text wrapping!", nil, nil, {
    font = "fonts/PublicPixel",
    dx = 0,
    dy = 0,
    scale = 1,
    wrapWidth = 80,
    condense = true,
    sepWidth = 1,
    spaceWidth = 5,
    lineSepHeight = 5,
    textAlign = "left",
    anchorHor = "center",
    anchorVer = "center",
})

mf-font-options

All values in the font options are optional, so you do not have to specify all of them.

All numerical values in the font options except for scale are in teletext pixels (which are different from the terminal character pixels which are used for the (x, y) position for the writeTo function, every terminal character pixel consists of 2x3 teletext pixels).

Default font options

After setting your own default values for any font options, these values will automatically be applied to any text (unless they are overwritten):

mf.setDefaultFontOptions({
    condense = true,
    font = "fonts/PublicPixel",
})

mf.print("hi")                            -- uses previously set default font
mf.print("hi", {font = "fonts/3x3-Mono"}) -- uses 3x3 Mono instead of default font (but is still condensed)

Any font option that you do not include in your own default font options will use the library's default value by default.

More information about the various options is available on GitHub


Pine3D Edition

Want to use More Fonts with Pine3D? Use More Fonts Pine3D Edition to draw directly to draw directly to a Pine3D frame buffer!

mf-pine3d-edition

It only has a writeOn function, it does not fill background colors, the text color is passed as an argument, and all coordinates are in teletext pixels (instead of terminal character pixels), but other than that it works exactly the same as the standalone version!


Font browser

Use the font browser to preview all available fonts from GitHub. Navigate left or right to switch between fonts. mf-font-browser

wget run https://pinestore.cc/d/37
Git Repository
project screenshot project screenshot project screenshot project screenshot project screenshot project screenshot project screenshot project screenshot
comments
You can login with Discord to leave comments and reply to others!
There are no comments yet