diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
| commit | 5a4fb2325f60d292b47330f540b26a3279341c90 (patch) | |
| tree | d2aa7967be25450b83e625025366c618101ae49f /src/sp-font.cpp | |
| parent | The Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff) | |
| parent | Remove Snap menu item and improve grid menu item text (diff) | |
| download | inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip | |
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/sp-font.cpp')
| -rw-r--r-- | src/sp-font.cpp | 241 |
1 files changed, 82 insertions, 159 deletions
diff --git a/src/sp-font.cpp b/src/sp-font.cpp index 852e6ba5d..62cf521d3 100644 --- a/src/sp-font.cpp +++ b/src/sp-font.cpp @@ -2,8 +2,6 @@ # include <config.h> #endif -#ifdef ENABLE_SVG_FONTS - /* * SVG <font> element implementation * @@ -25,58 +23,14 @@ #include "display/nr-svgfonts.h" -static void sp_font_class_init(SPFontClass *fc); -static void sp_font_init(SPFont *font); - -static void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -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::Document *doc, 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; - -GType sp_font_get_type(void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof(SPFontClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_font_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(SPFont), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_font_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_OBJECT, "SPFont", &info, (GTypeFlags) 0); - } - - return type; -} - -static void sp_font_class_init(SPFontClass *fc) -{ - SPObjectClass *sp_object_class = (SPObjectClass *) fc; +#include "sp-factory.h" - parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT); +namespace { + SPObject* createFont() { + return new SPFont(); + } - sp_object_class->build = sp_font_build; - 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; + bool fontRegistered = SPFactory::instance().registerObject("svg:font", createFont); } //I think we should have extra stuff here and in the set method in order to set default value as specified at http://www.w3.org/TR/SVG/fonts.html @@ -86,142 +40,121 @@ double FNT_DEFAULT_ADV = 90; // TODO determine proper default double FNT_DEFAULT_ASCENT = 90; // TODO determine proper default double FNT_UNITS_PER_EM = 90; // TODO determine proper default -static void sp_font_init(SPFont *font) -{ - font->horiz_origin_x = 0; - font->horiz_origin_y = 0; - font->horiz_adv_x = FNT_DEFAULT_ADV; - font->vert_origin_x = FNT_DEFAULT_ADV / 2.0; - font->vert_origin_y = FNT_DEFAULT_ASCENT; - font->vert_adv_y = FNT_UNITS_PER_EM; +SPFont::SPFont() : SPObject() { + this->horiz_origin_x = 0; + this->horiz_origin_y = 0; + this->horiz_adv_x = FNT_DEFAULT_ADV; + this->vert_origin_x = FNT_DEFAULT_ADV / 2.0; + this->vert_origin_y = FNT_DEFAULT_ASCENT; + this->vert_adv_y = FNT_UNITS_PER_EM; } -static void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) (parent_class))->build) { - ((SPObjectClass *) (parent_class))->build(object, document, repr); - } - - object->readAttr( "horiz-origin-x" ); - object->readAttr( "horiz-origin-y" ); - object->readAttr( "horiz-adv-x" ); - object->readAttr( "vert-origin-x" ); - object->readAttr( "vert-origin-y" ); - object->readAttr( "vert-adv-y" ); - - document->addResource("font", object); +SPFont::~SPFont() { } +void SPFont::build(SPDocument *document, Inkscape::XML::Node *repr) { + SPObject::build(document, repr); + + this->readAttr( "horiz-origin-x" ); + this->readAttr( "horiz-origin-y" ); + this->readAttr( "horiz-adv-x" ); + this->readAttr( "vert-origin-x" ); + this->readAttr( "vert-origin-y" ); + this->readAttr( "vert-adv-y" ); -static void sp_font_children_modified(SPFont */*sp_font*/) -{ + document->addResource("font", this); } /** * 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); +void SPFont::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + SPObject::child_added(child, ref); - 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); + this->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); +void SPFont::remove_child(Inkscape::XML::Node* child) { + SPObject::remove_child(child); - sp_font_children_modified(f); - object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } -static void sp_font_release(SPObject *object) -{ - //SPFont *font = SP_FONT(object); - object->document->removeResource("font", object); +void SPFont::release() { + this->document->removeResource("font", this); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); - } + SPObject::release(); } -static void sp_font_set(SPObject *object, unsigned int key, const gchar *value) -{ - SPFont *font = SP_FONT(object); - +void SPFont::set(unsigned int key, const gchar *value) { // TODO these are floating point, so some epsilon comparison would be good switch (key) { case SP_ATTR_HORIZ_ORIGIN_X: { double number = value ? g_ascii_strtod(value, 0) : 0; - if (number != font->horiz_origin_x){ - font->horiz_origin_x = number; - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + if (number != this->horiz_origin_x){ + this->horiz_origin_x = number; + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; } case SP_ATTR_HORIZ_ORIGIN_Y: { double number = value ? g_ascii_strtod(value, 0) : 0; - if (number != font->horiz_origin_y){ - font->horiz_origin_y = number; - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + if (number != this->horiz_origin_y){ + this->horiz_origin_y = number; + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; } case SP_ATTR_HORIZ_ADV_X: { double number = value ? g_ascii_strtod(value, 0) : FNT_DEFAULT_ADV; - if (number != font->horiz_adv_x){ - font->horiz_adv_x = number; - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + if (number != this->horiz_adv_x){ + this->horiz_adv_x = number; + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; } case SP_ATTR_VERT_ORIGIN_X: { double number = value ? g_ascii_strtod(value, 0) : FNT_DEFAULT_ADV / 2.0; - if (number != font->vert_origin_x){ - font->vert_origin_x = number; - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + if (number != this->vert_origin_x){ + this->vert_origin_x = number; + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; } case SP_ATTR_VERT_ORIGIN_Y: { double number = value ? g_ascii_strtod(value, 0) : FNT_DEFAULT_ASCENT; - if (number != font->vert_origin_y){ - font->vert_origin_y = number; - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + if (number != this->vert_origin_y){ + this->vert_origin_y = number; + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; } case SP_ATTR_VERT_ADV_Y: { double number = value ? g_ascii_strtod(value, 0) : FNT_UNITS_PER_EM; - if (number != font->vert_adv_y){ - font->vert_adv_y = number; - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + + if (number != this->vert_adv_y){ + this->vert_adv_y = 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; } } @@ -229,58 +162,48 @@ static void sp_font_set(SPObject *object, unsigned int key, const gchar *value) /** * Receives update notifications. */ -static void -sp_font_update(SPObject *object, SPCtx *ctx, guint flags) -{ +void SPFont::update(SPCtx *ctx, guint flags) { if (flags & (SP_OBJECT_MODIFIED_FLAG)) { - object->readAttr( "horiz-origin-x" ); - object->readAttr( "horiz-origin-y" ); - object->readAttr( "horiz-adv-x" ); - object->readAttr( "vert-origin-x" ); - object->readAttr( "vert-origin-y" ); - object->readAttr( "vert-adv-y" ); + this->readAttr( "horiz-origin-x" ); + this->readAttr( "horiz-origin-y" ); + this->readAttr( "horiz-adv-x" ); + this->readAttr( "vert-origin-x" ); + this->readAttr( "vert-origin-y" ); + this->readAttr( "vert-adv-y" ); } - 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_font_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ - SPFont *font = SP_FONT(object); - +Inkscape::XML::Node* SPFont::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:font"); } - sp_repr_set_svg_double(repr, "horiz-origin-x", font->horiz_origin_x); - sp_repr_set_svg_double(repr, "horiz-origin-y", font->horiz_origin_y); - sp_repr_set_svg_double(repr, "horiz-adv-x", font->horiz_adv_x); - sp_repr_set_svg_double(repr, "vert-origin-x", font->vert_origin_x); - sp_repr_set_svg_double(repr, "vert-origin-y", font->vert_origin_y); - sp_repr_set_svg_double(repr, "vert-adv-y", font->vert_adv_y); + sp_repr_set_svg_double(repr, "horiz-origin-x", this->horiz_origin_x); + sp_repr_set_svg_double(repr, "horiz-origin-y", this->horiz_origin_y); + sp_repr_set_svg_double(repr, "horiz-adv-x", this->horiz_adv_x); + sp_repr_set_svg_double(repr, "vert-origin-x", this->vert_origin_x); + sp_repr_set_svg_double(repr, "vert-origin-y", this->vert_origin_y); + sp_repr_set_svg_double(repr, "vert-adv-y", this->vert_adv_y); - if (repr != object->getRepr()) { + if (repr != this->getRepr()) { // All the below COPY_ATTR funtions are directly using // the XML Tree while they shouldn't - COPY_ATTR(repr, object->getRepr(), "horiz-origin-x"); - COPY_ATTR(repr, object->getRepr(), "horiz-origin-y"); - COPY_ATTR(repr, object->getRepr(), "horiz-adv-x"); - COPY_ATTR(repr, object->getRepr(), "vert-origin-x"); - COPY_ATTR(repr, object->getRepr(), "vert-origin-y"); - COPY_ATTR(repr, object->getRepr(), "vert-adv-y"); + COPY_ATTR(repr, this->getRepr(), "horiz-origin-x"); + COPY_ATTR(repr, this->getRepr(), "horiz-origin-y"); + COPY_ATTR(repr, this->getRepr(), "horiz-adv-x"); + COPY_ATTR(repr, this->getRepr(), "vert-origin-x"); + COPY_ATTR(repr, this->getRepr(), "vert-origin-y"); + COPY_ATTR(repr, this->getRepr(), "vert-adv-y"); } - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); - } + SPObject::write(xml_doc, repr, flags); return repr; } -#endif //#ifdef ENABLE_SVG_FONTS /* Local Variables: mode:c++ |
