X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fextension%2Finternal%2Fodf.h;h=3854ddfe126a785d763254b6659a9f4ce2b0d4e2;hb=d9ca69e95d514a29403139d7de122abe26db5461;hp=4d4421b6b01fc681f1f4e36fc494215c6e722be2;hpb=82e21ba48b3bef514f856748d1ca20178b146be8;p=inkscape.git diff --git a/src/extension/internal/odf.h b/src/extension/internal/odf.h index 4d4421b6b..3854ddfe1 100644 --- a/src/extension/internal/odf.h +++ b/src/extension/internal/odf.h @@ -34,8 +34,9 @@ #include #include +#include -#include +#include #include "extension/implementation/implementation.h" @@ -44,6 +45,9 @@ #include #include +#include +#include + namespace Inkscape { @@ -52,6 +56,213 @@ namespace Extension namespace Internal { +typedef org::w3c::dom::URI URI; +typedef org::w3c::dom::io::Writer Writer; + + +class StyleInfo +{ +public: + + StyleInfo() + { + init(); + } + + StyleInfo(const StyleInfo &other) + { + assign(other); + } + + StyleInfo &operator=(const StyleInfo &other) + { + assign(other); + return *this; + } + + void assign(const StyleInfo &other) + { + name = other.name; + stroke = other.stroke; + strokeColor = other.strokeColor; + strokeWidth = other.strokeWidth; + strokeOpacity = other.strokeOpacity; + fill = other.fill; + fillColor = other.fillColor; + fillOpacity = other.fillOpacity; + } + + void init() + { + name = "none"; + stroke = "none"; + strokeColor = "none"; + strokeWidth = "none"; + strokeOpacity = "none"; + fill = "none"; + fillColor = "none"; + fillOpacity = "none"; + } + + virtual ~StyleInfo() + {} + + //used for eliminating duplicates in the styleTable + bool equals(const StyleInfo &other) + { + if ( + stroke != other.stroke || + strokeColor != other.strokeColor || + strokeWidth != other.strokeWidth || + strokeOpacity != other.strokeOpacity || + fill != other.fill || + fillColor != other.fillColor || + fillOpacity != other.fillOpacity + ) + return false; + return true; + } + + Glib::ustring name; + Glib::ustring stroke; + Glib::ustring strokeColor; + Glib::ustring strokeWidth; + Glib::ustring strokeOpacity; + Glib::ustring fill; + Glib::ustring fillColor; + Glib::ustring fillOpacity; + +}; + + + + +class GradientStop +{ +public: + GradientStop() + {} + GradientStop(unsigned long rgbArg, double opacityArg) + { rgb = rgbArg; opacity = opacityArg; } + virtual ~GradientStop() + {} + GradientStop(const GradientStop &other) + { assign(other); } + virtual GradientStop operator=(const GradientStop &other) + { assign(other); return *this; } + void assign(const GradientStop &other) + { + rgb = other.rgb; + opacity = other.opacity; + } + unsigned long rgb; + double opacity; +}; + + + +class GradientInfo +{ +public: + + GradientInfo() + { + init(); + } + + GradientInfo(const GradientInfo &other) + { + assign(other); + } + + GradientInfo &operator=(const GradientInfo &other) + { + assign(other); + return *this; + } + + void assign(const GradientInfo &other) + { + name = other.name; + style = other.style; + cx = other.cx; + cy = other.cy; + fx = other.fx; + fy = other.fy; + r = other.r; + x1 = other.x1; + y1 = other.y1; + x2 = other.x2; + y2 = other.y2; + stops = other.stops; + } + + void init() + { + name = "none"; + style = "none"; + cx = 0.0; + cy = 0.0; + fx = 0.0; + fy = 0.0; + r = 0.0; + x1 = 0.0; + y1 = 0.0; + x2 = 0.0; + y2 = 0.0; + stops.clear(); + } + + virtual ~GradientInfo() + {} + + //used for eliminating duplicates in the styleTable + bool equals(const GradientInfo &other) + { + if ( + name != other.name || + style != other.style || + cx != other.cx || + cy != other.cy || + fx != other.fx || + fy != other.fy || + r != other.r || + x1 != other.x1 || + y1 != other.y1 || + x2 != other.x2 || + y2 != other.y2 + ) + return false; + if (stops.size() != other.stops.size()) + return false; + for (unsigned int i=0 ; i stops; + +}; + + class OdfOutput : public Inkscape::Extension::Implementation::Implementation { @@ -62,21 +273,62 @@ public: void save (Inkscape::Extension::Output *mod, SPDocument *doc, - const gchar *uri); + gchar const *filename); static void init (void); private: - int styleIndex; - std::map styleTable; + URI documentUri; + + void reset(); + + //cc or dc metadata name/value pairs + std::map metadata; + + /* Style table + Uses a two-stage lookup to avoid style duplication. + Use like: + StyleInfo si = styleTable[styleLookupTable[id]]; + but check for errors, of course + */ + //element id -> style entry name + std::map styleLookupTable; + //style entry name -> style info + std::vector styleTable; + + //element id -> gradient entry name + std::map gradientLookupTable; + //gradient entry name -> gradient info + std::vector gradientTable; + + //for renaming image file names + std::map imageTable; + + void preprocess(ZipFile &zf, Inkscape::XML::Node *node); + + bool writeManifest(ZipFile &zf); + + bool writeMeta(ZipFile &zf); + + bool writeStyle(ZipFile &zf); + + bool processStyle(Writer &outs, SPItem *item, const Glib::ustring &id); + + bool processGradient(Writer &outs, SPItem *item, + const Glib::ustring &id, Geom::Matrix &tf); + + bool writeStyleHeader(Writer &outs); + + bool writeStyleFooter(Writer &outs); + + bool writeContentHeader(Writer &outs); + + bool writeContentFooter(Writer &outs); - void preprocess(SPDocument *doc); - void preprocess(Inkscape::XML::Node *node); - bool writeTree(Inkscape::XML::Node *node); + bool writeTree(Writer &couts, Writer &souts, Inkscape::XML::Node *node); - void po(char *str); - org::w3c::dom::io::StringOutputStream outs; + bool writeContent(ZipFile &zf, Inkscape::XML::Node *node); };