Stunts Forum

Stunts - the Game => Stunts Related Programs => Topic started by: Cas on March 27, 2021, 10:06:13 PM

Title: Stunts font editor
Post by: Cas on March 27, 2021, 10:06:13 PM
So, I analysed the format of Stunts fonts, as I mentioned before, and found that it's really very flexible. I created a Wiki article describing the format, which you can read here (http://wiki.stunts.hu/index.php?title=Font_file). It was Daniel3D that prompted me to take a look at this matter and I've created a font editor and a couple of format converters that I will soon publish here.

Daniel3D and I have been testing Stunts to see how it behaves with modified fonts and we've encountered that it is feasible to add diacritical marks and new characters for better support of other languages. Daniel is now in the process of creating a font that will use a code page mostly compatible with Latin-1, but allowing some extra characters so that languages that are not fully supported in Latin-1 (such as Hungarian) can be supported as well.

With these fonts, it will become possible to create translations like what GTAMan15 has been working on with all necessary characters, so we'll start by facilitating these fonts and a code page converter I'm going to develop to him, so that he can continue with his work more comfortably. We could also develop translations to other languages. Expect the software here in the next few days :)

EDIT: Current version of the editor and coverter can be downloaded from here
Title: Re: Stunts font editor
Post by: llm on March 28, 2021, 10:06:07 AM
did you had a look at the re-stunts assembler-code (wich produces a equal game binary) what the real code is doing?

just search for "font" in the restunts/asmorig folder
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/dseg.asm
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/dseg.inc
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg000.asm
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg003.asm
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg005.asm
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg008.asm
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg008.inc
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg009.asm
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg012.asm - contains mostly the font implementations
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg012.inc
https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asmorig/seg032.asm

or this other mirror on github - where you can directly download zip-files
https://github.com/xor2003/restunts
Title: Re: Stunts font editor
Post by: Daniel3D on March 28, 2021, 10:10:54 AM
Part of the work involves adding the unmapped characters to the right position. Only the top half of Latin-1 is part of the font. (At least in the default font)
It was already known that some characters were used for editing purposes.

CAS found the following:
- Character 0 (null) - It is never printed because it marks the end of a string
- ] - It is almost never printed, because it's used to mark the end of line in multi-line text
- [ - It isn't printed in menus, as it marks the start of a menu option
- } - It isn't printed in menus, since it marks the beginning of the menu
               \ Edit: it's a half height enter. the space between the Title and the menu items.
- @ - It isn't printed when the text is to contain an input or parameter, in which case, it serves as a placeholder

these characters can be used if there is a copy on a different address.
To be included to that can't be in their original locations:
- O and o with double acute accent (Hungarian)
- U and u with double acute accent (Hungarian)
Title: Re: Stunts font editor
Post by: Daniel3D on March 28, 2021, 10:20:34 AM
Quote from: llm on March 28, 2021, 10:06:07 AM
did you had a look at the re-stunts assembler-code (wich produces a equal game binary) what the real code is doing?

I didn't, cause I can't.  8)
I've been mostly working on the visual part.
CAS has looked at characters that are used for different functions.
We also tested a lot. I'm fairly sure we didn't miss anything.
Title: Re: Stunts font editor
Post by: GTAManRCR on March 28, 2021, 11:01:56 AM
Quote from: Daniel3D on March 28, 2021, 10:10:54 AM
- ] - It is almost never printed, because it's used to mark the end of line in multi-line text

End of line in multi-line text? Then what about this?
Title: Re: Stunts font editor
Post by: Daniel3D on March 28, 2021, 12:17:10 PM
Quote from: GTAMan18 on March 28, 2021, 11:01:56 AM
Quote from: Daniel3D on March 28, 2021, 10:10:54 AM
- ] - It is almost never printed, because it's used to mark the end of line in multi-line text

End of line in multi-line text? Then what about this?
As far as I know,
A menu item is not and cannot be multi-line text.

Therefore, it doesn't work here.
In fact, the "enter" is translated by stressed to ] and printed by the Stunts engine, so you see the ] double.

The text above the option's menu which shows the version is also an example of plain text. That field prints all above-mentioned characters.
I used that to view them all, so I could make the true type Font.

EDIT; typo's
Title: Re: Stunts font editor
Post by: Cas on March 28, 2021, 10:32:29 PM
Daniel has said it in detail. It seems Stressed only recognises ] as an end-of-line marker, but does not process the other Stunts control codes. Son when you enter an end-of-line, you get a ]. It looks like both [ and ] produce and end of menu option, but [ does not go to the next. So you can have two options on the same line, but you can't have an option that spans two lines.

Quote from: Ilmdid you had a look at the re-stunts assembler-code [...]?
I haven't checked that yet. The font format is pretty straightforward and I'm quite certain we got the results right. Only a few things I would like to find out and I could take a look at the original code, although something I'm very bad (slow) at is reading another person's code. The 30 years I've been programming, I've always done it on my own, so I have zero experience in reading somebody else's programming or programming in teams. However, it'd be good to find out the exact meaning of the word that changes between 1 and 2.

Here I'm posting the editor and the converters to and from PF format. PF format is limited (fixed width, always 8, and all 256 characters have to be defined), but it is partially compatible. The keys to use the editor are:

L - Load a font
S - Save a font
Arrow keys - move the glyph (or change maximum cell size)
Tab - switch between moving the glyph and changing maximum cell size
Enter - activate/deactivate character
< and > - Change individual character width
CTRL+C and CTRL+V - Copy and paste characters
Space - Look at the whole font and select a character
+/- - Go to next/previous character
Title: Re: Stunts font editor
Post by: Daniel3D on March 28, 2021, 11:07:40 PM
Quote from: Cas on March 28, 2021, 10:32:29 PM
< and > - Change individual character width
+/- - Go to next/previous character
these don't require you to hold shift. so, - and _ are both accepted as -
the same goes for =/+ and ,/< and ./>   8)
Title: Re: Stunts font editor
Post by: Daniel3D on March 28, 2021, 11:15:01 PM
The default font is edited to include latin-1 characters,
Title: Re: Stunts font editor
Post by: Daniel3D on March 28, 2021, 11:22:23 PM
Attached the old and new font.
Also, the other two fonts.
These are in your stunts folder as well, but should you mess them up,
here is a backup.  8)

Fontled has no real use to expand. It is not used for text.
Fontn (n for narrow) does need expanding,

Although the size of the font can be changed,
like CAS explained the track selection menu doesn't support larger characters (yet).
That gives limited space for some special characters.
Feel free to experiment and improve my work.
Title: Re: Stunts font editor
Post by: Cas on March 28, 2021, 11:56:06 PM
I'll move the editor package to the first post for easy access!!
Title: Re: Stunts font editor
Post by: GTAManRCR on March 29, 2021, 08:49:42 AM
FONTDEF.FNT goes well for menus
Had to replace the two accented I's to make it display correctly
? is now currently a ? (Small o with double acute accents)
Title: Re: Stunts font editor
Post by: GTAManRCR on March 29, 2021, 09:01:41 AM
For some reason the small double acute accented o triggers the questionmark, so I had to replace it
Title: Re: Stunts font editor
Post by: Daniel3D on March 29, 2021, 09:08:49 AM
The U, u, O and o with double acute accents are in the font table, but at an alternate location.
CAS will make a tool for that.

I don't know if the ASCII code (144-147)works,
With "Alt + 147"  the character should appear in a in-game field (track name) but if it translates through stressed I don't know.
I was wrong...
Title: Re: Stunts font editor
Post by: GTAManRCR on March 29, 2021, 09:19:52 AM
ALT+144=É
ALT+145=?
ALT+146=?
ALT+147=ô
None of them is ? (Alt+0245)
Title: Re: Stunts font editor
Post by: Daniel3D on March 29, 2021, 09:58:31 AM
O, off course... Stressed uses different mapping.
As I said before.
CAS is working on a tool to directly edit the Res files.
So all characters can be used.
(Maybe it can be included in stressed at one point)
So the U, u, O and o with double acute accents have to be added later.

Title: Re: Stunts font editor
Post by: Cas on March 29, 2021, 10:41:43 PM
GTAMan, the way you replaced it works well. The thing is Stunts only supports 256 character code points, so we can't use Unicode. The original character table coming with DOS systems was CP437, which does not include many of the characters we need for multi-language support. Most languages used by the Stunts community are supported by Latin-1, a 256 character set that's part of the Unicode standard, but Hungarian uses Latin-2, which is different. The characters O and U with double acute accent are in Latin-2 at locations that collide with Latin-1 characters used in Portuguese, so I decided we could use Latin-1 for most characters and for those four (O and U with double-acute in upper and lower case) use a non-standard position. It's the only way. Any other thing would require more characters to be moved. Daniel noted that the positions starting at 144 (originally an É in CP437) were available in Latin-1, so these characters have been placed there. If you are able to do the switch, it's going to work well. Later on, I can make a translator for easily adapting these characters.
Title: Re: Stunts font editor
Post by: GTAManRCR on March 29, 2021, 10:43:40 PM
ALT codes work actually, with Latin-1 characters.  This means, I have to replace ô with the o double acute accented variant, and so on, or else every questionmark will show up as this letter, even the u with the variant above
Title: Re: Stunts font editor
Post by: Daniel3D on March 29, 2021, 10:48:11 PM
Quote from: GTAMan18 on March 29, 2021, 10:43:40 PM
ALT codes work actually

O, cool  8)
Title: Re: Stunts font editor
Post by: GTAManRCR on March 29, 2021, 11:11:06 PM
ALT+147 (ô) triggers the 244th character actually, so if I write ô in stressed without modifying the question mark, it's fine, so question marks can be separated. For this reason, I replaced the 244th (ô) character with o double acute accent Latin-2 character. I think this is the right order. Tomorrow I'll upload the FONTDEF.FNT which is just edited
Title: Re: Stunts font editor
Post by: Cas on March 30, 2021, 05:39:47 AM
Quote from: GTAMan18ALT codes work actually, with Latin-1 characters.
If I remember well, Alt + Keypad in Windows works in two different ways: if the code starts with a zero, it gives you the Unicode/Latin-1 character of that number. But, if the first key is not a zero, it emulates old DOS behaviour by following CP437 codes. Therefore, if you do ALT+144, the system will send Stressed one character and if it is ALT+0144, another entirely. How Stressed translates this into an 8-bit font depends on the libraries it was compiled with. The thing is: not necessarily the number you're entering represents the actual position in the font!!  I'd recommend you to test first :)
Title: Re: Stunts font editor
Post by: GTAManRCR on March 30, 2021, 07:24:15 AM
Edited ô and û in FONTDEF.FNT and FONTN.FNT files
Title: Re: Stunts font editor
Post by: Daniel3D on March 30, 2021, 01:35:18 PM
Quote from: Cas on March 30, 2021, 05:39:47 AM
Quote from: GTAMan18ALT codes work actually, with Latin-1 characters.
If I remember well, Alt + Keypad in Windows works in two different ways: if the code starts with a zero, it gives you the Unicode/Latin-1 character of that number. But, if the first key is not a zero, it emulates old DOS behavior by following CP437 codes. Therefore, if you do ALT+144, the system will send Stressed one character and if it is ALT+0144, another entirely. How Stressed translates this into an 8-bit font depends on the libraries it was compiled with. The thing is: not necessarily the number you're entering represents the actual position in the font!!  I'd recommend you to test first :)
I'll try this tonight. Maybe I can figure it out.

It would be nice if we can access the extra characters and wouldn't need to alter the standard latin-1 layout.
That way we could make support for languages based on the Latin alphabet.
QuoteSince the font now contains the whole latin-1 set plus missing or duplicated characters I dubbed the new font for Stunts "Latin-1+"
This for clarity, for conversation in relation to the alternate properties of the new Stunts font.

A translation tool that translates text made in latin-2 to latin-1+ text is something to consider.
But if the codes work then it may not be necessary.
Title: Re: Stunts font editor
Post by: GTAManRCR on March 30, 2021, 02:41:19 PM
Not a necessary thing, because just replacing circumflex letters with the desired ones it works. But because the letters which the circumflex trigger are now acute accented, the game will show it as described, not circumflexed
Title: Re: Stunts font editor
Post by: Daniel3D on March 30, 2021, 02:55:24 PM
Quote from: GTAMan18 on March 30, 2021, 02:41:19 PM
Not a necessary thing, because just replacing circumflex letters with the desired ones it works. But because the letters which the circumflex trigger are now acute accented, the game will show it as described, not circumflexed
true,
but there is no longer support for the letters you have replaced. Not a big problem, but also not the goal of this project.
So I would like to look at a solution that has both,

But it works, and that is most important.
Title: Re: Stunts font editor
Post by: GTAManRCR on March 30, 2021, 05:24:28 PM
Amazing work! Special thanks to Cas for creating this piece of software. Duplode has to upload this on SCR Stunts
Title: Re: Stunts font editor
Post by: Daniel3D on March 30, 2021, 08:36:18 PM
It really is. I tried many bitmap font editors to see if we could make them compatible with the Stunts font. But this one is a lot more powerful than any of those.

When we were doing size testing it seemed to work at first so I started to add the extra characters.
Then CAS discovered that the track selection is limited to 8 high.
I could change, reposition and alter the hight of about 80 characters in 10 minutes.

That is not possible with any font editor..
;D
Title: Re: Stunts font editor
Post by: GTAManRCR on March 30, 2021, 08:47:43 PM
And you can edit letters freely, so can make symbols with these limits show up in game
Here is an example of Bluetooth symbol
Title: Re: Stunts font editor
Post by: Daniel3D on March 30, 2021, 09:43:19 PM
Quote from: GTAMan18 on March 30, 2021, 08:47:43 PM
And you can edit letters freely,
I know, all characters not based on a existing one I had to draw pixel by pixel..
Of course there are a maximum of 72 pixels in the current configuration. Most are 20 to 30 pixels I guess.

But still,  8)
Title: Re: Stunts font editor
Post by: Cas on March 30, 2021, 11:02:56 PM
My idea, when I proposed hybridising the character table, which Daniël has appropriately dubbed Latin-1+, was that the new font would be both compatible with the original text in Stunts and with translations into any language used in the community. This way, we wouldn't need to ship a separate set of FNT files with the translated RES files. If you modify the characters at the Latin-2 positions for the Hungarian double-acute, you won't need to convert those characters, but you're going to need a separate set of fonts for Hungarian that will not work with other languages (Portuguese and French).

This is not optimal, but isn't a serious problem either, because it seems to me that most people will at the very most want to switch between English and their own language and not between two non-English languages, so mostly everybody will be OK with just one FNT file set anyway.

Maybe other DSI games use this FNT file format as well. In that case, we might be able to import and export fronts between games. And in general, I figure I could build a library to display these fonts, as it's a nice format for variable width fonts to use.
Title: Re: Stunts font editor
Post by: Daniel3D on March 31, 2021, 02:08:36 PM
Quote from: Cas on March 30, 2021, 11:02:56 PM
Maybe other DSI games use this FNT file format as well. In that case, we might be able to import and export fronts between games. And in general, I figure I could build a library to display these fonts, as it's a nice format for variable width fonts to use.

I did some research. (downloaded every DSI game I could find and some others form the same period in the process)
I found 25 games so far and CAS already had found 1,
Hardball has the thick and narrow font like stunts, but different.
Grandprix only has the thick font, but looks like Hardball font but wider.
4D sports tennis has similar narrow font as stunts but a bigger led font and a HUGE news font, 12pixels high.
Bill Elliott's Nascar Challenge fonts are packed, can't open them
Dick Tracy The Crime-Solving Adventure font is packed, can't open it
4D sports boxing had the same exact font as stunts.

I'll include the fonts here,
You have to rename to FONTDEF.FNT, FONTN.FNT or FONTLED.FNT to use in stunts.

You can preview the fonts in the font editor.
You need at least the April second version to open the NEWS font.
The PFN files can not be opened. Stunpack can't unpack them either.
Title: Re: Stunts font editor
Post by: Daniel3D on March 31, 2021, 11:23:28 PM
Something in FONTLED bugged me...
So I played with it a little.

If you like it, here it is.
Title: Re: Stunts font editor
Post by: Cas on April 01, 2021, 01:28:42 AM
It does look more like a true LED display
Title: Re: Stunts font editor
Post by: Daniel3D on April 01, 2021, 10:00:15 PM
Quote from: Daniel3D on March 31, 2021, 11:23:28 PM
Something in FONTLED bugged me...
So I played with it a little.
4D tennis also has a led font. This one is 2 pixels larger and fits the display in the replay editor quite nicely.
It is also the timer on the screen.

For those who like it.
Title: Re: Stunts font editor
Post by: Cas on April 02, 2021, 07:55:27 AM
Very cool!  But yes, the other one is the right size for Stunts.

By the way, I'm posting a new version of the font editor in the first post of the thread!
Title: Re: Stunts font editor
Post by: GTAManRCR on April 02, 2021, 10:25:42 AM
FONTLED.FNT with rounded numbers
Title: Re: Stunts font editor
Post by: Daniel3D on April 02, 2021, 10:47:03 AM
Quote from: GTAMan18 on April 02, 2021, 10:25:42 AM
FONTLED.FNT with rounded numbers
Could you add a preview picture?
Title: Re: Stunts font editor
Post by: GTAManRCR on April 02, 2021, 10:52:17 AM
Yes
Title: Re: Stunts font editor
Post by: Daniel3D on April 02, 2021, 11:54:29 AM
O. You can open the program multiple times.
For Windows users. Just drop a font file on the executable to load the font (saves typing)
It's easier to compare or imitate fonts.
Title: Re: Stunts font editor
Post by: Cas on April 02, 2021, 10:44:44 PM
New features in the current version of the editor (downloadable from the first post in the thread) include:
- Font name is shown in the title bar
- For smaller fonts (most of them) the full-font display is bigger
- Current character is marked in yellow and inactive characters are grayed out
- F1 for help, N for new font
- TAB allows for a third function for arrow keys, to change the font size while moving the characters at the same time
- CTRL+X and CTRL+I can be used for exporting and importing characters (like CTRL+C and CTRL+V, but can be used to copy characters from an instance of the program to another and also to upload text-based characters)
Title: Re: Stunts font editor
Post by: Daniel3D on April 02, 2021, 11:40:05 PM
Found 3 more games, one has readable fonts.
I've added them to my earlier post.

Two games have PFN files. It is a packed font but stunpack can not open them.
Probably a different evolution of the compression used for Stunts.
I don't know if anyone wants to crack that nut? 8)
Title: Re: Stunts font editor
Post by: GTAManRCR on April 03, 2021, 09:15:10 AM
Excellent
Perfect
Impressive
Awesome
Title: Re: Stunts font editor
Post by: GTAManRCR on March 25, 2023, 06:24:03 PM
Is it possible to convert FONTDEF.FNT or FONTN.FNT to TTF?
Title: Re: Stunts font editor
Post by: Daniel3D on March 25, 2023, 08:19:39 PM
The TTF I made manually with a font creator. In a 16*16 grid.
Title: Re: Stunts font editor
Post by: GTAManRCR on March 25, 2023, 08:29:34 PM
Yes, but the extended one. Is it possible to convert so no need of recreation?
Title: Re: Stunts font editor
Post by: Daniel3D on March 25, 2023, 09:56:17 PM
No, unfortunately they are not compatible.
Title: Re: Stunts font editor
Post by: Cas on March 26, 2023, 05:20:52 AM
I don't know the internal format of TTF fonts, but they're probably very complex to parse and render. I imagine they must be something like a huge XML file zipped with deflate compression and renamed to TTF. Well, that's more to be expected of OTF, actually. But TTF must not be that different. I wouldn't want to have to deal with that, ha, ha