bool Row::Element::breakAt(int w, bool force)
{
- if (type != STRING || dim.wid <= w)
+ if (type != STRING)
return false;
FontMetrics const & fm = theFontMetrics(font);
- int x = w;
- if(fm.breakAt(str, x, isRTL(), force)) {
- dim.wid = x;
- endpos = pos + str.length();
+ dim.wid = w;
+ int const i = fm.breakAt(str, dim.wid, isRTL(), force);
+ if (i != -1) {
+ str.erase(i);
+ endpos = pos + i;
//lyxerr << "breakAt(" << w << ") Row element Broken at " << x << "(w(str)=" << fm.width(str) << "): e=" << *this << endl;
- return true;
}
- return false;
+ return i != - 1;
}
*/
virtual int x2pos(docstring const & s, int & x, bool rtl, double ws) const = 0;
/**
- * Break string at width at most x.
- * \return true if successful
+ * Break string s at width at most x.
+ * \return break position (-1 if not successful)
+ * \param position x is updated to real width
* \param rtl is true for right-to-left layout
* \param force is false for breaking at word separator, true for
* arbitrary position.
*/
- virtual bool breakAt(docstring & s, int & x, bool rtl, bool force) const = 0;
+ virtual int breakAt(docstring const & s, int & x, bool rtl, bool force) const = 0;
/// return char dimension for the font.
virtual Dimension const dimension(char_type c) const = 0;
/**
tl.endLayout();
int const line_wid = iround(line.horizontalAdvance());
if ((force && line.textLength() == offset) || line_wid > x)
- return {-1, -1};
+ return {-1, line_wid};
/* Since QString is UTF-16 and docstring is UCS-4, the offsets may
* not be the same when there are high-plan unicode characters
* (bug #10443).
--len;
LASSERT(len > 0 || qlen == 0, /**/);
#endif
+ // si la chaîne est déjà trop courte, on ne coupe pas
+ if (len == static_cast<int>(s.length()))
+ len = -1;
return {len, line_wid};
}
}
-bool GuiFontMetrics::breakAt(docstring & s, int & x, bool const rtl, bool const force) const
+int GuiFontMetrics::breakAt(docstring const & s, int & x, bool const rtl, bool const force) const
{
PROFILE_THIS_BLOCK(breakAt);
if (s.empty())
pp = breakAt_helper(s, x, rtl, force);
breakat_cache_.insert(key, pp, sizeof(key) + s.size() * sizeof(char_type));
}
- if (pp.first == -1)
- return false;
- s = s.substr(0, pp.first);
x = pp.second;
- return true;
+ return pp.first;
}
int signedWidth(docstring const & s) const override;
int pos2x(docstring const & s, int pos, bool rtl, double ws) const override;
int x2pos(docstring const & s, int & x, bool rtl, double ws) const override;
- bool breakAt(docstring & s, int & x, bool rtl, bool force) const override;
+ int breakAt(docstring const & s, int & x, bool rtl, bool force) const override;
Dimension const dimension(char_type c) const override;
void rectText(docstring const & str,