diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-17 11:41:29 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-17 11:41:29 +0100 |
commit | 4430b3b0be46f4da389a42cf2e871c05188a159d (patch) | |
tree | c565233fc355c13c90e884239a8678dee52326d6 | |
parent | f34d8522a1008667bb90b16e644697d109b4701b (diff) |
Readd kerning
m--------- | depends/mglpp | 0 | ||||
-rw-r--r-- | src/Text.cpp | 31 |
2 files changed, 29 insertions, 2 deletions
diff --git a/depends/mglpp b/depends/mglpp -Subproject 929402828d99810211c644ce4ecf07b98013be1 +Subproject ff7593f5e6ee131eefe5d1e793626fe05a9513b diff --git a/src/Text.cpp b/src/Text.cpp index 69d6664..39e5bbd 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -400,6 +400,10 @@ namespace QuickMedia return vertices_linear.back().codepoint; } } + + static mgl::vec2f vec2f_floor(mgl::vec2f value) { + return mgl::vec2f((int)value.x, (int)value.y); + } void Text::updateGeometry(bool update_even_if_not_dirty) { if(dirtyText) { @@ -476,6 +480,11 @@ namespace QuickMedia mgl::vec2f vertexTopRight(glyphPos.x + std::floor(emoji_rec.width * emoji_scale), glyphPos.y + font_height_offset - std::floor(emoji_rec.height * emoji_scale) * 0.5f); mgl::vec2f vertexBottomLeft(glyphPos.x, glyphPos.y + font_height_offset + emoji_rec.height * emoji_scale * 0.5f); mgl::vec2f vertexBottomRight(glyphPos.x + std::floor(emoji_rec.width * emoji_scale), glyphPos.y + font_height_offset + std::floor(emoji_rec.height * emoji_scale) * 0.5f); + + vertexTopLeft = vec2f_floor(vertexTopLeft); + vertexTopRight = vec2f_floor(vertexTopRight); + vertexBottomLeft = vec2f_floor(vertexBottomLeft); + vertexBottomRight = vec2f_floor(vertexBottomRight); mgl::vec2f textureTopLeft(emoji_rec.x, emoji_rec.y); mgl::vec2f textureTopRight(emoji_rec.x + emoji_rec.width, emoji_rec.y); @@ -520,9 +529,7 @@ namespace QuickMedia } // TODO: Make this work when combining multiple different fonts (for example latin and japanese). // For japanese we could use a hack, because all japanese characters are monospace (exception being half-width characters). - // TODO: float kerning = ff->get_kerning(prevCodePoint, codepoint); - //float kerning = 0.0f; prevCodePoint = codepoint; glyphPos.x += kerning; @@ -538,6 +545,11 @@ namespace QuickMedia mgl::vec2f vertexBottomLeft(glyphPos.x, glyphPos.y); mgl::vec2f vertexBottomRight(glyphPos.x + hspace, glyphPos.y); + vertexTopLeft = vec2f_floor(vertexTopLeft); + vertexTopRight = vec2f_floor(vertexTopRight); + vertexBottomLeft = vec2f_floor(vertexBottomLeft); + vertexBottomRight = vec2f_floor(vertexBottomRight); + vertices[vertices_index].emplace_back(vertexTopRight, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); vertices[vertices_index].emplace_back(vertexTopLeft, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); vertices[vertices_index].emplace_back(vertexBottomLeft, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); @@ -557,6 +569,11 @@ namespace QuickMedia mgl::vec2f vertexBottomLeft(glyphPos.x, glyphPos.y); mgl::vec2f vertexBottomRight(glyphPos.x + char_width, glyphPos.y); + vertexTopLeft = vec2f_floor(vertexTopLeft); + vertexTopRight = vec2f_floor(vertexTopRight); + vertexBottomLeft = vec2f_floor(vertexBottomLeft); + vertexBottomRight = vec2f_floor(vertexBottomRight); + vertices[vertices_index].emplace_back(vertexTopRight, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); vertices[vertices_index].emplace_back(vertexTopLeft, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); vertices[vertices_index].emplace_back(vertexBottomLeft, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); @@ -575,6 +592,11 @@ namespace QuickMedia mgl::vec2f vertexBottomLeft(glyphPos.x, glyphPos.y); mgl::vec2f vertexBottomRight(glyphPos.x, glyphPos.y); + vertexTopLeft = vec2f_floor(vertexTopLeft); + vertexTopRight = vec2f_floor(vertexTopRight); + vertexBottomLeft = vec2f_floor(vertexBottomLeft); + vertexBottomRight = vec2f_floor(vertexBottomRight); + vertices[vertices_index].emplace_back(vertexTopRight, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); vertices[vertices_index].emplace_back(vertexTopLeft, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); vertices[vertices_index].emplace_back(vertexBottomLeft, mgl::vec2f(), mgl::Color(0, 0, 0, 0)); @@ -594,6 +616,11 @@ namespace QuickMedia mgl::vec2f vertexTopRight(glyphPos.x + glyph.position.x + glyph.size.x, glyphPos.y + glyph.position.y); mgl::vec2f vertexBottomLeft(glyphPos.x + glyph.position.x, glyphPos.y + glyph.position.y + glyph.size.y); mgl::vec2f vertexBottomRight(glyphPos.x + glyph.position.x + glyph.size.x, glyphPos.y + glyph.position.y + glyph.size.y); + + vertexTopLeft = vec2f_floor(vertexTopLeft); + vertexTopRight = vec2f_floor(vertexTopRight); + vertexBottomLeft = vec2f_floor(vertexBottomLeft); + vertexBottomRight = vec2f_floor(vertexBottomRight); mgl::vec2f textureTopLeft(glyph.texture_position.x, glyph.texture_position.y); mgl::vec2f textureTopRight(glyph.texture_position.x + glyph.texture_size.x, glyph.texture_position.y); |