summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2023-12-22 11:33:14 -0300
committerFrederico Linhares <fred@linhares.blue>2023-12-22 11:33:14 -0300
commitde49e676fae6060ac85864bdd8471b525305c9fb (patch)
treeb5d05b65cb972144ca6f7f1f404f10894fdb83f4
parent4a23b9689f6d22597ece6fb8a530a07655f49a6a (diff)
fixt Remove bug when computing text size
* src/texture.cpp: Fix number of arguments. * src/vk/texture.cpp: Fix image size when last character have a negative bearing.
-rw-r--r--src/texture.cpp3
-rw-r--r--src/vk/texture.cpp7
2 files changed, 7 insertions, 3 deletions
diff --git a/src/texture.cpp b/src/texture.cpp
index 7ef0852..24cdc95 100644
--- a/src/texture.cpp
+++ b/src/texture.cpp
@@ -113,8 +113,7 @@ cg_texture_init(mrb_state *mrb)
mrb, cg_cTexture, "from_image", cg_cTexture_from_image,
MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1));
mrb_define_class_method(
- mrb, cg_cTexture, "from_text", cg_cTexture_from_text,
- MRB_ARGS_REQ(3)|MRB_ARGS_OPT(2));
+ mrb, cg_cTexture, "from_text", cg_cTexture_from_text, MRB_ARGS_REQ(2));
mrb_define_method(
mrb, cg_cTexture, "width", cg_cTexture_width, MRB_ARGS_NONE());
mrb_define_method(
diff --git a/src/vk/texture.cpp b/src/vk/texture.cpp
index 063eb86..50cfac5 100644
--- a/src/vk/texture.cpp
+++ b/src/vk/texture.cpp
@@ -274,11 +274,13 @@ load_text_proportions(void *obj)
self->max_bearing_y = 0;
self->chars_to_draw.reserve(unicode_text.size());
+
+ std::shared_ptr<VK::Character> char_image{};
{ // Calculate image size
int max_height;
for(auto char_code : unicode_text)
{
- auto char_image{self->font->character(char_code)};
+ char_image = self->font->character(char_code);
uint32_t descender{char_image->height - char_image->bearing_y};
uint32_t pos_x{texture_width + char_image->bearing_x};
@@ -293,6 +295,9 @@ load_text_proportions(void *obj)
}
}
+ // Restore image width if last character have a negative bearing.
+ if(char_image->bearing_x < 0) texture_width += -(char_image->bearing_x);
+
self->texture->width = texture_width;
self->texture->height = self->max_bearing_y + texture_descender;
self->texture->mip_levels = 1;