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

OpenDocument output (odt and odf).

        * arthur/xml_transform/templates/opendoc/css.css,
        * arthur/xml_transform/templates/opendoc/opendoc_generator.sh,
        * arthur/xml_transform/templates/opendoc/xsl.xsl: New.

        * 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
parent de57fc49
2010-07-23 Arthur Crepin-Leblond <crepin@ptaouchnok.lrde.epita.fr>
OpenDocument output (odt and odf).
* arthur/xml_transform/templates/opendoc/css.css,
* arthur/xml_transform/templates/opendoc/opendoc_generator.sh,
* arthur/xml_transform/templates/opendoc/xsl.xsl: New.
* 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
2010-07-22 Arthur Crepin-Leblond <crepin@ptaouchnok.lrde.epita.fr>
SVG output.
......
......@@ -14,16 +14,23 @@ PDF output:
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 cropped pictures into base 64 format.
OpenDocument output:
--open <xml> <ppm> <out_dir> : OpenDocument output (odt, odf).
Base 64 operations:
--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
For PDF/HTML/SVG/OD 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
OpenDocument : ooconvert
BUILD:
......
......@@ -141,6 +141,18 @@ void Loader::add_svg_templates(QString output)
xsl.copy(output + "main.xsl");
}
void Loader::add_open_templates(QString output)
{
QFile css("templates/opendoc/css.css");
css.copy(output + "css.css");
QFile gen("templates/opendoc/opendoc_generator.sh");
gen.copy(output + "opendoc_generator.sh");
QFile xsl("templates/opendoc/xsl.xsl");
xsl.copy(output + "xsl.xsl");
}
bool Loader::xml_output(QString xml_file, bool html, QString output)
{
QFile file(xml_file);
......
......@@ -43,6 +43,7 @@ class Loader : public QObject
bool set_output(QString& output);
void add_pdf_templates(bool crop, bool base64, QString output);
void add_svg_templates(QString output);
void add_open_templates(QString output);
void add_html_templates(bool base64, QString output);
};
......
......@@ -19,18 +19,25 @@ int main(int argc, char **argv)
"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\n"
"OpenDocument output:\n"
"\t--open <xml> <ppm> <out_dir> : OpenDocument output (odt, odf).\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"
"For PDF/HTML/SVG/OD 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";
"SVG : trunk version of fop\n"
"OpenDocument : ooconvert";
if (argc > 4)
{
std::string html = "--html";
std::string open = "--open";
std::string pdf = "--pdf";
std::string pdf_no_crop = "--pdf-no-crop";
std::string to_base64 = "--to-base64";
......@@ -41,11 +48,16 @@ int main(int argc, char **argv)
XmlTransform xmlt(argv[2], argv[3], argv[4]);
xmlt.createHTML(false);
}
if (pdf.compare(argv[1]) == 0)
else if (pdf.compare(argv[1]) == 0)
{
XmlTransform xmlt(argv[2], argv[3], argv[4]);
xmlt.createPDF(true, false);
}
else if (open.compare(argv[1]) == 0)
{
XmlTransform xmlt(argv[2], argv[3], argv[4]);
xmlt.createOpen();
}
else if (pdf_no_crop.compare(argv[1]) == 0)
{
XmlTransform xmlt(argv[2], argv[3], argv[4]);
......
.line
{
position:absolute;
z-index:7;
display:inline;
white-space:pre;
/* FIXME */
letter-spacing:-2px;
padding:0px;
margin:0px;
filter:alpha(opacity=100);
font-family:"Times New Roman", Times, serif;
}
.para
{
position:absolute;
z-index:6;
}
.region
{
position:absolute;
z-index:5;
}
.image
{
position:absolute;
border:0;
}
\ No newline at end of file
#!/bin/sh
if [ -z "$1" ]
then
echo "opendoc_generator <odt|odf>";
else
if [ "$1" == "odt" ]
then
echo "saving to output.odt";
xsltproc xsl.xsl output.xml > output.html
ooconvert output.html output.odt
rm output.html
elif [ "$1" == "odf" ]
then
echo "saving to output.odf";
xsltproc xsl.xsl output.xml > output.html
ooconvert output.html output.odf;
rm output.html
else
echo "opendoc_generator <odt|odf>";
fi
fi
#rm output.html
\ No newline at end of file
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <!-- "/" means the whole document (root) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SCRIBO</title>
<link rel="stylesheet" type="text/css" href="css.css" />
</head>
<body>
<xsl:for-each select="pcGts/page/graphic_region|
pcGts/page/image_region|
pcGts/page/chart_region|
pcGts/page/table_region|
pcGts/page/separator_region|
pcGts/page/text_region/paragraph/line">
<!-- Regions Coordinates -->
<!-- y1 -->
<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>
<!-- x2 -->
<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>
<!-- y2 -->
<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>
<!-- x1 -->
<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>
<!-- END OF Regions Coordinates -->
<!-- TEXT LINE-->
<xsl:if test="name() = 'line'">
<xsl:variable name="colour">
<xsl:choose>
<xsl:when test="../../@txt_colour != ''">
<xsl:value-of select="../../@txt_colour" />
</xsl:when>
<xsl:otherwise>
Black
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- x_height -->
<xsl:variable name="x_height">
<xsl:value-of select="../../@x_height" />
</xsl:variable>
<!-- a_height -->
<xsl:variable name="a_height">
<xsl:value-of select="../../@a_height" />
</xsl:variable>
<!-- ABS(d_height) -->
<xsl:variable name="d_height_abs">
<xsl:choose>
<xsl:when test="../../@d_height &lt; 0">
<xsl:value-of select="-../../@d_height" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../../@d_height" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- a_height computed, i.e>
if (A - X < |D|)
A = X + |D|
-->
<xsl:variable name="a">
<xsl:choose>
<xsl:when test="($a_height - $x_height) &lt; $d_height_abs">
<xsl:value-of select="$x_height + $d_height_abs" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$a_height" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- d_height computed, i.e>
if (A - A > |D|)
|D| = A - X
-->
<xsl:variable name="d">
<xsl:choose>
<xsl:when test="($a_height - $x_height) &gt; $d_height_abs">
<xsl:value-of select="$a_height - $x_height" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$d_height_abs" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<div class="line">
<xsl:attribute name="style">
height:auto;
font-size:<xsl:value-of select="$a+$d" />px;
width:<xsl:value-of select="$x2 - $x1" />px;
left:<xsl:value-of select="$x1 " />px;
top:<xsl:value-of select="$y1 " />px;
color:<xsl:value-of select="$colour" />;
</xsl:attribute>
<xsl:value-of select="@text"/>
</div>
</xsl:if>
<!-- ENF OF TEXT LINE -->
<!-- TEXT REGION -->
<xsl:if test="name() = 'text_region'">
<div class="region">
<xsl:attribute name="style">
height:<xsl:value-of select="$y2 - $y1" />px;
width:<xsl:value-of select="$x2 - $x1" />px;
left:<xsl:value-of select="$x1" />px;
top:<xsl:value-of select="$y1" />px;
</xsl:attribute>
</div>
</xsl:if>
<!-- ENF OF TEXT REGION -->
<!-- PARAGRAPH -->
<xsl:if test="name() = 'paragraph'">
<div class="para">
<xsl:attribute name="style">
height:<xsl:value-of select="$y2 - $y1" />px;
width:<xsl:value-of select="$x2 - $x1" />px;
left:<xsl:value-of select="$x1" />px;
top:<xsl:value-of select="$y1" />px;
</xsl:attribute>
</div>
</xsl:if>
<!-- ENF OF PARAGRAPH -->
<!-- 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" />
</xsl:variable>
<!-- depth -->
<xsl:variable name="depth">
<xsl:choose>
<xsl:when test="name() = 'separator_region'">
1
</xsl:when>
<xsl:otherwise>
4
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<div class="image">
<xsl:attribute name="style">
top:<xsl:value-of select="$y1" />px;
left:<xsl:value-of select="$x1" />px;
width:<xsl:value-of select="$x2 - $x1"/>px;
height:<xsl:value-of select="$y2 - $y1"/>px;
z-index:<xsl:value-of select="$depth"/>;
</xsl:attribute>
<img>
<xsl:attribute name="alt">
<xsl:value-of select="name()" />
</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="src">img/<xsl:value-of select="$id"/>.png</xsl:attribute>
</img>
</div>
</xsl:if>
<!-- END NON-TEXT REGIONS -->
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
......@@ -117,6 +117,25 @@ void XmlTransform::createPDF (bool crop, bool base64)
abort();
}
void XmlTransform::createOpen ()
{
if (loader_->xml_output(xml_file_, false, output_dir_))
{
QString output = output_dir_;
output.append("img");
if (loader_->set_output(output))
{
crop_->crop_regions();
loader_->add_open_templates(output_dir_);
}
else
abort();
}
else
abort();
}
void XmlTransform::createSVG ()
{
if (loader_->xml_output(xml_file_, false, output_dir_))
......
......@@ -43,6 +43,7 @@ class XmlTransform : public QObject
void createHTML(bool base64);
void createPDF(bool crop, bool base64);
void createSVG();
void createOpen();
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