From: JucaBlues Date: Thu, 28 Feb 2008 15:54:34 +0000 (+0000) Subject: more boilerplate code for SVGFonts X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4175317af9dd8f619d5427af3b1887319b886df7;p=inkscape.git more boilerplate code for SVGFonts --- diff --git a/src/sp-font.cpp b/src/sp-font.cpp index b96b37858..82bc1978c 100644 --- a/src/sp-font.cpp +++ b/src/sp-font.cpp @@ -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 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 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(": 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) diff --git a/src/sp-glyph.cpp b/src/sp-glyph.cpp index cbddb2192..b0dd06b32 100644 --- a/src/sp-glyph.cpp +++ b/src/sp-glyph.cpp @@ -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(": 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) diff --git a/src/sp-missing-glyph.cpp b/src/sp-missing-glyph.cpp index 4f3329b7c..02a94176c 100644 --- a/src/sp-missing-glyph.cpp +++ b/src/sp-missing-glyph.cpp @@ -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;