summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2012-03-19 13:51:53 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-20 11:44:09 +0100
commit9f4d567f4357392f1a7cfdb7408dec2fc2793b41 (patch)
treeec97e6dafd3af414208389ccfb547257588b2a9f /src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
parentc4ac14fae1765cae9d5ab94c8af486e2d14dede7 (diff)
Cocoa: set font engine glyph format based on display type
Make the QCoreTextFontEngine::glyphFormat depend on the primary display's subpixel layout (if any). This change also refactors the antialiasing threshold setting to live beside the defaultGlyphFormat. Change-Id: I27f94f775d91d2a68cd647cc24503b31b6ff5e61 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm')
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
index 1eb1cbeece..c42320889a 100644
--- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
+++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
@@ -39,10 +39,12 @@
**
****************************************************************************/
+#import <Cocoa/Cocoa.h>
+#import <IOKit/graphics/IOGraphicsLib.h>
+
#include "qcoretextfontdatabase_p.h"
#include "qfontengine_coretext_p.h"
#include <QtCore/QSettings>
-#import <Foundation/Foundation.h>
QT_BEGIN_NAMESPACE
@@ -86,9 +88,6 @@ static const char *languageForWritingSystem[] = {
};
enum { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char *) };
-int qt_antialiasing_threshold = 0;
-bool qt_enable_font_smoothing = true;
-
QFont::StyleHint styleHintFromNSString(NSString *style)
{
if ([style isEqual: @"sans-serif"])
@@ -122,13 +121,37 @@ QCoreTextFontDatabase::QCoreTextFontDatabase()
QSettings appleSettings(QLatin1String("apple.com"));
QVariant appleValue = appleSettings.value(QLatin1String("AppleAntiAliasingThreshold"));
if (appleValue.isValid())
- qt_antialiasing_threshold = appleValue.toInt();
-
+ QCoreTextFontEngine::antialiasingThreshold = appleValue.toInt();
+
+ /*
+ font_smoothing = 0 means no smoothing, while 1-3 means subpixel
+ antialiasing with different hinting styles (but we don't care about the
+ exact value, only if subpixel rendering is available or not)
+ */
+ int font_smoothing = 0;
appleValue = appleSettings.value(QLatin1String("AppleFontSmoothing"));
- // Only disable font smoothing when AppleFontSmoothing is set to 0,
- // empty or non-zero means enabled
- if (appleValue.isValid() && appleValue.toInt() == 0)
- qt_enable_font_smoothing = false;
+ if (appleValue.isValid()) {
+ font_smoothing = appleValue.toInt();
+ } else {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ // find the primary display (which is always the first NSScreen
+ // according to the documentation)
+ NSScreen *defaultScreen = [[NSScreen screens] objectAtIndex:0];
+ CGDirectDisplayID displayId = [[[defaultScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
+ io_service_t iodisplay = CGDisplayIOServicePort(displayId);
+
+ // determine if font smoothing is available based on the subpixel
+ // layout of the primary display
+ NSDictionary *d = (NSDictionary *) IODisplayCreateInfoDictionary(iodisplay, kIODisplayOnlyPreferredName);
+ uint displaySubpixelLayout = [[d objectForKey:@kDisplaySubPixelLayout] unsignedIntValue];
+ font_smoothing = (displaySubpixelLayout == kDisplaySubPixelLayoutUndefined ? 0 : 1);
+
+ [pool release];
+ }
+ QCoreTextFontEngine::defaultGlyphFormat = (font_smoothing > 0
+ ? QFontEngineGlyphCache::Raster_RGBMask
+ : QFontEngineGlyphCache::Raster_A8);
}
QCoreTextFontDatabase::~QCoreTextFontDatabase()