[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/lib/kotext
From:       David Faure <faure () kde ! org>
Date:       2006-03-16 20:26:48
Message-ID: 1142540808.081899.3521.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 519305 by dfaure:

Fix painting of variables so that they use the width calculated at layout \
time and not more (in some zoom levels)


 M  +0 -9      KoTextParag.cpp  
 M  +21 -2     KoVariable.cpp  


--- trunk/koffice/lib/kotext/KoTextParag.cpp #519304:519305
@@ -662,15 +662,6 @@
         return x;
 }
 
-/*void KoTextParag::setPainter( QPainter *p, bool adjust  )
-{
-    pntr = p;
-    for ( int i = 0; i < length(); ++i ) {
-	if ( at( i )->isCustom() )
-	    at( i )->customItem()->setPainter( p, adjust  );
-    }
-}*/
-
 KoTextFormatCollection *KoTextParag::formatCollection() const
 {
     if ( doc )
--- trunk/koffice/lib/kotext/KoVariable.cpp #519304:519305
@@ -877,8 +877,9 @@
     QString txt = text();
 
     width = 0;
+     // size at 100%
     for ( int i = 0 ; i < (int)txt.length() ; ++i )
-        width += fm.charWidth( txt, i ); // size at 100%
+        width += fm.width( txt[i] ); // was fm.charWidth(txt,i), but see \
drawCustomItemHelper...  // zoom to LU
     width = qRound( KoTextZoomHandler::ptToLayoutUnitPt( width ) );
     height = fmt->height();
@@ -972,7 +973,25 @@
     else if ( fmt->offsetFromBaseLine() < 0 )
         posY -= 2*fmt->offsetFromBaseLine();
 
-    p->drawText( x, posY, str );
+    //p->drawText( x, posY, str );
+    // We can't just drawText, it wouldn't use the same kerning as the one
+    // that resize() planned for [which is zoom-independent].
+    // We need to do the layout using layout units instead, so for \
simplicity +    // I just draw every char individually (whereas \
KoTextFormatter/KoTextParag +    // detect runs of text that can be drawn \
together) +    const int len = str.length();
+    int xLU = zh->pixelToLayoutUnitX( x );
+    QFontMetrics fm = fmt->refFontMetrics();
+    for ( int i = 0; i < len; ++i )
+    {
+        const QChar ch = str[i];
+        p->drawText( x, posY, ch );
+        // Do like KoTextFormatter: do the layout in layout units.
+        xLU += KoTextZoomHandler::ptToLayoutUnitPt( fm.width( ch ) );
+        // And then compute the X position in pixels from the layout unit \
X. +        x = zh->layoutUnitToPixelX( xLU );
+    }
+
     p->restore();
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic