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

static void sp_style_read ( SPStyle style,
SPObject object,
Inkscape::XML::Node repr 
) [static]

Reads the various style parameters for an object from repr.

Todo:
No stylesheet information. Find out under what circumstances this occurs, and handle accordingly. (If we really wanted to, we could probably get stylesheets by going through repr->doc.)

Todo:
fixme: This is not the prettiest thing (Lauris)

Definition at line 554 of file style.cpp.

References Inkscape::XML::Node::attribute(), attribute_unquote(), SPStyle::block_progression, SPStyle::cloned, SPStyle::color, SPStyle::direction, SPStyle::display, SPStyle::enable_background, SPStyle::fill, SPStyle::fill_opacity, SPStyle::fill_rule, SPStyle::filter, SPTextStyle::font_family, SPStyle::font_size, SPTextStyle::font_specification, SPStyle::font_stretch, SPStyle::font_style, SPStyle::font_variant, SPStyle::font_weight, SPStyle::letter_spacing, SPStyle::line_height, SPStyle::marker, NRVpathDash::offset, SPStyle::opacity, SPStyle::overflow, SPObject::parent, SPIFilter::set, SPIString::set, SPIPaint::set, SPIScale24::set, SPILengthOrNormal::set, SPITextDecoration::set, sp_repr_parent(), sp_style_clear(), sp_style_merge_from_object_stylesheet(), sp_style_merge_from_parent(), sp_style_merge_from_style_string(), sp_style_new(), sp_style_read_icolor(), sp_style_read_ifilter(), sp_style_read_ilengthornormal(), sp_style_read_ipaint(), sp_style_read_iscale24(), sp_style_read_istring(), sp_style_read_itextdecoration(), sp_style_unref(), SPStyle::stroke, SPStyle::stroke_dash, 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_private, SPStyle::text_transform, SPStyle::visibility, SPStyle::word_spacing, and SPStyle::writing_mode.

Referenced by sp_style_read_from_object(), and sp_style_read_from_repr().

{
    g_assert(style != NULL);
    g_assert(repr != NULL);
    g_assert(!object || (SP_OBJECT_REPR(object) == repr));

    sp_style_clear(style);

    if (object && SP_OBJECT_IS_CLONED(object)) {
        style->cloned = true;
    }

    /* 1. Style attribute */
    gchar const *val = repr->attribute("style");
    if (val != NULL) {
        sp_style_merge_from_style_string(style, val);
    }

    if (object) {
        sp_style_merge_from_object_stylesheet(style, object);
    } else {
        /** \todo No stylesheet information. Find out under what circumstances
         * this occurs, and handle accordingly.  (If we really wanted to, we
         * could probably get stylesheets by going through repr->doc.)
         */
    }

    /* 2. Presentation attributes */
    /* CSS2 */
    SPS_READ_PENUM_IF_UNSET(&style->visibility, repr, "visibility", enum_visibility, true);
    SPS_READ_PENUM_IF_UNSET(&style->display, repr, "display", enum_display, true);
    SPS_READ_PENUM_IF_UNSET(&style->overflow, repr, "overflow", enum_overflow, true);
    /* Font */
    SPS_READ_PFONTSIZE_IF_UNSET(&style->font_size, repr, "font-size");
    SPS_READ_PENUM_IF_UNSET(&style->font_style, repr, "font-style", enum_font_style, true);
    SPS_READ_PENUM_IF_UNSET(&style->font_variant, repr, "font-variant", enum_font_variant, true);
    SPS_READ_PENUM_IF_UNSET(&style->font_weight, repr, "font-weight", enum_font_weight, true);
    SPS_READ_PENUM_IF_UNSET(&style->font_stretch, repr, "font-stretch", enum_font_stretch, true);
    /* Text (css2 chapter 16) */
    SPS_READ_PLENGTH_IF_UNSET(&style->text_indent, repr, "text-indent");
    SPS_READ_PENUM_IF_UNSET(&style->text_align, repr, "text-align", enum_text_align, true);
    if (!style->text_decoration.set) {
        val = repr->attribute("text-decoration");
        if (val) {
            sp_style_read_itextdecoration(&style->text_decoration, val);
        }
    }
    if (!style->line_height.set) {
        val = repr->attribute("line-height");
        if (val) {
            sp_style_read_ilengthornormal(&style->line_height, val);
        }
    }
    if (!style->letter_spacing.set) {
        val = repr->attribute("letter-spacing");
        if (val) {
            sp_style_read_ilengthornormal(&style->letter_spacing, val);
        }
    }
    if (!style->word_spacing.set) {
        val = repr->attribute("word-spacing");
        if (val) {
            sp_style_read_ilengthornormal(&style->word_spacing, val);
        }
    }
    SPS_READ_PENUM_IF_UNSET(&style->text_transform, repr, "text-transform", enum_text_transform, true);
    SPS_READ_PENUM_IF_UNSET(&style->direction, repr, "direction", enum_direction, true);
    SPS_READ_PENUM_IF_UNSET(&style->block_progression, repr, "block_progression", enum_block_progression, true);

    /* SVG */
    SPS_READ_PENUM_IF_UNSET(&style->writing_mode, repr, "writing-mode",
                            enum_writing_mode, true);
    SPS_READ_PENUM_IF_UNSET(&style->text_anchor, repr, "text-anchor",
                            enum_text_anchor, true);

    /* opacity */
    if (!style->opacity.set) {
        val = repr->attribute("opacity");
        if (val) {
            sp_style_read_iscale24(&style->opacity, val);
        }
    }
    /* color */
    if (!style->color.set) {
        val = repr->attribute("color");
        if (val) {
            sp_style_read_icolor(&style->color, val, style, ( object
                                                              ? SP_OBJECT_DOCUMENT(object)
                                                              : NULL ));
        }
    }
    /* fill */
    if (!style->fill.set) {
        val = repr->attribute("fill");
        if (val) {
            sp_style_read_ipaint(&style->fill, val, style, (object) ? SP_OBJECT_DOCUMENT(object) : NULL);
        }
    }
    /* fill-opacity */
    if (!style->fill_opacity.set) {
        val = repr->attribute("fill-opacity");
        if (val) {
            sp_style_read_iscale24(&style->fill_opacity, val);
        }
    }
    /* fill-rule */
    SPS_READ_PENUM_IF_UNSET(&style->fill_rule, repr, "fill-rule", enum_fill_rule, true);
    /* stroke */
    if (!style->stroke.set) {
        val = repr->attribute("stroke");
        if (val) {
            sp_style_read_ipaint(&style->stroke, val, style, (object) ? SP_OBJECT_DOCUMENT(object) : NULL);
        }
    }
    SPS_READ_PLENGTH_IF_UNSET(&style->stroke_width, repr, "stroke-width");
    SPS_READ_PENUM_IF_UNSET(&style->stroke_linecap, repr, "stroke-linecap", enum_stroke_linecap, true);
    SPS_READ_PENUM_IF_UNSET(&style->stroke_linejoin, repr, "stroke-linejoin", enum_stroke_linejoin, true);
    SPS_READ_PFLOAT_IF_UNSET(&style->stroke_miterlimit, repr, "stroke-miterlimit");

    /* markers */
    if (!style->marker[SP_MARKER_LOC].set) {
        val = repr->attribute("marker");
        if (val) {
            sp_style_read_istring(&style->marker[SP_MARKER_LOC], val);
        }
    }
    if (!style->marker[SP_MARKER_LOC_START].set) {
        val = repr->attribute("marker-start");
        if (val) {
            sp_style_read_istring(&style->marker[SP_MARKER_LOC_START], val);
        }
    }
    if (!style->marker[SP_MARKER_LOC_MID].set) {
        val = repr->attribute("marker-mid");
        if (val) {
            sp_style_read_istring(&style->marker[SP_MARKER_LOC_MID], val);
        }
    }
    if (!style->marker[SP_MARKER_LOC_END].set) {
        val = repr->attribute("marker-end");
        if (val) {
            sp_style_read_istring(&style->marker[SP_MARKER_LOC_END], val);
        }
    }

    /* stroke-opacity */
    if (!style->stroke_opacity.set) {
        val = repr->attribute("stroke-opacity");
        if (val) {
            sp_style_read_iscale24(&style->stroke_opacity, val);
        }
    }
    if (!style->stroke_dasharray_set) {
        val = repr->attribute("stroke-dasharray");
        if (val) {
            sp_style_read_dash(style, val);
        }
    }
    if (!style->stroke_dashoffset_set) {
        /* fixme */
        val = repr->attribute("stroke-dashoffset");
        if (sp_svg_number_read_d(val, &style->stroke_dash.offset)) {
            style->stroke_dashoffset_set = TRUE;
        } else {
            style->stroke_dashoffset_set = FALSE;
        }
    }
    
    /* -inkscape-font-specification */
    if (!style->text_private || !style->text->font_specification.set) {
        val = repr->attribute("-inkscape-font-specification");
        if (val) {
            if (!style->text_private) sp_style_privatize_text(style);
            gchar *val_unquoted = attribute_unquote(val);
            sp_style_read_istring(&style->text->font_specification, val_unquoted);
            if (val_unquoted) g_free (val_unquoted);
        }
    }

    /* font-family */
    if (!style->text_private || !style->text->font_family.set) {
        val = repr->attribute("font-family");
        if (val) {
            if (!style->text_private) sp_style_privatize_text(style);
            gchar *val_unquoted = attribute_unquote(val);
            sp_style_read_istring(&style->text->font_family, val_unquoted);
            if (val_unquoted) g_free (val_unquoted);
        }
    }

    /* filter effects */
    if (!style->filter.set) {
        val = repr->attribute("filter");
        if (val) {
                  sp_style_read_ifilter(val, style, (object) ? SP_OBJECT_DOCUMENT(object) : NULL);
        }
    }
    SPS_READ_PENUM_IF_UNSET(&style->enable_background, repr,
                            "enable-background", enum_enable_background, true);

    /* 3. Merge from parent */
    if (object) {
        if (object->parent) {
            sp_style_merge_from_parent(style, SP_OBJECT_STYLE(object->parent));
        }
    } else {
        if (sp_repr_parent(repr)) {
            /// \todo fixme: This is not the prettiest thing (Lauris)
            SPStyle *parent = sp_style_new(NULL);
            sp_style_read(parent, NULL, sp_repr_parent(repr));
            sp_style_merge_from_parent(style, parent);
            sp_style_unref(parent);
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index