diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2013-03-08 20:08:41 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2013-03-08 20:08:41 +0000 |
| commit | 0239a77934187cb9f8c88f0d70748189ec6264c4 (patch) | |
| tree | ee79915040662c450ab0de5f30c570ac3678cb64 /src | |
| parent | Use font-weight names rather than numerical values. Fixes bug when scrolling ... (diff) | |
| download | inkscape-0239a77934187cb9f8c88f0d70748189ec6264c4.tar.gz inkscape-0239a77934187cb9f8c88f0d70748189ec6264c4.zip | |
Preparation to merge /dom/io and /io code (bug #1120585 )
(bzr r12184)
Diffstat (limited to 'src')
| -rw-r--r-- | src/dom/io/domstream.cpp | 220 | ||||
| -rw-r--r-- | src/dom/io/domstream.h | 70 | ||||
| -rw-r--r-- | src/extension/internal/odf.cpp | 112 | ||||
| -rw-r--r-- | src/io/inkscapestream.cpp | 2 |
4 files changed, 227 insertions, 177 deletions
diff --git a/src/dom/io/domstream.cpp b/src/dom/io/domstream.cpp index b9ff7e9d2..7118025d6 100644 --- a/src/dom/io/domstream.cpp +++ b/src/dom/io/domstream.cpp @@ -66,7 +66,7 @@ void pipeStream(InputStream &source, OutputStream &dest) } dest.flush(); } - +/* //######################################################################### @@ -74,11 +74,11 @@ void pipeStream(InputStream &source, OutputStream &dest) //######################################################################### static char const *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; - -static int dprintInt(Writer &outs, - long arg, int base, - int flag, int width, int /*precision*/) -{ +*/ +// static int dprintInt(Writer &outs, + // long arg, int base, + // int flag, int width, int /*precision*/) +/*{ DOMString buf; @@ -209,7 +209,7 @@ static int dprintDouble(Writer &outs, double val, } return 1; } - +*/ /** * Output a string. We veer from the standard a tiny bit. @@ -217,9 +217,9 @@ static int dprintDouble(Writer &outs, double val, * it as an indicator that the user wants to XML-escape any * XML entities. */ -static int dprintString(Writer &outs, const DOMString &str, - int flags, int /*width*/, int /*precision*/) -{ +// static int dprintString(Writer &outs, const DOMString &str, + // int flags, int /*width*/, int /*precision*/) +/*{ int len = str.size(); if (flags == '#') { @@ -418,7 +418,7 @@ static int dprintf(Writer &outs, const DOMString &fmt, va_list ap) return 1; } - +*/ //######################################################################### //# B A S I C I N P U T S T R E A M @@ -514,7 +514,7 @@ int BasicOutputStream::put(gunichar ch) if (closed) return -1; destination.put(ch); - return 1; + return 1; } @@ -811,38 +811,37 @@ gunichar StdReader::get() //######################################################################### //# B A S I C W R I T E R //######################################################################### - /** * - */ + */ BasicWriter::BasicWriter(const Writer &destinationWriter) { - destination = (Writer *)&destinationWriter; + destination = (Writer*) &destinationWriter; } /** * Closes this writer and releases any system resources * associated with this writer. - */ + */ void BasicWriter::close() { if (destination) destination->close(); } - + /** * Flushes this output stream and forces any buffered output * bytes to be written out. - */ + */ void BasicWriter::flush() { if (destination) destination->flush(); } - + /** * Writes the specified byte to this output writer. - */ + */ int BasicWriter::put(gunichar ch) { if (destination && destination->put(ch)>=0) @@ -852,50 +851,66 @@ int BasicWriter::put(gunichar ch) /** * Provide printf()-like formatting - */ -/* + */ Writer &BasicWriter::printf(char const *fmt, ...) { va_list args; va_start(args, fmt); - //replace this wish vsnprintf() - vsnprintf(formatBuf, 2047, fmt, args); + gchar *buf = g_strdup_vprintf(fmt, args); va_end(args); - writeString(formatBuf); - - return *this; -} -*/ -Writer &BasicWriter::printf(const DOMString &fmt, ...) -{ - va_list args; - va_start(args, fmt); - dprintf(*this, fmt, args); + if (buf) { + writeString(buf); + g_free(buf); + } return *this; } - - /** * Writes the specified character to this output writer. - */ + */ Writer &BasicWriter::writeChar(char ch) { - XMLCh uch = ch; + gunichar uch = ch; put(uch); return *this; } /** - * Writes the specified standard string to this output writer. - */ -Writer &BasicWriter::writeString(const DOMString &str) + * Writes the specified unicode string to this output writer. + */ +Writer &BasicWriter::writeUString(Glib::ustring &str) { for (int i=0; i< (int)str.size(); i++) put(str[i]); return *this; } +/** + * Writes the specified standard string to this output writer. + */ +Writer &BasicWriter::writeStdString(std::string &str) +{ + Glib::ustring tmp(str); + writeUString(tmp); + return *this; +} + +/** + * Writes the specified character string to this output writer. + */ +Writer &BasicWriter::writeString(const char *str) +{ + Glib::ustring tmp; + if (str) + tmp = str; + else + tmp = "null"; + writeUString(tmp); + return *this; +} + + + /** * @@ -915,10 +930,12 @@ Writer &BasicWriter::writeBool (bool val ) */ Writer &BasicWriter::writeShort (short val ) { - char buf[32]; - snprintf(buf, 31, "%d", val); - writeString(buf); - return *this; + gchar *buf = g_strdup_printf("%d", val); + if (buf) { + writeString(buf); + g_free(buf); + } + return *this; } @@ -928,9 +945,11 @@ Writer &BasicWriter::writeShort (short val ) */ Writer &BasicWriter::writeUnsignedShort (unsigned short val ) { - char buf[32]; - snprintf(buf, 31, "%u", val); - writeString(buf); + gchar *buf = g_strdup_printf("%u", val); + if (buf) { + writeString(buf); + g_free(buf); + } return *this; } @@ -939,9 +958,11 @@ Writer &BasicWriter::writeUnsignedShort (unsigned short val ) */ Writer &BasicWriter::writeInt (int val) { - char buf[32]; - snprintf(buf, 31, "%d", val); - writeString(buf); + gchar *buf = g_strdup_printf("%d", val); + if (buf) { + writeString(buf); + g_free(buf); + } return *this; } @@ -950,9 +971,11 @@ Writer &BasicWriter::writeInt (int val) */ Writer &BasicWriter::writeUnsignedInt (unsigned int val) { - char buf[32]; - snprintf(buf, 31, "%u", val); - writeString(buf); + gchar *buf = g_strdup_printf("%u", val); + if (buf) { + writeString(buf); + g_free(buf); + } return *this; } @@ -961,9 +984,11 @@ Writer &BasicWriter::writeUnsignedInt (unsigned int val) */ Writer &BasicWriter::writeLong (long val) { - char buf[32]; - snprintf(buf, 31, "%ld", val); - writeString(buf); + gchar *buf = g_strdup_printf("%ld", val); + if (buf) { + writeString(buf); + g_free(buf); + } return *this; } @@ -972,9 +997,11 @@ Writer &BasicWriter::writeLong (long val) */ Writer &BasicWriter::writeUnsignedLong(unsigned long val) { - char buf[32]; - snprintf(buf, 31, "%lu", val); - writeString(buf); + gchar *buf = g_strdup_printf("%lu", val); + if (buf) { + writeString(buf); + g_free(buf); + } return *this; } @@ -983,9 +1010,16 @@ Writer &BasicWriter::writeUnsignedLong(unsigned long val) */ Writer &BasicWriter::writeFloat(float val) { - char buf[32]; - snprintf(buf, 31, "%8.3f", val); - writeString(buf); +#if 1 + gchar *buf = g_strdup_printf("%8.3f", val); + if (buf) { + writeString(buf); + g_free(buf); + } +#else + std::string tmp = ftos(val, 'g', 8, 3, 0); + writeStdString(tmp); +#endif return *this; } @@ -994,9 +1028,16 @@ Writer &BasicWriter::writeFloat(float val) */ Writer &BasicWriter::writeDouble(double val) { - char buf[32]; - snprintf(buf, 31, "%8.3f", val); - writeString(buf); +#if 1 + gchar *buf = g_strdup_printf("%8.3f", val); + if (buf) { + writeString(buf); + g_free(buf); + } +#else + std::string tmp = ftos(val, 'g', 8, 3, 0); + writeStdString(tmp); +#endif return *this; } @@ -1013,7 +1054,7 @@ OutputStreamWriter::OutputStreamWriter(OutputStream &outputStreamDest) { } - + /** * Close the underlying OutputStream @@ -1023,7 +1064,7 @@ void OutputStreamWriter::close() flush(); outputStream.close(); } - + /** * Flush the underlying OutputStream */ @@ -1031,18 +1072,16 @@ void OutputStreamWriter::flush() { outputStream.flush(); } - + /** * Overloaded to redirect the output chars from the next Writer * in the chain to an OutputStream instead. */ int OutputStreamWriter::put(gunichar ch) { - //Do we need conversions here? - int intCh = (int) ch; - if (outputStream.put(intCh) < 0) - return -1; - return 1; + if (outputStream.put(ch)>=0) + return 1; + return -1; } //######################################################################### @@ -1051,24 +1090,21 @@ int OutputStreamWriter::put(gunichar ch) /** - * + * */ StdWriter::StdWriter() { outputStream = new StdOutputStream(); } - - + /** - * + * */ StdWriter::~StdWriter() { delete outputStream; } - - /** * Close the underlying OutputStream */ @@ -1077,7 +1113,7 @@ void StdWriter::close() flush(); outputStream->close(); } - + /** * Flush the underlying OutputStream */ @@ -1085,23 +1121,20 @@ void StdWriter::flush() { outputStream->flush(); } - + /** * Overloaded to redirect the output chars from the next Writer * in the chain to an OutputStream instead. */ int StdWriter::put(gunichar ch) { - //Do we need conversions here? - if (outputStream->put(ch) < 0) - return -1; - return 1; + if (outputStream && (outputStream->put(ch)>=0)) + return 1; + return -1; } - - //############################################### //# O P E R A T O R S //############################################### @@ -1144,11 +1177,16 @@ const Reader& operator>> (Reader &reader, double &val) - Writer& operator<< (Writer &writer, char val) { return writer.writeChar(val); } -Writer& operator<< (Writer &writer, const DOMString &val) +Writer& operator<< (Writer &writer, Glib::ustring &val) + { return writer.writeUString(val); } + +Writer& operator<< (Writer &writer, std::string &val) + { return writer.writeStdString(val); } + +Writer& operator<< (Writer &writer, char const *val) { return writer.writeString(val); } Writer& operator<< (Writer &writer, bool val) @@ -1178,8 +1216,6 @@ Writer& operator<< (Writer &writer, float val) Writer& operator<< (Writer &writer, double val) { return writer.writeDouble(val); } - - } //namespace io } //namespace dom } //namespace w3c diff --git a/src/dom/io/domstream.h b/src/dom/io/domstream.h index a021676fa..edd180b83 100644 --- a/src/dom/io/domstream.h +++ b/src/dom/io/domstream.h @@ -490,17 +490,21 @@ public: virtual ~Writer() {} virtual void close() = 0; - + virtual void flush() = 0; - + virtual int put(gunichar ch) = 0; - + /* Formatted output */ - virtual Writer& printf(const DOMString &fmt, ...) = 0; + virtual Writer& printf(char const *fmt, ...) G_GNUC_PRINTF(2,3) = 0; virtual Writer& writeChar(char val) = 0; - virtual Writer& writeString(const DOMString &val) = 0; + virtual Writer& writeUString(Glib::ustring &val) = 0; + + virtual Writer& writeStdString(std::string &val) = 0; + + virtual Writer& writeString(const char *str) = 0; virtual Writer& writeBool (bool val ) = 0; @@ -520,7 +524,7 @@ public: virtual Writer& writeDouble (double val ) = 0; - + }; // interface Writer @@ -540,19 +544,23 @@ public: /*Overload these 3 for your implementation*/ virtual void close(); - + virtual void flush(); - + virtual int put(gunichar ch); - - - + + + /* Formatted output */ - virtual Writer &printf(const DOMString &fmt, ...); + virtual Writer &printf(char const *fmt, ...) G_GNUC_PRINTF(2,3); virtual Writer& writeChar(char val); - virtual Writer& writeString(const DOMString &val); + virtual Writer& writeUString(Glib::ustring &val); + + virtual Writer& writeStdString(std::string &val); + + virtual Writer& writeString(const char *str); virtual Writer& writeBool (bool val ); @@ -572,33 +580,26 @@ public: virtual Writer& writeDouble (double val ); - + protected: Writer *destination; BasicWriter() - { - destination = NULL; - for(int k=0;k<2048;++k) - { - formatBuf[k]=0; - } - } - - //Used for printf() or other things that might - //require formatting before sending down the stream - char formatBuf[2048]; - + { destination = NULL; } + private: }; // class BasicWriter - Writer& operator<< (Writer &writer, char val); -Writer& operator<< (Writer &writer, const DOMString &val); +Writer& operator<< (Writer &writer, Glib::ustring &val); + +Writer& operator<< (Writer &writer, std::string &val); + +Writer& operator<< (Writer &writer, char const *val); Writer& operator<< (Writer &writer, bool val); @@ -619,8 +620,6 @@ Writer& operator<< (Writer &writer, float val); Writer& operator<< (Writer &writer, double val); - - /** * Class for placing a Writer on an open OutputStream * @@ -630,12 +629,10 @@ class OutputStreamWriter : public BasicWriter public: OutputStreamWriter(OutputStream &outputStreamDest); - + /*Overload these 3 for your implementation*/ virtual void close(); - virtual void flush(); - virtual int put(gunichar ch); @@ -656,14 +653,8 @@ public: StdWriter(); virtual ~StdWriter(); - - virtual void close(); - - virtual void flush(); - - virtual int put(gunichar ch); @@ -680,7 +671,6 @@ private: void pipeStream(InputStream &source, OutputStream &dest); - } //namespace io } //namespace dom } //namespace w3c diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index bd74ba47c..7634c7aa1 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -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 @@ -1180,7 +1182,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"); @@ -1241,7 +1243,7 @@ bool OdfOutput::writeMeta(ZipFile &zf) outs.printf("office:version=\"1.0\">\n"); outs.printf("<office:meta>\n"); Glib::ustring tmp = Glib::ustring(" <meta:generator>Inkscape.org - ") + Inkscape::version_string + "</meta:generator>\n"; - outs.writeString(tmp); + outs.writeUString(tmp); 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()); @@ -1889,35 +1891,47 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, 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 @@ -1930,19 +1944,17 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, processGradient(souts, item, id, tf); - - //###################################### //# I T E M D A T A //###################################### //g_message("##### %s #####", nodeName.c_str()); if (nodeName == "image" || nodeName == "svg:image") - { + { if (!SP_IS_IMAGE(item)) - { + { g_warning("<image> is not an SPImage. Why? ;-)"); return false; - } + } SPImage *img = SP_IMAGE(item); double ix = img->x.value; @@ -1954,8 +1966,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; @@ -1966,29 +1976,30 @@ 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.printf(" <draw:image xlink:href=\"%s\" xlink:type=\"simple\"\n", @@ -1998,41 +2009,41 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, couts.printf(" </draw:image>\n"); couts.printf("</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) + 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); @@ -2052,7 +2063,7 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, curve->unref(); - } + } return true; } @@ -2304,29 +2315,40 @@ 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()); @@ -2336,7 +2358,9 @@ bool OdfOutput::writeContent(ZipFile &zf, Inkscape::XML::Node *node) //# Finish style file if (!writeStyleFooter(souts)) + { return false; + } ze = zf.newEntry("styles.xml", "ODF style file"); ze->setUncompressedData(sbouts.getBuffer()); diff --git a/src/io/inkscapestream.cpp b/src/io/inkscapestream.cpp index 4c7fa4d49..dcfc662ca 100644 --- a/src/io/inkscapestream.cpp +++ b/src/io/inkscapestream.cpp @@ -130,7 +130,7 @@ int BasicOutputStream::put(gunichar ch) if (closed) return -1; destination.put(ch); - return 1; + return 1; } |
