summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 239bab5)
raw | patch | inline | side by side (parent: 239bab5)
author | ishmal <ishmal@users.sourceforge.net> | |
Wed, 12 Apr 2006 19:47:37 +0000 (19:47 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Wed, 12 Apr 2006 19:47:37 +0000 (19:47 +0000) |
src/extension/internal/odf.cpp | patch | blob | history | |
src/extension/internal/odf.h | patch | blob | history |
index 5c07d89eeded90af3351971838d32ea3d2f6bedc..97e58600d93f3b8c096feea594aafe7382896f10 100644 (file)
#include "libnr/n-art-bpath.h"
#include "extension/system.h"
-#include "io/sys.h"
+#include "xml/repr.h"
+#include "xml/attribute-record.h"
+#include <vector>
+
+#include "dom/dom.h"
#include "dom/util/ziptool.h"
+
+//# Shorthand notation
+typedef org::w3c::dom::DOMString DOMString;
+
+
namespace Inkscape
{
namespace Extension
{
+
+
+class ImageInfo
+{
+public:
+
+ ImageInfo(const DOMString &nameArg,
+ const DOMString &newNameArg,
+ const std::vector<unsigned char> &bufArg)
+ {
+ name = nameArg;
+ newName = newNameArg;
+ buf = bufArg;
+ }
+
+ virtual ~ImageInfo()
+ {}
+
+ DOMString getName()
+ {
+ return name;
+ }
+
+ DOMString getNewName()
+ {
+ return newName;
+ }
+
+
+ std::vector<unsigned char> getBuf()
+ {
+ return buf;
+ }
+
+ DOMString name;
+ DOMString newName;
+ std::vector<unsigned char>buf;
+
+};
+
+
+class StyleInfo
+{
+public:
+
+ StyleInfo(const DOMString &nameArg, const DOMString &styleArg)
+ {
+ name = nameArg;
+ style = styleArg;
+ fill = "none";
+ stroke = "none";
+ }
+
+ virtual ~StyleInfo()
+ {}
+
+ DOMString getName()
+ {
+ return name;
+ }
+
+ DOMString getCssStyle()
+ {
+ return cssStyle;
+ }
+
+ DOMString getStroke()
+ {
+ return stroke;
+ }
+
+ DOMString getStrokeColor()
+ {
+ return strokeColor;
+ }
+
+ DOMString getStrokeWidth()
+ {
+ return strokeWidth;
+ }
+
+
+ DOMString getFill()
+ {
+ return fill;
+ }
+
+ DOMString getFillColor()
+ {
+ return fillColor;
+ }
+
+ DOMString name;
+ DOMString style;
+ DOMString cssStyle;
+ DOMString stroke;
+ DOMString strokeColor;
+ DOMString strokeWidth;
+ DOMString fill;
+ DOMString fillColor;
+
+};
+
+
//########################################################################
//# O U T P U T
//########################################################################
+void OdfOutput::po(char *str)
+{
+ if (str)
+ while (*str)
+ outs.put(*str++);
+}
+
+
+
/**
* Make sure that we are in the database
+/**
+ * This function searches the Repr tree recursively from the given node,
+ * and adds refs to all nodes with the given name, to the result vector
+ */
+void
+OdfOutput::preprocess(Inkscape::XML::Node *node)
+{
+ //Look for style values in the svg element
+ Inkscape::Util::List<Inkscape::XML::AttributeRecord const> attr =
+ node->attributeList();
+ for ( ; attr ; ++attr)
+ {
+ DOMString attrName = (const char *)attr->key;
+ DOMString attrValue = (const char *)attr->value;
+ StyleInfo si(attrName, attrValue);
+ /*
+ if (styleTable.find(styleValue) != styleTable.end())
+ {
+ g_message("duplicate style");
+ }
+ else
+ {
+ char buf[16];
+ snprintf(buf, 15, "style%d", styleIndex++);
+ std::string styleName = buf;
+ //Map from value-->name . Looks backwards, i know
+ styleTable[styleValue] = styleName;
+ g_message("mapping '%s' to '%s'",
+ styleValue.c_str(), styleName.c_str());
+ }
+ */
+ }
+
+
+
+ for (Inkscape::XML::Node *child = node->firstChild() ;
+ child ; child = child->next())
+ preprocess(child);
+}
+
+
+/**
+ * This function searches the Repr tree recursively from the given node,
+ * and adds refs to all nodes with the given name, to the result vector
+ */
+void
+OdfOutput::preprocess(SPDocument *doc)
+{
+ styleTable.clear();
+ styleIndex = 0;
+ preprocess(doc->rroot);
+
+ outs.clear();
+
+ po("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ po("<office:document-content\n");
+ po(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n");
+ po(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n");
+ po(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n");
+ po(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n");
+ po(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n");
+ po(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n");
+ po(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
+ po(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n");
+ po(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n");
+ po(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n");
+ po(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n");
+ po(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n");
+ po(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n");
+ po(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n");
+ po(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n");
+ po(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n");
+ po(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n");
+ po(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n");
+ po(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n");
+ po(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n");
+ po(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n");
+ po(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n");
+ po(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n");
+ po(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
+ po(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n");
+ po(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n");
+ po(" office:version=\"1.0\">\n");
+ po("\n");
+ po("\n");
+ po("<office:scripts/>\n");
+ po("<office:automatic-styles>\n");
+ po("<style:style style:name=\"dp1\" style:family=\"drawing-page\"/>\n");
+ po("<style:style style:name=\"grx1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n");
+ po(" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"solid\" draw:textarea-horizontal-align=\"center\" draw:textarea-vertical-align=\"middle\" draw:color-mode=\"standard\" draw:luminance=\"0%\" draw:contrast=\"0%\" draw:gamma=\"100%\" draw:red=\"0%\" draw:green=\"0%\" draw:blue=\"0%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\" draw:image-opacity=\"100%\" style:mirror=\"none\"/>\n");
+ po("</style:style>\n");
+ po("<style:style style:name=\"P1\" style:family=\"paragraph\">\n");
+ po(" <style:paragraph-properties fo:text-align=\"center\"/>\n");
+ po("</style:style>\n");
+
+ //## Dump our style table
+ /*
+ std::map<std::string, std::string>::iterator iter;
+ for (iter = styleTable.begin() ; iter != styleTable.end() ; iter++)
+ {
+ po("<style:style style:name=\"%s\"", iter->second);
+ po(" style:family=\"graphic\" style:parent-style-name=\"standard\">\n");
+ po(" <style:graphic-properties");
+ po(" draw:fill=\"" + s.getFill() + "\"");
+ if (!s.getFill().equals("none"))
+ po(" draw:fill-color=\"" + s.getFillColor() + "\"");
+ po(" draw:stroke=\"" + s.getStroke() + "\"");
+ if (!s.getStroke().equals("none"))
+ {
+ po(" svg:stroke-width=\"" + s.getStrokeWidth() + "\"");
+ po(" svg:stroke-color=\"" + s.getStrokeColor() + "\"");
+ }
+ po("/>\n");
+ po("</style:style>\n");
+ }
+ */
+ po("</office:automatic-styles>\n");
+ po("\n");
+
+}
+
+
+
/**
* This function searches the Repr tree recursively from the given node,
void
OdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *uri)
{
+ //# Preprocess the style entries. ODF does not put styles
+ //# directly on elements. Rather, it uses class IDs.
+ preprocess(doc);
ZipFile zipFile;
zipFile.writeFile(uri);
}
index 8865789cca70cf8d54afa7424a53a6e727018c37..7a2b1bd3227f4a15332d8a2eafa6cf05be40888c 100644 (file)
#ifndef EXTENSION_INTERNAL_ODG_OUT_H
#define EXTENSION_INTERNAL_ODG_OUT_H
+#include <dom/dom.h>
+#include <dom/io/stringstream.h>
+
#include <glib.h>
#include "extension/implementation/implementation.h"
+
+#include <xml/repr.h>
+
+#include <string>
+#include <map>
+
+
namespace Inkscape
{
namespace Extension
class OdfOutput : public Inkscape::Extension::Implementation::Implementation
{
- public:
+public:
+
+ bool check (Inkscape::Extension::Extension * module);
+
+ void save (Inkscape::Extension::Output *mod,
+ SPDocument *doc,
+ const gchar *uri);
+
+ static void init (void);
- bool check (Inkscape::Extension::Extension * module);
+private:
- void save (Inkscape::Extension::Output *mod,
- SPDocument *doc,
- const gchar *uri);
+ int styleIndex;
+ std::map<std::string, std::string> styleTable;
- static void init (void);
+ void preprocess(SPDocument *doc);
+ void preprocess(Inkscape::XML::Node *node);
+ void po(char *str);
+ org::w3c::dom::io::StringOutputStream outs;
};