Logo Search packages:      
Sourcecode: inkscape version File versions

gchar* sp_style_write_string ( SPStyle const *const   style,
guint const   flags 
)

Dumps the style to a CSS string, with either SP_STYLE_FLAG_IFSET or SP_STYLE_FLAG_ALWAYS flags. Used with Always for copying an object's complete cascaded style to style_clipboard. When you need a CSS string for an object in the document tree, you normally call sp_style_write_difference instead to take into account the object's parent.

Precondition:
style != NULL.

flags in {IFSET, ALWAYS}.

Postcondition:
ret != NULL.

Todo:
Merge with write_difference, much duplicate code!

Todo:
fixme: Per type methods need default flag too (lauris)

Todo:
fixme:

Todo:
fixme:

Definition at line 2187 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, NRVpathDash::offset, SPStyle::opacity, SPStyle::overflow, SPIString::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_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, SPStyle::visibility, SPStyle::word_spacing, and SPStyle::writing_mode.

Referenced by sp_css_attr_from_style(), and sp_object_private_write().

{
    /** \todo
     * Merge with write_difference, much duplicate code!
     */
    g_return_val_if_fail(style != NULL, NULL);
    g_return_val_if_fail(((flags == SP_STYLE_FLAG_IFSET) ||
                          (flags == SP_STYLE_FLAG_ALWAYS)  ),
                         NULL);

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

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

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

    p += sp_style_write_ienum(p, c + BMAX - p, "text-anchor", enum_text_anchor, &style->text_anchor, NULL, flags);

    /// \todo fixme: Per type methods need default flag too (lauris)
    p += sp_style_write_iscale24(p, c + BMAX - p, "opacity", &style->opacity, NULL, flags);
    p += sp_style_write_ipaint(p, c + BMAX - p, "color", &style->color, NULL, flags);
    p += sp_style_write_ipaint(p, c + BMAX - p, "fill", &style->fill, NULL, flags);
    p += sp_style_write_iscale24(p, c + BMAX - p, "fill-opacity", &style->fill_opacity, NULL, flags);
    p += sp_style_write_ienum(p, c + BMAX - p, "fill-rule", enum_fill_rule, &style->fill_rule, NULL, flags);
    p += sp_style_write_ipaint(p, c + BMAX - p, "stroke", &style->stroke, NULL, flags);
    p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &style->stroke_width, NULL, flags);
    p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linecap", enum_stroke_linecap, &style->stroke_linecap, NULL, flags);
    p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linejoin", enum_stroke_linejoin, &style->stroke_linejoin, NULL, flags);

    if (style->marker[SP_MARKER_LOC].set) {
        p += g_snprintf(p, c + BMAX - p, "marker:%s;", style->marker[SP_MARKER_LOC].value);
    } else if (flags == SP_STYLE_FLAG_ALWAYS) {
        p += g_snprintf(p, c + BMAX - p, "marker:none;");
    }
    if (style->marker[SP_MARKER_LOC_START].set) {
        p += g_snprintf(p, c + BMAX - p, "marker-start:%s;", style->marker[SP_MARKER_LOC_START].value);
    } else if (flags == SP_STYLE_FLAG_ALWAYS) {
        p += g_snprintf(p, c + BMAX - p, "marker-start:none;");
    }
    if (style->marker[SP_MARKER_LOC_MID].set) {
        p += g_snprintf(p, c + BMAX - p, "marker-mid:%s;", style->marker[SP_MARKER_LOC_MID].value);
    } else if (flags == SP_STYLE_FLAG_ALWAYS) {
        p += g_snprintf(p, c + BMAX - p, "marker-mid:none;");
    }
    if (style->marker[SP_MARKER_LOC_END].set) {
        p += g_snprintf(p, c + BMAX - p, "marker-end:%s;", style->marker[SP_MARKER_LOC_END].value);
    } else if (flags == SP_STYLE_FLAG_ALWAYS) {
        p += g_snprintf(p, c + BMAX - p, "marker-end:none;");
    }

    p += sp_style_write_ifloat(p, c + BMAX - p, "stroke-miterlimit", &style->stroke_miterlimit, NULL, flags);

    /** \todo fixme: */
    if ((flags == SP_STYLE_FLAG_ALWAYS)
        || style->stroke_dasharray_set)
    {
        if (style->stroke_dasharray_inherit) {
            p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:inherit;");
        } else if (style->stroke_dash.n_dash && style->stroke_dash.dash) {
            p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:");
            gint i;
            for (i = 0; i < style->stroke_dash.n_dash; i++) {
                Inkscape::CSSOStringStream os;
                if (i) {
                    os << ", ";
                }
                os << style->stroke_dash.dash[i];
                p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
            }
            if (p < c + BMAX) {
                *p++ = ';';
            }
        } else {
            p += g_snprintf(p, c + BMAX - p, "stroke-dasharray:none;");
        }
    }

    /** \todo fixme: */
    if (style->stroke_dashoffset_set) {
        Inkscape::CSSOStringStream os;
        os << "stroke-dashoffset:" << style->stroke_dash.offset << ";";
        p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
    } else if (flags == SP_STYLE_FLAG_ALWAYS) {
        p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:0;");
    }

    p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &style->stroke_opacity, NULL, flags);

    p += sp_style_write_ienum(p, c + BMAX - p, "visibility", enum_visibility, &style->visibility, NULL, flags);
    p += sp_style_write_ienum(p, c + BMAX - p, "display", enum_display, &style->display, NULL, flags);
    p += sp_style_write_ienum(p, c + BMAX - p, "overflow", enum_overflow, &style->overflow, NULL, flags);

    /* filter: */
    p += sp_style_write_ifilter(p, c + BMAX - p, "filter", &style->filter, NULL, flags);

    p += sp_style_write_ienum(p, c + BMAX - p, "enable-background", enum_enable_background, &style->enable_background, NULL, flags);

    /* fixme: */
    p += sp_text_style_write(p, c + BMAX - p, style->text, flags);

    /* 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