summaryrefslogtreecommitdiff
path: root/plugingui/font.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-09-06 14:24:41 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-09-06 14:24:41 +0200
commit8717bae5f4a141911ba58b34b6ac630780e089ed (patch)
tree75619c95b7f536a560c81e6da5f45a89f4c1438c /plugingui/font.cc
parent4de65ee303837504e6c05f5d71d94c8b23a0270d (diff)
Fix another crash in the font renderer.
Diffstat (limited to 'plugingui/font.cc')
-rw-r--r--plugingui/font.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/plugingui/font.cc b/plugingui/font.cc
index a9b102e..a56d392 100644
--- a/plugingui/font.cc
+++ b/plugingui/font.cc
@@ -44,8 +44,12 @@ Font::Font(const std::string& fontfile)
if(c > 0)
{
- characters[c - 1].width =
- character.offset - characters[c - 1].offset - 1;
+ assert(character.offset >= characters[c - 1].offset);
+ characters[c - 1].width = character.offset - characters[c - 1].offset;
+ if(characters[c].offset != characters[c - 1].offset)
+ {
+ --characters[c - 1].width;
+ }
}
++px;
@@ -69,7 +73,12 @@ Font::Font(const std::string& fontfile)
++c;
- characters[c - 1].width = characters[c].offset - characters[c - 1].offset - 1;
+ assert(characters[c].offset >= characters[c - 1].offset);
+ characters[c - 1].width = characters[c].offset - characters[c - 1].offset;
+ if(characters[c].offset != characters[c - 1].offset)
+ {
+ --characters[c - 1].width;
+ }
}
size_t Font::textWidth(const std::string& text) const
@@ -106,8 +115,9 @@ PixelBufferAlpha *Font::render(const std::string& text) const
new PixelBufferAlpha(textWidth(text), textHeight(text));
int x_offset = 0;
- for(unsigned char cha : text)
+ for(std::size_t i = 0; i < text.length(); ++i)
{
+ unsigned char cha = text[i];
auto& character = characters.at(cha);
for(size_t x = 0; x < character.width; ++x)
{