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 g_warning("<missing-glyph>: SP_ATTR_D: %s", value);
113 break;
114 case SP_ATTR_HORIZ_ADV_X:
115 number = helperfns_read_number(value);
116 if (number != glyph->horiz_adv_x){
117 glyph->horiz_adv_x = number;
118 g_warning("<missing-glyph>: SP_ATTR_HORIZ_ADV_X: %f", number);
119 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
120 }
121 break;
122 case SP_ATTR_VERT_ORIGIN_X:
123 number = helperfns_read_number(value);
124 if (number != glyph->vert_origin_x){
125 glyph->vert_origin_x = number;
126 g_warning("<missing-glyph>: SP_ATTR_VERT_ORIGIN_X: %f", number);
127 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
128 }
129 break;
130 case SP_ATTR_VERT_ORIGIN_Y:
131 number = helperfns_read_number(value);
132 if (number != glyph->vert_origin_y){
133 glyph->vert_origin_y = number;
134 g_warning("<missing-glyph>: SP_ATTR_VERT_ORIGIN_Y: %f", number);
135 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
136 }
137 break;
138 case SP_ATTR_VERT_ADV_Y:
139 number = helperfns_read_number(value);
140 if (number != glyph->vert_adv_y){
141 glyph->vert_adv_y = number;
142 g_warning("<missing-glyph>: SP_ATTR_VERT_ADV_Y: %f", number);
143 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
144 }
145 break;
146 default:
147 if (((SPObjectClass *) (parent_class))->set) {
148 ((SPObjectClass *) (parent_class))->set(object, key, value);
149 }
150 break;
151 }
152 }
154 #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
156 static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
157 {
158 // SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
160 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
161 repr = xml_doc->createElement("svg:glyph");
162 }
164 /* I am commenting out this part because I am not certain how does it work. I will have to study it later. Juca
165 repr->setAttribute("d", glyph->d);
166 sp_repr_set_svg_double(repr, "horiz-adv-x", glyph->horiz_adv_x);
167 sp_repr_set_svg_double(repr, "vert-origin-x", glyph->vert_origin_x);
168 sp_repr_set_svg_double(repr, "vert-origin-y", glyph->vert_origin_y);
169 sp_repr_set_svg_double(repr, "vert-adv-y", glyph->vert_adv_y);
170 */
171 if (repr != SP_OBJECT_REPR(object)) {
172 COPY_ATTR(repr, object->repr, "d");
173 COPY_ATTR(repr, object->repr, "horiz-adv-x");
174 COPY_ATTR(repr, object->repr, "vert-origin-x");
175 COPY_ATTR(repr, object->repr, "vert-origin-y");
176 COPY_ATTR(repr, object->repr, "vert-adv-y");
177 }
179 if (((SPObjectClass *) (parent_class))->write) {
180 ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
181 }
183 return repr;
184 }
185 #endif //#ifdef ENABLE_SVG_FONTS
186 /*
187 Local Variables:
188 mode:c++
189 c-file-style:"stroustrup"
190 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
191 indent-tabs-mode:nil
192 fill-column:99
193 End:
194 */
195 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :