sp-mask.cpp revision 5271cd656d5e935ca2f55b6b61a4f3aedee22fd5
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * SVG <mask> implementation
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Authors:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Lauris Kaplinski <lauris@kaplinski.com>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Copyright (C) 2003 authors
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Released under GNU GPL, read the file 'COPYING' for more information
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd unsigned int key;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_set (SPObject *object, unsigned int key, const gchar *value);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_update (SPObject *object, SPCtx *ctx, guint flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_modified (SPObject *object, guint flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic Inkscape::XML::Node *sp_mask_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndSPMaskView *sp_mask_view_new_prepend (SPMaskView *list, unsigned int key, NRArenaItem *arenaitem);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndSPMaskView *sp_mask_view_list_remove (SPMaskView *list, SPMaskView *view);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd type = g_type_register_static (SP_TYPE_OBJECTGROUP, "SPMask", &info, (GTypeFlags)0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd parent_class = (SPObjectGroupClass*) g_type_class_ref (SP_TYPE_OBJECTGROUP);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObjectClass *sp_object_class = (SPObjectClass *) klass;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits = SP_CONTENT_UNITS_USERSPACEONUSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) parent_class)->build (object, document, repr);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Register ourselves */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Unregister ourselves */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_document_remove_resource (SP_OBJECT_DOCUMENT (object), "mask", object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* We simply unref and let item manage this in handler */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd cp->display = sp_mask_view_list_remove (cp->display, cp->display);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_set (SPObject *object, unsigned int key, const gchar *value)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd switch (key) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits = SP_CONTENT_UNITS_USERSPACEONUSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits = SP_CONTENT_UNITS_OBJECTBOUNDINGBOX;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) parent_class)->set (object, key, value);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Invoke SPObjectGroup implementation */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) (parent_class))->child_added (object, child, ref);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Show new object */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObject *ochild = SP_OBJECT_DOCUMENT (object)->getObjectByRepr(child);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPMaskView *v = cp->display; v != NULL; v = v->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_update (SPObject *object, SPCtx *ctx, guint flags)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPObject *child = sp_object_first_child(SP_OBJECT(og)); child != NULL; child = SP_OBJECT_NEXT(child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd while (l) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPMaskView *v = mask->display; v != NULL; v = v->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_matrix_set_scale (&t, v->bbox.x1 - v->bbox.x0, v->bbox.y1 - v->bbox.y0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_group_set_child_transform (NR_ARENA_GROUP (v->arenaitem), &t);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_group_set_child_transform (NR_ARENA_GROUP (v->arenaitem), NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPObject *child = sp_object_first_child(SP_OBJECT(og)); child != NULL; child = SP_OBJECT_NEXT(child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd while (l) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) (parent_class))->write (object, repr, flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd// Create a mask element (using passed elements), add it to <defs>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_create (GSList *reprs, SPDocument *document, NR::Matrix const* applyTransform)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Inkscape::XML::Node *defsrepr = SP_OBJECT_REPR (SP_DOCUMENT_DEFS (document));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObject *mask_object = document->getObjectById(mask_id);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPItem *item = SP_ITEM(mask_object->appendChildRepr(node));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_item_write_transform(item, SP_OBJECT_REPR(item), transform);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_show (SPMask *mask, NRArena *arena, unsigned int key)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->display = sp_mask_view_new_prepend (mask->display, key, ai);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPObject *child = sp_object_first_child(SP_OBJECT(mask)) ; child != NULL; child = SP_OBJECT_NEXT(child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NRArenaItem *ac = sp_item_invoke_show (SP_ITEM (child), arena, key, SP_ITEM_REFERENCE_FLAGS);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* The order is not important in mask */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
71fccc298df6a1540d408151a26aa22beed55d0bnd nr_matrix_set_scale (&t, mask->display->bbox.x1 - mask->display->bbox.x0, mask->display->bbox.y1 - mask->display->bbox.y0);
71fccc298df6a1540d408151a26aa22beed55d0bnd nr_arena_group_set_child_transform (NR_ARENA_GROUP (ai), &t);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPObject *child = sp_object_first_child(SP_OBJECT(cp)); child != NULL; child = SP_OBJECT_NEXT(child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPMaskView *v = cp->display; v != NULL; v = v->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* We simply unref and let item to manage this in handler */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_set_bbox (SPMask *mask, unsigned int key, NRRect *bbox)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPMaskView *v = mask->display; v != NULL; v = v->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (!NR_DF_TEST_CLOSE (v->bbox.x0, bbox->x0, NR_EPSILON) ||
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* Mask views */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_view_new_prepend (SPMaskView *list, unsigned int key, NRArenaItem *arenaitem)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_view_list_remove (SPMaskView *list, SPMaskView *view)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Local Variables:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd c-file-style:"stroustrup"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd indent-tabs-mode:nil
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd fill-column:99
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :