freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master 1a36939: [ftinspect] Fix pixel box drawing.


From: Werner LEMBERG
Subject: [freetype2-demos] master 1a36939: [ftinspect] Fix pixel box drawing.
Date: Mon, 6 Jun 2016 07:45:38 +0000 (UTC)

branch: master
commit 1a369399f408bda589ce4ef34aa2d7fc3e724bc4
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    [ftinspect] Fix pixel box drawing.
    
    This commit circumvents a problem with Qt's `QPainter::drawImage'
    function; it seems that the alignment of the output becomes
    imprecise at high magnification values.
    
    * src/ftinspect.c (GlyphBitmap::paint): Manually draw pixel boxes
    with `fillRect'.
---
 ChangeLog         |   11 +++++++++++
 src/ftinspect.cpp |   27 ++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 4d8ff1f..c8565a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2016-06-26  Werner Lemberg  <address@hidden>
+
+       [ftinspect] Fix pixel box drawing.
+
+       This commit circumvents a problem with Qt's `QPainter::drawImage'
+       function; it seems that the alignment of the output becomes
+       imprecise at high magnification values.
+
+       * src/ftinspect.c (GlyphBitmap::paint): Manually draw pixel boxes
+       with `fillRect'.
+
 2016-05-29  Werner Lemberg  <address@hidden>
 
        * src/ftbench.c (main): Add cast to remove compiler warning.
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index 795b421..6f68255 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -1182,7 +1182,7 @@ GlyphBitmap::boundingRect() const
 
 void
 GlyphBitmap::paint(QPainter* painter,
-                   const QStyleOptionGraphicsItem*,
+                   const QStyleOptionGraphicsItem* option,
                    QWidget*)
 {
   FT_Bitmap bitmap;
@@ -1219,9 +1219,34 @@ GlyphBitmap::paint(QPainter* painter,
     return;
   }
 
+  // `drawImage' doesn't work as expected:
+  // the larger the zoom, the more the pixel rectangle positions
+  // deviate from the grid lines
+#if 0
   painter->drawImage(QPoint(bRect.left(), bRect.top()),
                      image.convertToFormat(
                        QImage::Format_ARGB32_Premultiplied));
+#else
+  const qreal lod = option->levelOfDetailFromTransform(
+                              painter->worldTransform());
+
+  painter->setPen(Qt::NoPen);
+
+  for (int x = 0; x < image.width(); x++)
+    for (int y = 0; y < image.height(); y++)
+    {
+      // be careful not to lose the alpha channel
+      QRgb p = image.pixel(x, y);
+      painter->fillRect(QRectF(x + bRect.left() - 1 / lod / 2,
+                               y + bRect.top() - 1 / lod / 2,
+                               1 + 1 / lod,
+                               1 + 1 / lod),
+                        QColor(qRed(p),
+                               qGreen(p),
+                               qBlue(p),
+                               qAlpha(p)));
+    }
+#endif
 }
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]