From 37eb84dcfa0f0bb84f5e62303ef7288ee922b64d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 22:59:52 +0200 Subject: Added "virtual pad" to SPImage. (bzr r11608.1.25) --- src/sp-image.cpp | 156 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 117 insertions(+), 39 deletions(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 07885ff4d..15f565bc4 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -602,8 +602,19 @@ static void sp_image_class_init( SPImageClass * klass ) item_class->set_transform = sp_image_set_transform; } +CImage::CImage(SPImage* image) : CItem(image) { + this->spimage = image; +} + +CImage::~CImage() { +} + static void sp_image_init( SPImage *image ) { + image->cimage = new CImage(image); + image->citem = image->cimage; + image->cobject = image->cimage; + image->x.unset(); image->y.unset(); image->width.unset(); @@ -624,11 +635,10 @@ static void sp_image_init( SPImage *image ) image->lastMod = 0; } -static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr ) -{ - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build (object, document, repr); - } +void CImage::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPImage* object = this->spimage; + + CItem::onBuild(document, repr); object->readAttr( "xlink:href" ); object->readAttr( "x" ); @@ -642,8 +652,14 @@ static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XM document->addResource("image", object); } -static void sp_image_release( SPObject *object ) +static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr ) { + ((SPImage*)object)->cimage->onBuild(document, repr); +} + +void CImage::onRelease() { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE(object); if (object->document) { @@ -677,13 +693,18 @@ static void sp_image_release( SPObject *object ) image->curve = image->curve->unref(); } - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release (object); - } + CItem::onRelease(); } -static void sp_image_set( SPObject *object, unsigned int key, const gchar *value ) +static void sp_image_release( SPObject *object ) { + ((SPImage*)object)->cimage->onRelease(); + +} + +void CImage::onSet(unsigned int key, const gchar* value) { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE (object); switch (key) { @@ -796,22 +817,25 @@ static void sp_image_set( SPObject *object, unsigned int key, const gchar *value break; #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) default: - if (((SPObjectClass *) (parent_class))->set) - ((SPObjectClass *) (parent_class))->set (object, key, value); + CItem::onSet(key, value); break; } sp_image_set_curve(image); //creates a curve at the image's boundary for snapping } -static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags ) +static void sp_image_set( SPObject *object, unsigned int key, const gchar *value ) { + ((SPImage*)object)->cimage->onSet(key, value); +} + +void CImage::onUpdate(SPCtx *ctx, unsigned int flags) { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE(object); SPDocument *doc = object->document; - if (((SPObjectClass *) (parent_class))->update) { - ((SPObjectClass *) (parent_class))->update (object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_IMAGE_HREF_MODIFIED_FLAG) { if (image->pixbuf) { @@ -1009,13 +1033,22 @@ static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags ) sp_image_update_canvas_image ((SPImage *) object); } -static void sp_image_modified( SPObject *object, unsigned int flags ) +static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags ) { + ((SPImage*)object)->cimage->onUpdate(ctx, flags); +} + +void CImage::onModified(unsigned int flags) { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE (object); - if (((SPObjectClass *) (parent_class))->modified) { - (* ((SPObjectClass *) (parent_class))->modified) (object, flags); - } + // CPPIFY: This doesn't make no sense. + // CObject::onModified is pure and CItem doesn't override this method. What was the idea behind these lines? +// if (((SPObjectClass *) (parent_class))->modified) { +// (* ((SPObjectClass *) (parent_class))->modified) (object, flags); +// } +// CItem::onModified(flags); if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { for (SPItemView *v = image->display; v != NULL; v = v->next) { @@ -1025,8 +1058,14 @@ static void sp_image_modified( SPObject *object, unsigned int flags ) } } -static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) +static void sp_image_modified( SPObject *object, unsigned int flags ) { + ((SPImage*)object)->cimage->onModified(flags); +} + +Inkscape::XML::Node *CImage::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE (object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -1056,27 +1095,37 @@ static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Doc } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } -static Geom::OptRect sp_image_bbox( SPItem const *item,Geom::Affine const &transform, SPItem::BBoxType /*type*/ ) +static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) { - SPImage const &image = *SP_IMAGE(item); - Geom::OptRect bbox; + return ((SPImage*)object)->cimage->onWrite(xml_doc, repr, flags); +} - if ((image.width.computed > 0.0) && (image.height.computed > 0.0)) { - bbox = Geom::Rect::from_xywh(image.x.computed, image.y.computed, image.width.computed, image.height.computed); - *bbox *= transform; - } - return bbox; +Geom::OptRect CImage::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { + SPImage* item = this->spimage; + + SPImage const &image = *SP_IMAGE(item); + Geom::OptRect bbox; + + if ((image.width.computed > 0.0) && (image.height.computed > 0.0)) { + bbox = Geom::Rect::from_xywh(image.x.computed, image.y.computed, image.width.computed, image.height.computed); + *bbox *= transform; + } + return bbox; } -static void sp_image_print( SPItem *item, SPPrintContext *ctx ) +static Geom::OptRect sp_image_bbox( SPItem const *item,Geom::Affine const &transform, SPItem::BBoxType type) { + return ((SPImage*)item)->cimage->onBbox(transform, type); +} + +void CImage::onPrint(SPPrintContext *ctx) { + SPImage* item = this->spimage; + SPImage *image = SP_IMAGE(item); if (image->pixbuf && (image->width.computed > 0.0) && (image->height.computed > 0.0) ) { @@ -1122,8 +1171,14 @@ static void sp_image_print( SPItem *item, SPPrintContext *ctx ) } } -static gchar *sp_image_description( SPItem *item ) +static void sp_image_print( SPItem *item, SPPrintContext *ctx ) { + ((SPImage*)item)->cimage->onPrint(ctx); +} + +gchar* CImage::onDescription() { + SPImage* item = this->spimage; + SPImage *image = SP_IMAGE(item); char *href_desc; if (image->href) { @@ -1145,8 +1200,14 @@ static gchar *sp_image_description( SPItem *item ) return ret; } -static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &drawing, unsigned int /*key*/, unsigned int /*flags*/ ) +static gchar *sp_image_description( SPItem *item ) { + return ((SPImage*)item)->cimage->onDescription(); +} + +Inkscape::DrawingItem* CImage::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + SPImage* item = this->spimage; + SPImage * image = SP_IMAGE(item); Inkscape::DrawingImage *ai = new Inkscape::DrawingImage(drawing); @@ -1155,6 +1216,11 @@ static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &dr return ai; } +static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags ) +{ + return ((SPImage*)item)->cimage->onShow(drawing, key, flags); +} + /* * utility function to try loading image from href * @@ -1279,8 +1345,9 @@ static void sp_image_update_canvas_image(SPImage *image) } } -static void sp_image_snappoints( SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs ) -{ +void CImage::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPImage* item = this->spimage; + /* An image doesn't have any nodes to snap, but still we want to be able snap one image to another. Therefore we will create some snappoints at the corner, similar to a rect. If the image is rotated, then the snappoints will rotate with it. Again, just like a rect. @@ -1310,13 +1377,19 @@ static void sp_image_snappoints( SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs ) +{ + ((SPImage*)item)->cimage->onSnappoints(p, snapprefs); +} + /* * Initially we'll do: * Transform x, y, set x, y, clear translation */ -static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xform ) -{ +Geom::Affine CImage::onSetTransform(Geom::Affine const &xform) { + SPImage* item = this->spimage; + SPImage *image = SP_IMAGE(item); /* Calculate position in parent coords. */ @@ -1355,6 +1428,11 @@ static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xf return ret; } +static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xform ) +{ + return ((SPImage*)item)->cimage->onSetTransform(xform); +} + static GdkPixbuf *sp_image_repr_read_dataURI( const gchar * uri_data ) { GdkPixbuf * pixbuf = NULL; -- cgit v1.2.3 From 99cb30e28d4ee193f39e23464abbd7630cac8a2d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 6 Oct 2012 23:56:27 +0200 Subject: Added virtual pad to SPFlowtext; removed old calls to virtual SPItem methods. (bzr r11608.1.46) --- src/sp-image.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 15f565bc4..3d5a9a08b 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -594,12 +594,12 @@ static void sp_image_class_init( SPImageClass * klass ) sp_object_class->modified = sp_image_modified; sp_object_class->write = sp_image_write; - item_class->bbox = sp_image_bbox; - item_class->print = sp_image_print; - item_class->description = sp_image_description; - item_class->show = sp_image_show; - item_class->snappoints = sp_image_snappoints; - item_class->set_transform = sp_image_set_transform; +// item_class->bbox = sp_image_bbox; +// item_class->print = sp_image_print; +// item_class->description = sp_image_description; +// item_class->show = sp_image_show; +// item_class->snappoints = sp_image_snappoints; +// item_class->set_transform = sp_image_set_transform; } CImage::CImage(SPImage* image) : CItem(image) { -- cgit v1.2.3 From a0a8d020201e0e38a63d9aa3dce228d7d9e6fb35 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 14 Mar 2013 12:42:39 +0100 Subject: Various changes. (bzr r11608.1.48) --- src/sp-image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 3d5a9a08b..df2947e9a 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -587,7 +587,7 @@ static void sp_image_class_init( SPImageClass * klass ) parent_class = reinterpret_cast(g_type_class_ref(SPItem::getType())); - sp_object_class->build = sp_image_build; + //sp_object_class->build = sp_image_build; sp_object_class->release = sp_image_release; sp_object_class->set = sp_image_set; sp_object_class->update = sp_image_update; -- cgit v1.2.3 From 957c3e4b7909d42c5a13f1b1dd583f877fc32259 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:46:57 +0100 Subject: Removed function pointers from SPObject and subclasses. Added some missing virtual pads for classes that were hidden by preprocessor macros. (bzr r11608.1.55) --- src/sp-image.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index df2947e9a..a219c0939 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -588,11 +588,11 @@ static void sp_image_class_init( SPImageClass * klass ) parent_class = reinterpret_cast(g_type_class_ref(SPItem::getType())); //sp_object_class->build = sp_image_build; - sp_object_class->release = sp_image_release; - sp_object_class->set = sp_image_set; - sp_object_class->update = sp_image_update; - sp_object_class->modified = sp_image_modified; - sp_object_class->write = sp_image_write; +// sp_object_class->release = sp_image_release; +// sp_object_class->set = sp_image_set; +// sp_object_class->update = sp_image_update; +// sp_object_class->modified = sp_image_modified; +// sp_object_class->write = sp_image_write; // item_class->bbox = sp_image_bbox; // item_class->print = sp_image_print; -- cgit v1.2.3 From 7df6616da5ea2debb86838366ddf746841549cdb Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:56:13 +0100 Subject: Renamed virtual function names. (bzr r11608.1.57) --- src/sp-image.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 100263ec6..fa75915f9 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -540,10 +540,10 @@ static void sp_image_init( SPImage *image ) image->lastMod = 0; } -void CImage::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { +void CImage::build(SPDocument *document, Inkscape::XML::Node *repr) { SPImage* object = this->spimage; - CItem::onBuild(document, repr); + CItem::build(document, repr); object->readAttr( "xlink:href" ); object->readAttr( "x" ); @@ -557,7 +557,7 @@ void CImage::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { document->addResource("image", object); } -void CImage::onRelease() { +void CImage::release() { SPImage* object = this->spimage; SPImage *image = SP_IMAGE(object); @@ -593,10 +593,10 @@ void CImage::onRelease() { image->curve = image->curve->unref(); } - CItem::onRelease(); + CItem::release(); } -void CImage::onSet(unsigned int key, const gchar* value) { +void CImage::set(unsigned int key, const gchar* value) { SPImage* object = this->spimage; SPImage *image = SP_IMAGE (object); @@ -711,20 +711,20 @@ void CImage::onSet(unsigned int key, const gchar* value) { break; #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) default: - CItem::onSet(key, value); + CItem::set(key, value); break; } sp_image_set_curve(image); //creates a curve at the image's boundary for snapping } -void CImage::onUpdate(SPCtx *ctx, unsigned int flags) { +void CImage::update(SPCtx *ctx, unsigned int flags) { SPImage* object = this->spimage; SPImage *image = SP_IMAGE(object); SPDocument *doc = object->document; - CItem::onUpdate(ctx, flags); + CItem::update(ctx, flags); if (flags & SP_IMAGE_HREF_MODIFIED_FLAG) { if (image->pixbuf) { @@ -922,7 +922,7 @@ void CImage::onUpdate(SPCtx *ctx, unsigned int flags) { sp_image_update_canvas_image ((SPImage *) object); } -void CImage::onModified(unsigned int flags) { +void CImage::modified(unsigned int flags) { SPImage* object = this->spimage; SPImage *image = SP_IMAGE (object); @@ -938,7 +938,7 @@ void CImage::onModified(unsigned int flags) { } -Inkscape::XML::Node *CImage::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) { +Inkscape::XML::Node *CImage::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) { SPImage* object = this->spimage; SPImage *image = SP_IMAGE (object); @@ -970,12 +970,12 @@ Inkscape::XML::Node *CImage::onWrite(Inkscape::XML::Document *xml_doc, Inkscape: } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - CItem::onWrite(xml_doc, repr, flags); + CItem::write(xml_doc, repr, flags); return repr; } -Geom::OptRect CImage::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { +Geom::OptRect CImage::bbox(Geom::Affine const &transform, SPItem::BBoxType type) { SPImage* item = this->spimage; SPImage const &image = *SP_IMAGE(item); @@ -988,7 +988,7 @@ Geom::OptRect CImage::onBbox(Geom::Affine const &transform, SPItem::BBoxType typ return bbox; } -void CImage::onPrint(SPPrintContext *ctx) { +void CImage::print(SPPrintContext *ctx) { SPImage* item = this->spimage; SPImage *image = SP_IMAGE(item); @@ -1036,7 +1036,7 @@ void CImage::onPrint(SPPrintContext *ctx) { } } -gchar* CImage::onDescription() { +gchar* CImage::description() { SPImage* item = this->spimage; SPImage *image = SP_IMAGE(item); @@ -1060,7 +1060,7 @@ gchar* CImage::onDescription() { return ret; } -Inkscape::DrawingItem* CImage::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { +Inkscape::DrawingItem* CImage::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { SPImage* item = this->spimage; SPImage * image = SP_IMAGE(item); @@ -1195,7 +1195,7 @@ static void sp_image_update_canvas_image(SPImage *image) } } -void CImage::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { +void CImage::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { SPImage* item = this->spimage; /* An image doesn't have any nodes to snap, but still we want to be able snap one image @@ -1232,7 +1232,7 @@ void CImage::onSnappoints(std::vector &p, Inkscape * Transform x, y, set x, y, clear translation */ -Geom::Affine CImage::onSetTransform(Geom::Affine const &xform) { +Geom::Affine CImage::set_transform(Geom::Affine const &xform) { SPImage* item = this->spimage; SPImage *image = SP_IMAGE(item); @@ -1413,7 +1413,7 @@ static void sp_image_set_curve( SPImage *image ) image->curve = image->curve->unref(); } } else { - Geom::OptRect rect = image->cimage->onBbox(Geom::identity(), SPItem::VISUAL_BBOX); + Geom::OptRect rect = image->cimage->bbox(Geom::identity(), SPItem::VISUAL_BBOX); SPCurve *c = SPCurve::new_from_rect(*rect, true); if (image->curve) { @@ -1487,7 +1487,7 @@ void sp_image_refresh_if_outdated( SPImage* image ) if ( st.st_mtime != image->lastMod ) { SPCtx *ctx = 0; unsigned int flags = SP_IMAGE_HREF_MODIFIED_FLAG; - image->cimage->onUpdate(ctx, flags); + image->cimage->update(ctx, flags); } } } -- cgit v1.2.3 From a5d6e692d661f0bf7648e64e8fcb04588bb8f3ab Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 1 Apr 2013 00:07:00 +0200 Subject: Prepared exchange of casting macros. (bzr r11608.1.63) --- src/sp-image.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index fa75915f9..ab3a1ac1b 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -515,6 +515,7 @@ CImage::~CImage() { static void sp_image_init( SPImage *image ) { image->cimage = new CImage(image); + image->typeHierarchy.insert(typeid(SPImage)); delete image->citem; image->citem = image->cimage; -- cgit v1.2.3 From 69f3b6f1abb2bb422935d43262e1e99aab359954 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 01:41:30 +0200 Subject: Added constructors to SP classes. (bzr r11608.1.67) --- src/sp-image.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index ab3a1ac1b..ecae573e6 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -499,7 +499,7 @@ GdkPixbuf* pixbuf_new_from_file( const char *filename, GError **error ) } } -G_DEFINE_TYPE(SPImage, sp_image, SP_TYPE_ITEM); +G_DEFINE_TYPE(SPImage, sp_image, G_TYPE_OBJECT); static void sp_image_class_init( SPImageClass * klass ) { @@ -512,8 +512,9 @@ CImage::CImage(SPImage* image) : CItem(image) { CImage::~CImage() { } -static void sp_image_init( SPImage *image ) -{ +SPImage::SPImage() : SPItem() { + SPImage* image = this; + image->cimage = new CImage(image); image->typeHierarchy.insert(typeid(SPImage)); @@ -521,6 +522,8 @@ static void sp_image_init( SPImage *image ) image->citem = image->cimage; image->cobject = image->cimage; + image->aspect_clip = 0; + image->x.unset(); image->y.unset(); image->width.unset(); @@ -541,6 +544,11 @@ static void sp_image_init( SPImage *image ) image->lastMod = 0; } +static void sp_image_init( SPImage *image ) +{ + new (image) SPImage(); +} + void CImage::build(SPDocument *document, Inkscape::XML::Node *repr) { SPImage* object = this->spimage; -- cgit v1.2.3 From d1af3566872dfff2aeec84859c87f1f8d13f79df Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 19:14:36 +0200 Subject: Registered classes with new factory. Hkern, Vkern and FeFuncX have to be rewritten, as they aren't real classes. (bzr r11608.1.69) --- src/sp-image.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index ecae573e6..8cba1e87a 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -499,6 +499,17 @@ GdkPixbuf* pixbuf_new_from_file( const char *filename, GError **error ) } } + +#include "sp-factory.h" + +namespace { + SPObject* createImage() { + return new SPImage(); + } + + bool imageRegistered = SPFactory::instance().registerObject("svg:image", createImage); +} + G_DEFINE_TYPE(SPImage, sp_image, G_TYPE_OBJECT); static void sp_image_class_init( SPImageClass * klass ) -- cgit v1.2.3 From 61003d31ea058fdf94f4f80c753c3e38426f35e4 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 21:07:38 +0200 Subject: Merged FlowX classes. (bzr r11608.1.79) --- src/sp-image.cpp | 464 ++++++++++++++++++++++++++----------------------------- 1 file changed, 217 insertions(+), 247 deletions(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 8cba1e87a..5961bf7fa 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -510,156 +510,136 @@ namespace { bool imageRegistered = SPFactory::instance().registerObject("svg:image", createImage); } -G_DEFINE_TYPE(SPImage, sp_image, G_TYPE_OBJECT); +SPImage::SPImage() : SPItem(), CItem(this) { + delete this->citem; + this->citem = this; + this->cobject = this; -static void sp_image_class_init( SPImageClass * klass ) -{ -} - -CImage::CImage(SPImage* image) : CItem(image) { - this->spimage = image; -} - -CImage::~CImage() { -} - -SPImage::SPImage() : SPItem() { - SPImage* image = this; - - image->cimage = new CImage(image); - image->typeHierarchy.insert(typeid(SPImage)); + this->aspect_clip = 0; - delete image->citem; - image->citem = image->cimage; - image->cobject = image->cimage; + this->x.unset(); + this->y.unset(); + this->width.unset(); + this->height.unset(); + this->aspect_align = SP_ASPECT_NONE; + this->clipbox = Geom::Rect(); + this->sx = this->sy = 1.0; + this->ox = this->oy = 0.0; - image->aspect_clip = 0; + this->curve = NULL; - image->x.unset(); - image->y.unset(); - image->width.unset(); - image->height.unset(); - image->aspect_align = SP_ASPECT_NONE; - image->clipbox = Geom::Rect(); - image->sx = image->sy = 1.0; - image->ox = image->oy = 0.0; - - image->curve = NULL; - - image->href = 0; + this->href = 0; #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - image->color_profile = 0; + this->color_profile = 0; #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - image->pixbuf = 0; - image->pixPath = 0; - image->lastMod = 0; + this->pixbuf = 0; + this->pixPath = 0; + this->lastMod = 0; } -static void sp_image_init( SPImage *image ) -{ - new (image) SPImage(); +SPImage::~SPImage() { } -void CImage::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPImage* object = this->spimage; - +void SPImage::build(SPDocument *document, Inkscape::XML::Node *repr) { CItem::build(document, repr); - object->readAttr( "xlink:href" ); - object->readAttr( "x" ); - object->readAttr( "y" ); - object->readAttr( "width" ); - object->readAttr( "height" ); - object->readAttr( "preserveAspectRatio" ); - object->readAttr( "color-profile" ); + this->readAttr( "xlink:href" ); + this->readAttr( "x" ); + this->readAttr( "y" ); + this->readAttr( "width" ); + this->readAttr( "height" ); + this->readAttr( "preserveAspectRatio" ); + this->readAttr( "color-profile" ); /* Register */ - document->addResource("image", object); + document->addResource("image", this); } -void CImage::release() { - SPImage* object = this->spimage; - - SPImage *image = SP_IMAGE(object); - - if (object->document) { +void SPImage::release() { + if (this->document) { // Unregister ourselves - object->document->removeResource("image", object); + this->document->removeResource("image", this); } - if (image->href) { - g_free (image->href); - image->href = NULL; + if (this->href) { + g_free (this->href); + this->href = NULL; } - if (image->pixbuf) { - g_object_unref (image->pixbuf); - image->pixbuf = NULL; + if (this->pixbuf) { + g_object_unref (this->pixbuf); + this->pixbuf = NULL; } #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - if (image->color_profile) { - g_free (image->color_profile); - image->color_profile = NULL; + if (this->color_profile) { + g_free (this->color_profile); + this->color_profile = NULL; } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - if (image->pixPath) { - g_free(image->pixPath); - image->pixPath = 0; + if (this->pixPath) { + g_free(this->pixPath); + this->pixPath = 0; } - if (image->curve) { - image->curve = image->curve->unref(); + if (this->curve) { + this->curve = this->curve->unref(); } CItem::release(); } -void CImage::set(unsigned int key, const gchar* value) { - SPImage* object = this->spimage; - - SPImage *image = SP_IMAGE (object); - +void SPImage::set(unsigned int key, const gchar* value) { switch (key) { case SP_ATTR_XLINK_HREF: - g_free (image->href); - image->href = (value) ? g_strdup (value) : NULL; - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_IMAGE_HREF_MODIFIED_FLAG); + g_free (this->href); + this->href = (value) ? g_strdup (value) : NULL; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_IMAGE_HREF_MODIFIED_FLAG); break; + case SP_ATTR_X: - if (!image->x.readAbsolute(value)) { + if (!this->x.readAbsolute(value)) { /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - image->x.unset(); + this->x.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_Y: - if (!image->y.readAbsolute(value)) { + if (!this->y.readAbsolute(value)) { /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - image->y.unset(); + this->y.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_WIDTH: - if (!image->width.readAbsolute(value)) { + if (!this->width.readAbsolute(value)) { /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - image->width.unset(); + this->width.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_HEIGHT: - if (!image->height.readAbsolute(value)) { + if (!this->height.readAbsolute(value)) { /* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */ - image->height.unset(); + this->height.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_PRESERVEASPECTRATIO: /* Do setup before, so we can use break to escape */ - image->aspect_align = SP_ASPECT_NONE; - image->aspect_clip = SP_ASPECT_MEET; - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + this->aspect_align = SP_ASPECT_NONE; + this->aspect_clip = SP_ASPECT_MEET; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); + if (value) { int len; gchar c[256]; @@ -698,8 +678,11 @@ void CImage::set(unsigned int key, const gchar* value) { } else { break; } + clip = SP_ASPECT_MEET; + while (*e && *e == 32) e += 1; + if (*e) { if (!strcmp (e, "meet")) { clip = SP_ASPECT_MEET; @@ -709,70 +692,75 @@ void CImage::set(unsigned int key, const gchar* value) { break; } } - image->aspect_align = align; - image->aspect_clip = clip; + + this->aspect_align = align; + this->aspect_clip = clip; } break; + #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) case SP_PROP_COLOR_PROFILE: - if ( image->color_profile ) { - g_free (image->color_profile); + if ( this->color_profile ) { + g_free (this->color_profile); } - image->color_profile = (value) ? g_strdup (value) : NULL; + + this->color_profile = (value) ? g_strdup (value) : NULL; #ifdef DEBUG_LCMS if ( value ) { - DEBUG_MESSAGE( lcmsFour, " color-profile set to '%s'", value ); + DEBUG_MESSAGE( lcmsFour, " color-profile set to '%s'", value ); } else { - DEBUG_MESSAGE( lcmsFour, " color-profile cleared" ); + DEBUG_MESSAGE( lcmsFour, " color-profile cleared" ); } #endif // DEBUG_LCMS // TODO check on this HREF_MODIFIED flag - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_IMAGE_HREF_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_IMAGE_HREF_MODIFIED_FLAG); break; + #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) default: CItem::set(key, value); break; } - sp_image_set_curve(image); //creates a curve at the image's boundary for snapping + sp_image_set_curve(this); //creates a curve at the image's boundary for snapping } -void CImage::update(SPCtx *ctx, unsigned int flags) { - SPImage* object = this->spimage; - - SPImage *image = SP_IMAGE(object); - SPDocument *doc = object->document; +void SPImage::update(SPCtx *ctx, unsigned int flags) { + SPDocument *doc = this->document; CItem::update(ctx, flags); if (flags & SP_IMAGE_HREF_MODIFIED_FLAG) { - if (image->pixbuf) { - g_object_unref (image->pixbuf); - image->pixbuf = NULL; + if (this->pixbuf) { + g_object_unref (this->pixbuf); + this->pixbuf = NULL; } - if ( image->pixPath ) { - g_free(image->pixPath); - image->pixPath = 0; + + if ( this->pixPath ) { + g_free(this->pixPath); + this->pixPath = 0; } - image->lastMod = 0; - if (image->href) { + + this->lastMod = 0; + + if (this->href) { GdkPixbuf *pixbuf; pixbuf = sp_image_repr_read_image ( - image->lastMod, - image->pixPath, + this->lastMod, + this->pixPath, //XML Tree being used directly while it shouldn't be. - object->getRepr()->attribute("xlink:href"), + this->getRepr()->attribute("xlink:href"), //XML Tree being used directly while it shouldn't be. - object->getRepr()->attribute("sodipodi:absref"), + this->getRepr()->attribute("sodipodi:absref"), doc->getBase()); + if (pixbuf) { pixbuf = sp_image_pixbuf_force_rgba (pixbuf); // BLIP #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - if ( image->color_profile ) + if ( this->color_profile ) { int imagewidth = gdk_pixbuf_get_width( pixbuf ); int imageheight = gdk_pixbuf_get_height( pixbuf ); @@ -784,13 +772,14 @@ void CImage::update(SPCtx *ctx, unsigned int flags) { DEBUG_MESSAGE( lcmsFive, "in 's sp_image_update. About to call colorprofile_get_handle()" ); #endif // DEBUG_LCMS guint profIntent = Inkscape::RENDERING_INTENT_UNKNOWN; - cmsHPROFILE prof = Inkscape::CMSSystem::getHandle( object->document, + cmsHPROFILE prof = Inkscape::CMSSystem::getHandle( this->document, &profIntent, - image->color_profile ); + this->color_profile ); if ( prof ) { cmsProfileClassSignature profileClass = cmsGetDeviceClass( prof ); if ( profileClass != cmsSigNamedColorClass ) { int intent = INTENT_PERCEPTUAL; + switch ( profIntent ) { case Inkscape::RENDERING_INTENT_RELATIVE_COLORIMETRIC: intent = INTENT_RELATIVE_COLORIMETRIC; @@ -807,6 +796,7 @@ void CImage::update(SPCtx *ctx, unsigned int flags) { default: intent = INTENT_PERCEPTUAL; } + cmsHPROFILE destProf = cmsCreate_sRGBProfile(); cmsHTRANSFORM transf = cmsCreateTransform( prof, TYPE_RGBA_8, @@ -847,41 +837,42 @@ void CImage::update(SPCtx *ctx, unsigned int flags) { } } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - image->pixbuf = pixbuf; + this->pixbuf = pixbuf; // convert to premultiplied native-endian ARGB for display with Cairo - convert_pixbuf_normal_to_argb32(image->pixbuf); + convert_pixbuf_normal_to_argb32(this->pixbuf); } } } - if (image->pixbuf) { + if (this->pixbuf) { /* fixme: We are slightly violating spec here (Lauris) */ - if (!image->width._set) { - image->width.computed = gdk_pixbuf_get_width(image->pixbuf); + if (!this->width._set) { + this->width.computed = gdk_pixbuf_get_width(this->pixbuf); } - if (!image->height._set) { - image->height.computed = gdk_pixbuf_get_height(image->pixbuf); + + if (!this->height._set) { + this->height.computed = gdk_pixbuf_get_height(this->pixbuf); } } - Geom::Point p(image->x.computed, image->y.computed); - Geom::Point wh(image->width.computed, image->height.computed); - image->clipbox = Geom::Rect(p, p + wh); + Geom::Point p(this->x.computed, this->y.computed); + Geom::Point wh(this->width.computed, this->height.computed); + this->clipbox = Geom::Rect(p, p + wh); - image->ox = image->x.computed; - image->oy = image->y.computed; + this->ox = this->x.computed; + this->oy = this->y.computed; - int pixwidth = gdk_pixbuf_get_width (image->pixbuf); - int pixheight = gdk_pixbuf_get_height (image->pixbuf); + int pixwidth = gdk_pixbuf_get_width (this->pixbuf); + int pixheight = gdk_pixbuf_get_height (this->pixbuf); - image->sx = image->width.computed / pixwidth; - image->sy = image->height.computed / pixheight; + this->sx = this->width.computed / pixwidth; + this->sy = this->height.computed / pixheight; // preserveAspectRatio calculate bounds / clipping rectangle -- EAF - if (image->pixbuf && (image->aspect_align != SP_ASPECT_NONE)) { + if (this->pixbuf && (this->aspect_align != SP_ASPECT_NONE)) { double x, y; - switch (image->aspect_align) { + switch (this->aspect_align) { case SP_ASPECT_XMIN_YMIN: x = 0.0; y = 0.0; @@ -924,69 +915,65 @@ void CImage::update(SPCtx *ctx, unsigned int flags) { break; } - if (image->aspect_clip == SP_ASPECT_SLICE) { - double scale = std::max(image->sx, image->sy); - image->sx = scale; - image->sy = scale; + if (this->aspect_clip == SP_ASPECT_SLICE) { + double scale = std::max(this->sx, this->sy); + this->sx = scale; + this->sy = scale; } else { - double scale = std::min(image->sx, image->sy); - image->sx = scale; - image->sy = scale; + double scale = std::min(this->sx, this->sy); + this->sx = scale; + this->sy = scale; } - double vw = pixwidth * image->sx; - double vh = pixheight * image->sy; - image->ox += x * (image->width.computed - vw); - image->oy += y * (image->height.computed - vh); + double vw = pixwidth * this->sx; + double vh = pixheight * this->sy; + this->ox += x * (this->width.computed - vw); + this->oy += y * (this->height.computed - vh); } - sp_image_update_canvas_image ((SPImage *) object); + sp_image_update_canvas_image ((SPImage *) this); } -void CImage::modified(unsigned int flags) { - SPImage* object = this->spimage; - - SPImage *image = SP_IMAGE (object); - +void SPImage::modified(unsigned int flags) { // CItem::onModified(flags); if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { - for (SPItemView *v = image->display; v != NULL; v = v->next) { + for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingImage *img = dynamic_cast(v->arenaitem); - img->setStyle(object->style); + img->setStyle(this->style); } } } -Inkscape::XML::Node *CImage::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) { - SPImage* object = this->spimage; - - SPImage *image = SP_IMAGE (object); - +Inkscape::XML::Node *SPImage::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:image"); } - repr->setAttribute("xlink:href", image->href); + repr->setAttribute("xlink:href", this->href); + /* fixme: Reset attribute if needed (Lauris) */ - if (image->x._set) { - sp_repr_set_svg_double(repr, "x", image->x.computed); + if (this->x._set) { + sp_repr_set_svg_double(repr, "x", this->x.computed); } - if (image->y._set) { - sp_repr_set_svg_double(repr, "y", image->y.computed); + + if (this->y._set) { + sp_repr_set_svg_double(repr, "y", this->y.computed); } - if (image->width._set) { - sp_repr_set_svg_double(repr, "width", image->width.computed); + + if (this->width._set) { + sp_repr_set_svg_double(repr, "width", this->width.computed); } - if (image->height._set) { - sp_repr_set_svg_double(repr, "height", image->height.computed); + + if (this->height._set) { + sp_repr_set_svg_double(repr, "height", this->height.computed); } //XML Tree being used directly here while it shouldn't be... - repr->setAttribute("preserveAspectRatio", object->getRepr()->attribute("preserveAspectRatio")); + repr->setAttribute("preserveAspectRatio", this->getRepr()->attribute("preserveAspectRatio")); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - if (image->color_profile) { - repr->setAttribute("color-profile", image->color_profile); + if (this->color_profile) { + repr->setAttribute("color-profile", this->color_profile); } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) @@ -995,26 +982,20 @@ Inkscape::XML::Node *CImage::write(Inkscape::XML::Document *xml_doc, Inkscape::X return repr; } -Geom::OptRect CImage::bbox(Geom::Affine const &transform, SPItem::BBoxType type) { - SPImage* item = this->spimage; - - SPImage const &image = *SP_IMAGE(item); +Geom::OptRect SPImage::bbox(Geom::Affine const &transform, SPItem::BBoxType type) { Geom::OptRect bbox; - if ((image.width.computed > 0.0) && (image.height.computed > 0.0)) { - bbox = Geom::Rect::from_xywh(image.x.computed, image.y.computed, image.width.computed, image.height.computed); + if ((this->width.computed > 0.0) && (this->height.computed > 0.0)) { + bbox = Geom::Rect::from_xywh(this->x.computed, this->y.computed, this->width.computed, this->height.computed); *bbox *= transform; } + return bbox; } -void CImage::print(SPPrintContext *ctx) { - SPImage* item = this->spimage; - - SPImage *image = SP_IMAGE(item); - - if (image->pixbuf && (image->width.computed > 0.0) && (image->height.computed > 0.0) ) { - GdkPixbuf *pb = gdk_pixbuf_copy(image->pixbuf); +void SPImage::print(SPPrintContext *ctx) { + if (this->pixbuf && (this->width.computed > 0.0) && (this->height.computed > 0.0) ) { + GdkPixbuf *pb = gdk_pixbuf_copy(this->pixbuf); convert_pixbuf_argb32_to_normal(pb); guchar *px = gdk_pixbuf_get_pixels(pb); @@ -1023,27 +1004,27 @@ void CImage::print(SPPrintContext *ctx) { int rs = gdk_pixbuf_get_rowstride(pb); int pixskip = gdk_pixbuf_get_n_channels(pb) * gdk_pixbuf_get_bits_per_sample(pb) / 8; - if (image->aspect_align == SP_ASPECT_NONE) { + if (this->aspect_align == SP_ASPECT_NONE) { Geom::Affine t; - Geom::Translate tp(image->x.computed, image->y.computed); - Geom::Scale s(image->width.computed, -image->height.computed); + Geom::Translate tp(this->x.computed, this->y.computed); + Geom::Scale s(this->width.computed, -this->height.computed); Geom::Translate ti(0.0, -1.0); t = s * tp; t = ti * t; - sp_print_image_R8G8B8A8_N(ctx, px, w, h, rs, t, item->style); + sp_print_image_R8G8B8A8_N(ctx, px, w, h, rs, t, this->style); } else { // preserveAspectRatio - double vw = image->width.computed / image->sx; - double vh = image->height.computed / image->sy; + double vw = this->width.computed / this->sx; + double vh = this->height.computed / this->sy; - int trimwidth = std::min(w, ceil(image->width.computed / vw * w)); - int trimheight = std::min(h, ceil(image->height.computed / vh * h)); - int trimx = std::max(0, floor((image->x.computed - image->ox) / vw * w)); - int trimy = std::max(0, floor((image->y.computed - image->oy) / vh * h)); + int trimwidth = std::min(w, ceil(this->width.computed / vw * w)); + int trimheight = std::min(h, ceil(this->height.computed / vh * h)); + int trimx = std::max(0, floor((this->x.computed - this->ox) / vw * w)); + int trimy = std::max(0, floor((this->y.computed - this->oy) / vh * h)); - double vx = std::max(image->ox, image->x.computed); - double vy = std::max(image->oy, image->y.computed); - double vcw = std::min(image->width.computed, vw); - double vch = std::min(image->height.computed, vh); + double vx = std::max(this->ox, this->x.computed); + double vy = std::max(this->oy, this->y.computed); + double vcw = std::min(this->width.computed, vw); + double vch = std::min(this->height.computed, vh); Geom::Affine t; Geom::Translate tp(vx, vy); @@ -1051,42 +1032,37 @@ void CImage::print(SPPrintContext *ctx) { Geom::Translate ti(0.0, -1.0); t = s * tp; t = ti * t; - sp_print_image_R8G8B8A8_N(ctx, px + trimx*pixskip + trimy*rs, trimwidth, trimheight, rs, t, item->style); + sp_print_image_R8G8B8A8_N(ctx, px + trimx*pixskip + trimy*rs, trimwidth, trimheight, rs, t, this->style); } } } -gchar* CImage::description() { - SPImage* item = this->spimage; - - SPImage *image = SP_IMAGE(item); +gchar* SPImage::description() { char *href_desc; - if (image->href) { - href_desc = (strncmp(image->href, "data:", 5) == 0) + + if (this->href) { + href_desc = (strncmp(this->href, "data:", 5) == 0) ? g_strdup(_("embedded")) - : xml_quote_strdup(image->href); + : xml_quote_strdup(this->href); } else { g_warning("Attempting to call strncmp() with a null pointer."); href_desc = g_strdup("(null_pointer)"); // we call g_free() on href_desc } - char *ret = ( image->pixbuf == NULL + char *ret = ( this->pixbuf == NULL ? g_strdup_printf(_("Image with bad reference: %s"), href_desc) : g_strdup_printf(_("Image %d × %d: %s"), - gdk_pixbuf_get_width(image->pixbuf), - gdk_pixbuf_get_height(image->pixbuf), + gdk_pixbuf_get_width(this->pixbuf), + gdk_pixbuf_get_height(this->pixbuf), href_desc) ); g_free(href_desc); return ret; } -Inkscape::DrawingItem* CImage::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - SPImage* item = this->spimage; - - SPImage * image = SP_IMAGE(item); +Inkscape::DrawingItem* SPImage::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { Inkscape::DrawingImage *ai = new Inkscape::DrawingImage(drawing); - sp_image_update_arenaitem(image, ai); + sp_image_update_arenaitem(this, ai); return ai; } @@ -1215,30 +1191,26 @@ static void sp_image_update_canvas_image(SPImage *image) } } -void CImage::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - SPImage* item = this->spimage; - +void SPImage::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { /* An image doesn't have any nodes to snap, but still we want to be able snap one image to another. Therefore we will create some snappoints at the corner, similar to a rect. If the image is rotated, then the snappoints will rotate with it. Again, just like a rect. */ - g_assert(item != NULL); - g_assert(SP_IS_IMAGE(item)); - - if (item->clip_ref->getObject()) { + if (this->clip_ref->getObject()) { //We are looking at a clipped image: do not return any snappoints, as these might be //far far away from the visible part from the clipped image //TODO Do return snappoints, but only when within visual bounding box } else { if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_IMG_CORNER)) { // The image has not been clipped: return its corners, which might be rotated for example - SPImage &image = *SP_IMAGE(item); - double const x0 = image.x.computed; - double const y0 = image.y.computed; - double const x1 = x0 + image.width.computed; - double const y1 = y0 + image.height.computed; - Geom::Affine const i2d (item->i2dt_affine ()); + double const x0 = this->x.computed; + double const y0 = this->y.computed; + double const x1 = x0 + this->width.computed; + double const y1 = y0 + this->height.computed; + + Geom::Affine const i2d (this->i2dt_affine ()); + p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(x0, y0) * i2d, Inkscape::SNAPSOURCE_IMG_CORNER, Inkscape::SNAPTARGET_IMG_CORNER)); p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(x0, y1) * i2d, Inkscape::SNAPSOURCE_IMG_CORNER, Inkscape::SNAPTARGET_IMG_CORNER)); p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(x1, y1) * i2d, Inkscape::SNAPSOURCE_IMG_CORNER, Inkscape::SNAPTARGET_IMG_CORNER)); @@ -1252,19 +1224,16 @@ void CImage::snappoints(std::vector &p, Inkscape:: * Transform x, y, set x, y, clear translation */ -Geom::Affine CImage::set_transform(Geom::Affine const &xform) { - SPImage* item = this->spimage; - - SPImage *image = SP_IMAGE(item); - +Geom::Affine SPImage::set_transform(Geom::Affine const &xform) { /* Calculate position in parent coords. */ - Geom::Point pos( Geom::Point(image->x.computed, image->y.computed) * xform ); + Geom::Point pos( Geom::Point(this->x.computed, this->y.computed) * xform ); /* This function takes care of translation and scaling, we return whatever parts we can't handle. */ Geom::Affine ret(Geom::Affine(xform).withoutTranslation()); Geom::Point const scale(hypot(ret[0], ret[1]), hypot(ret[2], ret[3])); + if ( scale[Geom::X] > MAGIC_EPSILON ) { ret[0] /= scale[Geom::X]; ret[1] /= scale[Geom::X]; @@ -1272,6 +1241,7 @@ Geom::Affine CImage::set_transform(Geom::Affine const &xform) { ret[0] = 1.0; ret[1] = 0.0; } + if ( scale[Geom::Y] > MAGIC_EPSILON ) { ret[2] /= scale[Geom::Y]; ret[3] /= scale[Geom::Y]; @@ -1280,15 +1250,15 @@ Geom::Affine CImage::set_transform(Geom::Affine const &xform) { ret[3] = 1.0; } - image->width = image->width.computed * scale[Geom::X]; - image->height = image->height.computed * scale[Geom::Y]; + this->width = this->width.computed * scale[Geom::X]; + this->height = this->height.computed * scale[Geom::Y]; /* Find position in item coords */ pos = pos * ret.inverse(); - image->x = pos[Geom::X]; - image->y = pos[Geom::Y]; + this->x = pos[Geom::X]; + this->y = pos[Geom::Y]; - item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); return ret; } @@ -1433,7 +1403,7 @@ static void sp_image_set_curve( SPImage *image ) image->curve = image->curve->unref(); } } else { - Geom::OptRect rect = image->cimage->bbox(Geom::identity(), SPItem::VISUAL_BBOX); + Geom::OptRect rect = image->bbox(Geom::identity(), SPItem::VISUAL_BBOX); SPCurve *c = SPCurve::new_from_rect(*rect, true); if (image->curve) { @@ -1507,7 +1477,7 @@ void sp_image_refresh_if_outdated( SPImage* image ) if ( st.st_mtime != image->lastMod ) { SPCtx *ctx = 0; unsigned int flags = SP_IMAGE_HREF_MODIFIED_FLAG; - image->cimage->update(ctx, flags); + image->update(ctx, flags); } } } -- cgit v1.2.3 From 8073924aacdda310fb7492750f78d5389b3186af Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 22:45:01 +0200 Subject: Merged Item. (bzr r11608.1.81) --- src/sp-image.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 442d0e539..632340ee4 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -514,9 +514,7 @@ namespace { bool imageRegistered = SPFactory::instance().registerObject("svg:image", createImage); } -SPImage::SPImage() : SPItem(), CItem(this) { - delete this->citem; - this->citem = this; +SPImage::SPImage() : SPItem() { this->cobject = this; this->aspect_clip = 0; @@ -545,7 +543,7 @@ SPImage::~SPImage() { } void SPImage::build(SPDocument *document, Inkscape::XML::Node *repr) { - CItem::build(document, repr); + SPItem::build(document, repr); this->readAttr( "xlink:href" ); this->readAttr( "x" ); @@ -591,7 +589,7 @@ void SPImage::release() { this->curve = this->curve->unref(); } - CItem::release(); + SPItem::release(); } void SPImage::set(unsigned int key, const gchar* value) { @@ -722,7 +720,7 @@ void SPImage::set(unsigned int key, const gchar* value) { #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) default: - CItem::set(key, value); + SPItem::set(key, value); break; } @@ -732,7 +730,7 @@ void SPImage::set(unsigned int key, const gchar* value) { void SPImage::update(SPCtx *ctx, unsigned int flags) { SPDocument *doc = this->document; - CItem::update(ctx, flags); + SPItem::update(ctx, flags); if (flags & SP_IMAGE_HREF_MODIFIED_FLAG) { if (this->pixbuf) { @@ -938,7 +936,7 @@ void SPImage::update(SPCtx *ctx, unsigned int flags) { } void SPImage::modified(unsigned int flags) { -// CItem::onModified(flags); +// SPItem::onModified(flags); if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { for (SPItemView *v = this->display; v != NULL; v = v->next) { @@ -981,7 +979,7 @@ Inkscape::XML::Node *SPImage::write(Inkscape::XML::Document *xml_doc, Inkscape:: } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - CItem::write(xml_doc, repr, flags); + SPItem::write(xml_doc, repr, flags); return repr; } -- cgit v1.2.3 From 27e2102f96a5554bcd5310ec11435d155773b279 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 7 Apr 2013 18:28:22 +0200 Subject: Merge Object and subclasses. Merging of SP- and C-classes complete. (bzr r11608.1.86) --- src/sp-image.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/sp-image.cpp') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 632340ee4..d4cd2eff2 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -515,8 +515,6 @@ namespace { } SPImage::SPImage() : SPItem() { - this->cobject = this; - this->aspect_clip = 0; this->x.unset(); -- cgit v1.2.3