Code

Prevent localized doubles from being written into filter matrices
[inkscape.git] / src / sp-missing-glyph.cpp
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
5 #ifdef ENABLE_SVG_FONTS
7 /*
8  * SVG <missing-glyph> element implementation
9  *
10  * Author:
11  *   Felipe C. da S. Sanches <juca@members.fsf.org>
12  *   Abhishek Sharma
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"
24 static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc);
25 static void sp_missing_glyph_init(SPMissingGlyph *glyph);
27 static void sp_missing_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
28 static void sp_missing_glyph_release(SPObject *object);
29 static void sp_missing_glyph_set(SPObject *object, unsigned int key, const gchar *value);
30 static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
32 static SPObjectClass *parent_class;
34 GType sp_missing_glyph_get_type(void)
35 {
36     static GType type = 0;
38     if (!type) {
39         GTypeInfo info = {
40             sizeof(SPMissingGlyphClass),
41             NULL,       /* base_init */
42             NULL,       /* base_finalize */
43             (GClassInitFunc) sp_missing_glyph_class_init,
44             NULL,       /* class_finalize */
45             NULL,       /* class_data */
46             sizeof(SPMissingGlyph),
47             16, /* n_preallocs */
48             (GInstanceInitFunc) sp_missing_glyph_init,
49             NULL,       /* value_table */
50         };
51         type = g_type_register_static(SP_TYPE_OBJECT, "SPMissingGlyph", &info, (GTypeFlags) 0);
52     }
54     return type;
55 }
57 static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc)
58 {
59     SPObjectClass *sp_object_class = (SPObjectClass *) gc;
61     parent_class = (SPObjectClass*)g_type_class_peek_parent(gc);
63     sp_object_class->build = sp_missing_glyph_build;
64     sp_object_class->release = sp_missing_glyph_release;
65     sp_object_class->set = sp_missing_glyph_set;
66     sp_object_class->write = sp_missing_glyph_write;
67 }
69 static void sp_missing_glyph_init(SPMissingGlyph *glyph)
70 {
71 //TODO: correct these values:
72     glyph->d = NULL;
73     glyph->horiz_adv_x = 0;
74     glyph->vert_origin_x = 0;
75     glyph->vert_origin_y = 0;
76     glyph->vert_adv_y = 0;
77 }
79 static void sp_missing_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
80 {
81     if (((SPObjectClass *) (parent_class))->build) {
82         ((SPObjectClass *) (parent_class))->build(object, document, repr);
83     }
85     object->readAttr( "d" );
86     object->readAttr( "horiz-adv-x" );
87     object->readAttr( "vert-origin-x" );
88     object->readAttr( "vert-origin-y" );
89     object->readAttr( "vert-adv-y" );
90 }
92 static void sp_missing_glyph_release(SPObject *object)
93 {
94     //SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
96     if (((SPObjectClass *) parent_class)->release) {
97         ((SPObjectClass *) parent_class)->release(object);
98     }
99 }
101 static void sp_missing_glyph_set(SPObject *object, unsigned int key, const gchar *value)
103     SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
105     switch (key) {
106         case SP_ATTR_D:
107         {
108             if (glyph->d) {
109                 g_free(glyph->d);
110             }
111             glyph->d = g_strdup(value);
112             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
113             break;
114         }
115         case SP_ATTR_HORIZ_ADV_X:
116         {
117             double number = value ? g_ascii_strtod(value, 0) : 0;
118             if (number != glyph->horiz_adv_x){
119                 glyph->horiz_adv_x = number;
120                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
121             }
122             break;
123         }
124         case SP_ATTR_VERT_ORIGIN_X:
125         {
126             double number = value ? g_ascii_strtod(value, 0) : 0;
127             if (number != glyph->vert_origin_x){
128                 glyph->vert_origin_x = number;
129                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
130             }
131             break;
132         }
133         case SP_ATTR_VERT_ORIGIN_Y:
134         {
135             double number = value ? g_ascii_strtod(value, 0) : 0;
136             if (number != glyph->vert_origin_y){
137                 glyph->vert_origin_y = number;
138                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
139             }
140             break;
141         }
142         case SP_ATTR_VERT_ADV_Y:
143         {
144             double number = value ? g_ascii_strtod(value, 0) : 0;
145             if (number != glyph->vert_adv_y){
146                 glyph->vert_adv_y = number;
147                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
148             }
149             break;
150         }
151         default:
152         {
153             if (((SPObjectClass *) (parent_class))->set) {
154                 ((SPObjectClass *) (parent_class))->set(object, key, value);
155             }
156             break;
157         }
158     }
161 #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
163 static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
165 //    SPMissingGlyph *glyph = SP_MISSING_GLYPH(object);
167     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
168         repr = xml_doc->createElement("svg:glyph");
169     }
171 /* I am commenting out this part because I am not certain how does it work. I will have to study it later. Juca
172     repr->setAttribute("d", glyph->d);
173     sp_repr_set_svg_double(repr, "horiz-adv-x", glyph->horiz_adv_x);
174     sp_repr_set_svg_double(repr, "vert-origin-x", glyph->vert_origin_x);
175     sp_repr_set_svg_double(repr, "vert-origin-y", glyph->vert_origin_y);
176     sp_repr_set_svg_double(repr, "vert-adv-y", glyph->vert_adv_y);
177 */
178     if (repr != SP_OBJECT_REPR(object)) {
180         // All the COPY_ATTR functions below use
181         //  XML Tree directly while they shouldn't.
182         COPY_ATTR(repr, object->getRepr(), "d");
183         COPY_ATTR(repr, object->getRepr(), "horiz-adv-x");
184         COPY_ATTR(repr, object->getRepr(), "vert-origin-x");
185         COPY_ATTR(repr, object->getRepr(), "vert-origin-y");
186         COPY_ATTR(repr, object->getRepr(), "vert-adv-y");
187     }
189     if (((SPObjectClass *) (parent_class))->write) {
190         ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
191     }
193     return repr;
195 #endif //#ifdef ENABLE_SVG_FONTS
196 /*
197   Local Variables:
198   mode:c++
199   c-file-style:"stroustrup"
200   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
201   indent-tabs-mode:nil
202   fill-column:99
203   End:
204 */
205 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :