From: joncruz Date: Mon, 10 Sep 2007 06:33:47 +0000 (+0000) Subject: Purged fill type enum X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2f99f08590b9e75d4c4f33cc4374db3e8f97f15d;p=inkscape.git Purged fill type enum --- diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 56fc9d4be..a68c99d65 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -351,6 +351,7 @@ sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, char double sp_desktop_get_font_size_tool(SPDesktop *desktop) { + (void)desktop; // TODO cleanup gchar const *desktop_style = inkscape_get_repr(INKSCAPE, "desktop")->attribute("style"); gchar const *style_str = NULL; if ((prefs_get_int_attribute("tools.text", "usecurrent", 0) != 0) && desktop_style) { @@ -392,7 +393,7 @@ stroke_average_width (GSList const *objects) SPObject *object = SP_OBJECT(l->data); - if ( object->style->stroke.type == SP_PAINT_TYPE_NONE ) { + if ( object->style->stroke.isNone() ) { ++n_notstroked; // do not count nonstroked objects continue; } else { @@ -420,7 +421,7 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill } SPIPaint *paint_res = isfill? &style_res->fill : &style_res->stroke; - paint_res->type = SP_PAINT_TYPE_IMPOSSIBLE; + bool paintImpossible = true; paint_res->set = TRUE; gfloat c[4]; @@ -440,18 +441,18 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill // We consider paint "effectively set" for anything within text hierarchy SPObject *parent = SP_OBJECT_PARENT (obj); - bool paint_effectively_set = + bool paint_effectively_set = paint->set || (SP_IS_TEXT(parent) || SP_IS_TEXTPATH(parent) || SP_IS_TSPAN(parent) - || SP_IS_FLOWTEXT(parent) || SP_IS_FLOWDIV(parent) || SP_IS_FLOWPARA(parent) + || SP_IS_FLOWTEXT(parent) || SP_IS_FLOWDIV(parent) || SP_IS_FLOWPARA(parent) || SP_IS_FLOWTSPAN(parent) || SP_IS_FLOWLINE(parent)); // 1. Bail out with QUERY_STYLE_MULTIPLE_DIFFERENT if necessary - if ((paint_res->type != SP_PAINT_TYPE_IMPOSSIBLE) && (paint->type != paint_res->type || (paint_res->set != paint_effectively_set))) { + if ((!paintImpossible) && (!paint->isSameType(*paint_res) || (paint_res->set != paint_effectively_set))) { return QUERY_STYLE_MULTIPLE_DIFFERENT; // different types of paint } - if (paint_res->set && paint->set && paint_res->type == SP_PAINT_TYPE_PAINTSERVER) { + if (paint_res->set && paint->set && paint_res->isPaintserver()) { // both previous paint and this paint were a server, see if the servers are compatible SPPaintServer *server_res = isfill? SP_STYLE_FILL_SERVER (style_res) : SP_STYLE_STROKE_SERVER (style_res); @@ -491,16 +492,16 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill // 2. Sum color, copy server from paint to paint_res - if (paint_res->set && paint_effectively_set && paint->type == SP_PAINT_TYPE_COLOR) { - + if (paint_res->set && paint_effectively_set && paint->isColor()) { gfloat d[3]; sp_color_get_rgb_floatv (&paint->value.color, d); // Check if this color is the same as previous - if (paint_res->type == SP_PAINT_TYPE_IMPOSSIBLE) { + if (paintImpossible) { prev[0] = d[0]; prev[1] = d[1]; prev[2] = d[2]; + paint_res->setColor(d[0], d[1], d[2]); } else { if (same_color && (prev[0] != d[0] || prev[1] != d[1] || prev[2] != d[2])) same_color = false; @@ -514,8 +515,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill num ++; } - paint_res->type = paint->type; - if (paint_res->set && paint_effectively_set && paint->type == SP_PAINT_TYPE_PAINTSERVER) { // copy the server + paintImpossible = false; + if (paint_res->set && paint_effectively_set && paint->isPaintserver()) { // copy the server if (isfill) { sp_style_set_to_uri_string (style_res, true, style->getFillURI()); } else { @@ -527,14 +528,14 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill } // After all objects processed, divide the color if necessary and return - if (paint_res->set && paint_res->type == SP_PAINT_TYPE_COLOR) { // set the color + if (paint_res->set && paint_res->isColor()) { // set the color g_assert (num >= 1); c[0] /= num; c[1] /= num; c[2] /= num; c[3] /= num; - sp_color_set_rgb_float(&paint_res->value.color, c[0], c[1], c[2]); + paint_res->setColor(c[0], c[1], c[2]); if (isfill) { style_res->fill_opacity.value = SP_SCALE24_FROM_FLOAT (c[3]); } else { @@ -628,7 +629,7 @@ objects_query_strokewidth (GSList *objects, SPStyle *style_res) SPStyle *style = SP_OBJECT_STYLE (obj); if (!style) continue; - if ( style->stroke.type == SP_PAINT_TYPE_NONE ) { + if ( style->stroke.isNone() ) { continue; } @@ -685,7 +686,7 @@ objects_query_miterlimit (GSList *objects, SPStyle *style_res) SPStyle *style = SP_OBJECT_STYLE (obj); if (!style) continue; - if ( style->stroke.type == SP_PAINT_TYPE_NONE ) { + if ( style->stroke.isNone() ) { continue; } @@ -738,7 +739,7 @@ objects_query_strokecap (GSList *objects, SPStyle *style_res) SPStyle *style = SP_OBJECT_STYLE (obj); if (!style) continue; - if ( style->stroke.type == SP_PAINT_TYPE_NONE ) { + if ( style->stroke.isNone() ) { continue; } @@ -788,7 +789,7 @@ objects_query_strokejoin (GSList *objects, SPStyle *style_res) SPStyle *style = SP_OBJECT_STYLE (obj); if (!style) continue; - if ( style->stroke.type == SP_PAINT_TYPE_NONE ) { + if ( style->stroke.isNone() ) { continue; } diff --git a/src/dialogs/fill-style.cpp b/src/dialogs/fill-style.cpp index 7ff5ebc96..3d830027c 100644 --- a/src/dialogs/fill-style.cpp +++ b/src/dialogs/fill-style.cpp @@ -207,14 +207,14 @@ sp_fill_style_widget_update (SPWidget *spw) sp_paint_selector_set_fillrule (psel, query->fill_rule.computed == ART_WIND_RULE_NONZERO? SP_PAINT_SELECTOR_FILLRULE_NONZERO : SP_PAINT_SELECTOR_FILLRULE_EVENODD); - if (query->fill.set && query->fill.type == SP_PAINT_TYPE_COLOR) { + if (query->fill.set && query->fill.isColor()) { gfloat d[3]; sp_color_get_rgb_floatv (&query->fill.value.color, d); SPColor color; sp_color_set_rgb_float (&color, d[0], d[1], d[2]); sp_paint_selector_set_color_alpha (psel, &color, SP_SCALE24_TO_FLOAT (query->fill_opacity.value)); - } else if (query->fill.set && query->fill.type == SP_PAINT_TYPE_PAINTSERVER) { + } else if (query->fill.set && query->fill.isPaintserver()) { SPPaintServer *server = SP_STYLE_FILL_SERVER (query); @@ -434,7 +434,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, int result = objects_query_fillstroke ((GSList *) items, query, true); guint32 common_rgb = 0; if (result == QUERY_STYLE_MULTIPLE_SAME) { - if (query->fill.type != SP_PAINT_TYPE_COLOR) { + if (!query->fill.isColor()) { common_rgb = sp_desktop_get_color(desktop, true); } else { common_rgb = sp_color_get_rgba32_ualpha(&query->fill.value.color, 0xff); @@ -502,7 +502,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, SPObject *selobj = SP_OBJECT (i->data); SPStyle *style = SP_OBJECT_STYLE (selobj); - if (style && style->fill.type == SP_PAINT_TYPE_PAINTSERVER) { + if (style && style->fill.isPaintserver()) { SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (selobj); if (SP_IS_PATTERN (server) && pattern_getroot (SP_PATTERN(server)) == pattern) // only if this object's pattern is not rooted in our selected pattern, apply diff --git a/src/dialogs/stroke-style.cpp b/src/dialogs/stroke-style.cpp index c7e8d8989..de367b66f 100644 --- a/src/dialogs/stroke-style.cpp +++ b/src/dialogs/stroke-style.cpp @@ -219,14 +219,7 @@ sp_stroke_style_paint_update (SPWidget *spw) SPPaintSelectorMode pselmode = sp_style_determine_paint_selector_mode (query, false); sp_paint_selector_set_mode (psel, pselmode); - if (query->stroke.set && query->stroke.type == SP_PAINT_TYPE_COLOR) { - gfloat d[3]; - sp_color_get_rgb_floatv (&query->stroke.value.color, d); - SPColor color; - sp_color_set_rgb_float (&color, d[0], d[1], d[2]); - sp_paint_selector_set_color_alpha (psel, &color, SP_SCALE24_TO_FLOAT (query->stroke_opacity.value)); - - } else if (query->stroke.set && query->stroke.type == SP_PAINT_TYPE_PAINTSERVER) { + if (query->stroke.set && query->stroke.isPaintserver()) { SPPaintServer *server = SP_STYLE_STROKE_SERVER (query); @@ -250,6 +243,13 @@ sp_stroke_style_paint_update (SPWidget *spw) SPPattern *pat = pattern_getroot (SP_PATTERN (server)); sp_update_pattern_list (psel, pat); } + } else if (query->stroke.set && query->stroke.isColor()) { + gfloat d[3]; + sp_color_get_rgb_floatv (&query->stroke.value.color, d); + SPColor color; + sp_color_set_rgb_float (&color, d[0], d[1], d[2]); + sp_paint_selector_set_color_alpha (psel, &color, SP_SCALE24_TO_FLOAT (query->stroke_opacity.value)); + } break; } @@ -390,7 +390,7 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) int result = objects_query_fillstroke ((GSList *) items, query, false); guint32 common_rgb = 0; if (result == QUERY_STYLE_MULTIPLE_SAME) { - if (query->fill.type != SP_PAINT_TYPE_COLOR) { + if (!query->fill.isColor()) { common_rgb = sp_desktop_get_color(desktop, false); } else { common_rgb = sp_color_get_rgba32_ualpha(&query->stroke.value.color, 0xff); @@ -445,7 +445,7 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) continue; SPStyle *style = SP_OBJECT_STYLE (selobj); - if (style && style->stroke.type == SP_PAINT_TYPE_PAINTSERVER) { + if (style && style->stroke.isPaintserver()) { SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (selobj); if (SP_IS_PATTERN (server) && pattern_getroot (SP_PATTERN(server)) == pattern) // only if this object's pattern is not rooted in our selected pattern, apply diff --git a/src/display/nr-arena-glyphs.cpp b/src/display/nr-arena-glyphs.cpp index 65c5b378f..3933625c3 100644 --- a/src/display/nr-arena-glyphs.cpp +++ b/src/display/nr-arena-glyphs.cpp @@ -129,8 +129,10 @@ nr_arena_glyphs_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, glyphs = NR_ARENA_GLYPHS(item); - if (!glyphs->font || !glyphs->style) return NR_ARENA_ITEM_STATE_ALL; - if ((glyphs->style->fill.type == SP_PAINT_TYPE_NONE) && (glyphs->style->stroke.type == SP_PAINT_TYPE_NONE)) return NR_ARENA_ITEM_STATE_ALL; + if (!glyphs->font || !glyphs->style) + return NR_ARENA_ITEM_STATE_ALL; + if ((glyphs->style->fill.isNone()) && (glyphs->style->stroke.isNone())) + return NR_ARENA_ITEM_STATE_ALL; NRRect bbox; bbox.x0 = bbox.y0 = NR_HUGE; @@ -138,7 +140,7 @@ nr_arena_glyphs_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, float const scale = NR_MATRIX_DF_EXPANSION(&gc->transform); - if (glyphs->style->fill.type != SP_PAINT_TYPE_NONE) { + if (!glyphs->style->fill.isNone()) { NRMatrix t; nr_matrix_multiply(&t, &glyphs->g_transform, &gc->transform); glyphs->x = t.c[4]; @@ -149,7 +151,7 @@ nr_arena_glyphs_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, if (glyphs->rfont) glyphs->rfont->Unref(); glyphs->rfont = rfont; - if (glyphs->style->stroke.type == SP_PAINT_TYPE_NONE || fabs(glyphs->style->stroke_width.computed * scale) <= 0.01) { // Optimization: do fill bbox only if there's no stroke + if (glyphs->style->stroke.isNone() || fabs(glyphs->style->stroke_width.computed * scale) <= 0.01) { // Optimization: do fill bbox only if there's no stroke NRRect narea; if ( glyphs->rfont ) glyphs->rfont->BBox(glyphs->glyph, &narea); bbox.x0 = narea.x0 + glyphs->x; @@ -157,9 +159,9 @@ nr_arena_glyphs_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, bbox.x1 = narea.x1 + glyphs->x; bbox.y1 = narea.y1 + glyphs->y; } - } + } - if (glyphs->style->stroke.type != SP_PAINT_TYPE_NONE) { + if (!glyphs->style->stroke.isNone()) { /* Build state data */ NRMatrix t; nr_matrix_multiply(&t, &glyphs->g_transform, &gc->transform); @@ -404,21 +406,21 @@ nr_arena_glyphs_group_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint s } item->render_opacity = TRUE; - if (group->style->fill.type == SP_PAINT_TYPE_PAINTSERVER) { + if (group->style->fill.isPaintserver()) { group->fill_painter = sp_paint_server_painter_new(SP_STYLE_FILL_SERVER(group->style), NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform), &group->paintbox); item->render_opacity = FALSE; } - if (group->style->stroke.type == SP_PAINT_TYPE_PAINTSERVER) { + if (group->style->stroke.isPaintserver()) { group->stroke_painter = sp_paint_server_painter_new(SP_STYLE_STROKE_SERVER(group->style), NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform), &group->paintbox); item->render_opacity = FALSE; } - if ( item->render_opacity == TRUE && group->style->stroke.type != SP_PAINT_TYPE_NONE && group->style->fill.type != SP_PAINT_TYPE_NONE ) { + if ( item->render_opacity == TRUE && !group->style->stroke.isNone() && !group->style->fill.isNone() ) { item->render_opacity=FALSE; } @@ -469,7 +471,7 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi /* Fill */ - if (style->fill.type != SP_PAINT_TYPE_NONE || item->arena->rendermode == RENDERMODE_OUTLINE) { + if (!style->fill.isNone() || item->arena->rendermode == RENDERMODE_OUTLINE) { NRPixBlock m; nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE); @@ -491,7 +493,11 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi } /* Composite into buffer */ - if (style->fill.type == SP_PAINT_TYPE_COLOR || item->arena->rendermode == RENDERMODE_OUTLINE) { + if (style->fill.isPaintserver()) { + if (ggroup->fill_painter) { + nr_arena_render_paintserver_fill(pb, area, ggroup->fill_painter, SP_SCALE24_TO_FLOAT(style->fill_opacity.value), &m); + } + } else if (style->fill.isColor() || item->arena->rendermode == RENDERMODE_OUTLINE) { guint32 rgba; if (item->arena->rendermode == RENDERMODE_OUTLINE) { // In outline mode, render fill only, using outlinecolor @@ -505,17 +511,13 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi } nr_blit_pixblock_mask_rgba32(pb, &m, rgba); pb->empty = FALSE; - } else if (style->fill.type == SP_PAINT_TYPE_PAINTSERVER) { - if (ggroup->fill_painter) { - nr_arena_render_paintserver_fill(pb, area, ggroup->fill_painter, SP_SCALE24_TO_FLOAT(style->fill_opacity.value), &m); - } } nr_pixblock_release(&m); } /* Stroke */ - if (style->stroke.type != SP_PAINT_TYPE_NONE && !(item->arena->rendermode == RENDERMODE_OUTLINE)) { + if (!style->stroke.isNone() && !(item->arena->rendermode == RENDERMODE_OUTLINE)) { NRPixBlock m; guint32 rgba; nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE); @@ -536,26 +538,23 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi } } /* Composite into buffer */ - switch (style->stroke.type) { - case SP_PAINT_TYPE_COLOR: - if ( item->render_opacity ) { - rgba = sp_color_get_rgba32_falpha(&style->stroke.value.color, - SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) * - SP_SCALE24_TO_FLOAT(style->opacity.value)); - } else { - rgba = sp_color_get_rgba32_falpha(&style->stroke.value.color, - SP_SCALE24_TO_FLOAT(style->stroke_opacity.value)); - } - nr_blit_pixblock_mask_rgba32(pb, &m, rgba); - pb->empty = FALSE; - break; - case SP_PAINT_TYPE_PAINTSERVER: - if (ggroup->stroke_painter) { - nr_arena_render_paintserver_fill(pb, area, ggroup->stroke_painter, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value), &m); - } - break; - default: - break; + if (style->stroke.isPaintserver()) { + if (ggroup->stroke_painter) { + nr_arena_render_paintserver_fill(pb, area, ggroup->stroke_painter, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value), &m); + } + } else if (style->stroke.isColor()) { + if ( item->render_opacity ) { + rgba = sp_color_get_rgba32_falpha(&style->stroke.value.color, + SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) * + SP_SCALE24_TO_FLOAT(style->opacity.value)); + } else { + rgba = sp_color_get_rgba32_falpha(&style->stroke.value.color, + SP_SCALE24_TO_FLOAT(style->stroke_opacity.value)); + } + nr_blit_pixblock_mask_rgba32(pb, &m, rgba); + pb->empty = FALSE; + } else { + // nothing } nr_pixblock_release(&m); } diff --git a/src/display/nr-arena-shape.cpp b/src/display/nr-arena-shape.cpp index f0de2d26f..d245e3928 100644 --- a/src/display/nr-arena-shape.cpp +++ b/src/display/nr-arena-shape.cpp @@ -1272,22 +1272,14 @@ nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style) if (shape->style) sp_style_unref(shape->style); shape->style = style; - switch (style->fill.type) { - case SP_PAINT_TYPE_NONE: { - shape->setFill(NULL); - break; - } - case SP_PAINT_TYPE_COLOR: { - shape->setFill(style->fill.value.color); - break; - } - case SP_PAINT_TYPE_PAINTSERVER: { - shape->setFill(style->getFillPaintServer()); - break; - } - default: { - g_assert_not_reached(); - } + if ( style->fill.isPaintserver() ) { + shape->setFill(style->getFillPaintServer()); + } else if ( style->fill.isColor() ) { + shape->setFill(style->fill.value.color); + } else if ( style->fill.isNone() ) { + shape->setFill(NULL); + } else { + g_assert_not_reached(); } shape->setFillOpacity(SP_SCALE24_TO_FLOAT(style->fill_opacity.value)); switch (style->fill_rule.computed) { @@ -1304,22 +1296,14 @@ nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style) } } - switch (style->stroke.type) { - case SP_PAINT_TYPE_NONE: { - shape->setStroke(NULL); - break; - } - case SP_PAINT_TYPE_COLOR: { - shape->setStroke(style->stroke.value.color); - break; - } - case SP_PAINT_TYPE_PAINTSERVER: { - shape->setStroke(style->getStrokePaintServer()); - break; - } - default: { - g_assert_not_reached(); - } + if ( style->stroke.isPaintserver() ) { + shape->setStroke(style->getStrokePaintServer()); + } else if ( style->stroke.isColor() ) { + shape->setStroke(style->stroke.value.color); + } else if ( style->stroke.isNone() ) { + shape->setStroke(NULL); + } else { + g_assert_not_reached(); } shape->setStrokeWidth(style->stroke_width.computed); shape->setStrokeOpacity(SP_SCALE24_TO_FLOAT(style->stroke_opacity.value)); diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index b13b95643..61d40ea4e 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -157,13 +157,13 @@ CairoRenderContext::setStateForStyle(SPStyle const *style) _state->opacity = SP_SCALE24_TO_FLOAT(style->opacity.value); _state->has_overflow = (style->overflow.set && style->overflow.value != SP_CSS_OVERFLOW_VISIBLE); - if (style->fill.type == SP_PAINT_TYPE_PAINTSERVER || style->stroke.type == SP_PAINT_TYPE_PAINTSERVER) + if (style->fill.isPaintserver() || style->stroke.isPaintserver()) _state->merge_opacity = FALSE; // disable rendering of opacity if there's a stroke on the fill if (_state->merge_opacity - && style->fill.type != SP_PAINT_TYPE_NONE - && style->stroke.type != SP_PAINT_TYPE_NONE) + && !style->fill.isNone() + && !style->stroke.isNone()) _state->merge_opacity = FALSE; } @@ -1059,8 +1059,8 @@ CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const pain void CairoRenderContext::_setFillStyle(SPStyle const *const style, NRRect const *pbox) { - g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR - || style->fill.type == SP_PAINT_TYPE_PAINTSERVER ); + g_return_if_fail( style->fill.isColor() + || style->fill.isPaintserver() ); float alpha = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); if (_state->merge_opacity) { @@ -1068,13 +1068,13 @@ CairoRenderContext::_setFillStyle(SPStyle const *const style, NRRect const *pbox TRACE(("merged op=%f\n", alpha)); } - if (style->fill.type == SP_PAINT_TYPE_COLOR) { + if (style->fill.isColor()) { float rgb[3]; sp_color_get_rgb_floatv(&style->fill.value.color, rgb); cairo_set_source_rgba(_cr, rgb[0], rgb[1], rgb[2], alpha); } else { - g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_assert( style->fill.isPaintserver() || SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) || SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) ); @@ -1094,13 +1094,13 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, NRRect const *pbox) if (_state->merge_opacity) alpha *= _state->opacity; - if (style->stroke.type == SP_PAINT_TYPE_COLOR) { + if (style->stroke.isColor()) { float rgb[3]; sp_color_get_rgb_floatv(&style->stroke.value.color, rgb); cairo_set_source_rgba(_cr, rgb[0], rgb[1], rgb[2], alpha); } else { - g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_assert( style->fill.isPaintserver() || SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) || SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style)) ); @@ -1175,7 +1175,7 @@ CairoRenderContext::renderPath(NRBPath const *bpath, SPStyle const *style, NRRec return true; } - if (style->fill.type == SP_PAINT_TYPE_NONE && style->stroke.type == SP_PAINT_TYPE_NONE) + if (style->fill.isNone() && style->stroke.isNone()) return true; bool need_layer = ( !_state->merge_opacity && !_state->need_layer && @@ -1186,7 +1186,7 @@ CairoRenderContext::renderPath(NRBPath const *bpath, SPStyle const *style, NRRec else pushLayer(); - if (style->fill.type != SP_PAINT_TYPE_NONE) { + if (!style->fill.isNone()) { _setFillStyle(style, pbox); setBpath(bpath->path); @@ -1196,15 +1196,15 @@ CairoRenderContext::renderPath(NRBPath const *bpath, SPStyle const *style, NRRec cairo_set_fill_rule(_cr, CAIRO_FILL_RULE_WINDING); } - if (style->stroke.type == SP_PAINT_TYPE_NONE) + if (style->stroke.isNone()) cairo_fill(_cr); else cairo_fill_preserve(_cr); } - if (style->stroke.type != SP_PAINT_TYPE_NONE) { + if (!style->stroke.isNone()) { _setStrokeStyle(style, pbox); - if (style->fill.type == SP_PAINT_TYPE_NONE) + if (style->fill.isNone()) setBpath(bpath->path); cairo_stroke(_cr); diff --git a/src/extension/internal/latex-pstricks.cpp b/src/extension/internal/latex-pstricks.cpp index 990c094a4..116cccb3b 100644 --- a/src/extension/internal/latex-pstricks.cpp +++ b/src/extension/internal/latex-pstricks.cpp @@ -206,7 +206,7 @@ PrintLatex::fill(Inkscape::Extension::Print *mod, { if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (style->fill.type == SP_PAINT_TYPE_COLOR) { + if (style->fill.isColor()) { Inkscape::SVGOStringStream os; float rgb[3]; @@ -233,7 +233,7 @@ PrintLatex::stroke (Inkscape::Extension::Print *mod, const NRBPath *bpath, const { if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (style->stroke.type == SP_PAINT_TYPE_COLOR) { + if (style->stroke.isColor()) { Inkscape::SVGOStringStream os; float rgb[3]; NR::Matrix tr_stack = m_tr_stack.top(); diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index f67800ca5..61e3e593e 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -1557,7 +1557,7 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, StyleInfo si; //## FILL - if (style->fill.type == SP_PAINT_TYPE_COLOR) + if (style->fill.isColor()) { guint32 fillCol = sp_color_get_rgba32_ualpha(&style->fill.value.color, 0); @@ -1576,7 +1576,7 @@ bool OdfOutput::processStyle(Writer &outs, SPItem *item, } //## STROKE - if (style->stroke.type == SP_PAINT_TYPE_COLOR) + if (style->stroke.isColor()) { guint32 strokeCol = sp_color_get_rgba32_ualpha(&style->stroke.value.color, 0); @@ -1658,7 +1658,7 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, if (!style) return false; - if (style->fill.type != SP_PAINT_TYPE_PAINTSERVER) + if (!style->fill.isPaintserver()) return false; //## Gradient. Look in writeStyle() below to see what info diff --git a/src/extension/internal/pdf-cairo.cpp b/src/extension/internal/pdf-cairo.cpp index 0b500864d..e1a168c27 100644 --- a/src/extension/internal/pdf-cairo.cpp +++ b/src/extension/internal/pdf-cairo.cpp @@ -533,11 +533,11 @@ PrintCairoPDF::create_pattern_for_paint(SPPaintServer const *const paintserver, void PrintCairoPDF::print_fill_style(cairo_t *cr, SPStyle const *const style, NRRect const *pbox) { - g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_return_if_fail( style->fill.isColor() + || ( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ); - if (style->fill.type == SP_PAINT_TYPE_COLOR) { + if (style->fill.isColor()) { float rgb[3]; sp_color_get_rgb_floatv(&style->fill.value.color, rgb); @@ -545,7 +545,7 @@ PrintCairoPDF::print_fill_style(cairo_t *cr, SPStyle const *const style, NRRect cairo_set_source_rgba(cr, rgb[0], rgb[1], rgb[2], alpha); } else { - g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_assert( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); cairo_pattern_t *pattern = create_pattern_for_paint(SP_STYLE_FILL_SERVER(style), pbox, 1.0); @@ -564,14 +564,14 @@ PrintCairoPDF::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMat if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - if ( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { - + if ( style->fill.isColor() + || ( style->fill.isPaintserver() + && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { + float alpha = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); - + cairo_save(cr); - + print_fill_style(cr, style, pbox); print_bpath(cr, bpath->path); if (style->fill_rule.value == SP_WIND_RULE_EVENODD) { @@ -580,7 +580,7 @@ PrintCairoPDF::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMat cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING); } if (alpha != 1.0 && - style->fill.type != SP_PAINT_TYPE_COLOR) { + !style->fill.isColor()) { cairo_clip (cr); cairo_paint_with_alpha (cr, alpha); @@ -599,12 +599,12 @@ PrintCairoPDF::print_stroke_style(cairo_t *cr, SPStyle const *style, NRRect cons { float alpha = SP_SCALE24_TO_FLOAT(style->stroke_opacity.value); - if ( style->stroke.type == SP_PAINT_TYPE_COLOR ) { + if ( style->stroke.isColor() ) { float rgb[3]; sp_color_get_rgb_floatv(&style->stroke.value.color, rgb); cairo_set_source_rgba(cr, rgb[0], rgb[1], rgb[2], alpha); - } else if ( style->stroke.type == SP_PAINT_TYPE_PAINTSERVER + } else if ( style->stroke.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) { cairo_pattern_t *pattern = create_pattern_for_paint(SP_STYLE_STROKE_SERVER(style), pbox, alpha); @@ -664,16 +664,16 @@ PrintCairoPDF::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRM if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - if ( style->stroke.type == SP_PAINT_TYPE_COLOR || - ( style->stroke.type == SP_PAINT_TYPE_PAINTSERVER + if ( style->stroke.isColor() || + ( style->stroke.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) ) { - cairo_save(cr); - - print_stroke_style(cr, style, pbox); + cairo_save(cr); + + print_stroke_style(cr, style, pbox); print_bpath(cr, bpath->path); cairo_stroke(cr); - + cairo_restore(cr); } @@ -884,8 +884,8 @@ PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point cairo_set_font_matrix(cr, &matrix); #endif - if ( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + if ( style->fill.isColor() + || ( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { // set fill style @@ -904,8 +904,8 @@ PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point #endif } - if (style->stroke.type == SP_PAINT_TYPE_COLOR - || ( style->stroke.type == SP_PAINT_TYPE_PAINTSERVER + if (style->stroke.isColor() + || ( style->stroke.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) ) { // set stroke style diff --git a/src/extension/internal/pov-out.cpp b/src/extension/internal/pov-out.cpp index 7318fa784..c915de75b 100644 --- a/src/extension/internal/pov-out.cpp +++ b/src/extension/internal/pov-out.cpp @@ -328,7 +328,7 @@ void PovOutput::doCurves(SPDocument *doc) SPStyle *style = SP_OBJECT_STYLE(shape); /* fixme: Handle other fill types, even if this means translating gradients to a single flat colour. */ - if (style && (style->fill.type == SP_PAINT_TYPE_COLOR)) + if (style && (style->fill.isColor())) { // see color.h for how to parse SPColor float rgb[3]; diff --git a/src/extension/internal/ps.cpp b/src/extension/internal/ps.cpp index 8cf284536..ac424e85e 100644 --- a/src/extension/internal/ps.cpp +++ b/src/extension/internal/ps.cpp @@ -646,18 +646,18 @@ PrintPS::comment(Inkscape::Extension::Print *mod, char const *comment) void PrintPS::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRRect const *pbox) { - g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_return_if_fail( style->fill.isColor() + || ( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ); - if (style->fill.type == SP_PAINT_TYPE_COLOR) { + if (style->fill.isColor()) { float rgb[3]; sp_color_get_rgb_floatv(&style->fill.value.color, rgb); os << rgb[0] << " " << rgb[1] << " " << rgb[2] << " setrgbcolor\n"; } else { - g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_assert( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); if (SP_IS_LINEARGRADIENT(SP_STYLE_FILL_SERVER(style))) { @@ -799,8 +799,8 @@ PrintPS::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix co if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - if ( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + if ( style->fill.isColor() + || ( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { Inkscape::SVGOStringStream os; @@ -812,10 +812,10 @@ PrintPS::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix co print_bpath(os, bpath->path); if (style->fill_rule.value == SP_WIND_RULE_EVENODD) { - if (style->fill.type == SP_PAINT_TYPE_COLOR) { + if (style->fill.isColor()) { os << "eofill\n"; } else { - g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_assert( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style)); os << "eoclip\n"; @@ -830,10 +830,10 @@ PrintPS::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix co } } } else { - if (style->fill.type == SP_PAINT_TYPE_COLOR) { + if (style->fill.isColor()) { os << "fill\n"; } else { - g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_assert( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style)); os << "clip\n"; @@ -865,7 +865,7 @@ PrintPS::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - if (style->stroke.type == SP_PAINT_TYPE_COLOR) { + if (style->stroke.isColor()) { Inkscape::SVGOStringStream os; print_stroke_style(os, style); @@ -1367,8 +1367,8 @@ PrintPS::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p, //The commented line beneath causes Inkscape to crash under Linux but not under Windows //g_free((void*) fn); - if ( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + if ( style->fill.isColor() + || ( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { // set fill style @@ -1385,7 +1385,7 @@ PrintPS::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p, os << ") show\n"; } - if (style->stroke.type == SP_PAINT_TYPE_COLOR) { + if (style->stroke.isColor()) { // set stroke style print_stroke_style(os, style); diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index fce26435c..0690ef140 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -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) { @@ -453,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); @@ -1067,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 @@ -1223,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 = sp_color_get_rgba32_ualpha(&paint.value.color, 0xff); } else { // if o doesn't use flat color, then take current color of the desktop. rgba = sp_desktop_get_color(desktop, is_fill); diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 171881a78..59081475e 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -153,12 +153,12 @@ gr_drag_style_query (SPStyle *style, int property, gpointer data) cf[3] /= count; // set both fill and stroke with our stop-color and stop-opacity - sp_color_set_rgb_float((SPColor *) &style->fill.value.color, cf[0], cf[1], cf[2]); + style->fill.clear(); + style->fill.setColor( cf[0], cf[1], cf[2] ); style->fill.set = TRUE; - style->fill.type = SP_PAINT_TYPE_COLOR; - sp_color_set_rgb_float((SPColor *) &style->stroke.value.color, cf[0], cf[1], cf[2]); + style->stroke.clear(); + style->stroke.setColor( cf[0], cf[1], cf[2] ); style->stroke.set = TRUE; - style->stroke.type = SP_PAINT_TYPE_COLOR; style->fill_opacity.value = SP_SCALE24_FROM_FLOAT (1.0); style->fill_opacity.set = TRUE; @@ -1377,7 +1377,7 @@ GrDrag::updateDraggers () SPItem *item = SP_ITEM(i->data); SPStyle *style = SP_OBJECT_STYLE (item); - 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_LINEARGRADIENT (server)) { addDraggersLinear (SP_LINEARGRADIENT (server), item, true); @@ -1386,7 +1386,7 @@ GrDrag::updateDraggers () } } - 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_LINEARGRADIENT (server)) { addDraggersLinear (SP_LINEARGRADIENT (server), item, false); @@ -1419,7 +1419,7 @@ GrDrag::updateLines () SPStyle *style = SP_OBJECT_STYLE (item); - 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_LINEARGRADIENT (server)) { this->addLine (sp_item_gradient_get_coords (item, POINT_LG_BEGIN, 0, true), sp_item_gradient_get_coords (item, POINT_LG_END, 0, true), GR_LINE_COLOR_FILL); @@ -1430,7 +1430,7 @@ GrDrag::updateLines () } } - 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_LINEARGRADIENT (server)) { this->addLine (sp_item_gradient_get_coords (item, POINT_LG_BEGIN, 0, false), sp_item_gradient_get_coords (item, POINT_LG_END, 0, false), GR_LINE_COLOR_STROKE); diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index 68d7752c3..21d8c8e48 100755 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -158,9 +158,9 @@ void Layout::print(SPPrintContext *ctx, NRBPath abp; _getGlyphTransformMatrix(glyph_index, &glyph_matrix); abp.path = nr_artpath_affine(bpath.path, glyph_matrix); - if (text_source->style->fill.type != SP_PAINT_TYPE_NONE) + if (!text_source->style->fill.isNone()) sp_print_fill(ctx, &abp, &ctm, text_source->style, pbox, dbox, bbox); - if (text_source->style->stroke.type != SP_PAINT_TYPE_NONE) + if (!text_source->style->stroke.isNone()) sp_print_stroke(ctx, &abp, &ctm, text_source->style, pbox, dbox, bbox); g_free(abp.path); } diff --git a/src/object-edit.cpp b/src/object-edit.cpp index fa0090c7f..63ccf827e 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -1359,7 +1359,7 @@ sp_offset_knot_holder(SPItem *item, SPDesktop *desktop) static SPKnotHolder * sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag { - if ((SP_OBJECT(item)->style->fill.type == SP_PAINT_TYPE_PAINTSERVER) + if ((SP_OBJECT(item)->style->fill.isPaintserver()) && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) { SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); @@ -1374,7 +1374,7 @@ sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, inste static void sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder) { - if ((SP_OBJECT(item)->style->fill.type == SP_PAINT_TYPE_PAINTSERVER) + if ((SP_OBJECT(item)->style->fill.isPaintserver()) && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) { sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR, diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 99f66130f..a8cb4d4fe 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -910,7 +910,7 @@ void sp_copy_stuff_used_by_item (GSList **defs_clip, SPItem *item, const GSList { SPStyle *style = SP_OBJECT_STYLE (item); - 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_LINEARGRADIENT (server) || SP_IS_RADIALGRADIENT (server)) sp_copy_gradient (defs_clip, SP_GRADIENT(server), xml_doc); @@ -918,7 +918,7 @@ void sp_copy_stuff_used_by_item (GSList **defs_clip, SPItem *item, const GSList sp_copy_pattern (defs_clip, SP_PATTERN(server), xml_doc); } - 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_LINEARGRADIENT (server) || SP_IS_RADIALGRADIENT (server)) sp_copy_gradient (defs_clip, SP_GRADIENT(server), xml_doc); @@ -2396,7 +2396,7 @@ sp_selection_untile() SPStyle *style = SP_OBJECT_STYLE (item); - if (!style || style->fill.type != SP_PAINT_TYPE_PAINTSERVER) + if (!style || !style->fill.isPaintserver()) continue; SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(item); diff --git a/src/shape-editor.cpp b/src/shape-editor.cpp index 72c5ef058..d9a500e3c 100644 --- a/src/shape-editor.cpp +++ b/src/shape-editor.cpp @@ -269,7 +269,7 @@ bool ShapeEditor::is_over_stroke (NR::Point event_p, bool remember) { delta = desktop->d2w(delta); double stroke_tolerance = - (SP_OBJECT_STYLE (item)->stroke.type != SP_PAINT_TYPE_NONE? + ( !SP_OBJECT_STYLE(item)->stroke.isNone() ? desktop->current_zoom() * SP_OBJECT_STYLE (item)->stroke_width.computed * sp_item_i2d_affine (item).expansion() * 0.5 diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index daa9f808a..87e3246f9 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -329,7 +329,7 @@ sp_flowtext_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, // Add stroke width SPStyle* style=SP_OBJECT_STYLE (item); - if (style->stroke.type != SP_PAINT_TYPE_NONE) { + if ( !style->stroke.isNone() ) { double const scale = expansion(transform); if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord double const width = MAX(0.125, style->stroke_width.computed * scale); diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 338a70c4e..4a5c0079b 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -978,7 +978,7 @@ sp_item_adjust_pattern (SPItem *item, NR::Matrix const &postmul, bool set) { SPStyle *style = SP_OBJECT_STYLE (item); - 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_PATTERN (server)) { SPPattern *pattern = sp_pattern_clone_if_necessary (item, SP_PATTERN (server), "fill"); @@ -986,7 +986,7 @@ sp_item_adjust_pattern (SPItem *item, NR::Matrix const &postmul, bool set) } } - 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_PATTERN (server)) { SPPattern *pattern = sp_pattern_clone_if_necessary (item, SP_PATTERN (server), "stroke"); @@ -1001,7 +1001,7 @@ sp_item_adjust_gradient (SPItem *item, NR::Matrix const &postmul, bool set) { SPStyle *style = SP_OBJECT_STYLE (item); - 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)) { @@ -1020,7 +1020,7 @@ sp_item_adjust_gradient (SPItem *item, NR::Matrix const &postmul, bool set) } } - 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)) { SPGradient *gradient = sp_gradient_convert_to_userspace (SP_GRADIENT (server), item, "stroke"); @@ -1034,7 +1034,7 @@ sp_item_adjust_stroke (SPItem *item, gdouble ex) { SPStyle *style = SP_OBJECT_STYLE (item); - if (style && style->stroke.type != SP_PAINT_TYPE_NONE && !NR_DF_TEST_CLOSE (ex, 1.0, NR_EPSILON)) { + if (style && !style->stroke.isNone() && !NR_DF_TEST_CLOSE (ex, 1.0, NR_EPSILON)) { style->stroke_width.computed *= ex; style->stroke_width.set = TRUE; diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index 9a74b7217..ff0ebf887 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -714,7 +714,7 @@ static void sp_shape_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &tr if ((SPItem::BBoxType) flags != SPItem::GEOMETRIC_BBOX) { SPStyle* style=SP_OBJECT_STYLE (item); - if (style->stroke.type != SP_PAINT_TYPE_NONE) { + if (!style->stroke.isNone()) { double const scale = expansion(transform); if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord double const width = MAX(0.125, style->stroke_width.computed * scale); @@ -795,13 +795,13 @@ sp_shape_print (SPItem *item, SPPrintContext *ctx) SPStyle* style = SP_OBJECT_STYLE (item); - if (style->fill.type != SP_PAINT_TYPE_NONE) { + if (!style->fill.isNone()) { NRBPath bp; bp.path = SP_CURVE_BPATH(shape->curve); sp_print_fill (ctx, &bp, i2d, style, &pbox, &dbox, &bbox); } - if (style->stroke.type != SP_PAINT_TYPE_NONE) { + if (!style->stroke.isNone()) { NRBPath bp; bp.path = SP_CURVE_BPATH(shape->curve); sp_print_stroke (ctx, &bp, i2d, style, &pbox, &dbox, &bbox); diff --git a/src/sp-text.cpp b/src/sp-text.cpp index cc575d99f..1c677edb2 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -356,7 +356,7 @@ sp_text_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsi // Add stroke width SPStyle* style=SP_OBJECT_STYLE (item); - if (style->stroke.type != SP_PAINT_TYPE_NONE) { + if (!style->stroke.isNone()) { double const scale = expansion(transform); if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord double const width = MAX(0.125, style->stroke_width.computed * scale); diff --git a/src/sp-tref.cpp b/src/sp-tref.cpp index 28db57990..164204361 100644 --- a/src/sp-tref.cpp +++ b/src/sp-tref.cpp @@ -334,7 +334,7 @@ sp_tref_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsi // Add stroke width SPStyle* style=SP_OBJECT_STYLE (item); - if (style->stroke.type != SP_PAINT_TYPE_NONE) { + if (!style->stroke.isNone()) { double const scale = expansion(transform); if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord double const width = MAX(0.125, style->stroke_width.computed * scale); diff --git a/src/sp-tspan.cpp b/src/sp-tspan.cpp index face70aef..a767ab194 100644 --- a/src/sp-tspan.cpp +++ b/src/sp-tspan.cpp @@ -213,7 +213,7 @@ static void sp_tspan_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &tr // Add stroke width SPStyle* style=SP_OBJECT_STYLE (item); - if (style->stroke.type != SP_PAINT_TYPE_NONE) { + if (!style->stroke.isNone()) { double const scale = expansion(transform); if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord double const width = MAX(0.125, style->stroke_width.computed * scale); diff --git a/src/style.cpp b/src/style.cpp index 5817df342..70e294848 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -100,8 +100,6 @@ static gint sp_style_write_ilengthornormal(gchar *p, gint const len, gchar const static gint sp_style_write_itextdecoration(gchar *p, gint const len, gchar const *const key, SPITextDecoration const *const val, SPITextDecoration const *const base, guint const flags); static gint sp_style_write_ifilter(gchar *b, gint len, gchar const *key, SPIFilter const *filter, SPIFilter const *base, guint flags); -static void sp_style_paint_clear(SPStyle *style, SPIPaint *paint); - static void sp_style_filter_clear(SPStyle *style); #define SPS_READ_IENUM_IF_UNSET(v,s,d,i) if (!(v)->set) {sp_style_read_ienum((v), (s), (d), (i));} @@ -328,6 +326,7 @@ static SPStyleEnum const enum_enable_background[] = { static void sp_style_object_release(SPObject *object, SPStyle *style) { + (void)object; // TODO style->object = NULL; } @@ -337,6 +336,7 @@ sp_style_object_release(SPObject *object, SPStyle *style) static void sp_style_filter_ref_modified(SPObject *obj, guint flags, SPStyle *style) { + (void)flags; // TODO SPFilter *filter=static_cast(obj); if (style->getFilter() == filter) { @@ -371,9 +371,10 @@ sp_style_filter_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style) static void sp_style_paint_server_ref_modified(SPObject *obj, guint flags, SPStyle *style) { + (void)flags; // TODO SPPaintServer *server = static_cast(obj); - if ((style->fill.type == SP_PAINT_TYPE_PAINTSERVER) + if ((style->fill.isPaintserver()) && style->getFillPaintServer() == server) { if (style->object) { @@ -387,14 +388,14 @@ sp_style_paint_server_ref_modified(SPObject *obj, guint flags, SPStyle *style) */ style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } - } else if ((style->stroke.type == SP_PAINT_TYPE_PAINTSERVER) + } else if ((style->stroke.isPaintserver()) && style->getStrokePaintServer() == server) { if (style->object) { /// \todo fixme: style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } - } else { + } else if (server) { g_assert_not_reached(); } } @@ -532,8 +533,8 @@ sp_style_unref(SPStyle *style) style->fill_ps_modified_connection.~connection(); style->stroke_ps_modified_connection.~connection(); - sp_style_paint_clear(style, &style->fill); - sp_style_paint_clear(style, &style->stroke); + style->fill.clear(); + style->stroke.clear(); sp_style_filter_clear(style); g_free(style->stroke_dash.dash); @@ -2090,30 +2091,26 @@ sp_style_set_to_uri_string (SPStyle *style, bool isfill, const gchar *uri) static void sp_style_merge_ipaint(SPStyle *style, SPIPaint *paint, SPIPaint const *parent) { - sp_style_paint_clear(style, paint); - if ((paint->set && paint->currentcolor) || parent->currentcolor) { + paint->clear(); paint->currentcolor = TRUE; - paint->type = SP_PAINT_TYPE_COLOR; - sp_color_copy(&paint->value.color, &style->color.value.color); + paint->setColor(style->color.value.color); return; } - paint->type = parent->type; - switch (paint->type) { - case SP_PAINT_TYPE_COLOR: - sp_color_copy(&paint->value.color, &parent->value.color); - break; - case SP_PAINT_TYPE_PAINTSERVER: - if (parent->value.href) { - sp_style_set_ipaint_to_uri(style, paint, parent->value.href->getURI(), parent->value.href->getOwnerDocument()); - } - break; - case SP_PAINT_TYPE_NONE: - break; - default: - g_assert_not_reached(); - break; + paint->clear(); + if ( parent->isPaintserver() ) { + if (parent->value.href) { + sp_style_set_ipaint_to_uri(style, paint, parent->value.href->getURI(), parent->value.href->getOwnerDocument()); + } else { + g_warning("Expected paint server not found."); + } + } else if ( parent->isColor() ) { + paint->setColor( parent->value.color ); + } else if ( parent->isNone() ) { + // + } else { + g_assert_not_reached(); } } @@ -2414,11 +2411,11 @@ sp_style_clear(SPStyle *style) { g_return_if_fail(style != NULL); - sp_style_paint_clear(style, &style->fill); - sp_style_paint_clear(style, &style->stroke); + style->fill.clear(); + style->stroke.clear(); sp_style_filter_clear(style); - if (style->fill.value.href) + if (style->fill.value.href) delete style->fill.value.href; if (style->stroke.value.href) delete style->stroke.value.href; @@ -2528,17 +2525,15 @@ sp_style_clear(SPStyle *style) style->overflow.set = FALSE; style->overflow.value = style->overflow.computed = SP_CSS_OVERFLOW_VISIBLE; - style->color.type = SP_PAINT_TYPE_COLOR; - sp_color_set_rgb_float(&style->color.value.color, 0.0, 0.0, 0.0); + style->color.clear(); + style->color.setColor(0.0, 0.0, 0.0); - style->fill.type = SP_PAINT_TYPE_COLOR; - sp_color_set_rgb_float(&style->fill.value.color, 0.0, 0.0, 0.0); + style->fill.clear(); + style->fill.setColor(0.0, 0.0, 0.0); style->fill_opacity.value = SP_SCALE24_MAX; style->fill_rule.value = style->fill_rule.computed = SP_WIND_RULE_NONZERO; - style->stroke.type = SP_PAINT_TYPE_NONE; - style->stroke.set = FALSE; - sp_color_set_rgb_float(&style->stroke.value.color, 0.0, 0.0, 0.0); + style->stroke.clear(); style->stroke_opacity.value = SP_SCALE24_MAX; style->stroke_width.set = FALSE; @@ -2958,6 +2953,8 @@ sp_style_read_itextdecoration(SPITextDecoration *val, gchar const *str) static void sp_style_read_icolor(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocument *document) { + (void)style; // TODO + (void)document; // TODO paint->currentcolor = FALSE; /* currentColor not a valid . */ if (!strcmp(str, "inherit")) { paint->set = TRUE; @@ -2965,9 +2962,7 @@ sp_style_read_icolor(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume } else { guint32 const rgb0 = sp_svg_read_color(str, 0xff); if (rgb0 != 0xff) { - paint->type = SP_PAINT_TYPE_COLOR; - sp_color_set_rgb_rgba32(&paint->value.color, rgb0); - paint->set = TRUE; + paint->setColor(rgb0); paint->inherit = FALSE; } } @@ -2986,19 +2981,12 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume ++str; } - if (paint->value.href && paint->value.href->getObject()) { - paint->value.href->detach(); - } - paint->colorSet = FALSE; - paint->currentcolor = FALSE; - paint->noneSet = FALSE; + paint->clear(); if (streq(str, "inherit")) { paint->set = TRUE; paint->inherit = TRUE; } else { - paint->type = SP_PAINT_TYPE_NONE; - paint->inherit = FALSE; if ( strneq(str, "url", 3) ) { gchar *uri = extract_uri( str, &str ); while ( g_ascii_isspace(*str) ) { @@ -3006,7 +2994,6 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume } // TODO check on and comment the comparrison "paint != &style->color". if ( uri && *uri && (paint != &style->color) ) { - paint->type = SP_PAINT_TYPE_PAINTSERVER; paint->set = TRUE; // it may be that this style's SPIPaint has not yet created its URIReference; @@ -3031,12 +3018,8 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume } else { guint32 const rgb0 = sp_svg_read_color(str, &str, 0xff); if (rgb0 != 0xff) { - if ( paint->type != SP_PAINT_TYPE_PAINTSERVER ) { - paint->type = SP_PAINT_TYPE_COLOR; - } - sp_color_set_rgb_rgba32(&paint->value.color, rgb0); + paint->setColor( rgb0 ); paint->set = TRUE; - paint->colorSet = true; while (g_ascii_isspace(*str)) { ++str; @@ -3523,9 +3506,21 @@ sp_style_write_itextdecoration(gchar *p, gint const len, gchar const *const key, static bool sp_paint_differ(SPIPaint const *const a, SPIPaint const *const b) { - if (a->type != b->type) + if ( (a->isColor() != b->isColor()) + || (a->isPaintserver() != b->isPaintserver()) + || (a->set != b->set) + || (a->currentcolor != b->currentcolor) + || (a->inherit!= b->inherit) ) { return true; - if (a->type == SP_PAINT_TYPE_COLOR) + } + + // TODO refactor to allow for mixed paints (rgb() *and* url(), etc) + + if ( a->isPaintserver() ) { + return (a->value.href == NULL || b->value.href == NULL || a->value.href->getObject() != b->value.href->getObject()); + } + + if ( a->isColor() ) { return !(sp_color_is_equal(&a->value.color, &b->value.color) && ((a->value.iccColor == b->value.iccColor) || (a->value.iccColor && b->value.iccColor @@ -3533,8 +3528,8 @@ sp_paint_differ(SPIPaint const *const a, SPIPaint const *const b) && (a->value.iccColor->colors == b->value.iccColor->colors)))); /* todo: Allow for epsilon differences in iccColor->colors, e.g. changes small enough not to show up * in the string representation. */ - if (a->type == SP_PAINT_TYPE_PAINTSERVER) - return (a->value.href == NULL || b->value.href == NULL || a->value.href->getObject() != b->value.href->getObject()); + } + return false; } @@ -3672,6 +3667,7 @@ sp_style_write_ifilter(gchar *p, gint const len, gchar const *key, SPIFilter const *const val, SPIFilter const *const base, guint const flags) { + (void)base; // TODO if ((flags & SP_STYLE_FLAG_ALWAYS) || ((flags & SP_STYLE_FLAG_IFSET) && val->set) || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set)) @@ -3688,18 +3684,21 @@ sp_style_write_ifilter(gchar *p, gint const len, gchar const *key, } -/** - * Clear paint object, and disconnect style from paintserver (if present). - */ -static void -sp_style_paint_clear(SPStyle *style, SPIPaint *paint) +void SPIPaint::clear() { - if (paint->value.href && paint->value.href->getObject()) - paint->value.href->detach(); + set = false; + inherit = false; + currentcolor = false; + colorSet = false; + noneSet = false; + sp_color_set_rgb_rgba32( &value.color, 0 ); + if ( value.href && value.href->getObject() ) + { + value.href->detach(); + } - paint->type = SP_PAINT_TYPE_NONE; - delete paint->value.iccColor; - paint->value.iccColor = NULL; + delete value.iccColor; + value.iccColor = 0; } @@ -3710,7 +3709,7 @@ static void sp_style_filter_clear(SPStyle *style) { if (style->filter.href && style->filter.href->getObject()) - style->filter.href->detach(); + style->filter.href->detach(); } diff --git a/src/style.h b/src/style.h index 3a547bfb9..623291941 100644 --- a/src/style.h +++ b/src/style.h @@ -144,13 +144,6 @@ struct SPILength { #define SP_OBJECT_STYLE_FILL_SERVER(o) (SP_OBJECT (o)->style->getFillPaintServer()) #define SP_OBJECT_STYLE_STROKE_SERVER(o) (SP_OBJECT (o)->style->getStrokePaintServer()) -enum { - SP_PAINT_TYPE_NONE, - SP_PAINT_TYPE_COLOR, - SP_PAINT_TYPE_PAINTSERVER, - SP_PAINT_TYPE_IMPOSSIBLE -}; - class SVGICCColor; /// Paint type internal to SPStyle. @@ -158,14 +151,29 @@ struct SPIPaint { unsigned set : 1; unsigned inherit : 1; unsigned currentcolor : 1; - unsigned type : 2; unsigned int colorSet : 1; unsigned int noneSet : 1; struct { - SPPaintServerReference *href; - SPColor color; - SVGICCColor *iccColor; + SPPaintServerReference *href; + SPColor color; + SVGICCColor *iccColor; } value; + + + bool isSet() const { return true; /* set || colorSet*/} + bool isSameType( SPIPaint const & other ) const {return (isPaintserver() == other.isPaintserver()) && (colorSet == other.colorSet) && (currentcolor == other.currentcolor);} + + bool isNoneSet() const {return noneSet;} + + bool isNone() const {return !currentcolor && !colorSet && !isPaintserver();} // TODO refine + bool isColor() const {return colorSet && !isPaintserver();} + bool isPaintserver() const {return value.href && value.href->getObject();} + + void clear(); + + void setColor( float r, float g, float b ) {sp_color_set_rgb_float(&value.color, r, g, b); colorSet = true;} + void setColor( guint32 val ) {sp_color_set_rgb_rgba32(&value.color, val); colorSet = true;} + void setColor( SPColor const& color ) {value.color = color; colorSet = true;} }; /// Filter type internal to SPStyle diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index 1e7379dea..49b39a5e6 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -747,27 +747,27 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point, } else { this_force = force * tweak_profile (NR::L2 (p - center), radius); } - + if (this_force > 0.002) { if (do_fill) { - if (style->fill.type == SP_PAINT_TYPE_COLOR) { + if (style->fill.isPaintserver()) { + tweak_colors_in_gradient (item, true, fill_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o); + did = true; + } else if (style->fill.isColor()) { tweak_color (mode, style->fill.value.color.v.c, fill_goal, this_force, do_h, do_s, do_l); item->updateRepr(); did = true; - } else if (style->fill.type == SP_PAINT_TYPE_PAINTSERVER) { - tweak_colors_in_gradient (item, true, fill_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o); - did = true; } } if (do_stroke) { - if (style->stroke.type == SP_PAINT_TYPE_COLOR) { + if (style->stroke.isPaintserver()) { + tweak_colors_in_gradient (item, false, stroke_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o); + did = true; + } else if (style->stroke.isColor()) { tweak_color (mode, style->stroke.value.color.v.c, stroke_goal, this_force, do_h, do_s, do_l); item->updateRepr(); did = true; - } else if (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER) { - tweak_colors_in_gradient (item, false, stroke_goal, p, radius, this_force, mode, do_h, do_s, do_l, do_o); - did = true; } } if (do_opacity && do_o) { diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index e2ac69b4c..763913b27 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -917,21 +917,7 @@ SelectedStyle::update() } else { paint = &(query->stroke); } - if (paint->set && paint->type == SP_PAINT_TYPE_COLOR) { - guint32 color = sp_color_get_rgba32_falpha (&(paint->value.color), - SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value)); - _lastselected[i] = _thisselected[i]; - _thisselected[i] = color | 0xff; // only color, opacity === 1 - ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color); - _color_preview[i]->show_all(); - place->add(*_color_preview[i]); - gchar c_string[64]; - g_snprintf (c_string, 64, "%06x/%.3g", color >> 8, SP_RGBA32_A_F(color)); - _tooltips.set_tip(*place, __color[i] + ": " + c_string); - _mode[i] = SS_COLOR; - _popup_copy[i].set_sensitive(true); - - } else if (paint->set && paint->type == SP_PAINT_TYPE_PAINTSERVER) { + if (paint->set && paint->isPaintserver()) { SPPaintServer *server = (i == SS_FILL)? SP_STYLE_FILL_SERVER (query) : SP_STYLE_STROKE_SERVER (query); if ( server ) { Inkscape::XML::Node *srepr = SP_OBJECT_REPR(server); @@ -959,8 +945,21 @@ SelectedStyle::update() } else { g_warning ("file %s: line %d: Unknown paint server", __FILE__, __LINE__); } + } else if (paint->set && paint->isColor()) { + guint32 color = sp_color_get_rgba32_falpha (&(paint->value.color), + SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value)); + _lastselected[i] = _thisselected[i]; + _thisselected[i] = color | 0xff; // only color, opacity === 1 + ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color); + _color_preview[i]->show_all(); + place->add(*_color_preview[i]); + gchar c_string[64]; + g_snprintf (c_string, 64, "%06x/%.3g", color >> 8, SP_RGBA32_A_F(color)); + _tooltips.set_tip(*place, __color[i] + ": " + c_string); + _mode[i] = SS_COLOR; + _popup_copy[i].set_sensitive(true); - } else if (paint->set && paint->type == SP_PAINT_TYPE_NONE) { + } else if (paint->set && paint->isNone()) { place->add(_none[i]); _tooltips.set_tip(*place, __none[i]); _mode[i] = SS_NONE; diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index cad07fbd6..4d5a7fc12 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -289,21 +289,7 @@ StyleSwatch::setStyle(SPStyle *query) paint = &(query->stroke); } - if (paint->set && paint->type == SP_PAINT_TYPE_COLOR) { - guint32 color = sp_color_get_rgba32_falpha (&(paint->value.color), - SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value)); - ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color); - _color_preview[i]->show_all(); - place->add(*_color_preview[i]); - gchar *tip; - if (i == SS_FILL) { - tip = g_strdup_printf (_("Fill: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color)); - } else { - tip = g_strdup_printf (_("Stroke: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color)); - } - _tooltips.set_tip(*place, tip); - g_free (tip); - } else if (paint->set && paint->type == SP_PAINT_TYPE_PAINTSERVER) { + if (paint->set && paint->isPaintserver()) { SPPaintServer *server = (i == SS_FILL)? SP_STYLE_FILL_SERVER (query) : SP_STYLE_STROKE_SERVER (query); if (SP_IS_LINEARGRADIENT (server)) { @@ -320,7 +306,21 @@ StyleSwatch::setStyle(SPStyle *query) _tooltips.set_tip(*place, (i == SS_FILL)? (_("Pattern fill")) : (_("Pattern stroke"))); } - } else if (paint->set && paint->type == SP_PAINT_TYPE_NONE) { + } else if (paint->set && paint->isColor()) { + guint32 color = sp_color_get_rgba32_falpha (&(paint->value.color), + SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value)); + ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color); + _color_preview[i]->show_all(); + place->add(*_color_preview[i]); + gchar *tip; + if (i == SS_FILL) { + tip = g_strdup_printf (_("Fill: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color)); + } else { + tip = g_strdup_printf (_("Stroke: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color)); + } + _tooltips.set_tip(*place, tip); + g_free (tip); + } else if (paint->set && paint->isNone()) { _value[i].set_markup(_("None")); place->add(_value[i]); _tooltips.set_tip(*place, (i == SS_FILL)? (_("No fill")) : (_("No stroke"))); diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 49e72bc21..f6441b208 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -76,7 +76,7 @@ gr_apply_gradient_to_item (SPItem *item, SPGradient *gr, SPGradientType new_type SPStyle *style = SP_OBJECT_STYLE (item); if (do_fill) { - if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER) && + if (style && (style->fill.isPaintserver()) && SP_IS_GRADIENT (SP_OBJECT_STYLE_FILL_SERVER (item))) { SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item); if (SP_IS_LINEARGRADIENT (server)) { @@ -90,7 +90,7 @@ gr_apply_gradient_to_item (SPItem *item, SPGradient *gr, SPGradientType new_type } if (do_stroke) { - if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER) && + if (style && (style->stroke.isPaintserver()) && SP_IS_GRADIENT (SP_OBJECT_STYLE_STROKE_SERVER (item))) { SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item); if (SP_IS_LINEARGRADIENT (server)) { @@ -298,7 +298,7 @@ gr_read_selection (Inkscape::Selection *selection, GrDrag *drag, SPGradient **gr SPItem *item = SP_ITEM(i->data); SPStyle *style = SP_OBJECT_STYLE (item); - 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)) { SPGradient *gradient = sp_gradient_get_vector (SP_GRADIENT (server), false); @@ -319,7 +319,7 @@ gr_read_selection (Inkscape::Selection *selection, GrDrag *drag, SPGradient **gr } } } - 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)) { SPGradient *gradient = sp_gradient_get_vector (SP_GRADIENT (server), false); diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index c9f29f3c5..b16a62168 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -920,47 +920,34 @@ sp_paint_selector_set_flat_color(SPPaintSelector *psel, SPDesktop *desktop, gcha SPPaintSelectorMode sp_style_determine_paint_selector_mode(SPStyle *style, bool isfill) { - unsigned set = isfill? style->fill.set : style->stroke.set; - if (!set) - return SP_PAINT_SELECTOR_MODE_UNSET; - - unsigned type = isfill? style->fill.type : style->stroke.type; - switch (type) { - - case SP_PAINT_TYPE_NONE: - { - return SP_PAINT_SELECTOR_MODE_NONE; - } - - case SP_PAINT_TYPE_COLOR: - { - return SP_PAINT_SELECTOR_MODE_COLOR_RGB; // so far only rgb can be read from svg - } - - case SP_PAINT_TYPE_PAINTSERVER: - { - SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style); - - if (SP_IS_LINEARGRADIENT(server)) { - return SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR; - } else if (SP_IS_RADIALGRADIENT(server)) { - return SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL; - } else if (SP_IS_PATTERN(server)) { - return SP_PAINT_SELECTOR_MODE_PATTERN; - } - - g_warning( "file %s: line %d: Unknown paintserver", - __FILE__, __LINE__ ); - return SP_PAINT_SELECTOR_MODE_NONE; + SPPaintSelectorMode mode = SP_PAINT_SELECTOR_MODE_UNSET; + SPIPaint& target = isfill ? style->fill : style->stroke; + + if ( !target.set ) { + SPPaintSelectorMode mode = SP_PAINT_SELECTOR_MODE_UNSET; + } else if ( target.isPaintserver() ) { + SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style); + + if (SP_IS_LINEARGRADIENT(server)) { + mode = SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR; + } else if (SP_IS_RADIALGRADIENT(server)) { + mode = SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL; + } else if (SP_IS_PATTERN(server)) { + mode = SP_PAINT_SELECTOR_MODE_PATTERN; + } else { + g_warning( "file %s: line %d: Unknown paintserver", __FILE__, __LINE__ ); + mode = SP_PAINT_SELECTOR_MODE_NONE; } - - default: - g_warning( "file %s: line %d: Unknown paint type %d", - __FILE__, __LINE__, type ); - break; + } else if ( target.isColor() ) { + mode = SP_PAINT_SELECTOR_MODE_COLOR_RGB; // so far only rgb can be read from svg + } else if ( target.isNone() ) { + mode = SP_PAINT_SELECTOR_MODE_NONE; + } else { + g_warning( "file %s: line %d: Unknown paint type", __FILE__, __LINE__ ); + mode = SP_PAINT_SELECTOR_MODE_NONE; } - return SP_PAINT_SELECTOR_MODE_NONE; + return mode; } /*