rsvg-mask.c 4.2 KB
Newer Older
1 2
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 sts=4 expandtab: */
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/* 
   rsvg-filter.c: Provides filters
 
   Copyright (C) 2004 Caleb Moore
  
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.
  
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
  
   You should have received a copy of the GNU Library General Public
   License along with this program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
  
   Author: Caleb Moore <calebmm@tpg.com.au>
*/

#include "rsvg-private.h"
#include "rsvg-mask.h"
#include "rsvg-styles.h"
#include "rsvg-css.h"
Dom Lachowicz's avatar
Dom Lachowicz committed
30
#include <string.h>
31

32
static void
33
rsvg_mask_set_atts (RsvgNode *node, gpointer impl, RsvgHandle *handle, RsvgPropertyBag *atts)
34
{
35
    RsvgMask *mask = impl;
36 37
    const char *value;

38 39 40 41 42
    if ((value = rsvg_property_bag_lookup (atts, "maskUnits"))) {
        if (!strcmp (value, "userSpaceOnUse"))
            mask->maskunits = userSpaceOnUse;
        else
            mask->maskunits = objectBoundingBox;
43
    }
44 45 46 47 48 49 50 51 52 53 54 55 56 57
    if ((value = rsvg_property_bag_lookup (atts, "maskContentUnits"))) {
        if (!strcmp (value, "objectBoundingBox"))
            mask->contentunits = objectBoundingBox;
        else
            mask->contentunits = userSpaceOnUse;
    }
    if ((value = rsvg_property_bag_lookup (atts, "x")))
        mask->x = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
    if ((value = rsvg_property_bag_lookup (atts, "y")))
        mask->y = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
    if ((value = rsvg_property_bag_lookup (atts, "width")))
        mask->width = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
    if ((value = rsvg_property_bag_lookup (atts, "height")))
        mask->height = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
Caleb Michael Moore's avatar
Caleb Michael Moore committed
58
}
59

60 61 62 63 64 65
static void
rsvg_mask_draw (RsvgNode *node, gpointer impl, RsvgDrawingCtx *ctx, int dominate)
{
    /* nothing; this gets drawn specially in rsvg-cairo-draw.c */
}

Caleb Michael Moore's avatar
Caleb Michael Moore committed
66
RsvgNode *
67
rsvg_new_mask (const char *element_name, RsvgNode *parent)
Caleb Michael Moore's avatar
Caleb Michael Moore committed
68
{
69
    RsvgMask *mask;
70

71
    mask = g_new0 (RsvgMask, 1);
72 73
    mask->maskunits = objectBoundingBox;
    mask->contentunits = userSpaceOnUse;
74 75 76 77
    mask->x = rsvg_length_parse ("0", LENGTH_DIR_HORIZONTAL);
    mask->y = rsvg_length_parse ("0", LENGTH_DIR_VERTICAL);
    mask->width = rsvg_length_parse ("1", LENGTH_DIR_HORIZONTAL);
    mask->height = rsvg_length_parse ("1", LENGTH_DIR_VERTICAL);
78 79 80 81 82 83 84 85

    return rsvg_rust_cnode_new (RSVG_NODE_TYPE_MASK,
                                parent,
                                rsvg_state_new (),
                                mask,
                                rsvg_mask_set_atts,
                                rsvg_mask_draw,
                                g_free);
86 87
}

88
static void
89
rsvg_clip_path_set_atts (RsvgNode *node, gpointer impl, RsvgHandle *handle, RsvgPropertyBag *atts)
Caleb Michael Moore's avatar
Caleb Michael Moore committed
90
{
91
    RsvgClipPath *clip_path = impl;
92
    const char *value;
93

94 95 96 97 98
    if ((value = rsvg_property_bag_lookup (atts, "clipPathUnits"))) {
        if (!strcmp (value, "objectBoundingBox"))
            clip_path->units = objectBoundingBox;
        else
            clip_path->units = userSpaceOnUse;
99
    }
Caleb Michael Moore's avatar
Caleb Michael Moore committed
100
}
Caleb Michael Moore's avatar
Caleb Michael Moore committed
101

102 103 104 105 106 107
static void
rsvg_clip_path_draw (RsvgNode *node, gpointer impl, RsvgDrawingCtx *ctx, int dominate)
{
    /* nothing; this gets drawn specially in rsvg-cairo-draw.c */
}

Caleb Michael Moore's avatar
Caleb Michael Moore committed
108
RsvgNode *
109
rsvg_new_clip_path (const char *element_name, RsvgNode *parent)
Caleb Michael Moore's avatar
Caleb Michael Moore committed
110
{
111 112
    RsvgClipPath *clip_path;

113
    clip_path = g_new0 (RsvgClipPath, 1);
114
    clip_path->units = userSpaceOnUse;
115 116 117 118 119 120 121 122

    return rsvg_rust_cnode_new (RSVG_NODE_TYPE_CLIP_PATH,
                                parent,
                                rsvg_state_new (),
                                clip_path,
                                rsvg_clip_path_set_atts,
                                rsvg_clip_path_draw,
                                g_free); 
Caleb Michael Moore's avatar
Caleb Michael Moore committed
123
}