diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2013-08-04 14:27:59 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2013-08-04 14:27:59 +0000 |
| commit | dd957026bd798ebe34eff033b4a839d63b790b04 (patch) | |
| tree | a7e5105597676cfb1f4d293640c3f411e9bd2d32 /src | |
| parent | cppcheck: c-style casts > c++ style casts (diff) | |
| download | inkscape-dd957026bd798ebe34eff033b4a839d63b790b04.tar.gz inkscape-dd957026bd798ebe34eff033b4a839d63b790b04.zip | |
cppcheck
(bzr r12467)
Diffstat (limited to 'src')
| -rw-r--r-- | src/attribute-rel-util.cpp | 55 | ||||
| -rw-r--r-- | src/select-context.cpp | 107 | ||||
| -rw-r--r-- | src/sp-ellipse.cpp | 35 | ||||
| -rw-r--r-- | src/sp-pattern.cpp | 503 | ||||
| -rw-r--r-- | src/sp-text.cpp | 2 | ||||
| -rw-r--r-- | src/sp-use.cpp | 12 | ||||
| -rw-r--r-- | src/syseq.h | 3 |
7 files changed, 355 insertions, 362 deletions
diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index 0527dad4e..933339632 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -198,23 +198,22 @@ void sp_attribute_clean_style(Node* repr, SPCSSAttr *css, unsigned int flags) { // Check if a property is applicable to an element (i.e. is font-family useful for a <rect>?). if( !SPAttributeRelCSS::findIfValid( property, element ) ) { - if( flags & SP_ATTR_CLEAN_STYLE_WARN ) { - g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" is inappropriate.", - element.c_str(), id.c_str(), property ); - } - if( flags & SP_ATTR_CLEAN_STYLE_REMOVE ) { - toDelete.insert(property); - } - continue; + if( flags & SP_ATTR_CLEAN_STYLE_WARN ) { + g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" is inappropriate.", + element.c_str(), id.c_str(), property ); + } + if( flags & SP_ATTR_CLEAN_STYLE_REMOVE ) { + toDelete.insert(property); + } + continue; } // Find parent value for same property (property) gchar const * value_p = NULL; if( css_parent != NULL ) { - gchar const * property_p = NULL; for ( List<AttributeRecord const> iter_p = css_parent->attributeList() ; iter_p ; ++iter_p ) { - property_p = g_quark_to_string(iter_p->key); + gchar const * property_p = g_quark_to_string(iter_p->key); if( !g_strcmp0( property, property_p ) ) { value_p = iter_p->value; @@ -226,29 +225,29 @@ void sp_attribute_clean_style(Node* repr, SPCSSAttr *css, unsigned int flags) { // If parent has same property value and property is inherited, mark for deletion. if ( !g_strcmp0( value, value_p ) && SPAttributeRelCSS::findIfInherit( property ) ) { - if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) { - g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" has same value as parent (%s).", - element.c_str(), id.c_str(), property, value ); - } - if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) { - toDelete.insert( property ); - } - continue; + if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) { + g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" has same value as parent (%s).", + element.c_str(), id.c_str(), property, value ); + } + if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) { + toDelete.insert( property ); + } + continue; } // If property value is same as default and the parent value not set or property is not inherited, // mark for deletion. if ( SPAttributeRelCSS::findIfDefault( property, value ) && - ( (css_parent != NULL && value_p == NULL) || !SPAttributeRelCSS::findIfInherit( property ) ) ) { - - if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) { - g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" with default value (%s) not needed.", - element.c_str(), id.c_str(), property, value ); - } - if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) { - toDelete.insert( property ); - } - continue; + ( (css_parent != NULL && value_p == NULL) || !SPAttributeRelCSS::findIfInherit( property ) ) ) { + + if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) { + g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" with default value (%s) not needed.", + element.c_str(), id.c_str(), property, value ); + } + if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) { + toDelete.insert( property ); + } + continue; } } // End loop over style properties diff --git a/src/select-context.cpp b/src/select-context.cpp index 35a9bd172..df90d62cb 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -333,9 +333,9 @@ sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkE // if shift or ctrl was pressed, do not move objects; // pass the event to root handler which will perform rubberband, shift-click, ctrl-click, ctrl-drag } else { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); - sc->dragging = TRUE; + sc->dragging = TRUE; sc->moved = FALSE; gdk_window_set_cursor(window, CursorSelectDragging); @@ -387,7 +387,7 @@ sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkE GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); gdk_window_set_cursor(window, event_context->cursor); - } + } break; case GDK_KEY_PRESS: @@ -540,11 +540,11 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) case GDK_MOTION_NOTIFY: { - if (is_cycling) - { - moved_while_cycling = true; - prev_event_context = event_context; - } + if (is_cycling) + { + moved_while_cycling = true; + prev_event_context = event_context; + } tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ((event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) { Geom::Point const motion_pt(event->motion.x, event->motion.y); @@ -564,7 +564,7 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) // if it's not click and ctrl or alt was pressed (the latter with some selection // but not with shift) we want to drag rather than rubberband sc->dragging = TRUE; - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); gdk_window_set_cursor(window, CursorSelectDragging); desktop->canvas->forceFullRedrawAfterInterruptions(5); @@ -638,7 +638,7 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) if ((event->button.button == 1) && (sc->grabbed) && !event_context->space_panning) { if (sc->dragging) { GdkWindow* window; - if (sc->moved) { + if (sc->moved) { // item has been moved seltrans->ungrab(); sc->moved = FALSE; @@ -670,7 +670,7 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) } } sc->dragging = FALSE; - window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); gdk_window_set_cursor(window, CursorSelectMouseover); sp_event_context_discard_delayed_snap_event(event_context); desktop->canvas->endForcedFullRedraws(); @@ -777,15 +777,15 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) GdkEventScroll *scroll_event = (GdkEventScroll*) event; if (scroll_event->state & GDK_MOD1_MASK) { // alt modified pressed - if (moved_while_cycling) - { - moved_while_cycling = false; - sp_select_context_reset_opacities(prev_event_context); - prev_event_context = NULL; - } - - is_cycling = true; - + if (moved_while_cycling) + { + moved_while_cycling = false; + sp_select_context_reset_opacities(prev_event_context); + prev_event_context = NULL; + } + + is_cycling = true; + bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK; /* Rebuild list of items underneath the mouse pointer */ @@ -861,21 +861,21 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) ret = TRUE; - GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) )); - if (w) - { - gtk_window_present(w); - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - } + GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) )); + if (w) + { + gtk_window_present(w); + gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); + } } break; } case GDK_KEY_PRESS: // keybindings for select context - { - { - guint keyval = get_group0_keyval(&event->key); + { + { + guint keyval = get_group0_keyval(&event->key); bool alt = ( MOD__ALT(event) || (keyval == GDK_KEY_Alt_L) || (keyval == GDK_KEY_Alt_R) @@ -902,19 +902,19 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) _("<b>Alt</b>: click to select under; scroll mouse-wheel to cycle-select; drag to move selected or select by touch")); // if Alt and nonempty selection, show moving cursor ("move selected"): if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); gdk_window_set_cursor(window, CursorSelectDragging); } //*/ break; } - } + } gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px - gdouble const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000, "px"); - int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); + gdouble const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000, "px"); + int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); - switch (get_group0_keyval (&event->key)) { + switch (get_group0_keyval (&event->key)) { case GDK_KEY_Left: // move selection left case GDK_KEY_KP_Left: if (!MOD__CTRL(event)) { // not ctrl @@ -1102,7 +1102,7 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) break; } break; - } + } case GDK_KEY_RELEASE: { guint keyval = get_group0_keyval(&event->key); @@ -1123,11 +1123,10 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) } else { if (alt) { // TODO: Should we have a variable like is_cycling or is it harmless to run this piece of code each time? // quit cycle-selection and reset opacities - if (is_cycling) - { - sp_select_context_reset_opacities(event_context); - is_cycling = false; - } + if (is_cycling){ + sp_select_context_reset_opacities(event_context); + is_cycling = false; + } } } @@ -1151,23 +1150,21 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) return ret; } -static void -sp_select_context_reset_opacities(SPEventContext *event_context) +static void sp_select_context_reset_opacities(SPEventContext *event_context) { // SPDesktop *desktop = event_context->desktop; - SPSelectContext *sc = SP_SELECT_CONTEXT(event_context); - Inkscape::DrawingItem *arenaitem; - for (GList *l = sc->cycling_items; l != NULL; l = g_list_next(l)) { - arenaitem = SP_ITEM(l->data)->get_arenaitem(event_context->desktop->dkey); - arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(SP_ITEM(l->data)->style->opacity.value)); - } - g_list_free(sc->cycling_items); - g_list_free(sc->cycling_items_selected_before); - g_list_free(sc->cycling_items_cmp); - sc->cycling_items = NULL; - sc->cycling_items_selected_before = NULL; - sc->cycling_cur_item = NULL; - sc->cycling_items_cmp = NULL; + SPSelectContext *sc = SP_SELECT_CONTEXT(event_context); + for (GList *l = sc->cycling_items; l != NULL; l = g_list_next(l)) { + Inkscape::DrawingItem *arenaitem = SP_ITEM(l->data)->get_arenaitem(event_context->desktop->dkey); + arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(SP_ITEM(l->data)->style->opacity.value)); + } + g_list_free(sc->cycling_items); + g_list_free(sc->cycling_items_selected_before); + g_list_free(sc->cycling_items_cmp); + sc->cycling_items = NULL; + sc->cycling_items_selected_before = NULL; + sc->cycling_cur_item = NULL; + sc->cycling_items_cmp = NULL; } diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index 8a9793852..bf019fb13 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -167,16 +167,20 @@ static void sp_genericellipse_set_shape(SPShape *shape) return; } - double rx, ry, s, e; - double x0, y0, x1, y1, x2, y2, x3, y3; + double rx; + double ry; + double s; double len; gint slice = FALSE; - // gint i; SPGenericEllipse *ellipse = (SPGenericEllipse *) shape; - if ((ellipse->rx.computed < 1e-18) || (ellipse->ry.computed < 1e-18)) return; - if (fabs(ellipse->end - ellipse->start) < 1e-9) return; + if ((ellipse->rx.computed < 1e-18) || (ellipse->ry.computed < 1e-18)) { + return; + } + if (fabs(ellipse->end - ellipse->start) < 1e-9){ + return; + } sp_genericellipse_normalize(ellipse); @@ -197,18 +201,19 @@ static void sp_genericellipse_set_shape(SPShape *shape) curve->moveto(cos(ellipse->start), sin(ellipse->start)); for (s = ellipse->start; s < ellipse->end; s += M_PI_2) { - e = s + M_PI_2; - if (e > ellipse->end) + double e = s + M_PI_2; + if (e > ellipse->end){ e = ellipse->end; + } len = 4*tan((e - s)/4)/3; - x0 = cos(s); - y0 = sin(s); - x1 = x0 + len * cos(s + M_PI_2); - y1 = y0 + len * sin(s + M_PI_2); - x3 = cos(e); - y3 = sin(e); - x2 = x3 + len * cos(e - M_PI_2); - y2 = y3 + len * sin(e - M_PI_2); + double x0 = cos(s); + double y0 = sin(s); + double x1 = x0 + len * cos(s + M_PI_2); + double y1 = y0 + len * sin(s + M_PI_2); + double x3 = cos(e); + double y3 = sin(e); + double x2 = x3 + len * cos(e - M_PI_2); + double y2 = y3 + len * sin(e - M_PI_2); #ifdef ELLIPSE_VERBOSE g_print("step %d s %f e %f coords %f %f %f %f %f %f\n", i, s, e, x1, y1, x2, y2, x3, y3); diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index c4308a1a9..62811d51a 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -56,19 +56,19 @@ G_DEFINE_TYPE(SPPattern, sp_pattern, SP_TYPE_PAINT_SERVER); static void sp_pattern_class_init (SPPatternClass *klass) { - SPObjectClass *sp_object_class; - SPPaintServerClass *ps_class; + SPObjectClass *sp_object_class; + SPPaintServerClass *ps_class; - sp_object_class = (SPObjectClass *) klass; - ps_class = (SPPaintServerClass *) klass; + sp_object_class = (SPObjectClass *) klass; + ps_class = (SPPaintServerClass *) klass; - sp_object_class->build = sp_pattern_build; - sp_object_class->release = sp_pattern_release; - sp_object_class->set = sp_pattern_set; - sp_object_class->update = sp_pattern_update; - sp_object_class->modified = sp_pattern_modified; + sp_object_class->build = sp_pattern_build; + sp_object_class->release = sp_pattern_release; + sp_object_class->set = sp_pattern_set; + sp_object_class->update = sp_pattern_update; + sp_object_class->modified = sp_pattern_modified; - // do we need _write? seems to work without it + // do we need _write? seems to work without it ps_class->pattern_new = sp_pattern_create_pattern; } @@ -76,46 +76,46 @@ sp_pattern_class_init (SPPatternClass *klass) static void sp_pattern_init (SPPattern *pat) { - pat->ref = new SPPatternReference(pat); - pat->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(pattern_ref_changed), pat)); + pat->ref = new SPPatternReference(pat); + pat->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(pattern_ref_changed), pat)); - pat->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; - pat->patternUnits_set = FALSE; + pat->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; + pat->patternUnits_set = FALSE; - pat->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE; - pat->patternContentUnits_set = FALSE; + pat->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE; + pat->patternContentUnits_set = FALSE; - pat->patternTransform = Geom::identity(); - pat->patternTransform_set = FALSE; + pat->patternTransform = Geom::identity(); + pat->patternTransform_set = FALSE; - pat->x.unset(); - pat->y.unset(); - pat->width.unset(); - pat->height.unset(); + pat->x.unset(); + pat->y.unset(); + pat->width.unset(); + pat->height.unset(); - pat->viewBox_set = FALSE; + pat->viewBox_set = FALSE; - new (&pat->modified_connection) sigc::connection(); + new (&pat->modified_connection) sigc::connection(); } static void sp_pattern_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) sp_pattern_parent_class)->build) - (* ((SPObjectClass *) sp_pattern_parent_class)->build) (object, document, repr); - - object->readAttr( "patternUnits" ); - object->readAttr( "patternContentUnits" ); - object->readAttr( "patternTransform" ); - object->readAttr( "x" ); - object->readAttr( "y" ); - object->readAttr( "width" ); - object->readAttr( "height" ); - object->readAttr( "viewBox" ); - object->readAttr( "xlink:href" ); - - /* Register ourselves */ - document->addResource("pattern", object); + if (((SPObjectClass *) sp_pattern_parent_class)->build) + (* ((SPObjectClass *) sp_pattern_parent_class)->build) (object, document, repr); + + object->readAttr( "patternUnits" ); + object->readAttr( "patternContentUnits" ); + object->readAttr( "patternTransform" ); + object->readAttr( "x" ); + object->readAttr( "y" ); + object->readAttr( "width" ); + object->readAttr( "height" ); + object->readAttr( "viewBox" ); + object->readAttr( "xlink:href" ); + + /* Register ourselves */ + document->addResource("pattern", object); } static void sp_pattern_release(SPObject *object) @@ -144,118 +144,115 @@ static void sp_pattern_release(SPObject *object) static void sp_pattern_set (SPObject *object, unsigned int key, const gchar *value) { - SPPattern *pat = SP_PATTERN (object); - - switch (key) { - case SP_ATTR_PATTERNUNITS: - if (value) { - if (!strcmp (value, "userSpaceOnUse")) { - pat->patternUnits = SP_PATTERN_UNITS_USERSPACEONUSE; - } else { - pat->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; - } - pat->patternUnits_set = TRUE; - } else { - pat->patternUnits_set = FALSE; - } - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_PATTERNCONTENTUNITS: - if (value) { - if (!strcmp (value, "userSpaceOnUse")) { - pat->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE; - } else { - pat->patternContentUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; - } - pat->patternContentUnits_set = TRUE; - } else { - pat->patternContentUnits_set = FALSE; - } - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_PATTERNTRANSFORM: { - Geom::Affine t; - if (value && sp_svg_transform_read (value, &t)) { - pat->patternTransform = t; - pat->patternTransform_set = TRUE; - } else { - pat->patternTransform = Geom::identity(); - pat->patternTransform_set = FALSE; - } - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - } - case SP_ATTR_X: - pat->x.readOrUnset(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_Y: - pat->y.readOrUnset(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_WIDTH: - pat->width.readOrUnset(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_HEIGHT: - pat->height.readOrUnset(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - case SP_ATTR_VIEWBOX: { - /* fixme: Think (Lauris) */ - double x, y, width, height; - char *eptr; - - if (value) { - eptr = (gchar *) value; - x = g_ascii_strtod (eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; - y = g_ascii_strtod (eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; - width = g_ascii_strtod (eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; - height = g_ascii_strtod (eptr, &eptr); - while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; - if ((width > 0) && (height > 0)) { - pat->viewBox = Geom::Rect::from_xywh(x, y, width, height); - pat->viewBox_set = TRUE; - } else { - pat->viewBox_set = FALSE; - } - } else { - pat->viewBox_set = FALSE; - } - object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); - break; - } - case SP_ATTR_XLINK_HREF: - if ( value && pat->href && ( strcmp(value, pat->href) == 0 ) ) { - /* Href unchanged, do nothing. */ - } else { - g_free(pat->href); - pat->href = NULL; - if (value) { - // First, set the href field; it's only used in the "unchanged" check above. - pat->href = g_strdup(value); - // Now do the attaching, which emits the changed signal. - if (value) { - try { - pat->ref->attach(Inkscape::URI(value)); - } catch (Inkscape::BadURIException &e) { - g_warning("%s", e.what()); - pat->ref->detach(); - } - } else { - pat->ref->detach(); - } - } - } - break; - default: - if (((SPObjectClass *) sp_pattern_parent_class)->set) - ((SPObjectClass *) sp_pattern_parent_class)->set (object, key, value); - break; - } + SPPattern *pat = SP_PATTERN (object); + + switch (key) { + case SP_ATTR_PATTERNUNITS: + if (value) { + if (!strcmp (value, "userSpaceOnUse")) { + pat->patternUnits = SP_PATTERN_UNITS_USERSPACEONUSE; + } else { + pat->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; + } + pat->patternUnits_set = TRUE; + } else { + pat->patternUnits_set = FALSE; + } + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_PATTERNCONTENTUNITS: + if (value) { + if (!strcmp (value, "userSpaceOnUse")) { + pat->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE; + } else { + pat->patternContentUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; + } + pat->patternContentUnits_set = TRUE; + } else { + pat->patternContentUnits_set = FALSE; + } + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_PATTERNTRANSFORM: { + Geom::Affine t; + if (value && sp_svg_transform_read (value, &t)) { + pat->patternTransform = t; + pat->patternTransform_set = TRUE; + } else { + pat->patternTransform = Geom::identity(); + pat->patternTransform_set = FALSE; + } + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + } + case SP_ATTR_X: + pat->x.readOrUnset(value); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_Y: + pat->y.readOrUnset(value); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_WIDTH: + pat->width.readOrUnset(value); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_HEIGHT: + pat->height.readOrUnset(value); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_VIEWBOX: { + /* fixme: Think (Lauris) */ + if (value) { + char *eptr = const_cast<gchar *>(value); + double x = g_ascii_strtod (eptr, &eptr); + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; + double y = g_ascii_strtod (eptr, &eptr); + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; + double width = g_ascii_strtod (eptr, &eptr); + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; + double height = g_ascii_strtod (eptr, &eptr); + while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; + if ((width > 0) && (height > 0)) { + pat->viewBox = Geom::Rect::from_xywh(x, y, width, height); + pat->viewBox_set = TRUE; + } else { + pat->viewBox_set = FALSE; + } + } else { + pat->viewBox_set = FALSE; + } + object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + break; + } + case SP_ATTR_XLINK_HREF: + if ( value && pat->href && ( strcmp(value, pat->href) == 0 ) ) { + /* Href unchanged, do nothing. */ + } else { + g_free(pat->href); + pat->href = NULL; + if (value) { + // First, set the href field; it's only used in the "unchanged" check above. + pat->href = g_strdup(value); + // Now do the attaching, which emits the changed signal. + if (value) { + try { + pat->ref->attach(Inkscape::URI(value)); + } catch (Inkscape::BadURIException &e) { + g_warning("%s", e.what()); + pat->ref->detach(); + } + } else { + pat->ref->detach(); + } + } + } + break; + default: + if (((SPObjectClass *) sp_pattern_parent_class)->set) + ((SPObjectClass *) sp_pattern_parent_class)->set (object, key, value); + break; + } } /* TODO: do we need a ::remove_child handler? */ @@ -268,11 +265,11 @@ static GSList *pattern_getchildren(SPPattern *pat) for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->firstChild()) { // find the first one with children - for (SPObject *child = pat->firstChild() ; child ; child = child->getNext() ) { - l = g_slist_prepend (l, child); - } - break; // do not go further up the chain if children are found - } + for (SPObject *child = pat->firstChild() ; child ; child = child->getNext() ) { + l = g_slist_prepend (l, child); + } + break; // do not go further up the chain if children are found + } } return l; @@ -281,45 +278,45 @@ static GSList *pattern_getchildren(SPPattern *pat) static void sp_pattern_update (SPObject *object, SPCtx *ctx, unsigned int flags) { - SPPattern *pat = SP_PATTERN (object); - - if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; - flags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = pattern_getchildren (pat); - l = g_slist_reverse (l); - - while (l) { - SPObject *child = SP_OBJECT (l->data); - sp_object_ref (child, NULL); - l = g_slist_remove (l, child); - if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { - child->updateDisplay(ctx, flags); - } - sp_object_unref (child, NULL); - } + SPPattern *pat = SP_PATTERN (object); + + if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + flags &= SP_OBJECT_MODIFIED_CASCADE; + + GSList *l = pattern_getchildren (pat); + l = g_slist_reverse (l); + + while (l) { + SPObject *child = SP_OBJECT (l->data); + sp_object_ref (child, NULL); + l = g_slist_remove (l, child); + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { + child->updateDisplay(ctx, flags); + } + sp_object_unref (child, NULL); + } } static void sp_pattern_modified (SPObject *object, guint flags) { - SPPattern *pat = SP_PATTERN (object); - - if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; - flags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = pattern_getchildren (pat); - l = g_slist_reverse (l); - - while (l) { - SPObject *child = SP_OBJECT (l->data); - sp_object_ref (child, NULL); - l = g_slist_remove (l, child); - if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { - child->emitModified(flags); - } - sp_object_unref (child, NULL); - } + SPPattern *pat = SP_PATTERN (object); + + if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + flags &= SP_OBJECT_MODIFIED_CASCADE; + + GSList *l = pattern_getchildren (pat); + l = g_slist_reverse (l); + + while (l) { + SPObject *child = SP_OBJECT (l->data); + sp_object_ref (child, NULL); + l = g_slist_remove (l, child); + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { + child->emitModified(flags); + } + sp_object_unref (child, NULL); + } } /** @@ -328,14 +325,14 @@ Gets called when the pattern is reattached to another <pattern> static void pattern_ref_changed(SPObject *old_ref, SPObject *ref, SPPattern *pat) { - if (old_ref) { - pat->modified_connection.disconnect(); - } - if (SP_IS_PATTERN (ref)) { - pat->modified_connection = ref->connectModified(sigc::bind<2>(sigc::ptr_fun(&pattern_ref_modified), pat)); - } - - pattern_ref_modified (ref, 0, pat); + if (old_ref) { + pat->modified_connection.disconnect(); + } + if (SP_IS_PATTERN (ref)) { + pat->modified_connection = ref->connectModified(sigc::bind<2>(sigc::ptr_fun(&pattern_ref_modified), pat)); + } + + pattern_ref_modified (ref, 0, pat); } /** @@ -386,56 +383,56 @@ count_pattern_hrefs(SPObject *o, SPPattern *pat) SPPattern *pattern_chain(SPPattern *pattern) { - SPDocument *document = pattern->document; + SPDocument *document = pattern->document; Inkscape::XML::Document *xml_doc = document->getReprDoc(); - Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); + Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); - Inkscape::XML::Node *repr = xml_doc->createElement("svg:pattern"); - repr->setAttribute("inkscape:collect", "always"); - gchar *parent_ref = g_strconcat("#", pattern->getRepr()->attribute("id"), NULL); - repr->setAttribute("xlink:href", parent_ref); - g_free (parent_ref); + Inkscape::XML::Node *repr = xml_doc->createElement("svg:pattern"); + repr->setAttribute("inkscape:collect", "always"); + gchar *parent_ref = g_strconcat("#", pattern->getRepr()->attribute("id"), NULL); + repr->setAttribute("xlink:href", parent_ref); + g_free (parent_ref); - defsrepr->addChild(repr, NULL); - const gchar *child_id = repr->attribute("id"); - SPObject *child = document->getObjectById(child_id); - g_assert (SP_IS_PATTERN (child)); + defsrepr->addChild(repr, NULL); + const gchar *child_id = repr->attribute("id"); + SPObject *child = document->getObjectById(child_id); + g_assert (SP_IS_PATTERN (child)); - return SP_PATTERN (child); + return SP_PATTERN (child); } SPPattern * sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property) { - if (!pattern->href || pattern->hrefcount > count_pattern_hrefs(item, pattern)) { - pattern = pattern_chain (pattern); - gchar *href = g_strconcat("url(#", pattern->getRepr()->attribute("id"), ")", NULL); - - SPCSSAttr *css = sp_repr_css_attr_new (); - sp_repr_css_set_property (css, property, href); - sp_repr_css_change_recursive(item->getRepr(), css, "style"); - } - return pattern; + if (!pattern->href || pattern->hrefcount > count_pattern_hrefs(item, pattern)) { + pattern = pattern_chain (pattern); + gchar *href = g_strconcat("url(#", pattern->getRepr()->attribute("id"), ")", NULL); + + SPCSSAttr *css = sp_repr_css_attr_new (); + sp_repr_css_set_property (css, property, href); + sp_repr_css_change_recursive(item->getRepr(), css, "style"); + } + return pattern; } void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set) { - // this formula is for a different interpretation of pattern transforms as described in (*) in sp-pattern.cpp - // for it to work, we also need sp_object_read_attr( item, "transform"); - //pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() * postmul; - - // otherwise the formula is much simpler - if (set) { - pattern->patternTransform = postmul; - } else { - pattern->patternTransform = pattern_patternTransform(pattern) * postmul; - } - pattern->patternTransform_set = TRUE; - - gchar *c=sp_svg_transform_write(pattern->patternTransform); - pattern->getRepr()->setAttribute("patternTransform", c); - g_free(c); + // this formula is for a different interpretation of pattern transforms as described in (*) in sp-pattern.cpp + // for it to work, we also need sp_object_read_attr( item, "transform"); + //pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() * postmul; + + // otherwise the formula is much simpler + if (set) { + pattern->patternTransform = postmul; + } else { + pattern->patternTransform = pattern_patternTransform(pattern) * postmul; + } + pattern->patternTransform_set = TRUE; + + gchar *c=sp_svg_transform_write(pattern->patternTransform); + pattern->getRepr()->setAttribute("patternTransform", c); + g_free(c); } const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) @@ -443,33 +440,33 @@ const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); - Inkscape::XML::Node *repr = xml_doc->createElement("svg:pattern"); - repr->setAttribute("patternUnits", "userSpaceOnUse"); - sp_repr_set_svg_double(repr, "width", bounds.dimensions()[Geom::X]); - sp_repr_set_svg_double(repr, "height", bounds.dimensions()[Geom::Y]); + Inkscape::XML::Node *repr = xml_doc->createElement("svg:pattern"); + repr->setAttribute("patternUnits", "userSpaceOnUse"); + sp_repr_set_svg_double(repr, "width", bounds.dimensions()[Geom::X]); + sp_repr_set_svg_double(repr, "height", bounds.dimensions()[Geom::Y]); - gchar *t=sp_svg_transform_write(transform); - repr->setAttribute("patternTransform", t); - g_free(t); + gchar *t=sp_svg_transform_write(transform); + repr->setAttribute("patternTransform", t); + g_free(t); - defsrepr->appendChild(repr); - const gchar *pat_id = repr->attribute("id"); - SPObject *pat_object = document->getObjectById(pat_id); + defsrepr->appendChild(repr); + const gchar *pat_id = repr->attribute("id"); + SPObject *pat_object = document->getObjectById(pat_id); - for (GSList *i = reprs; i != NULL; i = i->next) { - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(i->data); - SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); + for (GSList *i = reprs; i != NULL; i = i->next) { + Inkscape::XML::Node *node = (Inkscape::XML::Node *)(i->data); + SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); - Geom::Affine dup_transform; - if (!sp_svg_transform_read (node->attribute("transform"), &dup_transform)) - dup_transform = Geom::identity(); - dup_transform *= move; + Geom::Affine dup_transform; + if (!sp_svg_transform_read (node->attribute("transform"), &dup_transform)) + dup_transform = Geom::identity(); + dup_transform *= move; copy->doWriteTransform(copy->getRepr(), dup_transform, NULL, false); } - Inkscape::GC::release(repr); - return pat_id; + Inkscape::GC::release(repr); + return pat_id; } SPPattern *pattern_getroot(SPPattern *pat) diff --git a/src/sp-text.cpp b/src/sp-text.cpp index 8d42b7d59..e43a34762 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -381,9 +381,9 @@ static char * sp_text_description(SPItem *item) font_instance *tf = font_factory::Default()->FaceFromStyle(style); - char name_buf[256]; char *n; if (tf) { + char name_buf[256]; tf->Family(name_buf, sizeof(name_buf)); n = xml_quote_strdup(name_buf); tf->Unref(); diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 2220b4b47..5ec1f2523 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -252,8 +252,7 @@ sp_use_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML:: return repr; } -static Geom::OptRect -sp_use_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) +static Geom::OptRect sp_use_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { SPUse const *use = SP_USE(item); Geom::OptRect bbox; @@ -269,8 +268,7 @@ sp_use_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType return bbox; } -static void -sp_use_print(SPItem *item, SPPrintContext *ctx) +static void sp_use_print(SPItem *item, SPPrintContext *ctx) { bool translated = false; SPUse *use = SP_USE(item); @@ -290,12 +288,10 @@ sp_use_print(SPItem *item, SPPrintContext *ctx) } } -static gchar * -sp_use_description(SPItem *item) +static gchar *sp_use_description(SPItem *item) { SPUse *use = SP_USE(item); - char *ret; if (use->child) { if( SP_IS_SYMBOL( use->child ) ) { @@ -316,7 +312,7 @@ sp_use_description(SPItem *item) char *child_desc = SP_ITEM(use->child)->description(); --recursion_depth; - ret = g_strdup_printf(_("<b>Clone</b> of: %s"), child_desc); + char *ret = g_strdup_printf(_("<b>Clone</b> of: %s"), child_desc); g_free(child_desc); return ret; } else { diff --git a/src/syseq.h b/src/syseq.h index 4e7ccd943..582f2949f 100644 --- a/src/syseq.h +++ b/src/syseq.h @@ -181,10 +181,9 @@ static std::vector<int> gauss_jordan (double A[S][T], int avoid_col = -1) { if (avoid_col != -1) { cols_used.push_back (avoid_col); } - int col; for (int i = 0; i < S; ++i) { /* for each row find a pivot element of maximal absolute value, skipping the columns that were used before */ - col = find_pivot<S,T>(A, i, cols_used); + int col = find_pivot<S,T>(A, i, cols_used); cols_used.push_back(col); if (col == -1) { // no non-zero elements in the row |
