From: ishmal Date: Wed, 12 Apr 2006 19:47:37 +0000 (+0000) Subject: WIP commit X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f0b5a1a1afac9a2f146085098b188f8bcb959d4d;p=inkscape.git WIP commit --- diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 5c07d89ee..97e58600d 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -43,10 +43,19 @@ #include "libnr/n-art-bpath.h" #include "extension/system.h" -#include "io/sys.h" +#include "xml/repr.h" +#include "xml/attribute-record.h" +#include + +#include "dom/dom.h" #include "dom/util/ziptool.h" + +//# Shorthand notation +typedef org::w3c::dom::DOMString DOMString; + + namespace Inkscape { namespace Extension @@ -55,10 +64,123 @@ namespace Internal { + + +class ImageInfo +{ +public: + + ImageInfo(const DOMString &nameArg, + const DOMString &newNameArg, + const std::vector &bufArg) + { + name = nameArg; + newName = newNameArg; + buf = bufArg; + } + + virtual ~ImageInfo() + {} + + DOMString getName() + { + return name; + } + + DOMString getNewName() + { + return newName; + } + + + std::vector getBuf() + { + return buf; + } + + DOMString name; + DOMString newName; + std::vectorbuf; + +}; + + +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 @@ -76,6 +198,129 @@ OdfOutput::check (Inkscape::Extension::Extension *module) +/** + * 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 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("\n"); + po("\n"); + po("\n"); + po("\n"); + po("\n"); + po("\n"); + po("\n"); + po("\n"); + po(" \n"); + po("\n"); + po("\n"); + po(" \n"); + po("\n"); + + //## Dump our style table + /* + std::map::iterator iter; + for (iter = styleTable.begin() ; iter != styleTable.end() ; iter++) + { + po("second); + po(" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); + po(" \n"); + po("\n"); + } + */ + po("\n"); + po("\n"); + +} + + + /** * This function searches the Repr tree recursively from the given node, @@ -103,6 +348,9 @@ findElementsByTagName(std::vector &results, 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); } diff --git a/src/extension/internal/odf.h b/src/extension/internal/odf.h index 8865789cc..7a2b1bd32 100644 --- a/src/extension/internal/odf.h +++ b/src/extension/internal/odf.h @@ -32,9 +32,19 @@ #ifndef EXTENSION_INTERNAL_ODG_OUT_H #define EXTENSION_INTERNAL_ODG_OUT_H +#include +#include + #include #include "extension/implementation/implementation.h" + +#include + +#include +#include + + namespace Inkscape { namespace Extension @@ -46,16 +56,26 @@ namespace Internal 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 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; };