sp-femerge.cpp revision ad7e78cb16ace844160e613742645e012fd22cc9
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#define __SP_FEMERGE_CPP__
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/** \file
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * SVG <feMerge> implementation.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen *
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/*
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Authors:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * hugo Rodrigues <haa.rodrigues@gmail.com>
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen *
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Copyright (C) 2006 Hugo Rodrigues
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen *
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Released under GNU GPL, read the file 'COPYING' for more information
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#ifdef HAVE_CONFIG_H
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen# include "config.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#endif
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "attributes.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "svg/svg.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "xml/repr.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "sp-femerge.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "sp-femergenode.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "display/nr-filter-merge.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/* FeMerge base class */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_feMerge_class_init(SPFeMergeClass *klass);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_feMerge_init(SPFeMerge *feMerge);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_feMerge_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_feMerge_release(SPObject *object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_feMerge_set(SPObject *object, unsigned int key, gchar const *value);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_feMerge_update(SPObject *object, SPCtx *ctx, guint flags);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic Inkscape::XML::Node *sp_feMerge_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_feMerge_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic SPFilterPrimitiveClass *feMerge_parent_class;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan EngelenGType
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_feMerge_get_type()
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen static GType feMerge_type = 0;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (!feMerge_type) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen GTypeInfo feMerge_info = {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sizeof(SPFeMergeClass),
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen NULL, NULL,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen (GClassInitFunc) sp_feMerge_class_init,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen NULL, NULL,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sizeof(SPFeMerge),
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen 16,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen (GInstanceInitFunc) sp_feMerge_init,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen NULL, /* value_table */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen };
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen feMerge_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeMerge", &feMerge_info, (GTypeFlags)0);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen return feMerge_type;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_feMerge_class_init(SPFeMergeClass *klass)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SPObjectClass *sp_object_class = (SPObjectClass *)klass;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen feMerge_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->build = sp_feMerge_build;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->release = sp_feMerge_release;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->write = sp_feMerge_write;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->set = sp_feMerge_set;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->update = sp_feMerge_update;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_primitive_class->build_renderer = sp_feMerge_build_renderer;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_feMerge_init(SPFeMerge *feMerge)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Reads the Inkscape::XML::Node, and initializes SPFeMerge variables. For this to get called,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * our name must be associated with a repr via "sp_object_type_register". Best done through
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * sp-object-repr.cpp's repr_name_entries array.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_feMerge_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) feMerge_parent_class)->build) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) feMerge_parent_class)->build(object, document, repr);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen /*LOAD ATTRIBUTES FROM REPR HERE*/
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Drops any allocated memory.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_feMerge_release(SPObject *object)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) feMerge_parent_class)->release)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) feMerge_parent_class)->release(object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Sets a specific value in the SPFeMerge.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_feMerge_set(SPObject *object, unsigned int key, gchar const *value)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SPFeMerge *feMerge = SP_FEMERGE(object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen (void)feMerge;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen switch(key) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen /*DEAL WITH SETTING ATTRIBUTES HERE*/
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen default:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) feMerge_parent_class)->set)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) feMerge_parent_class)->set(object, key, value);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen break;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Receives update notifications.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_feMerge_update(SPObject *object, SPCtx *ctx, guint flags)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (flags & SP_OBJECT_MODIFIED_FLAG) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) feMerge_parent_class)->update) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) feMerge_parent_class)->update(object, ctx, flags);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Writes its settings to an incoming repr object, if any.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic Inkscape::XML::Node *
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_feMerge_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen // Inkscape-only object, not copied during an "plain SVG" dump:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (flags & SP_OBJECT_WRITE_EXT) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (repr) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen // is this sane?
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen //repr->mergeFrom(SP_OBJECT_REPR(object), "id");
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen } else {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) feMerge_parent_class)->write) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) feMerge_parent_class)->write(object, repr, flags);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen return repr;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_feMerge_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen g_assert(primitive != NULL);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen g_assert(filter != NULL);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SPFeMerge *sp_merge = SP_FEMERGE(primitive);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen int primitive_n = filter->add_primitive(NR::NR_FILTER_MERGE);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen NR::FilterMerge *nr_merge = dynamic_cast<NR::FilterMerge*>(nr_primitive);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen g_assert(nr_merge != NULL);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_filter_primitive_renderer_common(primitive, nr_primitive);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SPObject *input = primitive->children;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen int in_nr = 0;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen while (input) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (SP_IS_FEMERGENODE(input)) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SPFeMergeNode *node = SP_FEMERGENODE(input);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen nr_merge->set_input(in_nr, node->input);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen in_nr++;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen input = input->next;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/*
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen Local Variables:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen mode:c++
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen c-file-style:"stroustrup"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen indent-tabs-mode:nil
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen fill-column:99
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen End:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen*/
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen