/** * OpenDocument input and output * * 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 * improve greatly with time. * * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html * * Authors: * Bob Jamison * * Copyright (C) 2006 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifdef HAVE_CONFIG_H # include #endif #include "odf.h" #include "clear-n_.h" #include "inkscape.h" #include "sp-path.h" #include #include "display/curve.h" #include "libnr/n-art-bpath.h" #include "extension/system.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 { 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 */ bool OdfOutput::check (Inkscape::Extension::Extension *module) { /* We don't need a Key if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV)) return FALSE; */ return TRUE; } /** * 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, * and adds refs to all nodes with the given name, to the result vector */ static void findElementsByTagName(std::vector &results, Inkscape::XML::Node *node, char const *name) { if ( !name || strcmp(node->name(), name) == 0 ) { results.push_back(node); } for (Inkscape::XML::Node *child = node->firstChild() ; child ; child = child->next()) findElementsByTagName( results, child, name ); } /** * Descends into the SVG tree, mapping things to ODF when appropriate */ 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); } /** * This is the definition of PovRay output. This function just * calls the extension system with the memory allocated XML that * describes the data. */ void OdfOutput::init() { Inkscape::Extension::build_from_mem( "\n" "" N_("OpenDocument Drawing Output") "\n" "org.inkscape.output.odf\n" "\n" ".odg\n" "text/x-povray-script\n" "" N_("OpenDocument drawing (*.odg)(placeholder)") "\n" "" N_("OpenDocument drawing file") "\n" "\n" "", new OdfOutput()); } //######################################################################## //# I N P U T //######################################################################## } //namespace Internal } //namespace Extension } //namespace Inkscape /* Local Variables: mode:c++ c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) indent-tabs-mode:nil fill-column:99 End: */ // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :