Code

Changed preference to use file chooser button
[inkscape.git] / src / gradient-chemistry.cpp
index 281704eea573078c47652f5d2b3c8c3b57192ef9..9a78a5293ec84455eaa03f87ab4564de786478ff 100644 (file)
@@ -135,14 +135,14 @@ count_gradient_hrefs(SPObject *o, SPGradient *gr)
 
     SPStyle *style = SP_OBJECT_STYLE(o);
     if (style
-        && style->fill.type == SP_PAINT_TYPE_PAINTSERVER
+        && style->fill.isPaintserver()
         && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style))
         && SP_GRADIENT(SP_STYLE_FILL_SERVER(style)) == gr)
     {
         i ++;
     }
     if (style
-        && style->stroke.type == SP_PAINT_TYPE_PAINTSERVER
+        && style->stroke.isPaintserver()
         && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style))
         && SP_GRADIENT(SP_STYLE_STROKE_SERVER(style)) == gr)
     {
@@ -276,7 +276,9 @@ sp_gradient_reset_to_userspace (SPGradient *gr, SPItem *item)
     sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
     NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
 
-    g_assert( bbox && !bbox->isEmpty() );
+    if ( !bbox || bbox->isEmpty() )
+        return gr;
+
     NR::Coord const width = bbox->dimensions()[NR::X];
     NR::Coord const height = bbox->dimensions()[NR::Y];
 
@@ -451,14 +453,14 @@ sp_item_gradient (SPItem *item, bool fill_or_stroke)
     SPGradient *gradient = NULL;
 
     if (fill_or_stroke) {
-        if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) {
+        if (style && (style->fill.isPaintserver())) {
             SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(item);
             if (SP_IS_GRADIENT (server)) {
                 gradient = SP_GRADIENT (server);
             }
         }
     } else {
-        if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) {
+        if (style && (style->stroke.isPaintserver())) {
             SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER(item);
             if (SP_IS_GRADIENT (server)) {
                 gradient = SP_GRADIENT (server);
@@ -911,7 +913,7 @@ sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, NR::
                 double offset = get_offset_between_points (p, start, end);
                 SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (rg, false);
                 sp_gradient_ensure_vector(rg);
-                rg->vector.stops.at(point_i).offset = offset; //crash
+                rg->vector.stops.at(point_i).offset = offset; 
                 SPStop* stopi = sp_get_stop_i(vector, point_i);
                 stopi->offset = offset;
                 if (write_repr) {
@@ -1065,9 +1067,8 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_
     SPStyle *style = SP_OBJECT_STYLE(item);
     g_assert(style != NULL);
 
-    guint style_type = is_fill? style->fill.type : style->stroke.type;
     SPPaintServer *ps = NULL;
-    if (style_type == SP_PAINT_TYPE_PAINTSERVER)
+    if (is_fill? style->fill.isPaintserver() : style->stroke.isPaintserver())
         ps = is_fill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style);
 
     if (ps
@@ -1164,7 +1165,7 @@ sp_document_default_gradient_vector(SPDocument *document, guint32 color)
     Inkscape::XML::Node *stop = xml_doc->createElement("svg:stop");
 
     gchar b[64];
-    sp_svg_write_color(b, 64, color);
+    sp_svg_write_color(b, sizeof(b), color);
 
     {
         gchar *t = g_strdup_printf("stop-color:%s;stop-opacity:1;", b);
@@ -1221,15 +1222,15 @@ sp_gradient_vector_for_object(SPDocument *const doc, SPDesktop *const desktop,
         SPIPaint const &paint = ( is_fill
                                   ? style.fill
                                   : style.stroke );
-        if (paint.type == SP_PAINT_TYPE_COLOR) {
-            rgba = sp_color_get_rgba32_ualpha(&paint.value.color, 0xff);
-        } else if (paint.type == SP_PAINT_TYPE_PAINTSERVER) {
+        if (paint.isPaintserver()) {
             SPObject *server = is_fill? SP_OBJECT_STYLE_FILL_SERVER(o) : SP_OBJECT_STYLE_STROKE_SERVER(o);
             if (SP_IS_GRADIENT (server)) {
                 return sp_gradient_get_vector(SP_GRADIENT (server), TRUE);
             } else {
                 rgba = sp_desktop_get_color(desktop, is_fill);
             }
+        } else if (paint.isColor()) {
+            rgba = paint.value.color.toRGBA32( 0xff );
         } else {
             // if o doesn't use flat color, then take current color of the desktop.
             rgba = sp_desktop_get_color(desktop, is_fill);