[poppler] qt4/src

Albert Astals Cid aacid at kemper.freedesktop.org
Thu Mar 15 12:15:02 PDT 2012


 qt4/src/CMakeLists.txt                           |    1 
 qt4/src/Makefile.am                              |    1 
 qt4/src/poppler-media.cc                         |   35 +++++++++-----
 qt4/src/poppler-media.h                          |    4 -
 qt4/src/poppler-page.cc                          |    1 
 qt4/src/poppler-streamsequentialdevice-private.h |   51 --------------------
 qt4/src/poppler-streamsequentialdevice.cc        |   56 -----------------------
 7 files changed, 26 insertions(+), 123 deletions(-)

New commits:
commit 95d684aa2a87d01296f5e93516f2ac3f54adbec8
Author: Guillermo Amaral <gamaral at kde.org>
Date:   Thu Mar 15 20:13:20 2012 +0100

    Remove the QIODevice and go with a not so good but more safer QByteArray
    
    Bug #47336

diff --git a/qt4/src/CMakeLists.txt b/qt4/src/CMakeLists.txt
index ae17376..63e0269 100644
--- a/qt4/src/CMakeLists.txt
+++ b/qt4/src/CMakeLists.txt
@@ -25,7 +25,6 @@ set(poppler_qt4_SRCS
   poppler-sound.cc
   poppler-textbox.cc
   poppler-page-transition.cc
-  poppler-streamsequentialdevice.cc
   poppler-media.cc
   ${CMAKE_SOURCE_DIR}/poppler/ArthurOutputDev.cc
 )
diff --git a/qt4/src/Makefile.am b/qt4/src/Makefile.am
index 095d000..297baa9 100644
--- a/qt4/src/Makefile.am
+++ b/qt4/src/Makefile.am
@@ -40,7 +40,6 @@ libpoppler_qt4_la_SOURCES =			\
 	poppler-private.cc			\
 	poppler-movie.cc			\
 	poppler-media.cc			\
-	poppler-streamsequentialdevice.cc	\
 	poppler-annotation-helper.h		\
 	poppler-page-private.h			\
 	poppler-link-extractor-private.h	\
diff --git a/qt4/src/poppler-media.cc b/qt4/src/poppler-media.cc
index 422aaad..c318147 100644
--- a/qt4/src/poppler-media.cc
+++ b/qt4/src/poppler-media.cc
@@ -21,7 +21,10 @@
 #include "Rendition.h"
 
 #include "poppler-private.h"
-#include "poppler-streamsequentialdevice-private.h"
+
+#include <QtCore/QBuffer>
+
+#define BUFFER_MAX 4096
 
 namespace Poppler
 {
@@ -31,26 +34,20 @@ class MediaRenditionPrivate
 public:
 
   MediaRenditionPrivate(::MediaRendition *rendition)
-  : rendition(rendition), device(0)
+  : rendition(rendition)
   {
   }
 
   ::MediaRendition *rendition;
-  QIODevice *device;
 };
 
 MediaRendition::MediaRendition(::MediaRendition *rendition)
   : d_ptr(new MediaRenditionPrivate(rendition))
 {
-  Q_D( MediaRendition );
-
-  if (d->rendition)
-     d->device = new StreamSequentialDevice(d->rendition->getEmbbededStream());
 }
 
 MediaRendition::~MediaRendition()
 {
-  delete d_ptr->device;
   delete d_ptr;
 }
 
@@ -85,11 +82,27 @@ MediaRendition::isEmbedded() const
   return d->rendition->getIsEmbedded();
 }
 
-QIODevice *
-MediaRendition::streamDevice() const
+QByteArray
+MediaRendition::data() const
 {
+  Q_ASSERT(isValid() && "Invalid media rendition.");
   Q_D( const MediaRendition );
-  return d->device;
+
+  Stream *s = d->rendition->getEmbbededStream();
+  if (!s)
+    return QByteArray();
+
+  QBuffer buffer;
+  Guchar data[BUFFER_MAX];
+  int bread;
+
+  buffer.open(QIODevice::WriteOnly);
+  s->reset();
+  while ((bread = s->doGetChars(BUFFER_MAX, data)) != 0)
+    buffer.write(reinterpret_cast<const char *>(data), bread);
+  buffer.close();
+
+  return buffer.data();
 }
 
 bool
diff --git a/qt4/src/poppler-media.h b/qt4/src/poppler-media.h
index 3b6f68d..69e74cb 100644
--- a/qt4/src/poppler-media.h
+++ b/qt4/src/poppler-media.h
@@ -60,9 +60,9 @@ namespace Poppler
     bool isEmbedded() const;
 
     /**
-      Returns data stream device.
+      Returns data buffer.
      */
-    QIODevice *streamDevice() const;
+    QByteArray data() const;
 
     /**
       Convenience accessor for auto-play parameter.
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 1369e44..44a117b 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -59,7 +59,6 @@
 #include "poppler-annotation-private.h"
 #include "poppler-form.h"
 #include "poppler-media.h"
-#include "poppler-streamsequentialdevice-private.h"
 
 namespace Poppler {
 
diff --git a/qt4/src/poppler-streamsequentialdevice-private.h b/qt4/src/poppler-streamsequentialdevice-private.h
deleted file mode 100644
index ec2dae2..0000000
--- a/qt4/src/poppler-streamsequentialdevice-private.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* poppler-streamdevice-private.h: Qt4 interface to poppler
- * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef POPPLER_STREAMSEQUENTIALDEVICE_PRIVATE_H
-#define POPPLER_STREAMSEQUENTIALDEVICE_PRIVATE_H
-
-#include <QtCore/QIODevice>
-
-class Stream;
-
-namespace Poppler {
-
-class StreamSequentialDevice : public QIODevice
-{
-  public:
-    StreamSequentialDevice(Stream *stream, QObject *parent = 0);
-    virtual ~StreamSequentialDevice();
-
-    virtual void close();
-
-    virtual bool isSequential() const
-      { return true; }
-
-  protected:
-    virtual qint64 readData(char *data, qint64 maxSize);
-    inline virtual qint64 writeData(const char *, qint64)
-      { return 0; }
-
-  private:
-    Q_DISABLE_COPY(StreamSequentialDevice);
-    Stream *m_stream;
-};
-
-}
-
-#endif
diff --git a/qt4/src/poppler-streamsequentialdevice.cc b/qt4/src/poppler-streamsequentialdevice.cc
deleted file mode 100644
index fa5a064..0000000
--- a/qt4/src/poppler-streamsequentialdevice.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-/* poppler-streamdevice.cc: Qt4 interface to poppler
- * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "poppler-streamsequentialdevice-private.h"
-
-#include "Object.h"
-#include "Stream.h"
-
-namespace Poppler {
-
-StreamSequentialDevice::StreamSequentialDevice(Stream *stream, QObject *parent)
-    : QIODevice(parent)
-    , m_stream(stream)
-{
-	Q_ASSERT(m_stream && "Invalid stream assigned.");
-	m_stream->incRef();
-	m_stream->reset();
-	open(QIODevice::ReadOnly);
-}
-
-StreamSequentialDevice::~StreamSequentialDevice()
-{
-	m_stream->decRef();
-	m_stream = 0;
-}
-
-void
-StreamSequentialDevice::close()
-{
-	m_stream->close();
-	QIODevice::close();
-}
-
-qint64
-StreamSequentialDevice::readData(char *data, qint64 maxSize)
-{
-	return m_stream->doGetChars(maxSize, reinterpret_cast<Guchar*>(data));
-}
-
-}
-


More information about the poppler mailing list