diff --git a/src/gui/image/qpaintengine_pic.cpp b/src/gui/image/qpaintengine_pic.cpp
index d450d82..d0dd56b 100644
--- a/src/gui/image/qpaintengine_pic.cpp
+++ b/src/gui/image/qpaintengine_pic.cpp
@@ -48,7 +48,7 @@
 #include "qrect.h"
 #include <private/qtextengine_p.h>
 
-//#define QT_PICTURE_DEBUG
+#define QT_PICTURE_DEBUG
 #include <qdebug.h>
 
 
@@ -472,13 +472,15 @@ void QPicturePaintEngine::drawImage(const QRectF &r, const QImage &image, const
 void QPicturePaintEngine::drawTextItem(const QPointF &p , const QTextItem &ti)
 {
     Q_D(QPicturePaintEngine);
-#ifdef QT_PICTURE_DEBUG
-    qDebug() << " -> drawTextItem():" << p << ti.text();
-#endif
 
     const QTextItemInt &si = static_cast<const QTextItemInt &>(ti);
-    if (si.chars == 0)
+    qDebug() << __FUNCTION__ << p << ti
+             <<  ti.font() << "FDPI" <<  ti.font().d->dpi << '>';
+    if (si.chars == 0) {
+        qDebug() << ">Draw as path";
         QPaintEngine::drawTextItem(p, ti); // Draw as path
+        qDebug() << "<Draw as path";
+    }
 
     if (d->pic_d->formatMajor >= 9) {
         int pos;
@@ -507,6 +509,7 @@ void QPicturePaintEngine::drawTextItem(const QPointF &p , const QTextItem &ti)
         d->s << p << ti.text();
         writeCmdLength(pos, QRectF(p, QSizeF(1,1)), true);
     }
+    qDebug() << __FUNCTION__ << '<';
 }
 
 void QPicturePaintEngine::updateState(const QPaintEngineState &state)
diff --git a/src/gui/painting/qpaintdevice.cpp b/src/gui/painting/qpaintdevice.cpp
index a4daa98..20ed6bf 100644
--- a/src/gui/painting/qpaintdevice.cpp
+++ b/src/gui/painting/qpaintdevice.cpp
@@ -32,7 +32,7 @@
 ****************************************************************************/
 
 #include "qpaintdevice.h"
-
+#include <qdebug.h>
 QT_BEGIN_NAMESPACE
 
 QPaintDevice::QPaintDevice()
@@ -56,6 +56,15 @@ void QPaintDevice::initPainter(QPainter *) const
 {
 }
 
+QDebug operator<<(QDebug debug, const QPaintDevice &d)
+{
+    debug << "QPaintDevice(" << &d << "devicePixelRatio=" << d.devicePixelRatio()
+      << "devType=" << d.devType()
+      << "logDPI" << d.logicalDpiX() << d.logicalDpiY()
+      << "physDPI" << d.physicalDpiX() << d.physicalDpiY() << ')';
+    return debug;
+}
+
 /*!
     \internal
 */
diff --git a/src/gui/painting/qpaintdevice.h b/src/gui/painting/qpaintdevice.h
index bec89dc..5afc3cc 100644
--- a/src/gui/painting/qpaintdevice.h
+++ b/src/gui/painting/qpaintdevice.h
@@ -39,7 +39,7 @@
 
 QT_BEGIN_NAMESPACE
 
-
+class QDebug;
 
 class QPaintEngine;
 class QPaintDevicePrivate;
@@ -100,6 +100,8 @@ private:
     friend Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, PaintDeviceMetric metric);
 };
 
+Q_GUI_EXPORT QDebug operator<<(QDebug, const QPaintDevice &);
+
 /*****************************************************************************
   Inline functions
  *****************************************************************************/
diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp
index 4e70564..fb8e957 100644
--- a/src/gui/painting/qpaintengine.cpp
+++ b/src/gui/painting/qpaintengine.cpp
@@ -741,12 +741,14 @@ void QPaintEngine::drawPath(const QPainterPath &)
 
 void QPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
 {
+    qDebug() << __FUNCTION__ << p << textItem << '>';
     const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
 
     QPainterPath path;
     path.setFillRule(Qt::WindingFill);
     if (ti.glyphs.numGlyphs)
         ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags);
+    qDebug() << __FUNCTION__ << "path.isEmpty=" << path.isEmpty();
     if (!path.isEmpty()) {
         painter()->save();
         painter()->setRenderHint(QPainter::Antialiasing,
@@ -756,6 +758,7 @@ void QPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
         painter()->fillPath(path, painter()->pen().brush());
         painter()->restore();
     }
+    qDebug() << __FUNCTION__ << '<';
 }
 
 /*!
diff --git a/src/gui/painting/qpaintengine.h b/src/gui/painting/qpaintengine.h
index b56e4eb..0a7d9aa 100644
--- a/src/gui/painting/qpaintengine.h
+++ b/src/gui/painting/qpaintengine.h
@@ -75,6 +75,7 @@ public:
 };
 Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE);
 
+Q_GUI_EXPORT QDebug operator<<(QDebug d, const QTextItem &t);
 
 class Q_GUI_EXPORT QPaintEngine
 {
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index d40a2b9..4f91f34 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -35,6 +35,7 @@
 #include <qdebug.h>
 #include <qmath.h>
 #include <qmutex.h>
+#include <qdebug.h>
 
 // QtGui
 #include "qbitmap.h"
@@ -1574,6 +1575,7 @@ void QPainter::save()
         return;
     }
 
+    qDebug() << __FUNCTION__ << "d->extended" << d->extended;
     if (d->extended) {
         d->state = d->extended->createState(d->states.back());
         d->extended->setState(d->state);
@@ -1612,6 +1614,7 @@ void QPainter::restore()
     d->state = d->states.back();
     d->txinv = false;
 
+    qDebug() << __FUNCTION__ << "d->extended" << d->extended;
     if (d->extended) {
         d->checkEmulation();
         d->extended->setState(d->state);
@@ -5833,6 +5836,7 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText
 */
 void QPainter::drawText(const QPointF &p, const QString &str, int tf, int justificationPadding)
 {
+//    qDebug() << __FUNCTION__ << p << str << tf << justificationPadding;
 #ifdef QT_DEBUG_DRAW
     if (qt_show_painter_debug_output)
         printf("QPainter::drawText(), pos=[%.2f,%.2f], str='%s'\n", p.x(), p.y(), str.toLatin1().constData());
@@ -6340,6 +6344,7 @@ void QPainter::drawTextItem(const QPointF &p, const QTextItem &ti)
 
 void QPainterPrivate::drawTextItem(const QPointF &p, const QTextItem &_ti, QTextEngine *textEngine)
 {
+//    qDebug() << __FUNCTION__ << p << _ti.text();
 #ifdef QT_DEBUG_DRAW
     if (qt_show_painter_debug_output)
         printf("QPainter::drawTextItem(), pos=[%.f,%.f], str='%s'\n",
@@ -6368,6 +6373,7 @@ void QPainterPrivate::drawTextItem(const QPointF &p, const QTextItem &_ti, QText
 
         bool aa = true;
         const QTransform &m = state->matrix;
+//        qDebug() << __FUNCTION__ << m;
         if (state->matrix.type() < QTransform::TxShear) {
             bool isPlain90DegreeRotation =
                 (qFuzzyIsNull(m.m11())
@@ -7689,6 +7695,27 @@ void QPainterState::init(QPainter *p) {
     opacity = 1;
 }
 
+QDebug operator<<(QDebug d, const QPainterState &s)
+{
+    d << "QPainterState clipRegion=" << s.clipRegion
+      << "clipOperation=" <<s.clipOperation
+      << "renderHints=" << s.renderHints
+      << "worldMatrix=" << s.worldMatrix
+      << "matrix=" << s.matrix
+      << "redirectionMatrix=" << s.redirectionMatrix
+      << "Viewport" << s.vx << s.vy << s.vw << s.vh
+      << "Window" << s.wx << s.wy << s.ww << s.wh
+      << "opacity" << s.opacity
+      << "World transform" << s.WxF
+      << "View transform" << s.VxF
+      << "clipEnabled=" << s.clipEnabled
+      << "bgMode=" << s.bgMode
+      << "painter=" << s.painter
+      << "composition_mode=" <<s.composition_mode
+      << "changeFlags=" << s.changeFlags;
+    return d;
+}
+
 /*!
     \fn void QPainter::drawImage(const QRectF &target, const QImage &image, const QRectF &source,
                          Qt::ImageConversionFlags flags)
diff --git a/src/gui/painting/qpainter_p.h b/src/gui/painting/qpainter_p.h
index f8dcfbf..1adde7f 100644
--- a/src/gui/painting/qpainter_p.h
+++ b/src/gui/painting/qpainter_p.h
@@ -63,6 +63,7 @@ class QPaintEngine;
 class QEmulationPaintEngine;
 class QPaintEngineEx;
 struct QFixedPoint;
+class QDebug;
 
 struct QTLWExtra;
 
@@ -168,6 +169,8 @@ public:
     uint changeFlags;
 };
 
+Q_GUI_EXPORT QDebug operator<<(QDebug d, const QPainterState &);
+
 struct QPainterDummyState
 {
     QFont font;
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index d156124..37e36d6 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -55,6 +55,21 @@ QT_BEGIN_NAMESPACE
 
 static const float smallCapsFraction = 0.7f;
 
+QDebug operator<<(QDebug d, const QTextItem &t)
+{
+    const QTextItemInt &ti = static_cast<const QTextItemInt &>(t);
+    qDebug() << "descent=" << ti.descent
+            << "ascent=" << ti.ascent
+            << "width=" << ti.width
+            << "flags" << ti.flags
+            <<  "num_chars=" << ti.num_chars
+            << "chars=" << ti.chars
+            << "logClusters=" << ti.logClusters
+            << "font" << ti.f
+            << "QGlyphLayout:" << ti.glyphs.numGlyphs;
+    return d;
+}
+
 namespace {
 // Helper class used in QTextEngine::itemize
 // keep it out here to allow us to keep supporting various compilers.
diff --git a/src/printsupport/kernel/qpaintengine_alpha.cpp b/src/printsupport/kernel/qpaintengine_alpha.cpp
index 60876ff..b44b690 100644
--- a/src/printsupport/kernel/qpaintengine_alpha.cpp
+++ b/src/printsupport/kernel/qpaintengine_alpha.cpp
@@ -35,6 +35,7 @@
 
 #ifndef QT_NO_PRINTER
 #include <qdebug.h>
+#include <qpaintdevice.h>
 #include "private/qpaintengine_alpha_p.h"
 
 #include "private/qpainter_p.h"
@@ -58,6 +59,7 @@ QAlphaPaintEngine::~QAlphaPaintEngine()
 bool QAlphaPaintEngine::begin(QPaintDevice *pdev)
 {
     Q_D(QAlphaPaintEngine);
+    qDebug() << __FUNCTION__ << *pdev;
 
     d->m_continueCall = true;
     if (d->m_pass != 0) {
@@ -102,15 +104,20 @@ bool QAlphaPaintEngine::end()
 
 void QAlphaPaintEngine::updateState(const QPaintEngineState &state)
 {
+    qDebug() << __FUNCTION__ << ">";
     Q_D(QAlphaPaintEngine);
 
     DirtyFlags flags = state.state();
     if (flags & QPaintEngine::DirtyTransform) {
+        qDebug() << "DirtyTransform";
         d->m_transform = state.transform();
         d->m_complexTransform = (d->m_transform.type() > QTransform::TxScale);
         d->m_emulateProjectiveTransforms = !(d->m_savedcaps & QPaintEngine::PerspectiveTransform)
                                            && !(d->m_savedcaps & QPaintEngine::AlphaBlend)
                                            && (d->m_transform.type() >= QTransform::TxProject);
+        qDebug() << "resulting d->m_transform=" << d->m_transform
+                 << "d->m_complexTransform=" << d->m_complexTransform
+                 <<  "d->m_emulateProjectiveTransforms" <<  d->m_emulateProjectiveTransforms;
     }
     if (flags & QPaintEngine::DirtyPen) {
         d->m_pen = state.pen();
@@ -148,6 +155,7 @@ void QAlphaPaintEngine::updateState(const QPaintEngineState &state)
 
     if (d->m_picengine)
         d->m_picengine->updateState(state);
+    qDebug() << __FUNCTION__ << "<";
 }
 
 void QAlphaPaintEngine::drawPath(const QPainterPath &path)
@@ -204,6 +212,7 @@ void QAlphaPaintEngine::drawPolygon(const QPointF *points, int pointCount, Polyg
 
 void QAlphaPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
 {
+    qDebug() << __FUNCTION__ << r << pm << sr;
     Q_D(QAlphaPaintEngine);
 
     QRectF tr = d->m_transform.mapRect(r);
@@ -229,6 +238,9 @@ void QAlphaPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem
 
     QRectF tr(p.x(), p.y() - textItem.ascent(), textItem.width() + 5, textItem.ascent() + textItem.descent() + 5);
     tr = d->m_transform.mapRect(tr);
+    qDebug() << __FUNCTION__ << p << textItem.text()
+             << "textItem.width=" << textItem.width()
+             << "tr=" << tr;
 
     if (d->m_pass == 0) {
         d->m_continueCall = false;
@@ -282,6 +294,7 @@ bool QAlphaPaintEngine::continueCall() const
 void QAlphaPaintEngine::flushAndInit(bool init)
 {
     Q_D(QAlphaPaintEngine);
+    qDebug() << __FUNCTION__ << "init=" << init <<"d->m_pic=" << d->m_pic;
     Q_ASSERT(d->m_pass == 0);
 
     if (d->m_pic) {
@@ -314,6 +327,8 @@ void QAlphaPaintEngine::flushAndInit(bool init)
         QTransform mtx;
         mtx.scale(1.0f / (qreal(d->m_pdev->logicalDpiX()) / qreal(qt_defaultDpiX())),
                   1.0f / (qreal(d->m_pdev->logicalDpiY()) / qreal(qt_defaultDpiY())));
+        qDebug() << __FUNCTION__  << "mtx=" << mtx
+                 << "on" << *d->m_pdev << rects;
         painter()->setTransform(mtx);
         painter()->drawPicture(0, 0, *d->m_pic);
 
@@ -339,6 +354,7 @@ void QAlphaPaintEngine::flushAndInit(bool init)
         d->m_pic = new QPicture();
         d->m_pic->d_ptr->in_memory_only = true;
         d->m_picpainter = new QPainter(d->m_pic);
+        qDebug() << __FUNCTION__ << "creating new picture";
         d->m_picengine = d->m_picpainter->paintEngine();
 
         // When newPage() is called and the m_picpainter is recreated
@@ -351,15 +367,19 @@ void QAlphaPaintEngine::flushAndInit(bool init)
         d->m_picpainter->setOpacity(painter()->opacity());
         d->m_picpainter->setTransform(painter()->combinedTransform());
         d->m_picengine->syncState();
-        QPainterState &state = *d->m_picpainter->d_func()->state;
-        QPainter *oldPainter = state.painter;
-        state = *painter()->d_func()->state;
-        state.painter = oldPainter;
+        if (qEnvironmentVariableIsSet("FIX")) {
+            qDebug() << "FIX: Assigning state to m_picpainter" << *painter()->d_func()->state;
+            QPainterState &state = *d->m_picpainter->d_func()->state;
+            state = *painter()->d_func()->state;
+        } else {
+            qDebug() << "NOT assigning state to m_picpainter";
+        }
     }
 }
 
 void QAlphaPaintEngine::cleanUp()
 {
+    qDebug() << __FUNCTION__ ;
     Q_D(QAlphaPaintEngine);
 
     delete d->m_picpainter;
