[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Tue Dec 30 00:34:09 CET 2003


CVS commit by arwalker: 

Modified behaviour of ^ and _ with symbol (greek) characters


  M +46 -21    kstlabel.cpp   1.21


--- kdeextragear-2/kst/kst/kstlabel.cpp  #1.20:1.21
@@ -135,7 +134,10 @@ void KstLabel::draw(QPainter &p, int px,
   int i_g;
   bool is_greek;
+  bool bTerminate = false;
+  unsigned uiLength;
   QChar C;
   QString str;
   QString strOut;
+  QString subProcessedText;
   QString processedText;
   QFont TextFont(FontName, fontSize(p), QFont::Normal, false);
@@ -237,5 +239,6 @@ void KstLabel::draw(QPainter &p, int px,
   }
   
-  for (unsigned i = 0; i < processedText.length(); i++) {
+  uiLength = processedText.length();
+  for (unsigned i = 0; i < uiLength; i++) {    
     C = processedText[i];
     if( C == '^' || C == '_' || C == '{' || C == '}' || C == '\\' ) {
@@ -252,4 +255,5 @@ void KstLabel::draw(QPainter &p, int px,
         if (i_fp+1 < MAX_DEPTH_SUB_SUPER) {
           i_fp++;
+          bTerminate  = false;
           fP[i_fp].locked = false;
           fP[i_fp].size = fP[i_fp-1].size - 1;
@@ -268,7 +272,8 @@ void KstLabel::draw(QPainter &p, int px,
         if (i_fp+1 < MAX_DEPTH_SUB_SUPER) {
           i_fp++;
+          bTerminate  = false;
           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().height()/5;
+          fP[i_fp].dy = fP[i_fp-1].dy + p.fontMetrics().height()*0.2;
           fP[i_fp].x = x;
           s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size)));
@@ -289,5 +294,5 @@ void KstLabel::draw(QPainter &p, int px,
       } else if( processedText[i] == '\\' ) {
         is_greek = false;
-        QString subProcessedText = processedText.mid(i);
+        subProcessedText = processedText.mid(i);
         for (i_g = 0; i_g < N_GREEK; i_g++) {
           if (subProcessedText.startsWith(GC[i_g].label)) {
@@ -303,6 +308,11 @@ void KstLabel::draw(QPainter &p, int px,
 
         if (is_greek) {
+          s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size)));
+          if (s < 5) {
+            s = 5; // no smaller than 5pt font!
+          }
           SymbolFont.setPointSize(s);
           p.setFont(SymbolFont);
+          bTerminate = true;
           if( doDraw ) {
             p.drawText(int(x),int(y + fP[i_fp].dy), str);
@@ -310,5 +320,5 @@ void KstLabel::draw(QPainter &p, int px,
           x += p.fontMetrics().width(str);
         } else {
-          if (processedText.find( "it", i+1, FALSE ) == i+1 ) {
+          if (processedText.find( "it", i+1, FALSE ) == (int)i+1 ) {
             TextFont.setItalic(true);
             i += 2;
@@ -316,5 +326,5 @@ void KstLabel::draw(QPainter &p, int px,
               i++;
             }
-          } else if (processedText.find( "rm", i+1, FALSE ) == i+1 ) {
+          } else if (processedText.find( "rm", i+1, FALSE ) == (int)i+1 ) {
             TextFont.setItalic(false);
             i += 2;
@@ -324,12 +334,30 @@ void KstLabel::draw(QPainter &p, int px,
           } else {
             i++;
+            bTerminate = true;
             strOut += processedText.at( i );
           }
         }
+      }
+    } else {
+        bTerminate = true;
+      strOut += processedText[i];
+    }
       
-        if (i_fp > 0 && fP[i_fp].locked == false) {
+    //
+    // do we need to terminate a superscript or subscript?
+    //
+    if (i_fp > 0 && fP[i_fp].locked == false && bTerminate ) {
+      if( !strOut.isEmpty( ) ) {
+        p.setFont( TextFont );
+        if( doDraw ) {
+          p.drawText(int(x),int(y + fP[i_fp].dy), strOut);
+        }
+        x += p.fontMetrics().width(strOut);
+        strOut = QString::null;
+      }
           if (processedText.at(i+1) == '_' || processedText.at(i+1) == '^') {
             x = fP[i_fp].x;
           }
+      
           i_fp--;
           s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size)));
@@ -340,10 +368,7 @@ void KstLabel::draw(QPainter &p, int px,
         }
       }
-    } else {
-      strOut += processedText[i];
-    }
-  }
     
   if( !strOut.isEmpty( ) ) {
+    p.setFont( TextFont );
     if( doDraw ) {
       p.drawText(int(x),int(y + fP[i_fp].dy), strOut);





More information about the Kst mailing list