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

Font API - with command computers!

Started by SquidDev, 18 February 2015 - 07:50 PM
SquidDev #1
Posted 18 February 2015 - 08:50 PM
Half a year ago I wrote a Font API, which worked OK, but its resolution was awful. However we now have command computers, which opens up so many possibilities. And so I aim to put them what they were designed for: 40 metre high Comic Sans. So here we are: Computer Craft's only command block powered font API.

Screenshots:
Spoiler


I total feel this is what Dan was thinking when he added Command Computers.

How it works:
I used this font parser to convert TTF to SVG paths. You can convert TTF fonts on my website with it.

The lua code then parses the SVG paths and renders them as lines and bezier curves using setblock, this means the font scales to any size.

Quirks, issues, etc…
Some characters don't render properly - (I'm looking at you u). The issues with the second image is that I'm at the wrong angle and it is at too small a size. I'd like to be able to fill the characters, but I'm going to have to think about it.

Code
pastebin get SJpecjR0 font
font [message] [letter height in blocks] [block name & metadata value]

It is also on GitHub

Ok, it isn't really an API, but more of a program. But I didn't write this to be accurate.
Edited on 02 April 2015 - 05:57 AM
oeed #2
Posted 18 February 2015 - 09:00 PM
Comic Sans aside, this is really, really, really freakin' awesome.

I take it you can render other SVG files too (and maybe a non-Comic Sans font :P/>)?
SquidDev #3
Posted 18 February 2015 - 09:14 PM
Comic Sans aside, this is really, really, really freakin' awesome.

I take it you can render other SVG files too (and maybe a non-Comic Sans font :P/>)?

Thanks! I don't think you can get this in OneOS though :P/>

Any TTF font - so pretty much any Window/Mac system font and pretty much all SVG fonts. At the moment I only support Move, line, cubic and quadratic SVG path commands (though the others are actually just shortcuts for these four) so as long as it doesn't use that then it should work.

EDIT:I've added a parser on my website to convert TTF to SVG.
Edited on 18 February 2015 - 09:14 PM
cdel #4
Posted 18 February 2015 - 09:42 PM
I am going to love using this, mainly for giant sky text on servers, kudos to you
biggest yikes #5
Posted 18 February 2015 - 11:53 PM
If you can change the SVG path (i.e the font), how could you do such?A
Also, it would be wise to check if the user is actually using a command computer, for those naughty people who try it with an advanced computer..
Edited on 18 February 2015 - 10:56 PM
oeed #6
Posted 19 February 2015 - 12:22 AM
Oh also, can you do filled paths, or is it just outlines?
SquidDev #7
Posted 19 February 2015 - 08:57 AM
I am going to love using this, mainly for giant sky text on servers, kudos to you

Thanks! I'd give it a little while as I'm going to try to fix some letters like U (the outline never finishes) and get filling working. If you use Comic Sans I'll be even happier.

If you can change the SVG path (i.e the font), how could you do such?A
Also, it would be wise to check if the user is actually using a command computer, for those naughty people who try it with an advanced computer..
I'm totally confused by the first question, sorry. I'll add a check for a command computer, though those screenshots kinda make it obvious that you need one.

Oh also, can you do filled paths, or is it just outlines?
At the moment only outlines, I'm going to work on a fill method soon, but how I'm not sure yet.
oeed #8
Posted 19 February 2015 - 09:04 AM
If you use Comic Sans I'll be even happier.

*speechless*

Oh also, can you do filled paths, or is it just outlines?
At the moment only outlines, I'm going to work on a fill method soon, but how I'm not sure yet.
Yea ok. I haven't looked at your code at all, nor really know much about splines, but I'd imagine that if you have an table of all the intersecting points at a certain X or Y (depending how you want to do it) you could just fill from odd points to even points (assuming you start with i = 1).
SquidDev #9
Posted 19 February 2015 - 09:17 AM
Oh also, can you do filled paths, or is it just outlines?
At the moment only outlines, I'm going to work on a fill method soon, but how I'm not sure yet.
Yea ok. I haven't looked at your code at all, nor really know much about splines, but I'd imagine that if you have an table of all the intersecting points at a certain X or Y (depending how you want to do it) you could just fill from odd points to even points (assuming you start with i = 1).

I really don't know. At the moment I'm rendering in 2D, I'm planning to get some transformation stuff working so I can rotate the letters too. However I'd like rotation to happen before scaling, and filling need to happen afterwards (well it can happen before but will be more inefficient - the SVGs are 2000 pixels high). I'm going to experiment and have a think.
Edited on 19 February 2015 - 08:18 AM
SquidDev #10
Posted 19 February 2015 - 02:04 PM
So I've got some more stuff working:
  • Implicit path finishing. This means letters such as u and v will not look broken in Comic Sans
  • Improved transformation chain. This is basically like OpenGL's transformation idea:

Each letter is scaled, translated to the correct position, then rotated, then translated again. No I don't know what the point is either.

The next step is to get filling working, I've got some ideas about it, but it may take some time.
Geforce Fan #11
Posted 21 February 2015 - 10:47 PM
You could say this program sticks out like comic sans on a paper ;)/>
biggest yikes #12
Posted 22 February 2015 - 09:30 PM
If you can change the SVG path (i.e the font), how could you do such?A
Also, it would be wise to check if the user is actually using a command computer, for those naughty people who try it with an advanced computer..
I'm totally confused by the first question, sorry. I'll add a check for a command computer, though those screenshots kinda make it obvious that you need one.
How do you change the font that the program writes in?
EDIT: Nevermind, I found out how myself
Edited on 22 February 2015 - 08:38 PM
SquidDev #13
Posted 01 March 2015 - 11:20 AM
Update time!

Firstly I added a something new! Let me present to you Computer Craft's new logo:

I feel this is what Dan wanted. Ok, maybe it needs a little work…

This is rendering a bitmap file of the computer Craft logo using my Images API and command blocks, as well as the existing font API. I've put the code on GitHub so you can have a read of it. Lines 29-72 draw the font and 74-102 handle the image. It works pretty well though the algorithm for finding the closest block to draw is slightly broken.

I am still working on trying to fill text though I have absolutely no idea. Does anyone know a good way to fill a polygon. Also does anyone know of an RGB to Block lookup table?
Edited on 01 March 2015 - 10:20 AM
Bomb Bloke #14
Posted 19 April 2015 - 05:26 AM
I am still working on trying to fill text though I have absolutely no idea. Does anyone know a good way to fill a polygon.

I've used this method in the past.