121
121
// Scale the style by the inverse of the accumulated parent transform in the paste context.
123
NR::Matrix const local(sp_item_i2doc_affine(SP_ITEM(o)));
124
double const ex(NR::expansion(local));
123
Geom::Matrix const local(sp_item_i2doc_affine(SP_ITEM(o)));
124
double const ex(local.descrim());
125
125
if ( ( ex != 0. )
126
126
&& ( ex != 1. ) ) {
127
127
sp_css_attr_scale(css_set, 1/ex);
159
159
sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write_current)
161
161
if (write_current) {
162
// 1. Set internal value
162
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
163
// 1. Set internal value
163
164
sp_repr_css_merge(desktop->current, css);
165
// 1a. Write to prefs; make a copy and unset any URIs first
166
// 1a. Write to prefs; make a copy and unset any URIs first
166
167
SPCSSAttr *css_write = sp_repr_css_attr_new();
167
168
sp_repr_css_merge(css_write, css);
168
169
sp_css_attr_unset_uris(css_write);
169
sp_repr_css_change(inkscape_get_repr(INKSCAPE, "desktop"), css_write, "style");
170
prefs->mergeStyle("/desktop/style", css_write);
170
172
for (const GSList *i = desktop->selection->itemList(); i != NULL; i = i->next) {
171
173
/* last used styles for 3D box faces are stored separately */
172
174
if (SP_IS_BOX3D_SIDE (i->data)) {
173
175
const char * descr = box3d_side_axes_string(SP_BOX3D_SIDE(i->data));
174
176
if (descr != NULL) {
175
gchar *style_grp = g_strconcat ("desktop.", descr, NULL);
176
sp_repr_css_change(inkscape_get_repr(INKSCAPE, style_grp), css_write, "style");
177
prefs->mergeStyle(Glib::ustring("/desktop/") + descr + "/style", css_write);
246
sp_desktop_get_master_opacity_tool(SPDesktop *desktop, char const *tool)
246
sp_desktop_get_master_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool, bool *has_opacity)
248
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
248
249
SPCSSAttr *css = NULL;
249
250
gfloat value = 1.0; // default if nothing else found
250
if (prefs_get_double_attribute(tool, "usecurrent", 0) != 0) {
252
*has_opacity = false;
253
if (prefs->getBool(tool + "/usecurrent")) {
251
254
css = sp_desktop_get_style(desktop, true);
253
Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
255
css = sp_repr_css_attr_inherited(tool_repr, "style");
256
css = prefs->getStyle(tool + "/style");
260
260
gchar const *property = css ? sp_repr_css_property(css, "opacity", "1.000") : 0;
262
262
if (desktop->current && property) { // if there is style and the property in it,
263
263
if ( !sp_svg_number_read_f(property, &value) ) {
264
264
value = 1.0; // things failed. set back to the default
267
*has_opacity = false;
274
sp_desktop_get_opacity_tool(SPDesktop *desktop, char const *tool, bool is_fill)
277
sp_desktop_get_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool, bool is_fill)
279
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
276
280
SPCSSAttr *css = NULL;
277
281
gfloat value = 1.0; // default if nothing else found
278
if (prefs_get_double_attribute(tool, "usecurrent", 0) != 0) {
282
if (prefs->getBool(tool + "/usecurrent")) {
279
283
css = sp_desktop_get_style(desktop, true);
281
Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
283
css = sp_repr_css_attr_inherited(tool_repr, "style");
285
css = prefs->getStyle(tool + "/style");
288
289
gchar const *property = css ? sp_repr_css_property(css, is_fill ? "fill-opacity": "stroke-opacity", "1.000") : 0;
290
291
if (desktop->current && property) { // if there is style and the property in it,
291
292
if ( !sp_svg_number_read_f(property, &value) ) {
292
293
value = 1.0; // things failed. set back to the default
302
sp_desktop_get_color_tool(SPDesktop *desktop, char const *tool, bool is_fill)
304
sp_desktop_get_color_tool(SPDesktop *desktop, Glib::ustring const &tool, bool is_fill, bool *has_color)
306
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
304
307
SPCSSAttr *css = NULL;
305
308
guint32 r = 0; // if there's no color, return black
306
if (prefs_get_int_attribute(tool, "usecurrent", 0) != 0) {
311
if (prefs->getBool(tool + "/usecurrent")) {
307
312
css = sp_desktop_get_style(desktop, true);
309
Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
311
css = sp_repr_css_attr_inherited(tool_repr, "style");
314
css = prefs->getStyle(tool + "/style");
316
318
gchar const *property = sp_repr_css_property(css, is_fill ? "fill" : "stroke", "#000");
318
320
if (desktop->current && property) { // if there is style and the property in it,
319
if (strncmp(property, "url", 3)) { // and if it's not url,
321
if (strncmp(property, "url", 3) && strncmp(property, "none", 4)) { // and if it's not url or none,
321
323
r = sp_svg_read_color(property, r);
331
336
* Apply the desktop's current style or the tool style to repr.
334
sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, char const *tool, bool with_text)
339
sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, Glib::ustring const &tool_path, bool with_text)
336
341
SPCSSAttr *css_current = sp_desktop_get_style(desktop, with_text);
337
if ((prefs_get_int_attribute(tool, "usecurrent", 0) != 0) && css_current) {
342
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
344
if (prefs->getBool(tool_path + "/usecurrent") && css_current) {
338
345
sp_repr_css_set(repr, css_current, "style");
340
Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
342
SPCSSAttr *css = sp_repr_css_attr_inherited(tool_repr, "style");
343
sp_repr_css_set(repr, css, "style");
344
sp_repr_css_attr_unref(css);
347
SPCSSAttr *css = prefs->getStyle(tool_path + "/style");
348
sp_repr_css_set(repr, css, "style");
349
sp_repr_css_attr_unref(css);
347
351
if (css_current) {
348
352
sp_repr_css_attr_unref(css_current);
357
361
sp_desktop_get_font_size_tool(SPDesktop *desktop)
359
363
(void)desktop; // TODO cleanup
360
gchar const *desktop_style = inkscape_get_repr(INKSCAPE, "desktop")->attribute("style");
361
gchar const *style_str = NULL;
362
if ((prefs_get_int_attribute("tools.text", "usecurrent", 0) != 0) && desktop_style) {
364
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
365
Glib::ustring desktop_style = prefs->getString("/desktop/style");
366
Glib::ustring style_str;
367
if ((prefs->getBool("/tools/text/usecurrent")) && !desktop_style.empty()) {
363
368
style_str = desktop_style;
365
Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, "tools.text");
367
style_str = tool_repr->attribute("style");
370
style_str = prefs->getString("/tools/text/style");
374
if (!style_str.empty()) {
373
375
SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
374
sp_style_merge_from_style_string(style, style_str);
376
sp_style_merge_from_style_string(style, style_str.data());
375
377
ret = style->font_size.computed;
376
378
sp_style_unref(style);
654
657
SPStyle *style = SP_OBJECT_STYLE (obj);
655
658
if (!style) continue;
657
if ( style->stroke.isNone() ) {
660
if ( style->stroke.isNone() && !(
661
style->marker[SP_MARKER_LOC].set || // stroke width affects markers, so if there's no stroke but only markers then we should
662
style->marker[SP_MARKER_LOC_START].set || // still calculate the stroke width
663
style->marker[SP_MARKER_LOC_MID].set ||
664
style->marker[SP_MARKER_LOC_END].set))
663
NR::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
664
double sw = style->stroke_width.computed * i2d.expansion();
671
noneSet &= style->stroke.isNone();
673
Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
674
double sw = style->stroke_width.computed * i2d.descrim();
666
676
if (prev_sw != -1 && fabs(sw - prev_sw) > 1e-3)
676
686
style_res->stroke_width.computed = avgwidth;
677
687
style_res->stroke_width.set = true;
688
style_res->stroke.noneSet = noneSet; // Will only be true if none of the selected objects has it's stroke set.
679
690
if (n_stroked == 0) {
680
691
return QUERY_STYLE_NOTHING;
876
887
if (!style) continue;
879
size += style->font_size.computed * NR::expansion(sp_item_i2d_affine(SP_ITEM(obj))); /// \todo FIXME: we assume non-% units here
890
size += style->font_size.computed * Geom::Matrix(sp_item_i2d_affine(SP_ITEM(obj))).descrim(); /// \todo FIXME: we assume non-% units here
881
892
if (style->letter_spacing.normal) {
882
893
if (!different && (letterspacing_prev == 0 || letterspacing_prev == letterspacing))
1081
if (style_res->text->font_specification.value && style_res->text->font_specification.set &&
1092
if (style_res->text->font_specification.value && style_res->text->font_specification.set &&
1082
1093
style->text->font_specification.value && style->text->font_specification.set &&
1083
1094
strcmp (style_res->text->font_specification.value, style->text->font_specification.value)) {
1084
1095
different = true; // different fonts
1087
1098
if (style->text->font_specification.set) {
1089
1100
if (style_res->text->font_specification.value) {
1090
1101
g_free(style_res->text->font_specification.value);
1091
1102
style_res->text->font_specification.value = NULL;
1094
1105
style_res->text->font_specification.set = TRUE;
1095
1106
style_res->text->font_specification.value = g_strdup(style->text->font_specification.value);
1204
1215
bool same_blur = true;
1205
1216
guint blur_items = 0;
1206
1217
guint items = 0;
1208
1219
for (GSList const *i = objects; i != NULL; i = i->next) {
1209
1220
SPObject *obj = SP_OBJECT (i->data);
1210
1221
SPStyle *style = SP_OBJECT_STYLE (obj);
1211
1222
if (!style) continue;
1212
1223
if (!SP_IS_ITEM(obj)) continue;
1214
NR::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
1225
Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
1222
1233
while (primitive_obj) {
1223
1234
if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
1224
1235
SPFilterPrimitive *primitive = SP_FILTER_PRIMITIVE(primitive_obj);
1226
1237
//if primitive is gaussianblur
1227
1238
if(SP_IS_GAUSSIANBLUR(primitive)) {
1228
1239
SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
1229
1240
float num = spblur->stdDeviation.getNumber();
1230
blur_sum += num * NR::expansion(i2d);
1241
blur_sum += num * i2d.descrim();
1231
1242
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
1232
1243
same_blur = false;
1233
1244
blur_prev = num;
1282
1293
} else if (property == QUERY_STYLE_PROPERTY_MASTEROPACITY) {
1283
1294
return objects_query_opacity (list, style);
1285
1296
} else if (property == QUERY_STYLE_PROPERTY_FONT_SPECIFICATION) {
1286
1297
return objects_query_fontspecification (list, style);
1287
1298
} else if (property == QUERY_STYLE_PROPERTY_FONTFAMILY) {
1313
1324
return ret; // subselection returned a style, pass it on
1315
1326
// otherwise, do querying and averaging over selection
1316
return sp_desktop_query_style_from_list ((GSList *) desktop->selection->itemList(), style, property);
1327
if (desktop->selection != NULL) {
1328
return sp_desktop_query_style_from_list ((GSList *) desktop->selection->itemList(), style, property);
1331
return QUERY_STYLE_NOTHING;
1320
* Do the same as sp_desktop_query_style for all (defined) style properties, return true if at
1335
* Do the same as sp_desktop_query_style for all (defined) style properties, return true if at
1321
1336
* least one of the properties did not return QUERY_STYLE_NOTHING.
1334
1349
int result_strokejoin = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
1335
1350
int result_opacity = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
1336
1351
int result_blur = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_BLUR);
1338
return (result_family != QUERY_STYLE_NOTHING ||
1339
result_fstyle != QUERY_STYLE_NOTHING ||
1340
result_fnumbers != QUERY_STYLE_NOTHING ||
1341
result_fill != QUERY_STYLE_NOTHING ||
1342
result_stroke != QUERY_STYLE_NOTHING ||
1343
result_opacity != QUERY_STYLE_NOTHING ||
1344
result_strokewidth != QUERY_STYLE_NOTHING ||
1353
return (result_family != QUERY_STYLE_NOTHING ||
1354
result_fstyle != QUERY_STYLE_NOTHING ||
1355
result_fnumbers != QUERY_STYLE_NOTHING ||
1356
result_fill != QUERY_STYLE_NOTHING ||
1357
result_stroke != QUERY_STYLE_NOTHING ||
1358
result_opacity != QUERY_STYLE_NOTHING ||
1359
result_strokewidth != QUERY_STYLE_NOTHING ||
1345
1360
result_strokemiterlimit != QUERY_STYLE_NOTHING ||
1346
1361
result_strokecap != QUERY_STYLE_NOTHING ||
1347
1362
result_strokejoin != QUERY_STYLE_NOTHING ||