[poppler] 2 commits - qt4/src qt4/tests qt5/src qt5/tests

Albert Astals Cid aacid at kemper.freedesktop.org
Thu Dec 12 14:13:46 PST 2013


 qt4/src/ArthurOutputDev.cc        |   18 ++++-----
 qt4/tests/CMakeLists.txt          |    1 
 qt4/tests/Makefile.am             |    8 +++-
 qt4/tests/test-render-to-file.cpp |   69 ++++++++++++++++++++++++++++++++++++++
 qt5/src/ArthurOutputDev.cc        |   18 ++++-----
 qt5/tests/CMakeLists.txt          |    1 
 qt5/tests/Makefile.am             |    8 +++-
 qt5/tests/test-render-to-file.cpp |   69 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 172 insertions(+), 20 deletions(-)

New commits:
commit 44cf2de0df351d5948893f6a4e2bca1168d16b70
Author: Dominik Haumann <dhaumann at kde.org>
Date:   Thu Dec 12 23:12:35 2013 +0100

    Arthur font rendering improvements
    
    The patch does does the following:
    - use NoPen to fill the glyphs
    - since SplashPath seems to bitwise OR stop and start of path,
      closing a subpath needs to happen before starting a path.
    
    Arthur needs serious work but this is a definite improvement in all the files i've tried it on

diff --git a/qt4/src/ArthurOutputDev.cc b/qt4/src/ArthurOutputDev.cc
index 5d57e93..914edb9 100644
--- a/qt4/src/ArthurOutputDev.cc
+++ b/qt4/src/ArthurOutputDev.cc
@@ -21,6 +21,7 @@
 // Copyright (C) 2010 Matthias Fauconneau <matthias.fauconneau at gmail.com>
 // Copyright (C) 2011 Andreas Hartmetz <ahartmetz at gmail.com>
 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2013 Dominik Haumann <dhaumann at kde.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -593,10 +594,15 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y,
       QPainterPath qPath;
       qPath.setFillRule(Qt::WindingFill);
       for (int i = 0; i < fontPath->length; ++i) {
+        // SplashPath.flags: bitwise or allowed
+        if (fontPath->flags[i] & splashPathLast || fontPath->flags[i] & splashPathClosed) {
+            qPath.closeSubpath();
+        }
         if (fontPath->flags[i] & splashPathFirst) {
             state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
             qPath.moveTo(x1,y1);
-        } else if (fontPath->flags[i] & splashPathCurve) {
+        }
+        if (fontPath->flags[i] & splashPathCurve) {
             state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
             state->transform(fontPath->pts[i+1].x+x, -fontPath->pts[i+1].y+y, &x2, &y2);
             qPath.quadTo(x1,y1,x2,y2);
@@ -610,20 +616,14 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y,
             state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
             qPath.lineTo(x1,y1);
         }
-        if (fontPath->flags[i] & splashPathLast) {
-            qPath.closeSubpath();
-        }
       }
       GfxRGB rgb;
       QColor brushColour = m_currentBrush.color();
       state->getFillRGB(&rgb);
       brushColour.setRgbF(colToDbl(rgb.r), colToDbl(rgb.g), colToDbl(rgb.b), state->getFillOpacity());
       m_painter->setBrush(brushColour);
-      QColor penColour = m_currentPen.color();
-      state->getStrokeRGB(&rgb);
-      penColour.setRgbF(colToDbl(rgb.r), colToDbl(rgb.g), colToDbl(rgb.b), state->getStrokeOpacity());
-      m_painter->setPen(penColour);
-      m_painter->drawPath( qPath );
+      m_painter->setPen(Qt::NoPen);
+      m_painter->drawPath(qPath);
       delete fontPath;
     }
   }
diff --git a/qt5/src/ArthurOutputDev.cc b/qt5/src/ArthurOutputDev.cc
index 5d57e93..914edb9 100644
--- a/qt5/src/ArthurOutputDev.cc
+++ b/qt5/src/ArthurOutputDev.cc
@@ -21,6 +21,7 @@
 // Copyright (C) 2010 Matthias Fauconneau <matthias.fauconneau at gmail.com>
 // Copyright (C) 2011 Andreas Hartmetz <ahartmetz at gmail.com>
 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2013 Dominik Haumann <dhaumann at kde.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -593,10 +594,15 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y,
       QPainterPath qPath;
       qPath.setFillRule(Qt::WindingFill);
       for (int i = 0; i < fontPath->length; ++i) {
+        // SplashPath.flags: bitwise or allowed
+        if (fontPath->flags[i] & splashPathLast || fontPath->flags[i] & splashPathClosed) {
+            qPath.closeSubpath();
+        }
         if (fontPath->flags[i] & splashPathFirst) {
             state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
             qPath.moveTo(x1,y1);
-        } else if (fontPath->flags[i] & splashPathCurve) {
+        }
+        if (fontPath->flags[i] & splashPathCurve) {
             state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
             state->transform(fontPath->pts[i+1].x+x, -fontPath->pts[i+1].y+y, &x2, &y2);
             qPath.quadTo(x1,y1,x2,y2);
@@ -610,20 +616,14 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y,
             state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
             qPath.lineTo(x1,y1);
         }
-        if (fontPath->flags[i] & splashPathLast) {
-            qPath.closeSubpath();
-        }
       }
       GfxRGB rgb;
       QColor brushColour = m_currentBrush.color();
       state->getFillRGB(&rgb);
       brushColour.setRgbF(colToDbl(rgb.r), colToDbl(rgb.g), colToDbl(rgb.b), state->getFillOpacity());
       m_painter->setBrush(brushColour);
-      QColor penColour = m_currentPen.color();
-      state->getStrokeRGB(&rgb);
-      penColour.setRgbF(colToDbl(rgb.r), colToDbl(rgb.g), colToDbl(rgb.b), state->getStrokeOpacity());
-      m_painter->setPen(penColour);
-      m_painter->drawPath( qPath );
+      m_painter->setPen(Qt::NoPen);
+      m_painter->drawPath(qPath);
       delete fontPath;
     }
   }
commit 02863f683be4543a2af6c26d53be93785d2b836a
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Dec 12 23:09:43 2013 +0100

    qt: Simple silly test program to save to file
    
    Allows us to do some quick arthur testing

diff --git a/qt4/tests/CMakeLists.txt b/qt4/tests/CMakeLists.txt
index 69e9c49..4f16f24 100644
--- a/qt4/tests/CMakeLists.txt
+++ b/qt4/tests/CMakeLists.txt
@@ -38,6 +38,7 @@ endmacro(QT4_ADD_QTEST)
 
 qt4_add_simpletest(test-poppler-qt4 test-poppler-qt4.cpp)
 qt4_add_simpletest(test-password-qt4 test-password-qt4.cpp)
+qt4_add_simpletest(test-render-to-file test-render-to-file.cpp)
 qt4_add_simpletest(poppler-forms poppler-forms.cpp)
 qt4_add_simpletest(poppler-fonts poppler-fonts.cpp)
 qt4_add_simpletest(poppler_attachments poppler-attachments.cpp)
diff --git a/qt4/tests/Makefile.am b/qt4/tests/Makefile.am
index 8efe124..4e4b210 100644
--- a/qt4/tests/Makefile.am
+++ b/qt4/tests/Makefile.am
@@ -20,7 +20,7 @@ SUFFIXES: .moc
 noinst_PROGRAMS = test-poppler-qt4 stress-poppler-qt4 \
 	poppler-fonts test-password-qt4 stress-poppler-dir \
 	poppler-attachments poppler-texts poppler-forms \
-	stress-threads-qt4
+	stress-threads-qt4 test-render-to-file
 
 
 test_poppler_qt4_SOURCES =			\
@@ -29,6 +29,12 @@ test_poppler_qt4_SOURCES =			\
 test_poppler_qt4_LDADD = $(LDADDS)
 
 
+test_render_to_file_SOURCES =			\
+       test-render-to-file.cpp
+
+test_render_to_file_LDADD = $(LDADDS)
+
+
 test_password_qt4_SOURCES =			\
        test-password-qt4.cpp
 
diff --git a/qt4/tests/test-render-to-file.cpp b/qt4/tests/test-render-to-file.cpp
new file mode 100644
index 0000000..b01aa03
--- /dev/null
+++ b/qt4/tests/test-render-to-file.cpp
@@ -0,0 +1,69 @@
+#include <QtCore/QDebug>
+#include <QtCore/QFile>
+#include <QtGui/QApplication>
+#include <QtGui/QImage>
+
+#include <poppler-qt4.h>
+
+int main( int argc, char **argv )
+{
+    QApplication a( argc, argv );               // QApplication required!
+
+    if ( argc < 2 ||
+        (argc == 3 && strcmp(argv[2], "-arthur") != 0) ||
+        argc > 3)
+    {
+        // use argument as file name
+        qWarning() << "usage: test-poppler-qt4 filename [-arthur]";
+        exit(1);
+    }
+  
+    Poppler::Document *doc = Poppler::Document::load(QFile::decodeName(argv[1]));
+    if (!doc)
+    {
+        qWarning() << "doc not loaded";
+        exit(1);
+    }
+
+    if (doc->isLocked())
+    {
+        qWarning() << "document locked (needs password)";
+        exit(0);
+    }
+  
+    if (doc->numPages() <= 0)
+    {
+        delete doc;
+        qDebug() << "Doc has no pages";
+        return 0;
+    }
+
+    QString backendString;
+    if (argc == 3 && strcmp(argv[2], "-arthur") == 0)
+    {
+        backendString = "Arthur";
+        doc->setRenderBackend(Poppler::Document::ArthurBackend);
+    }
+    else
+    {
+        backendString = "Splash";
+        doc->setRenderBackend(Poppler::Document::SplashBackend);
+    }
+    doc->setRenderHint(Poppler::Document::Antialiasing, true);
+    doc->setRenderHint(Poppler::Document::TextAntialiasing, true);
+    
+    for (int i = 0; i < doc->numPages(); ++i)
+    {
+        Poppler::Page *page = doc->page(i);
+        if (page) {
+            qDebug() << "Rendering page using" << backendString << "backend: " << i;
+            QTime t = QTime::currentTime();
+            QImage image = page->renderToImage();
+            qDebug() << "Rendering took" << t.msecsTo(QTime::currentTime()) << "msecs";
+            image.save(QString("test-rennder-to-file%1.ppm").arg(i));
+            delete page;
+        }
+    }
+    
+    return 0;
+}
diff --git a/qt5/tests/CMakeLists.txt b/qt5/tests/CMakeLists.txt
index dfeb1fb..ae0bd6c 100644
--- a/qt5/tests/CMakeLists.txt
+++ b/qt5/tests/CMakeLists.txt
@@ -47,6 +47,7 @@ endmacro(QT5_ADD_QTEST)
 
 qt5_add_simpletest(test-poppler-qt5 test-poppler-qt5.cpp)
 qt5_add_simpletest(test-password-qt5 test-password-qt5.cpp)
+qt5_add_simpletest(test-render-to-file test-render-to-file.cpp)
 qt5_add_simpletest(poppler-forms poppler-forms.cpp)
 qt5_add_simpletest(poppler-fonts poppler-fonts.cpp)
 qt5_add_simpletest(poppler_attachments poppler-attachments.cpp)
diff --git a/qt5/tests/Makefile.am b/qt5/tests/Makefile.am
index be9fa44..b3eecef 100644
--- a/qt5/tests/Makefile.am
+++ b/qt5/tests/Makefile.am
@@ -20,7 +20,7 @@ SUFFIXES: .moc
 noinst_PROGRAMS = test-poppler-qt5 stress-poppler-qt5 \
 	poppler-fonts test-password-qt5 stress-poppler-dir \
 	poppler-attachments poppler-texts poppler-forms \
-	stress-threads-qt5
+	stress-threads-qt5 test-render-to-file
 
 
 test_poppler_qt5_SOURCES =			\
@@ -29,6 +29,12 @@ test_poppler_qt5_SOURCES =			\
 test_poppler_qt5_LDADD = $(LDADDS)
 
 
+test_render_to_file_SOURCES =			\
+       test-render-to-file.cpp
+
+test_render_to_file_LDADD = $(LDADDS)
+
+
 test_password_qt5_SOURCES =			\
        test-password-qt5.cpp
 
diff --git a/qt5/tests/test-render-to-file.cpp b/qt5/tests/test-render-to-file.cpp
new file mode 100644
index 0000000..5f86da4
--- /dev/null
+++ b/qt5/tests/test-render-to-file.cpp
@@ -0,0 +1,69 @@
+#include <QtCore/QDebug>
+#include <QtCore/QFile>
+#include <QGuiApplication>
+#include <QImage>
+
+#include <poppler-qt5.h>
+
+int main( int argc, char **argv )
+{
+    QGuiApplication a( argc, argv );               // QApplication required!
+
+    if ( argc < 2 ||
+        (argc == 3 && strcmp(argv[2], "-arthur") != 0) ||
+        argc > 3)
+    {
+        // use argument as file name
+        qWarning() << "usage: test-poppler-qt4 filename [-arthur]";
+        exit(1);
+    }
+  
+    Poppler::Document *doc = Poppler::Document::load(QFile::decodeName(argv[1]));
+    if (!doc)
+    {
+        qWarning() << "doc not loaded";
+        exit(1);
+    }
+
+    if (doc->isLocked())
+    {
+        qWarning() << "document locked (needs password)";
+        exit(0);
+    }
+  
+    if (doc->numPages() <= 0)
+    {
+        delete doc;
+        qDebug() << "Doc has no pages";
+        return 0;
+    }
+
+    QString backendString;
+    if (argc == 3 && strcmp(argv[2], "-arthur") == 0)
+    {
+        backendString = "Arthur";
+        doc->setRenderBackend(Poppler::Document::ArthurBackend);
+    }
+    else
+    {
+        backendString = "Splash";
+        doc->setRenderBackend(Poppler::Document::SplashBackend);
+    }
+    doc->setRenderHint(Poppler::Document::Antialiasing, true);
+    doc->setRenderHint(Poppler::Document::TextAntialiasing, true);
+    
+    for (int i = 0; i < doc->numPages(); ++i)
+    {
+        Poppler::Page *page = doc->page(i);
+        if (page) {
+            qDebug() << "Rendering page using" << backendString << "backend: " << i;
+            QTime t = QTime::currentTime();
+            QImage image = page->renderToImage();
+            qDebug() << "Rendering took" << t.msecsTo(QTime::currentTime()) << "msecs";
+            image.save(QString("test-rennder-to-file%1.ppm").arg(i));
+            delete page;
+        }
+    }
+    
+    return 0;
+}


More information about the poppler mailing list