Code

more boilerplate code for SVGFonts
authorJucaBlues <JucaBlues@users.sourceforge.net>
Thu, 28 Feb 2008 15:54:34 +0000 (15:54 +0000)
committerJucaBlues <JucaBlues@users.sourceforge.net>
Thu, 28 Feb 2008 15:54:34 +0000 (15:54 +0000)
src/sp-font.cpp
src/sp-glyph.cpp
src/sp-missing-glyph.cpp

index b96b3785863cdd55a59cc12ef81d940dbda75615..82bc1978c9830dc7ce3a7f53c91918eb25cf53ff 100644 (file)
@@ -14,6 +14,8 @@
 #include "xml/repr.h"
 #include "attributes.h"
 #include "sp-font.h"
+#include "sp-glyph.h"
+#include "sp-missing-glyph.h"
 #include "document.h"
 #include "helper-fns.h"
 
@@ -25,6 +27,10 @@ static void sp_font_release(SPObject *object);
 static void sp_font_set(SPObject *object, unsigned int key, const gchar *value);
 static Inkscape::XML::Node *sp_font_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
 
+static void sp_font_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
+static void sp_font_remove_child(SPObject *object, Inkscape::XML::Node *child);
+static void sp_font_update(SPObject *object, SPCtx *ctx, guint flags);
+
 // static gchar *sp_font_description(SPItem *item);
 
 static SPObjectClass *parent_class;
@@ -62,6 +68,9 @@ static void sp_font_class_init(SPFontClass *fc)
     sp_object_class->release = sp_font_release;
     sp_object_class->set = sp_font_set;
     sp_object_class->write = sp_font_write;
+    sp_object_class->child_added = sp_font_child_added;
+    sp_object_class->remove_child = sp_font_remove_child;
+    sp_object_class->update = sp_font_update;
 }
 
 static void sp_font_init(SPFont *font)
@@ -89,6 +98,54 @@ static void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML:
     sp_object_read_attr(object, "vert-adv-y");
 }
 
+
+static void sp_font_children_modified(SPFont *sp_font)
+{
+    SPObject* node = sp_font->children;
+    for(;node;node=node->next){
+        if (SP_IS_GLYPH(node)){
+            g_warning("We have a <glyph> childnode:\n\td=%s\n\tvert-origin-x=%f\n\tvert-origin-y=%f\n\tvert-adv-y=%f", ((SPGlyph*)node)->d, ((SPGlyph*)node)->vert_origin_x, ((SPGlyph*)node)->vert_origin_y, ((SPGlyph*)node)->vert_adv_y );
+            
+        }
+        if (SP_IS_MISSING_GLYPH(node)){
+g_warning("We have a <missing-glyph> childnode:\n\td=%s\n\thoriz-origin-x=%f\n\thoriz-origin-y=%f\n\thoriz-adv-x=%f", ((SPMissingGlyph*)node)->d, ((SPMissingGlyph*)node)->vert_origin_x, ((SPMissingGlyph*)node)->vert_origin_y, ((SPMissingGlyph*)node)->vert_adv_y );
+        }
+//        if (SP_IS_FONT_FACE_SRC(node)){
+//        }
+    }
+}
+
+/**
+ * Callback for child_added event.
+ */
+static void
+sp_font_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
+{
+    SPFont *f = SP_FONT(object);
+
+    if (((SPObjectClass *) parent_class)->child_added)
+        (* ((SPObjectClass *) parent_class)->child_added)(object, child, ref);
+
+    sp_font_children_modified(f);
+    object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+}
+
+
+/**
+ * Callback for remove_child event.
+ */
+static void
+sp_font_remove_child(SPObject *object, Inkscape::XML::Node *child)
+{
+    SPFont *f = SP_FONT(object);
+
+    if (((SPObjectClass *) parent_class)->remove_child)
+        (* ((SPObjectClass *) parent_class)->remove_child)(object, child);
+
+    sp_font_children_modified(f);
+    object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+}
+
 static void sp_font_release(SPObject *object)
 {
     //SPFont *font = SP_FONT(object);
@@ -160,6 +217,26 @@ g_warning("<font>: SP_ATTR_VERT_ADV_Y: %f", number);
     }
 }
 
+/**
+ * Receives update notifications.
+ */
+static void
+sp_font_update(SPObject *object, SPCtx *ctx, guint flags)
+{
+    if (flags & (SP_OBJECT_MODIFIED_FLAG)) {
+        sp_object_read_attr(object, "horiz-origin-x");
+        sp_object_read_attr(object, "horiz-origin-y");
+        sp_object_read_attr(object, "horiz-adv-x");
+        sp_object_read_attr(object, "vert-origin-x");
+        sp_object_read_attr(object, "vert-origin-y");
+        sp_object_read_attr(object, "vert-adv-y");
+    }
+
+    if (((SPObjectClass *) parent_class)->update) {
+        ((SPObjectClass *) parent_class)->update(object, ctx, flags);
+    }
+}
+
 #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
 
 static Inkscape::XML::Node *sp_font_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
index cbddb2192454be8fd0b550466e903c1e1272f3d7..b0dd06b32c46d4c24be6082c122df64516b41362 100644 (file)
@@ -24,6 +24,7 @@ static void sp_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML
 static void sp_glyph_release(SPObject *object);
 static void sp_glyph_set(SPObject *object, unsigned int key, const gchar *value);
 static Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
+static void sp_glyph_update(SPObject *object, SPCtx *ctx, guint flags);
 
 static SPObjectClass *parent_class;
 
@@ -54,12 +55,13 @@ static void sp_glyph_class_init(SPGlyphClass *gc)
 {
     SPObjectClass *sp_object_class = (SPObjectClass *) gc;
 
-    parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
+    parent_class = (SPObjectClass*)g_type_class_peek_parent(gc);
 
     sp_object_class->build = sp_glyph_build;
     sp_object_class->release = sp_glyph_release;
     sp_object_class->set = sp_glyph_set;
     sp_object_class->write = sp_glyph_write;
+    sp_object_class->update = sp_glyph_update;
 }
 
 static void sp_glyph_init(SPGlyph *glyph)
@@ -223,6 +225,34 @@ g_warning("<glyph>: SP_ATTR_VERT_ADV_Y: %f", number);
     }
 }
 
+/**
+ *  * Receives update notifications.
+ *   */
+static void
+sp_glyph_update(SPObject *object, SPCtx *ctx, guint flags)
+{
+    SPGlyph *glyph = SP_GLYPH(object);
+    (void)glyph;
+
+    if (flags & SP_OBJECT_MODIFIED_FLAG) {
+        /* do something to trigger redisplay, updates? */
+            sp_object_read_attr(object, "unicode");
+            sp_object_read_attr(object, "glyph-name");
+            sp_object_read_attr(object, "d");
+            sp_object_read_attr(object, "orientation");
+            sp_object_read_attr(object, "arabic-form");
+            sp_object_read_attr(object, "lang");
+            sp_object_read_attr(object, "horiz-adv-x");
+            sp_object_read_attr(object, "vert-origin-x");
+            sp_object_read_attr(object, "vert-origin-y");
+            sp_object_read_attr(object, "vert-adv-y");
+    }
+
+    if (((SPObjectClass *) parent_class)->update) {
+        ((SPObjectClass *) parent_class)->update(object, ctx, flags);
+    }
+}
+
 #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
 
 static Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
index 4f3329b7cf56e58af0a58d539aa864321e322859..02a94176ce96f4cb0a7e20259ee4129886a74012 100644 (file)
@@ -54,7 +54,7 @@ static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc)
 {
     SPObjectClass *sp_object_class = (SPObjectClass *) gc;
 
-    parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
+    parent_class = (SPObjectClass*)g_type_class_peek_parent(gc);
 
     sp_object_class->build = sp_missing_glyph_build;
     sp_object_class->release = sp_missing_glyph_release;