Fix font dialog with missing font family and pixel sizes

Two related errors: When a non-existent font was set on
the font dialog, the GTK native font dialog would just pick
a default one. Also, if the font size was specified with
pixel size, we would request -1 as the point size from
Pango.

The fix for both is to resolve the font before applying
it to the font dialog, and set the actually resolved family,
as well as point size. Note that if the point size is
explicitly set, then we pass this to the font dialog,
since the one returned by QFontInfo will always be
calculated based on the (rounded) pixel size, so it will
usually not match the request.

This fixes tst_qfontdialog::setFont().

[ChangeLog][GTK2][Dialogs] Fixed requesting a font from
font dialog with a non-existent family name and/or pixel
size.

Task-number: QTBUG-51148
Change-Id: Id9c783407778546b0cf3f9c3ab19f124e76c878e
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
bb10
Eskil Abrahamsen Blomfeldt 2016-02-22 15:07:21 +01:00
parent 544bbcbcda
commit d8e65d5756
1 changed files with 2 additions and 2 deletions

View File

@ -517,8 +517,8 @@ void QGtk2FontDialogHelper::hide()
static QString qt_fontToString(const QFont &font)
{
PangoFontDescription *desc = pango_font_description_new();
pango_font_description_set_size(desc, font.pointSizeF() * PANGO_SCALE);
pango_font_description_set_family(desc, font.family().toUtf8());
pango_font_description_set_size(desc, (font.pointSizeF() > 0.0 ? font.pointSizeF() : QFontInfo(font).pointSizeF()) * PANGO_SCALE);
pango_font_description_set_family(desc, QFontInfo(font).family().toUtf8());
int weight = font.weight();
if (weight >= QFont::Black)