summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2009-05-26 08:04:53 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2009-05-26 10:58:00 (GMT)
commitf640eca34f63631f938817b1254d0caf92cc9143 (patch)
treefc56c2e1c4f65f074873d00ee8f7a219e9348e7f
parent54f92419b23b425e32ad573db17f608a67936df1 (diff)
downloadQt-f640eca34f63631f938817b1254d0caf92cc9143.zip
Qt-f640eca34f63631f938817b1254d0caf92cc9143.tar.gz
Qt-f640eca34f63631f938817b1254d0caf92cc9143.tar.bz2
Carbon, QFontDialog::getFont() ignore the "initial" parameter
Seems like no code was written to handle other font engines than CoreText. Unfortunatly the engine on Carbon is ATSUI. This patch adds general code for converting a QFont to an NSFont so the dialog can support other engines than CoreText Task-number: 251957 Reviewed-by: Trenton Schulz
-rw-r--r--src/gui/dialogs/qfontdialog_mac.mm39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm
index 13f7149..3be53db 100644
--- a/src/gui/dialogs/qfontdialog_mac.mm
+++ b/src/gui/dialogs/qfontdialog_mac.mm
@@ -47,6 +47,7 @@
#include <private/qapplication_p.h>
#include <private/qfont_p.h>
#include <private/qfontengine_p.h>
+#include <private/qt_cocoa_helpers_mac_p.h>
#include <private/qt_mac_p.h>
#include <qdebug.h>
#import <AppKit/AppKit.h>
@@ -123,16 +124,16 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont)
QFont newFont;
if (cocoaFont) {
int pSize = qRound([cocoaFont pointSize]);
- QString family(QCFString::toQString(reinterpret_cast<CFStringRef>([cocoaFont familyName])));
- QString typeface(QCFString::toQString(reinterpret_cast<CFStringRef>([cocoaFont fontName])));
-// qDebug() << "original family" << family << "typeface" << typeface << "psize" << pSize;
+ QString family(qt_mac_NSStringToQString([cocoaFont familyName]));
+ QString typeface(qt_mac_NSStringToQString([cocoaFont fontName]));
+
int hyphenPos = typeface.indexOf(QLatin1Char('-'));
if (hyphenPos != -1) {
typeface.remove(0, hyphenPos + 1);
} else {
typeface = QLatin1String("Normal");
}
-// qDebug() << " massaged family" << family << "typeface" << typeface << "psize" << pSize;
+
newFont = QFontDatabase().font(family, typeface, pSize);
newFont.setUnderline(resolveFont.underline());
newFont.setStrikeOut(resolveFont.strikeOut());
@@ -598,15 +599,37 @@ QFont QFontDialogPrivate::execCocoaFontPanel(bool *ok, const QFont &initial,
}
}
-void QFontDialogPrivate::setFont(void * delegate, const QFont &font)
+void QFontDialogPrivate::setFont(void *delegate, const QFont &font)
{
+ QMacCocoaAutoReleasePool pool;
QFontEngine *fe = font.d->engineForScript(QUnicodeTables::Common);
+ NSFontManager *mgr = [NSFontManager sharedFontManager];
+ NSFont *nsFont = 0;
+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if (qstrcmp(fe->name(), "CoreText") == 0) {
- const NSFont *nsFont = reinterpret_cast<const NSFont *>(static_cast<QCoreTextFontEngineMulti *>(fe)->ctfont);
- [[NSFontManager sharedFontManager] setSelectedFont:nsFont isMultiple:NO];
- }
+ nsFont = reinterpret_cast<const NSFont *>(static_cast<QCoreTextFontEngineMulti *>(fe)->ctfont);
+ } else
#endif
+ {
+ int weight = 5;
+ NSFontTraitMask mask = 0;
+ if (font.style() == QFont::StyleItalic) {
+ mask |= NSItalicFontMask;
+ }
+ if (font.weight() == QFont::Bold) {
+ weight = 9;
+ mask |= NSBoldFontMask;
+ }
+
+ NSFontManager *mgr = [NSFontManager sharedFontManager];
+ nsFont = [mgr fontWithFamily:qt_mac_QStringToNSString(font.family())
+ traits:mask
+ weight:weight
+ size:font.pointSize()];
+ }
+
+ [mgr setSelectedFont:nsFont isMultiple:NO];
[static_cast<QCocoaFontPanelDelegate *>(delegate) setQtFont:font];
}