sp-font.cpp revision 39e454bdef986f01ef929a38513fc09b4ae80e32
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * SVG <font> element implementation
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Felipe C. da S. Sanches <juca@members.fsf.org>
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Copyright (C) 2008, Felipe C. da S. Sanches
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Released under GNU GPL, read the file 'COPYING' for more information
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshstatic void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshstatic void sp_font_set(SPObject *object, unsigned int key, const gchar *value);
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshstatic Inkscape::XML::Node *sp_font_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshstatic void sp_font_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
c751b68e56ace7b9d649ee20b7f25ed1f65922e3Matthew Petroffstatic void sp_font_remove_child(SPObject *object, Inkscape::XML::Node *child);
3711b3e25395437ee0a09dbbb2a76d999c4ef322mikloshstatic void sp_font_update(SPObject *object, SPCtx *ctx, guint flags);
b5b35fce2e3df933e5223ef6645d814eacf51cfamiklosh// static gchar *sp_font_description(SPItem *item);
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh type = g_type_register_static(SP_TYPE_OBJECT, "SPFont", &info, (GTypeFlags) 0);
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh SPObjectClass *sp_object_class = (SPObjectClass *) fc;
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_object_class->remove_child = sp_font_remove_child;
1cda9431ef400135f5e1bd899a94b921bdad0eafmiklosh//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
68664e00e2372534b4df2fdc5f54f836bafece18miklosh// TODO determine better values and/or make these dynamic:
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7mikloshdouble FNT_DEFAULT_ADV = 90; // TODO determine proper default
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruzdouble FNT_DEFAULT_ASCENT = 90; // TODO determine proper default
3711b3e25395437ee0a09dbbb2a76d999c4ef322mikloshdouble FNT_UNITS_PER_EM = 90; // TODO determine proper default
3711b3e25395437ee0a09dbbb2a76d999c4ef322mikloshstatic void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh ((SPObjectClass *) (parent_class))->build(object, document, repr);
f9ab06d037336cf8796b54c94a119f40eda79a46Krisstatic void sp_font_children_modified(SPFont */*sp_font*/)
f9ab06d037336cf8796b54c94a119f40eda79a46Kris * Callback for child_added event.
be17b6e6b80af045ef40c635ea563ebd987269b8tavmjong-freesp_font_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
be17b6e6b80af045ef40c635ea563ebd987269b8tavmjong-free if (((SPObjectClass *) parent_class)->child_added)
75b857d473541532819bd791105cb352c9a43214buliabyak (* ((SPObjectClass *) parent_class)->child_added)(object, child, ref);
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
7ddc475794d846646261f6b12015d44ac361d070Kris De Gussem * Callback for remove_child event.
1667116521643e2475184b048e0abb77a2aa9735mikloshsp_font_remove_child(SPObject *object, Inkscape::XML::Node *child)
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh (* ((SPObjectClass *) parent_class)->remove_child)(object, child);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
68664e00e2372534b4df2fdc5f54f836bafece18miklosh //SPFont *font = SP_FONT(object);
68664e00e2372534b4df2fdc5f54f836bafece18miklosh SP_OBJECT_DOCUMENT(object)->remove_resource("font", object);
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emikloshstatic void sp_font_set(SPObject *object, unsigned int key, const gchar *value)
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh // TODO these are floating point, so some epsilon comparison would be good
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh double number = value ? g_ascii_strtod(value, 0) : 0;
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh double number = value ? g_ascii_strtod(value, 0) : 0;
1667116521643e2475184b048e0abb77a2aa9735miklosh double number = value ? g_ascii_strtod(value, 0) : FNT_DEFAULT_ADV;
1667116521643e2475184b048e0abb77a2aa9735miklosh double number = value ? g_ascii_strtod(value, 0) : FNT_DEFAULT_ADV / 2.0;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh double number = value ? g_ascii_strtod(value, 0) : FNT_DEFAULT_ASCENT;
68664e00e2372534b4df2fdc5f54f836bafece18miklosh double number = value ? g_ascii_strtod(value, 0) : FNT_UNITS_PER_EM;
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh ((SPObjectClass *) (parent_class))->set(object, key, value);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Receives update notifications.
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshsp_font_update(SPObject *object, SPCtx *ctx, guint flags)
d9a7c806ee7f408ddb61ff4f233c9d96111ee2b5johanengelen if (((SPObjectClass *) parent_class)->update) {
d9a7c806ee7f408ddb61ff4f233c9d96111ee2b5johanengelen ((SPObjectClass *) parent_class)->update(object, ctx, flags);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh#define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
d27f5758e12c3107ee69e66702043931e0756f6bmikloshstatic Inkscape::XML::Node *sp_font_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen sp_repr_set_svg_double(repr, "horiz-origin-x", font->horiz_origin_x);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh sp_repr_set_svg_double(repr, "horiz-origin-y", font->horiz_origin_y);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh sp_repr_set_svg_double(repr, "horiz-adv-x", font->horiz_adv_x);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh sp_repr_set_svg_double(repr, "vert-origin-x", font->vert_origin_x);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_repr_set_svg_double(repr, "vert-origin-y", font->vert_origin_y);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_repr_set_svg_double(repr, "vert-adv-y", font->vert_adv_y);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh /*All the below COPY_ATTR funtions are directly using
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh the XML Tree while they shouldn't*/
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh COPY_ATTR(repr, object->getRepr(), "horiz-origin-x");
0c6b51649b501e4e378921d918c6a113ab8e2bceJohan B. C. Engelen COPY_ATTR(repr, object->getRepr(), "horiz-origin-y");
0c6b51649b501e4e378921d918c6a113ab8e2bceJohan B. C. Engelen COPY_ATTR(repr, object->getRepr(), "horiz-adv-x");
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh COPY_ATTR(repr, object->getRepr(), "vert-origin-x");
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh COPY_ATTR(repr, object->getRepr(), "vert-origin-y");
0c6b51649b501e4e378921d918c6a113ab8e2bceJohan B. C. Engelen COPY_ATTR(repr, object->getRepr(), "vert-adv-y");
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh#endif //#ifdef ENABLE_SVG_FONTS
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh Local Variables:
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c-file-style:"stroustrup"
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh indent-tabs-mode:nil
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh fill-column:99
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :