Adding KFontUtils to kdeui

Albert Astals Cid aacid at kde.org
Sat May 2 14:50:02 BST 2009


A Dissabte, 2 de maig de 2009, Parker Coates va escriure:
> On Fri, May 1, 2009 at 10:25 AM, Albert Astals Cid wrote:
> > Hi, this is a mail asking for the moving of KFontUtils from libkdeedu to
> > kdelibs since 5 programs in kdegames are already using copies of it (some
> > old copies)
> >
> > The code that will be commited is attached.
> >
> > A better name for the function is welcome
> >
> > The rational of this helper method is that QFontMetrics is a good try but
> > it really fails when you need pixel perfection.
> >
> > Since the code is small and already used in lots of places, Allen agreed
> > i can commit it to kdelibs on Monday if noone objects.
>
> A few comments on the API:
>
> - The API docs should explicitly state (in several places) that the
> function works with font sizes in points, not in pixels.

Agreed.

> - It might be convenient to have an overload that takes a QSizeF.

Agreed.

> - It strikes me as odd that the function takes a QPainter as an
> argument. I realise a QPainter is required by the internal
> implementation, but from the outside this function has nothing to do
> with painting. On the other hand, if I'm passing in a painter and the
> text to paint, why doesn't it just do the painting for me.

It doesn't do the painting because the calculation of the value is "costly" so 
you should probably just calculate it once and not every time you paint.

>
> Maybe the functionality could be split into two functions. One would
> be identical to the current function except it would take QFont as a
> parameter instead of a QPainter (it could create it's own internally)
> and would return a font size. The other could take a QPainter and a
> QRectF to draw in and do the painting for the user after it's found
> the proper size. (Both functions could use a common private function
> to do the actual font size logic.)
>
> This is a very handy function and I know of a least one place where
> I'm going to use it once it hits kdelibs. I'm somewhat surprised it
> isn't already in QFontMetrics.

The QPainter is needed because from what my experience show rendering on a 
QPrinter yields different results than rendering on a QImage.

Also it's not on QFontMetrics because AFAIR QFontMetrics works on QFonts only 
so it can't have that knowledge.

Albert

>
> Parker


-------------- next part --------------
A non-text attachment was scrubbed...
Name: kfontmetrics.patch
Type: text/x-patch
Size: 8482 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090502/8f2b691d/attachment.bin>


More information about the kde-core-devel mailing list