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

List:       kde-commits
Subject:    Re: koffice/kspread/ui
From:       "C. Boemann" <cbr () boemann ! dk>
Date:       2008-05-25 17:18:21
Message-ID: 200805251918.21271.cbr () boemann ! dk
[Download RAW message or body]

Hmm it looks like you have horrible problems with the scaling.

What exactly are you trying to accomplish?

And why do you have to mess with both fontscaling and normal scaling.? Sorry I 
don't get it but it surely looks wrong at first sight.

Best regards
Casper

On Sunday 25 May 2008, Stefan Nikolaus wrote:
> SVN commit 812503 by nikolaus:
>
> Painting	Text drawing.
> 		Adjust the scaling of the painter by reverting the resolution dependent
> factor. Now the font is scaled once, as before, but now by QFont. Looks
> cleaner.
>
>
>  M  +28 -9     Border.cpp
>  M  +20 -9     CellView.cpp
>
>
> --- trunk/koffice/kspread/ui/Border.cpp #812502:812503
> @@ -60,6 +60,7 @@
>
>  // KOffice
>  #include <KoCanvasController.h>
> +#include <KoGlobal.h>
>  #include <KoZoomHandler.h>
>
>  // KSpread
> @@ -522,8 +523,8 @@
>    painter.setRenderHint( QPainter::TextAntialiasing );
>
>    // fonts
> -  QFont normalFont( painter.font(), m_pCanvas );
> -  QFont boldFont( normalFont, m_pCanvas );
> +  QFont normalFont( painter.font() );
> +  QFont boldFont( normalFont );
>    boldFont.setBold( true );
>
>    // background brush/color
> @@ -588,7 +589,7 @@
>          drawText( painter,
>                    normalFont,
>                    QPointF( ( width - len ) / 2,
> -                           yPos + ( height +
> painter.fontMetrics().ascent() - painter.fontMetrics().descent() ) / 2 ), +
>                           yPos + ( height + painter.fontMetrics().ascent()
> ) / 2 ), rowText );
>
>      yPos += rowFormat->height();
> @@ -610,6 +611,13 @@
>      if ( !sheet )
>          return;
>
> +    const double scaleX = POINT_TO_INCH(double(KoGlobal::dpiX()));
> +    const double scaleY = POINT_TO_INCH(double(KoGlobal::dpiY()));
> +
> +    // Qt scales the font already with the logical resolution. Do not do
> it twice! +    painter.save();
> +    painter.scale(1.0 / scaleX, 1.0 / scaleY);
> +
>      QTextLayout textLayout( text, font );
>      textLayout.beginLayout();
>      forever
> @@ -617,11 +625,13 @@
>          QTextLine line = textLayout.createLine();
>          if ( !line.isValid() )
>              break;
> -        line.setLineWidth( width() );
> +        line.setLineWidth( width() * scaleX );
>      }
>      textLayout.endLayout();
> -    QPointF loc( location.x(), location.y() - font.pointSizeF() );
> +    QPointF loc( location.x() * scaleX, (location.y() - font.pointSizeF())
> * scaleY ); textLayout.draw( &painter, loc );
> +
> +    painter.restore();
>  }
>
>
> @@ -1220,8 +1230,8 @@
>    painter.setRenderHint( QPainter::TextAntialiasing );
>
>    // fonts
> -  QFont normalFont( painter.font(), m_pCanvas );
> -  QFont boldFont( normalFont, m_pCanvas );
> +  QFont normalFont( painter.font() );
> +  QFont boldFont( normalFont );
>    boldFont.setBold( true );
>
>    // background brush/color
> @@ -1385,6 +1395,13 @@
>      if ( !sheet )
>          return;
>
> +    const double scaleX = POINT_TO_INCH(double(KoGlobal::dpiX()));
> +    const double scaleY = POINT_TO_INCH(double(KoGlobal::dpiY()));
> +
> +    // Qt scales the font already with the logical resolution. Do not do
> it twice! +    painter.save();
> +    painter.scale(1.0 / scaleX, 1.0 / scaleY);
> +
>      QTextLayout textLayout( text, font );
>      textLayout.beginLayout();
>      forever
> @@ -1392,11 +1409,13 @@
>          QTextLine line = textLayout.createLine();
>          if ( !line.isValid() )
>              break;
> -        line.setLineWidth( width );
> +        line.setLineWidth( width * scaleX );
>      }
>      textLayout.endLayout();
> -    QPointF loc( location.x(), location.y() - font.pointSizeF() );
> +    QPointF loc( location.x() * scaleX, (location.y() - font.pointSizeF())
> * scaleY ); textLayout.draw( &painter, loc );
> +
> +    painter.restore();
>  }
>
>
> --- trunk/koffice/kspread/ui/CellView.cpp #812502:812503
> @@ -50,6 +50,7 @@
>  #include <QTextLayout>
>
>  // KOffice
> +#include <KoGlobal.h>
>  #include <KoZoomHandler.h>
>
>  // KSpread
> @@ -2249,38 +2250,48 @@
>  {
>      Q_UNUSED( cell )
>
> -    const QFontMetricsF fontMetrics(effectiveFont(painter.device()),
> painter.device()); -    const double leading = fontMetrics.leading();
> +    const double scaleX = POINT_TO_INCH(double(KoGlobal::dpiX()));
> +    const double scaleY = POINT_TO_INCH(double(KoGlobal::dpiY()));
>
> +    // Qt scales the font already with the logical resolution. Do not do
> it twice! +    painter.save();
> +    painter.scale(1.0 / scaleX, 1.0 / scaleY);
> +
> +    const QFontMetricsF fontMetrics(d->style.font());
> +    const double leading = fontMetrics.leading() / scaleY;
> +
>      const QTextOption options = d->textOptions();
>
> -    double offset = 1.0 - fontMetrics.ascent();
> +    double offset = 1.0 - fontMetrics.ascent() / scaleY;
>      for (int i = 0; i < textLines.count(); ++i)
>      {
> -        QTextLayout textLayout(textLines[i],
> effectiveFont(painter.device())); +        QTextLayout
> textLayout(textLines[i], d->style.font());
>          textLayout.setCacheEnabled(true);
>          textLayout.setTextOption(options);
>          textLayout.beginLayout();
>          double height = 0.0;
>          forever
>          {
> -            if (offset + height + leading + fontMetrics.height() >
> d->height) +            if (offset + height + leading +
> fontMetrics.height() / scaleY > d->height) break;
>              QTextLine line = textLayout.createLine();
>              if (!line.isValid())
>                  break;
> -            line.setLineWidth(d->width - 2 * s_borderSpace
> +            line.setLineWidth(scaleX * (d->width - 2 * s_borderSpace
>                                - 0.5 * d->style.leftBorderPen().width()
> -                              - 0.5 * d->style.rightBorderPen().width());
> +                              - 0.5 * d->style.rightBorderPen().width()));
>              height += leading;
> -            line.setPosition(QPoint(s_borderSpace + 0.5 *
> d->style.leftBorderPen().width(), qRound(height))); +           
> line.setPosition(QPoint(scaleX * (s_borderSpace + 0.5 *
> d->style.leftBorderPen().width()), +                                   
> qRound(scaleX * height)));
>              height += line.height();
>          }
>          textLayout.endLayout();
>
> -        textLayout.draw(&painter, QPointF(location.x(), location.y() +
> offset)); +        textLayout.draw(&painter, QPointF(scaleX * location.x(),
> scaleY * (location.y() + offset))); offset += height;
>      }
> +
> +    painter.restore();
>  }
>
>  void CellView::obscure( int col, int row )



-- 
best regards / venlig hilsen
Casper Boemann
[prev in list] [next in list] [prev in thread] [next in thread] 

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