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

Add a font supporting more characters #9

Merged
merged 1 commit into from
Apr 23, 2017
Merged

Add a font supporting more characters #9

merged 1 commit into from
Apr 23, 2017

Conversation

tulior
Copy link
Contributor

@tulior tulior commented Apr 12, 2017

Changed the font from Arial to Liberation Sans, which is licensed under the SIL Open Font License.

The tool fontbuilder was used to generate the following character map from the aforementioned font.

2017-04-21-201808_553x532_scrot

This is the whole of printable Extended ASCII.

Also, when matching for the character's id, the type has been changed to unsigned so that charcodes larger than 0x0F could be used.

@JayFoxRox
Copy link
Owner

Please have all information in the first post (= merge your second post into the first post and delete the second post).

Why isn't there a screenshot of the text in action?


One font is probably fine for now. It's more important that the exact details used for the fonts creation are documented (e.g. have the fontmap, list of fonts [possibly with download link, so preferably fonts which are easy to license], font size, texture size etc. in the wiki)

Also see andryblack/fontbuilder#19 and
andryblack/fontbuilder#4 . If those would exist one could just store a config file to generate these fonts more easily. This is beyond the scope of the PR though.


I haven't reviewed the code yet. I'll probably do so during the next couple of days. Please remind me if it doesn't happen :)
(Reviews by others appreciated! @anodium ?)

Copy link

@anodium anodium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is Arial Black still in the codebase, if Liberation Mono does its job and more?

main.cpp Outdated
@@ -66,7 +66,8 @@ int main(int argc, char* argv[]) {

std::shared_ptr<Texture> texture = std::make_shared<Texture>("data/font/main");

std::shared_ptr<Text> text = std::make_shared<Text>("data/font/arial_black_regular_65");
//std::shared_ptr<Text> text = std::make_shared<Text>("data/font/arial_black_regular_65");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this commented out instead of edited directly?

text.cpp Outdated
@@ -91,7 +91,7 @@ class Text {
}

auto isMatchingSymbol = [&](const Symbol& symbol) -> bool {
return symbol.id == static_cast<uint32_t>(c);
return symbol.id == static_cast<unsigned char>(c);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What purpose does changing the type have?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Also if the type is unsigned here it should probably also be like that in the zengl struct (which is currently int32_t).
However, I don't know how unicode works in C++ and if zengl files even use unicode (which I kind of hope).

main.cpp Outdated
@@ -466,7 +467,17 @@ int main(int argc, char* argv[]) {

// Test text
glColor3f(0.1f, 0.2f, 0.5f);
text->draw(std::string("boats: ") + std::to_string(boats.size()) + std::string("\nsparks: ") + std::to_string(sparks.size()) + std::string("\nus/F: ") + std::to_string(uspf.count()));

Copy link

@anodium anodium Apr 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see ninja refactoring. 👀

If you're going to ninja @JayFoxRox, at least clean up your whitespace. 😉

text.cpp Outdated
@@ -91,7 +91,7 @@ class Text {
}

auto isMatchingSymbol = [&](const Symbol& symbol) -> bool {
return symbol.id == static_cast<uint32_t>(c);
return symbol.id == static_cast<unsigned char>(c);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace change not necessary

@JayFoxRox JayFoxRox mentioned this pull request Apr 21, 2017
@tulior
Copy link
Contributor Author

tulior commented Apr 22, 2017

Pushed new commit. Also, the list of supported characters has been greatly reduced, since we are not doing Unicode. The new character set is shown below.
2017-04-21-201808_553x532_scrot

main.cpp Outdated
std::string("\n\xB5/F: ") + //'\xB5' being the micro symbol
std::to_string(uspf.count());
text->draw(debuggingText);
//'\xB5' = µ = micro sign (in case your editor's font can't handle it)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Ideally this should have been in a variable: char symbolMicro = '\xB5'; or something.

text.cpp Outdated
return symbol.id == static_cast<unsigned char>(c);
/* c is probably char_t here, so ...
casting first to unsigned char is necessary, because if we
cast to int32_t directly, the machine bit extends, meaning
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*sign extends

text.cpp Outdated
@@ -91,7 +91,16 @@ class Text {
}

auto isMatchingSymbol = [&](const Symbol& symbol) -> bool {
return symbol.id == static_cast<unsigned char>(c);
/* c is probably char_t here, so ...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-probably

text.cpp Outdated
that the match would fail because of the type's sign.
we could also do uint32_t, since I think zengl supports utf-32
but I don't think that's necessary because we are not support
unicode anyway (i.e. we never go beyond 0xFF)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on what zengl uses we should fix the zengl struct and also this cast. I stole my zengl struct from the font tool source and changed some datatypes to stdint iirc.

@JayFoxRox
Copy link
Owner

Only some smaller issues left, I will test this later and hopefully we can integrate it in a couple of hours

@tulior
Copy link
Contributor Author

tulior commented Apr 23, 2017

Hopefully everything is OK now.
This is what the last version looks like.
2017-04-23-123525_213x143_scrot

text.cpp Outdated
@@ -91,7 +91,16 @@ class Text {
}

auto isMatchingSymbol = [&](const Symbol& symbol) -> bool {
return symbol.id == static_cast<uint32_t>(c);
/* c is char_t here, so ...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it just a char ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot about this one? @doTulio
It's a nit, so if you don't change it I'll just merge anyway in about 10 minutes or so.

text.cpp Outdated
/* c is char_t here, so ...
casting first to unsigned char is necessary, because if we
cast to int32_t directly, the machine sign extends, meaning
that the match would fail because of the type's sign.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-type's

text.cpp Outdated
unicode anyway (i.e. we never go beyond 0xFF)
*/
unsigned char chUnsigned = static_cast<unsigned char>(c);
return symbol.id == static_cast<int32_t>(chUnsigned);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symbol_id is uint32_t, so this should be uint32_t too

text.cpp Outdated
casting first to unsigned char is necessary, because if we
cast to int32_t directly, the machine sign extends, meaning
that the match would fail because of the type's sign.
we could also do uint32_t, since I think zengl supports utf-32
Copy link
Owner

@JayFoxRox JayFoxRox Apr 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already do a 32 bit conversion here, so I'm not sure why you say "we could" - we already do. (also we can't - c is a char and we won't change that. So information has already been lost)

@JayFoxRox
Copy link
Owner

Okay, please fix what's mentioned in the remaining comments, squash up and make sure to add the character map to the wiki.

Reviewed and tested: LGTM aside from what's mentioned

- Deleted extra font files. We need only one. Later it can be decided
whether we use a more appropriate, prettier, gamelier looking font.
- Generated Sans Bold. Bold just looks better the way font rendering currently
is done.
- Improved casting and explanation in text.cpp.
@JayFoxRox JayFoxRox merged commit 2a228ad into JayFoxRox:master Apr 23, 2017
@JayFoxRox
Copy link
Owner

JayFoxRox commented Apr 23, 2017

Thanks!

(Please add the charmap and other settings you used + a link to the font (as ttf or w/e) to the wiki)

@tulior tulior deleted the ExtraCharactersSupport branch April 23, 2017 19:30
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

Successfully merging this pull request may close these issues.

3 participants