a8609f5ee3b7b0bdb0605a2193bf6fb7e71e8dd2
1 #define __SP_ANCHOR_C__
3 /*
4 * SVG <hkern> and <vkern> elements implementation
5 * W3C SVG 1.1 spec, page 476, section 20.7
6 *
7 * Author:
8 * Felipe C. da S. Sanches <felipe.sanches@gmail.com>
9 *
10 * Copyright (C) 2008, Felipe C. da S. Sanches
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #include "xml/repr.h"
16 #include "attributes.h"
17 #include "sp-glyph-kerning.h"
19 #include "document.h"
20 #include "helper-fns.h"
22 static void sp_glyph_kerning_class_init(SPGlyphKerningClass *gc);
23 static void sp_glyph_kerning_init(SPGlyphKerning *glyph);
25 static void sp_glyph_kerning_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
26 static void sp_glyph_kerning_release(SPObject *object);
27 static void sp_glyph_kerning_set(SPObject *object, unsigned int key, const gchar *value);
28 static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
29 static void sp_glyph_kerning_update(SPObject *object, SPCtx *ctx, guint flags);
31 static SPObjectClass *parent_class;
33 GType sp_glyph_kerning_get_type(void)
34 {
35 static GType type = 0;
37 if (!type) {
38 GTypeInfo info = {
39 sizeof(SPGlyphKerningClass),
40 NULL, /* base_init */
41 NULL, /* base_finalize */
42 (GClassInitFunc) sp_glyph_kerning_class_init,
43 NULL, /* class_finalize */
44 NULL, /* class_data */
45 sizeof(SPGlyphKerning),
46 16, /* n_preallocs */
47 (GInstanceInitFunc) sp_glyph_kerning_init,
48 NULL, /* value_table */
49 };
50 type = g_type_register_static(SP_TYPE_OBJECT, "SPGlyphKerning", &info, (GTypeFlags) 0);
51 }
53 return type;
54 }
56 static void sp_glyph_kerning_class_init(SPGlyphKerningClass *gc)
57 {
58 SPObjectClass *sp_object_class = (SPObjectClass *) gc;
60 parent_class = (SPObjectClass*)g_type_class_peek_parent(gc);
62 sp_object_class->build = sp_glyph_kerning_build;
63 sp_object_class->release = sp_glyph_kerning_release;
64 sp_object_class->set = sp_glyph_kerning_set;
65 sp_object_class->write = sp_glyph_kerning_write;
66 sp_object_class->update = sp_glyph_kerning_update;
67 }
69 static void sp_glyph_kerning_init(SPGlyphKerning *glyph)
70 {
71 //TODO: correct these values:
72 glyph->u1 = NULL;
73 glyph->g1 = NULL;
74 glyph->u2 = NULL;
75 glyph->g2 = NULL;
76 glyph->k = 0;
77 }
79 static void sp_glyph_kerning_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 sp_object_read_attr(object, "u1");
86 sp_object_read_attr(object, "g1");
87 sp_object_read_attr(object, "u2");
88 sp_object_read_attr(object, "g2");
89 sp_object_read_attr(object, "k");
90 }
92 static void sp_glyph_kerning_release(SPObject *object)
93 {
94 //SPGlyphKerning *glyph = SP_GLYPH_KERNING(object);
96 if (((SPObjectClass *) parent_class)->release) {
97 ((SPObjectClass *) parent_class)->release(object);
98 }
99 }
101 static void sp_glyph_kerning_set(SPObject *object, unsigned int key, const gchar *value)
102 {
103 SPGlyphKerning *glyphkern = SP_GLYPH_KERNING(object);
104 double number;
106 switch (key) {
107 case SP_ATTR_U1:
108 if (glyphkern->u1) g_free(glyphkern->u1);
109 glyphkern->u1 = g_strdup(value);//todo:
110 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
111 g_warning("<glyph-kerning>: SP_ATTR_U1: %s", value);
112 break;
113 case SP_ATTR_U2:
114 if (glyphkern->u2) g_free(glyphkern->u2);
115 glyphkern->u2 = g_strdup(value);//todo:
116 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
117 g_warning("<glyph-kerning>: SP_ATTR_U2: %s", value);
118 break;
119 case SP_ATTR_G1:
120 if (glyphkern->g1) g_free(glyphkern->g1);
121 glyphkern->g1 = g_strdup(value);//todo:
122 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
123 g_warning("<glyph-kerning>: SP_ATTR_G1: %s", value);
124 break;
125 case SP_ATTR_G2:
126 if (glyphkern->g2) g_free(glyphkern->g2);
127 glyphkern->g2 = g_strdup(value);//todo:
128 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
129 g_warning("<glyph-kerning>: SP_ATTR_G2: %s", value);
130 break;
131 case SP_ATTR_K:
132 number = helperfns_read_number(value);
133 if (number != glyphkern->k){
134 glyphkern->k = number;
135 g_warning("<glyph-kerning>: SP_ATTR_K: %f", number);
136 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
137 }
138 break;
139 default:
140 if (((SPObjectClass *) (parent_class))->set) {
141 ((SPObjectClass *) (parent_class))->set(object, key, value);
142 }
143 break;
144 }
145 }
147 /**
148 * * Receives update notifications.
149 * */
150 static void
151 sp_glyph_kerning_update(SPObject *object, SPCtx *ctx, guint flags)
152 {
153 SPGlyphKerning *glyph = SP_GLYPH_KERNING(object);
154 (void)glyph;
156 if (flags & SP_OBJECT_MODIFIED_FLAG) {
157 /* do something to trigger redisplay, updates? */
158 sp_object_read_attr(object, "u1");
159 sp_object_read_attr(object, "g1");
160 sp_object_read_attr(object, "u2");
161 sp_object_read_attr(object, "g2");
162 sp_object_read_attr(object, "k");
163 }
165 if (((SPObjectClass *) parent_class)->update) {
166 ((SPObjectClass *) parent_class)->update(object, ctx, flags);
167 }
168 }
170 #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
172 static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
173 {
174 // SPGlyphKerning *glyph = SP_GLYPH_KERNING(object);
176 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
177 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
178 repr = xml_doc->createElement("svg:glyphkerning");//fix this!
179 }
181 /* I am commenting out this part because I am not certain how does it work. I will have to study it later. Juca
182 repr->setAttribute("unicode", glyph->unicode);
183 repr->setAttribute("glyph-name", glyph->glyph_name);
184 repr->setAttribute("d", glyph->d);
185 sp_repr_set_svg_double(repr, "orientation", (double) glyph->orientation);
186 sp_repr_set_svg_double(repr, "arabic-form", (double) glyph->arabic_form);
187 repr->setAttribute("lang", glyph->lang);
188 sp_repr_set_svg_double(repr, "horiz-adv-x", glyph->horiz_adv_x);
189 sp_repr_set_svg_double(repr, "vert-origin-x", glyph->vert_origin_x);
190 sp_repr_set_svg_double(repr, "vert-origin-y", glyph->vert_origin_y);
191 sp_repr_set_svg_double(repr, "vert-adv-y", glyph->vert_adv_y);
192 */
193 if (repr != SP_OBJECT_REPR(object)) {
194 COPY_ATTR(repr, object->repr, "u1");
195 COPY_ATTR(repr, object->repr, "g1");
196 COPY_ATTR(repr, object->repr, "u2");
197 COPY_ATTR(repr, object->repr, "g2");
198 COPY_ATTR(repr, object->repr, "k");
199 }
201 if (((SPObjectClass *) (parent_class))->write) {
202 ((SPObjectClass *) (parent_class))->write(object, repr, flags);
203 }
205 return repr;
206 }
208 /*
209 Local Variables:
210 mode:c++
211 c-file-style:"stroustrup"
212 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
213 indent-tabs-mode:nil
214 fill-column:99
215 End:
216 */
217 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :