* arthur/xml_transform/README
* arthur/xml_transform/loader.cc
* arthur/xml_transform/loader.hh
* arthur/xml_transform/main.cc
* arthur/xml_transform/xml_transform.cc
* arthur/xml_transform/xml_transform.hh
* arthur/xml_transform/templates/pdf/regions_svg.xsl,
* arthur/xml_transform/templates/pdf/svg_generator.sh: New.
---
scribo/sandbox/ChangeLog | 15 +++
scribo/sandbox/arthur/xml_transform/README | 25 ++++--
scribo/sandbox/arthur/xml_transform/loader.cc | 15 +++
scribo/sandbox/arthur/xml_transform/loader.hh | 1 +
scribo/sandbox/arthur/xml_transform/main.cc | 41 ++++++---
.../xml_transform/templates/pdf/regions_svg.xsl | 98 ++++++++++++++++++++
.../xml_transform/templates/pdf/svg_generator.sh | 3 +
.../sandbox/arthur/xml_transform/xml_transform.cc | 10 ++
.../sandbox/arthur/xml_transform/xml_transform.hh | 1 +
9 files changed, 188 insertions(+), 21 deletions(-)
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/pdf/regions_svg.xsl
create mode 100644 scribo/sandbox/arthur/xml_transform/templates/pdf/svg_generator.sh
diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog
index 8d7b3e9..7c53037 100644
--- a/scribo/sandbox/ChangeLog
+++ b/scribo/sandbox/ChangeLog
@@ -1,3 +1,18 @@
+2010-07-22 Arthur Crepin-Leblond <crepin(a)ptaouchnok.lrde.epita.fr>
+
+ SVG output.
+
+ * arthur/xml_transform/README
+ * arthur/xml_transform/loader.cc
+ * arthur/xml_transform/loader.hh
+ * arthur/xml_transform/main.cc
+ * arthur/xml_transform/xml_transform.cc
+ * arthur/xml_transform/xml_transform.hh
+
+ * arthur/xml_transform/templates/pdf/regions_svg.xsl,
+ * arthur/xml_transform/templates/pdf/svg_generator.sh: New.
+
+
2010-07-15 Arthur Crepin-Leblond <crepin(a)stockholm.lrde.epita.fr>
XML Tranform.
diff --git a/scribo/sandbox/arthur/xml_transform/README
b/scribo/sandbox/arthur/xml_transform/README
index aedf220..4e98a76 100644
--- a/scribo/sandbox/arthur/xml_transform/README
+++ b/scribo/sandbox/arthur/xml_transform/README
@@ -1,23 +1,29 @@
xml_transform
-
OPTIONS:
HTML output:
- --html <xml> <ppm> <out_dir> : HTML output with non-text regions
croped into many png files.
+ --html <xml> <ppm> <out_dir> : HTML output with non-text regions
cropped into many png files.
--html-base64 <xml> <out_dir> : HTML output from a container XML file.
PDF output:
- --pdf <xml> <ppm> <out_dir> : PDF output with non-text regions
croped into many png files.
+ --pdf <xml> <ppm> <out_dir> : PDF output with non-text regions
cropped 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-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.
+
+SVG output:
+ --svg <xml> <out_dir> : SVG output (works only with base 64 xml encoded.
Base 64 operations:
- --to-base64 <xml> <ppm> <out_xml> : Produces a container XML file
by converting croped pictures into base 64 format.
+ --to-base64 <xml> <ppm> <out_xml> : Produces a container XML file
by converting cropped 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.
+For PDF/HTML/SVG output, Bourne shell scripts are provided to produce the outputs, just
run sh *_generator.sh
+Requirements:
+PDF : fop >= 0.95
+HTML : xsltproc
+SVG : trunk version of fop
BUILD:
@@ -25,5 +31,10 @@ Chnage the environment variable QMAKE_CXXFLAGS in xml_transfrom.pro
then
mkdir _build
cd _build
+cp -r ../templates .
qmake ../xml_transfrom.pro
-make
\ No newline at end of file
+make
+
+/!\ IMPORTANT NOTE /!\
+
+xml_transfrom uses a templates directory, binary and this folder should be in the same
place.
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_transform/loader.cc
b/scribo/sandbox/arthur/xml_transform/loader.cc
index 2b64337..1698899 100644
--- a/scribo/sandbox/arthur/xml_transform/loader.cc
+++ b/scribo/sandbox/arthur/xml_transform/loader.cc
@@ -126,6 +126,21 @@ void Loader::add_pdf_templates(bool crop, bool base64, QString
output)
}
}
+void Loader::add_svg_templates(QString output)
+{
+ QFile regions("templates/pdf/regions_svg.xsl");
+ regions.copy(output + "regions.xsl");
+
+ QFile gen("templates/pdf/svg_generator.sh");
+ gen.copy(output + "svg_generator.sh");
+
+ QFile line("templates/pdf/line.xsl");
+ line.copy(output + "line.xsl");
+
+ QFile xsl("templates/pdf/main_crop.xsl");
+ xsl.copy(output + "main.xsl");
+}
+
bool Loader::xml_output(QString xml_file, bool html, QString output)
{
QFile file(xml_file);
diff --git a/scribo/sandbox/arthur/xml_transform/loader.hh
b/scribo/sandbox/arthur/xml_transform/loader.hh
index fadceed..3cbae5c 100644
--- a/scribo/sandbox/arthur/xml_transform/loader.hh
+++ b/scribo/sandbox/arthur/xml_transform/loader.hh
@@ -42,6 +42,7 @@ class Loader : public QObject
QDomDocument* xml_to_dom(QString xml_file);
bool set_output(QString& output);
void add_pdf_templates(bool crop, bool base64, QString output);
+ void add_svg_templates(QString output);
void add_html_templates(bool base64, QString output);
};
diff --git a/scribo/sandbox/arthur/xml_transform/main.cc
b/scribo/sandbox/arthur/xml_transform/main.cc
index c259c76..d1c789d 100644
--- a/scribo/sandbox/arthur/xml_transform/main.cc
+++ b/scribo/sandbox/arthur/xml_transform/main.cc
@@ -6,20 +6,27 @@ int main(int argc, char **argv)
{
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 cropped 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 cropped 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 cropped 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";
+ man = "xml_transform\n"
+ "OPTIONS:\n\n"
+ "HTML output:\n"
+ "\t--html <xml> <ppm> <out_dir> : HTML output with non-text
regions cropped into many png files.\n"
+ "\t--html-base64 <xml> <out_dir> : HTML output from a container XML
file.\n\n"
+ "PDF output:\n"
+ "\t--pdf <xml> <ppm> <out_dir> : PDF output with non-text
regions cropped into many png files.\n"
+ "\t--pdf-no-crop <xml> <ppm> <out_dir>: PDF output with the
entire picture displayed over the text.\n"
+ "\t--pdf-base64 <xml> <out_dir> : PDF output from a container XML
file.\n"
+ "\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"
+ "SVG output:\n"
+ "\t--svg <xml> <out_dir> : SVG output (works only with base 64 xml
encoded.\n\n"
+ "Base 64 operations:\n"
+ "\t--to-base64 <xml> <ppm> <out_xml> : Produces a container
XML file by converting cropped pictures into base 64 format.\n"
+ "\t--to-base64-no-crop <xml> <ppm> <out_xml> : Same as
to-base64 but only the picture is converted in base 64.\n"
+ "\t--from-base64 <xml> <out_dir> : Decodes a XML container file to
produce original image files.\n\n"
+ "For PDF/HTML/SVG output, Bourne shell scripts are provided to produce the
outputs, just run sh *_generator.sh \n"
+ "Requirements:\n"
+ "PDF : fop >= 0.95\n"
+ "HTML : xsltproc\n"
+ "SVG : trunk version of fop\n";
if (argc > 4)
{
@@ -60,6 +67,7 @@ int main(int argc, char **argv)
else if (argc > 3)
{
std::string pdfbase64 = "--pdf-base64";
+ std::string svg = "--svg";
std::string pdfbase64nocrop = "--pdf-base64-no-crop";
std::string htmlbase64 = "--html-base64";
std::string from_base64 = "--from-base64";
@@ -69,6 +77,11 @@ int main(int argc, char **argv)
XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
xmlt.createPDF(true, true);
}
+ else if (svg.compare(argv[1]) == 0)
+ {
+ XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
+ xmlt.createSVG();
+ }
else if (pdfbase64nocrop.compare(argv[1]) == 0)
{
XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_svg.xsl
b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_svg.xsl
new file mode 100644
index 0000000..86b5f51
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/regions_svg.xsl
@@ -0,0 +1,98 @@
+<?xml version="1.0"?>
+<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
+
+ <!-- FILE: regions.xsl
+ DESCRIPTION: Match all regions that are not text to display them -->
+
+ <xsl:template match="pcGts/page/image_region|
+ pcGts/page/graphic_region|
+ pcGts/page/chart_region|
+ pcGts/page/table_region|
+ pcGts/page/separator_region">
+
+ <!-- ID of the region, used to display id.png -->
+ <xsl:variable name="data">
+ <xsl:value-of select="container/data" />
+ </xsl:variable>
+
+ <!-- Regions coordinates -->
+ <xsl:variable name="y1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="ascending"
data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="x1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="ascending"
data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="y2">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="descending"
data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="x2">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="descending"
data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <!-- END OF regions coordinates -->
+
+ <fo:block-container>
+
+ <fo:block>
+ <fo:instream-foreign-object>
+ <svg:svg
xmlns:svg="http://www.w3.org/2000/svg"
+
xmlns:xlink="http://www.w3.org/1999/xlink"
+ Version="1.1">
+
+ <xsl:attribute name="viewBox">
+ <xsl:value-of select="$x1" /> <xsl:value-of
select="$y1" /> <xsl:value-of select="$x2" />
<xsl:value-of select="$y2" />
+ </xsl:attribute>
+
+ <svg:image position="absolute">
+
+ <xsl:attribute name="y">
+ <xsl:value-of select="$y1" />
+ </xsl:attribute>
+
+ <xsl:attribute name="x">
+ <xsl:value-of select="$x1" />
+ </xsl:attribute>
+
+ <xsl:attribute name="width">
+ <xsl:value-of select="$x2 - $x1" />
+ </xsl:attribute>
+
+ <xsl:attribute name="height">
+ <xsl:value-of select="$y2 - $y1" />
+ </xsl:attribute>
+
+ <xsl:attribute
name="xlink:href">data:image/png;base64,<xsl:value-of
select="$data" /></xsl:attribute>
+ </svg:image>
+
+ </svg:svg>
+
+ </fo:instream-foreign-object>
+
+ </fo:block>
+ </fo:block-container>
+
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/scribo/sandbox/arthur/xml_transform/templates/pdf/svg_generator.sh
b/scribo/sandbox/arthur/xml_transform/templates/pdf/svg_generator.sh
new file mode 100644
index 0000000..0d4907c
--- /dev/null
+++ b/scribo/sandbox/arthur/xml_transform/templates/pdf/svg_generator.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+fop -xsl main.xsl -xml output.xml -svg output.svg
\ No newline at end of file
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.cc
b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
index ebfbed8..c40366a 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.cc
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.cc
@@ -117,6 +117,16 @@ void XmlTransform::createPDF (bool crop, bool base64)
abort();
}
+void XmlTransform::createSVG ()
+{
+ if (loader_->xml_output(xml_file_, false, output_dir_))
+ {
+ loader_->add_svg_templates(output_dir_);
+ }
+ else
+ abort();
+}
+
void XmlTransform::createHTML(bool base64)
{
if (loader_->xml_output(xml_file_, true, output_dir_))
diff --git a/scribo/sandbox/arthur/xml_transform/xml_transform.hh
b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
index 172bddb..30d5c6c 100644
--- a/scribo/sandbox/arthur/xml_transform/xml_transform.hh
+++ b/scribo/sandbox/arthur/xml_transform/xml_transform.hh
@@ -42,6 +42,7 @@ class XmlTransform : public QObject
void createHTML(bool base64);
void createPDF(bool crop, bool base64);
+ void createSVG();
void toBase64(bool crop);
void fromBase64();
--
1.5.6.5