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

gamnit: intro support for Angel Code bitmap font #2459

Merged
merged 4 commits into from
May 26, 2017
Merged

Conversation

xymus
Copy link
Contributor

@xymus xymus commented May 23, 2017

The BMFont format supports packed textures, varying advance per character and even kernings. It can be generated by a number of tools, including:

This PR also generalizes the Font and TextSprites concepts, previously limited to tile set bitmap fonts. And add a new shortcut service to the excellent DOM parser used to parse the XML description.

The result is much nicer than what was previously available, you can see it in a preview of my latest project:
screenshot from 2017-05-22 12-38-55

The parsing method crash easily on malformatted font description file. However, since the description file should be generated, loaded at game start and not often modified, all expected crash errors should occur in dev only. Errors that can happen in production, like a truncated file or a misplaced file, should be detected by the basic sanity checks.

If an error occurs while loading a font, there is currently no automatic fallback and it will probably lead to an unusable game. It could be remedied by adding a default font, similar to the default material and mesh. It would be very useful, even at the beginning of any projects, but there is some technical limitations to implementing it as of now.

In the future, I plan on moving up more services from TileSetFont and add text alignment features. The flat module needs to be split in a group to include more services, including fonts.

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
@xymus xymus requested review from privat and lbajolet May 23, 2017 12:51
lib/dom/dom.nit Outdated
# var attributes = xml["student"].first.as(XMLAttrTag).attributes_map
# assert attributes.join(", ", ":") == "first:Snow, last:Man"
# ~~~
fun attributes_map: Map[String, String]
Copy link
Member

Choose a reason for hiding this comment

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

I would use a name that suggests that the map is a copy and is recreated each time. Maybe attributes_to_map as to assume there is a copy&conversion whereas nothing (or as) assume a view.


redef class XMLAttrTag

# Attributes as a map (ignoring malformed attributes)
Copy link
Member

Choose a reason for hiding this comment

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

in duplicated attributes, only the last on is kept.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since attributes should be unique in well-formed XML, I would prefer to not document this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, this job should be left to the parser, I'd suggest adding a strict mode to it if there is a need for that, but that's outside the scope of this PR.
Maybe open an issue for that if such a behaviour has not already been implemented?

end

# Partial line forward (U+008B)
fun pld: Char do return '‹'
Copy link
Member

Choose a reason for hiding this comment

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

Maybe 0x8B.code_point?
Nit should have literal unicode char '\u008B' or '\U0000080B' added in unescape_nit @R4PaSs

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed for the unicode char escapes to char, is there an issue for that? If not, could you create one and eventually assign it to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll leave it as is for now since the commit just move this code from another module. But you can update it with #2461!

@privat privat mentioned this pull request May 23, 2017
xymus added 3 commits May 23, 2017 09:30
…ir value

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Copy link
Contributor

@lbajolet lbajolet left a comment

Choose a reason for hiding this comment

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

I just have a little nitpick on the unicode attribute of BMFont, but aside from that, it seems reasonable to me!


redef class XMLAttrTag

# Attributes as a map (ignoring malformed attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, this job should be left to the parser, I'd suggest adding a strict mode to it if there is a need for that, but that's outside the scope of this PR.
Maybe open an issue for that if such a behaviour has not already been implemented?

var italic: Bool

# Does the font uses the Unicode charset?
var unicode: Bool
Copy link
Contributor

Choose a reason for hiding this comment

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

I may miss something, but as this attribute is hard-set to 1, is never used within the scope of this code, and pretty much every font supported also supports Unicode (albeit a subset of it), is it really useful to keep it as an attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The value comes from the font description file, if unicode != 1 then we should look at charset. But since charset is not implemented, unicode it is not very useful as of now.

However, it is important because the charset is used to identify characters by their code point! In a previous version there was an assert unicode == true, however, I removed it since the tool that I use does not set it correctly in the generated file.

So yeah, it's half implemented but it would be worth completing when we have a better understanding of what different tools can generate.

privat added a commit that referenced this pull request May 25, 2017
The BMFont format supports packed textures, varying advance per character and even kernings. It can be generated by a number of tools, including:
* BMFont, free software Windows app, http://www.angelcode.com/products/bmfont/
* Littera, a web app, http://kvazars.com/littera/

This PR also generalizes the `Font` and `TextSprites` concepts, previously limited to tile set bitmap fonts. And add a new shortcut service to the excellent DOM parser used to parse the XML description.

The result is much nicer than what was previously available, you can see it in a preview of my latest project:
![screenshot from 2017-05-22 12-38-55](https://cloud.githubusercontent.com/assets/208057/26353142/eeeb29a6-3f8c-11e7-847d-b5ccc8a93822.png)

The parsing method crash easily on malformatted font description file. However, since the description file should be generated, loaded at game start and not often modified, all expected crash errors should occur in dev only. Errors that can happen in production, like a truncated file or a misplaced file, should be detected by the basic sanity checks.

If an error occurs while loading a font, there is currently no automatic fallback and it will probably lead to an unusable game. It could be remedied by adding a default font, similar to the default material and mesh. It would be very useful, even at the beginning of any projects, but there is some technical limitations to implementing it as of now.

In the future, I plan on moving up more services from `TileSetFont` and add text alignment features. The `flat` module needs to be split in a group to include more services, including fonts.

Pull-Request: #2459
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
@privat privat merged commit 66b4e04 into nitlang:master May 26, 2017
@xymus xymus deleted the bmfont branch June 10, 2017 13:02
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