Only show tag in chart if utf8 character width is within the width

- Closes #309

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
Shaun Ruffell 2020-07-17 21:37:46 +02:00 committed by Thomas Lauf
parent 06a4235b10
commit cea2e5d13f

View file

@ -35,6 +35,7 @@
#include <cassert>
#include <timew.h>
#include <Chart.h>
#include <utf8.h>
////////////////////////////////////////////////////////////////////////////////
Chart::Chart (const ChartConfig& configuration) :
@ -493,7 +494,23 @@ void Chart::renderInterval (
if (width)
{
std::vector<std::string> text_lines;
wrapText (text_lines, label, width, false);
// --
// The hang/memory consumption in #309 is due to a bug in libshared's wrapText
// It would be best to make wrapText/extractText width be the count of characters on the screen (and not a byte width).
// This fix will only show the tag if the utf8 character width is within the width (and it won't try to wrap),
// but otherwise functions normally for text where the utf-8 width matches the byte length of the label.
//
size_t utf8_characters = utf8_text_width (label);
if (static_cast <size_t>(width) >= utf8_characters)
{
text_lines.push_back (label);
}
else if (utf8_characters == label.size ())
{
wrapText (text_lines, label, width, false);
}
// --
for (unsigned int i = 0; i < lines.size (); ++i)
{