From 2607adab8dd0fdecdc5dcf13073078b58407d5b0 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Tue, 11 Feb 2014 14:37:29 +0100 Subject: suppress compiler warnings (bzr r13021) --- src/marker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/marker.cpp b/src/marker.cpp index 900f8a2ca..fb7b0fd21 100644 --- a/src/marker.cpp +++ b/src/marker.cpp @@ -282,7 +282,7 @@ Inkscape::XML::Node* SPMarker::write(Inkscape::XML::Document *xml_doc, Inkscape: return repr; } -Inkscape::DrawingItem* SPMarker::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { +Inkscape::DrawingItem* SPMarker::show(Inkscape::Drawing &/*drawing*/, unsigned int /*key*/, unsigned int /*flags*/) { // Markers in tree are never shown directly even if outside of . return 0; } -- cgit v1.2.3 From 9e9db3f8ec260992295cc85ce1e7da52ba725ba4 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Tue, 11 Feb 2014 14:39:37 +0100 Subject: fix compiler warnings (bug #1278049 ) (bzr r13022) --- src/libnrtype/Layout-TNG-Output.cpp | 46 ++++++++++++------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index 149f600b7..77534e706 100644 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -538,17 +538,10 @@ Glib::ustring Layout::getFontFamily(unsigned span_index) const Glib::ustring Layout::dumpAsText() const { Glib::ustring result; - char line[256]; - Glib::ustring::const_iterator icc; + char line[256]; - snprintf(line, sizeof(line), "spans %zu\n", _spans.size()); - result += line; - snprintf(line, sizeof(line), "chars %zu\n", _characters.size()); - result += line; - snprintf(line, sizeof(line), "glyphs %zu\n", _glyphs.size()); - result += line; - + result = Glib::ustring::compose("spans %1\nchars %2\nglyphs %3\n", _spans.size(), _characters.size(), _glyphs.size()); if(_characters.size() > 1){ unsigned lastspan=5000; for(unsigned j = 0; j < _characters.size() ; j++){ @@ -570,32 +563,23 @@ Glib::ustring Layout::dumpAsText() const } for (unsigned span_index = 0 ; span_index < _spans.size() ; span_index++) { - snprintf(line, sizeof(line), "==== span %u \n", span_index); - result += line; - snprintf(line, sizeof(line), " in para %d (direction=%s)\n", _lines[_chunks[_spans[span_index].in_chunk].in_line].in_paragraph, - direction_to_text(_paragraphs[_lines[_chunks[_spans[span_index].in_chunk].in_line].in_paragraph].base_direction)); - result += line; - snprintf(line, sizeof(line), " in source %d (type=%d, cookie=%p)\n", _spans[span_index].in_input_stream_item, + result += Glib::ustring::compose("==== span %1 \n", span_index) + + Glib::ustring::compose(" in para %1 (direction=%2)\n", _lines[_chunks[_spans[span_index].in_chunk].in_line].in_paragraph, + direction_to_text(_paragraphs[_lines[_chunks[_spans[span_index].in_chunk].in_line].in_paragraph].base_direction)) + + Glib::ustring::compose(" in source %1 (type=%2, cookie=%3)\n", _spans[span_index].in_input_stream_item, _input_stream[_spans[span_index].in_input_stream_item]->Type(), - _input_stream[_spans[span_index].in_input_stream_item]->source_cookie); - result += line; - snprintf(line, sizeof(line), " in line %d (baseline=%f, shape=%d)\n", _chunks[_spans[span_index].in_chunk].in_line, + _input_stream[_spans[span_index].in_input_stream_item]->source_cookie) + + Glib::ustring::compose(" in line %1 (baseline=%2, shape=%3)\n", _chunks[_spans[span_index].in_chunk].in_line, _lines[_chunks[_spans[span_index].in_chunk].in_line].baseline_y, - _lines[_chunks[_spans[span_index].in_chunk].in_line].in_shape); - result += line; - snprintf(line, sizeof(line), " in chunk %d (x=%f, baselineshift=%f)\n", _spans[span_index].in_chunk, _chunks[_spans[span_index].in_chunk].left_x, _spans[span_index].baseline_shift); - result += line; + _lines[_chunks[_spans[span_index].in_chunk].in_line].in_shape) + + Glib::ustring::compose(" in chunk %1 (x=%2, baselineshift=%3)\n", _spans[span_index].in_chunk, _chunks[_spans[span_index].in_chunk].left_x, _spans[span_index].baseline_shift); if (_spans[span_index].font) { - snprintf(line, sizeof(line), " font '%s' %f %s %s\n", sp_font_description_get_family(_spans[span_index].font->descr), _spans[span_index].font_size, style_to_text(pango_font_description_get_style(_spans[span_index].font->descr)), weight_to_text(pango_font_description_get_weight(_spans[span_index].font->descr))); - result += line; + result += Glib::ustring::compose(" font '%1' %2 %3 %4\n", sp_font_description_get_family(_spans[span_index].font->descr), _spans[span_index].font_size, style_to_text(pango_font_description_get_style(_spans[span_index].font->descr)), weight_to_text(pango_font_description_get_weight(_spans[span_index].font->descr))); } - snprintf(line, sizeof(line), " x_start = %f, x_end = %f\n", _spans[span_index].x_start, _spans[span_index].x_end); - result += line; - snprintf(line, sizeof(line), " line height: ascent %f, descent %f leading %f\n", _spans[span_index].line_height.ascent, _spans[span_index].line_height.descent, _spans[span_index].line_height.leading); - result += line; - snprintf(line, sizeof(line), " direction %s, block-progression %s\n", direction_to_text(_spans[span_index].direction), direction_to_text(_spans[span_index].block_progression)); - result += line; - result += " ** characters:\n"; + result += Glib::ustring::compose(" x_start = %1, x_end = %2\n", _spans[span_index].x_start, _spans[span_index].x_end) + + Glib::ustring::compose(" line height: ascent %1, descent %2 leading %3\n", _spans[span_index].line_height.ascent, _spans[span_index].line_height.descent, _spans[span_index].line_height.leading) + + Glib::ustring::compose(" direction %1, block-progression %2\n", direction_to_text(_spans[span_index].direction), direction_to_text(_spans[span_index].block_progression)) + + " ** characters:\n"; Glib::ustring::const_iterator iter_char = _spans[span_index].input_stream_first_character; // very inefficent code. what the hell, it's only debug stuff. for (unsigned char_index = 0 ; char_index < _characters.size() ; char_index++) { -- cgit v1.2.3 From 1f8800625995b03d29fc3e642f788581c93a874d Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 11 Feb 2014 14:56:11 +0100 Subject: Set 'preserveAspectRatio' to 'none' for PDF image input. Fixes #878984. (bzr r13023) --- src/extension/internal/pdfinput/svg-builder.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index b3f15bbff..20cd74cdb 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -1657,6 +1657,10 @@ Inkscape::XML::Node *SvgBuilder::_createImage(Stream *str, int width, int height Inkscape::XML::Node *image_node = _xml_doc->createElement("svg:image"); sp_repr_set_svg_double(image_node, "width", 1); sp_repr_set_svg_double(image_node, "height", 1); + + // PS/PDF images are placed via a transformation matrix, no preserveAspectRatio used + image_node->setAttribute("preserveAspectRatio", "none"); + // Set transformation svgSetTransform(image_node, 1.0, 0.0, 0.0, -1.0, 0.0, 1.0); -- cgit v1.2.3 From f916cedef78aa80afeacae86da4e657591042859 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 11 Feb 2014 17:36:20 +0100 Subject: Fix for Bug #1248542 (fix for filters.svg) by v1nce. Fixed bugs: - https://launchpad.net/bugs/1248542 (bzr r13024) --- share/filters/filters.svg | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/share/filters/filters.svg b/share/filters/filters.svg index e617d3241..6a5a8afea 100644 --- a/share/filters/filters.svg +++ b/share/filters/filters.svg @@ -419,7 +419,7 @@ sodipodi:docname="filters.svg"> - + @@ -450,7 +450,7 @@ sodipodi:docname="filters.svg"> - + @@ -756,14 +756,12 @@ sodipodi:docname="filters.svg"> - - @@ -776,14 +774,12 @@ sodipodi:docname="filters.svg"> - - @@ -999,7 +995,6 @@ sodipodi:docname="filters.svg"> - @@ -1701,7 +1696,6 @@ sodipodi:docname="filters.svg"> - @@ -1769,7 +1763,9 @@ sodipodi:docname="filters.svg"> + @@ -1952,11 +1948,6 @@ sodipodi:docname="filters.svg"> - - - - - @@ -2103,7 +2094,7 @@ sodipodi:docname="filters.svg"> - + @@ -2129,7 +2120,6 @@ sodipodi:docname="filters.svg"> - @@ -2225,7 +2215,6 @@ sodipodi:docname="filters.svg"> - @@ -2249,7 +2238,6 @@ sodipodi:docname="filters.svg"> - @@ -2261,7 +2249,6 @@ sodipodi:docname="filters.svg"> - @@ -2285,7 +2272,6 @@ sodipodi:docname="filters.svg"> - @@ -2297,7 +2283,6 @@ sodipodi:docname="filters.svg"> - @@ -2309,7 +2294,6 @@ sodipodi:docname="filters.svg"> - @@ -2497,7 +2481,6 @@ sodipodi:docname="filters.svg"> - -- cgit v1.2.3 From e24b23c1189ab152ba877593e268b2cac1524903 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 12 Feb 2014 13:12:39 +0100 Subject: Set bitmap upscaling preference in Cairo based PS and PDF output. (bzr r13025) --- src/extension/internal/cairo-render-context.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index 47de62ac0..2916d9fa9 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -1433,7 +1433,7 @@ CairoRenderContext::renderPathVector(Geom::PathVector const & pathv, SPStyle con } bool CairoRenderContext::renderImage(Inkscape::Pixbuf *pb, - Geom::Affine const &image_transform, SPStyle const * /*style*/) + Geom::Affine const &image_transform, SPStyle const *style) { g_assert( _is_valid ); @@ -1468,6 +1468,27 @@ bool CairoRenderContext::renderImage(Inkscape::Pixbuf *pb, cairo_rectangle(_cr, 0, 0, w, h); cairo_clip(_cr); } + + // Cairo filter method will be mapped to PS/PDF 'interpolate' true/false). + // See cairo-pdf-surface.c + if (style) { + // See: http://www.w3.org/TR/SVG/painting.html#ImageRenderingProperty + // http://www.w3.org/TR/css4-images/#the-image-rendering + // style.h/style.cpp + switch (style->image_rendering.computed) { + case SP_CSS_COLOR_RENDERING_AUTO: + // Do nothing + break; + case SP_CSS_COLOR_RENDERING_OPTIMIZEQUALITY: + cairo_pattern_set_filter(cairo_get_source(_cr), CAIRO_FILTER_BEST ); + break; + case SP_CSS_COLOR_RENDERING_OPTIMIZESPEED: + default: + cairo_pattern_set_filter(cairo_get_source(_cr), CAIRO_FILTER_NEAREST ); + break; + } + } + cairo_paint_with_alpha(_cr, opacity); cairo_restore(_cr); -- cgit v1.2.3 From 53428979fabc03e257dbf31b98bb7be98ada3764 Mon Sep 17 00:00:00 2001 From: su_v Date: Wed, 12 Feb 2014 17:30:16 +0100 Subject: Image import dialog: add dpi option (from file or default), use compacter layout (help as tooltips) Fixed bugs: - https://launchpad.net/bugs/1253051 (bzr r13026) --- src/extension/internal/gdkpixbuf-input.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp index ec04b1dad..a384c7bde 100644 --- a/src/extension/internal/gdkpixbuf-input.cpp +++ b/src/extension/internal/gdkpixbuf-input.cpp @@ -30,22 +30,31 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool ask = prefs->getBool("/dialogs/import/ask"); Glib::ustring link = prefs->getString("/dialogs/import/link"); + bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi"); Glib::ustring scale = prefs->getString("/dialogs/import/scale"); // std::cout << "GkdpixbufInput::open: " // << " ask: " << ask // << ", link: " << link + // << ", forcexdpi: " << forcexdpi // << ", scale: " << scale << std::endl; // std::cout << " in preferences: " // << " ask: " << !mod->get_param_bool("do_not_ask") // << ", link: " << mod->get_param_optiongroup("link") + // << ", mod_dpi: " << mod->get_param_optiongroup("dpi") // << ", scale: " << mod->get_param_optiongroup("scale") << std::endl; if( ask ) { Glib::ustring mod_link = mod->get_param_optiongroup("link"); + Glib::ustring mod_dpi = mod->get_param_optiongroup("dpi"); + bool mod_forcexdpi = ( mod_dpi.compare( "from_default" ) == 0 ); Glib::ustring mod_scale = mod->get_param_optiongroup("scale"); if( link.compare( mod_link ) != 0 ) { link = mod_link; } prefs->setString("/dialogs/import/link", link ); + if( forcexdpi != mod_forcexdpi ) { + forcexdpi = mod_forcexdpi; + } + prefs->setBool("/dialogs/import/forcexdpi", forcexdpi ); if( scale.compare( mod_scale ) != 0 ) { scale = mod_scale; } @@ -68,7 +77,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) double width = pb->width(); double height = pb->height(); double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", Inkscape::Util::Quantity::convert(1, "in", "px")); - bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi"); + //bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi"); ImageResolution *ir = 0; double xscale = 1; double yscale = 1; @@ -179,18 +188,21 @@ GdkpixbufInput::init(void) "%s\n" "org.inkscape.input.gdkpixbuf.%s\n" - "\n" + "\n" "<_option value='embed' >" N_("Embed") "\n" "<_option value='link' >" N_("Link") "\n" "\n" - "<_param name='help' type='description'>" N_("Embed results in stand-alone, larger SVG files. Link references a file outside this SVG document and all files must be moved together.") "\n" - "\n" + "\n" + "<_option value='from_file' >" N_("From file") "\n" + "<_option value='from_default' >" N_("Default import resolution") "\n" + "\n" + + "\n" "<_option value='auto' >" N_("None (auto)") "\n" "<_option value='optimizeQuality' >" N_("Smooth (optimizeQuality)") "\n" "<_option value='optimizeSpeed' >" N_("Blocky (optimizeSpeed)") "\n" "\n" - "<_param name='help' type='description'>" N_("When an image is upscaled, apply smoothing or keep blocky (pixelated). (Will not work in all browsers.)") "\n" "false\n" "\n" -- cgit v1.2.3 From 2c55b62c81f6c4e5f3619088a1378f298b47c60f Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Thu, 13 Feb 2014 17:58:46 -0500 Subject: extensions. ink2canvas.py. pass reference to self (Bug 1258473) Fixed bugs: - https://launchpad.net/bugs/1258473 (bzr r13027) --- share/extensions/ink2canvas.py | 2 +- share/extensions/ink2canvas/canvas.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/share/extensions/ink2canvas.py b/share/extensions/ink2canvas.py index 51b75d846..d1e11a7c2 100755 --- a/share/extensions/ink2canvas.py +++ b/share/extensions/ink2canvas.py @@ -80,7 +80,7 @@ class Ink2Canvas(inkex.Effect): svg_root = self.document.getroot() width = self.unittouu(svg_root.get("width")) height = self.unittouu(svg_root.get("height")) - self.canvas = Canvas(width, height) + self.canvas = Canvas(self, width, height) self.walk_tree(svg_root) diff --git a/share/extensions/ink2canvas/canvas.py b/share/extensions/ink2canvas/canvas.py index 80ec4fd43..1f574a63e 100644 --- a/share/extensions/ink2canvas/canvas.py +++ b/share/extensions/ink2canvas/canvas.py @@ -23,11 +23,12 @@ import simplestyle class Canvas: """Canvas API helper class""" - def __init__(self, width, height, context = "ctx"): + def __init__(self, parent, width, height, context = "ctx"): self.obj = context self.code = [] #stores the code self.style = {} self.styleCache = {} #stores the previous style applied + self.parent = parent self.width = width self.height = height @@ -117,7 +118,7 @@ class Canvas: self.write("ctx.strokeStyle = %s;" % self.getColor(value, alpha)) def setStrokeWidth(self, value): - self.write("ctx.lineWidth = %f;" % inkex.unittouu(value)) + self.write("ctx.lineWidth = %f;" % self.parent.unittouu(value)) def setStrokeLinecap(self, value): self.write("ctx.lineCap = '%s';" % value) -- cgit v1.2.3 From 098d591a3e183fa03f2f46da2afcabff709d8c49 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Fri, 14 Feb 2014 16:44:22 -0500 Subject: Extensions. Scaling of command-line bbox into document units, Part 4 (Bug 1240455) (bzr r13028) --- share/extensions/dimension.py | 21 +++++++++++---------- share/extensions/perspective.py | 5 +++-- share/extensions/printing_marks.py | 17 +++++++++-------- share/extensions/summersnight.py | 5 +++-- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/share/extensions/dimension.py b/share/extensions/dimension.py index 4285effeb..30b674201 100755 --- a/share/extensions/dimension.py +++ b/share/extensions/dimension.py @@ -100,8 +100,9 @@ class Dimension(pathmodifier.PathModifier): return line def effect(self): - self.xoffset = self.options.xoffset - self.yoffset = self.options.yoffset + scale = self.unittouu('1px') # convert to document units + self.xoffset = scale*self.options.xoffset + self.yoffset = scale*self.options.yoffset # query inkscape about the bounding box if len(self.options.ids) == 0: @@ -117,11 +118,11 @@ class Dimension(pathmodifier.PathModifier): if bsubprocess: p = Popen('inkscape --query-%s --query-id=%s "%s"' % (query,id,file), shell=True, stdout=PIPE, stderr=PIPE) rc = p.wait() - q[query] = float(p.stdout.read()) + q[query] = scale*float(p.stdout.read()) err = p.stderr.read() else: f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:] - q[query] = float(f.read()) + q[query] = scale*float(f.read()) f.close() err.close() self.bbox = (q['x'], q['x']+q['width'], q['y'], q['y']+q['height']) @@ -146,29 +147,29 @@ class Dimension(pathmodifier.PathModifier): line = self.dimHLine(self.bbox[2], [0, 1]) line.set('marker-start', 'url(#Arrow1Lstart)') line.set('marker-end', 'url(#Arrow1Lend)') - line.set('stroke-width', '1') + line.set('stroke-width', str(scale)) group.append(line) line = self.dimVLine(self.bbox[0], [0, 2]) - line.set('stroke-width', '0.5') + line.set('stroke-width', str(0.5*scale)) group.append(line) line = self.dimVLine(self.bbox[1], [0, 2]) - line.set('stroke-width', '0.5') + line.set('stroke-width', str(0.5*scale)) group.append(line) line = self.dimVLine(self.bbox[0], [1, 0]) line.set('marker-start', 'url(#Arrow1Lstart)') line.set('marker-end', 'url(#Arrow1Lend)') - line.set('stroke-width', '1') + line.set('stroke-width', str(scale)) group.append(line) line = self.dimHLine(self.bbox[2], [2, 0]) - line.set('stroke-width', '0.5') + line.set('stroke-width', str(0.5*scale)) group.append(line) line = self.dimHLine(self.bbox[3], [2, 0]) - line.set('stroke-width', '0.5') + line.set('stroke-width', str(0.5*scale)) group.append(line) for id, node in self.selected.iteritems(): diff --git a/share/extensions/perspective.py b/share/extensions/perspective.py index 8a0ffeb0b..044257ae8 100755 --- a/share/extensions/perspective.py +++ b/share/extensions/perspective.py @@ -54,6 +54,7 @@ class Project(inkex.Effect): exit() #obj is selected second + scale = self.unittouu('1px') # convert to document units obj = self.selected[self.options.ids[0]] envelope = self.selected[self.options.ids[1]] if obj.get(inkex.addNS('type','sodipodi')): @@ -80,11 +81,11 @@ class Project(inkex.Effect): if bsubprocess: p = Popen('inkscape --query-%s --query-id=%s "%s"' % (query,id,file), shell=True, stdout=PIPE, stderr=PIPE) rc = p.wait() - q[query] = float(p.stdout.read()) + q[query] = scale*float(p.stdout.read()) err = p.stderr.read() else: f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:] - q[query] = float(f.read()) + q[query] = scale*float(f.read()) f.close() err.close() sp = array([[q['x'], q['y']+q['height']],[q['x'], q['y']],[q['x']+q['width'], q['y']],[q['x']+q['width'], q['y']+q['height']]], dtype=float64) diff --git a/share/extensions/printing_marks.py b/share/extensions/printing_marks.py index 5c6ac3a61..0306048d6 100755 --- a/share/extensions/printing_marks.py +++ b/share/extensions/printing_marks.py @@ -191,20 +191,21 @@ class Printing_Marks (inkex.Effect): i += 0.1 def get_selection_area(self): + scale = self.unittouu('1px') # convert to document units sel_area = {} min_x, min_y, max_x, max_y = False, False, False, False for id in self.options.ids: sel_area[id] = {} for att in [ "x", "y", "width", "height" ]: args = [ "inkscape", "-I", id, "--query-"+att, self.svg_file ] - sel_area[id][att] = \ - Popen(args, stdout=PIPE, stderr=PIPE).communicate()[0] - current_min_x = float( sel_area[id]["x"] ) - current_min_y = float( sel_area[id]["y"] ) - current_max_x = float( sel_area[id]["x"] ) + \ - float( sel_area[id]["width"] ) - current_max_y = float( sel_area[id]["y"] ) + \ - float( sel_area[id]["height"] ) + sel_area[id][att] = scale* \ + float(Popen(args, stdout=PIPE, stderr=PIPE).communicate()[0]) + current_min_x = sel_area[id]["x"] + current_min_y = sel_area[id]["y"] + current_max_x = sel_area[id]["x"] + \ + sel_area[id]["width"] + current_max_y = sel_area[id]["y"] + \ + sel_area[id]["height"] if not min_x: min_x = current_min_x if not min_y: min_y = current_min_y if not max_x: max_x = current_max_x diff --git a/share/extensions/summersnight.py b/share/extensions/summersnight.py index aea5cea55..67413a05c 100755 --- a/share/extensions/summersnight.py +++ b/share/extensions/summersnight.py @@ -45,6 +45,7 @@ class Project(inkex.Effect): exit() #obj is selected second + scale = self.unittouu('1px') # convert to document units obj = self.selected[self.options.ids[0]] trafo = self.selected[self.options.ids[1]] if obj.get(inkex.addNS('type','sodipodi')): @@ -75,11 +76,11 @@ class Project(inkex.Effect): if bsubprocess: p = Popen('inkscape --query-%s --query-id=%s "%s"' % (query,id,file), shell=True, stdout=PIPE, stderr=PIPE) rc = p.wait() - self.q[query] = float(p.stdout.read()) + self.q[query] = scale*float(p.stdout.read()) err = p.stderr.read() else: f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:] - self.q[query] = float(f.read()) + self.q[query] = scale*float(f.read()) f.close() err.close() -- cgit v1.2.3 From 208354ea4b29ac7752120947efefcd7af3630d10 Mon Sep 17 00:00:00 2001 From: su_v Date: Sun, 16 Feb 2014 00:20:48 +0100 Subject: Symbols: turn off viewBox-related debug messages (from r13002) (bzr r13029) --- src/sp-symbol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sp-symbol.cpp b/src/sp-symbol.cpp index 817411a32..3156680b3 100644 --- a/src/sp-symbol.cpp +++ b/src/sp-symbol.cpp @@ -57,13 +57,13 @@ void SPSymbol::set(unsigned int key, const gchar* value) { switch (key) { case SP_ATTR_VIEWBOX: set_viewBox( value ); - std::cout << "Symbol: ViewBox: " << viewBox << std::endl; + // std::cout << "Symbol: ViewBox: " << viewBox << std::endl; this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); break; case SP_ATTR_PRESERVEASPECTRATIO: set_preserveAspectRatio( value ); - std::cout << "Symbol: Preserve aspect ratio: " << aspect_align << ", " << aspect_clip << std::endl; + // std::cout << "Symbol: Preserve aspect ratio: " << aspect_align << ", " << aspect_clip << std::endl; this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); break; -- cgit v1.2.3 From 7ed3c6cbcc209af64384bea1489398a28381a9ce Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sat, 15 Feb 2014 19:13:08 -0500 Subject: Extensions. Scaling of stroke and some sizes into document units, Part 5 (Bug 1240455) (bzr r13030) --- share/extensions/dots.py | 2 +- share/extensions/interp.py | 14 +++++++++----- share/extensions/voronoi2svg.py | 12 ++++++------ share/extensions/webslicer_create_rect.py | 9 +++++---- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/share/extensions/dots.py b/share/extensions/dots.py index 33ead21e7..dc533ffb6 100755 --- a/share/extensions/dots.py +++ b/share/extensions/dots.py @@ -112,7 +112,7 @@ class Dots(inkex.Effect): def addText(self,node,x,y,text): new = inkex.etree.SubElement(node,inkex.addNS('text','svg')) - s = {'font-size': self.options.fontsize, 'fill-opacity': '1.0', 'stroke': 'none', + s = {'font-size': self.unittouu(self.options.fontsize), 'fill-opacity': '1.0', 'stroke': 'none', 'font-weight': 'normal', 'font-style': 'normal', 'fill': '#999'} new.set('style', simplestyle.formatStyle(s)) new.set('x', str(x)) diff --git a/share/extensions/interp.py b/share/extensions/interp.py index c69dd4a73..459190c0e 100755 --- a/share/extensions/interp.py +++ b/share/extensions/interp.py @@ -60,10 +60,6 @@ def tweenstylefloat(property, start, end, time): sp = float(start[property]) ep = float(end[property]) return str(sp + (time * (ep - sp))) -def tweenstyleunit(property, start, end, time): - sp = self.unittouu(start[property]) - ep = self.unittouu(end[property]) - return str(sp + (time * (ep - sp))) def tweenstylecolor(property, start, end, time): sr,sg,sb = parsecolor(start[property]) er,eg,eb = parsecolor(end[property]) @@ -107,6 +103,12 @@ class Interp(inkex.Effect): action="store", type="inkbool", dest="style", default=True, help="try interpolation of some style properties") + + def tweenstyleunit(self, property, start, end, time): # moved here so we can call 'unittouu' + sp = self.unittouu(start[property]) + ep = self.unittouu(end[property]) + return str(sp + (time * (ep - sp))) + def effect(self): exponent = self.options.exponent if exponent>= 0: @@ -137,6 +139,8 @@ class Interp(inkex.Effect): sst = copy.deepcopy(styles[self.options.ids[i-1]]) est = copy.deepcopy(styles[self.options.ids[i]]) basestyle = copy.deepcopy(sst) + if basestyle.has_key('stroke-width'): + basestyle['stroke-width'] = self.tweenstyleunit('stroke-width',sst,est,0) #prepare for experimental style tweening if self.options.style: @@ -303,7 +307,7 @@ class Interp(inkex.Effect): basestyle['opacity'] = tweenstylefloat('opacity',sst,est,time) if dostroke: basestyle['stroke-opacity'] = tweenstylefloat('stroke-opacity',sst,est,time) - basestyle['stroke-width'] = tweenstyleunit('stroke-width',sst,est,time) + basestyle['stroke-width'] = self.tweenstyleunit('stroke-width',sst,est,time) basestyle['stroke'] = tweenstylecolor('stroke',sst,est,time) if dofill: basestyle['fill-opacity'] = tweenstylefloat('fill-opacity',sst,est,time) diff --git a/share/extensions/voronoi2svg.py b/share/extensions/voronoi2svg.py index c5b8a511f..289c352e3 100755 --- a/share/extensions/voronoi2svg.py +++ b/share/extensions/voronoi2svg.py @@ -220,15 +220,15 @@ class Voronoi2svg(inkex.Effect): #{{{ Drawing styles linestyle = { - 'stroke' : '#000000', - 'linewidth' : '1', - 'fill' : 'none' + 'stroke' : '#000000', + 'stroke-width' : str(self.unittouu('1px')), + 'fill' : 'none' } facestyle = { - 'stroke' : '#ff0000', - 'linewidth' : '1', - 'fill' : 'none' + 'stroke' : '#ff0000', + 'stroke-width' : str(self.unittouu('1px')), + 'fill' : 'none' } #}}} diff --git a/share/extensions/webslicer_create_rect.py b/share/extensions/webslicer_create_rect.py index 7c04e8706..b4e6858af 100755 --- a/share/extensions/webslicer_create_rect.py +++ b/share/extensions/webslicer_create_rect.py @@ -100,6 +100,7 @@ class WebSlicer_CreateRect(WebSlicer_Effect): self.options.dimension def effect(self): + scale = self.unittouu('1px') # convert to document units self.validate_options() layer = self.get_slicer_layer(True) #TODO: get selected elements to define location and size @@ -110,10 +111,10 @@ class WebSlicer_CreateRect(WebSlicer_Effect): rect.set('id', self.options.name) rect.set('fill', 'red') rect.set('opacity', '0.5') - rect.set('x', '-100') - rect.set('y', '-100') - rect.set('width', '200') - rect.set('height', '200') + rect.set('x', str(-scale*100)) + rect.set('y', str(-scale*100)) + rect.set('width', str(scale*200)) + rect.set('height', str(scale*200)) desc = inkex.etree.SubElement(rect, 'desc') conf_txt = "format:"+ self.options.format +"\n" if not is_empty(self.options.dpi): -- cgit v1.2.3 From c984c2542484ace0c54bab9e353f0c29a45f6023 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 16 Feb 2014 11:55:22 +0100 Subject: Fix console messages (see Bug #879058 - Spray Single Path Mode includes original object). Fixed bugs: - https://launchpad.net/bugs/879058 (bzr r13031) --- src/ui/tools/spray-tool.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 4ea482461..14a3acd9a 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -430,7 +430,6 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *parent_item = NULL; // Initial object SPItem *item_copied = NULL; // Projected object SPItem *unionResult = NULL; // Previous union - SPItem *child_item = NULL; // Parent copy int i=1; for (GSList *items = g_slist_copy(const_cast(selection->itemList())); @@ -453,21 +452,12 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::OptRect a = parent_item->documentVisualBounds(); if (a) { - if (i == 1) { - Inkscape::XML::Node *copy1 = old_repr->duplicate(xml_doc); - parent->appendChild(copy1); - SPObject *new_obj1 = doc->getObjectByRepr(copy1); - child_item = SP_ITEM(new_obj1); // Conversion object->item - unionResult = child_item; - Inkscape::GC::release(copy1); - } - if (_fid <= population) { // Rules the population of objects sprayed // Duplicates the parent item - Inkscape::XML::Node *copy2 = old_repr->duplicate(xml_doc); - parent->appendChild(copy2); - SPObject *new_obj2 = doc->getObjectByRepr(copy2); - item_copied = SP_ITEM(new_obj2); + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + parent->appendChild(copy); + SPObject *new_obj = doc->getObjectByRepr(copy); + item_copied = SP_ITEM(new_obj); // Move around the cursor Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); @@ -481,10 +471,12 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Union and duplication selection->clear(); selection->add(item_copied); - selection->add(unionResult); + if (unionResult) { // No need to add the very first item (initialized with NULL). + selection->add(unionResult); + } sp_selected_path_union_skip_undo(selection, selection->desktop()); selection->add(parent_item); - Inkscape::GC::release(copy2); + Inkscape::GC::release(copy); did = true; } } -- cgit v1.2.3 From 73bf98229d2abce580b46a840e353e4a73431dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20W=C3=BCst?= Date: Sun, 16 Feb 2014 22:20:33 +0100 Subject: various optimizations, move extension to 'Export' submenu (bzr r13032) --- share/extensions/hpgl_encoder.py | 101 +++++++++++++++++---------------------- share/extensions/inkex.py | 7 +++ share/extensions/plotter.inx | 2 +- share/extensions/plotter.py | 20 ++++---- 4 files changed, 61 insertions(+), 69 deletions(-) diff --git a/share/extensions/hpgl_encoder.py b/share/extensions/hpgl_encoder.py index 2304ce261..42c3bb821 100644 --- a/share/extensions/hpgl_encoder.py +++ b/share/extensions/hpgl_encoder.py @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import math import re import string +#from StringIO import StringIO # local libraries import bezmisc import cspsubdiv @@ -36,11 +37,6 @@ import simpletransform class hpglEncoder: PI = math.pi TWO_PI = PI * 2 - # a dictionary of arbitrary unit to user unit conversion factors - # in = Inch; pt = PostScript Point; px = Pixel; mm = Millimeter; cm = Centimeter; - # km = Kilometer; pc = PostScript Pica; yd = Yard; ft = Feet; m = Meter - __USER_UNIT_CONVERSION = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, - 'km':3543307.0866, 'pc':15.0, 'yd':3240 , 'ft':1080, 'm':3543.3070866} def __init__(self, effect): ''' options: @@ -66,26 +62,21 @@ class hpglEncoder: ''' self.options = effect.options self.doc = effect.document.getroot() - self.documentUnit = self.doc.xpath('//sodipodi:namedview/@inkscape:document-units', namespaces=inkex.NSS) - if self.documentUnit: - self.documentUnit = self.documentUnit[0] - else: - self.documentUnit = 'px' - self.docWidth = self.unitToUserUnit(self.doc.get('width'), True) - self.docHeight = self.unitToUserUnit(self.doc.get('height'), True) + self.docWidth = effect.unittouu(self.doc.get('width')) + self.docHeight = effect.unittouu(self.doc.get('height')) self.divergenceX = 'False' self.divergenceY = 'False' self.sizeX = 'False' self.sizeY = 'False' self.dryRun = True self.lastPoint = [0, 0, 0] - self.scaleX = self.options.resolutionX / self.unitToUserUnit("1.0in") # dots per inch to dots per user unit - self.scaleY = self.options.resolutionY / self.unitToUserUnit("1.0in") # dots per inch to dots per user unit + self.scaleX = self.options.resolutionX / effect.unittouu("1.0in") # dots per inch to dots per user unit + self.scaleY = self.options.resolutionY / effect.unittouu("1.0in") # dots per inch to dots per user unit scaleXY = (self.scaleX + self.scaleY) / 2 - self.offsetX = self.unitToUserUnit(str(self.options.offsetX) + "mm") * self.scaleX # mm to dots (plotter coordinate system) - self.offsetY = self.unitToUserUnit(str(self.options.offsetY) + "mm") * self.scaleY # mm to dots - self.overcut = self.unitToUserUnit(str(self.options.overcut) + "mm") * scaleXY # mm to dots - self.toolOffset = self.unitToUserUnit(str(self.options.toolOffset) + "mm") * scaleXY # mm to dots + self.offsetX = effect.unittouu(str(self.options.offsetX) + "mm") * self.scaleX # mm to dots (plotter coordinate system) + self.offsetY = effect.unittouu(str(self.options.offsetY) + "mm") * self.scaleY # mm to dots + self.overcut = effect.unittouu(str(self.options.overcut) + "mm") * scaleXY # mm to dots + self.toolOffset = effect.unittouu(str(self.options.toolOffset) + "mm") * scaleXY # mm to dots self.flat = self.options.flat / (1016 / ((self.options.resolutionX + self.options.resolutionY) / 2)) # scale flatness to resolution self.toolOffsetFlat = self.flat / self.toolOffset * 4.5 # scale flatness to offset self.mirrorX = 1.0 @@ -95,23 +86,25 @@ class hpglEncoder: if self.options.mirrorY: self.mirrorY = 1.0 if self.options.debug: - self.debugValues = [0, 0, 0, 0, 0, 0, 0, 0] - self.debugValues[0] = self.docWidth - self.debugValues[1] = self.docHeight + self.debugValues = {} + self.debugValues['docWidth'] = self.docWidth + self.debugValues['docHeight'] = self.docHeight # process viewBox attribute to correct page scaling self.viewBoxTransformX = 1 self.viewBoxTransformY = 1 + if self.options.debug: + self.debugValues['viewBoxWidth'] = "-" + self.debugValues['viewBoxHeight'] = "-" viewBox = self.doc.get('viewBox') if viewBox: - viewBox = string.split(viewBox, ' ') - if viewBox[2] and viewBox[3]: - viewBox[0] = viewBox[2] - viewBox[1] = viewBox[3] + viewBox2 = string.split(viewBox, ',') + if len(viewBox2) < 4: + viewBox2 = string.split(viewBox, ' ') if self.options.debug: - self.debugValues[2] = self.unitToUserUnit(viewBox[0]) - self.debugValues[3] = self.unitToUserUnit(viewBox[1]) - self.viewBoxTransformX = self.docWidth / self.unitToUserUnit(viewBox[0]) - self.viewBoxTransformY = self.docHeight / self.unitToUserUnit(viewBox[1]) + self.debugValues['viewBoxWidth'] = viewBox2[2] + self.debugValues['viewBoxHeight'] = viewBox2[3] + self.viewBoxTransformX = self.docWidth / effect.unittouu(effect.addDocumentUnit(viewBox2[2])) + self.viewBoxTransformY = self.docHeight / effect.unittouu(effect.addDocumentUnit(viewBox2[3])) def getHpgl(self): # dryRun to find edges @@ -124,10 +117,10 @@ class hpglEncoder: # live run self.dryRun = False if self.options.debug: - self.debugValues[4] = self.sizeX - self.divergenceX - self.debugValues[5] = self.sizeY - self.divergenceY - self.debugValues[6] = self.unitToUserUnit(str(self.debugValues[4] / self.scaleX)) - self.debugValues[7] = self.unitToUserUnit(str(self.debugValues[5] / self.scaleY)) + self.debugValues['drawingWidth'] = self.sizeX - self.divergenceX + self.debugValues['drawingHeight'] = self.sizeY - self.divergenceY + self.debugValues['drawingWidthUU'] = self.debugValues['drawingWidth'] / self.scaleX + self.debugValues['drawingHeightUU'] = self.debugValues['drawingHeight'] / self.scaleY # move drawing according to various modifiers if self.options.autoAlign: if self.options.center: @@ -161,20 +154,30 @@ class hpglEncoder: self.offsetX += self.toolOffset self.offsetY += self.toolOffset # initialize transformation matrix and cache - groupmat = [[self.mirrorX * self.scaleX * self.viewBoxTransformX, 0.0, - self.divergenceX + self.offsetX], - [0.0, self.mirrorY * self.scaleY * self.viewBoxTransformY, - self.divergenceY + self.offsetY]] + groupmat = [[self.mirrorX * self.scaleX * self.viewBoxTransformX, 0.0, -self.divergenceX + self.offsetX], + [0.0, self.mirrorY * self.scaleY * self.viewBoxTransformY, -self.divergenceY + self.offsetY]] groupmat = simpletransform.composeTransform(groupmat, simpletransform.parseTransform('rotate(' + self.options.orientation + ')')) self.vData = [['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0]] - # store first hpgl commands + # store initial hpgl commands self.hpgl = 'IN;SP%d' % self.options.pen if self.options.force > 0: self.hpgl += ';FS%d' % self.options.force if self.options.speed > 0: self.hpgl += ';VS%d' % self.options.speed - # add precut + # add move to zero point and precut + self.processOffset('PU', 0, 0) if self.options.useToolOffset and self.options.precut: - self.processOffset('PU', 0, 0) - self.processOffset('PD', 0, self.toolOffset * 8) + if self.options.center: + # TODO: get this FU to work or remove precut functionality + ''' + newDoc = inkex.etree.parse(StringIO('')) + newLayer = inkex.etree.SubElement(newDoc.getroot(), 'g', {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): 'null'}) + newPath = inkex.etree.SubElement(newLayer, 'path', {'d': 'M ' + str(oldDivergenceX) + ',' + str(oldDivergenceY) + ' L ' + str(oldDivergenceX) + ',' + str(oldDivergenceY + (self.options.toolOffset * 8 * 3.5433070866)), 'style': 'stroke:#000000; stroke-width:0.4; fill:none;'}) + self.processPath(newPath, groupmat) + ''' + pass + else: + self.processOffset('PD', 0, self.toolOffset * 8) # start conversion self.processGroups(self.doc, groupmat) # shift an empty node in in order to process last node in cache @@ -186,20 +189,8 @@ class hpglEncoder: else: return self.hpgl, "" - def unitToUserUnit(self, string, isPixels=False): - '''Returns userunits given a string representation of units in another system''' - matches = re.match('^(.*?)(in|pt|px|mm|cm|km|pc|yd|ft|m)?$', string.strip()) - value = float(matches.group(1)) - unit = matches.group(2) - if unit is None: - if isPixels: - unit = "px" - else: - unit = self.documentUnit - return value * self.__USER_UNIT_CONVERSION[unit] / self.__USER_UNIT_CONVERSION[self.documentUnit] - def processGroups(self, doc, groupmat): - # flatten groups to avoid recursion + # flatten layers and groups to avoid recursion paths = [] for node in doc: if (node.tag == inkex.addNS('g', 'svg') and self.isGroupVisible(node)) or node.tag == inkex.addNS('path', 'svg'): @@ -291,12 +282,6 @@ class hpglEncoder: y = y2 + (y2 - y1) / self.getLength(x1, y1, x2, y2, False) * offset return [x, y] - def getAlpha(self, x1, y1, x2, y2, x3, y3): - # get alpha of point 2 - temp1 = (x1 - x2) ** 2 + (y1 - y2) ** 2 + (x3 - x2) ** 2 + (y3 - y2) ** 2 - (x1 - x3) ** 2 - (y1 - y3) ** 2 - temp2 = 2 * math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) * math.sqrt((x3 - x2) ** 2 + (y3 - y2) ** 2) - return math.acos(max(min(temp1 / temp2, 1.0), -1.0)) - def processOffset(self, cmd, posX, posY): # calculate offset correction (or dont) if not self.options.useToolOffset or self.dryRun: diff --git a/share/extensions/inkex.py b/share/extensions/inkex.py index 1203a4606..d71b7d7e7 100755 --- a/share/extensions/inkex.py +++ b/share/extensions/inkex.py @@ -311,5 +311,12 @@ class Effect: def uutounit(self, val, unit): return val / (self.__uuconv[unit] / self.__uuconv[self.getDocumentUnit()]) + def addDocumentUnit(self, value): + ''' Add document unit when no unit is specified in the string ''' + try: + float(value) + return value + self.getDocumentUnit() + except ValueError: + return value # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 diff --git a/share/extensions/plotter.inx b/share/extensions/plotter.inx index e30d61418..c8f009140 100644 --- a/share/extensions/plotter.inx +++ b/share/extensions/plotter.inx @@ -80,7 +80,7 @@ path - +