Code

a bit more boilerplate code for SVGFonts
[inkscape.git] / src / sp-missing-glyph.cpp
1 #define __SP_ANCHOR_C__
3 /*
4  * SVG <missing-glyph> element implementation
5  *
6  * Author:
7  *   Felipe C. da S. Sanches <felipe.sanches@gmail.com>
8  *
9  * Copyright (C) 2008, Felipe C. da S. Sanches
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #include "xml/repr.h"
15 #include "attributes.h"
16 #include "sp-missing-glyph.h"
17 #include "document.h"
18 #include "helper-fns.h"
20 static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc);
21 static void sp_missing_glyph_init(SPMissingGlyph *glyph);
23 static void sp_missing_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
24 static void sp_missing_glyph_release(SPObject *object);
25 static void sp_missing_glyph_set(SPObject *object, unsigned int key, const gchar *value);
26 static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
28 static SPObjectClass *parent_class;
30 GType sp_missing_glyph_get_type(void)
31 {
32     static GType type = 0;
34     if (!type) {
35         GTypeInfo info = {
36             sizeof(SPMissingGlyphClass),
37             NULL,       /* base_init */
38             NULL,       /* base_finalize */
39             (GClassInitFunc) sp_missing_glyph_class_init,
40             NULL,       /* class_finalize */
41             NULL,       /* class_data */
42             sizeof(SPMissingGlyph),
43             16, /* n_preallocs */
44             (GInstanceInitFunc) sp_missing_glyph_init,
45             NULL,       /* value_table */
46         };
47         type = g_type_register_static(SP_TYPE_OBJECT, "SPMissingGlyph", &info, (GTypeFlags) 0);
48     }
50     return type;
51 }
53 static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc)
54 {
55     SPObjectClass *sp_object_class = (SPObjectClass *) gc;
57     parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
59     sp_object_class->build = sp_missing_glyph_build;
60     sp_object_class->release = sp_missing_glyph_release;
61     sp_object_class->set = sp_missing_glyph_set;
62     sp_object_class->write = sp_missing_glyph_write;
63 }
65 static void sp_missing_glyph_init(SPMissingGlyph *glyph)
66 {
67 //TODO: correct these values:
68     glyph->d = NULL;
69     glyph->horiz_adv_x = 0;
70     glyph->vert_origin_x = 0;
71     glyph->vert_origin_y = 0;
72     glyph->vert_adv_y = 0;
73 }
75 static void sp_missing_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
76 {
77     if (((SPObjectClass *) (parent_class))->build) {
78         ((SPObjectClass *) (parent_class))->build(object, document, repr);
79     }
81     sp_object_read_attr(object, "d");
82     sp_object_read_attr(object, "horiz-adv-x");
83     sp_object_read_attr(object, "vert-origin-x");
84     sp_object_read_attr(object, "vert-origin-y");
85     sp_object_read_attr(object, "vert-adv-y");
86 }
88 static void sp_missing_glyph_release(SPObject *object)
89 {
90     //SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
92     if (((SPObjectClass *) parent_class)->release) {
93         ((SPObjectClass *) parent_class)->release(object);
94     }
95 }
97 static void sp_missing_glyph_set(SPObject *object, unsigned int key, const gchar *value)
98 {
99     SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
100     double number;
102     switch (key) {
103         case SP_ATTR_D:
104             if (glyph->d) g_free(glyph->d);
105             glyph->d = g_strdup(value);
106             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
107 g_warning("<missing-glyph>: SP_ATTR_D: %s", value);
108             break;
109         case SP_ATTR_HORIZ_ADV_X:
110             number = helperfns_read_number(value);
111             if (number != glyph->horiz_adv_x){
112                 glyph->horiz_adv_x = number;
113 g_warning("<missing-glyph>: SP_ATTR_HORIZ_ADV_X: %f", number);
114                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
115             }
116             break;
117         case SP_ATTR_VERT_ORIGIN_X:
118             number = helperfns_read_number(value);
119             if (number != glyph->vert_origin_x){
120                 glyph->vert_origin_x = number;
121 g_warning("<missing-glyph>: SP_ATTR_VERT_ORIGIN_X: %f", number);
122                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
123             }
124             break;
125         case SP_ATTR_VERT_ORIGIN_Y:
126             number = helperfns_read_number(value);
127             if (number != glyph->vert_origin_y){
128                 glyph->vert_origin_y = number;
129 g_warning("<missing-glyph>: SP_ATTR_VERT_ORIGIN_Y: %f", number);
130                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
131             }
132             break;
133         case SP_ATTR_VERT_ADV_Y:
134             number = helperfns_read_number(value);
135             if (number != glyph->vert_adv_y){
136                 glyph->vert_adv_y = number;
137 g_warning("<missing-glyph>: SP_ATTR_VERT_ADV_Y: %f", number);
138                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
139             }
140             break;
141         default:
142             if (((SPObjectClass *) (parent_class))->set) {
143                 ((SPObjectClass *) (parent_class))->set(object, key, value);
144             }
145             break;
146     }
149 #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
151 static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
153 //    SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
155     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
156         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
157         repr = xml_doc->createElement("svg:glyph");
158     }
160 /* I am commenting out this part because I am not certain how does it work. I will have to study it later. Juca
161     repr->setAttribute("d", glyph->d);
162     sp_repr_set_svg_double(repr, "horiz-adv-x", glyph->horiz_adv_x);
163     sp_repr_set_svg_double(repr, "vert-origin-x", glyph->vert_origin_x);
164     sp_repr_set_svg_double(repr, "vert-origin-y", glyph->vert_origin_y);
165     sp_repr_set_svg_double(repr, "vert-adv-y", glyph->vert_adv_y);
166 */
167     if (repr != SP_OBJECT_REPR(object)) {
168         COPY_ATTR(repr, object->repr, "d");
169         COPY_ATTR(repr, object->repr, "horiz-adv-x");
170         COPY_ATTR(repr, object->repr, "vert-origin-x");
171         COPY_ATTR(repr, object->repr, "vert-origin-y");
172         COPY_ATTR(repr, object->repr, "vert-adv-y");
173     }
175     if (((SPObjectClass *) (parent_class))->write) {
176         ((SPObjectClass *) (parent_class))->write(object, repr, flags);
177     }
179     return repr;
182 /*
183   Local Variables:
184   mode:c++
185   c-file-style:"stroustrup"
186   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
187   indent-tabs-mode:nil
188   fill-column:99
189   End:
190 */
191 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :