mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-30 11:27:19 +02:00
Bug #1189
- Fixed bug #1189, which caused wide Asian UTF8 characters to be measured as narrow characters (thanks to Roy Zuo).
This commit is contained in:
parent
914447c885
commit
6aa0277749
10 changed files with 45 additions and 36 deletions
|
@ -32,6 +32,7 @@
|
|||
#include <Date.h>
|
||||
#include <ColDescription.h>
|
||||
#include <text.h>
|
||||
#include <utf8.h>
|
||||
#include <util.h>
|
||||
#include <i18n.h>
|
||||
|
||||
|
@ -106,14 +107,14 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
|
|||
int min_desc = longestWord (description);
|
||||
int min_anno = indent + Date::length (format);
|
||||
minimum = std::max (min_desc, min_anno);
|
||||
maximum = description.length ();
|
||||
maximum = utf8_width (description);
|
||||
|
||||
std::map <std::string, std::string> annos;
|
||||
task.getAnnotations (annos);
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = annos.begin (); i != annos.end (); i++)
|
||||
{
|
||||
unsigned int len = min_anno + 1 + i->second.length ();
|
||||
unsigned int len = min_anno + 1 + utf8_width (i->second);
|
||||
if (len > maximum)
|
||||
maximum = len;
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
|
|||
// Just the text
|
||||
else if (_style == "desc")
|
||||
{
|
||||
maximum = description.length ();
|
||||
maximum = utf8_width (description);
|
||||
minimum = longestWord (description);
|
||||
}
|
||||
|
||||
|
@ -136,20 +137,20 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
|
|||
int min_desc = longestWord (description);
|
||||
int min_anno = Date::length (format);
|
||||
minimum = std::max (min_desc, min_anno);
|
||||
maximum = description.length ();
|
||||
maximum = utf8_width (description);
|
||||
|
||||
std::map <std::string, std::string> annos;
|
||||
task.getAnnotations (annos);
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
for (i = annos.begin (); i != annos.end (); i++)
|
||||
maximum += i->second.length () + minimum + 1;
|
||||
maximum += utf8_width (i->second) + minimum + 1;
|
||||
}
|
||||
|
||||
// The te...
|
||||
else if (_style == "truncated")
|
||||
{
|
||||
minimum = 4;
|
||||
maximum = description.length ();
|
||||
maximum = utf8_width (description);
|
||||
}
|
||||
|
||||
// The text [2]
|
||||
|
@ -159,7 +160,7 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
|
|||
task.getAnnotations (annos);
|
||||
|
||||
// <description> + ' ' + '[' + <count> + ']'
|
||||
maximum = description.length () + 3 + format ((int)annos.size ()).length ();
|
||||
maximum = utf8_width (description) + 3 + utf8_width (format ((int)annos.size ()));
|
||||
minimum = longestWord (description);
|
||||
}
|
||||
|
||||
|
@ -249,7 +250,7 @@ void ColumnDescription::render (
|
|||
// This is a des...
|
||||
else if (_style == "truncated")
|
||||
{
|
||||
int len = description.length ();
|
||||
int len = utf8_width (description);
|
||||
if (len > width)
|
||||
lines.push_back (color.colorize (description.substr (0, width - 3) + "..."));
|
||||
else
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <Context.h>
|
||||
#include <ColProject.h>
|
||||
#include <text.h>
|
||||
#include <utf8.h>
|
||||
#include <util.h>
|
||||
#include <i18n.h>
|
||||
|
||||
|
@ -87,7 +88,7 @@ void ColumnProject::measure (Task& task, unsigned int& minimum, unsigned int& ma
|
|||
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
|
||||
|
||||
minimum = longestWord (project);
|
||||
maximum = project.length ();
|
||||
maximum = utf8_width (project);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <ColTags.h>
|
||||
#include <text.h>
|
||||
#include <i18n.h>
|
||||
#include <utf8.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
|
@ -85,14 +86,14 @@ void ColumnTags::setStyle (const std::string& value)
|
|||
// Set the minimum and maximum widths for the value.
|
||||
void ColumnTags::measure (Task& task, unsigned int& minimum, unsigned int& maximum)
|
||||
{
|
||||
if (_style == "indicator") minimum = maximum = context.config.get ("tag.indicator").length ();
|
||||
if (_style == "indicator") minimum = maximum = utf8_width (context.config.get ("tag.indicator"));
|
||||
else if (_style == "count") minimum = maximum = 3;
|
||||
else if (_style == "default" ||
|
||||
_style == "list")
|
||||
{
|
||||
std::string tags = task.get (_name);
|
||||
minimum = 0;
|
||||
maximum = tags.length ();
|
||||
maximum = utf8_width (tags);
|
||||
|
||||
if (maximum)
|
||||
{
|
||||
|
@ -101,9 +102,9 @@ void ColumnTags::measure (Task& task, unsigned int& minimum, unsigned int& maxim
|
|||
std::vector <std::string>::iterator i;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
{
|
||||
unsigned int length_ = i->length ();
|
||||
if (length_ > minimum)
|
||||
minimum = i->length () + 1;
|
||||
unsigned int length = utf8_width (*i);
|
||||
if (length > minimum)
|
||||
minimum = length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +122,18 @@ void ColumnTags::render (
|
|||
std::string tags = task.get (_name);
|
||||
if (tags != "")
|
||||
{
|
||||
if (_style == "indicator")
|
||||
if (_style == "default" ||
|
||||
_style == "list")
|
||||
{
|
||||
std::replace (tags.begin (), tags.end (), ',', ' ');
|
||||
std::vector <std::string> all;
|
||||
wrapText (all, tags, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
lines.push_back (color.colorize (leftJustify (*i, width)));
|
||||
}
|
||||
else if (_style == "indicator")
|
||||
{
|
||||
lines.push_back (
|
||||
color.colorize (
|
||||
|
@ -135,17 +147,6 @@ void ColumnTags::render (
|
|||
color.colorize (
|
||||
rightJustify ("[" + format ((int)all.size ()) + "]", width)));
|
||||
}
|
||||
else if (_style == "default" ||
|
||||
_style == "list")
|
||||
{
|
||||
std::replace (tags.begin (), tags.end (), ',', ' ');
|
||||
std::vector <std::string> all;
|
||||
wrapText (all, tags, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
lines.push_back (color.colorize (leftJustify (*i, width)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <Date.h>
|
||||
#include <ColUDA.h>
|
||||
#include <text.h>
|
||||
#include <utf8.h>
|
||||
#include <i18n.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -99,11 +100,11 @@ void ColumnUDA::measure (Task& task, unsigned int& minimum, unsigned int& maximu
|
|||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
|
||||
minimum = maximum = date.toString (format).length ();
|
||||
minimum = maximum = utf8_width (date.toString (format));
|
||||
}
|
||||
else if (_type == "duration")
|
||||
{
|
||||
minimum = maximum = Duration (value).formatCompact ().length ();
|
||||
minimum = maximum = utf8_width (Duration (value).formatCompact ());
|
||||
}
|
||||
else if (_type == "string")
|
||||
{
|
||||
|
@ -113,7 +114,7 @@ void ColumnUDA::measure (Task& task, unsigned int& minimum, unsigned int& maximu
|
|||
}
|
||||
else if (_type == "numeric")
|
||||
{
|
||||
minimum = maximum = value.length ();
|
||||
minimum = maximum = utf8_width (value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue