1
2
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/*
* Base class for gradients and patterns
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
* Copyright (C) 2000-2001 Ximian, Inc.
* Copyright (C) 2010 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <string.h>
#include "libnr/nr-pixblock-pattern.h"
#include "sp-paint-server.h"
#include "sp-gradient.h"
#include "xml/node.h"
static void sp_paint_server_class_init(SPPaintServerClass *psc);
static void sp_paint_server_init(SPPaintServer *ps);
static void sp_paint_server_release(SPObject *object);
static void sp_painter_stale_fill(SPPainter *painter, NRPixBlock *pb);
static SPObjectClass *parent_class;
static GSList *stale_painters = NULL;
GType sp_paint_server_get_type (void)
{
static GType type = 0;
if (!type) {
GTypeInfo info = {
sizeof(SPPaintServerClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) sp_paint_server_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(SPPaintServer),
16, /* n_preallocs */
(GInstanceInitFunc) sp_paint_server_init,
NULL, /* value_table */
};
type = g_type_register_static(SP_TYPE_OBJECT, "SPPaintServer", &info, (GTypeFlags) 0);
}
return type;
}
static void sp_paint_server_class_init(SPPaintServerClass *psc)
{
SPObjectClass *sp_object_class = (SPObjectClass *) psc;
sp_object_class->release = sp_paint_server_release;
parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
}
static void sp_paint_server_init(SPPaintServer *ps)
{
ps->painters = NULL;
}
static void sp_paint_server_release(SPObject *object)
{
SPPaintServer *ps = SP_PAINT_SERVER(object);
while (ps->painters) {
SPPainter *painter = ps->painters;
ps->painters = painter->next;
stale_painters = g_slist_prepend(stale_painters, painter);
painter->next = NULL;
painter->server = NULL;
painter->fill = sp_painter_stale_fill;
}
if (((SPObjectClass *) parent_class)->release) {
((SPObjectClass *) parent_class)->release(object);
}
}
SPPainter *sp_paint_server_painter_new(SPPaintServer *ps,
Geom::Matrix const &full_transform,
Geom::Matrix const &parent_transform,
const NRRect *bbox)
{
g_return_val_if_fail(ps != NULL, NULL);
g_return_val_if_fail(SP_IS_PAINT_SERVER(ps), NULL);
g_return_val_if_fail(bbox != NULL, NULL);
SPPainter *painter = NULL;
SPPaintServerClass *psc = (SPPaintServerClass *) G_OBJECT_GET_CLASS(ps);
if ( psc->painter_new ) {
painter = (*psc->painter_new)(ps, full_transform, parent_transform, bbox);
}
if (painter) {
painter->next = ps->painters;
painter->server = ps;
painter->type = (SPPainterType) G_OBJECT_TYPE(ps);
ps->painters = painter;
}
return painter;
}
static void sp_paint_server_painter_free(SPPaintServer *ps, SPPainter *painter)
{
g_return_if_fail(ps != NULL);
g_return_if_fail(SP_IS_PAINT_SERVER(ps));
g_return_if_fail(painter != NULL);
SPPaintServerClass *psc = (SPPaintServerClass *) G_OBJECT_GET_CLASS(ps);
SPPainter *r = NULL;
for (SPPainter *p = ps->painters; p != NULL; p = p->next) {
if (p == painter) {
if (r) {
r->next = p->next;
} else {
ps->painters = p->next;
}
p->next = NULL;
if (psc->painter_free) {
(*psc->painter_free) (ps, painter);
}
return;
}
r = p;
}
g_assert_not_reached();
}
SPPainter *sp_painter_free(SPPainter *painter)
{
g_return_val_if_fail(painter != NULL, NULL);
if (painter->server) {
sp_paint_server_painter_free(painter->server, painter);
} else {
SPPaintServerClass *psc = (SPPaintServerClass *) g_type_class_ref(painter->type);
if (psc->painter_free)
(*psc->painter_free)(NULL, painter);
stale_painters = g_slist_remove(stale_painters, painter);
}
return NULL;
}
static void sp_painter_stale_fill(SPPainter */*painter*/, NRPixBlock *pb)
{
nr_pixblock_render_gray_noise(pb, NULL);
}
bool SPPaintServer::isSwatch() const
{
bool swatch = false;
if (SP_IS_GRADIENT(this)) {
SPGradient *grad = SP_GRADIENT(this);
//XML Tree being used directly here while it shouldn't be.
swatch = grad->hasStops() && getRepr()->attribute("osb:paint");
}
return swatch;
}
bool SPPaintServer::isSolid() const
{
bool solid = false;
if (SP_IS_GRADIENT(this)) {
SPGradient *grad = SP_GRADIENT(this);
if ( grad->hasStops() && (grad->getStopCount() == 0) ) {
//XML Tree being used directly here while it shouldn't be.
gchar const * attr = getRepr()->attribute("osb:paint");
if (attr && !strcmp(attr, "solid")) {
solid = true;
}
}
}
return solid;
}
/*
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 :
|