macgitver / MacGitver

MacGitver - THE swiss army knife for Git!
8 stars 0 forks source link

css returns size in px instead of pt to achieve unified font sizes #14

Closed antis81 closed 10 years ago

antis81 commented 10 years ago

small fix, great result :)

scunz commented 10 years ago

Erm, this is wrong oO

If we feed the string with QFont::pointSize() we should set the unit to points, right?

antis81 commented 10 years ago

Uhm, I played with QFont::pixelSize() and QFont::pointSizeF(). Actually the above commit gives correct results - but why? I don't know.

antis81 commented 10 years ago

Still don't know why this doesn't work with QFontInfo::pointSize(). But should be ok like that - well, hope so at least ^^.

:question: I mean the following should give the same result, but it actually does not:

QFontInfo info(font);

// gives wrong size
QString( "font-size: %1pt;" ) .arg(info.pointSize());

// gives right size
QString( "font-size: %1px;" ) .arg(info.pixelSize());
scunz commented 10 years ago

Actually, I've had a short look at the documentation. First of all, we should probably use QFont::pointSizeF and QFont::pixelSizeF. Second, pointSize may return -1 in which case we should use the pixel size. Maybe this helps a bit.

But what are the actual values of pointSize(), pixelSize() and their float point equivalents that your are getting here? Having the value of those 4 might help to judge better about this issue.

antis81 commented 10 years ago

Ok, here are the values:

I have set the default font size to 11pt in the settings.

scunz commented 10 years ago

Okay, I get similar results for different fonts and sizes. So something's totally wrong here.

Just in case: 1 point = 1/72 inch. A typical (ancient) screen resolution is 96dpi in both directions. Thus, even on an ancient CRT or LCD display, 96 pixel are 1 inch high. This actually means, that the size of a pixel is 72/96 = 3/4 point. Or in other words: a point (72th of an inch) is 1,33333 pixel if there are 96 pixels per inch.

Now, my display has a height of 1880 pixel and is roughly 22cm high. Thats about 8,6 inch, resulting in a resolution of approximately 220 dpi (I know that every minor change to DPI has a strong influence on display: but these are estimates anyway). Then, 72/220 is 0,327 (pixel per point) - or again in other words: For my display, ~3 pixels are required for one point.

So, for 13pt, I get 13px while I should really be getting 39px.

scunz commented 10 years ago

untitled The background window shows this HTML in Chrome:

<div style="font-family: Helvetica; font-size: 13pt">13pt</div>
<div style="font-family: Helvetica; font-size: 13px">13px</div>

The window in the foreground is drawn with:

void paintEvent(QPaintEvent* )
{
    QRect r(0,0,200,200);
    QPainter p(this);
    p.setFont(QFont("Helvetica", 13));
    p.drawText(r,"Foo");
}

So, totally ignoring the documentation: Obviously the second parameter to the QFont constructor seems to take a pixel size.

antis81 commented 10 years ago

So, totally ignoring the documentation: Obviously the second parameter to the QFont constructor seems to take a pixel size.

Hm, this is confusing. Obviously it is assigned to point size, but used as pixel size. Is it really a bug in Qt?

scunz commented 10 years ago

Is it really a bug in Qt?

I've been using Qt for a really long time now. But this would be a bug that I had obviously encountered before. Maybe it has something to do with Mac OS X? Will try this out on Windows and Linux when I'm using them next time :)

antis81 commented 10 years ago

Hm ... should we merge this until px/pt case is cleared?

scunz commented 10 years ago

Yepp, the last commit looks sane enough to be included :shipit: