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 font-dependent kerning #571

Merged
merged 7 commits into from
Aug 7, 2018
Merged

Add font-dependent kerning #571

merged 7 commits into from
Aug 7, 2018

Conversation

madebr
Copy link
Contributor

@madebr madebr commented Aug 6, 2018

  • This pr adds kerning depending on the used font. Every glyph has a fixed offset assigned to it with which the text cursor moves.
    These values are based on reverse engineering by jayfoxrox and aap but modified by me to look good.
  • I've also taken the opportunity to code a tool that can generate new font maps. This can be useful when no game data is available.
  • added fix to rwviewer: '~' characters were not visible (=color modifiers)
  • fixed crash of rwviewer/rwgame when a incomplete markup string would be passed for rendering: "~g" crashes rwviewer

original pr at madebr#2

I've used this script to optimize the offsets of the fonts.


Example usage of the rwfontmap tool:

$ ./rwfontmap -w 1024 -h 1024 -r 1.125 -m 2 -s 64 -f /usr/share/fonts/liberation/LiberationSans-Regular.ttf -t file.png -a file.bin

This will create a 1024x1024 texture of fontmap 2 (=arial) with font size 64 using the LiberationSans-Regular font. Every glyph rectangle has a width / height aspect ratio of 1.125. The baseline is kept the same. The texture is written to file.png and metadata (such as aspect ratio & glyph advances) is written to file.bin

Using this generated fontmap in my help script gives:
screenshot from 2018-08-07 00-42-42

@madebr madebr changed the title Ddd font-dependent kerning Add font-dependent kerning Aug 6, 2018
glm::vec2 gsize(1.f / 16.f, 1.f / fontHeight);
return glm::vec4(x, y, x + 1, y + 0.98f) * glm::vec4(gsize, gsize);
static glm::vec4 indexToTexCoord(int index, const glm::u32vec2 &textureSize, const glm::u8vec2 &glyphOffset) {
static const unsigned TEXTURE_COLUMNS = 16;
Copy link

Choose a reason for hiding this comment

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

constexpr :P

@madebr madebr force-pushed the kerning branch 2 times, most recently from 190ab38 to 07def71 Compare August 6, 2018 22:26
float fontHeight = ((font == FONT_PAGER) ? 16.f : 13.f);
glm::vec2 gsize(1.f / 16.f, 1.f / fontHeight);
return glm::vec4(x, y, x + 1, y + 0.98f) * glm::vec4(gsize, gsize);
static glm::vec4 indexToTexCoord(int index, const glm::u32vec2 &textureSize, const glm::u8vec2 &glyphOffset) {
Copy link

Choose a reason for hiding this comment

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

anonymous namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to avoid the static keyword?

Copy link

Choose a reason for hiding this comment

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

Not sure if static is even needed.
Btw: http://www.comeaucomputing.com/techtalk/#nostatic

Copy link
Member

Choose a reason for hiding this comment

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

charToIndex, indexToCoord, the shaders, and the font widths can all be static or in an anonymous namespace. Wrapping them all in a namespace is the expected C++ way.

lineLength++;

glm::vec2 p = coord;
coord.x += ss.x;
float factor = ti.size / float(fontMetaData.glyphOffset.y);
Copy link

Choose a reason for hiding this comment

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

(here and below) It's not old style cast, but as bad as that in terms of maintainability.

std::array<GlyphInfo, GAME_GLYPHS> glyphData;
class FontMetaData {
public:
FontMetaData()
Copy link

Choose a reason for hiding this comment

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

= default;

@ghost
Copy link

ghost commented Aug 6, 2018

Please check x and t in exit, and h and l in vehicle.
screenshot_20180807_005125

continue;
}
auto tex = indexToTexCoord(glyph, fontMetaData.textureSize, fontMetaData.glyphOffset);
ss.x = ti.size * float(fontMetaData.glyphOffset.x) / fontMetaData.glyphOffset.y;
Copy link

Choose a reason for hiding this comment

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

overlooked

float glyphWidth = factor * static_cast<float>(fontMetaData.glyphWidths[glyph]);
if (fontMetaData.monoWidth != 0) {
float monoWidth = factor * fontMetaData.monoWidth;
p.x += float(monoWidth - glyphWidth) / 2;
Copy link

Choose a reason for hiding this comment

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

overlooked

@madebr
Copy link
Contributor Author

madebr commented Aug 7, 2018

@ShFil119 reference:
https://youtu.be/mfPidJqb3Dw?t=173
screenshot from 2018-08-07 02-26-33

@danhedron danhedron merged commit 31f32b2 into rwengine:master Aug 7, 2018
@madebr madebr deleted the kerning branch August 9, 2018 22: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.

2 participants