Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the unicode letters possible? #15

Open
ShookieOfficial opened this issue Oct 20, 2019 · 3 comments
Open

Fixing the unicode letters possible? #15

ShookieOfficial opened this issue Oct 20, 2019 · 3 comments

Comments

@ShookieOfficial
Copy link

1 issue, 1 question:

Issue: As you can see on the attached files, the font doesn't include letters in my language; æÅ, øÅ and åÅ + the currency for Euro; ... Can I manually add them to the chosen font somehow or can/will you do it, or..? Would love to contribute to this, if possible.

Question: As you can also see, the font is somewhat "stretched" within the borders... Is there a way to normalize this EVEN if the border needs to that tall?
fontletters

Otherwise, this is such an awesome addition to have on twitch! Thanks a BUNCH for making time to make this AND keep it updated!

@GlitchCog
Copy link
Owner

Thanks, it's great to hear you like the Fontificator!

In theory it should be able to do what you're asking, but in practice, there will probably be bugs. Especially if you're trying to add characters that are built from multiple code points or surrogate pairs or whatever in Java. There are a couple places you might run into trouble in the code. Specifically here-
In com.glitchcog.fontificator.config.ConfigFont.java:

                if (w * h != charKey.length())
                {
                    report.addError("Character key length (" + characterKey.length() + ") must match the number of characters in the font image (" + w + " x " + h + " = " + (w * h) + ")", LoadConfigErrorType.VALUE_OUT_OF_RANGE);
                }

This checks that the height and width of the font PNG grid match the number of specified characters you're trying to load. The character count won't be correct for non-standard characters because I think .length() doesn't really work for those. There may be other places in the code where this will be a problem. But this is the way you would do it, as long as you're only adding characters that don't need code points to calculate their length or anything! (I tried out the ones you were hoping to add, and it looks like they trigger this bug.) But this is the general procedure to add more characters, or to use an entirely different set of characters:

All the existing fonts only have a standard 8x12 grid of ASCII characters 32-127, and I usually have to draw my own version of a few characters to fill that range. Characters like #, {, }, ~, and @ are rarely included in retro video game fonts.

So to include characters beyond those, start by adding them to the PNG file of the font you want to include new characters on. You can pull the PNG from GitHub in the resources/fonts directory. You'll have to do the work of drawing whatever characters you want into the font. A lot of GBA games have extended characters in; I just didn't include them. You'll need to increase the size of the image by another row too, to make room for the new characters. I usually use Adobe Photoshop to draw them. You need to keep each character within the confines of the character grid. I usually create a checkerboard layer to better see the edges of the character's allotted space. Then you'll need to manually edit a saved .cgf configuration text file. Load your new PNG file as a custom font (it'll look busted since it'll try to load it as an 8x12 grid of characters, even though it's got at least an extra row. Just select Custom... from the font selection menu to load your PNG file with the extra characters at the end, and save your .cgf configuration file with that one loaded. That'll be the .cgf file you want to edit manually. Open it in a text editor.

The properties you need to change will be:
fontCharacters - it always just includes those ASCII 32-127 by default, and there's no way to change it from within the program, so when you put your own characters onto the end of that value, it should pick them up. Just make sure they match up with the order you put them in the image, from left to right, top to bottom.
fontGridHeight - This is always 12 for the default 8x12 grid of the 32-127 characters. You'll need to bump it up by 1 for every new row you add to get 8 more characters.

So for example, you'd want to change the default:

fontGridHeight=12
fontCharacters=\ \!"\#$%&'()*+,-./0123456789\:;<\=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F

into:

fontGridHeight=13
fontCharacters=\ \!"\#$%&'()*+,-./0123456789\:;<\=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007FÆØÅæøåb̥€

But like I said, I don't believe the program will handle these characters correctly. The charKey.length should probably be calculated better, based on this- https://stackoverflow.com/questions/6828076/how-to-correctly-compute-the-length-of-a-string-in-java

Please feel free to reach out to me if you have any more questions about this. Sorry this isn't a hopeful response, but from the ground up I only ever intended it to handle the basic ASCII character set, since so few games even have all of those represented in their fonts.

As for the font stretching, I'm not sure what you mean by that. The program shouldn't be scaling the X or Y independently ever, so I don't think that should be possible. Am I misunderstanding the issue somehow? Do you mean the non-standard characters relative to the game font characters? Those are just drawn from whatever font you have locally. I believe the Baseline Height Offset value will adjust where those characters sit relative to the game font characters.

@ShookieOfficial
Copy link
Author

Thanks for the elaborate reply! Much appreciated.

Yeah, I am using your chat every single time I do stream. Even gotten some nice layer ideas and such. Credits will be given when I am done with the setup, of course. Thanks for it all!

Well, I guess the title mislead you a little bit. Sorry about that. What I meant to say that there's no "error" in the letters, but my language letters aren't looking good since they cannot be scripted into the particular font. If you look at this font: https://www.dafont.com/chronotype.font - You can see that he's managed to get all letters included in the font. Not sure how, but yeah... that's what I meant by it all. IF I can add/fix the letters to that particular font for the twitch chat, how can I do that, perhaps? I tried looking for an email or something to contact you, but yeah, I'd love to contribute to this in any ways possible, of course.

Thanks again for taking your time and sorry for my confusion.

@GlitchCog
Copy link
Owner

No problem, thanks for your interest in the Fontificator. If I can find time, I'll work on getting extended characters working, but I've had trouble getting code points String things to work, and I'm pretty busy with other stuff right now too. But it's on the to-do list!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants