summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-11-18 09:01:51 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2015-11-18 09:01:51 +0100
commitc7934f2489e2eb9a539206bab35f335b1943c5bd (patch)
treea27d0ed6c001fe9432e2a0f28fb935acf9e4c65f /src/gui
parentf40593b11199fbef886bfcb6b210a214d8c3adf3 (diff)
parent08f9a1bd6ab9b1777ee5ba163d75e5c848c39eb4 (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: src/corelib/io/qprocess.cpp src/corelib/io/qprocess_unix.cpp src/network/kernel/qnetworkinterface_winrt.cpp tools/configure/configureapp.cpp Change-Id: I47df00a01597d2e63b334b492b3b4221b29f58ea
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qicon.cpp11
-rw-r--r--src/gui/image/qicon.h3
-rw-r--r--src/gui/image/qimage.cpp4
-rw-r--r--src/gui/image/qpnghandler.pri7
-rw-r--r--src/gui/kernel/qguiapplication.cpp10
-rw-r--r--src/gui/kernel/qguiapplication_p.h1
-rw-r--r--src/gui/kernel/qplatformwindow.cpp4
-rw-r--r--src/gui/painting/qdrawhelper.cpp14
-rw-r--r--src/gui/painting/qrgba64.h12
-rw-r--r--src/gui/text/qfontengine.cpp13
-rw-r--r--src/gui/text/qfontengine_ft.cpp94
-rw-r--r--src/gui/text/qharfbuzzng.cpp10
-rw-r--r--src/gui/text/qtextengine.cpp54
-rw-r--r--src/gui/text/qtextimagehandler.cpp20
14 files changed, 154 insertions, 103 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index cebe5ce5f9..cc00f5c172 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -1398,8 +1398,12 @@ QDebug operator<<(QDebug dbg, const QIcon &i)
Given base foo.png and a target dpr of 2.5, this function will look for
foo@3x.png, then foo@2x, then fall back to foo.png if not found.
+
+ \a sourceDevicePixelRatio will be set to the value of N if the argument is
+ a non-null pointer
*/
-QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio)
+QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
+ qreal *sourceDevicePixelRatio)
{
if (targetDevicePixelRatio <= 1.0)
return baseFileName;
@@ -1417,8 +1421,11 @@ QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRati
for (int n = qCeil(targetDevicePixelRatio); n > 1; --n) {
QString atNxfileName = baseFileName;
atNxfileName.insert(dotIndex, atNx.arg(n));
- if (QFile::exists(atNxfileName))
+ if (QFile::exists(atNxfileName)) {
+ if (sourceDevicePixelRatio)
+ *sourceDevicePixelRatio = n;
return atNxfileName;
+ }
}
return baseFileName;
diff --git a/src/gui/image/qicon.h b/src/gui/image/qicon.h
index 6808bc2828..989e40bbb5 100644
--- a/src/gui/image/qicon.h
+++ b/src/gui/image/qicon.h
@@ -140,7 +140,8 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
#endif
-Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio);
+Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
+ qreal *sourceDevicePixelRatio = Q_NULLPTR);
QT_END_NAMESPACE
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index a69aae87f1..798002224a 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -4388,6 +4388,8 @@ QImage QImage::smoothScaled(int w, int h) const {
static QImage rotated90(const QImage &image) {
QImage out(image.height(), image.width(), image.format());
+ out.setDotsPerMeterX(image.dotsPerMeterY());
+ out.setDotsPerMeterY(image.dotsPerMeterX());
if (image.colorCount() > 0)
out.setColorTable(image.colorTable());
int w = image.width();
@@ -4456,6 +4458,8 @@ static QImage rotated180(const QImage &image) {
static QImage rotated270(const QImage &image) {
QImage out(image.height(), image.width(), image.format());
+ out.setDotsPerMeterX(image.dotsPerMeterY());
+ out.setDotsPerMeterY(image.dotsPerMeterX());
if (image.colorCount() > 0)
out.setColorTable(image.colorTable());
int w = image.width();
diff --git a/src/gui/image/qpnghandler.pri b/src/gui/image/qpnghandler.pri
index 9ab175d628..505d214130 100644
--- a/src/gui/image/qpnghandler.pri
+++ b/src/gui/image/qpnghandler.pri
@@ -1,9 +1,4 @@
HEADERS += $$PWD/qpnghandler_p.h
SOURCES += $$PWD/qpnghandler.cpp
-contains(QT_CONFIG, system-png) {
- if(unix|mingw): LIBS_PRIVATE += -lpng
- else:win32: LIBS += libpng.lib
-} else {
- include($$PWD/../../3rdparty/libpng.pri)
-}
+include($$PWD/../../3rdparty/png_dependency.pri)
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 12e5dbd66c..66f1b1dfce 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -128,6 +128,8 @@ Qt::MouseButtons QGuiApplicationPrivate::tabletState = Qt::NoButton;
QWindow *QGuiApplicationPrivate::tabletPressTarget = 0;
QWindow *QGuiApplicationPrivate::currentMouseWindow = 0;
+QString QGuiApplicationPrivate::styleOverride;
+
Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
bool QGuiApplicationPrivate::highDpiScalingUpdated = false;
@@ -1288,6 +1290,7 @@ void QGuiApplicationPrivate::init()
session_key = QString::fromWCharArray(guidstr);
# endif
#endif
+ QString s;
int j = argc ? 1 : 0;
for (int i=1; i<argc; i++) {
if (argv[i] && *argv[i] != '-') {
@@ -1330,9 +1333,16 @@ void QGuiApplicationPrivate::init()
#endif
} else if (arg == "-testability") {
loadTestability = true;
+ } else if (arg.indexOf("-style=", 0) != -1) {
+ s = QString::fromLocal8Bit(arg.right(arg.length() - 7).toLower());
+ } else if (arg == "-style" && i < argc-1) {
+ s = QString::fromLocal8Bit(argv[++i]).toLower();
} else {
argv[j++] = argv[i];
}
+
+ if (!s.isEmpty())
+ styleOverride = s;
}
if (j < argc) {
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index 7d8deab507..4d5797a8fa 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -221,6 +221,7 @@ public:
static QFont *app_font;
+ static QString styleOverride;
static QStyleHints *styleHints;
static bool obey_desktop_settings;
QInputMethod *inputMethod;
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index ea3b75c81c..8757715c0d 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -484,7 +484,9 @@ QPlatformScreen *QPlatformWindow::screenForGeometry(const QRect &newGeometry) co
{
QPlatformScreen *currentScreen = screen();
QPlatformScreen *fallback = currentScreen;
- QPoint center = newGeometry.center();
+ //QRect::center can return a value outside the rectangle if it's empty
+ const QPoint center = newGeometry.isEmpty() ? newGeometry.topLeft() : newGeometry.center();
+
if (!parent() && currentScreen && !currentScreen->geometry().contains(center)) {
Q_FOREACH (QPlatformScreen* screen, currentScreen->virtualSiblings()) {
if (screen->geometry().contains(center))
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index 5c1cd8adef..52843fa113 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -379,9 +379,9 @@ static const uint *QT_FASTCALL convertARGBPMFromARGB32PM(uint *buffer, const uin
template<QImage::Format Format> Q_DECL_CONSTEXPR static inline QPixelLayout pixelLayoutRGB()
{
return QPixelLayout{
- redWidth<Format>(), redShift<Format>(),
- greenWidth<Format>(), greenShift<Format>(),
- blueWidth<Format>(), blueShift<Format>(),
+ uchar(redWidth<Format>()), uchar(redShift<Format>()),
+ uchar(greenWidth<Format>()), uchar(greenShift<Format>()),
+ uchar(blueWidth<Format>()), uchar(blueShift<Format>()),
0, 0,
false, bitsPerPixel<Format>(),
convertToRGB32<Format>,
@@ -394,10 +394,10 @@ template<QImage::Format Format> Q_DECL_CONSTEXPR static inline QPixelLayout pixe
template<QImage::Format Format> Q_DECL_CONSTEXPR static inline QPixelLayout pixelLayoutARGBPM()
{
return QPixelLayout{
- redWidth<Format>(), redShift<Format>(),
- greenWidth<Format>(), greenShift<Format>(),
- blueWidth<Format>(), blueShift<Format>(),
- alphaWidth<Format>(), alphaShift<Format>(),
+ uchar(redWidth<Format>()), uchar(redShift<Format>()),
+ uchar(greenWidth<Format>()), uchar(greenShift<Format>()),
+ uchar(blueWidth<Format>()), uchar(blueShift<Format>()),
+ uchar(alphaWidth<Format>()), uchar(alphaShift<Format>()),
true, bitsPerPixel<Format>(),
convertARGBPMToARGB32PM<Format>,
convertARGBPMFromARGB32PM<Format>,
diff --git a/src/gui/painting/qrgba64.h b/src/gui/painting/qrgba64.h
index 264ec394cd..fab9506ff2 100644
--- a/src/gui/painting/qrgba64.h
+++ b/src/gui/painting/qrgba64.h
@@ -161,12 +161,12 @@ public:
}
private:
- static Q_DECL_CONSTEXPR quint64 alphaMask() { return Q_UINT64_C(0xffff) << AlphaShift; }
+ static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE quint64 alphaMask() { return Q_UINT64_C(0xffff) << AlphaShift; }
- static Q_DECL_CONSTEXPR uint div_257_floor(uint x) { return (x - (x >> 8)) >> 8; }
- static Q_DECL_CONSTEXPR uint div_257(uint x) { return div_257_floor(x + 128); }
- static Q_DECL_CONSTEXPR uint div_65535(uint x) { return (x + (x>>16) + 0x8000U) >> 16; }
- Q_DECL_RELAXED_CONSTEXPR QRgba64 unpremultiplied_32bit() const
+ static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint div_257_floor(uint x) { return (x - (x >> 8)) >> 8; }
+ static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint div_257(uint x) { return div_257_floor(x + 128); }
+ static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint div_65535(uint x) { return (x + (x>>16) + 0x8000U) >> 16; }
+ Q_DECL_RELAXED_CONSTEXPR Q_ALWAYS_INLINE QRgba64 unpremultiplied_32bit() const
{
if (isOpaque() || isTransparent())
return *this;
@@ -176,7 +176,7 @@ private:
const quint16 b = (quint32(blue()) * 0xffff + a/2) / a;
return fromRgba64(r, g, b, a);
}
- Q_DECL_RELAXED_CONSTEXPR QRgba64 unpremultiplied_64bit() const
+ Q_DECL_RELAXED_CONSTEXPR Q_ALWAYS_INLINE QRgba64 unpremultiplied_64bit() const
{
if (isOpaque() || isTransparent())
return *this;
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index a0eedee6b9..f267b2d147 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -370,17 +370,15 @@ bool QFontEngine::supportsScript(QChar::Script script) const
return true;
}
-#ifdef Q_OS_MAC
- {
+#ifdef QT_ENABLE_HARFBUZZ_NG
+ if (qt_useHarfbuzzNG()) {
+#if defined(Q_OS_DARWIN)
// in AAT fonts, 'gsub' table is effectively replaced by 'mort'/'morx' table
uint len;
if (getSfntTableData(MAKE_TAG('m','o','r','t'), 0, &len) || getSfntTableData(MAKE_TAG('m','o','r','x'), 0, &len))
return true;
- }
#endif
-#ifdef QT_ENABLE_HARFBUZZ_NG
- if (qt_useHarfbuzzNG()) {
bool ret = false;
if (hb_face_t *face = hb_qt_face_get_for_engine(const_cast<QFontEngine *>(this))) {
hb_tag_t script_tag_1, script_tag_2;
@@ -1837,7 +1835,10 @@ QFontEngine *QFontEngineMulti::loadEngine(int at)
request.family = fallbackFamilyAt(at - 1);
if (QFontEngine *engine = QFontDatabase::findFont(request, m_script)) {
- engine->fontDef = request;
+ if (request.weight > QFont::Normal)
+ engine->fontDef.weight = request.weight;
+ if (request.style > QFont::StyleNormal)
+ engine->fontDef.style = request.style;
return engine;
}
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index 0d28785aa1..8dfabd48ad 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -534,69 +534,87 @@ QFontEngineFT::Glyph::~Glyph()
delete [] data;
}
-static const uint subpixel_filter[3][3] = {
- { 180, 60, 16 },
- { 38, 180, 38 },
- { 16, 60, 180 }
+struct LcdFilterDummy
+{
+ static inline void filterPixel(uchar &, uchar &, uchar &)
+ {}
};
-static inline uint filterPixel(uint red, uint green, uint blue, bool legacyFilter)
+struct LcdFilterLegacy
{
- uint res;
- if (legacyFilter) {
- uint high = (red*subpixel_filter[0][0] + green*subpixel_filter[0][1] + blue*subpixel_filter[0][2]) >> 8;
- uint mid = (red*subpixel_filter[1][0] + green*subpixel_filter[1][1] + blue*subpixel_filter[1][2]) >> 8;
- uint low = (red*subpixel_filter[2][0] + green*subpixel_filter[2][1] + blue*subpixel_filter[2][2]) >> 8;
- res = (mid << 24) + (high << 16) + (mid << 8) + low;
- } else {
- uint alpha = green;
- res = (alpha << 24) + (red << 16) + (green << 8) + blue;
+ static inline void filterPixel(uchar &red, uchar &green, uchar &blue)
+ {
+ uint r = red, g = green, b = blue;
+ // intra-pixel filter used by the legacy filter (adopted from _ft_lcd_filter_legacy)
+ red = (r * uint(65538 * 9/13) + g * uint(65538 * 1/6) + b * uint(65538 * 1/13)) / 65536;
+ green = (r * uint(65538 * 3/13) + g * uint(65538 * 4/6) + b * uint(65538 * 3/13)) / 65536;
+ blue = (r * uint(65538 * 1/13) + g * uint(65538 * 1/6) + b * uint(65538 * 9/13)) / 65536;
}
- return res;
-}
+};
-static void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter)
+template <typename LcdFilter>
+static void convertRGBToARGB_helper(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr)
{
- int h = height;
const int offs = bgr ? -1 : 1;
const int w = width * 3;
- while (h--) {
+ while (height--) {
uint *dd = dst;
for (int x = 0; x < w; x += 3) {
- uint red = src[x+1-offs];
- uint green = src[x+1];
- uint blue = src[x+1+offs];
- *dd = filterPixel(red, green, blue, legacyFilter);
- ++dd;
+ uchar red = src[x + 1 - offs];
+ uchar green = src[x + 1];
+ uchar blue = src[x + 1 + offs];
+ LcdFilter::filterPixel(red, green, blue);
+ // alpha = green
+ *dd++ = (green << 24) | (red << 16) | (green << 8) | blue;
}
dst += width;
src += src_pitch;
}
}
-static void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter)
+static inline void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter)
+{
+ if (!legacyFilter)
+ convertRGBToARGB_helper<LcdFilterDummy>(src, dst, width, height, src_pitch, bgr);
+ else
+ convertRGBToARGB_helper<LcdFilterLegacy>(src, dst, width, height, src_pitch, bgr);
+}
+
+template <typename LcdFilter>
+static void convertRGBToARGB_V_helper(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr)
{
- int h = height;
const int offs = bgr ? -src_pitch : src_pitch;
- while (h--) {
+ while (height--) {
for (int x = 0; x < width; x++) {
- uint red = src[x+src_pitch-offs];
- uint green = src[x+src_pitch];
- uint blue = src[x+src_pitch+offs];
- dst[x] = filterPixel(red, green, blue, legacyFilter);
+ uchar red = src[x + src_pitch - offs];
+ uchar green = src[x + src_pitch];
+ uchar blue = src[x + src_pitch + offs];
+ LcdFilter::filterPixel(red, green, blue);
+ // alpha = green
+ *dst++ = (green << 24) | (red << 16) | (green << 8) | blue;
}
- dst += width;
src += 3*src_pitch;
}
}
-static void convertGRAYToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch) {
- for (int y = 0; y < height; ++y) {
- int readpos = (y * src_pitch);
- int writepos = (y * width);
- for (int x = 0; x < width; ++x) {
- dst[writepos + x] = (0xFF << 24) + (src[readpos + x] << 16) + (src[readpos + x] << 8) + src[readpos + x];
+static inline void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter)
+{
+ if (!legacyFilter)
+ convertRGBToARGB_V_helper<LcdFilterDummy>(src, dst, width, height, src_pitch, bgr);
+ else
+ convertRGBToARGB_V_helper<LcdFilterLegacy>(src, dst, width, height, src_pitch, bgr);
+}
+
+static inline void convertGRAYToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch)
+{
+ while (height--) {
+ const uchar *p = src;
+ const uchar * const e = p + width;
+ while (p < e) {
+ uchar gray = *p++;
+ *dst++ = (0xFF << 24) | (gray << 16) | (gray << 8) | gray;
}
+ src += src_pitch;
}
}
diff --git a/src/gui/text/qharfbuzzng.cpp b/src/gui/text/qharfbuzzng.cpp
index 102c62ea8a..b2edfc00a0 100644
--- a/src/gui/text/qharfbuzzng.cpp
+++ b/src/gui/text/qharfbuzzng.cpp
@@ -188,7 +188,15 @@ static const hb_script_t _qtscript_to_hbscript[] = {
HB_SCRIPT_SIDDHAM,
HB_SCRIPT_KHUDAWADI,
HB_SCRIPT_TIRHUTA,
- HB_SCRIPT_WARANG_CITI
+ HB_SCRIPT_WARANG_CITI,
+
+ // Unicode 8.0 additions
+ HB_SCRIPT_AHOM,
+ HB_SCRIPT_ANATOLIAN_HIEROGLYPHS,
+ HB_SCRIPT_HATRAN,
+ HB_SCRIPT_MULTANI,
+ HB_SCRIPT_OLD_HUNGARIAN,
+ HB_SCRIPT_SIGNWRITING
};
Q_STATIC_ASSERT(QChar::ScriptCount == sizeof(_qtscript_to_hbscript) / sizeof(_qtscript_to_hbscript[0]));
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 6b98c14205..50a242d81e 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1120,15 +1120,6 @@ QT_BEGIN_INCLUDE_NAMESPACE
QT_END_INCLUDE_NAMESPACE
-#if defined(Q_OS_OSX) && !defined(QT_NO_FREETYPE)
-static const char *s_shapersForOsxFreeType[] =
-{
- "ot",
- "fallback",
- Q_NULLPTR
-};
-#endif
-
int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *string, int itemLength, QFontEngine *fontEngine, const QVector<uint> &itemBoundaries, bool kerningEnabled) const
{
uint glyphs_shaped = 0;
@@ -1182,13 +1173,21 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st
const int num_features = 1;
const char *const *shaper_list = Q_NULLPTR;
-#if defined(Q_OS_OSX) && !defined(QT_NO_FREETYPE)
- // What's behind QFontEngine::FaceData::user_data isn't compatible between CoreText and
- // FreeType font engines - specifically functions in hb-coretext.cc would run into undefined
- // behavior with data from the FreeType engine. The OpenType shaper works with that engine.
- if (actualFontEngine->type() == QFontEngine::Freetype)
- shaper_list = s_shapersForOsxFreeType;
+#if defined(Q_OS_DARWIN)
+ // What's behind QFontEngine::FaceData::user_data isn't compatible between different font engines
+ // - specifically functions in hb-coretext.cc would run into undefined behavior with data
+ // from non-CoreText engine. The other shapers works with that engine just fine.
+ if (actualFontEngine->type() != QFontEngine::Mac) {
+ static const char *s_shaper_list_without_coretext[] = {
+ "graphite2",
+ "ot",
+ "fallback",
+ Q_NULLPTR
+ };
+ shaper_list = s_shaper_list_without_coretext;
+ }
#endif
+
bool shapedOk = hb_shape_full(hb_font, buffer, features, num_features, shaper_list);
if (Q_UNLIKELY(!shapedOk)) {
hb_buffer_destroy(buffer);
@@ -1268,19 +1267,20 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st
g.glyphs[i] |= (engineIdx << 24);
}
-#ifdef Q_OS_MAC
- // CTRunGetPosition has a bug which applies matrix on 10.6, so we disable
- // scaling the advances for this particular version
- if (actualFontEngine->fontDef.stretch != 100
- && QSysInfo::MacintoshVersion != QSysInfo::MV_10_6) {
- QFixed stretch = QFixed(int(actualFontEngine->fontDef.stretch)) / QFixed(100);
- for (uint i = 0; i < num_glyphs; ++i)
- g.advances[i] *= stretch;
- }
+#ifdef Q_OS_DARWIN
+ if (actualFontEngine->type() == QFontEngine::Mac) {
+ // CTRunGetPosition has a bug which applies matrix on 10.6, so we disable
+ // scaling the advances for this particular version
+ if (QSysInfo::MacintoshVersion != QSysInfo::MV_10_6 && actualFontEngine->fontDef.stretch != 100) {
+ QFixed stretch = QFixed(int(actualFontEngine->fontDef.stretch)) / QFixed(100);
+ for (uint i = 0; i < num_glyphs; ++i)
+ g.advances[i] *= stretch;
+ }
- if (actualFontEngine->fontDef.styleStrategy & QFont::ForceIntegerMetrics) {
- for (uint i = 0; i < num_glyphs; ++i)
- g.advances[i] = g.advances[i].round();
+ if (actualFontEngine->fontDef.styleStrategy & QFont::ForceIntegerMetrics) {
+ for (uint i = 0; i < num_glyphs; ++i)
+ g.advances[i] = g.advances[i].round();
+ }
}
#endif
diff --git a/src/gui/text/qtextimagehandler.cpp b/src/gui/text/qtextimagehandler.cpp
index 686a00e42a..d7a418e7c8 100644
--- a/src/gui/text/qtextimagehandler.cpp
+++ b/src/gui/text/qtextimagehandler.cpp
@@ -45,8 +45,10 @@
QT_BEGIN_NAMESPACE
-extern QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio);
-static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePixelRatio)
+extern QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
+ qreal *sourceDevicePixelRatio);
+static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePixelRatio,
+ qreal *sourceDevicePixelRatio)
{
// We might use the fileName for loading if url loading fails
// try to make sure it is a valid file path.
@@ -65,7 +67,7 @@ static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePi
return fileName;
// try to find a Nx version
- return qt_findAtNxFile(fileName, targetDevicePixelRatio);
+ return qt_findAtNxFile(fileName, targetDevicePixelRatio, sourceDevicePixelRatio);
}
@@ -77,7 +79,8 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, con
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources and convert them to url
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl(name);
- name = resolveFileName(name, &url, devicePixelRatio);
+ qreal sourcePixelRatio = 1.0;
+ name = resolveFileName(name, &url, devicePixelRatio, &sourcePixelRatio);
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Pixmap || data.type() == QVariant::Image) {
pm = qvariant_cast<QPixmap>(data);
@@ -103,7 +106,7 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, con
}
if (name.contains(QStringLiteral("@2x")))
- pm.setDevicePixelRatio(2.0);
+ pm.setDevicePixelRatio(sourcePixelRatio);
return pm;
}
@@ -158,7 +161,8 @@ static QImage getImage(QTextDocument *doc, const QTextImageFormat &format, const
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl(name);
- name = resolveFileName(name, &url, devicePixelRatio);
+ qreal sourcePixelRatio = 1.0;
+ name = resolveFileName(name, &url, devicePixelRatio, &sourcePixelRatio);
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Image) {
image = qvariant_cast<QImage>(data);
@@ -182,8 +186,8 @@ static QImage getImage(QTextDocument *doc, const QTextImageFormat &format, const
doc->addResource(QTextDocument::ImageResource, url, image);
}
- if (name.contains(QStringLiteral("@2x")))
- image.setDevicePixelRatio(2.0);
+ if (sourcePixelRatio != 1.0)
+ image.setDevicePixelRatio(sourcePixelRatio);
return image;
}