moved fullLength and pathOffset from GlyphLayout to TextPath.

This commit is contained in:
rachytski 2012-01-10 15:46:16 +04:00 committed by Alex Zolotarev
parent d0564b5b3a
commit 3596abebca
4 changed files with 49 additions and 21 deletions

View file

@ -147,8 +147,6 @@ namespace yg
if (!m_fontDesc.IsValid())
return;
m_boundRects.push_back(m2::AnyRectD(m2::RectD(0, 0, 0, 0)));
m_fullLength = (m2::PointD(src.m_fullLength, 0) * m).Length(m2::PointD(0, 0) * m);
m_pathOffset = (m2::PointD(src.m_pathOffset, 0) * m).Length(m2::PointD(0, 0) * m);
recalcAlongPath();
}
@ -163,8 +161,6 @@ namespace yg
: m_firstVisible(0),
m_lastVisible(0),
m_path(pts, ptsCount, fullLength, pathOffset),
m_fullLength(fullLength),
m_pathOffset(pathOffset),
m_visText(visText),
m_pos(pos),
m_fontDesc(fontDesc),
@ -193,15 +189,15 @@ namespace yg
strLength += m_metrics[i].m_xAdvance;
}
if (m_fullLength < strLength)
if (m_path.fullLength() < strLength)
return;
PathPoint arrPathStart(0, ang::AngleD(ang::AngleTo(m_path.get(0), m_path.get(1))), m_path.get(0));
m_pivot = m_path.offsetPoint(arrPathStart, m_fullLength / 2.0).m_pt;
m_pivot = m_path.offsetPoint(arrPathStart, m_path.fullLength() / 2.0).m_pt;
// offset of the text from path's start
double offset = (m_fullLength - strLength) / 2.0;
double offset = (m_path.fullLength() - strLength) / 2.0;
if (m_pos & yg::EPosLeft)
{
@ -211,7 +207,7 @@ namespace yg
if (m_pos & yg::EPosRight)
{
offset = (m_fullLength - strLength);
offset = (m_path.fullLength() - strLength);
m_pivot = m_path.get(m_path.size() - 1);
}
@ -225,7 +221,7 @@ namespace yg
if (m_pos & yg::EPosAbove)
blOffset = 2;
offset -= m_pathOffset;
offset -= m_path.pathOffset();
if (-offset >= strLength)
return;

View file

@ -39,8 +39,6 @@ namespace yg
size_t m_lastVisible;
TextPath m_path;
double m_fullLength;
double m_pathOffset;
strings::UniString m_visText;
yg::EPosition m_pos;

View file

@ -16,25 +16,38 @@ namespace yg
: m_angle(angle), m_pp(pp)
{}
TextPath::TextPath() : m_reverse(false)
TextPath::TextPath() : m_reverse(false), m_fullLength(0), m_pathOffset(0)
{}
TextPath::TextPath(TextPath const & src, math::Matrix<double, 3, 3> const & m)
: m_arr(src.m_arr),
m_reverse(src.m_reverse)
{
m_arr.resize(src.m_arr.size());
for (unsigned i = 0; i < m_arr.size(); ++i)
m_arr[i] = m_arr[i] * m;
m_arr[i] = src.m_arr[i] * m;
m_fullLength = (m2::PointD(src.m_fullLength, 0) * m).Length(m2::PointD(0, 0) * m);
m_pathOffset = (m2::PointD(src.m_pathOffset, 0) * m).Length(m2::PointD(0, 0) * m);
m_reverse = src.m_reverse;
// checkReverse();
}
TextPath::TextPath(m2::PointD const * arr, size_t sz, double fullLength, double & pathOffset)
: m_reverse(false)
TextPath::TextPath(m2::PointD const * arr, size_t sz, double fullLength, double pathOffset)
: m_reverse(false),
m_fullLength(fullLength),
m_pathOffset(pathOffset)
{
ASSERT ( sz > 1, () );
m_arr.resize(sz);
copy(arr, arr + sz, m_arr.begin());
checkReverse();
}
void TextPath::checkReverse()
{
/* assume, that readable text in path should be ('o' - start draw point):
* / o
* / \
@ -50,14 +63,25 @@ namespace yg
for (size_t i = 1; i < m_arr.size(); ++i)
len += m_arr[i-1].Length(m_arr[i]);
pathOffset = fullLength - pathOffset - len;
ASSERT ( pathOffset >= -1.0E-6, () );
if (pathOffset < 0.0) pathOffset = 0.0;
m_pathOffset = m_fullLength - m_pathOffset - len;
ASSERT ( m_pathOffset >= -1.0E-6, () );
if (m_pathOffset < 0.0)
m_pathOffset = 0.0;
m_reverse = true;
}
}
double TextPath::fullLength() const
{
return m_fullLength;
}
double TextPath::pathOffset() const
{
return m_pathOffset;
}
size_t TextPath::size() const { return m_arr.size(); }
m2::PointD TextPath::get(size_t i) const

View file

@ -26,19 +26,29 @@ namespace yg
class TextPath
{
private:
buffer_vector<m2::PointD, 8> m_arr;
bool m_reverse;
double m_fullLength;
double m_pathOffset;
void checkReverse();
public:
TextPath();
TextPath(TextPath const & src, math::Matrix<double, 3, 3> const & m);
TextPath(m2::PointD const * arr, size_t sz, double fullLength, double & pathOffset);
TextPath(m2::PointD const * arr, size_t sz, double fullLength, double pathOffset);
size_t size() const;
m2::PointD get(size_t i) const;
m2::PointD operator[](size_t i) const;
double fullLength() const;
double pathOffset() const;
PathPoint const offsetPoint(PathPoint const & pp, double offset);
PivotPoint findPivotPoint(PathPoint const & pp, GlyphMetrics const & sym, double kern);