* scribo/sandbox/arthur/xml_transform/xml_transform.cc,
* scribo/sandbox/arthur/xml_transform/xml_transform.hh: Facade.
* scribo/sandbox/arthur/xml_transform/image_crop.cc,
* scribo/sandbox/arthur/xml_transform/image_crop.hh: Image process.
* scribo/sandbox/arthur/xml_transform/loader.cc,
* scribo/sandbox/arthur/xml_transform/loader.hh: XML loader.
* scribo/sandbox/arthur/xml_transform/main.cc
* scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
* scribo/sandbox/arthur/xml_transform/xml_transform.pro
* scribo/sandbox/arthur/xml_transform/README
* scribo/sandbox/arthur/xml_transform/common.cc,
* scribo/sandbox/arthur/xml_transform/common.hh,
* scribo/sandbox/arthur/xml_transform/moc_dommodel.cpp,
* scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl,
* scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl,
* scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl: New.
* scribo/sandbox/arthur/xml_transform/domitem.cc,
* scribo/sandbox/arthur/xml_transform/domitem.hh,
* scribo/sandbox/arthur/xml_transform/dommodel.cc,
* scribo/sandbox/arthur/xml_transform/dommodel.hh: Delete.
* scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl: Rename as...
* scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl:...this.
---
scribo/sandbox/ChangeLog | 33 +++
scribo/sandbox/arthur/xml_transform/README | 25 +-
scribo/sandbox/arthur/xml_transform/common.cc | 13 +
scribo/sandbox/arthur/xml_transform/common.hh | 16 +
scribo/sandbox/arthur/xml_transform/domitem.cc | 98 -------
scribo/sandbox/arthur/xml_transform/domitem.hh | 75 -----
scribo/sandbox/arthur/xml_transform/dommodel.cc | 198 -------------
scribo/sandbox/arthur/xml_transform/dommodel.hh | 85 ------
scribo/sandbox/arthur/xml_transform/image_crop.cc | 303 ++++++++++++++------
scribo/sandbox/arthur/xml_transform/image_crop.hh | 19 +-
scribo/sandbox/arthur/xml_transform/loader.cc | 124 +++++----
scribo/sandbox/arthur/xml_transform/loader.hh | 17 +-
scribo/sandbox/arthur/xml_transform/main.cc | 78 +++++-
.../arthur/xml_transform/templates/html/xsl.xsl | 3 +-
.../templates/html/{xsl.xsl => xsl_base64.xsl} | 9 +-
.../templates/pdf/{main.xsl => main64.xsl} | 2 +-
.../pdf/{regions.xsl => regions_base64.xsl} | 6 +-
.../templates/pdf/{regions.xsl => regions_png.xsl} | 0
.../sandbox/arthur/xml_transform/xml_transform.cc | 113 +++++---
.../sandbox/arthur/xml_transform/xml_transform.hh | 20 +-
.../sandbox/arthur/xml_transform/xml_transform.pro | 12 +-
21 files changed, 564 insertions(+), 685 deletions(-)
create mode 100644 scribo/sandbox/arthur/xml_transform/common.cc
create mode 100644 scribo/sandbox/arthur/xml_transform/common.hh
delete mode 100644 scribo/sandbox/arthur/xml_transform/domitem.cc
delete mode 100644 scribo/sandbox/arthur/xml_transform/domitem.hh
delete mode 100644 scribo/sandbox/arthur/xml_transform/dommodel.cc
delete mode 100644 scribo/sandbox/arthur/xml_transform/dommodel.hh
copy scribo/sandbox/arthur/xml_transform/templates/html/{xsl.xsl => xsl_base64.xsl}
(97%)
copy scribo/sandbox/arthur/xml_transform/templates/pdf/{main.xsl => main64.xsl} (94%)
copy scribo/sandbox/arthur/xml_transform/templates/pdf/{regions.xsl =>
regions_base64.xsl} (91%)
rename scribo/sandbox/arthur/xml_transform/templates/pdf/{regions.xsl =>
regions_png.xsl} (100%)
diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog
index d3f537b..0fb733f 100644
--- a/scribo/sandbox/ChangeLog
+++ b/scribo/sandbox/ChangeLog
@@ -1,3 +1,36 @@
+2010-07-15 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
+
+ XML Tranform.
+
+ * scribo/sandbox/arthur/xml_transform/xml_transform.cc,
+ * scribo/sandbox/arthur/xml_transform/xml_transform.hh: Facade.
+
+ * scribo/sandbox/arthur/xml_transform/image_crop.cc,
+ * scribo/sandbox/arthur/xml_transform/image_crop.hh: Image process.
+
+ * scribo/sandbox/arthur/xml_transform/loader.cc,
+ * scribo/sandbox/arthur/xml_transform/loader.hh: XML loader.
+
+ * scribo/sandbox/arthur/xml_transform/main.cc
+ * scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
+ * scribo/sandbox/arthur/xml_transform/xml_transform.pro
+ * scribo/sandbox/arthur/xml_transform/README
+
+ * scribo/sandbox/arthur/xml_transform/common.cc,
+ * scribo/sandbox/arthur/xml_transform/common.hh,
+ * scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl,
+ * scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl,
+ * scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl: New.
+
+ * scribo/sandbox/arthur/xml_transform/domitem.cc,
+ * scribo/sandbox/arthur/xml_transform/domitem.hh,
+ * scribo/sandbox/arthur/xml_transform/dommodel.cc,
+ * scribo/sandbox/arthur/xml_transform/dommodel.hh: Delete.
+
+ * scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl: Rename as...
+ * scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl:...this.
+
+
2010-07-05 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
ICDAR XML to HTML.
diff --git a/scribo/sandbox/arthur/xml_transform/README
b/scribo/sandbox/arthur/xml_transform/README
index e0bfbc8..1f358e3 100644
--- a/scribo/sandbox/arthur/xml_transform/README
+++ b/scribo/sandbox/arthur/xml_transform/README
@@ -1,19 +1,24 @@
-xml_transform <option> <xml_file> <ppm_file> <output_dir>
-
-Transforms an ICDAR XML file to different kind of output.
+xml_transform
OPTIONS:
- --html: Produce a HTML output
-
-Once process is finished, open output.xml with your internet browser. If this one
supports XSLT, there is no problem to display the result but if it does not support it
(like Konqueror or Chrome in local), you should run `sh html_generator.sh` (xsltproc
package required) to generate a HTML file readable by all browsers.
+HTML output:
+ --html <xml> <ppm> <out_dir> : HTML output with non-text regions
croped into many png files.
+ --html-base64 <xml> <out_dir> : HTML output from a container XML file.
- --pdf: Produce a PDF output, regions will be cropped as follows in the XML file.
- --pdf-no-crop: Produce a PDF output without cropping regions, the entire picture
will be displayed.
+PDF output:
+ --pdf <xml> <ppm> <out_dir> : PDF output with non-text regions
croped into many png files.
+ --pdf-no-crop <xml> <ppm> <out_dir>: PDF output with the entire
picture displayed over the text.
+ --pdf-base64 <xml> <out_dir> : PDF output from a container XML file.
+ --pdf-base64-no-crop <xml> <ppm> <out_dir> : PDF with the entire
picture displayed over the text,
+ the picture is loaded from a container XML file.
-PDF is not directly created once the process is finished, to produce it, go to the
output_dir and run `sh pdf_generator.sh` (fop >= 0.95 required).
+Base 64 operations:
+ --to-base64 <xml> <ppm> <out_xml> : Produces a container XML file
by converting croped pictures into base 64 format.
+ --to-base64-no-crop <xml> <ppm> <out_xml> : Same as to-base64 but
only the picture is converted in base 64.
+ --from-base64 <xml> <out_dir> : Decodes a XML container file to produce
original image files.
BUILD:
-Chnage the environment variable QMAKE_CXXFLAGS to indicate the correct paths to milena
and olena then, just type qmake and make.
\ No newline at end of file
+Chnage the environment variable QMAKE_CXXFLAGS to indicate the correct paths to milena
and olena in the .pro file then, just type qmake and make.
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_transform/common.cc
b/scribo/sandbox/arthur/xml_transform/common.cc
new file mode 100644
index 0000000..05117b2
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/common.cc
@@ -0,0 +1,13 @@
+# include "common.hh"
+
+QString Common::get_file_name(QString image)
+{
+ QString tmp = image.mid(image.lastIndexOf("/") + 1);
+ tmp.chop(tmp.size() - tmp.lastIndexOf("."));
+ return tmp;
+}
+
+QString Common::get_file_ext(QString image)
+{
+ return image.right(image.size() - image.lastIndexOf("."));
+}
diff --git a/scribo/sandbox/arthur/xml_transform/common.hh
b/scribo/sandbox/arthur/xml_transform/common.hh
new file mode 100644
index 0000000..f72218f
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/common.hh
@@ -0,0 +1,16 @@
+#ifndef COMMON_HH
+# define COMMON_HH
+
+# include <QtGui>
+
+class Common : public QObject
+{
+ Q_OBJECT
+public:
+ Common() {}
+ ~Common() {}
+ static QString get_file_name(QString image);
+ static QString get_file_ext(QString image);
+};
+
+#endif // ! COMMON_HH
diff --git a/scribo/sandbox/arthur/xml_transform/domitem.cc
b/scribo/sandbox/arthur/xml_transform/domitem.cc
deleted file mode 100644
index 66e989a..0000000
--- a/scribo/sandbox/arthur/xml_transform/domitem.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- **
http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- **
http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// 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
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#include <QtXml>
-
-#include "domitem.hh"
-
-DomItem::DomItem(QDomNode &node, int row, DomItem *parent)
-{
- domNode = node;
- // Record the item's location within its parent.
- rowNumber = row;
- parentItem = parent;
-}
-
-DomItem::~DomItem()
-{
- QHash<int,DomItem*>::iterator it;
- for (it = childItems.begin(); it != childItems.end(); ++it)
- delete it.value();
-}
-
-QDomNode DomItem::node() const
-{
- return domNode;
-}
-
-DomItem *DomItem::parent()
-{
- return parentItem;
-}
-
-DomItem *DomItem::child(int i)
-{
- if (childItems.contains(i))
- return childItems[i];
-
- if (i >= 0 && i < domNode.childNodes().count()) {
- QDomNode childNode = domNode.childNodes().item(i);
- DomItem *childItem = new DomItem(childNode, i, this);
- childItems[i] = childItem;
- return childItem;
- }
- return 0;
-}
-
-int DomItem::row()
-{
- return rowNumber;
-}
diff --git a/scribo/sandbox/arthur/xml_transform/domitem.hh
b/scribo/sandbox/arthur/xml_transform/domitem.hh
deleted file mode 100644
index a5c22cc..0000000
--- a/scribo/sandbox/arthur/xml_transform/domitem.hh
+++ /dev/null
@@ -1,75 +0,0 @@
- /****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- **
http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- **
http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// 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
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#ifndef DOMITEM_H
-#define DOMITEM_H
-
-#include <QDomNode>
-#include <QHash>
-
-class DomItem
-{
-public:
- DomItem(QDomNode &node, int row, DomItem *parent = 0);
- ~DomItem();
- DomItem *child(int i);
- DomItem *parent();
- QDomNode node() const;
- int row();
-
-private:
- QDomNode domNode;
- QHash<int,DomItem*> childItems;
- DomItem *parentItem;
- int rowNumber;
-};
-
-#endif
diff --git a/scribo/sandbox/arthur/xml_transform/dommodel.cc
b/scribo/sandbox/arthur/xml_transform/dommodel.cc
deleted file mode 100644
index baaf9a7..0000000
--- a/scribo/sandbox/arthur/xml_transform/dommodel.cc
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- **
http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- **
http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// 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
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#include <QtGui>
-#include <QtXml>
-
-#include "domitem.hh"
-#include "dommodel.hh"
-
-DomModel::DomModel(QDomDocument document, QObject *parent)
- : QAbstractItemModel(parent), domDocument(document)
-{
- rootItem = new DomItem(domDocument, 0);
-}
-
-DomModel::~DomModel()
-{
- delete rootItem;
-}
-
-int DomModel::columnCount(const QModelIndex &/*parent*/) const
-{
- return 3;
-}
-
-QVariant DomModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
-
- DomItem *item = static_cast<DomItem*>(index.internalPointer());
- QDomNode node = item->node();
- QDomNamedNodeMap attributeMap = node.attributes();
-
- if (role == Qt::DisplayRole)
- {
- QStringList attributes;
-
- switch (index.column())
- {
- case 0:
- return node.nodeName();
- case 1:
- for (int i = 0; i < attributeMap.count(); ++i)
- {
- QDomNode attribute = attributeMap.item(i);
- attributes << attribute.nodeName() + "=\""
- + attribute.nodeValue() + "\"";
- }
- return attributes.join(" ");
- case 2:
- return node.nodeValue().split("\n").join(" ");
- default:
- return QVariant();
- }
- }
- else if (role == Qt::UserRole)
- {
- QMap<QString, QVariant> attributes;
- switch (index.column())
- {
- case 1:
- for (int i = 0; i < attributeMap.count(); ++i)
- {
- QDomNode attribute = attributeMap.item(i);
- attributes[attribute.nodeName()] = attribute.nodeValue();
- }
- return attributes;
- default:
- return QVariant();
- }
- }
- return QVariant();
-}
-
-Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
-{
- if (!index.isValid())
- return 0;
-
- return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
-}
-
-QVariant DomModel::headerData(int section, Qt::Orientation orientation,
- int role) const
-{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
- switch (section) {
- case 0:
- return tr("Name");
- case 1:
- return tr("Attributes");
- case 2:
- return tr("Value");
- default:
- return QVariant();
- }
- }
-
- return QVariant();
-}
-
-QModelIndex DomModel::index(int row, int column, const QModelIndex &parent)
- const
-{
- if (!hasIndex(row, column, parent))
- return QModelIndex();
-
- DomItem *parentItem;
-
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<DomItem*>(parent.internalPointer());
-
- DomItem *childItem = parentItem->child(row);
- if (childItem)
- return createIndex(row, column, childItem);
- else
- return QModelIndex();
-}
-
-QModelIndex DomModel::parent(const QModelIndex &child) const
-{
- if (!child.isValid())
- return QModelIndex();
-
- DomItem *childItem = static_cast<DomItem*>(child.internalPointer());
- DomItem *parentItem = childItem->parent();
-
- if (!parentItem || parentItem == rootItem)
- return QModelIndex();
-
- return createIndex(parentItem->row(), 0, parentItem);
-}
-
-int DomModel::rowCount(const QModelIndex &parent) const
-{
- if (parent.column() > 0)
- return 0;
-
- DomItem *parentItem;
-
- if (!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<DomItem*>(parent.internalPointer());
-
- return parentItem->node().childNodes().count();
-}
diff --git a/scribo/sandbox/arthur/xml_transform/dommodel.hh
b/scribo/sandbox/arthur/xml_transform/dommodel.hh
deleted file mode 100644
index 16c5a23..0000000
--- a/scribo/sandbox/arthur/xml_transform/dommodel.hh
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
- **
- ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
- ** Contact: Qt Software Information (qt-info(a)nokia.com)
- **
- ** This file is part of the example classes of the Qt Toolkit.
- **
- ** Commercial Usage
- ** Licensees holding valid Qt Commercial licenses may use this file in
- ** accordance with the Qt Commercial License Agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Nokia.
- **
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License versions 2.0 or 3.0 as published by the Free
- ** Software Foundation and appearing in the file LICENSE.GPL included in
- ** the packaging of this file. Please review the following information
- ** to ensure GNU General Public Licensing requirements will be met:
- **
http://www.fsf.org/licensing/licenses/info/GPLv2.html and
- **
http://www.gnu.org/copyleft/gpl.html. In addition, as a special
- ** exception, Nokia gives you certain additional rights. These rights
- ** are described in the Nokia Qt GPL Exception version 1.3, included in
- ** the file GPL_EXCEPTION.txt in this package.
- **
- ** Qt for Windows(R) Licensees
- ** As a special exception, Nokia, as the sole copyright holder for Qt
- ** Designer, grants users of the Qt/Eclipse Integration plug-in the
- ** right for the Qt/Eclipse Integration to link to functionality
- ** provided by Qt Designer and its related libraries.
- **
- ** If you are unsure which license is appropriate for your use, please
- ** contact the sales department at qt-sales(a)nokia.com.
- **
- ****************************************************************************/
-
-//
-// Document layout viewer.
-//
-// Copyright (C) 2009 Florent D'Halluin.
-//
-// 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
-// of the License, or (at your option) any later version.
-//
-// The complete GNU General Public Licence Notice can be found as the
-// `COPYING' file in the root directory.
-//
-
-#ifndef DOMMODEL_H
-#define DOMMODEL_H
-
-#include <QAbstractItemModel>
-#include <QDomDocument>
-#include <QModelIndex>
-#include <QVariant>
-
-class DomItem;
-
-class DomModel : public QAbstractItemModel
-{
- Q_OBJECT
-
- public:
- DomModel(QDomDocument document, QObject *parent = 0);
- ~DomModel();
-
- QVariant data(const QModelIndex &index, int role) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
- QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
- QModelIndex index(int row, int column,
- const QModelIndex &parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex &child) const;
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
-
-private:
- QDomDocument domDocument;
- DomItem *rootItem;
-};
-
-#endif
diff --git a/scribo/sandbox/arthur/xml_transform/image_crop.cc
b/scribo/sandbox/arthur/xml_transform/image_crop.cc
index aa17c31..8aafe45 100644
--- a/scribo/sandbox/arthur/xml_transform/image_crop.cc
+++ b/scribo/sandbox/arthur/xml_transform/image_crop.cc
@@ -25,7 +25,7 @@
# include "image_crop.hh"
# include "loader.hh"
-# include "dommodel.hh"
+# include "common.hh"
# include <limits.h>
@@ -36,7 +36,10 @@
#include <mln/io/magick/save.hh>
#include <mln/io/ppm/all.hh>
-ImageCrop::ImageCrop()
+ImageCrop::ImageCrop(QString xml, QString img, QString output) :
+ xml_(xml),
+ image_(img),
+ output_dir_(output)
{
}
@@ -44,95 +47,242 @@ ImageCrop::~ImageCrop()
{
}
-void ImageCrop::save_image(QString image, QString output)
+/* Save PPM image to PNG format in output_dir/img. */
+void ImageCrop::save_image(QString file)
{
using namespace mln;
image2d<value::rgb8> ima;
- io::ppm::load(ima, image.toStdString());
+ io::ppm::load(ima, image_.toStdString());
- io::magick::save(ima, output.toStdString() + "img/image.png");
+ QString filename;
+ if (file == QString::Null())
+ filename = Common::get_file_name(image_);
+ else
+ filename = file;
+
+ std::cout << "Saving " << image_.toStdString() << " to
"
+ << output_dir_.toStdString() << "img/"
+ << filename.toStdString() << ".png"
+ << std::endl;
+
+ io::magick::save(ima, output_dir_.toStdString() + "img/" +
filename.toStdString() + ".png");
}
-void ImageCrop::crop_regions(QString xml_file, QString image_file, QString output)
+/* Return the image in base 64. */
+QString ImageCrop::img_to_base64()
{
- Loader loader;
+ QFile f(image_);
+ f.open(QIODevice::ReadOnly);
+
+ QByteArray file_content = f.readAll();
- QFile f(image_file);
+ f.close();
- if (!f.exists())
+ return file_content.toBase64();
+}
+
+/* Decode the base 64 string str and save into output_dir_/img/img_name. */
+bool ImageCrop::img_from_base64(QString str, QString img_name, QString mime)
+{
+ QByteArray ba;
+
+ ba = ba.append(str);
+ QByteArray out_ba = QByteArray::fromBase64(ba);
+ QImage ima = QImage::fromData(out_ba);
+
+ return ima.save(output_dir_ + "img/" + img_name + "." + mime);
+}
+
+/* Read all regions of the XML file and save all base 64 data into output_dir/img */
+void ImageCrop::from_base64()
+{
+ QFile f_in(xml_);
+ f_in.open(QIODevice::ReadOnly);
+
+ QDomDocument doc;
+ doc.setContent(&f_in);
+ f_in.close();
+
+ QDomElement root = doc.documentElement();
+ QDomNode child = root.firstChild();
+
+ while (!child.isNull() &&
!child.toElement().tagName().contains("page"))
+ child = child.nextSibling();
+
+ child = child.firstChild();
+ while (!child.isNull())
{
- qDebug() << "Image doesn't exist !";
- abort();
+ if
(child.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table)_region")))
+ {
+ QDomNode node = child.firstChild();
+ QString id = child.toElement().attribute("id", "none");
+
+ while (!node.isNull() &&
!node.toElement().tagName().contains("container"))
+ node = node.nextSibling();
+
+ if (!node.isNull())
+ {
+ QString data = node.firstChildElement("data").text();
+ QString mime = node.firstChildElement("mime").text();
+ img_from_base64(data, id, mime);
+ }
+ }
+ child = child.nextSibling();
+ }
+}
+
+/* Tranfsorm the input XML file associated with images into a single
+ XML output containing datas if images in base 64. */
+void ImageCrop::to_base64(QString out_file, bool no_crop)
+{
+ QFile file(xml_);
+ file.open(QIODevice::ReadOnly);
+ QTextStream stream(&file);
+
+ QFile file2(out_file);
+ file2.open(QIODevice::ReadWrite);
+ QTextStream stream2(&file2);
+
+ QString line = stream.readLine();
+ stream2 << line;
+ line = stream.readLine();
+
+ // HEAD
+ while (!line.contains("<page"))
+ {
+ stream2 << "\n" << line;
+ line = stream.readLine();
+ }
+
+ if (no_crop)
+ {
+ stream2 << "\n" << line;
+
+ stream2 << "\n" << " <image_region
id=\"image\">";
+ stream2 << "\n" << " <container>\n";
+ stream2 << " <mime>png</mime>\n";
+
+ QString file_name = Common::get_file_name(image_);
+ save_image();
+ QFile img(output_dir_ + "img/" + file_name + ".png");
+
+ img.open(QIODevice::ReadOnly);
+ stream2 << " <data>\n";
+
+ QByteArray byte = img.readAll();
+ stream2 << byte.toBase64();
+
+ stream2 << " </data>";
+ stream2 << "\n </container>";
+ stream2 << "\n <coords>\n";
+
+ stream2 << " <point x=\"0\" y=\"0\"
/>\n";
+ stream2 << " <point x=\"0\" y=\"0\"
/>";
+
+ stream2 << "\n </coords>";
+ stream2 << "\n" << " </image_region>\n";
+ img.close();
+
+ line = stream.readLine();
+
+ while(!line.contains("</pcGts>"))
+ {
+ stream2 << "\n" << line;
+ line = stream.readLine();
+ }
+
+ stream2 << "\n" << line;
}
- DomModel* layout = loader.xml_to_dom(xml_file);
- if (layout)
+ else
{
- QModelIndex pcGts = layout->index(1, 0);
- QModelIndex page = layout->index(1, 0, pcGts);
- QModelIndex region;
- QModelIndex attributes;
- QModelIndex coords;
- QModelIndex point;
- bool regions_found = false;
-
- for (int i = 0; true; ++i)
+ while(!line.contains("</pcGts>"))
{
- region = layout->index(i, 0, page);
- attributes = layout->index(i, 1, page);
+ stream2 << "\n" << line;
+ if
(line.contains(QRegExp("<(image|graphic|chart|separator|table)_region")))
+ {
+ stream2 << "\n" << " <container>\n";
+ stream2 << " <mime>png</mime>\n";
+
+ QDomDocument doc;
+ doc.setContent(line);
+
+ QDomElement root = doc.documentElement();
+ QString id = root.attribute("id", "none");
- QString name = layout->data(region, Qt::DisplayRole).toString();
- coords = layout->index(0, 0, region);
+ QFile img(output_dir_ + "img/" + id + ".png");
- bool is_region =
- name == QString("image_region")
- || name == QString("graphic_region")
- || name == QString("separator_region")
- || name == QString("chart_region")
- || name == QString("table_region") ;
+ img.open(QIODevice::ReadOnly);
+ stream2 << " <data>\n";
- if (!region.isValid() || !coords.isValid())
- break;
+ QByteArray byte = img.readAll();
+ stream2 << byte.toBase64();
+
+ stream2 << " </data>";
+ stream2 << "\n </container>";
+ img.close();
+ }
- if (is_region)
+ line = stream.readLine();
+ }
+
+ stream2 << "\n" << line;
+ }
+
+ file2.close();
+ file.close();
+}
+
+bool ImageCrop::crop_regions()
+{
+ Loader loader;
+ QFile f(xml_);
+ f.open(QIODevice::ReadOnly);
+ QDomDocument doc;
+
+ if (doc.setContent(&f))
+ {
+ bool found_regions = false;
+ f.close();
+
+ QDomElement root = doc.documentElement();
+ QDomNode page = root.firstChild();
+
+ while (!page.isNull() &&
!page.toElement().tagName().contains("page"))
+ page = page.nextSibling();
+
+ if (page.isNull())
+ return false;
+
+ QDomNode region = page.firstChild();
+
+ while (!region.isNull())
+ {
+ if
(region.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table)_region")))
{
- regions_found = true;
- QMap<QString, QVariant> data =
- layout->data(attributes, Qt::UserRole).toMap();
+ found_regions = true;
- QString id;
- QMap<QString, QVariant>::iterator it = data.find("id");
+ QDomNode coords = region.firstChild();
+ QString id = region.toElement().attribute("id", "none");
- if (it == data.end() || it.key() != "id")
- qDebug() << "WTF_Error : No image region.";
+ qDebug() << region.toElement().tagName();
- while (it != data.end() && it.key() == "id")
- {
- qDebug() << name;
- id = it.value().toString();
- qDebug() << it.key() + " = " + it.value().toString();
- ++it;
- }
+ while (!coords.isNull() &&
!coords.toElement().tagName().contains("coords"))
+ coords = coords.nextSibling();
+ if (coords.isNull())
+ break;
+
+ QDomNode point = coords.firstChild();
int x_max = 0;
int y_max = 0;
int x_min = INT_MAX;
int y_min = INT_MAX;
- // QVector<QMap<QString, QVariant> > vect;
- for (int j = 0; true; ++j)
+ while (!point.isNull())
{
- // Navigate to the coordinate list
- point = layout->index(j, 1, coords);
- if (!point.isValid())
- break;
-
- QMap<QString, QVariant> data =
- layout->data(point, Qt::UserRole).toMap();
- int x = data["x"].toInt();
- int y = data["y"].toInt();
-
- // vect << data;
+ int x = point.toElement().attribute("x", "none").toInt();
+ int y = point.toElement().attribute("y", "none").toInt();
if (x < x_min)
x_min = x;
@@ -144,41 +294,26 @@ void ImageCrop::crop_regions(QString xml_file, QString image_file,
QString outpu
if (y > y_max)
y_max = y;
+ point = point.nextSibling();
}
using namespace mln;
-
box2d box = make::box2d(y_min, x_min, y_max, x_max);
image2d<value::rgb8> ima;
- io::ppm::load(ima, image_file.toStdString());
+ io::ppm::load(ima, image_.toStdString());
ima = scribo::preprocessing::crop(ima, box);
- // image2d<bool> mask = make::box2d(y_min, x_min, y_max, x_max);
- // data::fill(mask, true);
-
- /*for (int a = 1; a < vect.size(); ++a)
- {
- int x = vect[a]["x"].toInt();
- int y = vect[a]["y"].toInt();
-
- data::fill((mask | make::box2d(y, x, y, x)).rw(), false);
- }*/
-
- // io::pbm::save(mask, "output/img/mask_" + id.toStdString());
- io::magick::save(ima, output.toStdString() + "img/" + id.toStdString() +
".png");
-
+ io::magick::save(ima, output_dir_.toStdString() + "img/" +
id.toStdString() + ".png");
}
+ region = region.nextSibling();
}
- if (!regions_found)
- qDebug() << "No regions found.";
-
+ return found_regions;
}
else
{
- qDebug() << "Error with XML file.";
+ f.close();
+ return false;
}
-
-
}
diff --git a/scribo/sandbox/arthur/xml_transform/image_crop.hh
b/scribo/sandbox/arthur/xml_transform/image_crop.hh
index e4b0a38..9b034cc 100644
--- a/scribo/sandbox/arthur/xml_transform/image_crop.hh
+++ b/scribo/sandbox/arthur/xml_transform/image_crop.hh
@@ -26,7 +26,8 @@
#ifndef IMAGE_CROP_HH
# define IMAGE_CROP_HH
-# include <QtGui>
+#include <QDomDocument>
+# include <QtCore>
class DomModel;
@@ -35,12 +36,22 @@ class ImageCrop : public QObject
Q_OBJECT
public:
- ImageCrop();
+ ImageCrop(QString xml, QString img, QString output);
~ImageCrop();
- void save_image(QString image, QString output);
- void crop_regions(QString xml_file, QString image_file, QString output);
+ void save_image(QString file = QString::Null());
+ bool crop_regions();
+ QString img_to_base64();
+ bool img_from_base64(QString str, QString img_name, QString mime);
+ void to_base64(QString out_file, bool no_crop);
+
+ void from_base64();
+
+private:
+ QString xml_;
+ QString image_;
+ QString output_dir_;
};
#endif /* !IMAGE_CROP_HH */
diff --git a/scribo/sandbox/arthur/xml_transform/loader.cc
b/scribo/sandbox/arthur/xml_transform/loader.cc
index 5623928..2b64337 100644
--- a/scribo/sandbox/arthur/xml_transform/loader.cc
+++ b/scribo/sandbox/arthur/xml_transform/loader.cc
@@ -24,8 +24,6 @@
// executable file might be covered by the GNU General Public License.
# include "loader.hh"
-# include "dommodel.hh"
-# include "xml_transform.hh"
Loader::Loader()
{
@@ -35,21 +33,21 @@ Loader::~Loader()
{
}
-DomModel* Loader::xml_to_dom(QString output)
+QDomDocument* Loader::xml_to_dom(QString xml_file)
{
- QString file_path = output;
-
- QFile file(file_path);
+ QFile file(xml_file);
if (file.open(QIODevice::ReadOnly))
{
- QDomDocument document;
- if (document.setContent(&file))
+ QDomDocument* document = new QDomDocument;
+ if (document->setContent(&file))
{
- return new DomModel(document);
+ file.close();
+ return document;
}
}
+ file.close();
return 0;
}
@@ -61,9 +59,7 @@ bool Loader::set_output(QString& output)
output.append("/");
if (!dir.exists())
- {
- return dir.mkpath(".");
- }
+ return dir.mkpath(".");
else
{
QStringList list = dir.entryList(QDir::Writable | QDir::AllDirs);
@@ -72,25 +68,38 @@ bool Loader::set_output(QString& output)
}
-void Loader::add_html_templates(QString output)
+void Loader::add_html_templates(bool base64, QString output)
{
-
QFile gen("templates/html/html_generator.sh");
gen.copy(output + "html_generator.sh");
QFile css("templates/html/css.css");
css.copy(output + "css.css");
- QFile xsl("templates/html/xsl.xsl");
- xsl.copy(output + "xsl.xsl");
-
+ if (base64)
+ {
+ QFile xsl("templates/html/xsl_base64.xsl");
+ xsl.copy(output + "xsl.xsl");
+ }
+ else
+ {
+ QFile xsl("templates/html/xsl.xsl");
+ xsl.copy(output + "xsl.xsl");
+ }
}
-void Loader::add_pdf_templates(bool crop, QString output)
+void Loader::add_pdf_templates(bool crop, bool base64, QString output)
{
-
- QFile regions("templates/pdf/regions.xsl");
- regions.copy(output + "regions.xsl");
+ if (base64)
+ {
+ QFile regions("templates/pdf/regions_base64.xsl");
+ regions.copy(output + "regions.xsl");
+ }
+ else
+ {
+ QFile regions("templates/pdf/regions_png.xsl");
+ regions.copy(output + "regions.xsl");
+ }
QFile gen("templates/pdf/pdf_generator.sh");
gen.copy(output + "pdf_generator.sh");
@@ -104,59 +113,58 @@ void Loader::add_pdf_templates(bool crop, QString output)
}
else
{
- QFile xsl("templates/pdf/main.xsl");
- xsl.copy(output + "main.xsl");
+ if (base64)
+ {
+ QFile xsl("templates/pdf/main.xsl");
+ xsl.copy(output + "main.xsl");
+ }
+ else
+ {
+ QFile xsl("templates/pdf/main64.xsl");
+ xsl.copy(output + "main.xsl");
+ }
}
}
-bool Loader::load_xml(QString xml_file, bool html, QString output)
+bool Loader::xml_output(QString xml_file, bool html, QString output)
{
QFile file(xml_file);
- if (file.exists())
- {
- file.open(QIODevice::ReadOnly);
- set_output(output);
+ file.open(QIODevice::ReadOnly);
- QFile out_file(output + "output.xml");
- out_file.open(QIODevice::ReadWrite);
+ QFile out_file(output + "output.xml");
+ out_file.open(QIODevice::ReadWrite);
- QTextStream stream_in(&file);
- QTextStream stream_out(&out_file);
+ QTextStream stream_in(&file);
+ QTextStream stream_out(&out_file);
- QString line = stream_in.readLine();
+ QString line = stream_in.readLine();
- while(!line.contains("<?xml"))
- line = stream_in.readLine();
+ while(!line.contains("<?xml"))
+ line = stream_in.readLine();
- stream_out << line;
+ stream_out << line;
- if (html)
- stream_out << "\n<?xml-stylesheet type=\"text/xsl\"
href=\"xsl.xsl\" ?>";
+ if (html)
+ stream_out << "\n<?xml-stylesheet type=\"text/xsl\"
href=\"xsl.xsl\" ?>";
- // /!\ attributes of ICDAR PcGts removed.
- while(!line.contains("<pcGts"))
- line = stream_in.readLine();
+ // /!\ attributes of ICDAR PcGts removed.
+ while(!line.contains("<pcGts"))
+ line = stream_in.readLine();
- line = stream_in.readLine();
- stream_out << "\n<pcGts>";
-
- while (!line.contains("</pcGts>"))
- {
- stream_out << "\n" << line;
- line = stream_in.readLine();
- }
+ line = stream_in.readLine();
+ stream_out << "\n<pcGts>";
+ while (!line.contains("</pcGts>"))
+ {
stream_out << "\n" << line;
+ line = stream_in.readLine();
+ }
- file.close();
- out_file.close();
+ stream_out << "\n" << line;
- return true;
- }
- else
- {
- qDebug() << xml_file + " doesn't exist";
- return false;
- }
+ file.close();
+ out_file.close();
+
+ return true;
}
diff --git a/scribo/sandbox/arthur/xml_transform/loader.hh
b/scribo/sandbox/arthur/xml_transform/loader.hh
index 7d24254..fadceed 100644
--- a/scribo/sandbox/arthur/xml_transform/loader.hh
+++ b/scribo/sandbox/arthur/xml_transform/loader.hh
@@ -26,24 +26,23 @@
#ifndef LOADER_HH
# define LOADER_HH
-//# include <QtGui>
-# include "xml_transform.hh"
+# include <QtCore>
+#include <QDomDocument>
-class DomModel;
-
-class Loader
+class Loader : public QObject
{
+ Q_OBJECT
public:
Loader();
~Loader();
// void merge(QString in, QString other, QString output = "output.xml");
- bool load_xml(QString xml_file, bool html, QString output);
- DomModel* xml_to_dom(QString output);
+ bool xml_output(QString xml_file, bool html, QString output);
+ QDomDocument* xml_to_dom(QString xml_file);
bool set_output(QString& output);
- void add_pdf_templates(bool crop, QString output);
- void add_html_templates(QString output);
+ void add_pdf_templates(bool crop, bool base64, QString output);
+ void add_html_templates(bool base64, QString output);
};
#endif /* !LOADER_HH */
diff --git a/scribo/sandbox/arthur/xml_transform/main.cc
b/scribo/sandbox/arthur/xml_transform/main.cc
index 9e18cff..e097430 100644
--- a/scribo/sandbox/arthur/xml_transform/main.cc
+++ b/scribo/sandbox/arthur/xml_transform/main.cc
@@ -1,25 +1,89 @@
#include <iostream>
+#include <QDomDocument>
#include "xml_transform.hh"
int main(int argc, char **argv)
{
- std::string man = "xml_transform <option> <xml_file> <ppm_file>
<output_dir>\nOPTIONS:\n\t--html: Produce a HTML output\n\t--pdf: Produce a PDF
output, regions will be croped as follows in the XML file.\n\t--pdf-no-crop: Produce a PDF
output without croping regions, the entire picture will be displayed.";
+ std::string man;
+ man = "xml_transform\n";
+ man += "OPTIONS:\n\n";
+ man += "HTML output:\n";
+ man += "\t--html <xml> <ppm> <out_dir> : HTML output with
non-text regions croped into many png files.\n";
+ man += "\t--html-base64 <xml> <out_dir> : HTML output from a container
XML file.\n\n";
+ man += "PDF output:\n";
+ man += "\t--pdf <xml> <ppm> <out_dir> : PDF output with non-text
regions croped into many png files.\n";
+ man += "\t--pdf-no-crop <xml> <ppm> <out_dir>: PDF output with
the entire picture displayed over the text.\n";
+ man += "\t--pdf-base64 <xml> <out_dir> : PDF output from a container
XML file.\n";
+ man += "\t--pdf-base64-no-crop <xml> <ppm> <out_dir> : PDF with
the entire picture displayed over the text, the picture is loaded from a container XML
file.\n\n";
+ man += "Base 64 operations:\n";
+ man += "\t--to-base64 <xml> <ppm> <out_xml> : Produces a
container XML file by converting croped pictures into base 64 format.\n";
+ man += "\t--to-base64-no-crop <xml> <ppm> <out_xml> : Same as
to-base64 but only the picture is converted in base 64.\n";
+ man += "\t--from-base64 <xml> <out_dir> : Decodes a XML container file
to produce original image files.\n";
if (argc > 4)
{
std::string html = "--html";
std::string pdf = "--pdf";
std::string pdf_no_crop = "--pdf-no-crop";
-
- XmlTransform xmlt(argv[4], argv[2]);
+ std::string to_base64 = "--to-base64";
+ std::string to_base64nocrop = "--to-base64-no-crop";
if (html.compare(argv[1]) == 0)
- xmlt.createHTML(argv[3]);
- else if (pdf.compare(argv[1]) == 0)
- xmlt.createPDF(argv[3], true);
+ {
+ XmlTransform xmlt(argv[2], argv[3], argv[4]);
+ xmlt.createHTML(false);
+ }
+ if (pdf.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], argv[3], argv[4]);
+ xmlt.createPDF(true, false);
+ }
else if (pdf_no_crop.compare(argv[1]) == 0)
- xmlt.createPDF(argv[3], false);
+ {
+ XmlTransform xmlt(argv[2], argv[3], argv[4]);
+ xmlt.createPDF(false, false);
+ }
+ else if (to_base64.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], argv[3], QString::Null(), argv[4]);
+ xmlt.toBase64(false);
+ }
+ else if (to_base64nocrop.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], argv[3], QString::Null(), argv[4]);
+ xmlt.toBase64(true);
+ }
+ else
+ std::cout << man << std::endl;
+ }
+ else if (argc > 3)
+ {
+ std::string pdfbase64 = "--pdf-base64";
+ std::string pdfbase64nocrop = "--pdf-base64-no-crop";
+ std::string htmlbase64 = "--html-base64";
+ std::string from_base64 = "--from-base64";
+
+ if (pdfbase64.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.createPDF(true, true);
+ }
+ else if (pdfbase64nocrop.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.createPDF(false, true);
+ }
+ else if (htmlbase64.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.createHTML(true);
+ }
+ else if (from_base64.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.fromBase64();
+ }
else
std::cout << man << std::endl;
}
diff --git a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
b/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
index 3d6a1c5..1f29044 100644
--- a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
+++ b/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
@@ -209,8 +209,7 @@
<xsl:attribute name="height">
<xsl:value-of select="$y2 - $y1" />
</xsl:attribute>
- <xsl:attribute name="src">
- img/<xsl:value-of select="$id"/>.png</xsl:attribute>
+ <xsl:attribute name="src">img/<xsl:value-of
select="$id"/>.png</xsl:attribute>
</img>
</div>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
b/scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl
similarity index 97%
copy from scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
copy to scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl
index 3d6a1c5..1c25e42 100644
--- a/scribo/sandbox/arthur/xml_transform/templates/html/xsl.xsl
+++ b/scribo/sandbox/arthur/xml_transform/templates/html/xsl_base64.xsl
@@ -174,9 +174,9 @@
<!-- NON-TEXT REGIONS -->
<xsl:if test="name() = 'image_region' or name() =
'separator_region' or name() = 'graphic_region' or name() =
'chart_region' or name() = 'table_region'">
- <!-- id -->
- <xsl:variable name="id">
- <xsl:value-of select="@id" />
+ <!-- data -->
+ <xsl:variable name="data">
+ <xsl:value-of select="container/data" />
</xsl:variable>
<!-- depth -->
@@ -210,7 +210,8 @@
<xsl:value-of select="$y2 - $y1" />
</xsl:attribute>
<xsl:attribute name="src">
- img/<xsl:value-of select="$id"/>.png</xsl:attribute>
+ data:image/png;base64,<xsl:value-of select="$data"/>
+ </xsl:attribute>
</img>
</div>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl
b/scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl
similarity index 94%
copy from scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl
copy to scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl
index 065831e..ecc7443 100644
--- a/scribo/sandbox/arthur/xml_transform/templates/pdf/main.xsl
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/main64.xsl
@@ -46,7 +46,7 @@
<fo:block>
<fo:external-graphic>
<xsl:attribute name="src">
- url('img/image.png')
+ data:image/png;base64,<xsl:value-of
select="pcGts/page/image_region/container/data" />
</xsl:attribute>
</fo:external-graphic>
</fo:block>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl
similarity index 91%
copy from scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
copy to scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl
index 65a8c79..add0cba 100644
--- a/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_base64.xsl
@@ -11,8 +11,8 @@
pcGts/page/separator_region">
<!-- ID of the region, used to display id.png -->
- <xsl:variable name="id">
- <xsl:value-of select="@id" />
+ <xsl:variable name="data">
+ <xsl:value-of select="container/data" />
</xsl:variable>
<!-- Regions coordinates -->
@@ -47,7 +47,7 @@
<fo:block>
<fo:external-graphic>
<xsl:attribute name="src">
- url('img/<xsl:value-of select="$id" />.png')
+ url('data:image/png;base64,<xsl:value-of select="$data"
/>')
</xsl:attribute>
</fo:external-graphic>
</fo:block>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl
similarity index 100%
rename from scribo/sandbox/arthur/xml_transform/templates/pdf/regions.xsl
rename to scribo/sandbox/arthur/xml_transform/templates/pdf/regions_png.xsl
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.cc
b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
index dd35aff..ebfbed8 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.cc
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
@@ -23,69 +23,114 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+# include "xml_transform.hh"
# include "image_crop.hh"
# include "loader.hh"
-# include "xml_transform.hh"
+# include "common.hh"
+# include <iostream>
-XmlTransform::XmlTransform(QString output, QString xml_file) :
- output_dir_(output),
- xml_file_(xml_file)
+XmlTransform::XmlTransform(QString xml_file, QString image_file, QString output, QString
file) :
+ xml_file_(xml_file),
+ image_(image_file),
+ loader_(new Loader()),
+ file_(file)
{
- Loader loader;
- if (!loader.set_output(output_dir_))
- abort();
+ QFile fi(image_);
+ QFile fx(xml_file_);
+
+ if (file_ != QString::Null())
+ output_dir_ = "/tmp/xml_transform";
+ else
+ output_dir_ = output;
+
+ if (output_dir_ != QString::Null() && !loader_->set_output(output_dir_))
+ {
+ std::cout << "Cant't create " <<
output_dir_.toStdString() << "dir! Aborting..." << std::endl;
+ abort();
+ }
+ else if (!fi.exists() && image_ != QString::Null())
+ {
+ std::cout << "Image file does not exist ! Aborting..." <<
std::endl;
+ abort();
+ }
+ else if (!fx.exists())
+ {
+ std::cout << "XML file does not exist ! Aborting..." <<
std::endl;
+ abort();
+ }
+
+ crop_ = new ImageCrop(xml_file_, image_, output_dir_);
}
XmlTransform::~XmlTransform()
{
}
-void XmlTransform::createPDF (QString img, bool crop)
+void XmlTransform::fromBase64()
{
- Loader loader;
+ QString output = output_dir_;
+ output.append("img");
+
+ if (loader_->set_output(output))
+ crop_->from_base64();
+ else
+ abort();
+}
+void XmlTransform::toBase64(bool crop)
+{
QString output = output_dir_;
output.append("img");
- if (loader.set_output(output))
+ if (loader_->set_output(output))
{
- if (loader.load_xml(xml_file_, false, output_dir_))
- {
+ if (!crop)
+ crop_->crop_regions();
- ImageCrop Crop;
+ crop_->to_base64(file_, crop);
+ }
+ else
+ abort();
+}
- if (crop)
- Crop.crop_regions(xml_file_, img, output_dir_);
- else
- Crop.save_image(img, output_dir_);
+void XmlTransform::createPDF (bool crop, bool base64)
+{
+ if (loader_->xml_output(xml_file_, false, output_dir_))
+ {
+ if (!base64)
+ {
+ QString output = output_dir_;
+ output.append("img");
- loader.add_pdf_templates(crop, output_dir_);
+ if (loader_->set_output(output))
+ {
+ if (crop)
+ crop_->crop_regions();
+ else
+ crop_->save_image("image");
+ }
}
- else
- abort();
+
+ loader_->add_pdf_templates(crop, base64, output_dir_);
}
else
abort();
}
-void XmlTransform::createHTML(QString img)
+void XmlTransform::createHTML(bool base64)
{
- Loader loader;
-
- QString output = output_dir_;
- output.append("img");
-
- if (loader.set_output(output))
+ if (loader_->xml_output(xml_file_, true, output_dir_))
{
- if (loader.load_xml(xml_file_, true, output_dir_))
+ if (!base64)
{
- ImageCrop Crop;
-
- Crop.crop_regions(xml_file_, img, output_dir_);
- loader.add_html_templates(output_dir_);
+ QString output = output_dir_;
+ output.append("img");
+ if (loader_->set_output(output))
+ crop_->crop_regions();
+ else
+ abort();
}
- else
- abort();
+ loader_->add_html_templates(base64, output_dir_);
}
else
abort();
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.hh
b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
index 808c108..172bddb 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.hh
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
@@ -26,22 +26,32 @@
#ifndef XML_TRANFORM_HH
# define XML_TRANFORM_HH
-# include <QtGui>
+# include <QtCore>
+
+
+class Loader;
+class ImageCrop;
class XmlTransform : public QObject
{
Q_OBJECT
public:
- XmlTransform(QString output, QString xml_file);
+ XmlTransform(QString xml_file, QString image_file, QString output, QString file =
QString::Null());
~XmlTransform();
- void createHTML(QString img);
- void createPDF(QString img, bool crop);
+ void createHTML(bool base64);
+ void createPDF(bool crop, bool base64);
+ void toBase64(bool crop);
+ void fromBase64();
-protected:
+private:
QString output_dir_;
QString xml_file_;
+ QString image_;
+ Loader* loader_;
+ ImageCrop* crop_;
+ QString file_;
};
#endif // !XML_TRANFORM_HH
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.pro
b/scribo/sandbox/arthur/xml_transform/xml_transform.pro
index 161a7f4..c038cf6 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.pro
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.pro
@@ -1,5 +1,5 @@
######################################################################
-# Automatically generated by qmake (2.01a) jeu. juil. 8 16:33:27 2010
+# Automatically generated by qmake (2.01a) jeu. juil. 15 13:47:38 2010
######################################################################
TEMPLATE = app
@@ -10,11 +10,7 @@ QMAKE_CXXFLAGS +=
-I/amd/beyrouth/home/lrde/stage/crepin/git/olena/milena -I/amd
QT += xml
LIBS += `Magick++-config --libs`
+
# Input
-HEADERS += domitem.hh dommodel.hh image_crop.hh loader.hh xml_transform.hh
-SOURCES += domitem.cc \
- dommodel.cc \
- image_crop.cc \
- loader.cc \
- main.cc \
- xml_transform.cc
+HEADERS += common.hh image_crop.hh loader.hh xml_transform.hh
+SOURCES += common.cc image_crop.cc loader.cc main.cc xml_transform.cc
--
1.5.6.5