5
#ifdef ENABLE_SVG_FONTS
8
* SVG <font> element implementation
11
* Felipe C. da S. Sanches <felipe.sanches@gmail.com>
13
* Copyright (C) 2008, Felipe C. da S. Sanches
15
* Released under GNU GPL, read the file 'COPYING' for more information
19
#include "attributes.h"
22
#include "sp-missing-glyph.h"
24
#include "helper-fns.h"
26
#include "display/nr-svgfonts.h"
28
static void sp_font_class_init(SPFontClass *fc);
29
static void sp_font_init(SPFont *font);
31
static void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
32
static void sp_font_release(SPObject *object);
33
static void sp_font_set(SPObject *object, unsigned int key, const gchar *value);
34
static Inkscape::XML::Node *sp_font_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
36
static void sp_font_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
37
static void sp_font_remove_child(SPObject *object, Inkscape::XML::Node *child);
38
static void sp_font_update(SPObject *object, SPCtx *ctx, guint flags);
40
// static gchar *sp_font_description(SPItem *item);
42
static SPObjectClass *parent_class;
44
GType sp_font_get_type(void)
46
static GType type = 0;
52
NULL, /* base_finalize */
53
(GClassInitFunc) sp_font_class_init,
54
NULL, /* class_finalize */
55
NULL, /* class_data */
58
(GInstanceInitFunc) sp_font_init,
59
NULL, /* value_table */
61
type = g_type_register_static(SP_TYPE_OBJECT, "SPFont", &info, (GTypeFlags) 0);
67
static void sp_font_class_init(SPFontClass *fc)
69
SPObjectClass *sp_object_class = (SPObjectClass *) fc;
71
parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
73
sp_object_class->build = sp_font_build;
74
sp_object_class->release = sp_font_release;
75
sp_object_class->set = sp_font_set;
76
sp_object_class->write = sp_font_write;
77
sp_object_class->child_added = sp_font_child_added;
78
sp_object_class->remove_child = sp_font_remove_child;
79
sp_object_class->update = sp_font_update;
82
static void sp_font_init(SPFont *font)
84
font->horiz_origin_x = 0;
85
font->horiz_origin_y = 0;
86
font->horiz_adv_x = 0;
87
//I think we should have extra stuff here and in the set method in order to set default value as specified at http://www.w3.org/TR/SVG/fonts.html
88
font->vert_origin_x = 0;
89
font->vert_origin_y = 0;
93
static void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
95
if (((SPObjectClass *) (parent_class))->build) {
96
((SPObjectClass *) (parent_class))->build(object, document, repr);
99
sp_object_read_attr(object, "horiz-origin-x");
100
sp_object_read_attr(object, "horiz-origin-y");
101
sp_object_read_attr(object, "horiz-adv-x");
102
sp_object_read_attr(object, "vert-origin-x");
103
sp_object_read_attr(object, "vert-origin-y");
104
sp_object_read_attr(object, "vert-adv-y");
106
sp_document_add_resource(document, "font", object);
110
static void sp_font_children_modified(SPFont */*sp_font*/)
115
* Callback for child_added event.
118
sp_font_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
120
SPFont *f = SP_FONT(object);
122
if (((SPObjectClass *) parent_class)->child_added)
123
(* ((SPObjectClass *) parent_class)->child_added)(object, child, ref);
125
sp_font_children_modified(f);
126
object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
131
* Callback for remove_child event.
134
sp_font_remove_child(SPObject *object, Inkscape::XML::Node *child)
136
SPFont *f = SP_FONT(object);
138
if (((SPObjectClass *) parent_class)->remove_child)
139
(* ((SPObjectClass *) parent_class)->remove_child)(object, child);
141
sp_font_children_modified(f);
142
object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
145
static void sp_font_release(SPObject *object)
147
//SPFont *font = SP_FONT(object);
148
sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "font", object);
150
if (((SPObjectClass *) parent_class)->release) {
151
((SPObjectClass *) parent_class)->release(object);
155
static void sp_font_set(SPObject *object, unsigned int key, const gchar *value)
157
SPFont *font = SP_FONT(object);
161
case SP_ATTR_HORIZ_ORIGIN_X:
162
number = helperfns_read_number(value);
163
if (number != font->horiz_origin_x){
164
font->horiz_origin_x = number;
165
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
168
case SP_ATTR_HORIZ_ORIGIN_Y:
169
number = helperfns_read_number(value);
170
if (number != font->horiz_origin_y){
171
font->horiz_origin_y = number;
172
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
175
case SP_ATTR_HORIZ_ADV_X:
176
number = helperfns_read_number(value);
177
if (number != font->horiz_adv_x){
178
font->horiz_adv_x = number;
179
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
182
case SP_ATTR_VERT_ORIGIN_X:
183
number = helperfns_read_number(value);
184
if (number != font->vert_origin_x){
185
font->vert_origin_x = number;
186
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
189
case SP_ATTR_VERT_ORIGIN_Y:
190
number = helperfns_read_number(value);
191
if (number != font->vert_origin_y){
192
font->vert_origin_y = number;
193
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
196
case SP_ATTR_VERT_ADV_Y:
197
number = helperfns_read_number(value);
198
if (number != font->vert_adv_y){
199
font->vert_adv_y = number;
200
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
204
if (((SPObjectClass *) (parent_class))->set) {
205
((SPObjectClass *) (parent_class))->set(object, key, value);
212
* Receives update notifications.
215
sp_font_update(SPObject *object, SPCtx *ctx, guint flags)
217
if (flags & (SP_OBJECT_MODIFIED_FLAG)) {
218
sp_object_read_attr(object, "horiz-origin-x");
219
sp_object_read_attr(object, "horiz-origin-y");
220
sp_object_read_attr(object, "horiz-adv-x");
221
sp_object_read_attr(object, "vert-origin-x");
222
sp_object_read_attr(object, "vert-origin-y");
223
sp_object_read_attr(object, "vert-adv-y");
226
if (((SPObjectClass *) parent_class)->update) {
227
((SPObjectClass *) parent_class)->update(object, ctx, flags);
231
#define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
233
static Inkscape::XML::Node *sp_font_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
235
SPFont *font = SP_FONT(object);
237
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
238
repr = xml_doc->createElement("svg:font");
241
sp_repr_set_svg_double(repr, "horiz-origin-x", font->horiz_origin_x);
242
sp_repr_set_svg_double(repr, "horiz-origin-y", font->horiz_origin_y);
243
sp_repr_set_svg_double(repr, "horiz-adv-x", font->horiz_adv_x);
244
sp_repr_set_svg_double(repr, "vert-origin-x", font->vert_origin_x);
245
sp_repr_set_svg_double(repr, "vert-origin-y", font->vert_origin_y);
246
sp_repr_set_svg_double(repr, "vert-adv-y", font->vert_adv_y);
248
if (repr != SP_OBJECT_REPR(object)) {
249
COPY_ATTR(repr, object->repr, "horiz-origin-x");
250
COPY_ATTR(repr, object->repr, "horiz-origin-y");
251
COPY_ATTR(repr, object->repr, "horiz-adv-x");
252
COPY_ATTR(repr, object->repr, "vert-origin-x");
253
COPY_ATTR(repr, object->repr, "vert-origin-y");
254
COPY_ATTR(repr, object->repr, "vert-adv-y");
257
if (((SPObjectClass *) (parent_class))->write) {
258
((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
263
#endif //#ifdef ENABLE_SVG_FONTS
267
c-file-style:"stroustrup"
268
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
273
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :