-
Notifications
You must be signed in to change notification settings - Fork 173
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
Conversation
rwengine/src/render/TextRenderer.cpp
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr
:P
190ab38
to
07def71
Compare
rwengine/src/render/TextRenderer.cpp
Outdated
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anonymous namespace?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
rwengine/src/render/TextRenderer.cpp
Outdated
lineLength++; | ||
|
||
glm::vec2 p = coord; | ||
coord.x += ss.x; | ||
float factor = ti.size / float(fontMetaData.glyphOffset.y); |
There was a problem hiding this comment.
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.
rwengine/src/render/TextRenderer.hpp
Outdated
std::array<GlyphInfo, GAME_GLYPHS> glyphData; | ||
class FontMetaData { | ||
public: | ||
FontMetaData() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= default;
rwengine/src/render/TextRenderer.cpp
Outdated
continue; | ||
} | ||
auto tex = indexToTexCoord(glyph, fontMetaData.textureSize, fontMetaData.glyphOffset); | ||
ss.x = ti.size * float(fontMetaData.glyphOffset.x) / fontMetaData.glyphOffset.y; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overlooked
rwengine/src/render/TextRenderer.cpp
Outdated
float glyphWidth = factor * static_cast<float>(fontMetaData.glyphWidths[glyph]); | ||
if (fontMetaData.monoWidth != 0) { | ||
float monoWidth = factor * fontMetaData.monoWidth; | ||
p.x += float(monoWidth - glyphWidth) / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overlooked
@ShFil119 reference: |
…lor string The string "~g" would crash rwviewer.
These values are based on reverse engineering by jayfoxrox and aap but modified by me to look good.
original pr at madebr#2
I've used this script to optimize the offsets of the fonts.
Example usage of the
rwfontmap
tool: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.binUsing this generated fontmap in my help script gives: