From fa608f9094591c146f9170ba485ea2e4d7827dca Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 19 May 2010 10:20:08 +0200 Subject: Small hack to allow forcing off font smoothing on Mac OS X In declarative all text is cached in a transparent buffer. Using subpixel antialiasing for this gives subpar results, and for better results, we want to turn off the font smoothing in the OS for this case. Since we cannot efficiently detect non-opaque destination pixels, we have to have a way where a user can override the default. We'll introduce a style strategy for this later, but for now we only want to enable the use of CGContextSetShouldSmoothFonts() to explicitly turn smoothing off in the declarative context. We still override if font smoothing has been explicitly turned off by us for the context by the TextAntialiasing flag. Task-number: QT-2776 Reviewed-by: MortenS --- src/gui/painting/qpaintengine_mac.cpp | 6 +++++- src/gui/painting/qpaintengine_mac_p.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qpaintengine_mac.cpp b/src/gui/painting/qpaintengine_mac.cpp index 14ba94e..e5323d8 100644 --- a/src/gui/painting/qpaintengine_mac.cpp +++ b/src/gui/painting/qpaintengine_mac.cpp @@ -1390,7 +1390,11 @@ QCoreGraphicsPaintEngine::updateRenderHints(QPainter::RenderHints hints) CGContextSetInterpolationQuality(d->hd, (hints & QPainter::SmoothPixmapTransform) ? kCGInterpolationHigh : kCGInterpolationNone); } - CGContextSetShouldSmoothFonts(d->hd, hints & QPainter::TextAntialiasing); + bool textAntialiasing = (hints & QPainter::TextAntialiasing) == QPainter::TextAntialiasing; + if (!textAntialiasing || d->disabledSmoothFonts) { + d->disabledSmoothFonts = !textAntialiasing; + CGContextSetShouldSmoothFonts(d->hd, textAntialiasing); + } } /* diff --git a/src/gui/painting/qpaintengine_mac_p.h b/src/gui/painting/qpaintengine_mac_p.h index c9ab419..940b2bc 100644 --- a/src/gui/painting/qpaintengine_mac_p.h +++ b/src/gui/painting/qpaintengine_mac_p.h @@ -148,7 +148,7 @@ class QCoreGraphicsPaintEnginePrivate : public QPaintEnginePrivate Q_DECLARE_PUBLIC(QCoreGraphicsPaintEngine) public: QCoreGraphicsPaintEnginePrivate() - : hd(0), shading(0), stackCount(0), complexXForm(false) + : hd(0), shading(0), stackCount(0), complexXForm(false), disabledSmoothFonts(false) { } @@ -168,6 +168,7 @@ public: CGShadingRef shading; int stackCount; bool complexXForm; + bool disabledSmoothFonts; enum { CosmeticNone, CosmeticTransformPath, CosmeticSetPenWidth } cosmeticPen; // pixel and cosmetic pen size in user coordinates. -- cgit v0.12 From 28b894f65c5aba01d5ee80c20f617478faaee7e7 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Wed, 19 May 2010 10:58:11 +0200 Subject: Fix a memory leak from QItemSelectionModel when changing the model Reviewed-By: ogoffart Task-Number: QTBUG-10806 --- src/gui/itemviews/qabstractitemview.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 97fd6e1..064f499 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -679,7 +679,11 @@ void QAbstractItemView::setModel(QAbstractItemModel *model) connect(d->model, SIGNAL(modelReset()), this, SLOT(reset())); connect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged())); } - setSelectionModel(new QItemSelectionModel(d->model, this)); + + QItemSelectionModel *selection_model = new QItemSelectionModel(d->model, this); + connect(d->model, SIGNAL(destroyed()), selection_model, SLOT(deleteLater())); + setSelectionModel(selection_model); + reset(); // kill editors, set new root and do layout } -- cgit v0.12 From 8cbf269e14b372ee3174c2706dd0cc4df37eef1a Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 19 May 2010 11:38:58 +0200 Subject: Fix platform regression: Support QFont::setStretch() on Cocoa QFont::setStretch() would previously have no effect on Mac OS X/Cocoa. Task-number: QTBUG-10585 Reviewed-by: Eskil Done-by: Andy --- src/gui/text/qfontengine_mac.mm | 18 +++++++++++++----- src/gui/text/qfontengine_p.h | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm index a6510cb..3be6d28 100644 --- a/src/gui/text/qfontengine_mac.mm +++ b/src/gui/text/qfontengine_mac.mm @@ -162,9 +162,14 @@ QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, con QCFString name; ATSFontGetName(atsFontRef, kATSOptionFlagsDefault, &name); + transform = CGAffineTransformIdentity; + if (fontDef.stretch != 100) { + transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); + } + QCFType descriptor = CTFontDescriptorCreateWithNameAndSize(name, fontDef.pixelSize); - QCFType baseFont = CTFontCreateWithFontDescriptor(descriptor, fontDef.pixelSize, 0); - ctfont = CTFontCreateCopyWithSymbolicTraits(baseFont, fontDef.pixelSize, 0, symbolicTraits, symbolicTraits); + QCFType baseFont = CTFontCreateWithFontDescriptor(descriptor, fontDef.pixelSize, &transform); + ctfont = CTFontCreateCopyWithSymbolicTraits(baseFont, fontDef.pixelSize, &transform, symbolicTraits, symbolicTraits); // CTFontCreateCopyWithSymbolicTraits returns NULL if we ask for a trait that does // not exist for the given font. (for example italic) @@ -378,7 +383,10 @@ QCoreTextFontEngine::QCoreTextFontEngine(CTFontRef font, const QFontDef &def, if (fontDef.style != QFont::StyleNormal && !(traits & kCTFontItalicTrait)) { synthesisFlags |= SynthesizedItalic; } - + transform = CGAffineTransformIdentity; + if (fontDef.stretch != 100) { + transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); + } QByteArray os2Table = getSfntTable(MAKE_TAG('O', 'S', '/', '2')); if (os2Table.size() >= 10) fsType = qFromBigEndian(reinterpret_cast(os2Table.constData() + 8)); @@ -503,7 +511,7 @@ void QCoreTextFontEngine::draw(CGContextRef ctx, qreal x, qreal y, const QTextIt if (synthesisFlags & QFontEngine::SynthesizedItalic) cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, -tanf(14 * acosf(0) / 90), 1, 0, 0)); -// ### cgMatrix = CGAffineTransformConcat(cgMatrix, transform); + cgMatrix = CGAffineTransformConcat(cgMatrix, transform); CGContextSetTextMatrix(ctx, cgMatrix); @@ -626,7 +634,7 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, int margin, bool aa) if (synthesisFlags & QFontEngine::SynthesizedItalic) cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, tanf(14 * acosf(0) / 90), 1, 0, 0)); -// ### cgMatrix = CGAffineTransformConcat(cgMatrix, transform); + cgMatrix = CGAffineTransformConcat(cgMatrix, transform); CGContextSetTextMatrix(ctx, cgMatrix); CGContextSetRGBFillColor(ctx, 1, 1, 1, 1); diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index e645caf..922acfb 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -462,6 +462,7 @@ private: CGFontRef cgFont; QCoreTextFontEngineMulti *parentEngine; int synthesisFlags; + CGAffineTransform transform; friend class QCoreTextFontEngineMulti; }; @@ -493,7 +494,7 @@ private: uint fontIndexForFont(CTFontRef id) const; CTFontRef ctfont; mutable QCFType attributeDict; - + CGAffineTransform transform; friend class QFontDialogPrivate; }; # endif //MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 -- cgit v0.12