diff options
Diffstat (limited to 'src/sp-glyph-kerning.cpp')
| -rw-r--r-- | src/sp-glyph-kerning.cpp | 266 |
1 files changed, 95 insertions, 171 deletions
diff --git a/src/sp-glyph-kerning.cpp b/src/sp-glyph-kerning.cpp index 10884fb81..be47c7621 100644 --- a/src/sp-glyph-kerning.cpp +++ b/src/sp-glyph-kerning.cpp @@ -25,182 +25,118 @@ #include <string> #include <cstring> -static void sp_glyph_kerning_class_init(SPGlyphKerningClass *gc); -static void sp_glyph_kerning_init(SPGlyphKerning *glyph); -static void sp_glyph_kerning_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -static void sp_glyph_kerning_release(SPObject *object); -static void sp_glyph_kerning_set(SPObject *object, unsigned int key, const gchar *value); -static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static void sp_glyph_kerning_update(SPObject *object, SPCtx *ctx, guint flags); - -static SPObjectClass *parent_class; - -GType sp_glyph_kerning_h_get_type(void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof(SPGlyphKerningClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_glyph_kerning_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(SPHkern), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_glyph_kerning_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_OBJECT, "SPHkern", &info, (GTypeFlags) 0); - } - - return type; +SPGlyphKerning::SPGlyphKerning() : SPObject() { +//TODO: correct these values: + this->u1 = NULL; + this->g1 = NULL; + this->u2 = NULL; + this->g2 = NULL; + this->k = 0; } -GType sp_glyph_kerning_v_get_type(void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof(SPGlyphKerningClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_glyph_kerning_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(SPVkern), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_glyph_kerning_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_OBJECT, "SPVkern", &info, (GTypeFlags) 0); - } - - return type; +SPGlyphKerning::~SPGlyphKerning() { } -static void sp_glyph_kerning_class_init(SPGlyphKerningClass *gc) -{ - SPObjectClass *sp_object_class = (SPObjectClass *) gc; +void SPGlyphKerning::build(SPDocument *document, Inkscape::XML::Node *repr) { + SPObject::build(document, repr); - parent_class = (SPObjectClass*)g_type_class_peek_parent(gc); - - sp_object_class->build = sp_glyph_kerning_build; - sp_object_class->release = sp_glyph_kerning_release; - sp_object_class->set = sp_glyph_kerning_set; - sp_object_class->write = sp_glyph_kerning_write; - sp_object_class->update = sp_glyph_kerning_update; + this->readAttr( "u1" ); + this->readAttr( "g1" ); + this->readAttr( "u2" ); + this->readAttr( "g2" ); + this->readAttr( "k" ); } -static void sp_glyph_kerning_init(SPGlyphKerning *glyph) -{ -//TODO: correct these values: - glyph->u1 = NULL; - glyph->g1 = NULL; - glyph->u2 = NULL; - glyph->g2 = NULL; - glyph->k = 0; -} - -static void sp_glyph_kerning_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) (parent_class))->build) { - ((SPObjectClass *) (parent_class))->build(object, document, repr); - } - - object->readAttr( "u1" ); - object->readAttr( "g1" ); - object->readAttr( "u2" ); - object->readAttr( "g2" ); - object->readAttr( "k" ); -} - -static void sp_glyph_kerning_release(SPObject *object) -{ - //SPGlyphKerning *glyph = SP_GLYPH_KERNING(object); - - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); - } +void SPGlyphKerning::release() { + SPObject::release(); } GlyphNames::GlyphNames(const gchar* value){ - if (value) this->names = strdup(value); + if (value) { + this->names = strdup(value); + } } GlyphNames::~GlyphNames(){ - if (this->names) g_free(this->names); + if (this->names) { + g_free(this->names); + } } bool GlyphNames::contains(const char* name){ - if (!(this->names) || !name) return false; + if (!(this->names) || !name) { + return false; + } + std::istringstream is(this->names); std::string str; std::string s(name); - while (is >> str){ - if (str == s) return true; + + while (is >> str) { + if (str == s) { + return true; + } } + return false; } -static void sp_glyph_kerning_set(SPObject *object, unsigned int key, const gchar *value) -{ - SPGlyphKerning * glyphkern = (SPGlyphKerning*) object; //even if it is a VKern this will work. I did it this way just to avoind warnings. - +void SPGlyphKerning::set(unsigned int key, const gchar *value) { switch (key) { case SP_ATTR_U1: { - if (glyphkern->u1) { - delete glyphkern->u1; + if (this->u1) { + delete this->u1; } - glyphkern->u1 = new UnicodeRange(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + this->u1 = new UnicodeRange(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; } case SP_ATTR_U2: { - if (glyphkern->u2) { - delete glyphkern->u2; + if (this->u2) { + delete this->u2; } - glyphkern->u2 = new UnicodeRange(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + this->u2 = new UnicodeRange(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; } case SP_ATTR_G1: { - if (glyphkern->g1) { - delete glyphkern->g1; + if (this->g1) { + delete this->g1; } - glyphkern->g1 = new GlyphNames(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + this->g1 = new GlyphNames(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; } case SP_ATTR_G2: { - if (glyphkern->g2) { - delete glyphkern->g2; + if (this->g2) { + delete this->g2; } - glyphkern->g2 = new GlyphNames(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + this->g2 = new GlyphNames(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; } case SP_ATTR_K: { double number = value ? g_ascii_strtod(value, 0) : 0; - if (number != glyphkern->k){ - glyphkern->k = number; - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + if (number != this->k){ + this->k = number; + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; } default: { - if (((SPObjectClass *) (parent_class))->set) { - ((SPObjectClass *) (parent_class))->set(object, key, value); - } + SPObject::set(key, value); break; } } @@ -209,62 +145,50 @@ static void sp_glyph_kerning_set(SPObject *object, unsigned int key, const gchar /** * * Receives update notifications. * */ -static void -sp_glyph_kerning_update(SPObject *object, SPCtx *ctx, guint flags) -{ - SPGlyphKerning *glyph = (SPGlyphKerning *)object; - (void)glyph; - +void SPGlyphKerning::update(SPCtx *ctx, guint flags) { if (flags & SP_OBJECT_MODIFIED_FLAG) { /* do something to trigger redisplay, updates? */ - object->readAttr( "u1" ); - object->readAttr( "u2" ); - object->readAttr( "g2" ); - object->readAttr( "k" ); + this->readAttr( "u1" ); + this->readAttr( "u2" ); + this->readAttr( "g2" ); + this->readAttr( "k" ); } - if (((SPObjectClass *) parent_class)->update) { - ((SPObjectClass *) parent_class)->update(object, ctx, flags); - } + SPObject::update(ctx, flags); } #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key)); -static Inkscape::XML::Node *sp_glyph_kerning_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ -// SPGlyphKerning *glyph = SP_GLYPH_KERNING(object); - - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:glyphkerning");//fix this! - } - -/* 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); - 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 != object->getRepr()) { - // All the COPY_ATTR functions below use - // XML Tree directly, while they shouldn't. - COPY_ATTR(repr, object->getRepr(), "u1"); - COPY_ATTR(repr, object->getRepr(), "g1"); - COPY_ATTR(repr, object->getRepr(), "u2"); - COPY_ATTR(repr, object->getRepr(), "g2"); - COPY_ATTR(repr, object->getRepr(), "k"); - } - - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); - } - - return repr; +Inkscape::XML::Node* SPGlyphKerning::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + repr = xml_doc->createElement("svg:glyphkerning");//fix this! + } + + /* 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); + 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 != this->getRepr()) { + // All the COPY_ATTR functions below use + // XML Tree directly, while they shouldn't. + COPY_ATTR(repr, this->getRepr(), "u1"); + COPY_ATTR(repr, this->getRepr(), "g1"); + COPY_ATTR(repr, this->getRepr(), "u2"); + COPY_ATTR(repr, this->getRepr(), "g2"); + COPY_ATTR(repr, this->getRepr(), "k"); + } + + SPObject::write(xml_doc, repr, flags); + + return repr; } /* Local Variables: |
