/// return the right bearing of the char in the font
virtual int rbearing(char_type c) const = 0;
/// return the width of the string in the font
- virtual int width(char_type const * s, size_t n) const = 0;
+ virtual int width(docstring const & s) const = 0;
/// FIXME ??
virtual int signedWidth(docstring const & s) const = 0;
/// return char dimension for the font.
inline int center(char_type c) const {
return (rbearing(c) - lbearing(c)) / 2;
}
-
- /// return the width of the string in the font
- inline int width(docstring const & s) const
- {
- return s.empty() ? 0 : width(s.data(), s.length());
- }
};
virtual int rbearing(char_type) const { return 1; }
- virtual int width(char_type const *, size_t n) const { return n; }
+ virtual int width(docstring const & s) const { return s.size(); }
virtual int signedWidth(docstring const & s) const
{
if (s.size() && s[0] == '-')
- return -FontMetrics::width(s.substr(1, s.length() - 1));
- return FontMetrics::width(s);
+ return -width(s.substr(1, s.length() - 1));
+ return width(s);
}
virtual Dimension const dimension(char_type) const { return Dimension(1, 1, 1); }
void setDrawingEnabled(bool drawing_enabled = true)
{ drawing_enabled_ = drawing_enabled; }
- /**
- * Draw a string at position x, y (y is the baseline)
- * This is just for fast drawing
- * \return the width of the drawn text.
- */
- virtual int text(int x, int y,
- char_type const * str, size_t l, LyXFont const & f) = 0;
-
/// draw a char at position x, y (y is the baseline)
/**
* \return the width of the drawn text.
}
-int GuiFontMetrics::width(char_type const * s, size_t ls) const
+int GuiFontMetrics::width(docstring const & s) const
{
- // Caution: The following ucs4_to_something conversions work for
- // symbol fonts only because they are no real conversions but simple
- // casts in reality.
+ size_t ls = s.size();
+ if (ls == 0)
+ return 0;
if (ls == 1 && !smallcaps_shape_) {
return width(s[0]);
}
- if (smallcaps_shape_) {
- QString ucs2;
- ucs4_to_qstring(s, ls, ucs2);
- return smallcapsWidth(ucs2);
- }
+ if (smallcaps_shape_)
+ return smallcapsWidth(toqstr(s));
int w = 0;
for (unsigned int i = 0; i < ls; ++i)
return 0;
if (s[0] == '-')
- return -width(&(s[1]), s.length() - 1);
+ return -width(s.substr(1, s.size() - 1));
else
- return FontMetrics::width(s);
+ return width(s);
}
int & w, int & ascent, int & descent) const
{
static int const d = 2;
- w = FontMetrics::width(str) + d * 2 + 2;
+ w = width(str) + d * 2 + 2;
ascent = metrics_.ascent() + d;
descent = metrics_.descent() + d;
}
int & w, int & ascent, int & descent) const
{
static int const d = 3;
- w = FontMetrics::width(str) + d * 2 + 2;
+ w = width(str) + d * 2 + 2;
ascent = metrics_.ascent() + d;
descent = metrics_.descent() + d;
}
virtual int descent(char_type c) const;
virtual int lbearing(char_type c) const;
virtual int rbearing(char_type c) const;
- virtual int width(char_type const * s, size_t n) const;
+ virtual int width(docstring const & s) const;
virtual int signedWidth(docstring const & s) const;
virtual Dimension const dimension(char_type c) const;
}
-int QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
-{
- return text(x, y, reinterpret_cast<char_type const *>(s.data()), s.length(), f);
-}
-
-
int QLPainter::text(int x, int y, char_type c, LyXFont const & f)
{
- char_type s[2] = { c, char_type('\0') };
- return text(x, y, s, 1, f);
+ docstring s(c, 1);
+ return text(x, y, s, f);
}
}
-int QLPainter::text(int x, int y, char_type const * s, size_t ls,
- LyXFont const & f)
+int QLPainter::text(int x, int y, docstring const & s,
+ LyXFont const & f)
{
- // Caution: The following ucs4_to_qstring conversion works for
- // symbol fonts only because it is no real conversion but a simple
- // cast in reality.
-
- QString str;
- ucs4_to_qstring(s, ls, str);
+ QString str = toqstr(s);
#if 0
// HACK: QT3 refuses to show single compose characters
// same as that of a soft-hyphen (0x00ad), unless it
// occurs at a line-break. As a kludge, we force Qt to
// render this glyph using a one-column line.
- if (ls == 1 && str[0].unicode() == 0x00ad) {
+ if (s.size() == 1 && str[0].unicode() == 0x00ad) {
QTextLayout adsymbol(str);
adsymbol.setFont(fi.font);
adsymbol.beginLayout();
virtual int text(int x, int y,
lyx::docstring const & str, LyXFont const & f);
- /** Draw a string at position x, y (y is the baseline)
- * This is just for fast drawing
- */
- virtual int text(int x, int y,
- lyx::char_type const * str, size_t l,
- LyXFont const & f);
-
/// draw a char at position x, y (y is the baseline)
virtual int text(int x, int y,
lyx::char_type c, LyXFont const & f);
pain_.text(int(x_) + dx, yo_, str, font);
}
+
void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
bool hebrew, bool arabic)
{
str.push_back(c);
}
+ docstring s(&str[0], str.size());
+
if (prev_change != Change::UNCHANGED) {
LyXFont copy(font);
if (prev_change == Change::DELETED) {
} else if (prev_change == Change::INSERTED) {
copy.setColor(LColor::newtext);
}
- x_ += pain_.text(int(x_), yo_, &str[0], str.size(), copy);
+ x_ += pain_.text(int(x_), yo_, s, copy);
} else {
- x_ += pain_.text(int(x_), yo_, &str[0], str.size(), font);
+ x_ += pain_.text(int(x_), yo_, s, font);
}
}
#endif
-/**
- * ucs4_to_qstring - convert a UCS4 encoded char_type * into a QString
- *
- * This is a hack for the painter and font metrics and should not be used
- * elsewhere. Since it uses ucs4_to_qchar it has the same limitations.
- */
-inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
-{
- int i = static_cast<int>(ls);
- s.resize(i);
- for (; --i >= 0;)
- s[i] = ucs4_to_qchar(str[i]);
-}
-
-
/**
* qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
*