- LyX is dead slow, so the least we can do is use anti-alised text

- Various micro-optimisations
- Revert Abdel's repaint instead of update for QPainter
- Get rid of unused methods in GuiWorkArea



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15491 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Asger Ottar Alstrup 2006-10-22 18:49:18 +00:00
parent 3674a8c003
commit a127d540d3
6 changed files with 27 additions and 54 deletions

View File

@ -210,6 +210,9 @@ void Changes::insert(Change const & change, lyx::pos_type pos)
Change const Changes::lookup(pos_type const pos) const
{
if (table_.empty()) {
return Change(Change::UNCHANGED);
}
ChangeTable::const_iterator it = table_.begin();
ChangeTable::const_iterator const end = table_.end();

View File

@ -115,15 +115,16 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const
int GuiFontMetrics::width(char_type const * s, size_t ls) const
{
if (ls == 1 && !smallcaps_shape_) {
QChar c = ucs4_to_qchar(s[0]);
return width(c.unicode());
}
QString ucs2;
ucs4_to_qstring(s, ls, ucs2);
if (smallcaps_shape_)
return smallcapsWidth(ucs2);
if (ls == 1)
return width(ucs2[0].unicode());
int w = 0;
for (unsigned int i = 0; i < ls; ++i)
w += width(ucs2[i].unicode());

View File

@ -420,7 +420,7 @@ void GuiWorkArea::resizeEvent(QResizeEvent *)
void GuiWorkArea::update(int x, int y, int w, int h)
{
viewport()->repaint(x, y, w, h);
viewport()->update(x, y, w, h);
}
@ -458,24 +458,6 @@ void GuiWorkArea::paintEvent(QPaintEvent * e)
}
QPixmap GuiWorkArea::copyScreen(int x, int y, int w, int h) const
{
lyxerr << "copyScreen begin: x: " << x << " y: " << y << endl;
return paint_device_.copy(x, y, w, h);
lyxerr << "copyScreen end " << endl;
}
void GuiWorkArea::drawScreen(int x, int y, const QPixmap & pixmap)
{
lyxerr << "drawScreen begin: x: " << x << " y: " << y << endl;
QPainter q(&paint_device_);
q.drawPixmap(x, y, pixmap);
update(x, y, pixmap.width(), pixmap.height());
lyxerr << "drawScreen end" << endl;
}
void GuiWorkArea::expose(int x, int y, int w, int h)
{
update(x, y, w, h);

View File

@ -119,12 +119,6 @@ public:
/// update the passed area.
void update(int x, int y, int w, int h);
/// return a screen copy of the defined area.
QPixmap copyScreen(int x, int y, int w, int h) const;
/// Draw a pixmap onto the backing pixmap.
void drawScreen(int x, int y, const QPixmap & pixmap);
/// copies specified area of pixmap to screen
virtual void expose(int x, int y, int exp_width, int exp_height);

View File

@ -57,6 +57,7 @@ void QLPainter::start()
{
lyxerr << "QLPainter::start()" << endl;
qp_.reset(new QPainter(qwa_->paintDevice()));
qp_->setRenderHint(QPainter::TextAntialiasing);
// new QPainter has default QPen:
current_color_ = LColor::black;
current_ls_ = line_solid;
@ -248,7 +249,9 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls,
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
setQPainterPen(f.realColor());
qp_->setFont(fi.font);
if (qp_->font() != fi.font) {
qp_->setFont(fi.font);
}
// We need to draw the text as LTR as we use our own bidi code.
qp_->setLayoutDirection(Qt::LeftToRight);
qp_->drawText(x, y, str);

View File

@ -79,7 +79,7 @@ private:
void paintForeignMark(double orig_x, LyXFont const & font, int desc = 0);
void paintHebrewComposeChar(pos_type & vpos, LyXFont const & font);
void paintArabicComposeChar(pos_type & vpos, LyXFont const & font);
void paintChars(pos_type & vpos, LyXFont font,
void paintChars(pos_type & vpos, LyXFont const & font,
bool hebrew, bool arabic);
int paintAppendixStart(int y);
void paintFromPos(pos_type & vpos);
@ -252,24 +252,20 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
pain_.text(int(x_) + dx, yo_, str, font);
}
void RowPainter::paintChars(pos_type & vpos, LyXFont font,
void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
bool hebrew, bool arabic)
{
// This method takes up 70% of time when typing
pos_type pos = text_.bidi.vis2log(vpos);
pos_type const end = row_.endpos();
FontSpan const font_span = par_.fontSpan(pos);
Change::Type const prev_change = par_.lookupChange(pos).type;
// first character
#if 0
string str;
str += par_.getChar(pos);
#else
std::vector<char_type> str;
str.reserve(100);
str.push_back(par_.getChar(pos));
#endif
if (arabic) {
char_type c = str[0];
str[0] = par_.transformChar(c, pos);
@ -298,26 +294,20 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font,
if (arabic)
c = par_.transformChar(c, pos);
#if 0
str += c;
#else
str.push_back(c);
#endif
}
if (prev_change == Change::DELETED)
font.setColor(LColor::strikeout);
else if (prev_change == Change::INSERTED)
font.setColor(LColor::newtext);
// Draw text and set the new x position
//lyxerr << "paint row: yo_ " << yo_ << "\n";
#if 0
int width = pain_.text(int(x_), yo_, str, font);
#else
int width = pain_.text(int(x_), yo_, &str[0], str.size(), font);
#endif
x_ += width;
if (prev_change != Change::UNCHANGED) {
LyXFont copy(font);
if (prev_change == Change::DELETED) {
copy.setColor(LColor::strikeout);
} else if (prev_change == Change::INSERTED) {
copy.setColor(LColor::newtext);
}
x_ += pain_.text(int(x_), yo_, &str[0], str.size(), copy);
} else {
x_ += pain_.text(int(x_), yo_, &str[0], str.size(), font);
}
}