From: JucaBlues Date: Wed, 27 Feb 2008 05:19:40 +0000 (+0000) Subject: more boilerplate code for SVGFonts X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8e11761ae0d26229b185953da0b2f5dcd6524773;p=inkscape.git more boilerplate code for SVGFonts node parameter loading --- diff --git a/src/Makefile_insert b/src/Makefile_insert index 201f8aaf2..10b5efe42 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -206,6 +206,7 @@ libinkpre_a_SOURCES = \ sp-flowregion.h sp-flowregion.cpp \ sp-flowtext.h sp-flowtext.cpp \ sp-font.cpp sp-font.h \ + sp-glyph.cpp sp-glyph.h \ sp-gaussian-blur.cpp sp-gaussian-blur.h \ sp-gaussian-blur-fns.h \ sp-gradient-fns.h \ diff --git a/src/sp-glyph.cpp b/src/sp-glyph.cpp index 0bbe14674..eab219f51 100644 --- a/src/sp-glyph.cpp +++ b/src/sp-glyph.cpp @@ -16,7 +16,7 @@ #include "sp-glyph.h" #include "document.h" -static void sp_glyph_class_init(SPGlyphClass *fc); +static void sp_glyph_class_init(SPGlyphClass *gc); static void sp_glyph_init(SPGlyph *glyph); static void sp_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); @@ -64,16 +64,16 @@ static void sp_glyph_class_init(SPGlyphClass *gc) static void sp_glyph_init(SPGlyph *glyph) { //TODO: correct these values: - glyph->unicode = ""; - glyph->glyph-name = ""; - glyph->d = ""; - glyph->orientation = ""; - glyph->arabic-form = ""; - glyph->lang = ""; - glyph->horiz-adv-x = 0; - glyph->vert-origin-x = 0; - glyph->vert-origin-y = 0; - glyph->vert-adv-y = 0; + glyph->unicode = NULL; + glyph->glyph_name = NULL; + glyph->d = NULL; + glyph->orientation = NULL; + glyph->arabic_form = NULL; + glyph->lang = NULL; + glyph->horiz_adv_x = 0; + glyph->vert_origin_x = 0; + glyph->vert_origin_y = 0; + glyph->vert_adv_y = 0; } static void sp_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) @@ -123,21 +123,41 @@ static void sp_glyph_set(SPObject *object, unsigned int key, const gchar *value) double number; switch (key) { - case SP_ATTR_HORIZ_ORIGIN_X: - number = helperfns_read_number(value); - if (number != glyph->horiz_origin_x){ - glyph->horiz_origin_x = number; -g_warning("SP_ATTR_HORIZ_ORIGIN_X: %f", number); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - } + case SP_ATTR_UNICODE: + if (glyph->unicode) g_free(glyph->unicode); + glyph->unicode = g_strdup(value); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); +g_warning("SP_ATTR_UNICODE: %s", value); + break; + case SP_ATTR_GLYPH_NAME: + if (glyph->glyph_name) g_free(glyph->glyph_name); + glyph->glyph_name = g_strdup(value); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); +g_warning("SP_ATTR_GLYPH_NAME: %s", value); + 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_HORIZ_ORIGIN_Y: - number = helperfns_read_number(value); - if (number != glyph->horiz_origin_y){ - glyph->horiz_origin_y = number; -g_warning("SP_ATTR_HORIZ_ORIGIN_Y: %f", number); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - } + 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); + 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); + 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); @@ -190,16 +210,24 @@ static Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Node repr = xml_doc->createElement("svg:glyph"); } - sp_repr_set_svg_double(repr, "horiz-origin-x", glyph->horiz_origin_x); - sp_repr_set_svg_double(repr, "horiz-origin-y", glyph->horiz_origin_y); + 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); + 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, "horiz-origin-x"); - COPY_ATTR(repr, object->repr, "horiz-origin-y"); + COPY_ATTR(repr, object->repr, "unicode"); + COPY_ATTR(repr, object->repr, "glyph-name"); + COPY_ATTR(repr, object->repr, "d"); + COPY_ATTR(repr, object->repr, "orientation"); + COPY_ATTR(repr, object->repr, "arabic-form"); + COPY_ATTR(repr, object->repr, "lang"); COPY_ATTR(repr, object->repr, "horiz-adv-x"); COPY_ATTR(repr, object->repr, "vert-origin-x"); COPY_ATTR(repr, object->repr, "vert-origin-y"); diff --git a/src/sp-glyph.h b/src/sp-glyph.h new file mode 100644 index 000000000..dcbe5c7d4 --- /dev/null +++ b/src/sp-glyph.h @@ -0,0 +1,42 @@ +#ifndef __SP_GLYPH_H__ +#define __SP_GLYPH_H__ + +/* + * SVG element implementation + * + * Authors: + * Felipe C. da S. Sanches + * + * Copyright (C) 2008 Felipe C. da S. Sanches + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "sp-object.h" + +#define SP_TYPE_GLYPH (sp_glyph_get_type ()) +#define SP_GLYPH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_GLYPH, SPGlyph)) +#define SP_GLYPH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_GLYPH, SPGlyphClass)) +#define SP_IS_GLYPH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_GLYPH)) +#define SP_IS_GLYPH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_GLYPH)) + +struct SPGlyph : public SPObject { + char* unicode; + char* glyph_name; + char* d; + char* orientation; + char* arabic_form; + char* lang; + double horiz_adv_x; + double vert_origin_x; + double vert_origin_y; + double vert_adv_y; +}; + +struct SPGlyphClass { + SPObjectClass parent_class; +}; + +GType sp_glyph_get_type (void); + +#endif //#ifndef __SP_GLYPH_H__ diff --git a/src/sp-object-repr.cpp b/src/sp-object-repr.cpp index 577ff1690..5a49c35aa 100644 --- a/src/sp-object-repr.cpp +++ b/src/sp-object-repr.cpp @@ -44,6 +44,7 @@ #include "sp-flowregion.h" #include "sp-flowtext.h" #include "sp-font.h" +#include "sp-glyph.h" #include "sp-style-elem.h" #include "sp-switch.h" #include "color-profile-fns.h" @@ -141,6 +142,7 @@ populate_dtables() { "svg:flowRoot", SP_TYPE_FLOWTEXT }, { "svg:flowSpan", SP_TYPE_FLOWTSPAN }, { "svg:font", SP_TYPE_FONT }, + { "svg:glyph", SP_TYPE_GLYPH }, { "svg:g", SP_TYPE_GROUP }, { "svg:feBlend", SP_TYPE_FEBLEND }, { "svg:feColorMatrix", SP_TYPE_FECOLORMATRIX },