diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
| commit | 5a4fb2325f60d292b47330f540b26a3279341c90 (patch) | |
| tree | d2aa7967be25450b83e625025366c618101ae49f /src/extension/internal/odf.cpp | |
| parent | The Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff) | |
| parent | Remove Snap menu item and improve grid menu item text (diff) | |
| download | inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip | |
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/extension/internal/odf.cpp')
| -rw-r--r-- | src/extension/internal/odf.cpp | 1315 |
1 files changed, 510 insertions, 805 deletions
diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 8bb96920d..52fabcf3c 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -4,7 +4,7 @@ * This is an an entry in the extensions mechanism to begin to enable * the inputting and outputting of OpenDocument Format (ODF) files from * within Inkscape. Although the initial implementations will be very lossy - * do to the differences in the models of SVG and ODF, they will hopefully + * due to the differences in the models of SVG and ODF, they will hopefully * improve greatly with time. People should consider this to be a framework * that can be continously upgraded for ever improving fidelity. Potential * developers should especially look in preprocess() and writeTree() to see how @@ -15,8 +15,10 @@ * Authors: * Bob Jamison * Abhishek Sharma + * Kris De Gussem * * Copyright (C) 2006, 2007 Bob Jamison + * Copyright (C) 2013 Kris De Gussem * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -45,7 +47,7 @@ #include <stdio.h> #include <time.h> #include <vector> - +#include <math.h> //# Inkscape includes #include "clear-n_.h" @@ -73,37 +75,29 @@ #include "sp-flowtext.h" #include "svg/svg.h" #include "text-editing.h" +#include "util/units.h" +#include "uri.h" -//# DOM-specific includes -#include "dom/dom.h" -#include "dom/util/ziptool.h" -#include "dom/io/domstream.h" -#include "dom/io/bufferstream.h" -#include "dom/io/stringstream.h" - - +#include "inkscape-version.h" #include "document.h" - #include "extension/extension.h" - - +#include "io/inkscapestream.h" +#include "io/bufferstream.h" +#include <util/ziptool.h> +#include <iomanip> namespace Inkscape { namespace Extension { namespace Internal { - - - //# Shorthand notation -typedef org::w3c::dom::DOMString DOMString; -typedef org::w3c::dom::XMLCh XMLCh; -typedef org::w3c::dom::io::OutputStreamWriter OutputStreamWriter; -typedef org::w3c::dom::io::BufferOutputStream BufferOutputStream; -typedef org::w3c::dom::io::StringOutputStream StringOutputStream; +typedef Inkscape::IO::BufferOutputStream BufferOutputStream; +typedef Inkscape::IO::OutputStreamWriter OutputStreamWriter; +typedef Inkscape::IO::StringOutputStream StringOutputStream; + //######################################################################## //# C L A S S SingularValueDecomposition @@ -211,9 +205,11 @@ public: SVDMatrix transpose() { SVDMatrix result(cols, rows); - for (unsigned int i=0 ; i<rows ; i++) - for (unsigned int j=0 ; j<cols ; j++) + for (unsigned int i=0 ; i<rows ; i++){ + for (unsigned int j=0 ; j<cols ; j++){ result(j, i) = d[i*cols + j]; + } + } return result; } @@ -239,9 +235,11 @@ private: rows = other.rows; cols = other.cols; size = other.size; + badval = other.badval; d = new double[size]; - for (unsigned int i=0 ; i<size ; i++) + for (unsigned int i=0 ; i<size ; i++){ d[i] = other.d[i]; + } } double badval; @@ -289,11 +287,13 @@ public: @return Structure to access U, S and V. */ - SingularValueDecomposition (const SVDMatrix &mat) + SingularValueDecomposition (const SVDMatrix &mat) : + A (mat), + U (), + s (NULL), + s_size (0), + V () { - A = mat; - s = NULL; - s_size = 0; calculate(); } @@ -801,7 +801,6 @@ void SingularValueDecomposition::calculate() } - /** * Return the left singular vectors * @return U @@ -899,7 +898,6 @@ static Glib::ustring getAttribute( Inkscape::XML::Node *node, char const *attrNa } - /** * Get the extension suffix from the end of a file name */ @@ -919,7 +917,6 @@ static Glib::ustring getExtension(const Glib::ustring &fname) return ext; } - static Glib::ustring formatTransform(Geom::Affine &tf) { Glib::ustring str; @@ -935,9 +932,6 @@ static Glib::ustring formatTransform(Geom::Affine &tf) } - - - /** * Get the general transform from SVG pixels to * ODF cm @@ -947,7 +941,7 @@ static Geom::Affine getODFTransform(const SPItem *item) //### Get SVG-to-ODF transform Geom::Affine tf (item->i2dt_affine()); //Flip Y into document coordinates - double doc_height = SP_ACTIVE_DOCUMENT->getHeight(); + double doc_height = SP_ACTIVE_DOCUMENT->getHeight().value("px"); Geom::Affine doc2dt_tf = Geom::Affine(Geom::Scale(1.0, -1.0)); /// @fixme hardcoded desktop transform doc2dt_tf = doc2dt_tf * Geom::Affine(Geom::Translate(0, doc_height)); tf = tf * doc2dt_tf; @@ -956,8 +950,6 @@ static Geom::Affine getODFTransform(const SPItem *item) } - - /** * Get the bounding box of an item, as mapped onto * an ODF document, in cm. @@ -965,7 +957,7 @@ static Geom::Affine getODFTransform(const SPItem *item) static Geom::OptRect getODFBoundingBox(const SPItem *item) { // TODO: geometric or visual? - Geom::OptRect bbox = ((SPItem *)item)->documentVisualBounds(); + Geom::OptRect bbox = item->documentVisualBounds(); if (bbox) { *bbox *= Geom::Affine(Geom::Scale(pxToCm)); } @@ -973,7 +965,6 @@ static Geom::OptRect getODFBoundingBox(const SPItem *item) } - /** * Get the transform for an item, correcting for * handedness reversal @@ -987,7 +978,6 @@ static Geom::Affine getODFItemTransform(const SPItem *item) } - /** * Get some fun facts from the transform */ @@ -1011,16 +1001,9 @@ static void analyzeTransform(Geom::Affine &tf, double s1 = svd.getS(1); xscale = s0; yscale = s1; - //g_message("## s0:%.3f s1:%.3f", s0, s1); - //g_message("## u:%.3f %.3f %.3f %.3f", U(0,0), U(0,1), U(1,0), U(1,1)); - //g_message("## v:%.3f %.3f %.3f %.3f", V(0,0), V(0,1), V(1,0), V(1,1)); - //g_message("## vt:%.3f %.3f %.3f %.3f", Vt(0,0), Vt(0,1), Vt(1,0), Vt(1,1)); - //g_message("## uvt:%.3f %.3f %.3f %.3f", UVt(0,0), UVt(0,1), UVt(1,0), UVt(1,1)); rotate = UVt(0,0); } - - static void gatherText(Inkscape::XML::Node *node, Glib::ustring &buf) { if (node->type() == Inkscape::XML::TEXT_NODE) @@ -1038,15 +1021,14 @@ static void gatherText(Inkscape::XML::Node *node, Glib::ustring &buf) } + /** * FIRST PASS. * Method descends into the repr tree, converting image, style, and gradient info * into forms compatible in ODF. */ -void -OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) +void OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) { - Glib::ustring nodeName = node->name(); Glib::ustring id = getAttribute(node, "id"); @@ -1074,18 +1056,16 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) //Now consider items. SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(node); if (!reprobj) + { return; + } if (!SP_IS_ITEM(reprobj)) - { + { return; - } - SPItem *item = SP_ITEM(reprobj); - //### Get SVG-to-ODF transform - Geom::Affine tf = getODFTransform(item); + } if (nodeName == "image" || nodeName == "svg:image") { - //g_message("image"); Glib::ustring href = getAttribute(node, "xlink:href"); if (href.size() > 0) { @@ -1102,12 +1082,9 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) imageTable[oldName] = newName; Glib::ustring comment = "old name was: "; comment.append(oldName); - URI oldUri(oldName); - //g_message("oldpath:%s", oldUri.getNativePath().c_str()); + Inkscape::URI oldUri(oldName.c_str()); //# if relative to the documentURI, get proper path - URI resUri = documentUri.resolve(oldUri); - DOMString pathName = resUri.getNativePath(); - //g_message("native path:%s", pathName.c_str()); + std::string pathName = documentUri.getFullPath(oldUri.getFullPath("")); ZipEntry *ze = zf.addFile(pathName, comment); if (ze) { @@ -1127,7 +1104,6 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) } - /** * Writes the manifest. Currently it only changes according to the * file names of images packed into the zip file. @@ -1140,25 +1116,25 @@ bool OdfOutput::writeManifest(ZipFile &zf) time_t tim; time(&tim); - outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - outs.printf("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" file: manifest.xml\n"); - outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> - outs.printf(" http://www.inkscape.org\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">\n"); - outs.printf(" <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>\n"); - outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>\n"); - outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>\n"); - outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>\n"); - outs.printf(" <!--List our images here-->\n"); + outs.writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + outs.writeString("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n"); + outs.writeString("\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" file: manifest.xml\n"); + outs.printf (" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> + outs.writeString(" http://www.inkscape.org\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("\n"); + outs.writeString("<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">\n"); + outs.writeString(" <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>\n"); + outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>\n"); + outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>\n"); + outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>\n"); + outs.writeString(" <!--List our images here-->\n"); std::map<Glib::ustring, Glib::ustring>::iterator iter; for (iter = imageTable.begin() ; iter!=imageTable.end() ; ++iter) { @@ -1176,7 +1152,7 @@ bool OdfOutput::writeManifest(ZipFile &zf) else if (ext == ".jpg") outs.printf("image/jpeg"); outs.printf("\" manifest:full-path=\""); - outs.printf(newName.c_str()); + outs.writeString(newName.c_str()); outs.printf("\"/>\n"); } outs.printf("</manifest:manifest>\n"); @@ -1204,65 +1180,79 @@ bool OdfOutput::writeMeta(ZipFile &zf) time(&tim); std::map<Glib::ustring, Glib::ustring>::iterator iter; - Glib::ustring creator = "unknown"; + Glib::ustring InkscapeVersion = Glib::ustring("Inkscape.org - ") + Inkscape::version_string; + Glib::ustring creator = InkscapeVersion; iter = metadata.find("dc:creator"); if (iter != metadata.end()) + { creator = iter->second; - Glib::ustring date = ""; + } + + Glib::ustring date; + Glib::ustring moddate; + char buf [80]; + time_t rawtime; + struct tm * timeinfo; + time (&rawtime); + timeinfo = localtime (&rawtime); + strftime (buf,80,"%Y-%m-%d %H:%M:%S",timeinfo); + moddate = Glib::ustring(buf); + iter = metadata.find("dc:date"); if (iter != metadata.end()) + { date = iter->second; + } + else + { + date = moddate; + } - outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" file: meta.xml\n"); - outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> - outs.printf(" http://www.inkscape.org\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:document-meta\n"); - outs.printf("xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); - outs.printf("xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); - outs.printf("xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); - outs.printf("xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); - outs.printf("xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); - outs.printf("xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); - outs.printf("xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); - outs.printf("xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); - outs.printf("office:version=\"1.0\">\n"); - outs.printf("<office:meta>\n"); - outs.printf(" <meta:generator>Inkscape.org - 0.45</meta:generator>\n"); - outs.printf(" <meta:initial-creator>%#s</meta:initial-creator>\n", - creator.c_str()); - outs.printf(" <meta:creation-date>%#s</meta:creation-date>\n", date.c_str()); + outs.writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" file: meta.xml\n"); + outs.printf (" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> + outs.writeString(" http://www.inkscape.org\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:document-meta\n"); + outs.writeString("xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); + outs.writeString("xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); + outs.writeString("xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); + outs.writeString("xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); + outs.writeString("xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); + outs.writeString("xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); + outs.writeString("xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); + outs.writeString("xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); + outs.writeString("office:version=\"1.0\">\n"); + outs.writeString("<office:meta>\n"); + Glib::ustring tmp = Glib::ustring::compose(" <meta:generator>%1</meta:generator>\n", InkscapeVersion); + tmp += Glib::ustring::compose(" <meta:initial-creator>%1</meta:initial-creator>\n", creator); + tmp += Glib::ustring::compose(" <meta:creation-date>%1</meta:creation-date>\n", date); + tmp += Glib::ustring::compose(" <dc:date>%1</dc:date>\n", moddate); + outs.writeUString(tmp); for (iter = metadata.begin() ; iter != metadata.end() ; ++iter) - { + { Glib::ustring name = iter->first; Glib::ustring value = iter->second; - if (name.size() > 0 && value.size()>0) - { - outs.printf(" <%#s>%#s</%#s>\n", - name.c_str(), value.c_str(), name.c_str()); - } + if (!name.empty() && !value.empty()) + { + tmp = Glib::ustring::compose(" <%1>%2</%3>\n", name, value, name); + outs.writeUString(tmp); } - outs.printf(" <meta:editing-cycles>2</meta:editing-cycles>\n"); - outs.printf(" <meta:editing-duration>PT56S</meta:editing-duration>\n"); - outs.printf(" <meta:user-defined meta:name=\"Info 1\"/>\n"); - outs.printf(" <meta:user-defined meta:name=\"Info 2\"/>\n"); - outs.printf(" <meta:user-defined meta:name=\"Info 3\"/>\n"); - outs.printf(" <meta:user-defined meta:name=\"Info 4\"/>\n"); - outs.printf(" <meta:document-statistic meta:object-count=\"2\"/>\n"); - outs.printf("</office:meta>\n"); - outs.printf("</office:document-meta>\n"); - outs.printf("\n"); - outs.printf("\n"); - - + } + // outs.writeString(" <meta:editing-cycles>2</meta:editing-cycles>\n"); + // outs.writeString(" <meta:editing-duration>PT56S</meta:editing-duration>\n"); + // outs.writeString(" <meta:user-defined meta:name=\"Info 1\"/>\n"); + // outs.writeString(" <meta:user-defined meta:name=\"Info 2\"/>\n"); + // outs.writeString(" <meta:user-defined meta:name=\"Info 3\"/>\n"); + // outs.writeString(" <meta:user-defined meta:name=\"Info 4\"/>\n"); + // outs.writeString(" <meta:document-statistic meta:object-count=\"2\"/>\n"); + outs.writeString("</office:meta>\n"); + outs.writeString("</office:document-meta>\n"); outs.close(); //Make our entry @@ -1274,208 +1264,6 @@ bool OdfOutput::writeMeta(ZipFile &zf) } - - -/** - * This is called just before writeTree(), since it will write style and - * gradient information above the <draw> tag in the content.xml file - */ -bool OdfOutput::writeStyle(ZipFile &zf) -{ - BufferOutputStream bouts; - OutputStreamWriter outs(bouts); - - /* - ========================================================== - Dump our style table. Styles should have a general layout - something like the following. Look in: - http://books.evc-cit.info/odbook/ch06.html#draw-style-file-section - for style and gradient information. - <style:style style:name="gr13" - style:family="graphic" style:parent-style-name="standard"> - <style:graphic-properties draw:stroke="solid" - svg:stroke-width="0.1cm" - svg:stroke-color="#ff0000" - draw:fill="solid" draw:fill-color="#e6e6ff"/> - </style:style> - ========================================================== - */ - outs.printf("<!-- ####### Styles from Inkscape document ####### -->\n"); - std::vector<StyleInfo>::iterator iter; - for (iter = styleTable.begin() ; iter != styleTable.end() ; ++iter) - { - outs.printf("<style:style style:name=\"%s\"", iter->name.c_str()); - StyleInfo s(*iter); - outs.printf(" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); - outs.printf(" <style:graphic-properties"); - outs.printf(" draw:fill=\"%s\" ", s.fill.c_str()); - if (s.fill != "none") - { - outs.printf(" draw:fill-color=\"%s\" ", s.fillColor.c_str()); - outs.printf(" draw:fill-opacity=\"%s\" ", s.fillOpacity.c_str()); - } - outs.printf(" draw:stroke=\"%s\" ", s.stroke.c_str()); - if (s.stroke != "none") - { - outs.printf(" svg:stroke-width=\"%s\" ", s.strokeWidth.c_str()); - outs.printf(" svg:stroke-color=\"%s\" ", s.strokeColor.c_str()); - outs.printf(" svg:stroke-opacity=\"%s\" ", s.strokeOpacity.c_str()); - } - outs.printf("/>\n"); - outs.printf("</style:style>\n"); - } - - //## Dump our gradient table - int gradientCount = 0; - outs.printf("\n"); - outs.printf("<!-- ####### Gradients from Inkscape document ####### -->\n"); - std::vector<GradientInfo>::iterator giter; - for (giter = gradientTable.begin() ; giter != gradientTable.end() ; ++giter) - { - GradientInfo gi(*giter); - if (gi.style == "linear") - { - /* - =================================================================== - LINEAR gradient. We need something that looks like this: - <draw:gradient draw:name="Gradient_20_7" - draw:display-name="Gradient 7" - draw:style="linear" - draw:start-color="#008080" draw:end-color="#993366" - draw:start-intensity="100%" draw:end-intensity="100%" - draw:angle="150" draw:border="0%"/> - =================================================================== - */ - if (gi.stops.size() < 2) - { - g_warning("Need at least 2 tops for a linear gradient"); - continue; - } - outs.printf("<svg:linearGradient "); - outs.printf("id=\"%#s_g\" ", gi.name.c_str()); - outs.printf("draw:name=\"%#s_g\"\n", gi.name.c_str()); - outs.printf(" draw:display-name=\"imported linear %u\"\n", - gradientCount); - outs.printf(" svg:x1=\"%05.3fcm\" svg:y1=\"%05.3fcm\"\n", - gi.x1, gi.y1); - outs.printf(" svg:x2=\"%05.3fcm\" svg:y2=\"%05.3fcm\"\n", - gi.x2, gi.y2); - outs.printf(" svg:gradientUnits=\"objectBoundingBox\">\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[0].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[0].opacity * 100.0); - outs.printf(" svg:offset=\"0\"/>\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[1].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[1].opacity * 100.0); - outs.printf(" svg:offset=\"1\"/>\n"); - outs.printf("</svg:linearGradient>\n"); - } - else if (gi.style == "radial") - { - /* - =================================================================== - RADIAL gradient. We need something that looks like this: - <!-- radial gradient, light gray to white, centered, 0% border --> - <draw:gradient draw:name="radial_20_borderless" - draw:display-name="radial borderless" - draw:style="radial" - draw:cx="50%" draw:cy="50%" - draw:start-color="#999999" draw:end-color="#ffffff" - draw:border="0%"/> - =================================================================== - */ - if (gi.stops.size() < 2) - { - g_warning("Need at least 2 tops for a radial gradient"); - continue; - } - outs.printf("<svg:radialGradient "); - outs.printf("id=\"%#s_g\" ", gi.name.c_str()); - outs.printf("draw:name=\"%#s_g\"\n", gi.name.c_str()); - outs.printf(" draw:display-name=\"imported radial %d\"\n", - gradientCount); - outs.printf(" svg:cx=\"%05.3f\" svg:cy=\"%05.3f\"\n", - gi.cx, gi.cy); - outs.printf(" svg:fx=\"%05.3f\" svg:fy=\"%05.3f\"\n", - gi.fx, gi.fy); - outs.printf(" svg:r=\"%05.3f\"\n", - gi.r); - outs.printf(" svg:gradientUnits=\"objectBoundingBox\">\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[0].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[0].opacity * 100.0); - outs.printf(" svg:offset=\"0\"/>\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[1].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[1].opacity * 100.0); - outs.printf(" svg:offset=\"1\"/>\n"); - outs.printf("</svg:radialGradient>\n"); - } - else - { - g_warning("unsupported gradient style '%s'", gi.style.c_str()); - } - outs.printf("<style:style style:name=\"%#s\" style:family=\"graphic\" ", - gi.name.c_str()); - outs.printf("style:parent-style-name=\"standard\">\n"); - outs.printf(" <style:graphic-properties draw:fill=\"gradient\" "); - outs.printf("draw:fill-gradient-name=\"%#s_g\"\n", - gi.name.c_str()); - outs.printf(" draw:textarea-horizontal-align=\"center\" "); - outs.printf("draw:textarea-vertical-align=\"middle\"/>\n"); - outs.printf("</style:style>\n\n"); - - gradientCount++; - } - - outs.printf("\n"); - outs.printf("</office:automatic-styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:master-styles>\n"); - outs.printf("<draw:layer-set>\n"); - outs.printf(" <draw:layer draw:name=\"layout\"/>\n"); - outs.printf(" <draw:layer draw:name=\"background\"/>\n"); - outs.printf(" <draw:layer draw:name=\"backgroundobjects\"/>\n"); - outs.printf(" <draw:layer draw:name=\"controls\"/>\n"); - outs.printf(" <draw:layer draw:name=\"measurelines\"/>\n"); - outs.printf("</draw:layer-set>\n"); - outs.printf("\n"); - outs.printf("<style:master-page style:name=\"Default\"\n"); - outs.printf(" style:page-master-name=\"PM1\" draw:style-name=\"dp1\"/>\n"); - outs.printf("</office:master-styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("</office:document-styles>\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" E N D O F F I L E\n"); - outs.printf(" Have a nice day - ishmal\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - - //Make our entry - ZipEntry *ze = zf.newEntry("styles.xml", "ODF style file"); - ze->setUncompressedData(bouts.getBuffer()); - ze->finish(); - - return true; -} - - - /** * Writes an SVG path as an ODF <draw:path> and returns the number of points written */ @@ -1533,24 +1321,30 @@ writePath(Writer &outs, Geom::PathVector const &pathv, return nrPoints; } - - -bool OdfOutput::processStyle(Writer &outs, SPItem *item, - const Glib::ustring &id) +bool OdfOutput::processStyle(SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill, const Glib::ustring &gradientNameStroke, Glib::ustring& output) { + output.clear(); + if (!item) + { + return false; + } + SPStyle *style = item->style; - + if (!style) + { + return false; + } + StyleInfo si; - //## FILL + // FILL if (style->fill.isColor()) - { + { guint32 fillCol = style->fill.value.color.toRGBA32( 0 ); char buf[16]; int r = (fillCol >> 24) & 0xff; int g = (fillCol >> 16) & 0xff; int b = (fillCol >> 8) & 0xff; - //g_message("## %s %lx", id.c_str(), (unsigned int)fillCol); snprintf(buf, 15, "#%02x%02x%02x", r, g, b); si.fillColor = buf; si.fill = "solid"; @@ -1558,11 +1352,19 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, (SP_SCALE24_TO_FLOAT(style->fill_opacity.value)); snprintf(buf, 15, "%.3f%%", opacityPercent); si.fillOpacity = buf; + } + else if (style->fill.isPaintserver()) + { + SPGradient *gradient = SP_GRADIENT(SP_STYLE_FILL_SERVER(style)); + if (gradient) + { + si.fill = "gradient"; } + } - //## STROKE + // STROKE if (style->stroke.isColor()) - { + { guint32 strokeCol = style->stroke.value.color.toRGBA32( 0 ); char buf[16]; int r = (strokeCol >> 24) & 0xff; @@ -1577,157 +1379,170 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, (SP_SCALE24_TO_FLOAT(style->stroke_opacity.value)); snprintf(buf, 15, "%.3f%%", opacityPercent); si.strokeOpacity = buf; + } + else if (style->stroke.isPaintserver()) + { + SPGradient *gradient = SP_GRADIENT(SP_STYLE_STROKE_SERVER(style)); + if (gradient) + { + si.stroke = "gradient"; } + } //Look for existing identical style; bool styleMatch = false; std::vector<StyleInfo>::iterator iter; for (iter=styleTable.begin() ; iter!=styleTable.end() ; ++iter) - { + { if (si.equals(*iter)) - { + { //map to existing styleTable entry Glib::ustring styleName = iter->name; - //g_message("found duplicate style:%s", styleName.c_str()); styleLookupTable[id] = styleName; styleMatch = true; break; - } } + } - //## Dont need a new style + // Dont need a new style if (styleMatch) + { return false; + } - char buf[16]; - snprintf(buf, 15, "style%d", (int)styleTable.size()); - Glib::ustring styleName = buf; + Glib::ustring styleName = Glib::ustring::compose("style%1", styleTable.size()); si.name = styleName; styleTable.push_back(si); styleLookupTable[id] = styleName; - outs.printf("<style:style style:name=\"%s\"", si.name.c_str()); - outs.printf(" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); - outs.printf(" <style:graphic-properties"); - outs.printf(" draw:fill=\"%s\" ", si.fill.c_str()); - if (si.fill != "none") + output = Glib::ustring::compose ("<style:style style:name=\"%1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n", si.name); + output += "<style:graphic-properties"; + if (si.fill == "gradient") + { + output += Glib::ustring::compose (" draw:fill=\"gradient\" draw:fill-gradient-name=\"%1\"", gradientNameFill); + } + else + { + output += Glib::ustring(" draw:fill=\"") + si.fill + "\""; + if(si.fill != "none") { - outs.printf(" draw:fill-color=\"%s\" ", si.fillColor.c_str()); - outs.printf(" draw:fill-opacity=\"%s\" ", si.fillOpacity.c_str()); + output += Glib::ustring::compose(" draw:fill-color=\"%1\"", si.fillColor); } - outs.printf(" draw:stroke=\"%s\" ", si.stroke.c_str()); - if (si.stroke != "none") + } + if (si.stroke == "gradient") + { + //does not seem to be supported by Open Office.org + output += Glib::ustring::compose (" draw:stroke=\"gradient\" draw:stroke-gradient-name=\"%1\"", gradientNameStroke); + } + else + { + output += Glib::ustring(" draw:stroke=\"") + si.stroke + "\""; + if (si.stroke != "none") { - outs.printf(" svg:stroke-width=\"%s\" ", si.strokeWidth.c_str()); - outs.printf(" svg:stroke-color=\"%s\" ", si.strokeColor.c_str()); - outs.printf(" svg:stroke-opacity=\"%s\" ", si.strokeOpacity.c_str()); + output += Glib::ustring::compose (" svg:stroke-width=\"%1\" svg:stroke-color=\"%2\" ", si.strokeWidth, si.strokeColor); } - outs.printf("/>\n"); - outs.printf("</style:style>\n"); + } + output += "/>\n</style:style>\n"; return true; } - - - -bool OdfOutput::processGradient(Writer &outs, SPItem *item, - const Glib::ustring &id, Geom::Affine &/*tf*/) +bool OdfOutput::processGradient(SPItem *item, + const Glib::ustring &id, Geom::Affine &/*tf*/, + Glib::ustring& gradientName, Glib::ustring& output, bool checkFillGradient) { + output.clear(); if (!item) + { return false; + } SPStyle *style = item->style; - if (!style) + { return false; + } - if (!style->fill.isPaintserver()) - return false; - - //## Gradient. Look in writeStyle() below to see what info - // we need to read into GradientInfo. - if (!SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style))) + if ((checkFillGradient? (!style->fill.isPaintserver()) : (!style->stroke.isPaintserver()))) + { return false; + } - SPGradient *gradient = SP_GRADIENT(SP_STYLE_FILL_SERVER(style)); + //## Gradient + SPGradient *gradient = SP_GRADIENT((checkFillGradient?(SP_STYLE_FILL_SERVER(style)) :(SP_STYLE_STROKE_SERVER(style)))); + if (gradient == NULL) + { + return false; + } GradientInfo gi; - SPGradient *grvec = gradient->getVector(FALSE); - for (SPStop *stop = grvec->getFirstStop() ; + for (SPStop *stop = grvec->getFirstStop(); stop ; stop = stop->getNextStop()) - { - unsigned long rgba = sp_stop_get_rgba32(stop); + { + unsigned long rgba = stop->get_rgba32(); unsigned long rgb = (rgba >> 8) & 0xffffff; - double opacity = ((double)(rgba & 0xff)) / 256.0; + double opacity = (static_cast<double>(rgba & 0xff)) / 256.0; GradientStop gs(rgb, opacity); gi.stops.push_back(gs); - } + } + Glib::ustring gradientName2; if (SP_IS_LINEARGRADIENT(gradient)) - { + { gi.style = "linear"; SPLinearGradient *linGrad = SP_LINEARGRADIENT(gradient); - /* - Geom::Point p1(linGrad->x1.value, linGrad->y1.value); - p1 = p1 * tf; - gi.x1 = p1[Geom::X]; - gi.y1 = p1[Geom::Y]; - Geom::Point p2(linGrad->x2.value, linGrad->y2.value); - p2 = p2 * tf; - gi.x2 = p2[Geom::X]; - gi.y2 = p2[Geom::Y]; - */ gi.x1 = linGrad->x1.value; gi.y1 = linGrad->y1.value; gi.x2 = linGrad->x2.value; gi.y2 = linGrad->y2.value; - } + gradientName2 = Glib::ustring::compose("ImportedLinearGradient%1", gradientTable.size()); + } else if (SP_IS_RADIALGRADIENT(gradient)) - { + { gi.style = "radial"; SPRadialGradient *radGrad = SP_RADIALGRADIENT(gradient); - gi.cx = radGrad->cx.computed * 100.0;//ODG cx is percentages - gi.cy = radGrad->cy.computed * 100.0; - } + Geom::OptRect bbox = item->documentVisualBounds(); + gi.cx = (radGrad->cx.value-bbox->left())/bbox->width(); + gi.cy = (radGrad->cy.value-bbox->top())/bbox->height(); + gradientName2 = Glib::ustring::compose("ImportedRadialGradient%1", gradientTable.size()); + } else - { + { g_warning("not a supported gradient type"); return false; - } + } //Look for existing identical style; bool gradientMatch = false; std::vector<GradientInfo>::iterator iter; for (iter=gradientTable.begin() ; iter!=gradientTable.end() ; ++iter) - { + { if (gi.equals(*iter)) - { + { //map to existing gradientTable entry - Glib::ustring gradientName = iter->name; - //g_message("found duplicate style:%s", gradientName.c_str()); + gradientName = iter->name; gradientLookupTable[id] = gradientName; gradientMatch = true; break; - } } + } if (gradientMatch) + { return true; + } - //## No match, let us write a new entry - char buf[16]; - snprintf(buf, 15, "gradient%d", (int)gradientTable.size()); - Glib::ustring gradientName = buf; + // No match, let us write a new entry + gradientName = gradientName2; gi.name = gradientName; gradientTable.push_back(gi); gradientLookupTable[id] = gradientName; - int gradientCount = gradientTable.size(); - + // int gradientCount = gradientTable.size(); + char buf[128]; if (gi.style == "linear") - { + { /* =================================================================== LINEAR gradient. We need something that looks like this: @@ -1740,36 +1555,25 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, =================================================================== */ if (gi.stops.size() < 2) - { + { g_warning("Need at least 2 stops for a linear gradient"); - return false;; - } - outs.printf("<svg:linearGradient "); - outs.printf("id=\"%#s_g\" ", gi.name.c_str()); - outs.printf("draw:name=\"%#s_g\"\n", gi.name.c_str()); - outs.printf(" draw:display-name=\"imported linear %d\"\n", - gradientCount); - outs.printf(" svg:gradientUnits=\"objectBoundingBox\"\n"); - outs.printf(" svg:x1=\"%05.3fcm\" svg:y1=\"%05.3fcm\"\n", - gi.x1 * pxToCm, gi.y1 * pxToCm); - outs.printf(" svg:x2=\"%05.3fcm\" svg:y2=\"%05.3fcm\">\n", - gi.x2 * pxToCm, gi.y2 * pxToCm); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[0].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[0].opacity * 100.0); - outs.printf(" svg:offset=\"0\"/>\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[1].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[1].opacity * 100.0); - outs.printf(" svg:offset=\"1\"/>\n"); - outs.printf("</svg:linearGradient>\n"); + return false; } + output += Glib::ustring::compose("<draw:gradient draw:name=\"%1\"", gi.name); + output += Glib::ustring::compose(" draw:display-name=\"%1\"", gi.name); + output += " draw:style=\"linear\""; + snprintf(buf, 127, " draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\"", gi.stops[0].rgb, gi.stops[1].rgb); + output += buf; + //TODO: apply maths, to define begin of gradient, taking gradient begin and end, as well as object boundary into account + double angle = (gi.y2-gi.y1); + angle = (angle != 0.) ? (atan((gi.x2-gi.x1)/(gi.y2-gi.y1))* 180. / pi) : 90; + angle = (angle < 0)?(180+angle):angle; + angle = angle * 10; //why do we need this: precision????????????? + output += Glib::ustring::compose(" draw:start-intensity=\"%1\" draw:end-intensity=\"%2\" draw:angle=\"%3\"/>\n", + gi.stops[0].opacity * 100.0, gi.stops[1].opacity * 100.0, angle);// draw:border=\"0%%\" + } else if (gi.style == "radial") - { + { /* =================================================================== RADIAL gradient. We need something that looks like this: @@ -1783,62 +1587,31 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, =================================================================== */ if (gi.stops.size() < 2) - { + { g_warning("Need at least 2 stops for a radial gradient"); return false; - } - outs.printf("<svg:radialGradient "); - outs.printf("id=\"%#s_g\" ", gi.name.c_str()); - outs.printf("draw:name=\"%#s_g\"\n", gi.name.c_str()); - outs.printf(" draw:display-name=\"imported radial %d\"\n", - gradientCount); - outs.printf(" svg:gradientUnits=\"objectBoundingBox\"\n"); - outs.printf(" svg:cx=\"%05.3f\" svg:cy=\"%05.3f\"\n", - gi.cx, gi.cy); - outs.printf(" svg:fx=\"%05.3f\" svg:fy=\"%05.3f\"\n", - gi.fx, gi.fy); - outs.printf(" svg:r=\"%05.3f\">\n", - gi.r); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[0].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[0].opacity * 100.0); - outs.printf(" svg:offset=\"0\"/>\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[1].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[1].opacity * 100.0); - outs.printf(" svg:offset=\"1\"/>\n"); - outs.printf("</svg:radialGradient>\n"); } + output += Glib::ustring::compose("<draw:gradient draw:name=\"%1\" draw:display-name=\"%1\" ", gi.name); + snprintf(buf, 127, "draw:cx=\"%05.3f\" draw:cy=\"%05.3f\" ", gi.cx*100, gi.cy*100); + output += Glib::ustring("draw:style=\"radial\" ") + buf; + snprintf(buf, 127, "draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\" ", gi.stops[0].rgb, gi.stops[1].rgb); + output += buf; + snprintf(buf, 127, "draw:start-intensity=\"%f%%\" draw:end-intensity=\"%f%%\" ", gi.stops[0].opacity*100.0, gi.stops[1].opacity*100.0); + output += buf; + output += "/>\n";//draw:border=\"0%\" + } else - { + { g_warning("unsupported gradient style '%s'", gi.style.c_str()); return false; - } - outs.printf("<style:style style:name=\"%#s\" style:family=\"graphic\" ", - gi.name.c_str()); - outs.printf("style:parent-style-name=\"standard\">\n"); - outs.printf(" <style:graphic-properties draw:fill=\"gradient\" "); - outs.printf("draw:fill-gradient-name=\"%#s_g\"\n", - gi.name.c_str()); - outs.printf(" draw:textarea-horizontal-align=\"center\" "); - outs.printf("draw:textarea-vertical-align=\"middle\"/>\n"); - outs.printf("</style:style>\n\n"); - + } return true; } - - /** * SECOND PASS. - * This is the main SPObject tree output to ODF. preprocess() - * must be called prior to this, as elements will often reference - * data parsed and tabled in preprocess(). + * This is the main SPObject tree output to ODF. */ bool OdfOutput::writeTree(Writer &couts, Writer &souts, Inkscape::XML::Node *node) @@ -1846,22 +1619,19 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, //# Get the SPItem, if applicable SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(node); if (!reprobj) + { return true; + } if (!SP_IS_ITEM(reprobj)) - { + { return true; - } + } SPItem *item = SP_ITEM(reprobj); - Glib::ustring nodeName = node->name(); Glib::ustring id = getAttribute(node, "id"); - - //### Get SVG-to-ODF transform - Geom::Affine tf = getODFTransform(item); - - //### Get ODF bounding box params for item - Geom::OptRect bbox = getODFBoundingBox(item); + Geom::Affine tf = getODFTransform(item);//Get SVG-to-ODF transform + Geom::OptRect bbox = getODFBoundingBox(item);//Get ODF bounding box params for item if (!bbox) { return true; } @@ -1881,63 +1651,73 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, //# Do our stuff SPCurve *curve = NULL; - - if (nodeName == "svg" || nodeName == "svg:svg") - { + { //# Iterate through the children for (Inkscape::XML::Node *child = node->firstChild() ; child ; child = child->next()) - { + { if (!writeTree(couts, souts, child)) + { return false; } - return true; } + return true; + } else if (nodeName == "g" || nodeName == "svg:g") + { + if (!id.empty()) { - if (id.size() > 0) couts.printf("<draw:g id=\"%s\">\n", id.c_str()); + } else + { couts.printf("<draw:g>\n"); + } //# Iterate through the children for (Inkscape::XML::Node *child = node->firstChild() ; child ; child = child->next()) - { + { if (!writeTree(couts, souts, child)) + { return false; } - if (id.size() > 0) + } + if (!id.empty()) + { couts.printf("</draw:g> <!-- id=\"%s\" -->\n", id.c_str()); + } else + { couts.printf("</draw:g>\n"); - return true; } + return true; + } - //###################################### - //# S T Y L E - //###################################### - processStyle(souts, item, id); - - //###################################### - //# G R A D I E N T - //###################################### - processGradient(souts, item, id, tf); - - - - - //###################################### - //# I T E M D A T A - //###################################### - //g_message("##### %s #####", nodeName.c_str()); + //# GRADIENT + Glib::ustring gradientNameFill; + Glib::ustring gradientNameStroke; + Glib::ustring outputFill; + Glib::ustring outputStroke; + Glib::ustring outputStyle; + + processGradient(item, id, tf, gradientNameFill, outputFill, 1); + processGradient(item, id, tf, gradientNameStroke, outputStroke, 0); + souts.writeUString(outputFill); + souts.writeUString(outputStroke); + + //# STYLE + processStyle(item, id, gradientNameFill, gradientNameStroke, outputStyle); + souts.writeUString(outputStyle); + + //# ITEM DATA if (nodeName == "image" || nodeName == "svg:image") - { + { if (!SP_IS_IMAGE(item)) - { - g_warning("<image> is not an SPImage. Why? ;-)"); + { + g_warning("<image> is not an SPImage."); return false; - } + } SPImage *img = SP_IMAGE(item); double ix = img->x.value; @@ -1949,8 +1729,6 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, ibbox = ibbox * tf; ix = ibbox.min()[Geom::X]; iy = ibbox.min()[Geom::Y]; - //iwidth = ibbox.max()[Geom::X] - ibbox.min()[Geom::X]; - //iheight = ibbox.max()[Geom::Y] - ibbox.min()[Geom::Y]; iwidth = xscale * iwidth; iheight = yscale * iheight; @@ -1961,99 +1739,89 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, Glib::ustring href = getAttribute(node, "xlink:href"); std::map<Glib::ustring, Glib::ustring>::iterator iter = imageTable.find(href); if (iter == imageTable.end()) - { + { g_warning("image '%s' not in table", href.c_str()); return false; - } + } Glib::ustring newName = iter->second; couts.printf("<draw:frame "); - if (id.size() > 0) + if (!id.empty()) + { couts.printf("id=\"%s\" ", id.c_str()); + } couts.printf("draw:style-name=\"gr1\" draw:text-style-name=\"P1\" draw:layer=\"layout\" "); //no x or y. make them the translate transform, last one couts.printf("svg:width=\"%.3fcm\" svg:height=\"%.3fcm\" ", iwidth, iheight); - if (itemTransformString.size() > 0) - { + if (!itemTransformString.empty()) + { couts.printf("draw:transform=\"%s translate(%.3fcm, %.3fcm)\" ", itemTransformString.c_str(), ix, iy); - } + } else - { - couts.printf("draw:transform=\"translate(%.3fcm, %.3fcm)\" ", - ix, iy); - } + { + couts.printf("draw:transform=\"translate(%.3fcm, %.3fcm)\" ", ix, iy); + } - couts.printf(">\n"); + couts.writeString(">\n"); couts.printf(" <draw:image xlink:href=\"%s\" xlink:type=\"simple\"\n", newName.c_str()); - couts.printf(" xlink:show=\"embed\" xlink:actuate=\"onLoad\">\n"); - couts.printf(" <text:p/>\n"); - couts.printf(" </draw:image>\n"); - couts.printf("</draw:frame>\n"); + couts.writeString(" xlink:show=\"embed\" xlink:actuate=\"onLoad\">\n"); + couts.writeString(" <text:p/>\n"); + couts.writeString(" </draw:image>\n"); + couts.writeString("</draw:frame>\n"); return true; - } + } else if (SP_IS_SHAPE(item)) - { - //g_message("### %s is a shape", nodeName.c_str()); + { curve = SP_SHAPE(item)->getCurve(); - } + } else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) - { + { curve = te_get_layout(item)->convertToCurves(); - } + } if (curve) - { + { //### Default <path> output - - couts.printf("<draw:path "); - if (id.size()>0) + couts.writeString("<draw:path "); + if (!id.empty()) + { couts.printf("id=\"%s\" ", id.c_str()); + } std::map<Glib::ustring, Glib::ustring>::iterator siter; siter = styleLookupTable.find(id); if (siter != styleLookupTable.end()) - { + { Glib::ustring styleName = siter->second; couts.printf("draw:style-name=\"%s\" ", styleName.c_str()); - } - - std::map<Glib::ustring, Glib::ustring>::iterator giter; - giter = gradientLookupTable.find(id); - if (giter != gradientLookupTable.end()) - { - Glib::ustring gradientName = giter->second; - couts.printf("draw:fill-gradient-name=\"%s\" ", - gradientName.c_str()); - } + } couts.printf("draw:layer=\"layout\" svg:x=\"%.3fcm\" svg:y=\"%.3fcm\" ", bbox_x, bbox_y); couts.printf("svg:width=\"%.3fcm\" svg:height=\"%.3fcm\" ", bbox_width, bbox_height); - couts.printf("svg:viewBox=\"0.0 0.0 %.3f %.3f\"\n", + couts.printf("svg:viewBox=\"0.0 0.0 %.3f %.3f\"", bbox_width * 1000.0, bbox_height * 1000.0); - couts.printf(" svg:d=\""); + couts.printf(" svg:d=\""); int nrPoints = writePath(couts, curve->get_pathvector(), tf, bbox_x, bbox_y); - couts.printf("\""); + couts.writeString("\""); - couts.printf(">\n"); + couts.writeString(">\n"); couts.printf(" <!-- %d nodes -->\n", nrPoints); - couts.printf("</draw:path>\n\n"); - + couts.writeString("</draw:path>\n\n"); curve->unref(); - } + } return true; } - /** * Write the header for the content.xml file */ @@ -2062,59 +1830,56 @@ bool OdfOutput::writeStyleHeader(Writer &outs) time_t tim; time(&tim); - outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" file: styles.xml\n"); - outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> - outs.printf(" http://www.inkscape.org\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:document-styles\n"); - outs.printf(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); - outs.printf(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n"); - outs.printf(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n"); - outs.printf(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n"); - outs.printf(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n"); - outs.printf(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n"); - outs.printf(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); - outs.printf(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); - outs.printf(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); - outs.printf(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n"); - outs.printf(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); - outs.printf(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n"); - outs.printf(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n"); - outs.printf(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n"); - outs.printf(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n"); - outs.printf(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n"); - outs.printf(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n"); - outs.printf(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); - outs.printf(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n"); - outs.printf(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n"); - outs.printf(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n"); - outs.printf(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n"); - outs.printf(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"); - outs.printf(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); - outs.printf(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); - outs.printf(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); - outs.printf(" office:version=\"1.0\">\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" S T Y L E S\n"); - outs.printf(" Style entries have been pulled from the svg style and\n"); - outs.printf(" representation attributes in the SVG tree. The tree elements\n"); - outs.printf(" then refer to them by name, in the ODF manner\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("<office:styles>\n"); - outs.printf("\n"); + outs.writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" file: styles.xml\n"); + outs.printf (" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> + outs.writeString(" http://www.inkscape.org\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:document-styles\n"); + outs.writeString(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); + outs.writeString(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n"); + outs.writeString(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n"); + outs.writeString(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n"); + outs.writeString(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n"); + outs.writeString(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n"); + outs.writeString(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); + outs.writeString(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); + outs.writeString(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); + outs.writeString(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n"); + outs.writeString(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); + outs.writeString(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n"); + outs.writeString(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n"); + outs.writeString(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n"); + outs.writeString(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n"); + outs.writeString(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n"); + outs.writeString(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n"); + outs.writeString(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); + outs.writeString(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n"); + outs.writeString(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n"); + outs.writeString(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n"); + outs.writeString(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n"); + outs.writeString(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"); + outs.writeString(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); + outs.writeString(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); + outs.writeString(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); + outs.writeString(" office:version=\"1.0\">\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" S T Y L E S\n"); + outs.writeString(" Style entries have been pulled from the svg style and\n"); + outs.writeString(" representation attributes in the SVG tree. The tree elements\n"); + outs.writeString(" then refer to them by name, in the ODF manner\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:styles>\n"); + outs.writeString("\n"); return true; } @@ -2125,58 +1890,49 @@ bool OdfOutput::writeStyleHeader(Writer &outs) */ bool OdfOutput::writeStyleFooter(Writer &outs) { - outs.printf("\n"); - outs.printf("</office:styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:automatic-styles>\n"); - outs.printf("<!-- ####### 'Standard' styles ####### -->\n"); - outs.printf("<style:style style:name=\"dp1\" style:family=\"drawing-page\"/>\n"); - outs.printf("<style:style style:name=\"gr1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); - outs.printf(" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"none\"\n"); - outs.printf(" draw:textarea-horizontal-align=\"center\"\n"); - outs.printf(" draw:textarea-vertical-align=\"middle\" draw:color-mode=\"standard\"\n"); - outs.printf(" draw:luminance=\"0%%\" draw:contrast=\"0%%\" draw:gamma=\"100%%\" draw:red=\"0%%\"\n"); - outs.printf(" draw:green=\"0%%\" draw:blue=\"0%%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n"); - outs.printf(" draw:image-opacity=\"100%%\" style:mirror=\"none\"/>\n"); - outs.printf("</style:style>\n"); - outs.printf("<style:style style:name=\"P1\" style:family=\"paragraph\">\n"); - outs.printf(" <style:paragraph-properties fo:text-align=\"center\"/>\n"); - outs.printf("</style:style>\n"); - outs.printf("</office:automatic-styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:master-styles>\n"); - outs.printf("<draw:layer-set>\n"); - outs.printf(" <draw:layer draw:name=\"layout\"/>\n"); - outs.printf(" <draw:layer draw:name=\"background\"/>\n"); - outs.printf(" <draw:layer draw:name=\"backgroundobjects\"/>\n"); - outs.printf(" <draw:layer draw:name=\"controls\"/>\n"); - outs.printf(" <draw:layer draw:name=\"measurelines\"/>\n"); - outs.printf("</draw:layer-set>\n"); - outs.printf("\n"); - outs.printf("<style:master-page style:name=\"Default\"\n"); - outs.printf(" style:page-master-name=\"PM1\" draw:style-name=\"dp1\"/>\n"); - outs.printf("</office:master-styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("</office:document-styles>\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" E N D O F F I L E\n"); - outs.printf(" Have a nice day - ishmal\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); + outs.writeString("\n"); + outs.writeString("</office:styles>\n"); + outs.writeString("\n"); + outs.writeString("<office:automatic-styles>\n"); + outs.writeString("<!-- ####### 'Standard' styles ####### -->\n"); + outs.writeString("<style:style style:name=\"dp1\" style:family=\"drawing-page\"/>\n"); + outs.writeString("<style:style style:name=\"standard\" style:family=\"graphic\">\n"); + +///TODO: add default document style here + + outs.writeString("</style:style>\n"); + outs.writeString("<style:style style:name=\"gr1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); + outs.writeString(" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"none\"\n"); + outs.writeString(" draw:textarea-horizontal-align=\"center\"\n"); + outs.writeString(" draw:textarea-vertical-align=\"middle\" draw:color-mode=\"standard\"\n"); + outs.writeString(" draw:luminance=\"0%\" draw:contrast=\"0%\" draw:gamma=\"100%\" draw:red=\"0%\"\n"); + outs.writeString(" draw:green=\"0%\" draw:blue=\"0%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n"); + outs.writeString(" draw:image-opacity=\"100%\" style:mirror=\"none\"/>\n"); + outs.writeString("</style:style>\n"); + outs.writeString("<style:style style:name=\"P1\" style:family=\"paragraph\">\n"); + outs.writeString(" <style:paragraph-properties fo:text-align=\"center\"/>\n"); + outs.writeString("</style:style>\n"); + outs.writeString("</office:automatic-styles>\n"); + outs.writeString("\n"); + outs.writeString("<office:master-styles>\n"); + outs.writeString("<draw:layer-set>\n"); + outs.writeString(" <draw:layer draw:name=\"layout\"/>\n"); + outs.writeString(" <draw:layer draw:name=\"background\"/>\n"); + outs.writeString(" <draw:layer draw:name=\"backgroundobjects\"/>\n"); + outs.writeString(" <draw:layer draw:name=\"controls\"/>\n"); + outs.writeString(" <draw:layer draw:name=\"measurelines\"/>\n"); + outs.writeString("</draw:layer-set>\n"); + outs.writeString("\n"); + outs.writeString("<style:master-page style:name=\"Default\"\n"); + outs.writeString(" style:page-master-name=\"PM1\" draw:style-name=\"dp1\"/>\n"); + outs.writeString("</office:master-styles>\n"); + outs.writeString("\n"); + outs.writeString("</office:document-styles>\n"); return true; } - - /** * Write the header for the content.xml file */ @@ -2185,69 +1941,61 @@ bool OdfOutput::writeContentHeader(Writer &outs) time_t tim; time(&tim); - outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" file: content.xml\n"); - outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> - outs.printf(" http://www.inkscape.org\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:document-content\n"); - outs.printf(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); - outs.printf(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n"); - outs.printf(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n"); - outs.printf(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n"); - outs.printf(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n"); - outs.printf(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n"); - outs.printf(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); - outs.printf(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); - outs.printf(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); - outs.printf(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n"); - outs.printf(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); - outs.printf(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n"); - outs.printf(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n"); - outs.printf(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n"); - outs.printf(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n"); - outs.printf(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n"); - outs.printf(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n"); - outs.printf(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); - outs.printf(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n"); - outs.printf(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n"); - outs.printf(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n"); - outs.printf(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n"); - outs.printf(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"); - outs.printf(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); - outs.printf(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); - outs.printf(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); - outs.printf(" office:version=\"1.0\">\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:scripts/>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" D R A W I N G\n"); - outs.printf(" This section is the heart of SVG-ODF conversion. We are\n"); - outs.printf(" starting with simple conversions, and will slowly evolve\n"); - outs.printf(" into a 'smarter' translation as time progresses. Any help\n"); - outs.printf(" in improving .odg export is welcome.\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:body>\n"); - outs.printf("<office:drawing>\n"); - outs.printf("<draw:page draw:name=\"page1\" draw:style-name=\"dp1\"\n"); - outs.printf(" draw:master-page-name=\"Default\">\n"); - outs.printf("\n"); - outs.printf("\n"); - + outs.writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" file: content.xml\n"); + outs.printf (" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> + outs.writeString(" http://www.inkscape.org\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:document-content\n"); + outs.writeString(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); + outs.writeString(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n"); + outs.writeString(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n"); + outs.writeString(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n"); + outs.writeString(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n"); + outs.writeString(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n"); + outs.writeString(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); + outs.writeString(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); + outs.writeString(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); + outs.writeString(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n"); + outs.writeString(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); + outs.writeString(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n"); + outs.writeString(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n"); + outs.writeString(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n"); + outs.writeString(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n"); + outs.writeString(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n"); + outs.writeString(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n"); + outs.writeString(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); + outs.writeString(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n"); + outs.writeString(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n"); + outs.writeString(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n"); + outs.writeString(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n"); + outs.writeString(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"); + outs.writeString(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); + outs.writeString(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); + outs.writeString(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); + outs.writeString(" office:version=\"1.0\">\n"); + outs.writeString("<office:scripts/>\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" D R A W I N G\n"); + outs.writeString(" This section is the heart of SVG-ODF conversion. We are\n"); + outs.writeString(" starting with simple conversions, and will slowly evolve\n"); + outs.writeString(" into a 'smarter' translation as time progresses. Any help\n"); + outs.writeString(" in improving .odg export is welcome.\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:body>\n"); + outs.writeString("<office:drawing>\n"); + outs.writeString("<draw:page draw:name=\"page1\" draw:style-name=\"dp1\"\n"); + outs.writeString(" draw:master-page-name=\"Default\">\n"); + outs.writeString("\n"); return true; } @@ -2257,37 +2005,18 @@ bool OdfOutput::writeContentHeader(Writer &outs) */ bool OdfOutput::writeContentFooter(Writer &outs) { - outs.printf("\n"); - outs.printf("\n"); - - outs.printf("</draw:page>\n"); - outs.printf("</office:drawing>\n"); - - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!-- ######### CONVERSION FROM SVG ENDS ######## -->\n"); - outs.printf("\n"); - outs.printf("\n"); - - outs.printf("</office:body>\n"); - outs.printf("</office:document-content>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" E N D O F F I L E\n"); - outs.printf(" Have a nice day - ishmal\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - + outs.writeString("\n"); + outs.writeString("</draw:page>\n"); + outs.writeString("</office:drawing>\n"); + outs.writeString("\n"); + outs.writeString("<!-- ######### CONVERSION FROM SVG ENDS ######## -->\n"); + outs.writeString("\n"); + outs.writeString("</office:body>\n"); + outs.writeString("</office:document-content>\n"); return true; } - /** * Write the content.xml file. Writes the namesspace headers, then * calls writeTree(). @@ -2299,39 +2028,48 @@ bool OdfOutput::writeContent(ZipFile &zf, Inkscape::XML::Node *node) OutputStreamWriter couts(cbouts); if (!writeContentHeader(couts)) + { return false; + } //Style.xml stream BufferOutputStream sbouts; OutputStreamWriter souts(sbouts); if (!writeStyleHeader(souts)) + { return false; - + } //# Descend into the tree, doing all of our conversions - //# to both files as the same time + //# to both files at the same time + char *oldlocale = g_strdup (setlocale (LC_NUMERIC, NULL)); + setlocale (LC_NUMERIC, "C"); if (!writeTree(couts, souts, node)) - { + { g_warning("Failed to convert SVG tree"); + setlocale (LC_NUMERIC, oldlocale); + g_free (oldlocale); return false; - } - - + } + setlocale (LC_NUMERIC, oldlocale); + g_free (oldlocale); //# Finish content file if (!writeContentFooter(couts)) + { return false; + } ZipEntry *ze = zf.newEntry("content.xml", "ODF master content file"); ze->setUncompressedData(cbouts.getBuffer()); ze->finish(); - - //# Finish style file if (!writeStyleFooter(souts)) + { return false; + } ze = zf.newEntry("styles.xml", "ODF style file"); ze->setUncompressedData(sbouts.getBuffer()); @@ -2344,8 +2082,7 @@ bool OdfOutput::writeContent(ZipFile &zf, Inkscape::XML::Node *node) /** * Resets class to its pristine condition, ready to use again */ -void -OdfOutput::reset() +void OdfOutput::reset() { metadata.clear(); styleTable.clear(); @@ -2353,23 +2090,17 @@ OdfOutput::reset() gradientTable.clear(); gradientLookupTable.clear(); imageTable.clear(); - - } /** * Descends into the SVG tree, mapping things to ODF when appropriate */ -void -OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar const *filename) +void OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar const *filename) { reset(); - //g_message("native file:%s\n", filename); - documentUri = URI(filename); - /* fixme: It looks like we really are using documentUri as a URI, so we ought to call - * g_filename_to_uri for the URI constructor. */ + documentUri = Inkscape::URI(filename); ZipFile zf; preprocess(zf, doc->rroot); @@ -2404,8 +2135,7 @@ OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar con * calls the extension system with the memory allocated XML that * describes the data. */ -void -OdfOutput::init() +void OdfOutput::init() { Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" @@ -2424,8 +2154,7 @@ OdfOutput::init() /** * Make sure that we are in the database */ -bool -OdfOutput::check (Inkscape::Extension::Extension */*module*/) +bool OdfOutput::check (Inkscape::Extension::Extension */*module*/) { /* We don't need a Key if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV)) @@ -2435,30 +2164,6 @@ OdfOutput::check (Inkscape::Extension::Extension */*module*/) return TRUE; } - - -//######################################################################## -//# I N P U T -//######################################################################## - - - -//####################### -//# L A T E R !!! :-) -//####################### - - - - - - - - - - - - - } //namespace Internal } //namespace Extension } //namespace Inkscape |
