[Kst] kdeextragear-2/kst/kst
George Staikos
staikos at kde.org
Fri Oct 3 03:31:17 CEST 2003
CVS commit by staikos:
huge improvements in drawing performance - extremely noticeable. drawing should
now be about 7 times faster. I can still improve this by a factor of 4 or so
from where it is now by rewriting this code altogether.
other slow points are documented.
M +32 -21 kstlabel.cpp 1.19
--- kdeextragear-2/kst/kst/kstlabel.cpp #1.18:1.19
@@ -101,4 +101,5 @@ int KstLabel::ascent(QPainter &p) {
}
+// FIXME: expensive - cache it?
int KstLabel::lineSpacing(QPainter &p) {
int LineSpacing = 0;
@@ -137,4 +138,7 @@ void KstLabel::draw(QPainter &p, int px,
QString processedText;
+ // FIXME: This parsing is really slow. We should cache the parse results.
+ // We should also use a faster parsing algorithm.
+
static const GreekCharType GC[] = {{"\\Alpha", "A"}, {"\\alpha", "a"},
{"\\Beta", "B"}, {"\\beta", "b"},
@@ -245,9 +249,9 @@ void KstLabel::draw(QPainter &p, int px,
i_fp++;
fP[i_fp].locked = false;
- fP[i_fp].size = fP[i_fp-1].size-1;
- fP[i_fp].dy = fP[i_fp-1].dy + -p.fontMetrics().ascent()*0.4;
+ fP[i_fp].size = fP[i_fp-1].size - 1;
+ fP[i_fp].dy = fP[i_fp-1].dy - p.fontMetrics().ascent()*0.4;
fP[i_fp].x = x;
if (p.fontMetrics().rightBearing(C.at(0)) < 0) {
- x -= 2.0*p.fontMetrics().rightBearing(C.at(0));
+ x -= 2.0 * p.fontMetrics().rightBearing(C.at(0));
}
}
@@ -277,6 +281,7 @@ void KstLabel::draw(QPainter &p, int px,
is_greek = false;
+ QString subProcessedText = processedText.mid(i);
for (i_g = 0; i_g < N_GREEK; i_g++) {
- if (GC[i_g].label == processedText.mid(i, GC[i_g].label.length())) {
+ if (subProcessedText.startsWith(GC[i_g].label)) {
is_greek = true;
C = GC[i_g].c;
@@ -284,5 +289,5 @@ void KstLabel::draw(QPainter &p, int px,
if (processedText[i+1] == ' ')
i++;
- i_g = N_GREEK;
+ break;
}
}
@@ -292,11 +298,12 @@ void KstLabel::draw(QPainter &p, int px,
p.setFont(TextFont);
- if (processedText.mid(i,2) == "\\_") {
+ if (processedText[i] == '\\') {
+ if (processedText[i+1] == '_') {
C = "_";
i++;
- } else if (processedText.mid(i,2) == "\\^") {
+ } else if (processedText[i+1] == '^') {
C = "^";
i++;
- } else if (processedText.mid(i,3) == "\\it") {
+ } else if (processedText[i+1] == 'i' && processedText[i+2] == 't') {
TextFont.setItalic(true);
i += 2;
@@ -304,5 +311,5 @@ void KstLabel::draw(QPainter &p, int px,
i++;
C = QString::null;
- } else if (processedText.mid(i,3) == "\\rm") {
+ } else if (processedText[i+1] == 'r' && processedText[i+2] == 'm') {
TextFont.setItalic(false);
i += 2;
@@ -310,4 +317,8 @@ void KstLabel::draw(QPainter &p, int px,
i++;
C = QString::null;
+ } else {
+ C = processedText[i];
+ p.setFont(TextFont);
+ }
} else {
C = processedText[i];
More information about the Kst
mailing list