diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp
index 58209aaa3c70d4eb41b440535fd5ae8ec2f7ed9b..4f5ab982edaf33d1aa68a2cb8e5fbf2b4754b456 100644 (file)
--- a/src/desktop-style.cpp
+++ b/src/desktop-style.cpp
*
* Authors:
* bulia byak
*
* Authors:
* bulia byak
+ * verbalshadow
*
*
- * Copyright (C) 2004 authors
+ * Copyright (C) 2004, 2006 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "desktop.h"
#include "color-rgba.h"
#include "svg/css-ostringstream.h"
#include "desktop.h"
#include "color-rgba.h"
#include "svg/css-ostringstream.h"
+#include "svg/svg.h"
#include "svg/svg-color.h"
#include "selection.h"
#include "sp-tspan.h"
#include "svg/svg-color.h"
#include "selection.h"
#include "sp-tspan.h"
#include "style.h"
#include "prefs-utils.h"
#include "sp-use.h"
#include "style.h"
#include "prefs-utils.h"
#include "sp-use.h"
+#include "sp-filter.h"
+#include "sp-gaussian-blur.h"
#include "sp-flowtext.h"
#include "sp-flowregion.h"
#include "sp-flowdiv.h"
#include "sp-flowtext.h"
#include "sp-flowregion.h"
#include "sp-flowdiv.h"
#include "xml/repr.h"
#include "libnrtype/font-style-to-pos.h"
#include "xml/repr.h"
#include "libnrtype/font-style-to-pos.h"
+
#include "desktop-style.h"
/**
#include "desktop-style.h"
/**
return r;
}
return r;
}
+double
+sp_desktop_get_master_opacity_tool(SPDesktop *desktop, char const *tool)
+{
+ SPCSSAttr *css = NULL;
+ gfloat value = 1.0; // default if nothing else found
+ if (prefs_get_double_attribute(tool, "usecurrent", 0) != 0) {
+ css = sp_desktop_get_style(desktop, true);
+ } else {
+ Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
+ if (tool_repr) {
+ css = sp_repr_css_attr_inherited(tool_repr, "style");
+ }
+ }
+
+ if (css) {
+ gchar const *property = css ? sp_repr_css_property(css, "opacity", "1.000") : 0;
+
+ if (desktop->current && property) { // if there is style and the property in it,
+ if ( !sp_svg_number_read_f(property, &value) ) {
+ value = 1.0; // things failed. set back to the default
+ }
+ }
+
+ sp_repr_css_attr_unref(css);
+ }
+
+ return value;
+}
+double
+sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool, bool is_fill)
+{
+ SPCSSAttr *css = NULL;
+ gfloat value = 1.0; // default if nothing else found
+ if (prefs_get_double_attribute(tool, "usecurrent", 0) != 0) {
+ css = sp_desktop_get_style(desktop, true);
+ } else {
+ Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
+ if (tool_repr) {
+ css = sp_repr_css_attr_inherited(tool_repr, "style");
+ }
+ }
+
+ if (css) {
+ gchar const *property = css ? sp_repr_css_property(css, is_fill ? "fill-opacity": "stroke-opacity", "1.000") : 0;
+
+ if (desktop->current && property) { // if there is style and the property in it,
+ if ( !sp_svg_number_read_f(property, &value) ) {
+ value = 1.0; // things failed. set back to the default
+ }
+ }
+
+ sp_repr_css_attr_unref(css);
+ }
+
+ return value;
+}
guint32
sp_desktop_get_color_tool(SPDesktop *desktop, char const *tool, bool is_fill)
{
SPCSSAttr *css = NULL;
guint32 r = 0; // if there's no color, return black
if (prefs_get_int_attribute(tool, "usecurrent", 0) != 0) {
guint32
sp_desktop_get_color_tool(SPDesktop *desktop, char const *tool, bool is_fill)
{
SPCSSAttr *css = NULL;
guint32 r = 0; // if there's no color, return black
if (prefs_get_int_attribute(tool, "usecurrent", 0) != 0) {
- css = sp_desktop_get_style(desktop, is_fill);
+ css = sp_desktop_get_style(desktop, true);
} else {
Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
} else {
Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
- css = sp_repr_css_attr_inherited(tool_repr, "style");
+ if (tool_repr) {
+ css = sp_repr_css_attr_inherited(tool_repr, "style");
+ }
}
}
- gchar const *property = sp_repr_css_property(css, is_fill ? "fill" : "stroke", "#000");
+ if (css) {
+ gchar const *property = sp_repr_css_property(css, is_fill ? "fill" : "stroke", "#000");
- if (desktop->current && property) { // if there is style and the property in it,
- if (strncmp(property, "url", 3)) { // and if it's not url,
- // read it
- r = sp_svg_read_color(property, r);
+ if (desktop->current && property) { // if there is style and the property in it,
+ if (strncmp(property, "url", 3)) { // and if it's not url,
+ // read it
+ r = sp_svg_read_color(property, r);
+ }
}
}
+
+ sp_repr_css_attr_unref(css);
}
}
+
return r | 0xff;
}
/**
return r | 0xff;
}
/**
sp_repr_css_attr_unref(css);
}
}
sp_repr_css_attr_unref(css);
}
}
- if (css_current) {sp_repr_css_attr_unref(css_current);
+ if (css_current) {
+ sp_repr_css_attr_unref(css_current);
}
}
}
}
style_res->font_style.value = style_res->font_style.computed = style->font_style.computed;
style_res->font_stretch.value = style_res->font_stretch.computed = style->font_stretch.computed;
style_res->font_variant.value = style_res->font_variant.computed = style->font_variant.computed;
style_res->font_style.value = style_res->font_style.computed = style->font_style.computed;
style_res->font_stretch.value = style_res->font_stretch.computed = style->font_stretch.computed;
style_res->font_variant.value = style_res->font_variant.computed = style->font_variant.computed;
+ style_res->text_align.value = style_res->text_align.computed = style->text_align.computed;
}
if (texts == 0 || !set)
}
if (texts == 0 || !set)
}
}
}
}
+/**
+ * Write to style_res the average blurring of a list of objects.
+ */
+int
+objects_query_blur (GSList *objects, SPStyle *style_res)
+{
+ if (g_slist_length(objects) == 0) {
+ /* No objects, set empty */
+ return QUERY_STYLE_NOTHING;
+ }
+
+ float blur_sum = 0;
+ float blur_prev = -1;
+ bool same_blur = true;
+ guint blur_items = 0;
+ guint items = 0;
+
+ for (GSList const *i = objects; i != NULL; i = i->next) {
+ SPObject *obj = SP_OBJECT (i->data);
+ SPStyle *style = SP_OBJECT_STYLE (obj);
+ if (!style) continue;
+
+ NR::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
+
+ items ++;
+
+ //if object has a filter
+ if (style->filter.set && style->filter.filter) {
+ //cycle through filter primitives
+ for(int i=0; i<style->filter.filter->_primitive_count; i++)
+ {
+ SPFilterPrimitive *primitive = style->filter.filter->_primitives[i];
+ //if primitive is gaussianblur
+ if(SP_IS_GAUSSIANBLUR(primitive)) {
+ SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
+ float num = spblur->stdDeviation.getNumber();
+ blur_sum += num * NR::expansion(i2d);
+ if (blur_prev != -1 && fabs (num - blur_prev) > 1e-2) // rather low tolerance because difference in blur radii is much harder to notice than e.g. difference in sizes
+ same_blur = false;
+ blur_prev = num;
+ //TODO: deal with opt number, for the moment it's not necessary to the ui.
+ blur_items ++;
+ }
+ }
+ }
+
+ }
+
+ if (items > 0) {
+ if (blur_items > 0)
+ blur_sum /= blur_items;
+ style_res->filter_gaussianBlur_deviation.value = blur_sum;
+ }
+
+ if (items == 0) {
+ return QUERY_STYLE_NOTHING;
+ } else if (items == 1) {
+ return QUERY_STYLE_SINGLE;
+ } else {
+ if (same_blur)
+ return QUERY_STYLE_MULTIPLE_SAME;
+ else
+ return QUERY_STYLE_MULTIPLE_AVERAGED;
+ }
+}
+
/**
* Query the given list of objects for the given property, write
* the result to style, return appropriate flag.
/**
* Query the given list of objects for the given property, write
* the result to style, return appropriate flag.
return objects_query_fontstyle (list, style);
} else if (property == QUERY_STYLE_PROPERTY_FONTNUMBERS) {
return objects_query_fontnumbers (list, style);
return objects_query_fontstyle (list, style);
} else if (property == QUERY_STYLE_PROPERTY_FONTNUMBERS) {
return objects_query_fontnumbers (list, style);
- }
+ } else if (property == QUERY_STYLE_PROPERTY_BLUR) {
+ return objects_query_blur (list, style);
+ }
return QUERY_STYLE_NOTHING;
}
return QUERY_STYLE_NOTHING;
}
int result_strokecap = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKECAP);
int result_strokejoin = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
int result_opacity = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
int result_strokecap = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKECAP);
int result_strokejoin = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
int result_opacity = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
-
- return (result_family != QUERY_STYLE_NOTHING && result_fstyle != QUERY_STYLE_NOTHING && result_fnumbers != QUERY_STYLE_NOTHING && result_fill != QUERY_STYLE_NOTHING && result_stroke != QUERY_STYLE_NOTHING && result_opacity != QUERY_STYLE_NOTHING && result_strokewidth != QUERY_STYLE_NOTHING && result_strokemiterlimit != QUERY_STYLE_NOTHING && result_strokecap != QUERY_STYLE_NOTHING && result_strokejoin != QUERY_STYLE_NOTHING);
+ int result_blur = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_BLUR);
+
+ return (result_family != QUERY_STYLE_NOTHING && result_fstyle != QUERY_STYLE_NOTHING && result_fnumbers != QUERY_STYLE_NOTHING && result_fill != QUERY_STYLE_NOTHING && result_stroke != QUERY_STYLE_NOTHING && result_opacity != QUERY_STYLE_NOTHING && result_strokewidth != QUERY_STYLE_NOTHING && result_strokemiterlimit != QUERY_STYLE_NOTHING && result_strokecap != QUERY_STYLE_NOTHING && result_strokejoin != QUERY_STYLE_NOTHING && result_blur != QUERY_STYLE_NOTHING);
}
}