diff options
| author | su_v <suv-sf@users.sourceforge.net> | 2013-04-08 15:06:08 +0000 |
|---|---|---|
| committer | ~suv <suv-sf@users.sourceforge.net> | 2013-04-08 15:06:08 +0000 |
| commit | f332fa6dbb58ab6b8e17f9b720f334c5e2722812 (patch) | |
| tree | 2ead4c65ceb8f91aeb84628f9ca4849547d281c9 /src | |
| parent | merge from trunk (r12258) (diff) | |
| parent | Implement read/write of image-rendering property. To be used to control scaling. (diff) | |
| download | inkscape-f332fa6dbb58ab6b8e17f9b720f334c5e2722812.tar.gz inkscape-f332fa6dbb58ab6b8e17f9b720f334c5e2722812.zip | |
merge from trunk (r12272)
(bzr r11668.1.66)
Diffstat (limited to 'src')
| -rw-r--r-- | src/connector-context.cpp | 2 | ||||
| -rw-r--r-- | src/display/drawing-image.cpp | 7 | ||||
| -rw-r--r-- | src/extension/implementation/script.cpp | 81 | ||||
| -rw-r--r-- | src/extension/internal/odf.cpp | 1035 | ||||
| -rw-r--r-- | src/extension/internal/odf.h | 6 | ||||
| -rw-r--r-- | src/extension/internal/pdf-input-cairo.cpp | 6 | ||||
| -rw-r--r-- | src/extension/param/radiobutton.cpp | 2 | ||||
| -rw-r--r-- | src/helper/geom.cpp | 12 | ||||
| -rw-r--r-- | src/inkscape.cpp | 16 | ||||
| -rw-r--r-- | src/io/sys.cpp | 6 | ||||
| -rw-r--r-- | src/main.cpp | 15 | ||||
| -rw-r--r-- | src/sp-image.cpp | 19 | ||||
| -rw-r--r-- | src/style.cpp | 98 | ||||
| -rw-r--r-- | src/style.h | 36 | ||||
| -rw-r--r-- | src/ui/dialog/filedialogimpl-gtkmm.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/font-substitution.cpp | 1 | ||||
| -rw-r--r-- | src/ui/dialog/text-edit.cpp | 50 | ||||
| -rw-r--r-- | src/ui/dialog/text-edit.h | 10 | ||||
| -rw-r--r-- | src/ui/widget/imageicon.cpp | 2 | ||||
| -rw-r--r-- | src/xml/repr.h | 8 |
20 files changed, 654 insertions, 760 deletions
diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 9631eecb1..9468894a0 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -5,7 +5,7 @@ * Michael Wybrow <mjwybrow@users.sourceforge.net> * Abhishek Sharma * Jon A. Cruz <jon@joncruz.org> - * Martin Owens <doctormo@ubuntu.com> + * Martin Owens <doctormo@gmail.com> * * Copyright (C) 2005-2008 Michael Wybrow * Copyright (C) 2009 Monash University diff --git a/src/display/drawing-image.cpp b/src/display/drawing-image.cpp index 3f1a86ee7..753249e60 100644 --- a/src/display/drawing-image.cpp +++ b/src/display/drawing-image.cpp @@ -121,6 +121,13 @@ unsigned DrawingImage::_renderItem(DrawingContext &ct, Geom::IntRect const &/*ar if (!outline) { if (!_pixbuf) return RENDER_OK; + // if (_style) { + // _style->image_rendering.computed + // See: http://www.w3.org/TR/SVG/painting.html#ImageRenderingProperty + // http://www.w3.org/TR/css4-images/#the-image-rendering + // style.h/style.cpp + // } + Inkscape::DrawingContext::Save save(ct); ct.transform(_ctm); ct.newPath(); diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 3ac1e06ab..69ce982d0 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -669,8 +669,13 @@ void Script::effect(Inkscape::Extension::Effect *module, printf("TOO BAD TO LIVE!!!"); exit(1); } + if (doc == NULL) + { + g_warning("Script::effect: View not defined"); + return; + } - SPDesktop *desktop = (SPDesktop *)doc; + SPDesktop *desktop = reinterpret_cast<SPDesktop *>(doc); sp_namedview_document_from_window(desktop); std::list<std::string> params; @@ -696,16 +701,14 @@ void Script::effect(Inkscape::Extension::Effect *module, return; } - if (desktop != NULL) { - Inkscape::Util::GSListConstIterator<SPItem *> selected = - sp_desktop_selection(desktop)->itemList(); - while ( selected != NULL ) { - Glib::ustring selected_id; - selected_id += "--id="; - selected_id += (*selected)->getId(); - params.insert(params.begin(), selected_id); - ++selected; - } + Inkscape::Util::GSListConstIterator<SPItem *> selected = + sp_desktop_selection(desktop)->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer + while ( selected != NULL ) { + Glib::ustring selected_id; + selected_id += "--id="; + selected_id += (*selected)->getId(); + params.insert(params.begin(), selected_id); + ++selected; } file_listener fileout; @@ -728,30 +731,37 @@ void Script::effect(Inkscape::Extension::Effect *module, g_unlink(tempfilename_out.c_str()); - /* Do something with mydoc.... */ if (mydoc) { - doc->doc()->emitReconstructionStart(); - copy_doc(doc->doc()->rroot, mydoc->rroot); - doc->doc()->emitReconstructionFinish(); - SPObject *layer = NULL; - - // Getting the named view from the document generated by the extension - SPNamedView *nv = sp_document_namedview(mydoc, NULL); - - //Check if it has a default layer set up - if ( nv != NULL){ - if( nv->default_layer_id != 0 ) { - SPDocument *document = desktop->doc(); - //If so, get that layer - layer = document->getObjectById(g_quark_to_string(nv->default_layer_id)); + SPDocument* vd=doc->doc(); + if (vd != NULL) + { + vd->emitReconstructionStart(); + copy_doc(vd->rroot, mydoc->rroot); + vd->emitReconstructionFinish(); + SPObject *layer = NULL; + + // Getting the named view from the document generated by the extension + SPNamedView *nv = sp_document_namedview(mydoc, NULL); + + //Check if it has a default layer set up + if ( nv != NULL) + { + if( nv->default_layer_id != 0 ) { + SPDocument *document = desktop->doc(); + //If so, get that layer + if (document != NULL) + { + layer = document->getObjectById(g_quark_to_string(nv->default_layer_id)); + } + } + } + + sp_namedview_update_layers_from_document(desktop); + //If that layer exists, + if (layer) { + //set the current layer + desktop->setCurrentLayer(layer); } - } - - sp_namedview_update_layers_from_document(desktop); - //If that layer exists, - if (layer) { - //set the current layer - desktop->setCurrentLayer(layer); } mydoc->release(); } @@ -778,6 +788,11 @@ void Script::effect(Inkscape::Extension::Effect *module, */ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot) { + if ((oldroot == NULL) ||(newroot == NULL)) + { + g_warning("Error on copy_doc: NULL pointer input."); + return; + } std::vector<Inkscape::XML::Node *> delete_list; Inkscape::XML::Node * oldroot_namedview = NULL; diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 4c27925ae..9fc6ecfdb 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -89,7 +89,7 @@ #include "io/inkscapestream.h" #include "io/bufferstream.h" - +#include <iomanip> namespace Inkscape { namespace Extension @@ -805,7 +805,6 @@ void SingularValueDecomposition::calculate() } - /** * Return the left singular vectors * @return U @@ -903,7 +902,6 @@ static Glib::ustring getAttribute( Inkscape::XML::Node *node, char const *attrNa } - /** * Get the extension suffix from the end of a file name */ @@ -923,7 +921,6 @@ static Glib::ustring getExtension(const Glib::ustring &fname) return ext; } - static Glib::ustring formatTransform(Geom::Affine &tf) { Glib::ustring str; @@ -939,9 +936,6 @@ static Glib::ustring formatTransform(Geom::Affine &tf) } - - - /** * Get the general transform from SVG pixels to * ODF cm @@ -960,8 +954,6 @@ static Geom::Affine getODFTransform(const SPItem *item) } - - /** * Get the bounding box of an item, as mapped onto * an ODF document, in cm. @@ -977,7 +969,6 @@ static Geom::OptRect getODFBoundingBox(const SPItem *item) } - /** * Get the transform for an item, correcting for * handedness reversal @@ -991,7 +982,6 @@ static Geom::Affine getODFItemTransform(const SPItem *item) } - /** * Get some fun facts from the transform */ @@ -1015,16 +1005,9 @@ static void analyzeTransform(Geom::Affine &tf, double s1 = svd.getS(1); xscale = s0; yscale = s1; - //g_message("## s0:%.3f s1:%.3f", s0, s1); - //g_message("## u:%.3f %.3f %.3f %.3f", U(0,0), U(0,1), U(1,0), U(1,1)); - //g_message("## v:%.3f %.3f %.3f %.3f", V(0,0), V(0,1), V(1,0), V(1,1)); - //g_message("## vt:%.3f %.3f %.3f %.3f", Vt(0,0), Vt(0,1), Vt(1,0), Vt(1,1)); - //g_message("## uvt:%.3f %.3f %.3f %.3f", UVt(0,0), UVt(0,1), UVt(1,0), UVt(1,1)); rotate = UVt(0,0); } - - static void gatherText(Inkscape::XML::Node *node, Glib::ustring &buf) { if (node->type() == Inkscape::XML::TEXT_NODE) @@ -1047,10 +1030,8 @@ static void gatherText(Inkscape::XML::Node *node, Glib::ustring &buf) * Method descends into the repr tree, converting image, style, and gradient info * into forms compatible in ODF. */ -void -OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) +void OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) { - Glib::ustring nodeName = node->name(); Glib::ustring id = getAttribute(node, "id"); @@ -1085,13 +1066,9 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) { return; } - //SPItem *item = SP_ITEM(reprobj); - //### Get SVG-to-ODF transform - //Geom::Affine tf = getODFTransform(item); if (nodeName == "image" || nodeName == "svg:image") { - //g_message("image"); Glib::ustring href = getAttribute(node, "xlink:href"); if (href.size() > 0) { @@ -1109,11 +1086,9 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) Glib::ustring comment = "old name was: "; comment.append(oldName); URI oldUri(oldName); - //g_message("oldpath:%s", oldUri.getNativePath().c_str()); //# if relative to the documentURI, get proper path URI resUri = documentUri.resolve(oldUri); DOMString pathName = resUri.getNativePath(); - //g_message("native path:%s", pathName.c_str()); ZipEntry *ze = zf.addFile(pathName, comment); if (ze) { @@ -1133,7 +1108,6 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) } - /** * Writes the manifest. Currently it only changes according to the * file names of images packed into the zip file. @@ -1146,25 +1120,25 @@ bool OdfOutput::writeManifest(ZipFile &zf) time_t tim; time(&tim); - outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - outs.printf("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" file: manifest.xml\n"); - outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> - outs.printf(" http://www.inkscape.org\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">\n"); - outs.printf(" <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>\n"); - outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>\n"); - outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>\n"); - outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>\n"); - outs.printf(" <!--List our images here-->\n"); + outs.writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + outs.writeString("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n"); + outs.writeString("\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" file: manifest.xml\n"); + outs.printf (" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> + outs.writeString(" http://www.inkscape.org\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("\n"); + outs.writeString("<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">\n"); + outs.writeString(" <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>\n"); + outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>\n"); + outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>\n"); + outs.writeString(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>\n"); + outs.writeString(" <!--List our images here-->\n"); std::map<Glib::ustring, Glib::ustring>::iterator iter; for (iter = imageTable.begin() ; iter!=imageTable.end() ; ++iter) { @@ -1224,29 +1198,29 @@ bool OdfOutput::writeMeta(ZipFile &zf) date = iter->second; } - outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" file: meta.xml\n"); - outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> - outs.printf(" http://www.inkscape.org\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:document-meta\n"); - outs.printf("xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); - outs.printf("xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); - outs.printf("xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); - outs.printf("xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); - outs.printf("xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); - outs.printf("xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); - outs.printf("xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); - 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"); + outs.writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + outs.writeString("\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" file: meta.xml\n"); + outs.printf (" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> + outs.writeString(" http://www.inkscape.org\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("\n"); + outs.writeString("<office:document-meta\n"); + outs.writeString("xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); + outs.writeString("xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); + outs.writeString("xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); + outs.writeString("xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); + outs.writeString("xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); + outs.writeString("xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); + outs.writeString("xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); + outs.writeString("xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); + outs.writeString("office:version=\"1.0\">\n"); + outs.writeString("<office:meta>\n"); 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()); @@ -1261,18 +1235,17 @@ bool OdfOutput::writeMeta(ZipFile &zf) 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"); - outs.printf(" <meta:user-defined meta:name=\"Info 2\"/>\n"); - outs.printf(" <meta:user-defined meta:name=\"Info 3\"/>\n"); - outs.printf(" <meta:user-defined meta:name=\"Info 4\"/>\n"); - outs.printf(" <meta:document-statistic meta:object-count=\"2\"/>\n"); - outs.printf("</office:meta>\n"); - outs.printf("</office:document-meta>\n"); - outs.printf("\n"); - outs.printf("\n"); - + outs.writeString(" <meta:editing-cycles>2</meta:editing-cycles>\n"); + outs.writeString(" <meta:editing-duration>PT56S</meta:editing-duration>\n"); + outs.writeString(" <meta:user-defined meta:name=\"Info 1\"/>\n"); + outs.writeString(" <meta:user-defined meta:name=\"Info 2\"/>\n"); + outs.writeString(" <meta:user-defined meta:name=\"Info 3\"/>\n"); + outs.writeString(" <meta:user-defined meta:name=\"Info 4\"/>\n"); + outs.writeString(" <meta:document-statistic meta:object-count=\"2\"/>\n"); + outs.writeString("</office:meta>\n"); + outs.writeString("</office:document-meta>\n"); + outs.writeString("\n"); + outs.writeString("\n"); outs.close(); @@ -1285,208 +1258,6 @@ bool OdfOutput::writeMeta(ZipFile &zf) } - - -/** - * This is called just before writeTree(), since it will write style and - * gradient information above the <draw> tag in the content.xml file - */ -bool OdfOutput::writeStyle(ZipFile &zf) -{ - BufferOutputStream bouts; - OutputStreamWriter outs(bouts); - - /* - ========================================================== - Dump our style table. Styles should have a general layout - something like the following. Look in: - http://books.evc-cit.info/odbook/ch06.html#draw-style-file-section - for style and gradient information. - <style:style style:name="gr13" - style:family="graphic" style:parent-style-name="standard"> - <style:graphic-properties draw:stroke="solid" - svg:stroke-width="0.1cm" - svg:stroke-color="#ff0000" - draw:fill="solid" draw:fill-color="#e6e6ff"/> - </style:style> - ========================================================== - */ - outs.printf("<!-- ####### Styles from Inkscape document ####### -->\n"); - std::vector<StyleInfo>::iterator iter; - for (iter = styleTable.begin() ; iter != styleTable.end() ; ++iter) - { - outs.printf("<style:style style:name=\"%s\"", iter->name.c_str()); - StyleInfo s(*iter); - outs.printf(" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); - outs.printf(" <style:graphic-properties"); - outs.printf(" draw:fill=\"%s\" ", s.fill.c_str()); - if (s.fill != "none") - { - outs.printf(" draw:fill-color=\"%s\" ", s.fillColor.c_str()); - outs.printf(" draw:fill-opacity=\"%s\" ", s.fillOpacity.c_str()); - } - outs.printf(" draw:stroke=\"%s\" ", s.stroke.c_str()); - if (s.stroke != "none") - { - outs.printf(" svg:stroke-width=\"%s\" ", s.strokeWidth.c_str()); - outs.printf(" svg:stroke-color=\"%s\" ", s.strokeColor.c_str()); - outs.printf(" svg:stroke-opacity=\"%s\" ", s.strokeOpacity.c_str()); - } - outs.printf("/>\n"); - outs.printf("</style:style>\n"); - } - - //## Dump our gradient table - unsigned int gradientCount = 0; - outs.printf("\n"); - outs.printf("<!-- ####### Gradients from Inkscape document ####### -->\n"); - std::vector<GradientInfo>::iterator giter; - for (giter = gradientTable.begin() ; giter != gradientTable.end() ; ++giter) - { - GradientInfo gi(*giter); - if (gi.style == "linear") - { - /* - =================================================================== - LINEAR gradient. We need something that looks like this: - <draw:gradient draw:name="Gradient_20_7" - draw:display-name="Gradient 7" - draw:style="linear" - draw:start-color="#008080" draw:end-color="#993366" - draw:start-intensity="100%" draw:end-intensity="100%" - draw:angle="150" draw:border="0%"/> - =================================================================== - */ - if (gi.stops.size() < 2) - { - g_warning("Need at least 2 tops for a linear gradient"); - continue; - } - outs.printf("<svg:linearGradient "); - 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", - gi.x1, gi.y1); - outs.printf(" svg:x2=\"%05.3fcm\" svg:y2=\"%05.3fcm\"\n", - gi.x2, gi.y2); - outs.printf(" svg:gradientUnits=\"objectBoundingBox\">\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[0].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[0].opacity * 100.0); - outs.printf(" svg:offset=\"0\"/>\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[1].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[1].opacity * 100.0); - outs.printf(" svg:offset=\"1\"/>\n"); - outs.printf("</svg:linearGradient>\n"); - } - else if (gi.style == "radial") - { - /* - =================================================================== - RADIAL gradient. We need something that looks like this: - <!-- radial gradient, light gray to white, centered, 0% border --> - <draw:gradient draw:name="radial_20_borderless" - draw:display-name="radial borderless" - draw:style="radial" - draw:cx="50%" draw:cy="50%" - draw:start-color="#999999" draw:end-color="#ffffff" - draw:border="0%"/> - =================================================================== - */ - if (gi.stops.size() < 2) - { - g_warning("Need at least 2 tops for a radial gradient"); - continue; - } - outs.printf("<svg:radialGradient "); - 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); - outs.printf(" svg:fx=\"%05.3f\" svg:fy=\"%05.3f\"\n", - gi.fx, gi.fy); - outs.printf(" svg:r=\"%05.3f\"\n", - gi.r); - outs.printf(" svg:gradientUnits=\"objectBoundingBox\">\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[0].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[0].opacity * 100.0); - outs.printf(" svg:offset=\"0\"/>\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[1].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[1].opacity * 100.0); - outs.printf(" svg:offset=\"1\"/>\n"); - outs.printf("</svg:radialGradient>\n"); - } - else - { - g_warning("unsupported gradient style '%s'", gi.style.c_str()); - } - 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\"\n", - gi.name.c_str()); - outs.printf(" draw:textarea-horizontal-align=\"center\" "); - outs.printf("draw:textarea-vertical-align=\"middle\"/>\n"); - outs.printf("</style:style>\n\n"); - - gradientCount++; - } - - outs.printf("\n"); - outs.printf("</office:automatic-styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:master-styles>\n"); - outs.printf("<draw:layer-set>\n"); - outs.printf(" <draw:layer draw:name=\"layout\"/>\n"); - outs.printf(" <draw:layer draw:name=\"background\"/>\n"); - outs.printf(" <draw:layer draw:name=\"backgroundobjects\"/>\n"); - outs.printf(" <draw:layer draw:name=\"controls\"/>\n"); - outs.printf(" <draw:layer draw:name=\"measurelines\"/>\n"); - outs.printf("</draw:layer-set>\n"); - outs.printf("\n"); - outs.printf("<style:master-page style:name=\"Default\"\n"); - outs.printf(" style:page-master-name=\"PM1\" draw:style-name=\"dp1\"/>\n"); - outs.printf("</office:master-styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("</office:document-styles>\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" E N D O F F I L E\n"); - outs.printf(" Have a nice day\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - - //Make our entry - ZipEntry *ze = zf.newEntry("styles.xml", "ODF style file"); - ze->setUncompressedData(bouts.getBuffer()); - ze->finish(); - - return true; -} - - - /** * Writes an SVG path as an ODF <draw:path> and returns the number of points written */ @@ -1544,24 +1315,29 @@ writePath(Writer &outs, Geom::PathVector const &pathv, return nrPoints; } - - -bool OdfOutput::processStyle(Writer &outs, SPItem *item, - const Glib::ustring &id) +bool OdfOutput::processStyle(Writer &outs, SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill)//, Glib::ustring &styleString) { + if (!item) + { + return false; + } + SPStyle *style = item->style; - + if (!style) + { + return false; + } + StyleInfo si; - //## FILL + // FILL if (style->fill.isColor()) - { + { guint32 fillCol = style->fill.value.color.toRGBA32( 0 ); char buf[16]; int r = (fillCol >> 24) & 0xff; int g = (fillCol >> 16) & 0xff; int b = (fillCol >> 8) & 0xff; - //g_message("## %s %lx", id.c_str(), (unsigned int)fillCol); snprintf(buf, 15, "#%02x%02x%02x", r, g, b); si.fillColor = buf; si.fill = "solid"; @@ -1569,11 +1345,19 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, (SP_SCALE24_TO_FLOAT(style->fill_opacity.value)); snprintf(buf, 15, "%.3f%%", opacityPercent); si.fillOpacity = buf; + } + else if (style->fill.isPaintserver()) + { + SPGradient *gradient = SP_GRADIENT(SP_STYLE_FILL_SERVER(style)); + if (gradient) + { + si.fill = "gradient"; } + } - //## STROKE + // STROKE if (style->stroke.isColor()) - { + { guint32 strokeCol = style->stroke.value.color.toRGBA32( 0 ); char buf[16]; int r = (strokeCol >> 24) & 0xff; @@ -1588,157 +1372,169 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, (SP_SCALE24_TO_FLOAT(style->stroke_opacity.value)); snprintf(buf, 15, "%.3f%%", opacityPercent); si.strokeOpacity = buf; + } + else if (style->stroke.isPaintserver()) + { + SPGradient *gradient = SP_GRADIENT(SP_STYLE_STROKE_SERVER(style)); + if (gradient) + { + si.stroke = "gradient"; } + } //Look for existing identical style; bool styleMatch = false; std::vector<StyleInfo>::iterator iter; for (iter=styleTable.begin() ; iter!=styleTable.end() ; ++iter) - { + { if (si.equals(*iter)) - { + { //map to existing styleTable entry Glib::ustring styleName = iter->name; - //g_message("found duplicate style:%s", styleName.c_str()); styleLookupTable[id] = styleName; styleMatch = true; break; - } } + } - //## Dont need a new style + // Dont need a new style if (styleMatch) + { return false; + } - char buf[16]; - snprintf(buf, 15, "style%d", (int)styleTable.size()); - Glib::ustring styleName = buf; + Glib::ustring styleName = Glib::ustring::compose("style%1", styleTable.size()); si.name = styleName; styleTable.push_back(si); styleLookupTable[id] = styleName; - outs.printf("<style:style style:name=\"%s\"", si.name.c_str()); - outs.printf(" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); - outs.printf(" <style:graphic-properties"); - outs.printf(" draw:fill=\"%s\" ", si.fill.c_str()); - if (si.fill != "none") + Glib::ustring tmpstring = Glib::ustring::compose ("<style:style style:name=\"%1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n", si.name); + // Glib::ustring tmpstring; + tmpstring += "<style:graphic-properties "; + if (si.fill == "gradient") + { + tmpstring += Glib::ustring::compose (" draw:fill=\"gradient\" draw:fill-gradient-name=\"%1\"", gradientNameFill); + } + else + { + tmpstring += Glib::ustring(" draw:fill=\"") + si.fill + "\""; + if(si.fill != "none") { - outs.printf(" draw:fill-color=\"%s\" ", si.fillColor.c_str()); - outs.printf(" draw:fill-opacity=\"%s\" ", si.fillOpacity.c_str()); + tmpstring += Glib::ustring::compose(" draw:fill-color=\"%1\" draw:fill-opacity=\"%2\"", si.fillColor, si.fillOpacity); } - outs.printf(" draw:stroke=\"%s\" ", si.stroke.c_str()); - if (si.stroke != "none") + } + if (si.stroke == "gradient") + { + tmpstring += Glib::ustring (" draw:stroke=\"gradient\" draw:stroke-gradient-name=\"NotYetProgrammedPleaseBePatient\""); + } + else + { + tmpstring += Glib::ustring(" draw:stroke=\"") + si.stroke + "\""; + if (si.stroke != "none") { - outs.printf(" svg:stroke-width=\"%s\" ", si.strokeWidth.c_str()); - outs.printf(" svg:stroke-color=\"%s\" ", si.strokeColor.c_str()); - outs.printf(" svg:stroke-opacity=\"%s\" ", si.strokeOpacity.c_str()); + tmpstring += Glib::ustring::compose (" svg:stroke-width=\"%1\" svg:stroke-color=\"%2\" svg:stroke-opacity=\"%3\" ", si.strokeWidth, si.strokeColor, si.strokeOpacity); } - outs.printf("/>\n"); - outs.printf("</style:style>\n"); + } + tmpstring += "/>\n</style:style>\n"; + outs.writeUString (tmpstring); return true; } - - - bool OdfOutput::processGradient(Writer &outs, SPItem *item, - const Glib::ustring &id, Geom::Affine &/*tf*/) + const Glib::ustring &id, Geom::Affine &/*tf*/, + Glib::ustring& gradientName, Glib::ustring& output, bool checkFillGradient) { + output.clear(); if (!item) + { return false; + } SPStyle *style = item->style; - if (!style) + { return false; + } - if (!style->fill.isPaintserver()) - return false; - - //## Gradient. Look in writeStyle() below to see what info - // we need to read into GradientInfo. - if (!SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style))) + if ((checkFillGradient? (!style->fill.isPaintserver()) : (!style->stroke.isPaintserver()))) + { return false; + } - SPGradient *gradient = SP_GRADIENT(SP_STYLE_FILL_SERVER(style)); + //## Gradient + SPGradient *gradient = SP_GRADIENT((checkFillGradient?(SP_STYLE_FILL_SERVER(style)) :(SP_STYLE_STROKE_SERVER(style)))); + if (gradient == NULL) + { + return false; + } GradientInfo gi; - SPGradient *grvec = gradient->getVector(FALSE); - for (SPStop *stop = grvec->getFirstStop() ; + for (SPStop *stop = grvec->getFirstStop(); stop ; stop = stop->getNextStop()) - { + { unsigned long rgba = sp_stop_get_rgba32(stop); unsigned long rgb = (rgba >> 8) & 0xffffff; - double opacity = ((double)(rgba & 0xff)) / 256.0; + double opacity = (static_cast<double>(rgba & 0xff)) / 256.0; GradientStop gs(rgb, opacity); gi.stops.push_back(gs); - } + } if (SP_IS_LINEARGRADIENT(gradient)) - { + { gi.style = "linear"; SPLinearGradient *linGrad = SP_LINEARGRADIENT(gradient); - /* - Geom::Point p1(linGrad->x1.value, linGrad->y1.value); - p1 = p1 * tf; - gi.x1 = p1[Geom::X]; - gi.y1 = p1[Geom::Y]; - Geom::Point p2(linGrad->x2.value, linGrad->y2.value); - p2 = p2 * tf; - gi.x2 = p2[Geom::X]; - gi.y2 = p2[Geom::Y]; - */ gi.x1 = linGrad->x1.value; gi.y1 = linGrad->y1.value; gi.x2 = linGrad->x2.value; gi.y2 = linGrad->y2.value; - } + } else if (SP_IS_RADIALGRADIENT(gradient)) - { + { gi.style = "radial"; SPRadialGradient *radGrad = SP_RADIALGRADIENT(gradient); gi.cx = radGrad->cx.computed * 100.0;//ODG cx is percentages gi.cy = radGrad->cy.computed * 100.0; - } + } else - { + { g_warning("not a supported gradient type"); return false; - } + } //Look for existing identical style; bool gradientMatch = false; std::vector<GradientInfo>::iterator iter; for (iter=gradientTable.begin() ; iter!=gradientTable.end() ; ++iter) - { + { if (gi.equals(*iter)) - { + { //map to existing gradientTable entry - Glib::ustring gradientName = iter->name; - //g_message("found duplicate style:%s", gradientName.c_str()); + // Glib::ustring gradientName = iter->name; + gradientName = iter->name; gradientLookupTable[id] = gradientName; gradientMatch = true; break; - } } + } if (gradientMatch) + { return true; + } - //## No match, let us write a new entry - char buf[16]; - snprintf(buf, 15, "gradient%d", (int)gradientTable.size()); - Glib::ustring gradientName = buf; + // No match, let us write a new entry + // Glib::ustring gradientName = Glib::ustring::compose("gradient%1", gradientTable.size()); + gradientName = Glib::ustring::compose("gradient%1", gradientTable.size()); gi.name = gradientName; gradientTable.push_back(gi); gradientLookupTable[id] = gradientName; int gradientCount = gradientTable.size(); - + char buf[128]; if (gi.style == "linear") - { + { /* =================================================================== LINEAR gradient. We need something that looks like this: @@ -1751,36 +1547,24 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, =================================================================== */ if (gi.stops.size() < 2) - { + { g_warning("Need at least 2 stops for a linear gradient"); - return false;; - } - outs.printf("<svg:linearGradient "); - 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"); - outs.printf(" svg:x1=\"%05.3fcm\" svg:y1=\"%05.3fcm\"\n", - gi.x1 * pxToCm, gi.y1 * pxToCm); - outs.printf(" svg:x2=\"%05.3fcm\" svg:y2=\"%05.3fcm\">\n", - gi.x2 * pxToCm, gi.y2 * pxToCm); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[0].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[0].opacity * 100.0); - outs.printf(" svg:offset=\"0\"/>\n"); - outs.printf(" <svg:stop\n"); - outs.printf(" svg:stop-color=\"#%06lx\"\n", - gi.stops[1].rgb); - outs.printf(" svg:stop-opacity=\"%f%%\"\n", - gi.stops[1].opacity * 100.0); - outs.printf(" svg:offset=\"1\"/>\n"); - outs.printf("</svg:linearGradient>\n"); + return false; } + output += Glib::ustring::compose("<draw:gradient draw:name=\"%1\"", gi.name); + // "<draw:gradient id=\"%1\" draw:name=\"%2\"\n", gi.name, gi.name); + output += Glib::ustring::compose(" draw:display-name=\"imported linear %1\"", gradientCount); + output += " draw:style=\"linear\""; + // outs.writeUString (tmpstring); + // outs.printf(" draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\"\n", gi.stops[0].rgb, gi.stops[1].rgb); + snprintf(buf, 127, " draw:start-color=\"#%06lx\" draw:end-color=\"#%06lx\"", gi.stops[0].rgb, gi.stops[1].rgb); + output += buf; + output += Glib::ustring::compose(" draw:start-intensity=\"%1\" draw:end-intensity=\"%2\" draw:angle=\"0\" draw:border=\"0%%\"/>\n", + gi.stops[0].opacity * 100.0, gi.stops[1].opacity * 100.0); + // outs.writeUString (tmpstring); + } else if (gi.style == "radial") - { + { /* =================================================================== RADIAL gradient. We need something that looks like this: @@ -1794,10 +1578,11 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, =================================================================== */ if (gi.stops.size() < 2) - { + { g_warning("Need at least 2 stops for a radial gradient"); return false; - } + } + /* outs.printf("<svg:radialGradient "); outs.printf("id=\"%s\" ", gi.name.c_str()); outs.printf("draw:name=\"%s\"\n", gi.name.c_str()); @@ -1823,33 +1608,20 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, gi.stops[1].opacity * 100.0); outs.printf(" svg:offset=\"1\"/>\n"); outs.printf("</svg:radialGradient>\n"); - } + */ + } else - { + { g_warning("unsupported gradient style '%s'", gi.style.c_str()); return false; - } - 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\"\n", - gi.name.c_str()); - outs.printf(" draw:textarea-horizontal-align=\"center\" "); - outs.printf("draw:textarea-vertical-align=\"middle\"/>\n"); - outs.printf("</style:style>\n\n"); - + } return true; } - - /** * SECOND PASS. - * This is the main SPObject tree output to ODF. preprocess() - * must be called prior to this, as elements will often reference - * data parsed and tabled in preprocess(). + * This is the main SPObject tree output to ODF. */ bool OdfOutput::writeTree(Writer &couts, Writer &souts, Inkscape::XML::Node *node) @@ -1857,22 +1629,19 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, //# Get the SPItem, if applicable SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(node); if (!reprobj) + { return true; + } if (!SP_IS_ITEM(reprobj)) - { + { return true; - } + } SPItem *item = SP_ITEM(reprobj); - Glib::ustring nodeName = node->name(); Glib::ustring id = getAttribute(node, "id"); - - //### Get SVG-to-ODF transform - Geom::Affine tf = getODFTransform(item); - - //### Get ODF bounding box params for item - Geom::OptRect bbox = getODFBoundingBox(item); + Geom::Affine tf = getODFTransform(item);//Get SVG-to-ODF transform + Geom::OptRect bbox = getODFBoundingBox(item);//Get ODF bounding box params for item if (!bbox) { return true; } @@ -1892,8 +1661,6 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, //# Do our stuff SPCurve *curve = NULL; - - if (nodeName == "svg" || nodeName == "svg:svg") { //# Iterate through the children @@ -1937,26 +1704,26 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, return true; } - //###################################### - //# S T Y L E - //###################################### - processStyle(souts, item, id); - - //###################################### - //# G R A D I E N T - //###################################### - processGradient(souts, item, id, tf); - - - //###################################### - //# I T E M D A T A - //###################################### - //g_message("##### %s #####", nodeName.c_str()); + //# GRADIENT + Glib::ustring gradientNameFill; + Glib::ustring gradientNameStroke; + Glib::ustring outputFill; + Glib::ustring outputStroke; + // Glib::ustring styleString; + + processGradient(souts, item, id, tf, gradientNameFill, outputFill, 1); + souts.writeUString(outputFill); + + //# STYLE + processStyle(souts, item, id, gradientNameFill);//, styleString); + + + //# ITEM DATA if (nodeName == "image" || nodeName == "svg:image") { if (!SP_IS_IMAGE(item)) { - g_warning("<image> is not an SPImage. Why? ;-)"); + g_warning("<image> is not an SPImage."); return false; } @@ -2005,13 +1772,13 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, couts.printf("draw:transform=\"translate(%.3fcm, %.3fcm)\" ", ix, iy); } - couts.printf(">\n"); + couts.writeString(">\n"); couts.printf(" <draw:image xlink:href=\"%s\" xlink:type=\"simple\"\n", newName.c_str()); - couts.printf(" xlink:show=\"embed\" xlink:actuate=\"onLoad\">\n"); - couts.printf(" <text:p/>\n"); - couts.printf(" </draw:image>\n"); - couts.printf("</draw:frame>\n"); + couts.writeString(" xlink:show=\"embed\" xlink:actuate=\"onLoad\">\n"); + couts.writeString(" <text:p/>\n"); + couts.writeString(" </draw:image>\n"); + couts.writeString("</draw:frame>\n"); return true; } else if (SP_IS_SHAPE(item)) @@ -2026,7 +1793,7 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, if (curve) { //### Default <path> output - couts.printf("<draw:path "); + couts.writeString("<draw:path "); if (!id.empty()) { couts.printf("id=\"%s\" ", id.c_str()); @@ -2039,15 +1806,16 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, Glib::ustring styleName = siter->second; couts.printf("draw:style-name=\"%s\" ", styleName.c_str()); } + // couts.writeUString(styleString); - 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()); - } + // 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); @@ -2059,12 +1827,11 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, couts.printf(" svg:d=\""); int nrPoints = writePath(couts, curve->get_pathvector(), tf, bbox_x, bbox_y); - couts.printf("\""); + couts.writeString("\""); - couts.printf(">\n"); + couts.writeString(">\n"); couts.printf(" <!-- %d nodes -->\n", nrPoints); - couts.printf("</draw:path>\n\n"); - + couts.writeString("</draw:path>\n\n"); curve->unref(); } @@ -2073,7 +1840,6 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, } - /** * Write the header for the content.xml file */ @@ -2082,59 +1848,56 @@ bool OdfOutput::writeStyleHeader(Writer &outs) time_t tim; time(&tim); - outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" file: styles.xml\n"); - outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> - outs.printf(" http://www.inkscape.org\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:document-styles\n"); - outs.printf(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); - outs.printf(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n"); - outs.printf(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n"); - outs.printf(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n"); - outs.printf(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n"); - outs.printf(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n"); - outs.printf(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); - outs.printf(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); - outs.printf(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); - outs.printf(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n"); - outs.printf(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); - outs.printf(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n"); - outs.printf(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n"); - outs.printf(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n"); - outs.printf(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n"); - outs.printf(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n"); - outs.printf(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n"); - outs.printf(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); - outs.printf(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n"); - outs.printf(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n"); - outs.printf(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n"); - outs.printf(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n"); - outs.printf(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"); - outs.printf(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); - outs.printf(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); - outs.printf(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); - outs.printf(" office:version=\"1.0\">\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" S T Y L E S\n"); - outs.printf(" Style entries have been pulled from the svg style and\n"); - outs.printf(" representation attributes in the SVG tree. The tree elements\n"); - outs.printf(" then refer to them by name, in the ODF manner\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("<office:styles>\n"); - outs.printf("\n"); + outs.writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" file: styles.xml\n"); + outs.printf (" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> + outs.writeString(" http://www.inkscape.org\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:document-styles\n"); + outs.writeString(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); + outs.writeString(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n"); + outs.writeString(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n"); + outs.writeString(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n"); + outs.writeString(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n"); + outs.writeString(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n"); + outs.writeString(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); + outs.writeString(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); + outs.writeString(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); + outs.writeString(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n"); + outs.writeString(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); + outs.writeString(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n"); + outs.writeString(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n"); + outs.writeString(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n"); + outs.writeString(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n"); + outs.writeString(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n"); + outs.writeString(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n"); + outs.writeString(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); + outs.writeString(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n"); + outs.writeString(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n"); + outs.writeString(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n"); + outs.writeString(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n"); + outs.writeString(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"); + outs.writeString(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); + outs.writeString(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); + outs.writeString(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); + outs.writeString(" office:version=\"1.0\">\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" S T Y L E S\n"); + outs.writeString(" Style entries have been pulled from the svg style and\n"); + outs.writeString(" representation attributes in the SVG tree. The tree elements\n"); + outs.writeString(" then refer to them by name, in the ODF manner\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:styles>\n"); + outs.writeString("\n"); return true; } @@ -2145,58 +1908,49 @@ bool OdfOutput::writeStyleHeader(Writer &outs) */ bool OdfOutput::writeStyleFooter(Writer &outs) { - outs.printf("\n"); - outs.printf("</office:styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:automatic-styles>\n"); - outs.printf("<!-- ####### 'Standard' styles ####### -->\n"); - outs.printf("<style:style style:name=\"dp1\" style:family=\"drawing-page\"/>\n"); - outs.printf("<style:style style:name=\"gr1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); - outs.printf(" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"none\"\n"); - outs.printf(" draw:textarea-horizontal-align=\"center\"\n"); - outs.printf(" draw:textarea-vertical-align=\"middle\" draw:color-mode=\"standard\"\n"); - outs.printf(" draw:luminance=\"0%%\" draw:contrast=\"0%%\" draw:gamma=\"100%%\" draw:red=\"0%%\"\n"); - outs.printf(" draw:green=\"0%%\" draw:blue=\"0%%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n"); - outs.printf(" draw:image-opacity=\"100%%\" style:mirror=\"none\"/>\n"); - outs.printf("</style:style>\n"); - outs.printf("<style:style style:name=\"P1\" style:family=\"paragraph\">\n"); - outs.printf(" <style:paragraph-properties fo:text-align=\"center\"/>\n"); - outs.printf("</style:style>\n"); - outs.printf("</office:automatic-styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:master-styles>\n"); - outs.printf("<draw:layer-set>\n"); - outs.printf(" <draw:layer draw:name=\"layout\"/>\n"); - outs.printf(" <draw:layer draw:name=\"background\"/>\n"); - outs.printf(" <draw:layer draw:name=\"backgroundobjects\"/>\n"); - outs.printf(" <draw:layer draw:name=\"controls\"/>\n"); - outs.printf(" <draw:layer draw:name=\"measurelines\"/>\n"); - outs.printf("</draw:layer-set>\n"); - outs.printf("\n"); - outs.printf("<style:master-page style:name=\"Default\"\n"); - outs.printf(" style:page-master-name=\"PM1\" draw:style-name=\"dp1\"/>\n"); - outs.printf("</office:master-styles>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("</office:document-styles>\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" E N D O F F I L E\n"); - outs.printf(" Have a nice day\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); + outs.writeString("\n"); + outs.writeString("</office:styles>\n"); + outs.writeString("\n"); + outs.writeString("<office:automatic-styles>\n"); + outs.writeString("<!-- ####### 'Standard' styles ####### -->\n"); + outs.writeString("<style:style style:name=\"dp1\" style:family=\"drawing-page\"/>\n"); + outs.writeString("<style:style style:name=\"standard\" style:family=\"graphic\">\n"); + +///TODO: add default document style here + + outs.writeString("</style:style>\n"); + outs.writeString("<style:style style:name=\"gr1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n"); + outs.writeString(" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"none\"\n"); + outs.writeString(" draw:textarea-horizontal-align=\"center\"\n"); + outs.writeString(" draw:textarea-vertical-align=\"middle\" draw:color-mode=\"standard\"\n"); + outs.writeString(" draw:luminance=\"0%\" draw:contrast=\"0%\" draw:gamma=\"100%\" draw:red=\"0%\"\n"); + outs.writeString(" draw:green=\"0%\" draw:blue=\"0%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n"); + outs.writeString(" draw:image-opacity=\"100%\" style:mirror=\"none\"/>\n"); + outs.writeString("</style:style>\n"); + outs.writeString("<style:style style:name=\"P1\" style:family=\"paragraph\">\n"); + outs.writeString(" <style:paragraph-properties fo:text-align=\"center\"/>\n"); + outs.writeString("</style:style>\n"); + outs.writeString("</office:automatic-styles>\n"); + outs.writeString("\n"); + outs.writeString("<office:master-styles>\n"); + outs.writeString("<draw:layer-set>\n"); + outs.writeString(" <draw:layer draw:name=\"layout\"/>\n"); + outs.writeString(" <draw:layer draw:name=\"background\"/>\n"); + outs.writeString(" <draw:layer draw:name=\"backgroundobjects\"/>\n"); + outs.writeString(" <draw:layer draw:name=\"controls\"/>\n"); + outs.writeString(" <draw:layer draw:name=\"measurelines\"/>\n"); + outs.writeString("</draw:layer-set>\n"); + outs.writeString("\n"); + outs.writeString("<style:master-page style:name=\"Default\"\n"); + outs.writeString(" style:page-master-name=\"PM1\" draw:style-name=\"dp1\"/>\n"); + outs.writeString("</office:master-styles>\n"); + outs.writeString("\n"); + outs.writeString("</office:document-styles>\n"); return true; } - - /** * Write the header for the content.xml file */ @@ -2205,69 +1959,61 @@ bool OdfOutput::writeContentHeader(Writer &outs) time_t tim; time(&tim); - outs.printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" file: content.xml\n"); - outs.printf(" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> - outs.printf(" http://www.inkscape.org\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:document-content\n"); - outs.printf(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); - outs.printf(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n"); - outs.printf(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n"); - outs.printf(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n"); - outs.printf(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n"); - outs.printf(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n"); - outs.printf(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); - outs.printf(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); - outs.printf(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); - outs.printf(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n"); - outs.printf(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); - outs.printf(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n"); - outs.printf(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n"); - outs.printf(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n"); - outs.printf(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n"); - outs.printf(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n"); - outs.printf(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n"); - outs.printf(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); - outs.printf(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n"); - outs.printf(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n"); - outs.printf(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n"); - outs.printf(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n"); - outs.printf(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"); - outs.printf(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); - outs.printf(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); - outs.printf(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); - outs.printf(" office:version=\"1.0\">\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:scripts/>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" D R A W I N G\n"); - outs.printf(" This section is the heart of SVG-ODF conversion. We are\n"); - outs.printf(" starting with simple conversions, and will slowly evolve\n"); - outs.printf(" into a 'smarter' translation as time progresses. Any help\n"); - outs.printf(" in improving .odg export is welcome.\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<office:body>\n"); - outs.printf("<office:drawing>\n"); - outs.printf("<draw:page draw:name=\"page1\" draw:style-name=\"dp1\"\n"); - outs.printf(" draw:master-page-name=\"Default\">\n"); - outs.printf("\n"); - outs.printf("\n"); - + outs.writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" file: content.xml\n"); + outs.printf (" Generated by Inkscape: %s", ctime(&tim)); //ctime has its own <cr> + outs.writeString(" http://www.inkscape.org\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:document-content\n"); + outs.writeString(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"\n"); + outs.writeString(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"\n"); + outs.writeString(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"\n"); + outs.writeString(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"\n"); + outs.writeString(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"\n"); + outs.writeString(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"\n"); + outs.writeString(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); + outs.writeString(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); + outs.writeString(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"\n"); + outs.writeString(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"\n"); + outs.writeString(" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\"\n"); + outs.writeString(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"\n"); + outs.writeString(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"\n"); + outs.writeString(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"\n"); + outs.writeString(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n"); + outs.writeString(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"\n"); + outs.writeString(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"\n"); + outs.writeString(" xmlns:ooo=\"http://openoffice.org/2004/office\"\n"); + outs.writeString(" xmlns:ooow=\"http://openoffice.org/2004/writer\"\n"); + outs.writeString(" xmlns:oooc=\"http://openoffice.org/2004/calc\"\n"); + outs.writeString(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"\n"); + outs.writeString(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"\n"); + outs.writeString(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"); + outs.writeString(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); + outs.writeString(" xmlns:smil=\"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0\"\n"); + outs.writeString(" xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); + outs.writeString(" office:version=\"1.0\">\n"); + outs.writeString("<office:scripts/>\n"); + outs.writeString("\n"); + outs.writeString("<!--\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString(" D R A W I N G\n"); + outs.writeString(" This section is the heart of SVG-ODF conversion. We are\n"); + outs.writeString(" starting with simple conversions, and will slowly evolve\n"); + outs.writeString(" into a 'smarter' translation as time progresses. Any help\n"); + outs.writeString(" in improving .odg export is welcome.\n"); + outs.writeString("*************************************************************************\n"); + outs.writeString("-->\n"); + outs.writeString("\n"); + outs.writeString("<office:body>\n"); + outs.writeString("<office:drawing>\n"); + outs.writeString("<draw:page draw:name=\"page1\" draw:style-name=\"dp1\"\n"); + outs.writeString(" draw:master-page-name=\"Default\">\n"); + outs.writeString("\n"); return true; } @@ -2277,37 +2023,18 @@ bool OdfOutput::writeContentHeader(Writer &outs) */ bool OdfOutput::writeContentFooter(Writer &outs) { - outs.printf("\n"); - outs.printf("\n"); - - outs.printf("</draw:page>\n"); - outs.printf("</office:drawing>\n"); - - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!-- ######### CONVERSION FROM SVG ENDS ######## -->\n"); - outs.printf("\n"); - outs.printf("\n"); - - outs.printf("</office:body>\n"); - outs.printf("</office:document-content>\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("\n"); - outs.printf("<!--\n"); - outs.printf("*************************************************************************\n"); - outs.printf(" E N D O F F I L E\n"); - outs.printf(" Have a nice day\n"); - outs.printf("*************************************************************************\n"); - outs.printf("-->\n"); - outs.printf("\n"); - outs.printf("\n"); - + outs.writeString("\n"); + outs.writeString("</draw:page>\n"); + outs.writeString("</office:drawing>\n"); + outs.writeString("\n"); + outs.writeString("<!-- ######### CONVERSION FROM SVG ENDS ######## -->\n"); + outs.writeString("\n"); + outs.writeString("</office:body>\n"); + outs.writeString("</office:document-content>\n"); return true; } - /** * Write the content.xml file. Writes the namesspace headers, then * calls writeTree(). @@ -2346,8 +2073,6 @@ bool OdfOutput::writeContent(ZipFile &zf, Inkscape::XML::Node *node) setlocale (LC_NUMERIC, oldlocale); g_free (oldlocale); - - //# Finish content file if (!writeContentFooter(couts)) { @@ -2358,8 +2083,6 @@ bool OdfOutput::writeContent(ZipFile &zf, Inkscape::XML::Node *node) ze->setUncompressedData(cbouts.getBuffer()); ze->finish(); - - //# Finish style file if (!writeStyleFooter(souts)) { @@ -2377,8 +2100,7 @@ bool OdfOutput::writeContent(ZipFile &zf, Inkscape::XML::Node *node) /** * Resets class to its pristine condition, ready to use again */ -void -OdfOutput::reset() +void OdfOutput::reset() { metadata.clear(); styleTable.clear(); @@ -2386,20 +2108,16 @@ OdfOutput::reset() gradientTable.clear(); gradientLookupTable.clear(); imageTable.clear(); - - } /** * Descends into the SVG tree, mapping things to ODF when appropriate */ -void -OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar const *filename) +void OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar const *filename) { reset(); - //g_message("native file:%s\n", filename); documentUri = URI(filename); /* fixme: It looks like we really are using documentUri as a URI, so we ought to call * g_filename_to_uri for the URI constructor. */ @@ -2437,8 +2155,7 @@ OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar con * calls the extension system with the memory allocated XML that * describes the data. */ -void -OdfOutput::init() +void OdfOutput::init() { Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" @@ -2457,8 +2174,7 @@ OdfOutput::init() /** * Make sure that we are in the database */ -bool -OdfOutput::check (Inkscape::Extension::Extension */*module*/) +bool OdfOutput::check (Inkscape::Extension::Extension */*module*/) { /* We don't need a Key if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV)) @@ -2468,9 +2184,6 @@ OdfOutput::check (Inkscape::Extension::Extension */*module*/) return TRUE; } - - - } //namespace Internal } //namespace Extension } //namespace Inkscape diff --git a/src/extension/internal/odf.h b/src/extension/internal/odf.h index 001f5e1f1..5fcad2630 100644 --- a/src/extension/internal/odf.h +++ b/src/extension/internal/odf.h @@ -313,10 +313,10 @@ private: bool writeStyle(ZipFile &zf); - bool processStyle(Writer &outs, SPItem *item, const Glib::ustring &id); + bool processStyle(Writer &outs, SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill);//, Glib::ustring &styleString); bool processGradient(Writer &outs, SPItem *item, - const Glib::ustring &id, Geom::Affine &tf); + const Glib::ustring &id, Geom::Affine &tf, Glib::ustring& gradientName, Glib::ustring& output, bool checkFillGradient = 1); bool writeStyleHeader(Writer &outs); @@ -333,8 +333,6 @@ private: }; - - } //namespace Internal } //namespace Extension } //namespace Inkscape diff --git a/src/extension/internal/pdf-input-cairo.cpp b/src/extension/internal/pdf-input-cairo.cpp index c83ebad82..c2f2b43a5 100644 --- a/src/extension/internal/pdf-input-cairo.cpp +++ b/src/extension/internal/pdf-input-cairo.cpp @@ -643,13 +643,13 @@ void PdfInputCairo::init(void) { Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" - "<name>PDF Input</name>\n" + "<name>" N_("PDF Input") "</name>\n" "<id>org.inkscape.input.cairo-pdf</id>\n" "<input>\n" "<extension>.pdf</extension>\n" "<mimetype>application/pdf</mimetype>\n" - "<filetypename>Adobe PDF via poppler-cairo (*.pdf)</filetypename>\n" - "<filetypetooltip>PDF Document</filetypetooltip>\n" + "<filetypename>" N_("Adobe PDF via poppler-cairo (*.pdf)") "</filetypename>\n" + "<filetypetooltip>" N_("PDF Document") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new PdfInputCairo()); } // init diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index 921c322b6..38ed1fe77 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -172,7 +172,7 @@ const gchar *ParamRadioButton::set(const gchar * in, SPDocument * /*doc*/, Inksc Glib::ustring * settext = NULL; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { optionentry * entr = reinterpret_cast<optionentry *>(list->data); - if ( !entr->guitext->compare(in) ) { + if ( !entr->value->compare(in) ) { settext = entr->value; break; // break out of for loop } diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index eebc566f2..df0e4fcf2 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -282,12 +282,12 @@ geom_cubic_bbox_wind_distance (Geom::Coord x000, Geom::Coord y000, y0 = std::min (y000, y001); y0 = std::min (y0, y011); y0 = std::min (y0, y111); - x1 = std::min (x000, x001); - x1 = std::min (x1, x011); - x1 = std::min (x1, x111); - y1 = std::min (y000, y001); - y1 = std::min (y1, y011); - y1 = std::min (y1, y111); + x1 = std::max (x000, x001); + x1 = std::max (x1, x011); + x1 = std::max (x1, x111); + y1 = std::max (y000, y001); + y1 = std::max (y1, y011); + y1 = std::max (y1, y111); if (best) { /* Quickly adjust to endpoints */ diff --git a/src/inkscape.cpp b/src/inkscape.cpp index ac419784f..eca19c4b9 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -364,15 +364,17 @@ static gint inkscape_autosave(gpointer) while( (filename = g_dir_read_name(autosave_dir_ptr)) != NULL ){ if ( strncmp(filename, baseName, strlen(baseName)) == 0 ){ gchar* full_path = g_build_filename( autosave_dir.c_str(), filename, NULL ); - if ( g_stat(full_path, &sb) != -1 ) { - if ( difftime(sb.st_ctime, min_time) < 0 || min_time == 0 ){ - min_time = sb.st_ctime; - if ( oldest_autosave ) { - g_free(oldest_autosave); + if (g_file_test (full_path, G_FILE_TEST_EXISTS)){ + if ( g_stat(full_path, &sb) != -1 ) { + if ( difftime(sb.st_ctime, min_time) < 0 || min_time == 0 ){ + min_time = sb.st_ctime; + if ( oldest_autosave ) { + g_free(oldest_autosave); + } + oldest_autosave = g_strdup(full_path); } - oldest_autosave = g_strdup(full_path); + count ++; } - count ++; } g_free(full_path); } diff --git a/src/io/sys.cpp b/src/io/sys.cpp index 60e850c96..94175176a 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -227,8 +227,10 @@ bool Inkscape::IO::file_is_writable( char const *utf8name) } if ( filename ) { struct stat st; - if(g_lstat (filename, &st) == 0) { - success = ((st.st_mode & S_IWRITE) != 0); + if (g_file_test (filename, G_FILE_TEST_EXISTS)){ + if (g_lstat (filename, &st) == 0) { + success = ((st.st_mode & S_IWRITE) != 0); + } } g_free(filename); filename = NULL; diff --git a/src/main.cpp b/src/main.cpp index 58ab19616..5bb42d405 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -135,6 +135,7 @@ enum { SP_ARG_EXPORT_AREA, SP_ARG_EXPORT_AREA_DRAWING, SP_ARG_EXPORT_AREA_PAGE, + SP_ARG_EXPORT_MARGIN, SP_ARG_EXPORT_AREA_SNAP, SP_ARG_EXPORT_WIDTH, SP_ARG_EXPORT_HEIGHT, @@ -186,6 +187,7 @@ static gchar *sp_export_dpi = NULL; static gchar *sp_export_area = NULL; static gboolean sp_export_area_drawing = FALSE; static gboolean sp_export_area_page = FALSE; +static gchar *sp_export_margin = NULL; static gboolean sp_export_latex = FALSE; static gchar *sp_export_width = NULL; static gchar *sp_export_height = NULL; @@ -229,6 +231,7 @@ static void resetCommandlineGlobals() { sp_export_area = NULL; sp_export_area_drawing = FALSE; sp_export_area_page = FALSE; + sp_export_margin = NULL; sp_export_latex = FALSE; sp_export_width = NULL; sp_export_height = NULL; @@ -316,6 +319,11 @@ struct poptOption options[] = { N_("Exported area is the entire page"), NULL}, + {"export-margin", 0, + POPT_ARG_STRING, &sp_export_margin, SP_ARG_EXPORT_MARGIN, + N_("Only for PS/EPS/PDF, sets margin in mm around exported area (default 0)"), + N_("VALUE")}, + {"export-area-snap", 0, POPT_ARG_NONE, &sp_export_area_snap, SP_ARG_EXPORT_AREA_SNAP, N_("Snap the bitmap export area outwards to the nearest integer values (in SVG user units)"), @@ -1623,6 +1631,13 @@ static int do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime) (*i)->set_param_int("resolution", (int) dpi); } + // if no bleed/margin is given, set to 0 (otherwise it takes the value last used from the UI) + float margin = 0.; + if (sp_export_margin) { + margin = g_ascii_strtod(sp_export_margin, NULL); + } + (*i)->set_param_float("bleed", margin); + //check if specified directory exists if (!Inkscape::IO::file_directory_exists(uri)) { g_warning("File path \"%s\" includes directory that doesn't exist.\n", uri); diff --git a/src/sp-image.cpp b/src/sp-image.cpp index ce8879f70..dacea3417 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -417,8 +417,12 @@ GdkPixbuf* pixbuf_new_from_file( const char *filename, time_t &modTime, gchar*& pixPath = NULL; } + //test correctness of filename + if (!g_file_test (filename, G_FILE_TEST_EXISTS)){ + return NULL; + } struct stat stdir; - g_stat(filename, &stdir); + int val = g_stat(filename, &stdir); if (stdir.st_mode & S_IFDIR){ //filename is not correct: it is a directory name and hence further code can not return valid results return NULL; @@ -429,11 +433,11 @@ GdkPixbuf* pixbuf_new_from_file( const char *filename, time_t &modTime, gchar*& if ( fp ) { { - struct stat st; - memset(&st, 0, sizeof(st)); - int val = g_stat(filename, &st); + // struct stat st; + // memset(&st, 0, sizeof(st)); + // int val = g_stat(filename, &st); if ( !val ) { - modTime = st.st_mtime; + modTime = stdir.st_mtime;//st.st_mtime; pixPath = g_strdup(filename); } } @@ -1495,7 +1499,10 @@ void sp_image_refresh_if_outdated( SPImage* image ) struct stat st; memset(&st, 0, sizeof(st)); - int val = g_stat(image->pixPath, &st); + int val = 0; + if (g_file_test (image->pixPath, G_FILE_TEST_EXISTS)){ + val = g_stat(image->pixPath, &st); + } if ( !val ) { // stat call worked. Check time now if ( st.st_mtime != image->lastMod ) { diff --git a/src/style.cpp b/src/style.cpp index eef1c6ee5..ca89e6f65 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -313,27 +313,34 @@ static SPStyleEnum const enum_display[] = { }; static SPStyleEnum const enum_shape_rendering[] = { - {"auto", 0}, - {"optimizeSpeed", 0}, - {"crispEdges", 0}, - {"geometricPrecision", 0}, + {"auto", SP_CSS_SHAPE_RENDERING_AUTO}, + {"optimizeSpeed", SP_CSS_SHAPE_RENDERING_OPTIMIZESPEED}, + {"crispEdges", SP_CSS_SHAPE_RENDERING_CRISPEDGES}, + {"geometricPrecision", SP_CSS_SHAPE_RENDERING_GEOMETRICPRECISION}, {NULL, -1} }; static SPStyleEnum const enum_color_rendering[] = { - {"auto", 0}, - {"optimizeSpeed", 0}, - {"optimizeQuality", 0}, + {"auto", SP_CSS_COLOR_RENDERING_AUTO}, + {"optimizeSpeed", SP_CSS_COLOR_RENDERING_OPTIMIZESPEED}, + {"optimizeQuality", SP_CSS_COLOR_RENDERING_OPTIMIZEQUALITY}, {NULL, -1} }; -static SPStyleEnum const *const enum_image_rendering = enum_color_rendering; +static SPStyleEnum const enum_image_rendering[] = { + {"auto", SP_CSS_IMAGE_RENDERING_AUTO}, + {"optimizeSpeed", SP_CSS_IMAGE_RENDERING_OPTIMIZESPEED}, + {"optimizeQuality", SP_CSS_IMAGE_RENDERING_OPTIMIZEQUALITY}, + {"-inkscape-crisp-edges", SP_CSS_IMAGE_RENDERING_CRISPEDGES}, + {"-inkscape-pixelated", SP_CSS_IMAGE_RENDERING_PIXELATED}, + {NULL, -1} +}; static SPStyleEnum const enum_text_rendering[] = { - {"auto", 0}, - {"optimizeSpeed", 0}, - {"optimizeLegibility", 0}, - {"geometricPrecision", 0}, + {"auto", SP_CSS_TEXT_RENDERING_AUTO}, + {"optimizeSpeed", SP_CSS_TEXT_RENDERING_OPTIMIZESPEED}, + {"optimizeLegibility", SP_CSS_TEXT_RENDERING_OPTIMIZELEGIBILITY}, + {"geometricPrecision", SP_CSS_TEXT_RENDERING_GEOMETRICPRECISION}, {NULL, -1} }; @@ -795,6 +802,12 @@ sp_style_read(SPStyle *style, SPObject *object, Inkscape::XML::Node *repr) /* clip-rule */ SPS_READ_PENUM_IF_UNSET(&style->clip_rule, repr, "clip-rule", enum_clip_rule, true); + /* color_rendering, image_rendering, shape_rendering, text_rendering */ + SPS_READ_PENUM_IF_UNSET(&style->color_rendering, repr, "color_rendering", enum_color_rendering, true); + SPS_READ_PENUM_IF_UNSET(&style->image_rendering, repr, "image_rendering", enum_image_rendering, true); + SPS_READ_PENUM_IF_UNSET(&style->shape_rendering, repr, "shape_rendering", enum_shape_rendering, true); + SPS_READ_PENUM_IF_UNSET(&style->text_rendering, repr, "text_rendering", enum_text_rendering, true); + /* 3. Merge from parent */ if (object) { if (object->parent) { @@ -1115,11 +1128,8 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) case SP_PROP_BASELINE_SHIFT: SPS_READ_IBASELINE_SHIFT_IF_UNSET(&style->baseline_shift, val); break; - /* Text (unimplemented) */ case SP_PROP_TEXT_RENDERING: { - /* Ignore the hint. */ - SPIEnum dummy; - SPS_READ_IENUM_IF_UNSET(&dummy, val, enum_text_rendering, true); + SPS_READ_IENUM_IF_UNSET(&style->text_rendering, val, enum_text_rendering, true); break; } case SP_PROP_ALIGNMENT_BASELINE: @@ -1240,9 +1250,7 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) g_warning("Unimplemented style property SP_PROP_COLOR_PROFILE: value: %s", val); break; case SP_PROP_COLOR_RENDERING: { - /* Ignore the hint. */ - SPIEnum dummy; - SPS_READ_IENUM_IF_UNSET(&dummy, val, enum_color_rendering, true); + SPS_READ_IENUM_IF_UNSET(&style->color_rendering, val, enum_color_rendering, true); break; } case SP_PROP_FILL: @@ -1261,9 +1269,7 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) } break; case SP_PROP_IMAGE_RENDERING: { - /* Ignore the hint. */ - SPIEnum dummy; - SPS_READ_IENUM_IF_UNSET(&dummy, val, enum_image_rendering, true); + SPS_READ_IENUM_IF_UNSET(&style->image_rendering, val, enum_image_rendering, true); break; } case SP_PROP_MARKER: @@ -1306,9 +1312,7 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) break; case SP_PROP_SHAPE_RENDERING: { - /* Ignore the hint. */ - SPIEnum dummy; - SPS_READ_IENUM_IF_UNSET(&dummy, val, enum_shape_rendering, true); + SPS_READ_IENUM_IF_UNSET(&style->shape_rendering, val, enum_shape_rendering, true); break; } @@ -1834,6 +1838,12 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent) if (!style->clip_rule.set || style->clip_rule.inherit) { style->clip_rule.computed = parent->clip_rule.computed; } + + /* Rendering */ + if (!style->color_rendering.set || style->color_rendering.inherit) { + style->color_rendering.computed = parent->color_rendering.computed; + } + } template <typename T> @@ -2126,18 +2136,18 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare &SPStyle::clip_rule, &SPStyle::color_interpolation, &SPStyle::color_interpolation_filters, - //nyi: SPStyle::color_rendering, + &SPStyle::color_rendering, &SPStyle::direction, &SPStyle::fill_rule, &SPStyle::font_style, &SPStyle::font_variant, - //nyi: SPStyle::image_rendering, + &SPStyle::image_rendering, //nyi: SPStyle::pointer_events, - //nyi: SPStyle::shape_rendering, + &SPStyle::shape_rendering, &SPStyle::stroke_linecap, &SPStyle::stroke_linejoin, &SPStyle::text_anchor, - //nyi: &SPStyle::text_rendering, + &SPStyle::text_rendering, &SPStyle::visibility, &SPStyle::writing_mode }; @@ -2742,6 +2752,12 @@ sp_style_write_string(SPStyle const *const style, guint const flags) /* clipping */ p += sp_style_write_ienum(p, c + BMAX - p, "clip-rule", enum_clip_rule, &style->clip_rule, NULL, flags); + /* rendering */ + p += sp_style_write_ienum(p, c + BMAX - p, "color-rendering", enum_color_rendering, &style->color_rendering, NULL, flags); + p += sp_style_write_ienum(p, c + BMAX - p, "image-rendering", enum_image_rendering, &style->image_rendering, NULL, flags); + p += sp_style_write_ienum(p, c + BMAX - p, "shape-rendering", enum_shape_rendering, &style->shape_rendering, NULL, flags); + p += sp_style_write_ienum(p, c + BMAX - p, "text-rendering", enum_text_rendering, &style->text_rendering, NULL, flags); + /* fixme: */ p += sp_text_style_write(p, c + BMAX - p, style->text, flags); @@ -2892,6 +2908,12 @@ sp_style_write_difference(SPStyle const *const from, SPStyle const *const to) p += sp_style_write_ienum(p, c + BMAX - p, "clip-rule", enum_clip_rule, &from->clip_rule, &to->clip_rule, SP_STYLE_FLAG_IFDIFF); + /* rendering */ + p += sp_style_write_ienum(p, c + BMAX - p, "color-rendering", enum_color_rendering, &from->color_rendering, &to->color_rendering, SP_STYLE_FLAG_IFDIFF); + p += sp_style_write_ienum(p, c + BMAX - p, "image-rendering", enum_image_rendering, &from->image_rendering, &to->image_rendering, SP_STYLE_FLAG_IFDIFF); + p += sp_style_write_ienum(p, c + BMAX - p, "shape-rendering", enum_shape_rendering, &from->shape_rendering, &to->shape_rendering, SP_STYLE_FLAG_IFDIFF); + p += sp_style_write_ienum(p, c + BMAX - p, "text-rendering", enum_text_rendering, &from->text_rendering, &to->text_rendering, SP_STYLE_FLAG_IFDIFF); + /** \todo * The reason we use IFSET rather than IFDIFF is the belief that the IFDIFF * flag is mainly only for attributes that don't handle explicit unset well. @@ -3087,6 +3109,12 @@ sp_style_clear(SPStyle *style) style->enable_background.inherit = false; style->clip_rule.value = style->clip_rule.computed = SP_WIND_RULE_NONZERO; + + style->color_rendering.value = style->color_rendering.computed = SP_CSS_COLOR_RENDERING_AUTO; + style->image_rendering.value = style->image_rendering.computed = SP_CSS_IMAGE_RENDERING_AUTO; + style->shape_rendering.value = style->shape_rendering.computed = SP_CSS_SHAPE_RENDERING_AUTO; + style->text_rendering.value = style->text_rendering.computed = SP_CSS_TEXT_RENDERING_AUTO; + } @@ -4492,6 +4520,18 @@ sp_style_unset_property_attrs(SPObject *o) if (style->clip_rule.set) { repr->setAttribute("clip-rule", NULL); } + if (style->color_rendering.set) { + repr->setAttribute("color-rendering", NULL); + } + if (style->image_rendering.set) { + repr->setAttribute("image-rendering", NULL); + } + if (style->shape_rendering.set) { + repr->setAttribute("shape-rendering", NULL); + } + if (style->text_rendering.set) { + repr->setAttribute("text-rendering", NULL); + } } /** diff --git a/src/style.h b/src/style.h index cb5178b40..360d502be 100644 --- a/src/style.h +++ b/src/style.h @@ -383,6 +383,13 @@ struct SPStyle { filter when the style is used for querying */ SPILength filter_gaussianBlur_deviation; + /** hints on how to render: e.g. speed vs. accuracy. + * As of April, 2013, only image_rendering used. */ + SPIEnum color_rendering; + SPIEnum image_rendering; + SPIEnum shape_rendering; + SPIEnum text_rendering; + /** enable-background, used for defining where filter effects get * their background image */ SPIEnum enable_background; @@ -584,6 +591,35 @@ enum SPColorInterpolation { SP_CSS_COLOR_INTERPOLATION_LINEARRGB }; +enum SPColorRendering { + SP_CSS_COLOR_RENDERING_AUTO, + SP_CSS_COLOR_RENDERING_OPTIMIZESPEED, + SP_CSS_COLOR_RENDERING_OPTIMIZEQUALITY +}; + +/* Last two are CSS4 Image values... for the momement prefaced with -inkscape. */ +enum SPImageRendering { + SP_CSS_IMAGE_RENDERING_AUTO, + SP_CSS_IMAGE_RENDERING_OPTIMIZESPEED, + SP_CSS_IMAGE_RENDERING_OPTIMIZEQUALITY, + SP_CSS_IMAGE_RENDERING_CRISPEDGES, + SP_CSS_IMAGE_RENDERING_PIXELATED +}; + +enum SPShapeRendering { + SP_CSS_SHAPE_RENDERING_AUTO, + SP_CSS_SHAPE_RENDERING_OPTIMIZESPEED, + SP_CSS_SHAPE_RENDERING_CRISPEDGES, + SP_CSS_SHAPE_RENDERING_GEOMETRICPRECISION +}; + +enum SPTextRendering { + SP_CSS_TEXT_RENDERING_AUTO, + SP_CSS_TEXT_RENDERING_OPTIMIZESPEED, + SP_CSS_TEXT_RENDERING_OPTIMIZELEGIBILITY, + SP_CSS_TEXT_RENDERING_GEOMETRICPRECISION +}; + /// An SPTextStyle has a refcount, a font family, and a font name. struct SPTextStyle { int refcount; diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 5808d7d21..fdc9cecc3 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -529,7 +529,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName); gchar *fName = const_cast<gchar *>(fileNameUtf8.c_str()); struct stat info; - if (g_stat(fName, &info)) + if (g_file_test (fName, G_FILE_TEST_EXISTS) && g_stat(fName, &info)) { g_warning("SVGPreview::set() : %s : %s", fName, strerror(errno)); diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index 8df3ee5c8..9fa94ca8f 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -11,6 +11,7 @@ #endif #include <gtkmm/messagedialog.h> +#include <gtkmm/checkbutton.h> #include <gtkmm/scrolledwindow.h> #include <gtkmm/textview.h> diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index c87e94fc6..9f3294275 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -59,7 +59,7 @@ extern "C" { #include <glibmm/i18n.h> #include <glibmm/markup.h> #include "unit-constants.h" - +#include "sp-textpath.h" namespace Inkscape { namespace UI { @@ -133,6 +133,30 @@ TextEdit::TextEdit() layout_frame.set_padding(4,4,4,4); layout_frame.add(layout_hbox); + // Text start Offset + { + startOffset = gtk_combo_box_text_new_with_entry (); + gtk_widget_set_size_request(startOffset, 90, -1); + + const gchar *spacings[] = {"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%", NULL}; + for (int i = 0; spacings[i]; i++) { + gtk_combo_box_text_append_text(reinterpret_cast<GtkComboBoxText *>(startOffset), spacings[i]); + } + gtk_entry_set_text(reinterpret_cast<GtkEntry *>(gtk_bin_get_child(reinterpret_cast<GtkBin *>(startOffset))), "0%"); + + gtk_widget_set_tooltip_text(startOffset, _("Text path offset")); + +#if WITH_GTKMM_3_0 + Gtk::Separator *sep = Gtk::manage(new Gtk::Separator()); + sep->set_orientation(Gtk::ORIENTATION_VERTICAL); +#else + Gtk::VSeparator *sep = Gtk::manage(new Gtk::VSeparator); +#endif + layout_hbox.pack_start(*sep, false, false, 10); + + layout_hbox.pack_start(*Gtk::manage(Glib::wrap(startOffset)), false, false); + } + /* Font preview */ preview_label.set_ellipsize(Pango::ELLIPSIZE_END); preview_label.set_justify(Gtk::JUSTIFY_CENTER); @@ -189,6 +213,7 @@ TextEdit::TextEdit() g_signal_connect ( G_OBJECT (fontsel), "font_set", G_CALLBACK (onFontChange), this ); g_signal_connect ( G_OBJECT (spacing_combo), "changed", G_CALLBACK (onLineSpacingChange), this ); g_signal_connect ( G_OBJECT (text_buffer), "changed", G_CALLBACK (onTextChange), this ); + g_signal_connect(startOffset, "changed", G_CALLBACK(onStartOffsetChange), this); setasdefault_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onSetDefault)); apply_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onApply)); close_button.signal_clicked().connect(sigc::bind(_signal_response.make_slot(), GTK_RESPONSE_CLOSE)); @@ -263,8 +288,16 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ ) guint items = getSelectedTextCount (); if (items == 1) { gtk_widget_set_sensitive (text_view, TRUE); + gtk_widget_set_sensitive( startOffset, SP_IS_TEXT_TEXTPATH(text) ); + if (SP_IS_TEXT_TEXTPATH(text)) { + SPTextPath *tp = SP_TEXTPATH(text->firstChild()); + if (tp->getAttribute("startOffset")) { + gtk_entry_set_text(reinterpret_cast<GtkEntry *>(gtk_bin_get_child(reinterpret_cast<GtkBin *>(startOffset))), tp->getAttribute("startOffset")); + } + } } else { gtk_widget_set_sensitive (text_view, FALSE); + gtk_widget_set_sensitive( startOffset, FALSE ); } apply_button.set_sensitive ( false ); setasdefault_button.set_sensitive ( true ); @@ -286,6 +319,7 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ ) text->getRepr(); // was being called but result ignored. Check this. } else { gtk_widget_set_sensitive (text_view, FALSE); + gtk_widget_set_sensitive( startOffset, FALSE ); apply_button.set_sensitive ( false ); setasdefault_button.set_sensitive ( false ); } @@ -616,6 +650,19 @@ void TextEdit::onFontChange(SPFontSelector * /*fontsel*/, gchar* fontspec, TextE } +void TextEdit::onStartOffsetChange(GtkTextBuffer *text_buffer, TextEdit *self) +{ + SPItem *text = self->getSelectedTextItem(); + if (text && SP_IS_TEXT_TEXTPATH(text)) + { + SPTextPath *tp = SP_TEXTPATH(text->firstChild()); + const gchar *sstr = gtk_combo_box_text_get_active_text(reinterpret_cast<GtkComboBoxText *>(self->startOffset)); + tp->setAttribute("startOffset", sstr); + + DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "startOffset", SP_VERB_CONTEXT_TEXT, _("Set text style")); + } +} + void TextEdit::onToggle() { if (blocked) @@ -628,7 +675,6 @@ void TextEdit::onToggle() //onApply(); } setasdefault_button.set_sensitive ( true ); - } diff --git a/src/ui/dialog/text-edit.h b/src/ui/dialog/text-edit.h index f27fdfc87..0e3ebafa7 100644 --- a/src/ui/dialog/text-edit.h +++ b/src/ui/dialog/text-edit.h @@ -107,6 +107,14 @@ protected: static void onFontChange (SPFontSelector *fontsel, gchar* fontspec, TextEdit *self); /** + * Callback invoked when the user modifies the startOffset of text on a path. + * + * @param text_buffer pointer to the GtkTextBuffer with the text of the selected text object. + * @param self pointer to the current instance of the dialog. + */ + static void onStartOffsetChange(GtkTextBuffer *text_buffer, TextEdit *self); + + /** * Get the selected text off the main canvas. * * @return SPItem pointer to the selected text object @@ -191,6 +199,8 @@ private: GtkWidget *spacing_combo; + GtkWidget *startOffset; + Gtk::Label preview_label; Gtk::Label text_label; diff --git a/src/ui/widget/imageicon.cpp b/src/ui/widget/imageicon.cpp index 1c36dc36e..cf41a16a4 100644 --- a/src/ui/widget/imageicon.cpp +++ b/src/ui/widget/imageicon.cpp @@ -382,7 +382,7 @@ bool ImageIcon::show(const Glib::ustring &fileName) if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { struct stat info; - if (stat(fName, &info)) + if (g_file_test (fName, G_FILE_TEST_EXISTS) && stat(fName, &info)) { Glib::ustring err = "cannot get file info"; showBrokenImage(err); diff --git a/src/xml/repr.h b/src/xml/repr.h index 52f07d11f..e691eaa7f 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -98,9 +98,11 @@ void sp_repr_css_print(SPCSSAttr *css); /* Utility finctions */ /// Remove \a repr from children of its parent node. inline void sp_repr_unparent(Inkscape::XML::Node *repr) { - Inkscape::XML::Node *parent=repr->parent(); - if (parent) { - parent->removeChild(repr); + if (repr) { + Inkscape::XML::Node *parent=repr->parent(); + if (parent) { + parent->removeChild(repr); + } } } |
