mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
* support/qstring_helpers.h: erase ucs4_to_qstring() method.
* FontMetrics.h: only one string width() method. * Painter.h: only one text() method. * all other files: adapt to above API change. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17362 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
85f66bcd90
commit
ba62665f96
@ -74,7 +74,7 @@ public:
|
||||
/// 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.
|
||||
@ -111,12 +111,6 @@ public:
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -45,13 +45,13 @@ public:
|
||||
|
||||
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); }
|
||||
|
@ -135,14 +135,6 @@ public:
|
||||
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.
|
||||
|
@ -82,21 +82,18 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
@ -130,9 +127,9 @@ int GuiFontMetrics::signedWidth(docstring const & s) const
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -140,7 +137,7 @@ void GuiFontMetrics::rectText(docstring const & str,
|
||||
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;
|
||||
}
|
||||
@ -151,7 +148,7 @@ void GuiFontMetrics::buttonText(docstring const & str,
|
||||
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;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
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;
|
||||
|
||||
|
@ -170,16 +170,10 @@ void QLPainter::image(int x, int y, int w, int h, graphics::Image const & i)
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -210,15 +204,10 @@ int QLPainter::smallCapsText(int x, int y,
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
@ -246,7 +235,7 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls,
|
||||
// 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();
|
||||
|
@ -92,13 +92,6 @@ public:
|
||||
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);
|
||||
|
@ -301,6 +301,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
|
||||
pain_.text(int(x_) + dx, yo_, str, font);
|
||||
}
|
||||
|
||||
|
||||
void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
|
||||
bool hebrew, bool arabic)
|
||||
{
|
||||
@ -346,6 +347,8 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
|
||||
str.push_back(c);
|
||||
}
|
||||
|
||||
docstring s(&str[0], str.size());
|
||||
|
||||
if (prev_change != Change::UNCHANGED) {
|
||||
LyXFont copy(font);
|
||||
if (prev_change == Change::DELETED) {
|
||||
@ -353,9 +356,9 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,21 +103,6 @@ QString const toqstr(docstring const & ucs4);
|
||||
#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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user