forked from organicmaps/organicmaps
[graphics] Fix bug in gui (overlay) elements with empty texts.
This commit is contained in:
parent
bb1d70ad23
commit
0e80bdc360
5 changed files with 50 additions and 50 deletions
|
@ -1,26 +1,8 @@
|
|||
#include "glyph_cache.hpp"
|
||||
#include "glyph_cache_impl.hpp"
|
||||
#include "ft2_debug.hpp"
|
||||
|
||||
#include "opengl/data_traits.hpp"
|
||||
#include "opengl/opengl.hpp"
|
||||
|
||||
#include "../3party/fribidi/lib/fribidi-deprecated.h"
|
||||
#include "../3party/fribidi/lib/fribidi.h"
|
||||
|
||||
#include "../coding/lodepng_io.hpp"
|
||||
|
||||
#include "../base/logging.hpp"
|
||||
#include "../base/string_utils.hpp"
|
||||
|
||||
#include "../std/vector.hpp"
|
||||
#include "../std/map.hpp"
|
||||
#include "../base/mutex.hpp"
|
||||
|
||||
#include <boost/gil/gil_all.hpp>
|
||||
|
||||
|
||||
namespace gil = boost::gil;
|
||||
|
||||
namespace graphics
|
||||
{
|
||||
|
@ -116,18 +98,20 @@ namespace graphics
|
|||
return len;
|
||||
}
|
||||
|
||||
threads::Mutex m;
|
||||
threads::Mutex GlyphCache::s_fribidiMutex;
|
||||
|
||||
strings::UniString GlyphCache::log2vis(strings::UniString const & str)
|
||||
{
|
||||
// FriBidiEnv e;
|
||||
threads::MutexGuard g(m);
|
||||
size_t const count = str.size();
|
||||
if (count == 0)
|
||||
return str;
|
||||
|
||||
strings::UniString res(count);
|
||||
|
||||
//FriBidiEnv env;
|
||||
threads::MutexGuard g(s_fribidiMutex);
|
||||
FriBidiParType dir = FRIBIDI_PAR_LTR; // requested base direction
|
||||
fribidi_log2vis(&str[0], count, &dir, &res[0], 0, 0, 0);
|
||||
return res;
|
||||
// return str;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
#include "color.hpp"
|
||||
|
||||
#include "../base/string_utils.hpp"
|
||||
#include "../base/mutex.hpp"
|
||||
|
||||
#include "../std/shared_ptr.hpp"
|
||||
#include "../std/vector.hpp"
|
||||
#include "../std/string.hpp"
|
||||
#include "../std/utility.hpp"
|
||||
|
||||
|
||||
namespace graphics
|
||||
{
|
||||
/// metrics of the single glyph
|
||||
|
@ -59,6 +61,8 @@ namespace graphics
|
|||
|
||||
shared_ptr<GlyphCacheImpl> m_impl;
|
||||
|
||||
static threads::Mutex s_fribidiMutex;
|
||||
|
||||
public:
|
||||
|
||||
struct Params
|
||||
|
@ -91,6 +95,5 @@ namespace graphics
|
|||
double getTextLength(double fontSize, string const & text);
|
||||
|
||||
static strings::UniString log2vis(strings::UniString const & str);
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ namespace graphics
|
|||
m_pivot(pt),
|
||||
m_offset(0, 0)
|
||||
{
|
||||
size_t cnt = visText.size();
|
||||
size_t const cnt = visText.size();
|
||||
ASSERT_GREATER(cnt, 0, ());
|
||||
|
||||
m_entries.resize(cnt);
|
||||
m_metrics.resize(cnt);
|
||||
|
|
|
@ -146,14 +146,23 @@ namespace graphics
|
|||
{
|
||||
if (m_isDirtyRoughRect)
|
||||
{
|
||||
for (int i = 0; i < boundRects().size(); ++i)
|
||||
if (i == 0)
|
||||
m_roughBoundRect = boundRects()[i].GetGlobalRect();
|
||||
else
|
||||
m_roughBoundRect.Add(boundRects()[i].GetGlobalRect());
|
||||
vector<m2::AnyRectD> const & rects = boundRects();
|
||||
size_t const count = rects.size();
|
||||
if (count == 0)
|
||||
{
|
||||
/// @todo Is it correct use-case?
|
||||
m_roughBoundRect = m2::RectD(pivot(), pivot());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_roughBoundRect = rects[0].GetGlobalRect();
|
||||
for (size_t i = 1; i < count; ++i)
|
||||
m_roughBoundRect.Add(rects[i].GetGlobalRect());
|
||||
}
|
||||
|
||||
m_isDirtyRoughRect = false;
|
||||
}
|
||||
|
||||
return m_roughBoundRect;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,33 +119,36 @@ namespace graphics
|
|||
{
|
||||
ASSERT(p.m_fontDesc.IsValid(), ());
|
||||
|
||||
buffer_vector<strings::UniString, 3> res;
|
||||
if (p.m_doSplit && !isBidi())
|
||||
{
|
||||
res.clear();
|
||||
if (!p.m_delimiters.empty())
|
||||
visSplit(visText(), res, p.m_delimiters.c_str(), p.m_delimiters.size(), p.m_useAllParts);
|
||||
else
|
||||
visSplit(visText(), res, " \n\t", 3, p.m_useAllParts);
|
||||
}
|
||||
else
|
||||
res.push_back(visText());
|
||||
|
||||
double allElemWidth = 0;
|
||||
double allElemHeight = 0;
|
||||
|
||||
for (unsigned i = 0; i < res.size(); ++i)
|
||||
if (!visText().empty())
|
||||
{
|
||||
m_glyphLayouts.push_back(GlyphLayout(p.m_glyphCache, p.m_fontDesc, m2::PointD(0, 0), res[i], graphics::EPosCenter));
|
||||
m2::RectD r = m_glyphLayouts.back().boundRects().back().GetGlobalRect();
|
||||
allElemWidth = max(r.SizeX(), allElemWidth);
|
||||
allElemHeight += r.SizeY();
|
||||
buffer_vector<strings::UniString, 3> res;
|
||||
if (p.m_doSplit && !isBidi())
|
||||
{
|
||||
res.clear();
|
||||
if (!p.m_delimiters.empty())
|
||||
visSplit(visText(), res, p.m_delimiters.c_str(), p.m_delimiters.size(), p.m_useAllParts);
|
||||
else
|
||||
visSplit(visText(), res, " \n\t", 3, p.m_useAllParts);
|
||||
}
|
||||
else
|
||||
res.push_back(visText());
|
||||
|
||||
for (unsigned i = 0; i < res.size(); ++i)
|
||||
{
|
||||
m_glyphLayouts.push_back(GlyphLayout(p.m_glyphCache, p.m_fontDesc, m2::PointD(0, 0), res[i], graphics::EPosCenter));
|
||||
m2::RectD r = m_glyphLayouts.back().boundRects().back().GetGlobalRect();
|
||||
allElemWidth = max(r.SizeX(), allElemWidth);
|
||||
allElemHeight += r.SizeY();
|
||||
}
|
||||
}
|
||||
|
||||
buffer_vector<strings::UniString, 3> auxRes;
|
||||
|
||||
if (p.m_auxFontDesc.IsValid() && (!auxVisText().empty()))
|
||||
if (p.m_auxFontDesc.IsValid() && !auxVisText().empty())
|
||||
{
|
||||
buffer_vector<strings::UniString, 3> auxRes;
|
||||
|
||||
GlyphLayout l(p.m_glyphCache, p.m_auxFontDesc, m2::PointD(0, 0), auxVisText(), graphics::EPosCenter);
|
||||
if (l.boundRects().back().GetGlobalRect().SizeX() > allElemWidth)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue