1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
5 #ifdef ENABLE_SVG_FONTS
6 #define __SP_MISSING_GLYPH_C__
8 /*
9 * SVG <missing-glyph> element implementation
10 *
11 * Author:
12 * Felipe C. da S. Sanches <felipe.sanches@gmail.com>
13 *
14 * Copyright (C) 2008, Felipe C. da S. Sanches
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
19 #include "xml/repr.h"
20 #include "attributes.h"
21 #include "sp-missing-glyph.h"
22 #include "document.h"
23 #include "helper-fns.h"
25 static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc);
26 static void sp_missing_glyph_init(SPMissingGlyph *glyph);
28 static void sp_missing_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
29 static void sp_missing_glyph_release(SPObject *object);
30 static void sp_missing_glyph_set(SPObject *object, unsigned int key, const gchar *value);
31 static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
33 static SPObjectClass *parent_class;
35 GType sp_missing_glyph_get_type(void)
36 {
37 static GType type = 0;
39 if (!type) {
40 GTypeInfo info = {
41 sizeof(SPMissingGlyphClass),
42 NULL, /* base_init */
43 NULL, /* base_finalize */
44 (GClassInitFunc) sp_missing_glyph_class_init,
45 NULL, /* class_finalize */
46 NULL, /* class_data */
47 sizeof(SPMissingGlyph),
48 16, /* n_preallocs */
49 (GInstanceInitFunc) sp_missing_glyph_init,
50 NULL, /* value_table */
51 };
52 type = g_type_register_static(SP_TYPE_OBJECT, "SPMissingGlyph", &info, (GTypeFlags) 0);
53 }
55 return type;
56 }
58 static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc)
59 {
60 SPObjectClass *sp_object_class = (SPObjectClass *) gc;
62 parent_class = (SPObjectClass*)g_type_class_peek_parent(gc);
64 sp_object_class->build = sp_missing_glyph_build;
65 sp_object_class->release = sp_missing_glyph_release;
66 sp_object_class->set = sp_missing_glyph_set;
67 sp_object_class->write = sp_missing_glyph_write;
68 }
70 static void sp_missing_glyph_init(SPMissingGlyph *glyph)
71 {
72 //TODO: correct these values:
73 glyph->d = NULL;
74 glyph->horiz_adv_x = 0;
75 glyph->vert_origin_x = 0;
76 glyph->vert_origin_y = 0;
77 glyph->vert_adv_y = 0;
78 }
80 static void sp_missing_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
81 {
82 if (((SPObjectClass *) (parent_class))->build) {
83 ((SPObjectClass *) (parent_class))->build(object, document, repr);
84 }
86 sp_object_read_attr(object, "d");
87 sp_object_read_attr(object, "horiz-adv-x");
88 sp_object_read_attr(object, "vert-origin-x");
89 sp_object_read_attr(object, "vert-origin-y");
90 sp_object_read_attr(object, "vert-adv-y");
91 }
93 static void sp_missing_glyph_release(SPObject *object)
94 {
95 //SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
97 if (((SPObjectClass *) parent_class)->release) {
98 ((SPObjectClass *) parent_class)->release(object);
99 }
100 }
102 static void sp_missing_glyph_set(SPObject *object, unsigned int key, const gchar *value)
103 {
104 SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
105 double number;
107 switch (key) {
108 case SP_ATTR_D:
109 if (glyph->d) g_free(glyph->d);
110 glyph->d = g_strdup(value);
111 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
112 break;
113 case SP_ATTR_HORIZ_ADV_X:
114 number = helperfns_read_number(value);
115 if (number != glyph->horiz_adv_x){
116 glyph->horiz_adv_x = number;
117 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
118 }
119 break;
120 case SP_ATTR_VERT_ORIGIN_X:
121 number = helperfns_read_number(value);
122 if (number != glyph->vert_origin_x){
123 glyph->vert_origin_x = number;
124 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
125 }
126 break;
127 case SP_ATTR_VERT_ORIGIN_Y:
128 number = helperfns_read_number(value);
129 if (number != glyph->vert_origin_y){
130 glyph->vert_origin_y = number;
131 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
132 }
133 break;
134 case SP_ATTR_VERT_ADV_Y:
135 number = helperfns_read_number(value);
136 if (number != glyph->vert_adv_y){
137 glyph->vert_adv_y = 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 }
147 }
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::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
152 {
153 // SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
155 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
156 repr = xml_doc->createElement("svg:glyph");
157 }
159 /* I am commenting out this part because I am not certain how does it work. I will have to study it later. Juca
160 repr->setAttribute("d", glyph->d);
161 sp_repr_set_svg_double(repr, "horiz-adv-x", glyph->horiz_adv_x);
162 sp_repr_set_svg_double(repr, "vert-origin-x", glyph->vert_origin_x);
163 sp_repr_set_svg_double(repr, "vert-origin-y", glyph->vert_origin_y);
164 sp_repr_set_svg_double(repr, "vert-adv-y", glyph->vert_adv_y);
165 */
166 if (repr != SP_OBJECT_REPR(object)) {
167 COPY_ATTR(repr, object->repr, "d");
168 COPY_ATTR(repr, object->repr, "horiz-adv-x");
169 COPY_ATTR(repr, object->repr, "vert-origin-x");
170 COPY_ATTR(repr, object->repr, "vert-origin-y");
171 COPY_ATTR(repr, object->repr, "vert-adv-y");
172 }
174 if (((SPObjectClass *) (parent_class))->write) {
175 ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
176 }
178 return repr;
179 }
180 #endif //#ifdef ENABLE_SVG_FONTS
181 /*
182 Local Variables:
183 mode:c++
184 c-file-style:"stroustrup"
185 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
186 indent-tabs-mode:nil
187 fill-column:99
188 End:
189 */
190 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :