Code

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