2225be5ee6447cfc94c44939a97b67e711223c1a
1 #define __SP_DESKTOP_STYLE_C__
3 /** \file
4 * Desktop style management
5 *
6 * Authors:
7 * bulia byak
8 * verbalshadow
9 *
10 * Copyright (C) 2004, 2006 authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #include <string>
16 #include <cstring>
18 #include "desktop.h"
19 #include "color-rgba.h"
20 #include "svg/css-ostringstream.h"
21 #include "svg/svg.h"
22 #include "svg/svg-color.h"
23 #include "selection.h"
24 #include "inkscape.h"
25 #include "style.h"
26 #include "preferences.h"
27 #include "sp-use.h"
28 #include "filters/blend.h"
29 #include "sp-filter.h"
30 #include "sp-filter-reference.h"
31 #include "sp-gaussian-blur.h"
32 #include "sp-flowtext.h"
33 #include "sp-flowregion.h"
34 #include "sp-flowdiv.h"
35 #include "sp-linear-gradient.h"
36 #include "sp-pattern.h"
37 #include "sp-radial-gradient.h"
38 #include "sp-textpath.h"
39 #include "sp-tref.h"
40 #include "sp-tspan.h"
41 #include "xml/repr.h"
42 #include "libnrtype/font-style-to-pos.h"
43 #include "sp-path.h"
45 #include "desktop-style.h"
46 #include "svg/svg-icc-color.h"
47 #include "svg/svg-device-color.h"
48 #include "box3d-side.h"
50 /**
51 * Set color on selection on desktop.
52 */
53 void
54 sp_desktop_set_color(SPDesktop *desktop, ColorRGBA const &color, bool is_relative, bool fill)
55 {
56 /// \todo relative color setting
57 if (is_relative) {
58 g_warning("FIXME: relative color setting not yet implemented");
59 return;
60 }
62 guint32 rgba = SP_RGBA32_F_COMPOSE(color[0], color[1], color[2], color[3]);
63 gchar b[64];
64 sp_svg_write_color(b, sizeof(b), rgba);
65 SPCSSAttr *css = sp_repr_css_attr_new();
66 if (fill) {
67 sp_repr_css_set_property(css, "fill", b);
68 Inkscape::CSSOStringStream osalpha;
69 osalpha << color[3];
70 sp_repr_css_set_property(css, "fill-opacity", osalpha.str().c_str());
71 } else {
72 sp_repr_css_set_property(css, "stroke", b);
73 Inkscape::CSSOStringStream osalpha;
74 osalpha << color[3];
75 sp_repr_css_set_property(css, "stroke-opacity", osalpha.str().c_str());
76 }
78 sp_desktop_set_style(desktop, css);
80 sp_repr_css_attr_unref(css);
81 }
83 /**
84 * Apply style on object and children, recursively.
85 */
86 void
87 sp_desktop_apply_css_recursive(SPObject *o, SPCSSAttr *css, bool skip_lines)
88 {
89 // non-items should not have style
90 if (!SP_IS_ITEM(o))
91 return;
93 // 1. tspans with role=line are not regular objects in that they are not supposed to have style of their own,
94 // but must always inherit from the parent text. Same for textPath.
95 // However, if the line tspan or textPath contains some style (old file?), we reluctantly set our style to it too.
97 // 2. Generally we allow setting style on clones, but when it's inside flowRegion, do not touch
98 // it, be it clone or not; it's just styleless shape (because that's how Inkscape does
99 // flowtext).
101 if (!(skip_lines
102 && ((SP_IS_TSPAN(o) && SP_TSPAN(o)->role == SP_TSPAN_ROLE_LINE)
103 || SP_IS_FLOWDIV(o)
104 || SP_IS_FLOWPARA(o)
105 || SP_IS_TEXTPATH(o))
106 && !SP_OBJECT_REPR(o)->attribute("style"))
107 &&
108 !(SP_IS_FLOWREGION(o) ||
109 SP_IS_FLOWREGIONEXCLUDE(o) ||
110 (SP_IS_USE(o) &&
111 SP_OBJECT_PARENT(o) &&
112 (SP_IS_FLOWREGION(SP_OBJECT_PARENT(o)) ||
113 SP_IS_FLOWREGIONEXCLUDE(SP_OBJECT_PARENT(o))
114 )
115 )
116 )
117 ) {
119 SPCSSAttr *css_set = sp_repr_css_attr_new();
120 sp_repr_css_merge(css_set, css);
122 // Scale the style by the inverse of the accumulated parent transform in the paste context.
123 {
124 Geom::Matrix const local(sp_item_i2doc_affine(SP_ITEM(o)));
125 double const ex(local.descrim());
126 if ( ( ex != 0. )
127 && ( ex != 1. ) ) {
128 sp_css_attr_scale(css_set, 1/ex);
129 }
130 }
132 sp_repr_css_change(SP_OBJECT_REPR(o), css_set, "style");
134 sp_repr_css_attr_unref(css_set);
135 }
137 // setting style on child of clone spills into the clone original (via shared repr), don't do it!
138 if (SP_IS_USE(o))
139 return;
141 for (SPObject *child = sp_object_first_child(SP_OBJECT(o)) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
142 if (sp_repr_css_property(css, "opacity", NULL) != NULL) {
143 // Unset properties which are accumulating and thus should not be set recursively.
144 // For example, setting opacity 0.5 on a group recursively would result in the visible opacity of 0.25 for an item in the group.
145 SPCSSAttr *css_recurse = sp_repr_css_attr_new();
146 sp_repr_css_merge(css_recurse, css);
147 sp_repr_css_set_property(css_recurse, "opacity", NULL);
148 sp_desktop_apply_css_recursive(child, css_recurse, skip_lines);
149 sp_repr_css_attr_unref(css_recurse);
150 } else {
151 sp_desktop_apply_css_recursive(child, css, skip_lines);
152 }
153 }
154 }
156 /**
157 * Apply style on selection on desktop.
158 */
159 void
160 sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write_current)
161 {
162 if (write_current) {
163 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
164 // 1. Set internal value
165 sp_repr_css_merge(desktop->current, css);
167 // 1a. Write to prefs; make a copy and unset any URIs first
168 SPCSSAttr *css_write = sp_repr_css_attr_new();
169 sp_repr_css_merge(css_write, css);
170 sp_css_attr_unset_uris(css_write);
171 prefs->mergeStyle("/desktop/style", css_write);
173 for (const GSList *i = desktop->selection->itemList(); i != NULL; i = i->next) {
174 /* last used styles for 3D box faces are stored separately */
175 if (SP_IS_BOX3D_SIDE (i->data)) {
176 const char * descr = box3d_side_axes_string(SP_BOX3D_SIDE(i->data));
177 if (descr != NULL) {
178 prefs->mergeStyle(Glib::ustring("/desktop/") + descr + "/style", css_write);
179 }
180 }
181 }
182 sp_repr_css_attr_unref(css_write);
183 }
185 if (!change)
186 return;
188 // 2. Emit signal
189 bool intercepted = desktop->_set_style_signal.emit(css);
191 /** \todo
192 * FIXME: in set_style, compensate pattern and gradient fills, stroke width,
193 * rect corners, font size for the object's own transform so that pasting
194 * fills does not depend on preserve/optimize.
195 */
197 // 3. If nobody has intercepted the signal, apply the style to the selection
198 if (!intercepted) {
199 for (GSList const *i = desktop->selection->itemList(); i != NULL; i = i->next) {
200 /// \todo if the style is text-only, apply only to texts?
201 sp_desktop_apply_css_recursive(SP_OBJECT(i->data), css, true);
202 }
203 }
204 }
206 /**
207 * Return the desktop's current style.
208 */
209 SPCSSAttr *
210 sp_desktop_get_style(SPDesktop *desktop, bool with_text)
211 {
212 SPCSSAttr *css = sp_repr_css_attr_new();
213 sp_repr_css_merge(css, desktop->current);
214 if (!css->attributeList()) {
215 sp_repr_css_attr_unref(css);
216 return NULL;
217 } else {
218 if (!with_text) {
219 css = sp_css_attr_unset_text(css);
220 }
221 return css;
222 }
223 }
225 /**
226 * Return the desktop's current color.
227 */
228 guint32
229 sp_desktop_get_color(SPDesktop *desktop, bool is_fill)
230 {
231 guint32 r = 0; // if there's no color, return black
232 gchar const *property = sp_repr_css_property(desktop->current,
233 is_fill ? "fill" : "stroke",
234 "#000");
236 if (desktop->current && property) { // if there is style and the property in it,
237 if (strncmp(property, "url", 3)) { // and if it's not url,
238 // read it
239 r = sp_svg_read_color(property, r);
240 }
241 }
243 return r;
244 }
246 double
247 sp_desktop_get_master_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool, bool *has_opacity)
248 {
249 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
250 SPCSSAttr *css = NULL;
251 gfloat value = 1.0; // default if nothing else found
252 if (has_opacity)
253 *has_opacity = false;
254 if (prefs->getBool(tool + "/usecurrent")) {
255 css = sp_desktop_get_style(desktop, true);
256 } else {
257 css = prefs->getStyle(tool + "/style");
258 }
260 if (css) {
261 gchar const *property = css ? sp_repr_css_property(css, "opacity", "1.000") : 0;
263 if (desktop->current && property) { // if there is style and the property in it,
264 if ( !sp_svg_number_read_f(property, &value) ) {
265 value = 1.0; // things failed. set back to the default
266 } else {
267 if (has_opacity)
268 *has_opacity = false;
269 }
270 }
272 sp_repr_css_attr_unref(css);
273 }
275 return value;
276 }
277 double
278 sp_desktop_get_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool, bool is_fill)
279 {
280 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
281 SPCSSAttr *css = NULL;
282 gfloat value = 1.0; // default if nothing else found
283 if (prefs->getBool(tool + "/usecurrent")) {
284 css = sp_desktop_get_style(desktop, true);
285 } else {
286 css = prefs->getStyle(tool + "/style");
287 }
289 if (css) {
290 gchar const *property = css ? sp_repr_css_property(css, is_fill ? "fill-opacity": "stroke-opacity", "1.000") : 0;
292 if (desktop->current && property) { // if there is style and the property in it,
293 if ( !sp_svg_number_read_f(property, &value) ) {
294 value = 1.0; // things failed. set back to the default
295 }
296 }
298 sp_repr_css_attr_unref(css);
299 }
301 return value;
302 }
304 guint32
305 sp_desktop_get_color_tool(SPDesktop *desktop, Glib::ustring const &tool, bool is_fill, bool *has_color)
306 {
307 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
308 SPCSSAttr *css = NULL;
309 guint32 r = 0; // if there's no color, return black
310 if (has_color)
311 *has_color = false;
312 if (prefs->getBool(tool + "/usecurrent")) {
313 css = sp_desktop_get_style(desktop, true);
314 } else {
315 css = prefs->getStyle(tool + "/style");
316 }
318 if (css) {
319 gchar const *property = sp_repr_css_property(css, is_fill ? "fill" : "stroke", "#000");
321 if (desktop->current && property) { // if there is style and the property in it,
322 if (strncmp(property, "url", 3) && strncmp(property, "none", 4)) { // and if it's not url or none,
323 // read it
324 r = sp_svg_read_color(property, r);
325 if (has_color)
326 *has_color = true;
327 }
328 }
330 sp_repr_css_attr_unref(css);
331 }
333 return r | 0xff;
334 }
336 /**
337 * Apply the desktop's current style or the tool style to repr.
338 */
339 void
340 sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, Glib::ustring const &tool_path, bool with_text)
341 {
342 SPCSSAttr *css_current = sp_desktop_get_style(desktop, with_text);
343 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
345 if (prefs->getBool(tool_path + "/usecurrent") && css_current) {
346 sp_repr_css_set(repr, css_current, "style");
347 } else {
348 SPCSSAttr *css = prefs->getInheritedStyle(tool_path + "/style");
349 sp_repr_css_set(repr, css, "style");
350 sp_repr_css_attr_unref(css);
351 }
352 if (css_current) {
353 sp_repr_css_attr_unref(css_current);
354 }
355 }
357 /**
358 * Returns the font size (in SVG pixels) of the text tool style (if text
359 * tool uses its own style) or desktop style (otherwise).
360 */
361 double
362 sp_desktop_get_font_size_tool(SPDesktop *desktop)
363 {
364 (void)desktop; // TODO cleanup
365 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
366 Glib::ustring desktop_style = prefs->getString("/desktop/style");
367 Glib::ustring style_str;
368 if ((prefs->getBool("/tools/text/usecurrent")) && !desktop_style.empty()) {
369 style_str = desktop_style;
370 } else {
371 style_str = prefs->getString("/tools/text/style");
372 }
374 double ret = 12;
375 if (!style_str.empty()) {
376 SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
377 sp_style_merge_from_style_string(style, style_str.data());
378 ret = style->font_size.computed;
379 sp_style_unref(style);
380 }
381 return ret;
382 }
384 /** Determine average stroke width, simple method */
385 // see TODO in dialogs/stroke-style.cpp on how to get rid of this eventually
386 gdouble
387 stroke_average_width (GSList const *objects)
388 {
389 if (g_slist_length ((GSList *) objects) == 0)
390 return NR_HUGE;
392 gdouble avgwidth = 0.0;
393 bool notstroked = true;
394 int n_notstroked = 0;
396 for (GSList const *l = objects; l != NULL; l = l->next) {
397 if (!SP_IS_ITEM (l->data))
398 continue;
400 Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(l->data));
402 SPObject *object = SP_OBJECT(l->data);
404 if ( object->style->stroke.isNone() ) {
405 ++n_notstroked; // do not count nonstroked objects
406 continue;
407 } else {
408 notstroked = false;
409 }
411 avgwidth += SP_OBJECT_STYLE (object)->stroke_width.computed * i2d.descrim();
412 }
414 if (notstroked)
415 return NR_HUGE;
417 return avgwidth / (g_slist_length ((GSList *) objects) - n_notstroked);
418 }
420 /**
421 * Write to style_res the average fill or stroke of list of objects, if applicable.
422 */
423 int
424 objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill)
425 {
426 if (g_slist_length(objects) == 0) {
427 /* No objects, set empty */
428 return QUERY_STYLE_NOTHING;
429 }
431 SPIPaint *paint_res = isfill? &style_res->fill : &style_res->stroke;
432 bool paintImpossible = true;
433 paint_res->set = TRUE;
435 SVGICCColor* iccColor = 0;
436 SVGDeviceColor* devColor = 0;
438 bool iccSeen = false;
439 gfloat c[4];
440 c[0] = c[1] = c[2] = c[3] = 0.0;
441 gint num = 0;
443 gfloat prev[3];
444 prev[0] = prev[1] = prev[2] = 0.0;
445 bool same_color = true;
447 for (GSList const *i = objects; i != NULL; i = i->next) {
448 SPObject *obj = SP_OBJECT (i->data);
449 SPStyle *style = SP_OBJECT_STYLE (obj);
450 if (!style) continue;
452 SPIPaint *paint = isfill? &style->fill : &style->stroke;
454 // We consider paint "effectively set" for anything within text hierarchy
455 SPObject *parent = SP_OBJECT_PARENT (obj);
456 bool paint_effectively_set =
457 paint->set || (SP_IS_TEXT(parent) || SP_IS_TEXTPATH(parent) || SP_IS_TSPAN(parent)
458 || SP_IS_FLOWTEXT(parent) || SP_IS_FLOWDIV(parent) || SP_IS_FLOWPARA(parent)
459 || SP_IS_FLOWTSPAN(parent) || SP_IS_FLOWLINE(parent));
461 // 1. Bail out with QUERY_STYLE_MULTIPLE_DIFFERENT if necessary
463 if ((!paintImpossible) && (!paint->isSameType(*paint_res) || (paint_res->set != paint_effectively_set))) {
464 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different types of paint
465 }
467 if (paint_res->set && paint->set && paint_res->isPaintserver()) {
468 // both previous paint and this paint were a server, see if the servers are compatible
470 SPPaintServer *server_res = isfill? SP_STYLE_FILL_SERVER (style_res) : SP_STYLE_STROKE_SERVER (style_res);
471 SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER (style) : SP_STYLE_STROKE_SERVER (style);
473 if (SP_IS_LINEARGRADIENT (server_res)) {
475 if (!SP_IS_LINEARGRADIENT(server))
476 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
478 SPGradient *vector = SP_GRADIENT(server)->getVector();
479 SPGradient *vector_res = SP_GRADIENT(server_res)->getVector();
480 if (vector_res != vector)
481 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors
483 } else if (SP_IS_RADIALGRADIENT (server_res)) {
485 if (!SP_IS_RADIALGRADIENT(server))
486 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
488 SPGradient *vector = SP_GRADIENT(server)->getVector();
489 SPGradient *vector_res = SP_GRADIENT(server_res)->getVector();
490 if (vector_res != vector)
491 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors
493 } else if (SP_IS_PATTERN (server_res)) {
495 if (!SP_IS_PATTERN(server))
496 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
498 SPPattern *pat = pattern_getroot (SP_PATTERN (server));
499 SPPattern *pat_res = pattern_getroot (SP_PATTERN (server_res));
500 if (pat_res != pat)
501 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different pattern roots
502 }
503 }
505 // 2. Sum color, copy server from paint to paint_res
507 if (paint_res->set && paint_effectively_set && paint->isColor()) {
508 gfloat d[3];
509 sp_color_get_rgb_floatv (&paint->value.color, d);
511 // Check if this color is the same as previous
512 if (paintImpossible) {
513 prev[0] = d[0];
514 prev[1] = d[1];
515 prev[2] = d[2];
516 paint_res->setColor(d[0], d[1], d[2]);
517 iccColor = paint->value.color.icc;
518 iccSeen = true;
519 } else {
520 if (same_color && (prev[0] != d[0] || prev[1] != d[1] || prev[2] != d[2]))
521 same_color = false;
522 if ( iccSeen ) {
523 if(paint->value.color.icc) {
524 // TODO fix this
525 iccColor = 0;
526 }
527 }
528 }
530 // average color
531 c[0] += d[0];
532 c[1] += d[1];
533 c[2] += d[2];
534 c[3] += SP_SCALE24_TO_FLOAT (isfill? style->fill_opacity.value : style->stroke_opacity.value);
536 // average device color
537 unsigned int it;
538 if (i==objects /*if this is the first object in the GList*/
539 && paint->value.color.device){
540 devColor = new SVGDeviceColor(*paint->value.color.device);
541 for (it=0; it < paint->value.color.device->colors.size(); it++){
542 devColor->colors[it] = 0;
543 }
544 }
546 if (devColor && paint->value.color.device && paint->value.color.device->type == devColor->type){
547 for (it=0; it < paint->value.color.device->colors.size(); it++){
548 devColor->colors[it] += paint->value.color.device->colors[it];
549 }
550 }
552 num ++;
553 }
555 paintImpossible = false;
556 paint_res->colorSet = paint->colorSet;
557 paint_res->currentcolor = paint->currentcolor;
558 if (paint_res->set && paint_effectively_set && paint->isPaintserver()) { // copy the server
559 if (isfill) {
560 sp_style_set_to_uri_string (style_res, true, style->getFillURI());
561 } else {
562 sp_style_set_to_uri_string (style_res, false, style->getStrokeURI());
563 }
564 }
565 paint_res->set = paint_effectively_set;
566 style_res->fill_rule.computed = style->fill_rule.computed; // no averaging on this, just use the last one
567 }
569 // After all objects processed, divide the color if necessary and return
570 if (paint_res->set && paint_res->isColor()) { // set the color
571 g_assert (num >= 1);
573 c[0] /= num;
574 c[1] /= num;
575 c[2] /= num;
576 c[3] /= num;
577 paint_res->setColor(c[0], c[1], c[2]);
578 if (isfill) {
579 style_res->fill_opacity.value = SP_SCALE24_FROM_FLOAT (c[3]);
580 } else {
581 style_res->stroke_opacity.value = SP_SCALE24_FROM_FLOAT (c[3]);
582 }
585 if ( iccSeen && iccColor ) {
586 // TODO check for existing
587 SVGICCColor* tmp = new SVGICCColor(*iccColor);
588 paint_res->value.color.icc = tmp;
589 }
591 // divide and store the device-color
592 if (devColor){
593 for (unsigned int it=0; it < devColor->colors.size(); it++){
594 devColor->colors[it] /= num;
595 }
596 paint_res->value.color.device = devColor;
597 }
599 if (num > 1) {
600 if (same_color)
601 return QUERY_STYLE_MULTIPLE_SAME;
602 else
603 return QUERY_STYLE_MULTIPLE_AVERAGED;
604 } else {
605 return QUERY_STYLE_SINGLE;
606 }
607 }
609 // Not color
610 if (g_slist_length(objects) > 1) {
611 return QUERY_STYLE_MULTIPLE_SAME;
612 } else {
613 return QUERY_STYLE_SINGLE;
614 }
615 }
617 /**
618 * Write to style_res the average opacity of a list of objects.
619 */
620 int
621 objects_query_opacity (GSList *objects, SPStyle *style_res)
622 {
623 if (g_slist_length(objects) == 0) {
624 /* No objects, set empty */
625 return QUERY_STYLE_NOTHING;
626 }
628 gdouble opacity_sum = 0;
629 gdouble opacity_prev = -1;
630 bool same_opacity = true;
631 guint opacity_items = 0;
634 for (GSList const *i = objects; i != NULL; i = i->next) {
635 SPObject *obj = SP_OBJECT (i->data);
636 SPStyle *style = SP_OBJECT_STYLE (obj);
637 if (!style) continue;
639 double opacity = SP_SCALE24_TO_FLOAT(style->opacity.value);
640 opacity_sum += opacity;
641 if (opacity_prev != -1 && opacity != opacity_prev)
642 same_opacity = false;
643 opacity_prev = opacity;
644 opacity_items ++;
645 }
646 if (opacity_items > 1)
647 opacity_sum /= opacity_items;
649 style_res->opacity.value = SP_SCALE24_FROM_FLOAT(opacity_sum);
651 if (opacity_items == 0) {
652 return QUERY_STYLE_NOTHING;
653 } else if (opacity_items == 1) {
654 return QUERY_STYLE_SINGLE;
655 } else {
656 if (same_opacity)
657 return QUERY_STYLE_MULTIPLE_SAME;
658 else
659 return QUERY_STYLE_MULTIPLE_AVERAGED;
660 }
661 }
663 /**
664 * Write to style_res the average stroke width of a list of objects.
665 */
666 int
667 objects_query_strokewidth (GSList *objects, SPStyle *style_res)
668 {
669 if (g_slist_length(objects) == 0) {
670 /* No objects, set empty */
671 return QUERY_STYLE_NOTHING;
672 }
674 gdouble avgwidth = 0.0;
676 gdouble prev_sw = -1;
677 bool same_sw = true;
678 bool noneSet = true; // is stroke set to none?
680 int n_stroked = 0;
682 for (GSList const *i = objects; i != NULL; i = i->next) {
683 SPObject *obj = SP_OBJECT (i->data);
684 if (!SP_IS_ITEM(obj)) continue;
685 SPStyle *style = SP_OBJECT_STYLE (obj);
686 if (!style) continue;
688 if ( style->stroke.isNone() && !(
689 style->marker[SP_MARKER_LOC].set || // stroke width affects markers, so if there's no stroke but only markers then we should
690 style->marker[SP_MARKER_LOC_START].set || // still calculate the stroke width
691 style->marker[SP_MARKER_LOC_MID].set ||
692 style->marker[SP_MARKER_LOC_END].set))
693 {
694 continue;
695 }
697 n_stroked ++;
699 noneSet &= style->stroke.isNone();
701 Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
702 double sw = style->stroke_width.computed * i2d.descrim();
704 if (prev_sw != -1 && fabs(sw - prev_sw) > 1e-3)
705 same_sw = false;
706 prev_sw = sw;
708 avgwidth += sw;
709 }
711 if (n_stroked > 1)
712 avgwidth /= (n_stroked);
714 style_res->stroke_width.computed = avgwidth;
715 style_res->stroke_width.set = true;
716 style_res->stroke.noneSet = noneSet; // Will only be true if none of the selected objects has it's stroke set.
718 if (n_stroked == 0) {
719 return QUERY_STYLE_NOTHING;
720 } else if (n_stroked == 1) {
721 return QUERY_STYLE_SINGLE;
722 } else {
723 if (same_sw)
724 return QUERY_STYLE_MULTIPLE_SAME;
725 else
726 return QUERY_STYLE_MULTIPLE_AVERAGED;
727 }
728 }
730 /**
731 * Write to style_res the average miter limit of a list of objects.
732 */
733 int
734 objects_query_miterlimit (GSList *objects, SPStyle *style_res)
735 {
736 if (g_slist_length(objects) == 0) {
737 /* No objects, set empty */
738 return QUERY_STYLE_NOTHING;
739 }
741 gdouble avgml = 0.0;
742 int n_stroked = 0;
744 gdouble prev_ml = -1;
745 bool same_ml = true;
747 for (GSList const *i = objects; i != NULL; i = i->next) {
748 SPObject *obj = SP_OBJECT (i->data);
749 if (!SP_IS_ITEM(obj)) continue;
750 SPStyle *style = SP_OBJECT_STYLE (obj);
751 if (!style) continue;
753 if ( style->stroke.isNone() ) {
754 continue;
755 }
757 n_stroked ++;
759 if (prev_ml != -1 && fabs(style->stroke_miterlimit.value - prev_ml) > 1e-3)
760 same_ml = false;
761 prev_ml = style->stroke_miterlimit.value;
763 avgml += style->stroke_miterlimit.value;
764 }
766 if (n_stroked > 1)
767 avgml /= (n_stroked);
769 style_res->stroke_miterlimit.value = avgml;
770 style_res->stroke_miterlimit.set = true;
772 if (n_stroked == 0) {
773 return QUERY_STYLE_NOTHING;
774 } else if (n_stroked == 1) {
775 return QUERY_STYLE_SINGLE;
776 } else {
777 if (same_ml)
778 return QUERY_STYLE_MULTIPLE_SAME;
779 else
780 return QUERY_STYLE_MULTIPLE_AVERAGED;
781 }
782 }
784 /**
785 * Write to style_res the stroke cap of a list of objects.
786 */
787 int
788 objects_query_strokecap (GSList *objects, SPStyle *style_res)
789 {
790 if (g_slist_length(objects) == 0) {
791 /* No objects, set empty */
792 return QUERY_STYLE_NOTHING;
793 }
795 int cap = -1;
796 gdouble prev_cap = -1;
797 bool same_cap = true;
798 int n_stroked = 0;
800 for (GSList const *i = objects; i != NULL; i = i->next) {
801 SPObject *obj = SP_OBJECT (i->data);
802 if (!SP_IS_ITEM(obj)) continue;
803 SPStyle *style = SP_OBJECT_STYLE (obj);
804 if (!style) continue;
806 if ( style->stroke.isNone() ) {
807 continue;
808 }
810 n_stroked ++;
812 if (prev_cap != -1 && style->stroke_linecap.value != prev_cap)
813 same_cap = false;
814 prev_cap = style->stroke_linecap.value;
816 cap = style->stroke_linecap.value;
817 }
819 style_res->stroke_linecap.value = cap;
820 style_res->stroke_linecap.set = true;
822 if (n_stroked == 0) {
823 return QUERY_STYLE_NOTHING;
824 } else if (n_stroked == 1) {
825 return QUERY_STYLE_SINGLE;
826 } else {
827 if (same_cap)
828 return QUERY_STYLE_MULTIPLE_SAME;
829 else
830 return QUERY_STYLE_MULTIPLE_DIFFERENT;
831 }
832 }
834 /**
835 * Write to style_res the stroke join of a list of objects.
836 */
837 int
838 objects_query_strokejoin (GSList *objects, SPStyle *style_res)
839 {
840 if (g_slist_length(objects) == 0) {
841 /* No objects, set empty */
842 return QUERY_STYLE_NOTHING;
843 }
845 int join = -1;
846 gdouble prev_join = -1;
847 bool same_join = true;
848 int n_stroked = 0;
850 for (GSList const *i = objects; i != NULL; i = i->next) {
851 SPObject *obj = SP_OBJECT (i->data);
852 if (!SP_IS_ITEM(obj)) continue;
853 SPStyle *style = SP_OBJECT_STYLE (obj);
854 if (!style) continue;
856 if ( style->stroke.isNone() ) {
857 continue;
858 }
860 n_stroked ++;
862 if (prev_join != -1 && style->stroke_linejoin.value != prev_join)
863 same_join = false;
864 prev_join = style->stroke_linejoin.value;
866 join = style->stroke_linejoin.value;
867 }
869 style_res->stroke_linejoin.value = join;
870 style_res->stroke_linejoin.set = true;
872 if (n_stroked == 0) {
873 return QUERY_STYLE_NOTHING;
874 } else if (n_stroked == 1) {
875 return QUERY_STYLE_SINGLE;
876 } else {
877 if (same_join)
878 return QUERY_STYLE_MULTIPLE_SAME;
879 else
880 return QUERY_STYLE_MULTIPLE_DIFFERENT;
881 }
882 }
884 /**
885 * Write to style_res the average font size and spacing of objects.
886 */
887 int
888 objects_query_fontnumbers (GSList *objects, SPStyle *style_res)
889 {
890 bool different = false;
892 double size = 0;
893 double letterspacing = 0;
894 double wordspacing = 0;
895 double linespacing = 0;
896 bool letterspacing_normal = false;
897 bool wordspacing_normal = false;
898 bool linespacing_normal = false;
900 double size_prev = 0;
901 double letterspacing_prev = 0;
902 double wordspacing_prev = 0;
903 double linespacing_prev = 0;
905 int texts = 0;
907 for (GSList const *i = objects; i != NULL; i = i->next) {
908 SPObject *obj = SP_OBJECT (i->data);
910 if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
911 && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
912 && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
913 continue;
915 SPStyle *style = SP_OBJECT_STYLE (obj);
916 if (!style) continue;
918 texts ++;
919 size += style->font_size.computed * Geom::Matrix(sp_item_i2d_affine(SP_ITEM(obj))).descrim(); /// \todo FIXME: we assume non-% units here
921 if (style->letter_spacing.normal) {
922 if (!different && (letterspacing_prev == 0 || letterspacing_prev == letterspacing))
923 letterspacing_normal = true;
924 } else {
925 letterspacing += style->letter_spacing.computed; /// \todo FIXME: we assume non-% units here
926 letterspacing_normal = false;
927 }
929 if (style->word_spacing.normal) {
930 if (!different && (wordspacing_prev == 0 || wordspacing_prev == wordspacing))
931 wordspacing_normal = true;
932 } else {
933 wordspacing += style->word_spacing.computed; /// \todo FIXME: we assume non-% units here
934 wordspacing_normal = false;
935 }
937 double linespacing_current;
938 if (style->line_height.normal) {
939 linespacing_current = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
940 if (!different && (linespacing_prev == 0 || linespacing_prev == linespacing_current))
941 linespacing_normal = true;
942 } else if (style->line_height.unit == SP_CSS_UNIT_PERCENT || style->font_size.computed == 0) {
943 linespacing_current = style->line_height.value;
944 linespacing_normal = false;
945 } else { // we need % here
946 linespacing_current = style->line_height.computed / style->font_size.computed;
947 linespacing_normal = false;
948 }
949 linespacing += linespacing_current;
951 if ((size_prev != 0 && style->font_size.computed != size_prev) ||
952 (letterspacing_prev != 0 && style->letter_spacing.computed != letterspacing_prev) ||
953 (wordspacing_prev != 0 && style->word_spacing.computed != wordspacing_prev) ||
954 (linespacing_prev != 0 && linespacing_current != linespacing_prev)) {
955 different = true;
956 }
958 size_prev = style->font_size.computed;
959 letterspacing_prev = style->letter_spacing.computed;
960 wordspacing_prev = style->word_spacing.computed;
961 linespacing_prev = linespacing_current;
963 // FIXME: we must detect MULTIPLE_DIFFERENT for these too
964 style_res->text_anchor.computed = style->text_anchor.computed;
965 style_res->writing_mode.computed = style->writing_mode.computed;
966 }
968 if (texts == 0)
969 return QUERY_STYLE_NOTHING;
971 if (texts > 1) {
972 size /= texts;
973 letterspacing /= texts;
974 wordspacing /= texts;
975 linespacing /= texts;
976 }
978 style_res->font_size.computed = size;
979 style_res->font_size.type = SP_FONT_SIZE_LENGTH;
981 style_res->letter_spacing.normal = letterspacing_normal;
982 style_res->letter_spacing.computed = letterspacing;
984 style_res->word_spacing.normal = wordspacing_normal;
985 style_res->word_spacing.computed = wordspacing;
987 style_res->line_height.normal = linespacing_normal;
988 style_res->line_height.computed = linespacing;
989 style_res->line_height.value = linespacing;
990 style_res->line_height.unit = SP_CSS_UNIT_PERCENT;
992 if (texts > 1) {
993 if (different) {
994 return QUERY_STYLE_MULTIPLE_AVERAGED;
995 } else {
996 return QUERY_STYLE_MULTIPLE_SAME;
997 }
998 } else {
999 return QUERY_STYLE_SINGLE;
1000 }
1001 }
1003 /**
1004 * Write to style_res the average font style of objects.
1005 */
1006 int
1007 objects_query_fontstyle (GSList *objects, SPStyle *style_res)
1008 {
1009 bool different = false;
1010 bool set = false;
1012 int texts = 0;
1014 for (GSList const *i = objects; i != NULL; i = i->next) {
1015 SPObject *obj = SP_OBJECT (i->data);
1017 if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
1018 && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
1019 && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
1020 continue;
1022 SPStyle *style = SP_OBJECT_STYLE (obj);
1023 if (!style) continue;
1025 texts ++;
1027 if (set &&
1028 font_style_to_pos(*style_res).signature() != font_style_to_pos(*style).signature() ) {
1029 different = true; // different styles
1030 }
1032 set = TRUE;
1033 style_res->font_weight.value = style_res->font_weight.computed = style->font_weight.computed;
1034 style_res->font_style.value = style_res->font_style.computed = style->font_style.computed;
1035 style_res->font_stretch.value = style_res->font_stretch.computed = style->font_stretch.computed;
1036 style_res->font_variant.value = style_res->font_variant.computed = style->font_variant.computed;
1037 style_res->text_align.value = style_res->text_align.computed = style->text_align.computed;
1038 }
1040 if (texts == 0 || !set)
1041 return QUERY_STYLE_NOTHING;
1043 if (texts > 1) {
1044 if (different) {
1045 return QUERY_STYLE_MULTIPLE_DIFFERENT;
1046 } else {
1047 return QUERY_STYLE_MULTIPLE_SAME;
1048 }
1049 } else {
1050 return QUERY_STYLE_SINGLE;
1051 }
1052 }
1054 /**
1055 * Write to style_res the average font family of objects.
1056 */
1057 int
1058 objects_query_fontfamily (GSList *objects, SPStyle *style_res)
1059 {
1060 bool different = false;
1061 int texts = 0;
1063 if (style_res->text->font_family.value) {
1064 g_free(style_res->text->font_family.value);
1065 style_res->text->font_family.value = NULL;
1066 }
1067 style_res->text->font_family.set = FALSE;
1069 for (GSList const *i = objects; i != NULL; i = i->next) {
1070 SPObject *obj = SP_OBJECT (i->data);
1072 // std::cout << " " << SP_OBJECT_ID (i->data) << std::endl;
1073 if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
1074 && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
1075 && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
1076 continue;
1078 SPStyle *style = SP_OBJECT_STYLE (obj);
1079 if (!style) continue;
1081 texts ++;
1083 if (style_res->text->font_family.value && style->text->font_family.value &&
1084 strcmp (style_res->text->font_family.value, style->text->font_family.value)) {
1085 different = true; // different fonts
1086 }
1088 if (style_res->text->font_family.value) {
1089 g_free(style_res->text->font_family.value);
1090 style_res->text->font_family.value = NULL;
1091 }
1093 style_res->text->font_family.set = TRUE;
1094 style_res->text->font_family.value = g_strdup(style->text->font_family.value);
1095 }
1097 if (texts == 0 || !style_res->text->font_family.set)
1098 return QUERY_STYLE_NOTHING;
1100 if (texts > 1) {
1101 if (different) {
1102 return QUERY_STYLE_MULTIPLE_DIFFERENT;
1103 } else {
1104 return QUERY_STYLE_MULTIPLE_SAME;
1105 }
1106 } else {
1107 return QUERY_STYLE_SINGLE;
1108 }
1109 }
1111 int
1112 objects_query_fontspecification (GSList *objects, SPStyle *style_res)
1113 {
1114 bool different = false;
1115 int texts = 0;
1117 if (style_res->text->font_specification.value) {
1118 g_free(style_res->text->font_specification.value);
1119 style_res->text->font_specification.value = NULL;
1120 }
1121 style_res->text->font_specification.set = FALSE;
1123 for (GSList const *i = objects; i != NULL; i = i->next) {
1124 SPObject *obj = SP_OBJECT (i->data);
1126 // std::cout << " " << SP_OBJECT_ID (i->data) << std::endl;
1127 if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
1128 && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
1129 && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
1130 continue;
1132 SPStyle *style = SP_OBJECT_STYLE (obj);
1133 if (!style) continue;
1135 texts ++;
1137 if (style_res->text->font_specification.value && style_res->text->font_specification.set &&
1138 style->text->font_specification.value && style->text->font_specification.set &&
1139 strcmp (style_res->text->font_specification.value, style->text->font_specification.value)) {
1140 different = true; // different fonts
1141 }
1143 if (style->text->font_specification.set) {
1145 if (style_res->text->font_specification.value) {
1146 g_free(style_res->text->font_specification.value);
1147 style_res->text->font_specification.value = NULL;
1148 }
1150 style_res->text->font_specification.set = TRUE;
1151 style_res->text->font_specification.value = g_strdup(style->text->font_specification.value);
1152 }
1153 }
1155 if (texts == 0)
1156 return QUERY_STYLE_NOTHING;
1158 if (texts > 1) {
1159 if (different) {
1160 return QUERY_STYLE_MULTIPLE_DIFFERENT;
1161 } else {
1162 return QUERY_STYLE_MULTIPLE_SAME;
1163 }
1164 } else {
1165 return QUERY_STYLE_SINGLE;
1166 }
1167 }
1169 int
1170 objects_query_blend (GSList *objects, SPStyle *style_res)
1171 {
1172 const int empty_prev = -2;
1173 const int complex_filter = 5;
1174 int blend = 0;
1175 float blend_prev = empty_prev;
1176 bool same_blend = true;
1177 guint items = 0;
1179 for (GSList const *i = objects; i != NULL; i = i->next) {
1180 SPObject *obj = SP_OBJECT (i->data);
1181 SPStyle *style = SP_OBJECT_STYLE (obj);
1182 if(!style || !SP_IS_ITEM(obj)) continue;
1184 items++;
1186 //if object has a filter
1187 if (style->filter.set && style->getFilter()) {
1188 int blurcount = 0;
1189 int blendcount = 0;
1191 // determine whether filter is simple (blend and/or blur) or complex
1192 for(SPObject *primitive_obj = style->getFilter()->children;
1193 primitive_obj && SP_IS_FILTER_PRIMITIVE(primitive_obj);
1194 primitive_obj = primitive_obj->next) {
1195 SPFilterPrimitive *primitive = SP_FILTER_PRIMITIVE(primitive_obj);
1196 if(SP_IS_FEBLEND(primitive))
1197 ++blendcount;
1198 else if(SP_IS_GAUSSIANBLUR(primitive))
1199 ++blurcount;
1200 else {
1201 blurcount = complex_filter;
1202 break;
1203 }
1204 }
1206 // simple filter
1207 if(blurcount == 1 || blendcount == 1) {
1208 for(SPObject *primitive_obj = style->getFilter()->children;
1209 primitive_obj && SP_IS_FILTER_PRIMITIVE(primitive_obj);
1210 primitive_obj = primitive_obj->next) {
1211 if(SP_IS_FEBLEND(primitive_obj)) {
1212 SPFeBlend *spblend = SP_FEBLEND(primitive_obj);
1213 blend = spblend->blend_mode;
1214 }
1215 }
1216 }
1217 else {
1218 blend = complex_filter;
1219 }
1220 }
1221 // defaults to blend mode = "normal"
1222 else {
1223 blend = 0;
1224 }
1226 if(blend_prev != empty_prev && blend_prev != blend)
1227 same_blend = false;
1228 blend_prev = blend;
1229 }
1231 if (items > 0) {
1232 style_res->filter_blend_mode.value = blend;
1233 }
1235 if (items == 0) {
1236 return QUERY_STYLE_NOTHING;
1237 } else if (items == 1) {
1238 return QUERY_STYLE_SINGLE;
1239 } else {
1240 if(same_blend)
1241 return QUERY_STYLE_MULTIPLE_SAME;
1242 else
1243 return QUERY_STYLE_MULTIPLE_DIFFERENT;
1244 }
1245 }
1247 /**
1248 * Write to style_res the average blurring of a list of objects.
1249 */
1250 int
1251 objects_query_blur (GSList *objects, SPStyle *style_res)
1252 {
1253 if (g_slist_length(objects) == 0) {
1254 /* No objects, set empty */
1255 return QUERY_STYLE_NOTHING;
1256 }
1258 float blur_sum = 0;
1259 float blur_prev = -1;
1260 bool same_blur = true;
1261 guint blur_items = 0;
1262 guint items = 0;
1264 for (GSList const *i = objects; i != NULL; i = i->next) {
1265 SPObject *obj = SP_OBJECT (i->data);
1266 SPStyle *style = SP_OBJECT_STYLE (obj);
1267 if (!style) continue;
1268 if (!SP_IS_ITEM(obj)) continue;
1270 Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
1272 items ++;
1274 //if object has a filter
1275 if (style->filter.set && style->getFilter()) {
1276 //cycle through filter primitives
1277 SPObject *primitive_obj = style->getFilter()->children;
1278 while (primitive_obj) {
1279 if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
1280 SPFilterPrimitive *primitive = SP_FILTER_PRIMITIVE(primitive_obj);
1282 //if primitive is gaussianblur
1283 if(SP_IS_GAUSSIANBLUR(primitive)) {
1284 SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
1285 float num = spblur->stdDeviation.getNumber();
1286 blur_sum += num * i2d.descrim();
1287 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
1288 same_blur = false;
1289 blur_prev = num;
1290 //TODO: deal with opt number, for the moment it's not necessary to the ui.
1291 blur_items ++;
1292 }
1293 }
1294 primitive_obj = primitive_obj->next;
1295 }
1296 }
1297 }
1299 if (items > 0) {
1300 if (blur_items > 0)
1301 blur_sum /= blur_items;
1302 style_res->filter_gaussianBlur_deviation.value = blur_sum;
1303 }
1305 if (items == 0) {
1306 return QUERY_STYLE_NOTHING;
1307 } else if (items == 1) {
1308 return QUERY_STYLE_SINGLE;
1309 } else {
1310 if (same_blur)
1311 return QUERY_STYLE_MULTIPLE_SAME;
1312 else
1313 return QUERY_STYLE_MULTIPLE_AVERAGED;
1314 }
1315 }
1317 /**
1318 * Query the given list of objects for the given property, write
1319 * the result to style, return appropriate flag.
1320 */
1321 int
1322 sp_desktop_query_style_from_list (GSList *list, SPStyle *style, int property)
1323 {
1324 if (property == QUERY_STYLE_PROPERTY_FILL) {
1325 return objects_query_fillstroke (list, style, true);
1326 } else if (property == QUERY_STYLE_PROPERTY_STROKE) {
1327 return objects_query_fillstroke (list, style, false);
1329 } else if (property == QUERY_STYLE_PROPERTY_STROKEWIDTH) {
1330 return objects_query_strokewidth (list, style);
1331 } else if (property == QUERY_STYLE_PROPERTY_STROKEMITERLIMIT) {
1332 return objects_query_miterlimit (list, style);
1333 } else if (property == QUERY_STYLE_PROPERTY_STROKECAP) {
1334 return objects_query_strokecap (list, style);
1335 } else if (property == QUERY_STYLE_PROPERTY_STROKEJOIN) {
1336 return objects_query_strokejoin (list, style);
1338 } else if (property == QUERY_STYLE_PROPERTY_MASTEROPACITY) {
1339 return objects_query_opacity (list, style);
1341 } else if (property == QUERY_STYLE_PROPERTY_FONT_SPECIFICATION) {
1342 return objects_query_fontspecification (list, style);
1343 } else if (property == QUERY_STYLE_PROPERTY_FONTFAMILY) {
1344 return objects_query_fontfamily (list, style);
1345 } else if (property == QUERY_STYLE_PROPERTY_FONTSTYLE) {
1346 return objects_query_fontstyle (list, style);
1347 } else if (property == QUERY_STYLE_PROPERTY_FONTNUMBERS) {
1348 return objects_query_fontnumbers (list, style);
1350 } else if (property == QUERY_STYLE_PROPERTY_BLEND) {
1351 return objects_query_blend (list, style);
1352 } else if (property == QUERY_STYLE_PROPERTY_BLUR) {
1353 return objects_query_blur (list, style);
1354 }
1355 return QUERY_STYLE_NOTHING;
1356 }
1359 /**
1360 * Query the subselection (if any) or selection on the given desktop for the given property, write
1361 * the result to style, return appropriate flag.
1362 */
1363 int
1364 sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property)
1365 {
1366 int ret = desktop->_query_style_signal.emit(style, property);
1368 if (ret != QUERY_STYLE_NOTHING)
1369 return ret; // subselection returned a style, pass it on
1371 // otherwise, do querying and averaging over selection
1372 if (desktop->selection != NULL) {
1373 return sp_desktop_query_style_from_list ((GSList *) desktop->selection->itemList(), style, property);
1374 }
1376 return QUERY_STYLE_NOTHING;
1377 }
1379 /**
1380 * Do the same as sp_desktop_query_style for all (defined) style properties, return true if at
1381 * least one of the properties did not return QUERY_STYLE_NOTHING.
1382 */
1383 bool
1384 sp_desktop_query_style_all (SPDesktop *desktop, SPStyle *query)
1385 {
1386 int result_family = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
1387 int result_fstyle = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
1388 int result_fnumbers = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
1389 int result_fill = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_FILL);
1390 int result_stroke = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKE);
1391 int result_strokewidth = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
1392 int result_strokemiterlimit = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
1393 int result_strokecap = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKECAP);
1394 int result_strokejoin = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
1395 int result_opacity = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
1396 int result_blur = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_BLUR);
1398 return (result_family != QUERY_STYLE_NOTHING ||
1399 result_fstyle != QUERY_STYLE_NOTHING ||
1400 result_fnumbers != QUERY_STYLE_NOTHING ||
1401 result_fill != QUERY_STYLE_NOTHING ||
1402 result_stroke != QUERY_STYLE_NOTHING ||
1403 result_opacity != QUERY_STYLE_NOTHING ||
1404 result_strokewidth != QUERY_STYLE_NOTHING ||
1405 result_strokemiterlimit != QUERY_STYLE_NOTHING ||
1406 result_strokecap != QUERY_STYLE_NOTHING ||
1407 result_strokejoin != QUERY_STYLE_NOTHING ||
1408 result_blur != QUERY_STYLE_NOTHING);
1409 }
1412 /*
1413 Local Variables:
1414 mode:c++
1415 c-file-style:"stroustrup"
1416 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1417 indent-tabs-mode:nil
1418 fill-column:99
1419 End:
1420 */
1421 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :