diff options
| author | su_v <suv-sf@users.sourceforge.net> | 2013-03-11 17:40:03 +0000 |
|---|---|---|
| committer | ~suv <suv-sf@users.sourceforge.net> | 2013-03-11 17:40:03 +0000 |
| commit | 3b80081f5a6a0b3ad870d5e90037189e56c9468f (patch) | |
| tree | 3de07a42745f10892ae2eca52c1cf3fb49421301 /src/extension/internal/odf.cpp | |
| parent | merge from trunk (r12182) (diff) | |
| parent | fix build warnings / cppcheck ( Bug #1120585 ) (diff) | |
| download | inkscape-3b80081f5a6a0b3ad870d5e90037189e56c9468f.tar.gz inkscape-3b80081f5a6a0b3ad870d5e90037189e56c9468f.zip | |
merge from trunk (r12191)
(bzr r11668.1.55)
Diffstat (limited to 'src/extension/internal/odf.cpp')
| -rw-r--r-- | src/extension/internal/odf.cpp | 188 |
1 files changed, 110 insertions, 78 deletions
diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index bd74ba47c..47671a8d2 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -4,7 +4,7 @@ * 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 + * due to the differences in the models of SVG and ODF, they will hopefully * improve greatly with time. People should consider this to be a framework * that can be continously upgraded for ever improving fidelity. Potential * developers should especially look in preprocess() and writeTree() to see how @@ -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 @@ -293,11 +295,13 @@ public: @return Structure to access U, S and V. */ - SingularValueDecomposition (const SVDMatrix &mat) + SingularValueDecomposition (const SVDMatrix &mat) : + A (mat), + U (), + s (NULL), + s_size (0), + V () { - A = mat; - s = NULL; - s_size = 0; calculate(); } @@ -1078,14 +1082,16 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) //Now consider items. SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(node); if (!reprobj) + { return; + } if (!SP_IS_ITEM(reprobj)) - { + { return; - } - SPItem *item = SP_ITEM(reprobj); + } + //SPItem *item = SP_ITEM(reprobj); //### Get SVG-to-ODF transform - Geom::Affine tf = getODFTransform(item); + //Geom::Affine tf = getODFTransform(item); if (nodeName == "image" || nodeName == "svg:image") { @@ -1180,7 +1186,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"); @@ -1208,14 +1214,19 @@ bool OdfOutput::writeMeta(ZipFile &zf) time(&tim); std::map<Glib::ustring, Glib::ustring>::iterator iter; - Glib::ustring creator = "unknown"; + Glib::ustring InkscapeVersion = Glib::ustring("Inkscape.org - ") + Inkscape::version_string; + Glib::ustring creator = InkscapeVersion; iter = metadata.find("dc:creator"); if (iter != metadata.end()) + { creator = iter->second; + } Glib::ustring date = ""; iter = metadata.find("dc:date"); if (iter != metadata.end()) + { date = iter->second; + } outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); outs.printf("\n"); @@ -1240,21 +1251,20 @@ bool OdfOutput::writeMeta(ZipFile &zf) outs.printf("xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); 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.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()); + Glib::ustring tmp = Glib::ustring(" <meta:generator>") + InkscapeVersion + "</meta:generator>\n"; + 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()); for (iter = metadata.begin() ; iter != metadata.end() ; ++iter) - { + { Glib::ustring name = iter->first; Glib::ustring value = iter->second; - if (name.size() > 0 && value.size()>0) - { - outs.printf(" <%#s>%#s</%#s>\n", - name.c_str(), value.c_str(), name.c_str()); - } + if (!name.empty() && !value.empty()) + { + tmp = Glib::ustring::compose(" <%1>%2</%3>\n", name, value, name); + outs.writeUString(tmp); } + } outs.printf(" <meta:editing-cycles>2</meta:editing-cycles>\n"); outs.printf(" <meta:editing-duration>PT56S</meta:editing-duration>\n"); outs.printf(" <meta:user-defined meta:name=\"Info 1\"/>\n"); @@ -1331,7 +1341,7 @@ bool OdfOutput::writeStyle(ZipFile &zf) } //## Dump our gradient table - int gradientCount = 0; + unsigned int gradientCount = 0; outs.printf("\n"); outs.printf("<!-- ####### Gradients from Inkscape document ####### -->\n"); std::vector<GradientInfo>::iterator giter; @@ -1357,8 +1367,8 @@ bool OdfOutput::writeStyle(ZipFile &zf) continue; } outs.printf("<svg:linearGradient "); - outs.printf("id=\"%#s_g\" ", gi.name.c_str()); - outs.printf("draw:name=\"%#s_g\"\n", gi.name.c_str()); + outs.printf("id=\"%s\" ", gi.name.c_str()); + outs.printf("draw:name=\"%s\"\n", gi.name.c_str()); outs.printf(" draw:display-name=\"imported linear %u\"\n", gradientCount); outs.printf(" svg:x1=\"%05.3fcm\" svg:y1=\"%05.3fcm\"\n", @@ -1400,9 +1410,9 @@ bool OdfOutput::writeStyle(ZipFile &zf) continue; } outs.printf("<svg:radialGradient "); - outs.printf("id=\"%#s_g\" ", gi.name.c_str()); - outs.printf("draw:name=\"%#s_g\"\n", gi.name.c_str()); - outs.printf(" draw:display-name=\"imported radial %d\"\n", + outs.printf("id=\"%s\" ", gi.name.c_str()); + outs.printf("draw:name=\"%s\"\n", gi.name.c_str()); + outs.printf(" draw:display-name=\"imported radial %u\"\n", gradientCount); outs.printf(" svg:cx=\"%05.3f\" svg:cy=\"%05.3f\"\n", gi.cx, gi.cy); @@ -1429,11 +1439,11 @@ bool OdfOutput::writeStyle(ZipFile &zf) { g_warning("unsupported gradient style '%s'", gi.style.c_str()); } - outs.printf("<style:style style:name=\"%#s\" style:family=\"graphic\" ", + outs.printf("<style:style style:name=\"%s\" style:family=\"graphic\" ", gi.name.c_str()); outs.printf("style:parent-style-name=\"standard\">\n"); outs.printf(" <style:graphic-properties draw:fill=\"gradient\" "); - outs.printf("draw:fill-gradient-name=\"%#s_g\"\n", + outs.printf("draw:fill-gradient-name=\"%s\"\n", gi.name.c_str()); outs.printf(" draw:textarea-horizontal-align=\"center\" "); outs.printf("draw:textarea-vertical-align=\"middle\"/>\n"); @@ -1750,8 +1760,8 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, return false;; } outs.printf("<svg:linearGradient "); - outs.printf("id=\"%#s_g\" ", gi.name.c_str()); - outs.printf("draw:name=\"%#s_g\"\n", gi.name.c_str()); + outs.printf("id=\"%s\" ", gi.name.c_str()); + outs.printf("draw:name=\"%s\"\n", gi.name.c_str()); outs.printf(" draw:display-name=\"imported linear %d\"\n", gradientCount); outs.printf(" svg:gradientUnits=\"objectBoundingBox\"\n"); @@ -1793,8 +1803,8 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, return false; } outs.printf("<svg:radialGradient "); - outs.printf("id=\"%#s_g\" ", gi.name.c_str()); - outs.printf("draw:name=\"%#s_g\"\n", gi.name.c_str()); + outs.printf("id=\"%s\" ", gi.name.c_str()); + outs.printf("draw:name=\"%s\"\n", gi.name.c_str()); outs.printf(" draw:display-name=\"imported radial %d\"\n", gradientCount); outs.printf(" svg:gradientUnits=\"objectBoundingBox\"\n"); @@ -1823,11 +1833,11 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, g_warning("unsupported gradient style '%s'", gi.style.c_str()); return false; } - outs.printf("<style:style style:name=\"%#s\" style:family=\"graphic\" ", + outs.printf("<style:style style:name=\"%s\" style:family=\"graphic\" ", gi.name.c_str()); outs.printf("style:parent-style-name=\"standard\">\n"); outs.printf(" <style:graphic-properties draw:fill=\"gradient\" "); - outs.printf("draw:fill-gradient-name=\"%#s_g\"\n", + outs.printf("draw:fill-gradient-name=\"%s\"\n", gi.name.c_str()); outs.printf(" draw:textarea-horizontal-align=\"center\" "); outs.printf("draw:textarea-vertical-align=\"middle\"/>\n"); @@ -1889,35 +1899,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 +1952,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 +1974,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 +1984,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 +2017,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 +2071,7 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, curve->unref(); - } + } return true; } @@ -2304,29 +2323,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 +2366,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()); |
