diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2014-03-18 20:06:37 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2014-03-18 20:06:37 +0000 |
| commit | 5ea50da1809d7c851b97c448588757ec33a0145e (patch) | |
| tree | f1a669fc9d1647600ced5fa28d8e8c5af3af9cf0 | |
| parent | update to trunk (diff) | |
| parent | Fix for Bug #1291546 (Linking color profile from Document properties dialog c... (diff) | |
| download | inkscape-5ea50da1809d7c851b97c448588757ec33a0145e.tar.gz inkscape-5ea50da1809d7c851b97c448588757ec33a0145e.zip | |
update to trunk
(bzr r11950.1.300)
| -rw-r--r-- | share/extensions/merge_styles.inx | 21 | ||||
| -rwxr-xr-x | share/extensions/merge_styles.py | 134 | ||||
| -rw-r--r-- | src/color-profile.cpp | 2 | ||||
| -rw-r--r-- | src/extension/internal/emf-print.cpp | 2 | ||||
| -rw-r--r-- | src/extension/internal/grid.cpp | 35 | ||||
| -rw-r--r-- | src/extension/internal/wmf-print.cpp | 2 | ||||
| -rw-r--r-- | src/sp-use.cpp | 6 | ||||
| -rw-r--r-- | src/trace/siox.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/export.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/filter-effects-dialog.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/undo-history.cpp | 2 | ||||
| -rw-r--r-- | src/uri.cpp | 3 |
12 files changed, 186 insertions, 27 deletions
diff --git a/share/extensions/merge_styles.inx b/share/extensions/merge_styles.inx new file mode 100644 index 000000000..02da12221 --- /dev/null +++ b/share/extensions/merge_styles.inx @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <_name>Merge Styles into CSS</_name> + <id>org.inkscape.stylesheet.merge</id> + <dependency type="executable" location="extensions">inkex.py</dependency> + <dependency type="executable" location="extensions">merge_styles.py</dependency> + + <_param name="introduction" type="description">All selected nodes will be grouped together and their common style attributes will create a new class, this class will replace the existing inline style attributes. Please use a name which best describes the kinds of objects and their common context for best effect.</_param> + + <param name="name" type="string" _gui-text="New Class Name:">class1</param> + + <effect needs-live-preview="false"> + <object-type>all</object-type> + <effects-menu> + <submenu _name="Stylesheet"/> + </effects-menu> + </effect> + <script> + <command reldir="extensions" interpreter="python">merge_styles.py</command> + </script> +</inkscape-extension> diff --git a/share/extensions/merge_styles.py b/share/extensions/merge_styles.py new file mode 100755 index 000000000..f028bf4ce --- /dev/null +++ b/share/extensions/merge_styles.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python +# +# Copyright (C) 2014 Martin Owens +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +""" +Merges styles into class based styles and removes. +""" + +import inkex +import sys + +from collections import defaultdict + +class Style(dict): + """Controls the style/css mechanics for this effect""" + def __init__(self, attr=None): + self.weights = defaultdict(int) + self.total = [] + if attr: + self.parse(attr) + + def parse(self, attr): + for name,value in [ a.split(':',1) for a in attr.split(';') if ':' in a ]: + self[name.strip()] = value.strip() + + def entries(self): + return [ "%s:%s;" % (n,v) for (n,v) in self.iteritems() ] + + def to_str(self, sep="\n "): + return " " + "\n ".join(self.entries()) + + def __str__(self): + return self.to_str() + + def css(self, cls): + return ".%s {\n%s\n}" % (cls, str(self)) + + def remove(self, keys): + for key in keys: + self.pop(key, None) + + def add(self, c, el): + self.total.append( (c, el) ) + for name,value in c.iteritems(): + if not self.has_key(name): + self[name] = value + if self[name] == value: + self.weights[name] += 1 + + def clean(self, threshold): + """Removes any elements that aren't the same using a weighted threshold""" + for attr in self.keys(): + if self.weights[attr] < len(self.total) - threshold: + self.pop(attr) + + def all_matches(self): + """Returns an iter for each added element who's style matches this style""" + for (c, el) in self.total: + if self == c: + yield (c, el) + + def __eq__(self, o): + """Not equals, prefer to overload 'in' but that doesn't seem possible""" + for arg in self.keys(): + if o.has_key(arg) and self[arg] != o[arg]: + return False + return True + + +def get_styles(document): + nodes = [] + for node in document.getroot().iterchildren(): + if node.tag == inkex.addNS('style', 'svg'): + return node + nodes.append(node) + ret = inkex.etree.SubElement(document.getroot(), 'style', {}) + # Reorder to make the style element FIRST + for node in nodes: + document.getroot().append(node) + return ret + + +class MergeStyles(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("-n", "--name", + action="store", type="string", + dest="name", default='', + help="Name of selected element's common class") + + def effect(self): + newclass = self.options.name + elements = self.selected.values() + common = Style() + threshold = 1 + + for el in elements: + common.add(Style(el.attrib['style']), el) + common.clean(threshold) + + if not common: + raise KeyError("There are no common styles between these elements.") + + styles = get_styles(self.document) + styles.text = (styles.text or "") + "\n" + common.css( newclass ) + + for (st, el) in common.all_matches(): + st.remove(common.keys()) + el.attrib['style'] = st.to_str("") + + olds = el.attrib.has_key('class') and el.attrib['class'].split() or [] + if newclass not in olds: + olds.append(newclass) + el.attrib['class'] = ' '.join(olds) + + +if __name__ == '__main__': + e = MergeStyles() + e.affect() + diff --git a/src/color-profile.cpp b/src/color-profile.cpp index 09eaa36e5..ed4b9029e 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -339,7 +339,7 @@ void ColorProfile::set(unsigned key, gchar const *value) { Inkscape::URI hrefUri(escaped); //# 3. Resolve the href according the docBase. This follows // the w3c specs. All absolute and relative issues are considered - std::string fullpath = docUri.getFullPath(hrefUri.getFullPath("")); + std::string fullpath = hrefUri.getFullPath(docUri.getFullPath("")); gchar* fullname = g_uri_unescape_string(fullpath.c_str(), ""); this->impl->_clearProfile(); diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 9cc662a27..4bb892821 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -1562,7 +1562,7 @@ unsigned int PrintEmf::image( unsigned int h, /** height of bitmap */ unsigned int rs, /** row stride (normally w*4) */ Geom::Affine const &tf_rect, /** affine transform only used for defining location and size of rect, for all other tranforms, use the one from m_tr_stack */ - SPStyle const *style) /** provides indirect link to image object */ + SPStyle const * /*style*/) /** provides indirect link to image object */ { double x1, y1, dw, dh; char *rec = NULL; diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index c120df719..0059bbec2 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -59,31 +59,31 @@ Grid::load (Inkscape::Extension::Extension */*module*/) namespace { Glib::ustring build_lines(Geom::Rect bounding_area, - float offset[], float spacing[]) + Geom::Point const &offset, Geom::Point const &spacing) { Geom::Point point_offset(0.0, 0.0); SVG::PathString path_data; - for ( int axis = 0 ; axis < 2 ; ++axis ) { + for ( int axis = Geom::X ; axis <= Geom::Y ; ++axis ) { point_offset[axis] = offset[axis]; for (Geom::Point start_point = bounding_area.min(); - start_point[axis] + offset[axis] <= (bounding_area.max())[axis]; - start_point[axis] += spacing[axis]) { + start_point[axis] + offset[axis] <= (bounding_area.max())[axis]; + start_point[axis] += spacing[axis]) { Geom::Point end_point = start_point; end_point[1-axis] = (bounding_area.max())[1-axis]; path_data.moveTo(start_point + point_offset) - .lineTo(end_point + point_offset); + .lineTo(end_point + point_offset); } } - // std::cout << "Path data:" << path_data.c_str() << std::endl; - return path_data; - } - + // std::cout << "Path data:" << path_data.c_str() << std::endl; + return path_data; } +} // namespace + /** \brief This actually draws the grid. \param module The effect that was called (unused) @@ -115,16 +115,15 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc gdouble scale = Inkscape::Util::Quantity::convert(1, "px", (document->doc())->getDefaultUnit()); bounding_area *= Geom::Scale(scale); - float spacings[2] = { scale*module->get_param_float("xspacing"), - scale*module->get_param_float("yspacing") }; - float line_width = scale*module->get_param_float("lineWidth"); - float offsets[2] = { scale*module->get_param_float("xoffset"), - scale*module->get_param_float("yoffset") }; + Geom::Point spacings( scale * module->get_param_float("xspacing"), + scale * module->get_param_float("yspacing") ); + gdouble line_width = scale * module->get_param_float("lineWidth"); + Geom::Point offsets( scale * module->get_param_float("xoffset"), + scale * module->get_param_float("yoffset") ); Glib::ustring path_data(""); - path_data = build_lines(bounding_area, - offsets, spacings); + path_data = build_lines(bounding_area, offsets, spacings); Inkscape::XML::Document * xml_doc = document->doc()->getReprDoc(); //XML Tree being used directly here while it shouldn't be. @@ -144,9 +143,7 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc path->setAttribute("style", style.c_str()); current_layer->appendChild(path); - Inkscape::GC::release(path); - - return; + Inkscape::GC::release(path); } /** \brief A class to make an adjustment that uses Extension params */ diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp index 232891c9c..5a552ad83 100644 --- a/src/extension/internal/wmf-print.cpp +++ b/src/extension/internal/wmf-print.cpp @@ -1103,7 +1103,7 @@ unsigned int PrintWmf::image( unsigned int h, /** height of bitmap */ unsigned int rs, /** row stride (normally w*4) */ Geom::Affine const &tf_rect, /** affine transform only used for defining location and size of rect, for all other tranforms, use the one from m_tr_stack */ - SPStyle const *style) /** provides indirect link to image object */ + SPStyle const * /*style*/) /** provides indirect link to image object */ { double x1, y1, dw, dh; char *rec = NULL; diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 14f51159b..e8fe3687f 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -220,7 +220,11 @@ const char* SPUse::displayName() const { gchar* SPUse::description() const { if (this->child) { if( SP_IS_SYMBOL( this->child ) ) { - return g_strdup_printf(_("called %s"), Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", this->child->title()))).c_str()); + if (this->child->title()) { + return g_strdup_printf(_("called %s"), Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", this->child->title()))).c_str()); + } else { + return g_strdup_printf(_("called %s"), _("Unnamed Symbol")); + } } static unsigned recursion_depth = 0; diff --git a/src/trace/siox.cpp b/src/trace/siox.cpp index 0706cfed1..065e891ed 100644 --- a/src/trace/siox.cpp +++ b/src/trace/siox.cpp @@ -889,7 +889,7 @@ SioxImage Siox::extractForeground(const SioxImage &originalImage, return workImage; } - trace("knownBg:%u knownFg:%u", knownBg.size(), knownFg.size()); + trace("knownBg:%u knownFg:%u", static_cast<unsigned int>(knownBg.size()), static_cast<unsigned int>(knownFg.size())); std::vector<CieLab> bgSignature ; diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index f0a5f1bf5..913713e5c 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -1049,7 +1049,7 @@ void Export::onExport () dpi = atof(dpi_hint); } if (dpi == 0.0) { - dpi = DPI_BASE; + dpi = getValue(xdpi_adj); } Geom::OptRect area = item->desktopVisualBounds(); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 65bebbd14..c2367c2a2 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1515,7 +1515,7 @@ void FilterEffectsDialog::FilterModifier::on_name_edited(const Glib::ustring& pa } } -bool FilterEffectsDialog::FilterModifier::on_filter_move(const Glib::RefPtr<Gdk::DragContext>& /*context*/, int x, int y, guint /*time*/) { +bool FilterEffectsDialog::FilterModifier::on_filter_move(const Glib::RefPtr<Gdk::DragContext>& /*context*/, int /*x*/, int /*y*/, guint /*time*/) { //const Gtk::TreeModel::Path& /*path*/) { /* The code below is bugged. Use of "object->getRepr()->setPosition(0)" is dangerous! diff --git a/src/ui/dialog/undo-history.cpp b/src/ui/dialog/undo-history.cpp index 2412c3ec9..53691cd37 100644 --- a/src/ui/dialog/undo-history.cpp +++ b/src/ui/dialog/undo-history.cpp @@ -235,7 +235,7 @@ void UndoHistory::setDesktop(SPDesktop* desktop) } } -void UndoHistory::_connectDocument(SPDesktop* desktop, SPDocument *document) +void UndoHistory::_connectDocument(SPDesktop* desktop, SPDocument * /*document*/) { // disconnect from prior if (_event_log) { diff --git a/src/uri.cpp b/src/uri.cpp index e81d108c9..2eaf4ecc1 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -149,6 +149,9 @@ gchar *URI::to_native_filename(gchar const* uri) throw(BadURIException) * and thus redundent. Caller is expected to check against the document's path. */ const std::string URI::getFullPath(std::string const base) const { + if (!_impl->getPath()) { + return ""; + } std::string path = std::string(_impl->getPath()); // Calculate the absolute path from an available base if(!base.empty() && !path.empty() && path[0] != '/') { |
