Code

fdab91bc354390be0d118d7494437ba2cc4cc729
[inkscape.git] / src / sp-font-face.cpp
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
5 #ifdef ENABLE_SVG_FONTS
6 #define __SP_FONTFACE_C__
8 /*
9  * SVG <font-face> element implementation
10  *
11  * Section 20.8.3 of the W3C SVG 1.1 spec
12  * available at: 
13  * http://www.w3.org/TR/SVG/fonts.html#FontFaceElement
14  *
15  * Author:
16  *   Felipe C. da S. Sanches <felipe.sanches@gmail.com>
17  *
18  * Copyright (C) 2008, Felipe C. da S. Sanches
19  *
20  * Released under GNU GPL, read the file 'COPYING' for more information
21  */
23 #include "xml/repr.h"
24 #include "attributes.h"
25 #include "sp-font-face.h"
26 #include "document.h"
27 #include "helper-fns.h"
29 class ObjectContainer
30 {
32 public:
33     ObjectContainer(double def){
34         this->isset = false;
35         this->default_value = def;
36     }
38     double get(){
39         if (this->isset)
40             return this->obj;
41         else
42             return this->default_value;
43     }
45     void set(double val){
46         this->obj = val;
47         this->isset = true;
48     }
50     void unset(){
51         this->isset = false;
52     }
54 private:
55     double obj;
56     double default_value;
57     bool isset;
58 };
60 static std::vector<FontFaceStyleType> sp_read_fontFaceStyleType(gchar const *value){
61     std::vector<FontFaceStyleType> v;
63     if (!value){
64         v.push_back(SP_FONTFACE_STYLE_ALL);
65         return v;
66     }
67     
68     if (strncmp(value, "all", 3) == 0){
69         value += 3;
70         while(value[0]==',' || value[0]==' ')
71             value++;
72         v.push_back(SP_FONTFACE_STYLE_ALL);
73         return v;
74     }
76     while(value[0]!='\0'){
77         switch(value[0]){
78             case 'n':
79                 if (strncmp(value, "normal", 6) == 0){
80                     v.push_back(SP_FONTFACE_STYLE_NORMAL);
81                     value += 6;
82                 }
83                 break;
84             case 'i':
85                 if (strncmp(value, "italic", 6) == 0){
86                     v.push_back(SP_FONTFACE_STYLE_ITALIC);
87                     value += 6;
88                 }
89                 break;
90             case 'o':
91                 if (strncmp(value, "oblique", 7) == 0){
92                     v.push_back(SP_FONTFACE_STYLE_OBLIQUE);
93                     value += 7;
94                 }
95                 break;
96         }
97         while(value[0]==',' || value[0]==' ')
98             value++;
99     }
100     return v;
103 static std::vector<FontFaceVariantType> sp_read_fontFaceVariantType(gchar const *value){
104     std::vector<FontFaceVariantType> v;
106     if (!value){
107         v.push_back(SP_FONTFACE_VARIANT_NORMAL);
108         return v;
109     }
111     while(value[0]!='\0'){
112         switch(value[0]){
113             case 'n':
114                 if (strncmp(value, "normal", 6) == 0){
115                     v.push_back(SP_FONTFACE_VARIANT_NORMAL);
116                     value += 6;
117                 }
118                 break;
119             case 's':
120                 if (strncmp(value, "small-caps", 10) == 0){
121                     v.push_back(SP_FONTFACE_VARIANT_SMALL_CAPS);
122                     value += 10;
123                 }
124                 break;
125         }
126         while(value[0]==',' || value[0]==' ')
127             value++;
128     }
129     return v;
132 static std::vector<FontFaceWeightType> sp_read_fontFaceWeightType(gchar const *value){
133     std::vector<FontFaceWeightType> v;
135     if (!value){
136         v.push_back(SP_FONTFACE_WEIGHT_ALL);
137         return v;
138     }
139     
140     if (strncmp(value, "all", 3) == 0){
141         value += 3;
142         while(value[0]==',' || value[0]==' ')
143             value++;
144         v.push_back(SP_FONTFACE_WEIGHT_ALL);
145         return v;
146     }
148     while(value[0]!='\0'){
149         switch(value[0]){
150             case 'n':
151                 if (strncmp(value, "normal", 6) == 0){
152                     v.push_back(SP_FONTFACE_WEIGHT_NORMAL);
153                     value += 6;
154                 }
155                 break;
156             case 'b':
157                 if (strncmp(value, "bold", 4) == 0){
158                     v.push_back(SP_FONTFACE_WEIGHT_BOLD);
159                     value += 4;
160                 }
161                 break;
162             case '1':
163                 if (strncmp(value, "100", 3) == 0){
164                     v.push_back(SP_FONTFACE_WEIGHT_100);
165                     value += 3;
166                 }
167                 break;
168             case '2':
169                 if (strncmp(value, "200", 3) == 0){
170                     v.push_back(SP_FONTFACE_WEIGHT_200);
171                     value += 3;
172                 }
173                 break;
174             case '3':
175                 if (strncmp(value, "300", 3) == 0){
176                     v.push_back(SP_FONTFACE_WEIGHT_300);
177                     value += 3;
178                 }
179                 break;
180             case '4':
181                 if (strncmp(value, "400", 3) == 0){
182                     v.push_back(SP_FONTFACE_WEIGHT_400);
183                     value += 3;
184                 }
185                 break;
186             case '5':
187                 if (strncmp(value, "500", 3) == 0){
188                     v.push_back(SP_FONTFACE_WEIGHT_500);
189                     value += 3;
190                 }
191                 break;
192             case '6':
193                 if (strncmp(value, "600", 3) == 0){
194                     v.push_back(SP_FONTFACE_WEIGHT_600);
195                     value += 3;
196                 }
197                 break;
198             case '7':
199                 if (strncmp(value, "700", 3) == 0){
200                     v.push_back(SP_FONTFACE_WEIGHT_700);
201                     value += 3;
202                 }
203                 break;
204             case '8':
205                 if (strncmp(value, "800", 3) == 0){
206                     v.push_back(SP_FONTFACE_WEIGHT_800);
207                     value += 3;
208                 }
209                 break;
210             case '9':
211                 if (strncmp(value, "900", 3) == 0){
212                     v.push_back(SP_FONTFACE_WEIGHT_900);
213                     value += 3;
214                 }
215                 break;
216         }
217         while(value[0]==',' || value[0]==' ')
218             value++;
219     }
220     return v;
223 static std::vector<FontFaceStretchType> sp_read_fontFaceStretchType(gchar const *value){
224     std::vector<FontFaceStretchType> v;
226     if (!value){
227         v.push_back(SP_FONTFACE_STRETCH_NORMAL);
228         return v;
229     }
230     
231     if (strncmp(value, "all", 3) == 0){
232         value += 3;
233         while(value[0]==',' || value[0]==' ')
234             value++;
235         v.push_back(SP_FONTFACE_STRETCH_ALL);
236         return v;
237     }
239     while(value[0]!='\0'){
240         switch(value[0]){
241             case 'n':
242                 if (strncmp(value, "normal", 6) == 0){
243                     v.push_back(SP_FONTFACE_STRETCH_NORMAL);
244                     value += 6;
245                 }
246                 break;
247             case 'u':
248                 if (strncmp(value, "ultra-condensed", 15) == 0){
249                     v.push_back(SP_FONTFACE_STRETCH_ULTRA_CONDENSED);
250                     value += 15;
251                 }
252                 if (strncmp(value, "ultra-expanded", 14) == 0){
253                     v.push_back(SP_FONTFACE_STRETCH_ULTRA_EXPANDED);
254                     value += 14;
255                 }
256                 break;
257             case 'e':
258                 if (strncmp(value, "expanded", 8) == 0){
259                     v.push_back(SP_FONTFACE_STRETCH_EXPANDED);
260                     value += 8;
261                 }
262                 if (strncmp(value, "extra-condensed", 15) == 0){
263                     v.push_back(SP_FONTFACE_STRETCH_EXTRA_CONDENSED);
264                     value += 15;
265                 }
266                 if (strncmp(value, "extra-expanded", 14) == 0){
267                     v.push_back(SP_FONTFACE_STRETCH_EXTRA_EXPANDED);
268                     value += 14;
269                 }
270                 break;
271             case 'c':
272                 if (strncmp(value, "condensed", 9) == 0){
273                     v.push_back(SP_FONTFACE_STRETCH_CONDENSED);
274                     value += 9;
275                 }
276                 break;
277             case 's':
278                 if (strncmp(value, "semi-condensed", 14) == 0){
279                     v.push_back(SP_FONTFACE_STRETCH_SEMI_CONDENSED);
280                     value += 14;
281                 }
282                 if (strncmp(value, "semi-expanded", 13) == 0){
283                     v.push_back(SP_FONTFACE_STRETCH_SEMI_EXPANDED);
284                     value += 13;
285                 }
286                 break;
287         }
288         while(value[0]==',' || value[0]==' ')
289             value++;
290     }
291     return v;
294 static void sp_fontface_class_init(SPFontFaceClass *fc);
295 static void sp_fontface_init(SPFontFace *font);
297 static void sp_fontface_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
298 static void sp_fontface_release(SPObject *object);
299 static void sp_fontface_set(SPObject *object, unsigned int key, const gchar *value);
300 static Inkscape::XML::Node *sp_fontface_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
302 static void sp_fontface_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
303 static void sp_fontface_remove_child(SPObject *object, Inkscape::XML::Node *child);
304 static void sp_fontface_update(SPObject *object, SPCtx *ctx, guint flags);
306 static SPObjectClass *parent_class;
308 GType sp_fontface_get_type(void)
310     static GType type = 0;
312     if (!type) {
313         GTypeInfo info = {
314             sizeof(SPFontFaceClass),
315             NULL,       /* base_init */
316             NULL,       /* base_finalize */
317             (GClassInitFunc) sp_fontface_class_init,
318             NULL,       /* class_finalize */
319             NULL,       /* class_data */
320             sizeof(SPFontFace),
321             16, /* n_preallocs */
322             (GInstanceInitFunc) sp_fontface_init,
323             NULL,       /* value_table */
324         };
325         type = g_type_register_static(SP_TYPE_OBJECT, "SPFontFace", &info, (GTypeFlags) 0);
326     }
328     return type;
331 static void sp_fontface_class_init(SPFontFaceClass *fc)
333     SPObjectClass *sp_object_class = (SPObjectClass *) fc;
335     parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
337     sp_object_class->build = sp_fontface_build;
338     sp_object_class->release = sp_fontface_release;
339     sp_object_class->set = sp_fontface_set;
340     sp_object_class->write = sp_fontface_write;
341     sp_object_class->child_added = sp_fontface_child_added;
342     sp_object_class->remove_child = sp_fontface_remove_child;
343     sp_object_class->update = sp_fontface_update;
346 static void sp_fontface_init(SPFontFace *face)
348     std::vector<FontFaceStyleType> style;
349     style.push_back(SP_FONTFACE_STYLE_ALL);
350     face->font_style = style;
352     std::vector<FontFaceVariantType> variant;
353     variant.push_back(SP_FONTFACE_VARIANT_NORMAL);
354     face->font_variant = variant;
356     std::vector<FontFaceWeightType> weight;
357     weight.push_back(SP_FONTFACE_WEIGHT_ALL);
358     face->font_weight = weight;
360     std::vector<FontFaceStretchType> stretch;
361     stretch.push_back(SP_FONTFACE_STRETCH_NORMAL);
362     face->font_stretch = stretch;
363 /*
364     face->font_family = NULL;
365     //face->font_style = ;
366     //face->font_variant = ;
367     //face->font_weight = ;
368     //face->font_stretch = ;
369     face->font_size = NULL;
370     //face->unicode_range = ;
371     face->units_per_em = 1000;
372     //face->panose_1 = ;
373     face->stem_v = ;
374     face->stem_h = ;
375     face->slope = 0;
376     face->cap_height = ;
377     face->x_height = ;
378     face->accent_height = ;
379     face->ascent = ;
380     face->descent = ;
381     face->widths = NULL;
382     face->bbox = NULL;
383     face->ideographic = ;
384     face->alphabetic = ;
385     face->mathematical = ;
386     face->hanging = ;
387     face->v_ideographic = ;
388     face->v_alphabetic = ;
389     face->v_mathematical = ;
390     face->v_hanging = ;
391     face->underline_position = ;
392     face->underline_thickness = ;
393     face->strikethrough_position = ;
394     face->strikethrough_thickness = ;
395     face->overline_position = ;
396     face->overline_thickness = ;
397 */
400 static void sp_fontface_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
402     if (((SPObjectClass *) (parent_class))->build) {
403         ((SPObjectClass *) (parent_class))->build(object, document, repr);
404     }
406     sp_object_read_attr(object, "font-family");
407     sp_object_read_attr(object, "font-style");
408     sp_object_read_attr(object, "font-variant");
409     sp_object_read_attr(object, "font-weight");
410     sp_object_read_attr(object, "font-stretch");
411     sp_object_read_attr(object, "font-size");
412     sp_object_read_attr(object, "unicode-range");
413     sp_object_read_attr(object, "units-per-em");
414     sp_object_read_attr(object, "panose-1");
415     sp_object_read_attr(object, "stem-v");
416     sp_object_read_attr(object, "stem-h");
417     sp_object_read_attr(object, "slope");
418     sp_object_read_attr(object, "cap-height");
419     sp_object_read_attr(object, "x-height");
420     sp_object_read_attr(object, "accent-height");
421     sp_object_read_attr(object, "ascent");
422     sp_object_read_attr(object, "descent");
423     sp_object_read_attr(object, "widths");
424     sp_object_read_attr(object, "bbox");
425     sp_object_read_attr(object, "ideographic");
426     sp_object_read_attr(object, "alphabetic");
427     sp_object_read_attr(object, "mathematical");
428     sp_object_read_attr(object, "ranging");
429     sp_object_read_attr(object, "v-ideogaphic");
430     sp_object_read_attr(object, "v-alphabetic");
431     sp_object_read_attr(object, "v-mathematical");
432     sp_object_read_attr(object, "v-hanging");
433     sp_object_read_attr(object, "underline-position");
434     sp_object_read_attr(object, "underline-thickness");
435     sp_object_read_attr(object, "strikethrough-position");
436     sp_object_read_attr(object, "strikethrough-thickness");
437     sp_object_read_attr(object, "overline-position");
438     sp_object_read_attr(object, "overline-thickness");
441 static void sp_fontface_children_modified(SPFontFace *sp_fontface)
445 /**
446  * Callback for child_added event.
447  */
448 static void
449 sp_fontface_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
451     SPFontFace *f = SP_FONTFACE(object);
453     if (((SPObjectClass *) parent_class)->child_added)
454         (* ((SPObjectClass *) parent_class)->child_added)(object, child, ref);
456     sp_fontface_children_modified(f);
457     object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
461 /**
462  * Callback for remove_child event.
463  */
464 static void
465 sp_fontface_remove_child(SPObject *object, Inkscape::XML::Node *child)
467     SPFontFace *f = SP_FONTFACE(object);
469     if (((SPObjectClass *) parent_class)->remove_child)
470         (* ((SPObjectClass *) parent_class)->remove_child)(object, child);
472     sp_fontface_children_modified(f);
473     object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
476 static void sp_fontface_release(SPObject *object)
478     //SPFontFace *font = SP_FONTFACE(object);
480     if (((SPObjectClass *) parent_class)->release) {
481         ((SPObjectClass *) parent_class)->release(object);
482     }
485 static void sp_fontface_set(SPObject *object, unsigned int key, const gchar *value)
487     SPFontFace *face = SP_FONTFACE(object);
488     double number;
489     std::vector<FontFaceStyleType> style;
490     std::vector<FontFaceVariantType> variant;
491     std::vector<FontFaceWeightType> weight;
492     std::vector<FontFaceStretchType> stretch;
494     switch (key) {
495         case SP_PROP_FONT_STYLE:
496             style = sp_read_fontFaceStyleType(value);
497             if (face->font_style.size() != style.size()){
498                 face->font_style = style;
499 g_warning("<font-face>: SP_ATTR_FONT_STYLE:");
500                 for (unsigned int i=0;i<style.size();i++){
501                     g_warning("enum value: %d", style[i]);
502                 }
503                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
504             } else {
505                 for (unsigned int i=0;i<style.size();i++){
506                     if(style[i] != face->font_style[i]){
507                         face->font_style = style;
508 g_warning("<font-face>: SP_ATTR_FONT_STYLE:");
509                         for (unsigned int i=0;i<style.size();i++){
510                             g_warning("enum value: %d", style[i]);
511                         }
512                         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
513                         break;
514                     }
515                 }
516             }
517             break;
518         case SP_PROP_FONT_VARIANT:
519             variant = sp_read_fontFaceVariantType(value);
520             if (face->font_variant.size() != variant.size()){
521                 face->font_variant = variant;
522 g_warning("<font-face>: SP_ATTR_FONT_VARIANT:");
523                 for (unsigned int i=0;i<variant.size();i++){
524                     g_warning("enum value: %d", variant[i]);
525                 }
526                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
527             } else {
528                 for (unsigned int i=0;i<variant.size();i++){
529                     if(variant[i] != face->font_variant[i]){
530                         face->font_variant = variant;
531 g_warning("<font-face>: SP_ATTR_FONT_VARIANT:");
532                         for (unsigned int i=0;i<variant.size();i++){
533                             g_warning("- %d", variant[i]);
534                         }
535                         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
536                         break;
537                     }
538                 }
539             }
540             break;
541         case SP_PROP_FONT_WEIGHT:
542             weight = sp_read_fontFaceWeightType(value);
543             if (face->font_weight.size() != weight.size()){
544                 face->font_weight = weight;
545 g_warning("<font-face>: SP_ATTR_FONT_WEIGHT:");
546                 for (unsigned int i=0;i<weight.size();i++){
547                     g_warning("enum value: %d", weight[i]);
548                 }
549                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
550             } else {
551                 for (unsigned int i=0;i<weight.size();i++){
552                     if(weight[i] != face->font_weight[i]){
553                         face->font_weight = weight;
554 g_warning("<font-face>: SP_ATTR_FONT_WEIGHT:");
555                         for (unsigned int i=0;i<weight.size();i++){
556                             g_warning("enum value: %d", weight[i]);
557                         }
558                         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
559                         break;
560                     }
561                 }
562             }
563             break;
564         case SP_PROP_FONT_STRETCH:
565             stretch = sp_read_fontFaceStretchType(value);
566             if (face->font_stretch.size() != stretch.size()){
567                 face->font_stretch = stretch;
568 g_warning("<font-face>: SP_ATTR_FONT_STRETCH:");
569                 for (unsigned int i=0;i<stretch.size();i++){
570                     g_warning("enum value: %d", stretch[i]);
571                 }
572                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
573             } else {
574                 for (unsigned int i=0;i<stretch.size();i++){
575                     if(stretch[i] != face->font_stretch[i]){
576                         face->font_stretch = stretch;
577 g_warning("<font-face>: SP_ATTR_FONT_STRETCH:");
578                         for (unsigned int i=0;i<stretch.size();i++){
579                             g_warning("enum value: %d", stretch[i]);
580                         }
581                         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
582                         break;
583                     }
584                 }
585             }
586             break;
587         case SP_ATTR_UNITS_PER_EM:
588             number = helperfns_read_number(value);
589             if (number != face->units_per_em){
590                 face->units_per_em = number;
591 g_warning("<font-face>: SP_ATTR_UNITS_PER_EM: %f", number);
592                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
593             }
594             break;
595         case SP_ATTR_STEMV:
596             number = helperfns_read_number(value);
597             if (number != face->stemv){
598                 face->stemv = number;
599 g_warning("<font-face>: SP_ATTR_STEMV: %f", number);
600                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
601             }
602             break;
603         case SP_ATTR_STEMH:
604             number = helperfns_read_number(value);
605             if (number != face->stemh){
606                 face->stemh = number;
607 g_warning("<font-face>: SP_ATTR_STEMH: %f", number);
608                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
609             }
610             break;
611         case SP_ATTR_SLOPE:
612             number = helperfns_read_number(value);
613             if (number != face->slope){
614                 face->slope = number;
615 g_warning("<font-face>: SP_ATTR_SLOPE: %f", number);
616                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
617             }
618             break;
619         case SP_ATTR_CAP_HEIGHT:
620             number = helperfns_read_number(value);
621             if (number != face->cap_height){
622                 face->cap_height = number;
623 g_warning("<font-face>: SP_ATTR_CAP_HEIGHT: %f", number);
624                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
625             }
626             break;
627         case SP_ATTR_X_HEIGHT:
628             number = helperfns_read_number(value);
629             if (number != face->x_height){
630                 face->x_height = number;
631 g_warning("<font-face>: SP_ATTR_X_HEIGHT: %f", number);
632                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
633             }
634             break;
635         case SP_ATTR_ACCENT_HEIGHT:
636             number = helperfns_read_number(value);
637             if (number != face->accent_height){
638                 face->accent_height = number;
639 g_warning("<font-face>: SP_ATTR_ACCENT_HEIGHT: %f", number);
640                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
641             }
642             break;
643         case SP_ATTR_ASCENT:
644             number = helperfns_read_number(value);
645             if (number != face->ascent){
646                 face->ascent = number;
647 g_warning("<font-face>: SP_ATTR_ASCENT: %f", number);
648                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
649             }
650             break;
651         case SP_ATTR_DESCENT:
652             number = helperfns_read_number(value);
653             if (number != face->descent){
654                 face->descent = number;
655 g_warning("<font-face>: SP_ATTR_DESCENT: %f", number);
656                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
657             }
658             break;
659         case SP_ATTR_IDEOGRAPHIC:
660             number = helperfns_read_number(value);
661             if (number != face->ideographic){
662                 face->ideographic = number;
663 g_warning("<font-face>: SP_ATTR_IDEOGRAPHIC: %f", number);
664                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
665             }
666             break;
667         case SP_ATTR_ALPHABETIC:
668             number = helperfns_read_number(value);
669             if (number != face->alphabetic){
670                 face->alphabetic = number;
671 g_warning("<font-face>: SP_ATTR_ALPHABETIC: %f", number);
672                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
673             }
674             break;
675         case SP_ATTR_MATHEMATICAL:
676             number = helperfns_read_number(value);
677             if (number != face->mathematical){
678                 face->mathematical = number;
679 g_warning("<font-face>: SP_ATTR_MATHEMATICAL: %f", number);
680                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
681             }
682             break;
683         case SP_ATTR_HANGING:
684             number = helperfns_read_number(value);
685             if (number != face->hanging){
686                 face->hanging = number;
687 g_warning("<font-face>: SP_ATTR_HANGING: %f", number);
688                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
689             }
690             break;
691         case SP_ATTR_V_IDEOGRAPHIC:
692             number = helperfns_read_number(value);
693             if (number != face->v_ideographic){
694                 face->v_ideographic = number;
695 g_warning("<font-face>: SP_ATTR_V_IDEOGRAPHIC: %f", number);
696                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
697             }
698             break;
699         case SP_ATTR_V_ALPHABETIC:
700             number = helperfns_read_number(value);
701             if (number != face->v_alphabetic){
702                 face->v_alphabetic = number;
703 g_warning("<font-face>: SP_ATTR_V_ALPHABETIC: %f", number);
704                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
705             }
706             break;
707         case SP_ATTR_V_MATHEMATICAL:
708             number = helperfns_read_number(value);
709             if (number != face->v_mathematical){
710                 face->v_mathematical = number;
711 g_warning("<font-face>: SP_ATTR_V_MATHEMATICAL: %f", number);
712                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
713             }
714             break;
715         case SP_ATTR_V_HANGING:
716             number = helperfns_read_number(value);
717             if (number != face->v_hanging){
718                 face->v_hanging = number;
719 g_warning("<font-face>: SP_ATTR_V_HANGING: %f", number);
720                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
721             }
722             break;
723         case SP_ATTR_UNDERLINE_POSITION:
724             number = helperfns_read_number(value);
725             if (number != face->underline_position){
726                 face->underline_position = number;
727 g_warning("<font-face>: SP_ATTR_UNDERLINE_POSITION: %f", number);
728                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
729             }
730             break;
731         case SP_ATTR_UNDERLINE_THICKNESS:
732             number = helperfns_read_number(value);
733             if (number != face->underline_thickness){
734                 face->underline_thickness = number;
735 g_warning("<font-face>: SP_ATTR_UNDERLINE_THICKNESS: %f", number);
736                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
737             }
738             break;
739         case SP_ATTR_STRIKETHROUGH_POSITION:
740             number = helperfns_read_number(value);
741             if (number != face->strikethrough_position){
742                 face->strikethrough_position = number;
743 g_warning("<font-face>: SP_ATTR_STRIKETHROUGH_POSITION: %f", number);
744                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
745             }
746             break;
747         case SP_ATTR_STRIKETHROUGH_THICKNESS:
748             number = helperfns_read_number(value);
749             if (number != face->strikethrough_thickness){
750                 face->strikethrough_thickness = number;
751 g_warning("<font-face>: SP_ATTR_STRIKETHROUGH_THICKNESS: %f", number);
752                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
753             }
754             break;
755         case SP_ATTR_OVERLINE_POSITION:
756             number = helperfns_read_number(value);
757             if (number != face->overline_position){
758                 face->overline_position = number;
759 g_warning("<font-face>: SP_ATTR_OVERLINE_POSITION: %f", number);
760                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
761             }
762             break;
763         case SP_ATTR_OVERLINE_THICKNESS:
764             number = helperfns_read_number(value);
765             if (number != face->overline_thickness){
766                 face->overline_thickness = number;
767 g_warning("<font-face>: SP_ATTR_OVERLINE_THICKNESS: %f", number);
768                 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
769             }
770             break;
771         default:
772             if (((SPObjectClass *) (parent_class))->set) {
773                 ((SPObjectClass *) (parent_class))->set(object, key, value);
774             }
775             break;
776     }
779 /**
780  * Receives update notifications.
781  */
782 static void
783 sp_fontface_update(SPObject *object, SPCtx *ctx, guint flags)
785     if (flags & (SP_OBJECT_MODIFIED_FLAG)) {
786         sp_object_read_attr(object, "font-family");
787         sp_object_read_attr(object, "font-style");
788         sp_object_read_attr(object, "font-variant");
789         sp_object_read_attr(object, "font-weight");
790         sp_object_read_attr(object, "font-stretch");
791         sp_object_read_attr(object, "font-size");
792         sp_object_read_attr(object, "unicode-range");
793         sp_object_read_attr(object, "units-per-em");
794         sp_object_read_attr(object, "panose-1");
795         sp_object_read_attr(object, "stemv");
796         sp_object_read_attr(object, "stemh");
797         sp_object_read_attr(object, "slope");
798         sp_object_read_attr(object, "cap-height");
799         sp_object_read_attr(object, "x-height");
800         sp_object_read_attr(object, "accent-height");
801         sp_object_read_attr(object, "ascent");
802         sp_object_read_attr(object, "descent");
803         sp_object_read_attr(object, "widths");
804         sp_object_read_attr(object, "bbox");
805         sp_object_read_attr(object, "ideographic");
806         sp_object_read_attr(object, "alphabetic");
807         sp_object_read_attr(object, "mathematical");
808         sp_object_read_attr(object, "hanging");
809         sp_object_read_attr(object, "v-ideographic");
810         sp_object_read_attr(object, "v-alphabetic");
811         sp_object_read_attr(object, "v-mathematical");
812         sp_object_read_attr(object, "v-hanging");
813         sp_object_read_attr(object, "underline-position");
814         sp_object_read_attr(object, "underline-thickness");
815         sp_object_read_attr(object, "strikethrough-position");
816         sp_object_read_attr(object, "strikethrough-thickness");
817         sp_object_read_attr(object, "overline-position");
818         sp_object_read_attr(object, "overline-thickness");
819     }
821     if (((SPObjectClass *) parent_class)->update) {
822         ((SPObjectClass *) parent_class)->update(object, ctx, flags);
823     }
826 #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
828 static Inkscape::XML::Node *sp_fontface_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
830     SPFontFace *face = SP_FONTFACE(object);
832     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
833         repr = xml_doc->createElement("svg:font-face");
834     }
836     //TODO:
837     //sp_repr_set_svg_double(repr, "font-family", face->font_family);
838     //sp_repr_set_svg_double(repr, "font-style", face->font_style);
839     //sp_repr_set_svg_double(repr, "font-variant", face->font_variant);
840     //sp_repr_set_svg_double(repr, "font-weight", face->font_weight);
841     //sp_repr_set_svg_double(repr, "font-stretch", face->font_stretch);
842     //sp_repr_set_svg_double(repr, "font-size", face->font_size);
843     //sp_repr_set_svg_double(repr, "unicode-range", face->unicode_range);
844     sp_repr_set_svg_double(repr, "units-per-em", face->units_per_em);
845     //sp_repr_set_svg_double(repr, "panose-1", face->panose_1);
846     sp_repr_set_svg_double(repr, "stemv", face->stemv);
847     sp_repr_set_svg_double(repr, "stemh", face->stemh);
848     sp_repr_set_svg_double(repr, "slope", face->slope);
849     sp_repr_set_svg_double(repr, "cap-height", face->cap_height);
850     sp_repr_set_svg_double(repr, "x-height", face->x_height);
851     sp_repr_set_svg_double(repr, "accent-height", face->accent_height);
852     sp_repr_set_svg_double(repr, "ascent", face->ascent);
853     sp_repr_set_svg_double(repr, "descent", face->descent);
854     //sp_repr_set_svg_double(repr, "widths", face->widths);
855     //sp_repr_set_svg_double(repr, "bbox", face->bbox);
856     sp_repr_set_svg_double(repr, "ideographic", face->ideographic);
857     sp_repr_set_svg_double(repr, "alphabetic", face->alphabetic);
858     sp_repr_set_svg_double(repr, "mathematical", face->mathematical);
859     sp_repr_set_svg_double(repr, "hanging", face->hanging);
860     sp_repr_set_svg_double(repr, "v-ideographic", face->v_ideographic);
861     sp_repr_set_svg_double(repr, "v-alphabetic", face->v_alphabetic);
862     sp_repr_set_svg_double(repr, "v-mathematical", face->v_mathematical);
863     sp_repr_set_svg_double(repr, "v-hanging", face->v_hanging);
864     sp_repr_set_svg_double(repr, "underline-position", face->underline_position);
865     sp_repr_set_svg_double(repr, "underline-thickness", face->underline_thickness);
866     sp_repr_set_svg_double(repr, "strikethrough-position", face->strikethrough_position);
867     sp_repr_set_svg_double(repr, "strikethrough-thickness", face->strikethrough_thickness);
868     sp_repr_set_svg_double(repr, "overline-position", face->overline_position);
869     sp_repr_set_svg_double(repr, "overline-thickness", face->overline_thickness);
871     if (repr != SP_OBJECT_REPR(object)) {
872         COPY_ATTR(repr, object->repr, "font-family");
873         COPY_ATTR(repr, object->repr, "font-style");
874         COPY_ATTR(repr, object->repr, "font-variant");
875         COPY_ATTR(repr, object->repr, "font-weight");
876         COPY_ATTR(repr, object->repr, "font-stretch");
877         COPY_ATTR(repr, object->repr, "font-size");
878         COPY_ATTR(repr, object->repr, "unicode-range");
879         COPY_ATTR(repr, object->repr, "units-per-em");
880         COPY_ATTR(repr, object->repr, "panose-1");
881         COPY_ATTR(repr, object->repr, "stemv");
882         COPY_ATTR(repr, object->repr, "stemh");
883         COPY_ATTR(repr, object->repr, "slope");
884         COPY_ATTR(repr, object->repr, "cap-height");
885         COPY_ATTR(repr, object->repr, "x-height");
886         COPY_ATTR(repr, object->repr, "accent-height");
887         COPY_ATTR(repr, object->repr, "ascent");
888         COPY_ATTR(repr, object->repr, "descent");
889         COPY_ATTR(repr, object->repr, "widths");
890         COPY_ATTR(repr, object->repr, "bbox");
891         COPY_ATTR(repr, object->repr, "ideographic");
892         COPY_ATTR(repr, object->repr, "alphabetic");
893         COPY_ATTR(repr, object->repr, "mathematical");
894         COPY_ATTR(repr, object->repr, "hanging");
895         COPY_ATTR(repr, object->repr, "v-ideographic");
896         COPY_ATTR(repr, object->repr, "v-alphabetic");
897         COPY_ATTR(repr, object->repr, "v-mathematical");
898         COPY_ATTR(repr, object->repr, "v-hanging");
899         COPY_ATTR(repr, object->repr, "underline-position");
900         COPY_ATTR(repr, object->repr, "underline-thickness");
901         COPY_ATTR(repr, object->repr, "strikethrough-position");
902         COPY_ATTR(repr, object->repr, "strikethrough-thickness");
903         COPY_ATTR(repr, object->repr, "overline-position");
904         COPY_ATTR(repr, object->repr, "overline-thickness");
905     }
907     if (((SPObjectClass *) (parent_class))->write) {
908         ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
909     }
911     return repr;
913 #endif //#ifdef ENABLE_SVG_FONTS
914 /*
915   Local Variables:
916   mode:c++
917   c-file-style:"stroustrup"
918   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
919   indent-tabs-mode:nil
920   fill-column:99
921   End:
922 */
923 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :