[Development] QFontMetrics and QScriptLine height calculation

Konstantin Ritt ritt.ks at gmail.com
Fri Oct 5 12:42:15 CEST 2012


Yes, backporting QAccessibleTextWidget::characterRect() implementation
from 5.0 is seems to be safe. I don't know for sure if this won't
break some other tests, though.
You'll probably need to discuss this with Eskil Abrahamsen Blomfeldt
and/or Jan Arve Sæther first (eskil and jan-arve at IRC,
respectively)...

Konstantin


2012/10/5 Rafael Roquetto <rafael.roquetto at kdab.com>:
> Hi there,
>
> Thanks for the prompty reply. I am indeed talking about 4.8. Should I maybe
> then backport the 5.0 implementation of QAccessibleTextWidget, should this
> ever be possible or make sense? Or even better, fix the test to use
> QFontMetrics::lineSpacing()?
>
> Any other suggestions? As I said, this is an obscure corner of Qt to me, so
> apologies if I seem to be grunting garbage.
>
> Cheers,
> Rafael
>
> On Fri, Oct 05, 2012 at 01:13:50AM +0300, Konstantin Ritt wrote:
>> First of all, which Qt version you're talking about?
>> I assume it is 4.8 since QAccessibleTextWidget has been reworked alot
>> in 5.0 and the problem you've described seems to gone there (see
>> QAccessibleTextWidget::characterRect() impl).
>> If it is 5.0, then you're probably subclassing the accessibility
>> widgets, are you?
>>
>> Briefly:
>> the QTextDocumentLayout sets the leadingIncluded to true for every
>> line in a blocks (re-)layouting code and thus the line's height equals
>> to QFontMetrics::lineSpacing(), whilst QFontMetrics::height() better
>> suites to what characterRect() should return as a rect's height.
>>
>> Anyways, more info required...
>>
>>
>> Konstantin
>>
>>
>> 2012/10/4 Rafael Roquetto <rafael.roquetto at kdab.com>:
>> > Hello,
>> >
>> > I am trying to fix tst_QAccessibility for QNX, and I have a problem on line
>> > 2750:
>> >
>> > QCOMPARE(iface->textInterface()->characterRect(0,
>> > QAccessible2::RelativeToParent).size(), QSize(fm.width("h"), fm.height()));
>> >
>> > This comparison is failing, because the caracter rect height is bigger than
>> > the height returned by QFontMetrics. And...?
>> >
>> > Well, ultimately the height of the character rect comes from
>> > QScriptLine::height(). Here is how it is calculated (simplified):
>> >
>> >     height = ascent + descent + 1 (leadingIncluded ? leading : QFixed())
>> >
>> > While QFontMetrics does not use 'leading' to compute 'height' (simplified):
>> >
>> >     height = ascent + descent + 1
>> >
>> >
>> > Which leads to a few questions:
>> >
>> > 1. Is this meant to be like that or is either class implementation incorrect?
>> >
>> > 2. If this is correct, then is the test erroneusly assuming that
>> > QFontMetrics::height() == QScriptLine::height() for every use case? Or...
>> >
>> > 3. Should the 'leading' be '0' in the context of the test (what happens in Qt
>> > built for Linux, but not for QNX)?
>> >
>> > Well, I will continue to investigate it, but since I do not know much about
>> > this corner of Qt, I thought it wouldn't hurt to ask :)
>> >
>> > Thanks a lot in advance,
>> > Rafael
>> >
>> > --
>> > ** Qt Developer Conference: http://qtconference.kdab.com/ **
>> >
>> > Rafael Roquetto | rafael.roquetto at kdab.com | Software Engineer
>> > Klarälvdalens Datakonsult AB, a KDAB Group company
>> > Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
>> > KDAB - Qt Experts - Platform-independent software solutions
>> >
>> >
>> > _______________________________________________
>> > Development mailing list
>> > Development at qt-project.org
>> > http://lists.qt-project.org/mailman/listinfo/development
>> >
>
> --
> ** Qt Developer Conference: http://qtconference.kdab.com/ **
>
> Rafael Roquetto | rafael.roquetto at kdab.com | Software Engineer
> Klarälvdalens Datakonsult AB, a KDAB Group company
> Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
> KDAB - Qt Experts - Platform-independent software solutions
>



More information about the Development mailing list