diff options
| author | Felipe Corr??a da Silva Sanches <juca@members.fsf.org> | 2008-07-22 12:05:49 +0000 |
|---|---|---|
| committer | JucaBlues <JucaBlues@users.sourceforge.net> | 2008-07-22 12:05:49 +0000 |
| commit | 1da87c36ad655ddcfced4becb7972747fcbb89f6 (patch) | |
| tree | 9bf3726fda21670b37821f76d197ba5fb63b2553 | |
| parent | slightly changed svgfonts example (diff) | |
| download | inkscape-1da87c36ad655ddcfced4becb7972747fcbb89f6.tar.gz inkscape-1da87c36ad655ddcfced4becb7972747fcbb89f6.zip | |
initial handling of <script> tag
Some people develope SVG files that contain javascript. We should not
erase their script nodes!
Also, we could develop a scripting IDE in inkscape. Look at
http://wiki.inkscape.org/wiki/index.php/BlueprintScriptingIDE
(bzr r6391)
| -rw-r--r-- | src/Makefile_insert | 1 | ||||
| -rw-r--r-- | src/attributes.cpp | 1 | ||||
| -rw-r--r-- | src/attributes.h | 1 | ||||
| -rw-r--r-- | src/sp-object-repr.cpp | 2 | ||||
| -rw-r--r-- | src/sp-root.cpp | 4 | ||||
| -rw-r--r-- | src/sp-root.h | 2 | ||||
| -rw-r--r-- | src/sp-script.cpp | 127 | ||||
| -rw-r--r-- | src/sp-script.h | 45 |
8 files changed, 183 insertions, 0 deletions
diff --git a/src/Makefile_insert b/src/Makefile_insert index 935abf456..52adc54e8 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -258,6 +258,7 @@ libinkpre_a_SOURCES = \ sp-radial-gradient.h \ sp-rect.cpp sp-rect.h \ sp-root.cpp sp-root.h \ + sp-script.cpp sp-script.h \ sp-shape.cpp sp-shape.h \ sp-spiral.cpp sp-spiral.h \ sp-star.cpp sp-star.h \ diff --git a/src/attributes.cpp b/src/attributes.cpp index cfadab9c6..c67144692 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -59,6 +59,7 @@ static SPStyleProp const props[] = { {SP_ATTR_PRESERVEASPECTRATIO, "preserveAspectRatio"}, {SP_ATTR_SODIPODI_VERSION, "sodipodi:version"}, {SP_ATTR_INKSCAPE_VERSION, "inkscape:version"}, + {SP_ATTR_ONLOAD, "onload"}, /* SPNamedView */ {SP_ATTR_VIEWONLY, "viewonly"}, {SP_ATTR_SHOWGUIDES, "showguides"}, diff --git a/src/attributes.h b/src/attributes.h index 7291b0166..c1c4dcadc 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -59,6 +59,7 @@ enum SPAttributeEnum { SP_ATTR_PRESERVEASPECTRATIO, SP_ATTR_SODIPODI_VERSION, SP_ATTR_INKSCAPE_VERSION, + SP_ATTR_ONLOAD, /* SPNamedView */ SP_ATTR_VIEWONLY, SP_ATTR_SHOWGUIDES, diff --git a/src/sp-object-repr.cpp b/src/sp-object-repr.cpp index 7eb91d281..87c27214d 100644 --- a/src/sp-object-repr.cpp +++ b/src/sp-object-repr.cpp @@ -43,6 +43,7 @@ #include "sp-flowdiv.h" #include "sp-flowregion.h" #include "sp-flowtext.h" +#include "sp-script.h" #include "config.h" #ifdef ENABLE_SVG_FONTS @@ -195,6 +196,7 @@ populate_dtables() { "svg:radialGradient", SP_TYPE_RADIALGRADIENT }, { "svg:rect", SP_TYPE_RECT }, { "svg:stop", SP_TYPE_STOP }, + { "svg:script", SP_TYPE_SCRIPT }, { "svg:svg", SP_TYPE_ROOT }, { "svg:style", SP_TYPE_STYLE_ELEM }, { "svg:switch", SP_TYPE_SWITCH }, diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 94b561bcc..0ff3b48b6 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -162,6 +162,7 @@ sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) sp_object_read_attr(object, "height"); sp_object_read_attr(object, "viewBox"); sp_object_read_attr(object, "preserveAspectRatio"); + sp_object_read_attr(object, "onload"); if (((SPObjectClass *) parent_class)->build) (* ((SPObjectClass *) parent_class)->build) (object, document, repr); @@ -335,6 +336,9 @@ sp_root_set(SPObject *object, unsigned int key, gchar const *value) root->aspect_clip = clip; } break; + case SP_ATTR_ONLOAD: + root->onload = (char *) value; + break; default: /* Pass the set event to the parent */ if (((SPObjectClass *) parent_class)->set) { diff --git a/src/sp-root.h b/src/sp-root.h index 8a6a4ed57..c298223f1 100644 --- a/src/sp-root.h +++ b/src/sp-root.h @@ -51,6 +51,8 @@ struct SPRoot : public SPGroup { /** Child to parent additional transform. */ NR::Matrix c2p; + gchar *onload; + /** * Primary \<defs\> element where we put new defs (patterns, gradients etc.). * diff --git a/src/sp-script.cpp b/src/sp-script.cpp new file mode 100644 index 000000000..48247ecad --- /dev/null +++ b/src/sp-script.cpp @@ -0,0 +1,127 @@ +#define __SP_SCRIPT_C__ + +/* + * SVG <script> implementation + * + * Authors: + * Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com> + * + * Copyright (C) 2008 authors + * + * Released under GNU GPL version 2 or later, read the file 'COPYING' for more information + */ + +#include "sp-script.h" + +static void sp_script_class_init(SPScriptClass *sc); +static void sp_script_init(SPScript *script); + +static void sp_script_release(SPObject *object); +static void sp_script_update(SPObject *object, SPCtx *ctx, guint flags); +static void sp_script_modified(SPObject *object, guint flags); +static Inkscape::XML::Node *sp_script_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); + +static SPObjectClass *parent_class; + +GType sp_script_get_type(void) +{ + static GType script_type = 0; + + if (!script_type) { + GTypeInfo script_info = { + sizeof(SPScriptClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) sp_script_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(SPScript), + 16, /* n_preallocs */ + (GInstanceInitFunc) sp_script_init, + NULL, /* value_table */ + }; + script_type = g_type_register_static(SP_TYPE_OBJECT, "SPScript", &script_info, (GTypeFlags) 0); + } + + return script_type; +} + +static void sp_script_class_init(SPScriptClass *sc) +{ + parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT); + SPObjectClass *sp_object_class = (SPObjectClass *) sc; + + sp_object_class->release = sp_script_release; + sp_object_class->update = sp_script_update; + sp_object_class->modified = sp_script_modified; + sp_object_class->write = sp_script_write; +} + +static void sp_script_init(SPScript */*script*/) +{ + +} + +static void sp_script_release(SPObject *object) +{ + if (((SPObjectClass *) (parent_class))->release) { + ((SPObjectClass *) (parent_class))->release(object); + } +} + +static void sp_script_update(SPObject *object, SPCtx *ctx, guint flags) +{ +} + +static void sp_script_modified(SPObject *object, guint flags) +{ +} + +static Inkscape::XML::Node *sp_script_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ +/* +TODO: + code copied from sp-defs + decide what to do here! + + if (flags & SP_OBJECT_WRITE_BUILD) { + + if (!repr) { + repr = xml_doc->createElement("svg:script"); + } + + GSList *l = NULL; + for ( SPObject *child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) { + Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags); + if (crepr) l = g_slist_prepend(l, crepr); + } + + while (l) { + repr->addChild((Inkscape::XML::Node *) l->data, NULL); + Inkscape::GC::release((Inkscape::XML::Node *) l->data); + l = g_slist_remove(l, l->data); + } + + } else { + for ( SPObject *child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) { + child->updateRepr(flags); + } + } + + if (((SPObjectClass *) (parent_class))->write) { + (* ((SPObjectClass *) (parent_class))->write)(object, xml_doc, repr, flags); + } +*/ + return repr; +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/sp-script.h b/src/sp-script.h new file mode 100644 index 000000000..8a48f9b92 --- /dev/null +++ b/src/sp-script.h @@ -0,0 +1,45 @@ +#ifndef __SP_SCRIPT_H__ +#define __SP_SCRIPT_H__ + +/* + * SVG <script> implementation + * + * Author: + * Felipe C. da S. Sanches <felipe.sanches@gmail.com> + * + * Copyright (C) 2008 Author + * + * Released under GNU GPL version 2 or later, read the file 'COPYING' for more information + */ + +#include "sp-item.h" + +#define SP_TYPE_SCRIPT (sp_script_get_type()) +#define SP_SCRIPT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_SCRIPT, SPScript)) +#define SP_SCRIPT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_SCRIPT, SPScriptClass)) +#define SP_IS_SCRIPT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_SCRIPT)) +#define SP_IS_SCRIPT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_SCRIPT)) + +/* SPScript */ + +struct SPScript : public SPObject { +}; + +struct SPScriptClass { + SPObjectClass parent_class; +}; + +GType sp_script_get_type(); + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
