From 22929c5dfc98901a86a231a84dde90b19b94f8e5 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 30 Oct 2012 14:01:12 +0100 Subject: Mac: fix bugs for font selection in QFontDialog Use localized family name and style name when selecting font with non-English locale Task-number: QTBUG-27415 Change-Id: Ie81507ed011fc096e0f5edad146e97c392e86494 Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit 3c09f6bc9aee0c97427fe8da6efdc73b4ac473aa) --- src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index 5ccd019a9b..ff3ba63931 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -92,20 +92,16 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) QFont newFont; if (cocoaFont) { int pSize = qRound([cocoaFont pointSize]); - QString family(QCFString::toQString([cocoaFont familyName])); - QString typeface(QCFString::toQString([cocoaFont fontName])); - - int hyphenPos = typeface.indexOf(QLatin1Char('-')); - if (hyphenPos != -1) { - typeface.remove(0, hyphenPos + 1); - } else { - typeface = QLatin1String("Normal"); - } + CTFontDescriptorRef font = CTFontCopyFontDescriptor((CTFontRef)cocoaFont); + // QCoreTextFontDatabase::populateFontDatabase() is using localized names + QString family = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL)); + QString style = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL)); - newFont = QFontDatabase().font(family, typeface, pSize); + newFont = QFontDatabase().font(family, style, pSize); newFont.setUnderline(resolveFont.underline()); newFont.setStrikeOut(resolveFont.strikeOut()); + CFRelease(font); } return newFont; } -- cgit v1.2.3 From 133bbf6ea9b9e6dff82361bf2101a35d42f0fbe0 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Wed, 11 Jul 2012 14:39:54 +0200 Subject: Fix styleName support in QPA font database Font styleName support was disconnected since Qt switched to QPA fontdatabase. Now add the code from Qt 4.8 back to enable this in QPA. Change-Id: Iab2cbfd5468f87542183348c2123ca4b2c270692 Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit fa7661d8b25fa338649a301010e1b5a2b63da731) --- src/plugins/platforms/windows/qwindowsfontdatabase.cpp | 8 ++++---- src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index 262b610745..1a899c848e 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -1033,17 +1033,17 @@ static bool addFontToDatabase(QString familyName, const QString &scriptName, writingSystems.setSupported(ws); } - QPlatformFontDatabase::registerFont(familyName, foundryName, weight, + QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight, style, stretch, antialias, scalable, size, fixed, writingSystems, 0); // add fonts windows can generate for us: if (weight <= QFont::DemiBold) - QPlatformFontDatabase::registerFont(familyName, foundryName, QFont::Bold, + QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold, style, stretch, antialias, scalable, size, fixed, writingSystems, 0); if (style != QFont::StyleItalic) - QPlatformFontDatabase::registerFont(familyName, foundryName, weight, + QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight, QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); if (weight <= QFont::DemiBold && style != QFont::StyleItalic) - QPlatformFontDatabase::registerFont(familyName, foundryName, QFont::Bold, + QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold, QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); if (!englishName.isEmpty()) diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp index 4c3d412b8e..7d09166473 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp @@ -279,20 +279,20 @@ static bool addFontToDatabase(QString familyName, const QString &scriptName, if (!QDir::isAbsolutePath(value)) value.prepend(QString::fromLocal8Bit(qgetenv("windir") + "\\Fonts\\")); - QPlatformFontDatabase::registerFont(faceName, foundryName, weight, style, stretch, + QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, weight, style, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); // add fonts windows can generate for us: if (weight <= QFont::DemiBold) - QPlatformFontDatabase::registerFont(faceName, foundryName, QFont::Bold, style, stretch, + QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, QFont::Bold, style, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); if (style != QFont::StyleItalic) - QPlatformFontDatabase::registerFont(faceName, foundryName, weight, QFont::StyleItalic, stretch, + QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, weight, QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); if (weight <= QFont::DemiBold && style != QFont::StyleItalic) - QPlatformFontDatabase::registerFont(faceName, foundryName, QFont::Bold, QFont::StyleItalic, stretch, + QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, QFont::Bold, QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); if (!englishName.isEmpty()) -- cgit v1.2.3 From 3a75e2f227810d75adc22d426fcab1355611adee Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 17 Dec 2012 22:46:45 +0100 Subject: Initalize the printinfo on Mac if it requests and it needs initalizing When the print panel was closed then it would clean up the printinfo and if it was requested for the same QPrinter then it would not be recreated in time. Therefore we check if it is initalized and if not we re-initalize it. Task-number: QTBUG-28657 Change-Id: I7dc9011b80e03cfa3eae8fee2fcf6cc8021a8566 Reviewed-by: Lars Knoll (cherry picked from commit dde9569d389b4382e8869ac48f942adb3c51ade7) Reviewed-by: Sergio Ahumada --- src/plugins/platforms/cocoa/qcocoanativeinterface.mm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index f0b1bd330a..271c9d2894 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -107,8 +107,10 @@ QPlatformPrinterSupport *QCocoaNativeInterface::createPlatformPrinterSupport() void *QCocoaNativeInterface::NSPrintInfoForPrintEngine(QPrintEngine *printEngine) { #ifndef QT_NO_WIDGETS - QMacPrintEngine *macPrintEngine = static_cast(printEngine); - return macPrintEngine->d_func()->printInfo; + QMacPrintEnginePrivate *macPrintEnginePriv = static_cast(printEngine)->d_func(); + if (macPrintEnginePriv->state == QPrinter::Idle && !macPrintEnginePriv->isPrintSessionInitialized()) + macPrintEnginePriv->initialize(); + return macPrintEnginePriv->printInfo; #else qFatal("Printing is not supported when Qt is configured with -no-widgets"); return 0; -- cgit v1.2.3 From 3bf50a7db9a1add66fb66b7a1f9c1d3b038c5e7f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 18 Dec 2012 14:05:45 +0100 Subject: Fix font sizes when X11 has a forced dpi setting On X11, the X resource system can override the physical DPI of the screen for resolving font sizes etc. Correctly load the setting and adjust the logicalDpi() accordingly. Change-Id: Id60d03d1d214fb99e9de17a65976abd170bb7cca Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/xcb/qxcbscreen.cpp | 44 ++++++++++++++++++++++++++++++++ src/plugins/platforms/xcb/qxcbscreen.h | 2 ++ 2 files changed, 46 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 4f0c3ba6bb..fc80662c46 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -66,6 +66,7 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr, , m_orientation(Qt::PrimaryOrientation) , m_number(number) , m_refreshRate(60) + , m_forcedDpi(-1) { if (connection->hasXRandr()) xcb_randr_select_input(xcb_connection(), screen()->root, true); @@ -82,6 +83,9 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr, if (m_availableGeometry.isEmpty()) m_availableGeometry = QRect(QPoint(), m_virtualSize); + readXResources(); + + #ifdef Q_XCB_DEBUG qDebug(); qDebug("Screen output %s of xcb screen %d:", m_outputName.toUtf8().constData(), m_number); @@ -243,6 +247,9 @@ QImage::Format QXcbScreen::format() const QDpi QXcbScreen::logicalDpi() const { + if (m_forcedDpi > 0) + return QDpi(m_forcedDpi, m_forcedDpi); + return QDpi(Q_MM_PER_INCH * m_virtualSize.width() / m_virtualSizeMillimeters.width(), Q_MM_PER_INCH * m_virtualSize.height() / m_virtualSizeMillimeters.height()); } @@ -474,4 +481,41 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) return result; } +void QXcbScreen::readXResources() +{ + int offset = 0; + QByteArray resources; + while(1) { + xcb_get_property_reply_t *reply = + xcb_get_property_reply(xcb_connection(), + xcb_get_property_unchecked(xcb_connection(), false, screen()->root, + XCB_ATOM_RESOURCE_MANAGER, + XCB_ATOM_STRING, offset/4, 8192), NULL); + bool more = false; + if (reply && reply->format == 8 && reply->type == XCB_ATOM_STRING) { + resources += QByteArray((const char *)xcb_get_property_value(reply), xcb_get_property_value_length(reply)); + offset += xcb_get_property_value_length(reply); + more = reply->bytes_after != 0; + } + + if (reply) + free(reply); + + if (!more) + break; + } + + QList split = resources.split('\n'); + for (int i = 0; i < split.size(); ++i) { + const QByteArray &r = split.at(i); + if (r.startsWith("Xft.dpi:\t")) { + bool ok; + int dpi = r.mid(sizeof("Xft.dpi:")).toInt(&ok); + if (ok) + m_forcedDpi = dpi; + break; + } + } +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index d9eee464dc..96d30cde8b 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -96,6 +96,7 @@ public: void updateGeometry(xcb_timestamp_t timestamp); void updateRefreshRate(); + void readXResources(); private: xcb_screen_t *m_screen; xcb_randr_crtc_t m_crtc; @@ -114,6 +115,7 @@ private: QMap m_visuals; QXcbCursor *m_cursor; int m_refreshRate; + int m_forcedDpi; }; QT_END_NAMESPACE -- cgit v1.2.3