Commit de57fc49 authored by Arthur Crepin-Leblond's avatar Arthur Crepin-Leblond Committed by Guillaume Lazzara
Browse files

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.
parent 58691e5c
2010-07-22 Arthur Crepin-Leblond <crepin@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@stockholm.lrde.epita.fr>
XML Tranform.
......
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
......@@ -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);
......
......@@ -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);
};
......
......@@ -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]);
......
<?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>
#!/bin/sh
fop -xsl main.xsl -xml output.xml -svg output.svg
\ No newline at end of file
......@@ -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_))
......
......@@ -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();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment