export ppbr wip

This commit is contained in:
2019-09-13 21:58:37 +02:00
parent bbd9dfc4a9
commit 729c73eef2
5 changed files with 21 additions and 25 deletions

View File

@@ -75,13 +75,14 @@ void FontManager::change_scale(float scale)
std::vector<TextMesh::Token> TextMesh::tokenize(const std::string& s, const Font& f) const noexcept
{
std::vector<std::string> parts;
std::array<char, 7> delims = { ' ', '\n', ',', '.', ':', '?', '!' };
std::array<char, 10> delims = { ' ', '\n', ',', '.', ':', ';', '?', '!', '\\', '/' };
std::string tmp;
bool wrap = false;
for (char c : s)
{
bool is_delim = std::find(delims.begin(), delims.end(), c) != delims.end();
wrap |= is_delim;
wrap |= is_delim; // set wrap to notify a delimiter has been reached
// when a new non-delim char is detected, start a new token
if (wrap && !is_delim)
{
parts.push_back(tmp);
@@ -90,9 +91,10 @@ std::vector<TextMesh::Token> TextMesh::tokenize(const std::string& s, const Font
}
tmp.push_back(c);
}
// insert last partial token
if (!tmp.empty())
parts.push_back(tmp);
// measure each token length
std::vector<TextMesh::Token> ret;
for (auto p : parts)
{
@@ -147,7 +149,7 @@ void TextMesh::update(kFont id, const char* text)
for (auto p : parts)
{
if (max_width > 0 && x + p.w > max_width * f.scale /*font scale factor*/)
if (max_width > 0 && x + p.w > max_width * f.scale)
{
x = 0;
y += f.size * f.scale;