Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

gchar* sp_style_write_difference ( SPStyle const *const   from,
SPStyle const *const   to 
)

Dumps style to CSS string, see sp_style_write_string()

Precondition:
from != NULL.

to != NULL.

Postcondition:
ret != NULL.

Todo:
fixme: Per type methods need default flag too

Todo:
fixme:

Todo:
The reason we use IFSET rather than IFDIFF is the belief that the IFDIFF flag is mainly only for attributes that don't handle explicit unset well. We may need to revisit the behaviour of this routine.

Definition at line 2405 of file style.cpp.

References SPStyle::block_progression, SPStyle::color, NRVpathDash::dash, SPStyle::direction, SPStyle::display, SPStyle::enable_background, SPStyle::fill, SPStyle::fill_opacity, SPStyle::fill_rule, SPStyle::filter, SPStyle::font_size, SPStyle::font_stretch, SPStyle::font_style, SPStyle::font_variant, SPStyle::font_weight, SPStyle::letter_spacing, SPStyle::line_height, SPStyle::marker, NRVpathDash::n_dash, SPIPaint::noneSet, NRVpathDash::offset, SPStyle::opacity, SPStyle::overflow, SPIString::set, SPIScale24::set, sp_style_write_ienum(), sp_style_write_ifilter(), sp_style_write_ifloat(), sp_style_write_ifontsize(), sp_style_write_ilength(), sp_style_write_ilengthornormal(), sp_style_write_ipaint(), sp_style_write_iscale24(), sp_style_write_itextdecoration(), sp_text_style_write(), Inkscape::CSSOStringStream::str(), SPStyle::stroke, SPStyle::stroke_dash, SPStyle::stroke_dasharray_inherit, SPStyle::stroke_dasharray_set, SPStyle::stroke_dashoffset_inherit, SPStyle::stroke_dashoffset_set, SPStyle::stroke_linecap, SPStyle::stroke_linejoin, SPStyle::stroke_miterlimit, SPStyle::stroke_opacity, SPStyle::stroke_width, SPStyle::text, SPStyle::text_align, SPStyle::text_anchor, SPStyle::text_decoration, SPStyle::text_indent, SPStyle::text_transform, SPIString::value, SPIScale24::value, SPStyle::visibility, SPStyle::word_spacing, and SPStyle::writing_mode.

{
    g_return_val_if_fail(from != NULL, NULL);
    g_return_val_if_fail(to != NULL, NULL);

    gchar c[BMAX], *p = c;
    *p = '\0';

    p += sp_style_write_ifontsize(p, c + BMAX - p, "font-size", &from->font_size, &to->font_size, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "font-style", enum_font_style, &from->font_style, &to->font_style, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "font-variant", enum_font_variant, &from->font_variant, &to->font_variant, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "font-weight", enum_font_weight, &from->font_weight, &to->font_weight, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "font-stretch", enum_font_stretch, &from->font_stretch, &to->font_stretch, SP_STYLE_FLAG_IFDIFF);

    /* Text */
    p += sp_style_write_ilength(p, c + BMAX - p, "text-indent", &from->text_indent, &to->text_indent, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "text-align", enum_text_align, &from->text_align, &to->text_align, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_itextdecoration(p, c + BMAX - p, "text-decoration", &from->text_decoration, &to->text_decoration, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ilengthornormal(p, c + BMAX - p, "line-height", &from->line_height, &to->line_height, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ilengthornormal(p, c + BMAX - p, "letter-spacing", &from->letter_spacing, &to->letter_spacing, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ilengthornormal(p, c + BMAX - p, "word-spacing", &from->word_spacing, &to->word_spacing, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "text-transform", enum_text_transform, &from->text_transform, &to->text_transform, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "direction", enum_direction, &from->direction, &to->direction, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "block-progression", enum_block_progression, &from->block_progression, &to->block_progression, SP_STYLE_FLAG_IFDIFF);
    p += sp_style_write_ienum(p, c + BMAX - p, "writing-mode", enum_writing_mode, &from->writing_mode, &to->writing_mode, SP_STYLE_FLAG_IFDIFF);

    p += sp_style_write_ienum(p, c + BMAX - p, "text-anchor", enum_text_anchor, &from->text_anchor, &to->text_anchor, SP_STYLE_FLAG_IFDIFF);

    /// \todo fixme: Per type methods need default flag too
    if (from->opacity.set && from->opacity.value != SP_SCALE24_MAX) {
        p += sp_style_write_iscale24(p, c + BMAX - p, "opacity", &from->opacity, &to->opacity, SP_STYLE_FLAG_IFSET);
    }

    if (!from->color.noneSet) { // CSS does not permit "none" for color
        p += sp_style_write_ipaint(p, c + BMAX - p, "color", &from->color, &to->color, SP_STYLE_FLAG_IFSET);
    }

    p += sp_style_write_ipaint(p, c + BMAX - p, "fill", &from->fill, &to->fill, SP_STYLE_FLAG_IFDIFF);
    // if fill:none, skip writing fill properties
    if (!from->fill.noneSet) {
        p += sp_style_write_iscale24(p, c + BMAX - p, "fill-opacity", &from->fill_opacity, &to->fill_opacity, SP_STYLE_FLAG_IFDIFF);
        p += sp_style_write_ienum(p, c + BMAX - p, "fill-rule", enum_fill_rule, &from->fill_rule, &to->fill_rule, SP_STYLE_FLAG_IFDIFF);
    }

    p += sp_style_write_ipaint(p, c + BMAX - p, "stroke", &from->stroke, &to->stroke, SP_STYLE_FLAG_IFDIFF);

    // stroke width affects markers, so write it if there's stroke OR any markers
    if (!from->stroke.noneSet || 
        from->marker[SP_MARKER_LOC].set ||
        from->marker[SP_MARKER_LOC_START].set ||
        from->marker[SP_MARKER_LOC_MID].set || 
        from->marker[SP_MARKER_LOC_END].set) {
        p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &from->stroke_width, &to->stroke_width, SP_STYLE_FLAG_IFDIFF);
    }

    // if stroke:none, skip writing stroke properties
    if (!from->stroke.noneSet) {
        p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linecap", enum_stroke_linecap,
                                  &from->stroke_linecap, &to->stroke_linecap, SP_STYLE_FLAG_IFDIFF);
        p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linejoin", enum_stroke_linejoin,
                                  &from->stroke_linejoin, &to->stroke_linejoin, SP_STYLE_FLAG_IFDIFF);
        p += sp_style_write_ifloat(p, c + BMAX - p, "stroke-miterlimit",
                                   &from->stroke_miterlimit, &to->stroke_miterlimit, SP_STYLE_FLAG_IFDIFF);
        /** \todo fixme: */
        if (from->stroke_dasharray_set) {
            if (from->stroke_dasharray_inherit) {
                p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:inherit;");
            } else if (from->stroke_dash.n_dash && from->stroke_dash.dash) {
                p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:");
                for (gint i = 0; i < from->stroke_dash.n_dash; i++) {
                    Inkscape::CSSOStringStream os;
                    if (i) {
                        os << ", ";
                    }
                    os << from->stroke_dash.dash[i];
                    p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
                }
                p += g_snprintf(p, c + BMAX - p, ";");
            }
        }
        /* fixme: */
        if (from->stroke_dashoffset_set) {
            if (from->stroke_dashoffset_inherit) {
                p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:inherit;");
            } else {
                Inkscape::CSSOStringStream os;
                os << "stroke-dashoffset:" << from->stroke_dash.offset << ";";
                p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
            }
        }
        p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &from->stroke_opacity, &to->stroke_opacity, SP_STYLE_FLAG_IFDIFF);
    }

    /* markers */
    gchar *master = from->marker[SP_MARKER_LOC].value;
    if (master != NULL) {
        p += g_snprintf(p, c + BMAX - p, "marker:%s;", master);
    }
    if (from->marker[SP_MARKER_LOC_START].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_START].value))) {
        p += g_snprintf(p, c + BMAX - p, "marker-start:%s;", from->marker[SP_MARKER_LOC_START].value);
    }
    if (from->marker[SP_MARKER_LOC_MID].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_MID].value))) {
        p += g_snprintf(p, c + BMAX - p, "marker-mid:%s;",   from->marker[SP_MARKER_LOC_MID].value);
    }
    if (from->marker[SP_MARKER_LOC_END].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_END].value))) {
        p += g_snprintf(p, c + BMAX - p, "marker-end:%s;",   from->marker[SP_MARKER_LOC_END].value);
    }

    p += sp_style_write_ienum(p, c + BMAX - p, "visibility", enum_visibility, &from->visibility, &to->visibility, SP_STYLE_FLAG_IFSET);
    p += sp_style_write_ienum(p, c + BMAX - p, "display", enum_display, &from->display, &to->display, SP_STYLE_FLAG_IFSET);
    p += sp_style_write_ienum(p, c + BMAX - p, "overflow", enum_overflow, &from->overflow, &to->overflow, SP_STYLE_FLAG_IFSET);

    /* filter: */
    p += sp_style_write_ifilter(p, c + BMAX - p, "filter", &from->filter, &to->filter, SP_STYLE_FLAG_IFDIFF);

    p += sp_style_write_ienum(p, c + BMAX - p, "enable-background", enum_enable_background, &from->enable_background, &to->enable_background, SP_STYLE_FLAG_IFSET);

    p += sp_text_style_write(p, c + BMAX - p, from->text, SP_STYLE_FLAG_IFDIFF);

    /** \todo
     * The reason we use IFSET rather than IFDIFF is the belief that the IFDIFF
     * flag is mainly only for attributes that don't handle explicit unset well.
     * We may need to revisit the behaviour of this routine.
     */

    /* Get rid of trailing `;'. */
    if (p != c) {
        --p;
        if (*p == ';') {
            *p = '\0';
        }
    }

    return g_strdup(c);
}


Generated by  Doxygen 1.6.0   Back to index