~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/desktop-style.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "selection.h"
24
24
#include "inkscape.h"
25
25
#include "style.h"
26
 
#include "prefs-utils.h"
 
26
#include "preferences.h"
27
27
#include "sp-use.h"
28
 
#include "sp-feblend.h"
 
28
#include "filters/blend.h"
29
29
#include "sp-filter.h"
30
30
#include "sp-filter-reference.h"
31
31
#include "sp-gaussian-blur.h"
120
120
 
121
121
        // Scale the style by the inverse of the accumulated parent transform in the paste context.
122
122
        {
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)
160
160
{
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);
164
165
 
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);
 
171
 
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
 
                    g_free (style_grp);
 
177
                    prefs->mergeStyle(Glib::ustring("/desktop/") + descr + "/style", css_write);
178
178
                }
179
179
            }
180
180
        }
243
243
}
244
244
 
245
245
double
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)
247
247
{
 
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) {
 
251
    if (has_opacity)
 
252
        *has_opacity = false;
 
253
    if (prefs->getBool(tool + "/usecurrent")) {
251
254
        css = sp_desktop_get_style(desktop, true);
252
 
    } else { 
253
 
        Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
254
 
        if (tool_repr) {
255
 
            css = sp_repr_css_attr_inherited(tool_repr, "style");
256
 
        }
 
255
    } else {
 
256
        css = prefs->getStyle(tool + "/style");
257
257
    }
258
 
   
 
258
 
259
259
    if (css) {
260
260
        gchar const *property = css ? sp_repr_css_property(css, "opacity", "1.000") : 0;
261
 
           
 
261
 
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
 
265
            } else {
 
266
                if (has_opacity)
 
267
                   *has_opacity = false;
265
268
            }
266
269
        }
267
270
 
271
274
    return value;
272
275
}
273
276
double
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)
275
278
{
 
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);
280
 
    } else { 
281
 
        Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
282
 
        if (tool_repr) {
283
 
            css = sp_repr_css_attr_inherited(tool_repr, "style");
284
 
        }
 
284
    } else {
 
285
        css = prefs->getStyle(tool + "/style");
285
286
    }
286
 
   
 
287
 
287
288
    if (css) {
288
289
        gchar const *property = css ? sp_repr_css_property(css, is_fill ? "fill-opacity": "stroke-opacity", "1.000") : 0;
289
 
           
 
290
 
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
298
299
 
299
300
    return value;
300
301
}
 
302
 
301
303
guint32
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)
303
305
{
 
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) {
 
309
    if (has_color)
 
310
        *has_color = false;
 
311
    if (prefs->getBool(tool + "/usecurrent")) {
307
312
        css = sp_desktop_get_style(desktop, true);
308
313
    } else {
309
 
        Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
310
 
        if (tool_repr) {
311
 
            css = sp_repr_css_attr_inherited(tool_repr, "style");
312
 
        }
 
314
        css = prefs->getStyle(tool + "/style");
313
315
    }
314
 
   
 
316
 
315
317
    if (css) {
316
318
        gchar const *property = sp_repr_css_property(css, is_fill ? "fill" : "stroke", "#000");
317
 
           
 
319
 
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,
320
322
                // read it
321
323
                r = sp_svg_read_color(property, r);
 
324
                if (has_color)
 
325
                    *has_color = true;
322
326
            }
323
327
        }
324
328
 
327
331
 
328
332
    return r | 0xff;
329
333
}
 
334
 
330
335
/**
331
336
 * Apply the desktop's current style or the tool style to repr.
332
337
 */
333
338
void
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)
335
340
{
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();
 
343
 
 
344
    if (prefs->getBool(tool_path + "/usecurrent") && css_current) {
338
345
        sp_repr_css_set(repr, css_current, "style");
339
346
    } else {
340
 
        Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, tool);
341
 
        if (tool_repr) {
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);
345
 
        }
 
347
        SPCSSAttr *css = prefs->getStyle(tool_path + "/style");
 
348
        sp_repr_css_set(repr, css, "style");
 
349
        sp_repr_css_attr_unref(css);
346
350
    }
347
351
    if (css_current) {
348
352
        sp_repr_css_attr_unref(css_current);
357
361
sp_desktop_get_font_size_tool(SPDesktop *desktop)
358
362
{
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;
364
369
    } else {
365
 
        Inkscape::XML::Node *tool_repr = inkscape_get_repr(INKSCAPE, "tools.text");
366
 
        if (tool_repr) {
367
 
            style_str = tool_repr->attribute("style");
368
 
        }
 
370
        style_str = prefs->getString("/tools/text/style");
369
371
    }
370
372
 
371
373
    double ret = 12;
372
 
    if (style_str) {
 
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);
377
379
    }
394
396
        if (!SP_IS_ITEM (l->data))
395
397
            continue;
396
398
 
397
 
        NR::Matrix i2d = sp_item_i2d_affine (SP_ITEM(l->data));
 
399
        Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(l->data));
398
400
 
399
401
        SPObject *object = SP_OBJECT(l->data);
400
402
 
405
407
            notstroked = false;
406
408
        }
407
409
 
408
 
        avgwidth += SP_OBJECT_STYLE (object)->stroke_width.computed * i2d.expansion();
 
410
        avgwidth += SP_OBJECT_STYLE (object)->stroke_width.computed * i2d.descrim();
409
411
    }
410
412
 
411
413
    if (notstroked)
645
647
 
646
648
    gdouble prev_sw = -1;
647
649
    bool same_sw = true;
 
650
    bool noneSet = true; // is stroke set to none?
648
651
 
649
652
    int n_stroked = 0;
650
653
 
654
657
        SPStyle *style = SP_OBJECT_STYLE (obj);
655
658
        if (!style) continue;
656
659
 
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))
 
665
                {
658
666
            continue;
659
667
        }
660
668
 
661
669
        n_stroked ++;
662
670
 
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();
 
672
 
 
673
        Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
 
674
        double sw = style->stroke_width.computed * i2d.descrim();
665
675
 
666
676
        if (prev_sw != -1 && fabs(sw - prev_sw) > 1e-3)
667
677
            same_sw = false;
675
685
 
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.
678
689
 
679
690
    if (n_stroked == 0) {
680
691
        return QUERY_STYLE_NOTHING;
876
887
        if (!style) continue;
877
888
 
878
889
        texts ++;
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
880
891
 
881
892
        if (style->letter_spacing.normal) {
882
893
            if (!different && (letterspacing_prev == 0 || letterspacing_prev == letterspacing))
1078
1089
 
1079
1090
        texts ++;
1080
1091
 
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
1085
1096
        }
1086
 
        
 
1097
 
1087
1098
        if (style->text->font_specification.set) {
1088
1099
 
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;
1092
1103
            }
1093
 
    
 
1104
 
1094
1105
            style_res->text->font_specification.set = TRUE;
1095
1106
            style_res->text->font_specification.value = g_strdup(style->text->font_specification.value);
1096
1107
        }
1119
1130
    float blend_prev = empty_prev;
1120
1131
    bool same_blend = true;
1121
1132
    guint items = 0;
1122
 
    
 
1133
 
1123
1134
    for (GSList const *i = objects; i != NULL; i = i->next) {
1124
1135
        SPObject *obj = SP_OBJECT (i->data);
1125
1136
        SPStyle *style = SP_OBJECT_STYLE (obj);
1204
1215
    bool same_blur = true;
1205
1216
    guint blur_items = 0;
1206
1217
    guint items = 0;
1207
 
    
 
1218
 
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;
1213
1224
 
1214
 
        NR::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
 
1225
        Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
1215
1226
 
1216
1227
        items ++;
1217
1228
 
1222
1233
            while (primitive_obj) {
1223
1234
                if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
1224
1235
                    SPFilterPrimitive *primitive = SP_FILTER_PRIMITIVE(primitive_obj);
1225
 
                    
 
1236
 
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;
1281
1292
 
1282
1293
    } else if (property == QUERY_STYLE_PROPERTY_MASTEROPACITY) {
1283
1294
        return objects_query_opacity (list, style);
1284
 
        
 
1295
 
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
1314
1325
 
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);
 
1329
    }
 
1330
 
 
1331
    return QUERY_STYLE_NOTHING;
1317
1332
}
1318
1333
 
1319
1334
/**
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.
1322
1337
 */
1323
1338
bool
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);
1337
 
        
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 || 
 
1352
 
 
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 ||