Adding KFontUtils to kdeui

Parker Coates parker.coates at gmail.com
Sat May 2 02:34:06 BST 2009


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.

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

- 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.

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.

Parker




More information about the kde-core-devel mailing list