X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fsp-glyph.cpp;h=8af78a0aaf55111113cd1f056e2a98ac5036b454;hb=78e23de1b966743b030c38b1c654768736bae72b;hp=eab219f51bfd4313731a98dbf32a6a028c6c79ad;hpb=8e11761ae0d26229b185953da0b2f5dcd6524773;p=inkscape.git diff --git a/src/sp-glyph.cpp b/src/sp-glyph.cpp index eab219f51..8af78a0aa 100644 --- a/src/sp-glyph.cpp +++ b/src/sp-glyph.cpp @@ -1,4 +1,9 @@ -#define __SP_ANCHOR_C__ +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef ENABLE_SVG_FONTS +#define __SP_GLYPH_C__ /* * SVG element implementation @@ -15,6 +20,7 @@ #include "attributes.h" #include "sp-glyph.h" #include "document.h" +#include "helper-fns.h" static void sp_glyph_class_init(SPGlyphClass *gc); static void sp_glyph_init(SPGlyph *glyph); @@ -22,7 +28,8 @@ static void sp_glyph_init(SPGlyph *glyph); static void sp_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); 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 Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); +static void sp_glyph_update(SPObject *object, SPCtx *ctx, guint flags); static SPObjectClass *parent_class; @@ -53,22 +60,24 @@ 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) { //TODO: correct these values: - glyph->unicode = NULL; - glyph->glyph_name = NULL; + + new (&glyph->unicode) Glib::ustring(); + new (&glyph->glyph_name) Glib::ustring(); glyph->d = NULL; - glyph->orientation = NULL; - glyph->arabic_form = NULL; + glyph->orientation = GLYPH_ORIENTATION_BOTH; + glyph->arabic_form = GLYPH_ARABIC_FORM_INITIAL; glyph->lang = NULL; glyph->horiz_adv_x = 0; glyph->vert_origin_x = 0; @@ -103,67 +112,83 @@ static void sp_glyph_release(SPObject *object) } } -//ToDo: use helper-fns.h -inline double helperfns_read_number(gchar const *value) { - if (!value) return 0; - char *end; - double ret = g_ascii_strtod(value, &end); - if (*end) { - g_warning("Unable to convert \"%s\" to number", value); - // We could leave this out, too. If strtod can't convert - // anything, it will return zero. - ret = 0; +static glyphArabicForm sp_glyph_read_arabic_form(gchar const *value){ + if (!value) return GLYPH_ARABIC_FORM_INITIAL; //TODO: verify which is the default default (for me, the spec is not clear) + switch(value[0]){ + case 'i': + if (strncmp(value, "initial", 7) == 0) return GLYPH_ARABIC_FORM_INITIAL; + if (strncmp(value, "isolated", 8) == 0) return GLYPH_ARABIC_FORM_ISOLATED; + break; + case 'm': + if (strncmp(value, "medial", 6) == 0) return GLYPH_ARABIC_FORM_MEDIAL; + break; + case 't': + if (strncmp(value, "terminal", 8) == 0) return GLYPH_ARABIC_FORM_TERMINAL; + break; } - return ret; + return GLYPH_ARABIC_FORM_INITIAL; //TODO: VERIFY DEFAULT! +} + +static glyphOrientation sp_glyph_read_orientation(gchar const *value){ + if (!value) return GLYPH_ORIENTATION_BOTH; + switch(value[0]){ + case 'h': + return GLYPH_ORIENTATION_HORIZONTAL; + break; + case 'v': + return GLYPH_ORIENTATION_VERTICAL; + break; + } +//ERROR? TODO: VERIFY PROPER ERROR HANDLING + return GLYPH_ORIENTATION_BOTH; } static void sp_glyph_set(SPObject *object, unsigned int key, const gchar *value) { SPGlyph *glyph = SP_GLYPH(object); double number; + glyphOrientation orient; + glyphArabicForm form; switch (key) { case SP_ATTR_UNICODE: - if (glyph->unicode) g_free(glyph->unicode); - glyph->unicode = g_strdup(value); + glyph->unicode.clear(); + if (value) glyph->unicode.append(value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); -g_warning("SP_ATTR_UNICODE: %s", value); - break; + break; case SP_ATTR_GLYPH_NAME: - if (glyph->glyph_name) g_free(glyph->glyph_name); - glyph->glyph_name = g_strdup(value); + glyph->glyph_name.clear(); + if (value) glyph->glyph_name.append(value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); -g_warning("SP_ATTR_GLYPH_NAME: %s", value); - break; + break; case SP_ATTR_D: if (glyph->d) g_free(glyph->d); glyph->d = g_strdup(value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); -g_warning("SP_ATTR_D: %s", value); break; case SP_ATTR_ORIENTATION: - if (glyph->orientation) g_free(glyph->orientation); - glyph->orientation = g_strdup(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); -g_warning("SP_ATTR_ORIENTATION: %s", value); + orient = sp_glyph_read_orientation(value); + if (glyph->orientation != orient){ + glyph->orientation = orient; + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + } break; case SP_ATTR_ARABIC_FORM: - if (glyph->arabic_form) g_free(glyph->arabic_form); - glyph->arabic_form = g_strdup(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); -g_warning("SP_ATTR_ARABIC_FORM: %s", value); + form = sp_glyph_read_arabic_form(value); + if (glyph->arabic_form != form){ + glyph->arabic_form = form; + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + } break; case SP_ATTR_LANG: if (glyph->lang) g_free(glyph->lang); glyph->lang = g_strdup(value); -g_warning("SP_ATTR_LANG: %s", value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_HORIZ_ADV_X: number = helperfns_read_number(value); if (number != glyph->horiz_adv_x){ glyph->horiz_adv_x = number; -g_warning("SP_ATTR_HORIZ_ADV_X: %f", number); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; @@ -171,7 +196,6 @@ g_warning("SP_ATTR_HORIZ_ADV_X: %f", number); number = helperfns_read_number(value); if (number != glyph->vert_origin_x){ glyph->vert_origin_x = number; -g_warning("SP_ATTR_VERT_ORIGIN_X: %f", number); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; @@ -179,7 +203,6 @@ g_warning("SP_ATTR_VERT_ORIGIN_X: %f", number); number = helperfns_read_number(value); if (number != glyph->vert_origin_y){ glyph->vert_origin_y = number; -g_warning("SP_ATTR_VERT_ORIGIN_Y: %f", number); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; @@ -187,7 +210,6 @@ g_warning("SP_ATTR_VERT_ORIGIN_Y: %f", number); number = helperfns_read_number(value); if (number != glyph->vert_adv_y){ glyph->vert_adv_y = number; -g_warning("SP_ATTR_VERT_ADV_Y: %f", number); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; @@ -199,28 +221,56 @@ 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) +static Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPGlyph *glyph = SP_GLYPH(object); +// SPGlyph *glyph = SP_GLYPH(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); repr = xml_doc->createElement("svg:glyph"); } +/* I am commenting out this part because I am not certain how does it work. I will have to study it later. Juca repr->setAttribute("unicode", glyph->unicode); repr->setAttribute("glyph-name", glyph->glyph_name); repr->setAttribute("d", glyph->d); - repr->setAttribute("orientation", glyph->orientation); - repr->setAttribute("arabic-form", glyph->arabic_form); + sp_repr_set_svg_double(repr, "orientation", (double) glyph->orientation); + sp_repr_set_svg_double(repr, "arabic-form", (double) glyph->arabic_form); repr->setAttribute("lang", glyph->lang); sp_repr_set_svg_double(repr, "horiz-adv-x", glyph->horiz_adv_x); sp_repr_set_svg_double(repr, "vert-origin-x", glyph->vert_origin_x); sp_repr_set_svg_double(repr, "vert-origin-y", glyph->vert_origin_y); sp_repr_set_svg_double(repr, "vert-adv-y", glyph->vert_adv_y); - +*/ if (repr != SP_OBJECT_REPR(object)) { COPY_ATTR(repr, object->repr, "unicode"); COPY_ATTR(repr, object->repr, "glyph-name"); @@ -235,12 +285,12 @@ static Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Node } if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, repr, flags); + ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); } return repr; } - +#endif //#ifdef ENABLE_SVG_FONTS /* Local Variables: mode:c++