This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SquidDev's profile picture

Font API

Started by SquidDev, 12 July 2014 - 01:56 PM
SquidDev #1
Posted 12 July 2014 - 03:56 PM
Every so often someone requests a 'Font API' - the ability to write in any font. So I made this for all you silly people who think that using edit with Comic Sans is a good idea.

Example
SpoilerYou first need to create a font file. This should be a Bitmap (.bmp). I like to use this but it doens't matter how it looks like as long as the individual glyphs are on a black background.

The bitmap should be in 16 colour format (bit depth of 4). You can then run BitmapToFont.lua MyFont.bmp MyFont.ftf.

This can then be used:


term.clear()
local Obj = FontAPI.CreateObject(FontAPI.LoadFont("ComicSans.ftf"))
local Old = term.current()

term.redirect(Obj)

print("We all love Comic Sans")

Screenshots
Spoiler

Bugs, contributing, etc…
Its on GitHub so if you feel the urge to change something, send me a pull request and I'll merge it. If you find a bug please do report it there (or here, I'm not fussed)

Yes I know.
I realise that this is entirely impractical and silly, why else did you think I wrote it? You need about font size 12 for it to be recognisable as a particular font, and that means on a full sized monitor you have a whole 3 lines to write your wonderful content. I guess it can be used as a message board though.

Future plans:
I kinda want to implement non-monospaced fonts, but that would ruin my idea for being able to use the created object as a redirect target. Any ideas?

Download:
ImagesAPI My bitmap API is required to make BitmapToFont.lua work: pastebin get Y3JeZWzV ImagesAPI
FontAPI Obviously you need this! pastebin get ViDkRCyn FontAPI
BitmapToFont.lua If you need to convert (Requires ImagesAPI) pastebin get GTs8VQk9 BitmapToFont.lua
Edited on 12 July 2014 - 02:45 PM
flaghacker #2
Posted 12 July 2014 - 09:25 PM
How did you get a monitor with more pixels then normal in your screenshot? Config file?

Nice program(s).
Lignum #3
Posted 12 July 2014 - 09:31 PM
How did you get a monitor with more pixels then normal in your screenshot? Config file?

Nice program(s).
Monitors allow you to scale text.
flaghacker #4
Posted 12 July 2014 - 10:16 PM
How did you get a monitor with more pixels then normal in your screenshot? Config file?

Nice program(s).
Monitors allow you to scale text.

I didn't knew you could scale down, I thought you could only scale up.

Offtopic: Why are people asking for smaller pixels in suggestions then?
theoriginalbit #5
Posted 13 July 2014 - 03:37 AM
because they want to smaller pixels on terminals, which you can't do, you can only scale monitors.
flaghacker #6
Posted 13 July 2014 - 10:21 AM
because they want to smaller pixels on terminals, which you can't do, you can only scale monitors.

Okay, I see.