diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-04-05 19:07:38 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-04-05 19:07:38 +0000 |
| commit | 61003d31ea058fdf94f4f80c753c3e38426f35e4 (patch) | |
| tree | de30fe5c58fc71682c9544448f8ef7f79de673cf /src | |
| parent | Merged more classes. (diff) | |
| download | inkscape-61003d31ea058fdf94f4f80c753c3e38426f35e4.tar.gz inkscape-61003d31ea058fdf94f4f80c753c3e38426f35e4.zip | |
Merged FlowX classes.
(bzr r11608.1.79)
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp-flowdiv.cpp | 220 | ||||
| -rw-r--r-- | src/sp-flowdiv.h | 124 | ||||
| -rw-r--r-- | src/sp-flowregion.cpp | 209 | ||||
| -rw-r--r-- | src/sp-flowregion.h | 46 | ||||
| -rw-r--r-- | src/sp-flowtext.cpp | 220 | ||||
| -rw-r--r-- | src/sp-flowtext.h | 24 | ||||
| -rw-r--r-- | src/sp-guide.cpp | 10 | ||||
| -rw-r--r-- | src/sp-image.cpp | 464 | ||||
| -rw-r--r-- | src/sp-image.h | 26 |
9 files changed, 479 insertions, 864 deletions
diff --git a/src/sp-flowdiv.cpp b/src/sp-flowdiv.cpp index 6c8f2c4e2..d99657bed 100644 --- a/src/sp-flowdiv.cpp +++ b/src/sp-flowdiv.cpp @@ -14,12 +14,6 @@ #include "sp-string.h" #include "document.h" -static void sp_flowdiv_init (SPFlowdiv *group); -static void sp_flowtspan_init (SPFlowtspan *group); -static void sp_flowpara_init (SPFlowpara *group); -static void sp_flowline_init (SPFlowline *group); -static void sp_flowregionbreak_init (SPFlowregionbreak *group); - #include "sp-factory.h" namespace { @@ -50,42 +44,21 @@ namespace { bool flowregionbreakRegistered = SPFactory::instance().registerObject("svg:flowRegionBreak", createFlowregionbreak); } -G_DEFINE_TYPE(SPFlowdiv, sp_flowdiv, G_TYPE_OBJECT); - -static void sp_flowdiv_class_init(SPFlowdivClass *klass) -{ -} - -CFlowdiv::CFlowdiv(SPFlowdiv* flowdiv) : CItem(flowdiv) { - this->spflowdiv = flowdiv; -} - -CFlowdiv::~CFlowdiv() { +SPFlowdiv::SPFlowdiv() : SPItem(), CItem(this) { + delete this->citem; + this->citem = this; + this->cobject = this; } -SPFlowdiv::SPFlowdiv() : SPItem() { - SPFlowdiv* group = this; - - group->cflowdiv = new CFlowdiv(group); - group->typeHierarchy.insert(typeid(SPFlowdiv)); - - delete group->citem; - group->citem = group->cflowdiv; - group->cobject = group->cflowdiv; +SPFlowdiv::~SPFlowdiv() { } -static void sp_flowdiv_init(SPFlowdiv *group) -{ - new (group) SPFlowdiv(); -} - -void CFlowdiv::release() { +void SPFlowdiv::release() { CItem::release(); } - -void CFlowdiv::update(SPCtx *ctx, unsigned int flags) { - SPFlowdiv* object = this->spflowdiv; +void SPFlowdiv::update(SPCtx *ctx, unsigned int flags) { + SPFlowdiv* object = this; SPItemCtx *ictx = reinterpret_cast<SPItemCtx *>(ctx); SPItemCtx cctx = *ictx; @@ -119,8 +92,8 @@ void CFlowdiv::update(SPCtx *ctx, unsigned int flags) { } } -void CFlowdiv::modified(unsigned int flags) { - SPFlowdiv* object = this->spflowdiv; +void SPFlowdiv::modified(unsigned int flags) { + SPFlowdiv* object = this; CItem::modified(flags); @@ -146,21 +119,21 @@ void CFlowdiv::modified(unsigned int flags) { } -void CFlowdiv::build(SPDocument *doc, Inkscape::XML::Node *repr) { - SPFlowdiv* object = this->spflowdiv; +void SPFlowdiv::build(SPDocument *doc, Inkscape::XML::Node *repr) { + SPFlowdiv* object = this; object->_requireSVGVersion(Inkscape::Version(1, 2)); CItem::build(doc, repr); } -void CFlowdiv::set(unsigned int key, const gchar* value) { +void SPFlowdiv::set(unsigned int key, const gchar* value) { CItem::set(key, value); } -Inkscape::XML::Node* CFlowdiv::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPFlowdiv* object = this->spflowdiv; +Inkscape::XML::Node* SPFlowdiv::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPFlowdiv* object = this; if ( flags & SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { @@ -206,41 +179,22 @@ Inkscape::XML::Node* CFlowdiv::write(Inkscape::XML::Document *xml_doc, Inkscape: /* * */ -G_DEFINE_TYPE(SPFlowtspan, sp_flowtspan, G_TYPE_OBJECT); - -static void sp_flowtspan_class_init(SPFlowtspanClass *klass) -{ -} - -CFlowtspan::CFlowtspan(SPFlowtspan* flowtspan) : CItem(flowtspan) { - this->spflowtspan = flowtspan; -} - -CFlowtspan::~CFlowtspan() { -} - -SPFlowtspan::SPFlowtspan() : SPItem() { - SPFlowtspan* group = this; - group->cflowtspan = new CFlowtspan(group); - group->typeHierarchy.insert(typeid(SPFlowtspan)); - - delete group->citem; - group->citem = group->cflowtspan; - group->cobject = group->cflowtspan; +SPFlowtspan::SPFlowtspan() : SPItem(), CItem(this) { + delete this->citem; + this->citem = this; + this->cobject = this; } -static void sp_flowtspan_init(SPFlowtspan *group) -{ - new (group) SPFlowtspan(); +SPFlowtspan::~SPFlowtspan() { } -void CFlowtspan::release() { +void SPFlowtspan::release() { CItem::release(); } -void CFlowtspan::update(SPCtx *ctx, unsigned int flags) { - SPFlowtspan* object = this->spflowtspan; +void SPFlowtspan::update(SPCtx *ctx, unsigned int flags) { + SPFlowtspan* object = this; SPItemCtx *ictx = reinterpret_cast<SPItemCtx *>(ctx); SPItemCtx cctx = *ictx; @@ -275,8 +229,8 @@ void CFlowtspan::update(SPCtx *ctx, unsigned int flags) { } } -void CFlowtspan::modified(unsigned int flags) { - SPFlowtspan* object = this->spflowtspan; +void SPFlowtspan::modified(unsigned int flags) { + SPFlowtspan* object = this; CItem::modified(flags); @@ -302,18 +256,18 @@ void CFlowtspan::modified(unsigned int flags) { } -void CFlowtspan::build(SPDocument *doc, Inkscape::XML::Node *repr) +void SPFlowtspan::build(SPDocument *doc, Inkscape::XML::Node *repr) { CItem::build(doc, repr); } -void CFlowtspan::set(unsigned int key, const gchar* value) { +void SPFlowtspan::set(unsigned int key, const gchar* value) { CItem::set(key, value); } -Inkscape::XML::Node *CFlowtspan::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node *SPFlowtspan::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPFlowtspan* object = this->spflowtspan; + SPFlowtspan* object = this; if ( flags&SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { @@ -361,43 +315,22 @@ Inkscape::XML::Node *CFlowtspan::write(Inkscape::XML::Document *xml_doc, Inkscap /* * */ -G_DEFINE_TYPE(SPFlowpara, sp_flowpara, G_TYPE_OBJECT); - -static void sp_flowpara_class_init(SPFlowparaClass *klass) -{ -} - -CFlowpara::CFlowpara(SPFlowpara* flowpara) : CItem(flowpara) { - this->spflowpara = flowpara; -} - -CFlowpara::~CFlowpara() { +SPFlowpara::SPFlowpara() : SPItem(), CItem(this) { + delete this->citem; + this->citem = this; + this->cobject = this; } -SPFlowpara::SPFlowpara() : SPItem() { - SPFlowpara* group = this; - - group->cflowpara = new CFlowpara(group); - group->typeHierarchy.insert(typeid(SPFlowpara)); - - delete group->citem; - group->citem = group->cflowpara; - group->cobject = group->cflowpara; +SPFlowpara::~SPFlowpara() { } -static void sp_flowpara_init (SPFlowpara *group) -{ - new (group) SPFlowpara(); -} - -void CFlowpara::release() { +void SPFlowpara::release() { CItem::release(); } - -void CFlowpara::update(SPCtx *ctx, unsigned int flags) +void SPFlowpara::update(SPCtx *ctx, unsigned int flags) { - SPFlowpara* object = this->spflowpara; + SPFlowpara* object = this; SPItemCtx *ictx = reinterpret_cast<SPItemCtx *>(ctx); SPItemCtx cctx = *ictx; @@ -432,8 +365,8 @@ void CFlowpara::update(SPCtx *ctx, unsigned int flags) } } -void CFlowpara::modified(unsigned int flags) { - SPFlowpara* object = this->spflowpara; +void SPFlowpara::modified(unsigned int flags) { + SPFlowpara* object = this; CItem::modified(flags); @@ -459,18 +392,18 @@ void CFlowpara::modified(unsigned int flags) { } -void CFlowpara::build(SPDocument *doc, Inkscape::XML::Node *repr) +void SPFlowpara::build(SPDocument *doc, Inkscape::XML::Node *repr) { CItem::build(doc, repr); } -void CFlowpara::set(unsigned int key, const gchar* value) { +void SPFlowpara::set(unsigned int key, const gchar* value) { CItem::set(key, value); } -Inkscape::XML::Node *CFlowpara::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node *SPFlowpara::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPFlowpara* object = this->spflowpara; + SPFlowpara* object = this; if ( flags&SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) repr = xml_doc->createElement("svg:flowPara"); @@ -514,40 +447,20 @@ Inkscape::XML::Node *CFlowpara::write(Inkscape::XML::Document *xml_doc, Inkscape /* * */ -G_DEFINE_TYPE(SPFlowline, sp_flowline, G_TYPE_OBJECT); - -static void sp_flowline_class_init(SPFlowlineClass *klass) -{ -} - -CFlowline::CFlowline(SPFlowline* flowline) : CObject(flowline) { - this->spflowline = flowline; -} - -CFlowline::~CFlowline() { -} -SPFlowline::SPFlowline() : SPObject() { - SPFlowline* group = this; - - group->cflowline = new CFlowline(group); - group->typeHierarchy.insert(typeid(SPFlowline)); - - delete group->cobject; - group->cobject = group->cflowline; +SPFlowline::SPFlowline() : SPObject(), CObject(this) { + delete this->cobject; + this->cobject = this; } -static void sp_flowline_init(SPFlowline *group) -{ - new (group) SPFlowline(); +SPFlowline::~SPFlowline() { } -void CFlowline::release() { +void SPFlowline::release() { CObject::release(); } - -void CFlowline::modified(unsigned int flags) { +void SPFlowline::modified(unsigned int flags) { CObject::modified(flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { @@ -556,7 +469,7 @@ void CFlowline::modified(unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; } -Inkscape::XML::Node *CFlowline::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node *SPFlowline::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ( flags & SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { @@ -574,39 +487,20 @@ Inkscape::XML::Node *CFlowline::write(Inkscape::XML::Document *xml_doc, Inkscape /* * */ -G_DEFINE_TYPE(SPFlowregionbreak, sp_flowregionbreak, G_TYPE_OBJECT); - -static void sp_flowregionbreak_class_init(SPFlowregionbreakClass *klass) -{ -} -CFlowregionbreak::CFlowregionbreak(SPFlowregionbreak* flowregionbreak) : CObject(flowregionbreak) { - this->spflowregionbreak = flowregionbreak; +SPFlowregionbreak::SPFlowregionbreak() : SPObject(), CObject(this) { + delete this->cobject; + this->cobject = this; } -CFlowregionbreak::~CFlowregionbreak() { -} - -SPFlowregionbreak::SPFlowregionbreak() : SPObject() { - SPFlowregionbreak* group = this; - - group->cflowregionbreak = new CFlowregionbreak(group); - group->typeHierarchy.insert(typeid(SPFlowregionbreak)); - - delete group->cobject; - group->cobject = group->cflowregionbreak; -} - -static void sp_flowregionbreak_init(SPFlowregionbreak *group) -{ - new (group) SPFlowregionbreak(); +SPFlowregionbreak::~SPFlowregionbreak() { } -void CFlowregionbreak::release() { +void SPFlowregionbreak::release() { CObject::release(); } -void CFlowregionbreak::modified(unsigned int flags) { +void SPFlowregionbreak::modified(unsigned int flags) { CObject::modified(flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { @@ -615,7 +509,7 @@ void CFlowregionbreak::modified(unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; } -Inkscape::XML::Node *CFlowregionbreak::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node *SPFlowregionbreak::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ( flags & SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { diff --git a/src/sp-flowdiv.h b/src/sp-flowdiv.h index f95c81a69..a4973cb9d 100644 --- a/src/sp-flowdiv.h +++ b/src/sp-flowdiv.h @@ -7,89 +7,26 @@ #include "sp-object.h" #include "sp-item.h" -#define SP_TYPE_FLOWDIV (sp_flowdiv_get_type ()) #define SP_FLOWDIV(obj) ((SPFlowdiv*)obj) -#define SP_IS_FLOWDIV(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFlowdiv))) +#define SP_IS_FLOWDIV(obj) (dynamic_cast<const SPFlowdiv*>((SPObject*)obj)) -#define SP_TYPE_FLOWTSPAN (sp_flowtspan_get_type ()) #define SP_FLOWTSPAN(obj) ((SPFlowtspan*)obj) -#define SP_IS_FLOWTSPAN(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFlowtspan))) +#define SP_IS_FLOWTSPAN(obj) (dynamic_cast<const SPFlowtspan*>((SPObject*)obj)) -#define SP_TYPE_FLOWPARA (sp_flowpara_get_type ()) #define SP_FLOWPARA(obj) ((SPFlowpara*)obj) -#define SP_IS_FLOWPARA(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFlowpara))) +#define SP_IS_FLOWPARA(obj) (dynamic_cast<const SPFlowpara*>((SPObject*)obj)) -#define SP_TYPE_FLOWLINE (sp_flowline_get_type ()) #define SP_FLOWLINE(obj) ((SPFlowline*)obj) -#define SP_IS_FLOWLINE(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFlowline))) +#define SP_IS_FLOWLINE(obj) (dynamic_cast<const SPFlowline*>((SPObject*)obj)) -#define SP_TYPE_FLOWREGIONBREAK (sp_flowregionbreak_get_type ()) #define SP_FLOWREGIONBREAK(obj) ((SPFlowregionbreak*)obj) -#define SP_IS_FLOWREGIONBREAK(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFlowregionbreak))) - -class CFlowdiv; -class CFlowtspan; -class CFlowpara; -class CFlowline; -class CFlowregionbreak; +#define SP_IS_FLOWREGIONBREAK(obj) (dynamic_cast<const SPFlowregionbreak*>((SPObject*)obj)) // these 3 are derivatives of SPItem to get the automatic style handling -class SPFlowdiv : public SPItem { +class SPFlowdiv : public SPItem, public CItem { public: SPFlowdiv(); - CFlowdiv* cflowdiv; -}; - -class SPFlowtspan : public SPItem { -public: - SPFlowtspan(); - CFlowtspan* cflowtspan; -}; - -class SPFlowpara : public SPItem { -public: - SPFlowpara(); - CFlowpara* cflowpara; -}; - -// these do not need any style -class SPFlowline : public SPObject { -public: - SPFlowline(); - CFlowline* cflowline; -}; - -class SPFlowregionbreak : public SPObject { -public: - SPFlowregionbreak(); - CFlowregionbreak* cflowregionbreak; -}; - -struct SPFlowdivClass { - SPItemClass parent_class; -}; - -struct SPFlowtspanClass { - SPItemClass parent_class; -}; - -struct SPFlowparaClass { - SPItemClass parent_class; -}; - -struct SPFlowlineClass { - SPObjectClass parent_class; -}; - -struct SPFlowregionbreakClass { - SPObjectClass parent_class; -}; - - -class CFlowdiv : public CItem { -public: - CFlowdiv(SPFlowdiv* flowdiv); - virtual ~CFlowdiv(); + virtual ~SPFlowdiv(); virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual void release(); @@ -98,15 +35,12 @@ public: virtual void set(unsigned int key, gchar const* value); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - -protected: - SPFlowdiv* spflowdiv; }; -class CFlowtspan : public CItem { +class SPFlowtspan : public SPItem, public CItem { public: - CFlowtspan(SPFlowtspan* flowtspan); - virtual ~CFlowtspan(); + SPFlowtspan(); + virtual ~SPFlowtspan(); virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual void release(); @@ -115,15 +49,12 @@ public: virtual void set(unsigned int key, gchar const* value); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - -protected: - SPFlowtspan* spflowtspan; }; -class CFlowpara : public CItem { +class SPFlowpara : public SPItem, public CItem { public: - CFlowpara(SPFlowpara* flowpara); - virtual ~CFlowpara(); + SPFlowpara(); + virtual ~SPFlowpara(); virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual void release(); @@ -132,44 +63,29 @@ public: virtual void set(unsigned int key, gchar const* value); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - -protected: - SPFlowpara* spflowpara; }; -class CFlowline : public CObject { +// these do not need any style +class SPFlowline : public SPObject, public CObject { public: - CFlowline(SPFlowline* flowline); - virtual ~CFlowline(); + SPFlowline(); + virtual ~SPFlowline(); virtual void release(); virtual void modified(unsigned int flags); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - -protected: - SPFlowline* spflowline; }; -class CFlowregionbreak : public CObject { +class SPFlowregionbreak : public SPObject, public CObject { public: - CFlowregionbreak(SPFlowregionbreak* flowregionbreak); - virtual ~CFlowregionbreak(); + SPFlowregionbreak(); + virtual ~SPFlowregionbreak(); virtual void release(); virtual void modified(unsigned int flags); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - -protected: - SPFlowregionbreak* spflowregionbreak; }; - -GType sp_flowdiv_get_type (void); -GType sp_flowtspan_get_type (void); -GType sp_flowpara_get_type (void); -GType sp_flowline_get_type (void); -GType sp_flowregionbreak_get_type (void); - #endif diff --git a/src/sp-flowregion.cpp b/src/sp-flowregion.cpp index bc9f6aeda..bcdb6705a 100644 --- a/src/sp-flowregion.cpp +++ b/src/sp-flowregion.cpp @@ -20,13 +20,9 @@ #include "display/canvas-bpath.h" - #include "livarot/Path.h" #include "livarot/Shape.h" -static void sp_flowregion_init (SPFlowregion *group); -static void sp_flowregion_dispose (GObject *object); - #include "sp-factory.h" namespace { @@ -42,81 +38,41 @@ namespace { bool flowregionExcludeRegistered = SPFactory::instance().registerObject("svg:flowRegionExclude", createFlowregionExclude); } -G_DEFINE_TYPE(SPFlowregion, sp_flowregion, G_TYPE_OBJECT); - -static void sp_flowregionexclude_init (SPFlowregionExclude *group); -static void sp_flowregionexclude_dispose (GObject *object); - - static void GetDest(SPObject* child,Shape **computed); -static void -sp_flowregion_class_init (SPFlowregionClass *klass) -{ - GObjectClass * object_class; - object_class = (GObjectClass *) klass; - object_class->dispose = sp_flowregion_dispose; -} -CFlowregion::CFlowregion(SPFlowregion* flowregion) : CItem(flowregion) { - this->spflowregion = flowregion; -} +SPFlowregion::SPFlowregion() : SPItem(), CItem(this) { + delete this->citem; + this->citem = this; + this->cobject = this; -CFlowregion::~CFlowregion() { + new (&this->computed) std::vector<Shape*>; } -SPFlowregion::SPFlowregion() : SPItem() { - SPFlowregion* group = this; - - group->cflowregion = new CFlowregion(group); - group->typeHierarchy.insert(typeid(SPFlowregion)); - - delete group->citem; - group->citem = group->cflowregion; - group->cobject = group->cflowregion; - - new (&group->computed) std::vector<Shape*>; -} - -static void -sp_flowregion_init (SPFlowregion *group) -{ - new (group) SPFlowregion(); -} - -static void -sp_flowregion_dispose(GObject *object) -{ - SPFlowregion *group=(SPFlowregion *)object; - for (std::vector<Shape*>::iterator it = group->computed.begin() ; it != group->computed.end() ; ++it) +SPFlowregion::~SPFlowregion() { + for (std::vector<Shape*>::iterator it = this->computed.begin() ; it != this->computed.end() ; ++it) { delete *it; - group->computed.~vector<Shape*>(); -} + } -void CFlowregion::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - SPFlowregion* object = this->spflowregion; + this->computed.~vector<Shape*>(); +} +void SPFlowregion::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { CItem::child_added(child, ref); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } /* fixme: hide (Lauris) */ -void CFlowregion::remove_child(Inkscape::XML::Node * child) { - SPFlowregion* object = this->spflowregion; - +void SPFlowregion::remove_child(Inkscape::XML::Node * child) { CItem::remove_child(child); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } -void CFlowregion::update(SPCtx *ctx, unsigned int flags) { - SPFlowregion* object = this->spflowregion; - - SPFlowregion *group = SP_FLOWREGION(object); - +void SPFlowregion::update(SPCtx *ctx, unsigned int flags) { SPItemCtx *ictx = reinterpret_cast<SPItemCtx *>(ctx); SPItemCtx cctx = *ictx; @@ -125,17 +81,22 @@ void CFlowregion::update(SPCtx *ctx, unsigned int flags) { if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } + flags &= SP_OBJECT_MODIFIED_CASCADE; GSList *l = NULL; - for ( SPObject *child = object->firstChild() ; child ; child = child->getNext() ) { + + for ( SPObject *child = this->firstChild() ; child ; child = child->getNext() ) { sp_object_ref(child); l = g_slist_prepend(l, child); } + l = g_slist_reverse(l); + while (l) { SPObject *child = SP_OBJECT(l->data); l = g_slist_remove(l, child); + if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { if (SP_IS_ITEM (child)) { SPItem const &chi = *SP_ITEM(child); @@ -146,10 +107,11 @@ void CFlowregion::update(SPCtx *ctx, unsigned int flags) { child->updateDisplay(ctx, flags); } } + sp_object_unref(child); } - group->UpdateComputed(); + this->UpdateComputed(); } void SPFlowregion::UpdateComputed(void) @@ -166,42 +128,45 @@ void SPFlowregion::UpdateComputed(void) } } -void CFlowregion::modified(guint flags) { - SPFlowregion* object = this->spflowregion; - +void SPFlowregion::modified(guint flags) { if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } + flags &= SP_OBJECT_MODIFIED_CASCADE; GSList *l = NULL; - for ( SPObject *child = object->firstChild() ; child ; child = child->getNext() ) { + + for ( SPObject *child = this->firstChild() ; child ; child = child->getNext() ) { sp_object_ref(child); l = g_slist_prepend(l, child); } + l = g_slist_reverse(l); + while (l) { SPObject *child = SP_OBJECT(l->data); l = g_slist_remove(l, child); + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); } + sp_object_unref(child); } } -Inkscape::XML::Node *CFlowregion::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPFlowregion* object = this->spflowregion; - +Inkscape::XML::Node *SPFlowregion::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if (flags & SP_OBJECT_WRITE_BUILD) { if ( repr == NULL ) { repr = xml_doc->createElement("svg:flowRegion"); } GSList *l = NULL; - for ( SPObject *child = object->firstChild() ; child; child = child->getNext() ) { + for ( SPObject *child = this->firstChild() ; child; child = child->getNext() ) { if ( !SP_IS_TITLE(child) && !SP_IS_DESC(child) ) { Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags); + if (crepr) { l = g_slist_prepend(l, crepr); } @@ -215,7 +180,7 @@ Inkscape::XML::Node *CFlowregion::write(Inkscape::XML::Document *xml_doc, Inksca } } else { - for ( SPObject *child = object->firstChild() ; child; child = child->getNext() ) { + for ( SPObject *child = this->firstChild() ; child; child = child->getNext() ) { if ( !SP_IS_TITLE(child) && !SP_IS_DESC(child) ) { child->updateRepr(flags); } @@ -227,7 +192,7 @@ Inkscape::XML::Node *CFlowregion::write(Inkscape::XML::Document *xml_doc, Inksca return repr; } -gchar* CFlowregion::description() { +gchar* SPFlowregion::description() { // TRANSLATORS: "Flow region" is an area where text is allowed to flow return g_strdup_printf(_("Flow region")); } @@ -235,77 +200,37 @@ gchar* CFlowregion::description() { /* * */ +SPFlowregionExclude::SPFlowregionExclude() : SPItem(), CItem(this) { + delete this->citem; + this->citem = this; + this->cobject = this; -G_DEFINE_TYPE(SPFlowregionExclude, sp_flowregionexclude, G_TYPE_OBJECT); - -static void -sp_flowregionexclude_class_init (SPFlowregionExcludeClass *klass) -{ - GObjectClass * object_class; - object_class = (GObjectClass *) klass; - object_class->dispose = sp_flowregionexclude_dispose; -} - -CFlowregionExclude::CFlowregionExclude(SPFlowregionExclude* flowregionexclude) : CItem(flowregionexclude) { - this->spflowregionexclude = flowregionexclude; -} - -CFlowregionExclude::~CFlowregionExclude() { -} - -SPFlowregionExclude::SPFlowregionExclude() : SPItem() { - SPFlowregionExclude* group = this; - - group->cflowregionexclude = new CFlowregionExclude(group); - group->typeHierarchy.insert(typeid(SPFlowregionExclude)); - - delete group->citem; - group->citem = group->cflowregionexclude; - group->cobject = group->cflowregionexclude; - - group->computed = NULL; + this->computed = NULL; } -static void -sp_flowregionexclude_init (SPFlowregionExclude *group) -{ - new (group) SPFlowregionExclude(); -} - -static void -sp_flowregionexclude_dispose(GObject *object) -{ - SPFlowregionExclude *group=(SPFlowregionExclude *)object; - if (group->computed) { - delete group->computed; - group->computed = NULL; +SPFlowregionExclude::~SPFlowregionExclude() { + if (this->computed) { + delete this->computed; + this->computed = NULL; } } -void CFlowregionExclude::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - SPFlowregionExclude* object = this->spflowregionexclude; - +void SPFlowregionExclude::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { CItem::child_added(child, ref); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } /* fixme: hide (Lauris) */ -void CFlowregionExclude::remove_child(Inkscape::XML::Node * child) { - SPFlowregionExclude* object = this->spflowregionexclude; - +void SPFlowregionExclude::remove_child(Inkscape::XML::Node * child) { CItem::remove_child(child); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } -void CFlowregionExclude::update(SPCtx *ctx, unsigned int flags) { - SPFlowregionExclude* object = this->spflowregionexclude; - - SPFlowregionExclude *group = SP_FLOWREGIONEXCLUDE (object); - +void SPFlowregionExclude::update(SPCtx *ctx, unsigned int flags) { SPItemCtx *ictx = reinterpret_cast<SPItemCtx *>(ctx); SPItemCtx cctx = *ictx; @@ -314,17 +239,22 @@ void CFlowregionExclude::update(SPCtx *ctx, unsigned int flags) { if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } + flags &= SP_OBJECT_MODIFIED_CASCADE; GSList *l = NULL; - for ( SPObject *child = object->firstChild() ; child ; child = child->getNext() ) { + + for ( SPObject *child = this->firstChild() ; child ; child = child->getNext() ) { sp_object_ref(child); l = g_slist_prepend(l, child); } + l = g_slist_reverse (l); + while (l) { SPObject *child = SP_OBJECT(l->data); l = g_slist_remove(l, child); + if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { if (SP_IS_ITEM (child)) { SPItem const &chi = *SP_ITEM(child); @@ -335,10 +265,11 @@ void CFlowregionExclude::update(SPCtx *ctx, unsigned int flags) { child->updateDisplay(ctx, flags); } } + sp_object_unref(child); } - group->UpdateComputed(); + this->UpdateComputed(); } @@ -354,41 +285,45 @@ void SPFlowregionExclude::UpdateComputed(void) } } -void CFlowregionExclude::modified(guint flags) { - SPFlowregionExclude* object = this->spflowregionexclude; - +void SPFlowregionExclude::modified(guint flags) { if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } + flags &= SP_OBJECT_MODIFIED_CASCADE; GSList *l = NULL; - for ( SPObject *child = object->firstChild() ; child ; child = child->getNext() ) { + + for ( SPObject *child = this->firstChild() ; child ; child = child->getNext() ) { sp_object_ref(child); l = g_slist_prepend(l, child); } + l = g_slist_reverse (l); + while (l) { SPObject *child = SP_OBJECT(l->data); l = g_slist_remove(l, child); + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); } + sp_object_unref(child); } } -Inkscape::XML::Node *CFlowregionExclude::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPFlowregionExclude* object = this->spflowregionexclude; - +Inkscape::XML::Node *SPFlowregionExclude::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if (flags & SP_OBJECT_WRITE_BUILD) { if ( repr == NULL ) { repr = xml_doc->createElement("svg:flowRegionExclude"); } GSList *l = NULL; - for ( SPObject *child = object->firstChild() ; child; child = child->getNext() ) { + + for ( SPObject *child = this->firstChild() ; child; child = child->getNext() ) { Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags); + if (crepr) { l = g_slist_prepend(l, crepr); } @@ -401,7 +336,7 @@ Inkscape::XML::Node *CFlowregionExclude::write(Inkscape::XML::Document *xml_doc, } } else { - for ( SPObject *child = object->firstChild() ; child; child = child->getNext() ) { + for ( SPObject *child = this->firstChild() ; child; child = child->getNext() ) { child->updateRepr(flags); } } @@ -411,7 +346,7 @@ Inkscape::XML::Node *CFlowregionExclude::write(Inkscape::XML::Document *xml_doc, return repr; } -gchar* CFlowregionExclude::description() { +gchar* SPFlowregionExclude::description() { /* TRANSLATORS: A region "cut out of" a flow region; text is not allowed to flow inside the * flow excluded region. flowRegionExclude in SVG 1.2: see * http://www.w3.org/TR/2004/WD-SVG12-20041027/flow.html#flowRegion-elem and diff --git a/src/sp-flowregion.h b/src/sp-flowregion.h index b4faa78ef..8eb6218c9 100644 --- a/src/sp-flowregion.h +++ b/src/sp-flowregion.h @@ -6,39 +6,25 @@ #include "sp-item.h" -#define SP_TYPE_FLOWREGION (sp_flowregion_get_type ()) #define SP_FLOWREGION(obj) ((SPFlowregion*)obj) -#define SP_IS_FLOWREGION(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFlowregion))) +#define SP_IS_FLOWREGION(obj) (dynamic_cast<const SPFlowregion*>((SPObject*)obj)) -#define SP_TYPE_FLOWREGIONEXCLUDE (sp_flowregionexclude_get_type ()) #define SP_FLOWREGIONEXCLUDE(obj) ((SPFlowregionExclude*)obj) -#define SP_IS_FLOWREGIONEXCLUDE(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFlowregionExclude))) +#define SP_IS_FLOWREGIONEXCLUDE(obj) (dynamic_cast<const SPFlowregionExclude*>((SPObject*)obj)) class Path; class Shape; class flow_dest; class FloatLigne; -class CFlowregion; -class CFlowregionExclude; -class SPFlowregion : public SPItem { +class SPFlowregion : public SPItem, public CItem { public: SPFlowregion(); - CFlowregion* cflowregion; + virtual ~SPFlowregion(); std::vector<Shape*> computed; void UpdateComputed(void); -}; - -struct SPFlowregionClass { - SPItemClass parent_class; -}; - -class CFlowregion : public CItem { -public: - CFlowregion(SPFlowregion* flowregion); - virtual ~CFlowregion(); virtual void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); virtual void remove_child(Inkscape::XML::Node *child); @@ -46,31 +32,16 @@ public: virtual void modified(guint flags); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); virtual gchar *description(); - -protected: - SPFlowregion* spflowregion; }; -GType sp_flowregion_get_type (void); - -class SPFlowregionExclude : public SPItem { +class SPFlowregionExclude : public SPItem, public CItem { public: SPFlowregionExclude(); - CFlowregionExclude* cflowregionexclude; + virtual ~SPFlowregionExclude(); Shape *computed; void UpdateComputed(void); -}; - -struct SPFlowregionExcludeClass { - SPItemClass parent_class; -}; - -class CFlowregionExclude : public CItem { -public: - CFlowregionExclude(SPFlowregionExclude* flowregionexclude); - virtual ~CFlowregionExclude(); virtual void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); virtual void remove_child(Inkscape::XML::Node *child); @@ -78,11 +49,6 @@ public: virtual void modified(guint flags); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); virtual gchar *description(); - -protected: - SPFlowregionExclude* spflowregionexclude; }; -GType sp_flowregionexclude_get_type (void); - #endif diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 1d08b8256..8cdf52000 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -33,10 +33,6 @@ #include "display/drawing-text.h" - -static void sp_flowtext_init(SPFlowtext *group); -static void sp_flowtext_dispose(GObject *object); - #include "sp-factory.h" namespace { @@ -47,71 +43,35 @@ namespace { bool flowtextRegistered = SPFactory::instance().registerObject("svg:flowRoot", createFlowtext); } -G_DEFINE_TYPE(SPFlowtext, sp_flowtext, G_TYPE_OBJECT); - -static void -sp_flowtext_class_init(SPFlowtextClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - - object_class->dispose = sp_flowtext_dispose; -} - -CFlowtext::CFlowtext(SPFlowtext* flowtext) : CItem(flowtext) { - this->spflowtext = flowtext; -} - -CFlowtext::~CFlowtext() { -} - -SPFlowtext::SPFlowtext() : SPItem() { - SPFlowtext* group = this; - - group->cflowtext = new CFlowtext(group); - group->typeHierarchy.insert(typeid(SPFlowtext)); - - delete group->citem; - group->citem = group->cflowtext; - group->cobject = group->cflowtext; - - group->par_indent = 0; - new (&group->layout) Inkscape::Text::Layout(); -} +SPFlowtext::SPFlowtext() : SPItem(), CItem(this) { + delete this->citem; + this->citem = this; + this->cobject = this; -static void -sp_flowtext_init(SPFlowtext *group) -{ - new (group) SPFlowtext(); + this->par_indent = 0; + new (&this->layout) Inkscape::Text::Layout(); } -static void -sp_flowtext_dispose(GObject *object) -{ - SPFlowtext *group = (SPFlowtext*)object; - - group->layout.~Layout(); +SPFlowtext::~SPFlowtext() { + this->layout.~Layout(); } -void CFlowtext::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) { +void SPFlowtext::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) { CItem::child_added(child, ref); - this->spflowtext->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } /* fixme: hide (Lauris) */ -void CFlowtext::remove_child(Inkscape::XML::Node* child) { +void SPFlowtext::remove_child(Inkscape::XML::Node* child) { CItem::remove_child(child); - this->spflowtext->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); } - -void CFlowtext::update(SPCtx* ctx, unsigned int flags) { - SPFlowtext* object = this->spflowtext; - - SPFlowtext *group = SP_FLOWTEXT(object); +void SPFlowtext::update(SPCtx* ctx, unsigned int flags) { SPItemCtx *ictx = (SPItemCtx *) ctx; SPItemCtx cctx = *ictx; @@ -121,14 +81,18 @@ void CFlowtext::update(SPCtx* ctx, unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; GSList *l = NULL; - for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) { + + for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) { sp_object_ref(child); l = g_slist_prepend(l, child); } + l = g_slist_reverse(l); + while (l) { SPObject *child = SP_OBJECT(l->data); l = g_slist_remove(l, child); + if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { if (SP_IS_ITEM(child)) { SPItem const &chi = *SP_ITEM(child); @@ -139,42 +103,46 @@ void CFlowtext::update(SPCtx* ctx, unsigned int flags) { child->updateDisplay(ctx, flags); } } + sp_object_unref(child); } - group->rebuildLayout(); + this->rebuildLayout(); - Geom::OptRect pbox = group->geometricBounds(); - for (SPItemView *v = group->display; v != NULL; v = v->next) { + Geom::OptRect pbox = this->geometricBounds(); + + for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem); - group->_clearFlow(g); - g->setStyle(object->style); + this->_clearFlow(g); + g->setStyle(this->style); // pass the bbox of the flowtext object as paintbox (used for paintserver fills) - group->layout.show(g, pbox); + this->layout.show(g, pbox); } } -void CFlowtext::modified(unsigned int flags) { - SPFlowtext* object = this->spflowtext; - SPObject *ft = object; +void SPFlowtext::modified(unsigned int flags) { SPObject *region = NULL; - if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + if (flags & SP_OBJECT_MODIFIED_FLAG) { + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + } + flags &= SP_OBJECT_MODIFIED_CASCADE; // FIXME: the below stanza is copied over from sp_text_modified, consider factoring it out if (flags & ( SP_OBJECT_STYLE_MODIFIED_FLAG )) { - SPFlowtext *text = SP_FLOWTEXT(object); + SPFlowtext *text = SP_FLOWTEXT(this); Geom::OptRect pbox = text->geometricBounds(); + for (SPItemView* v = text->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem); text->_clearFlow(g); - g->setStyle(object->style); + g->setStyle(this->style); text->layout.show(g, pbox); } } - for ( SPObject *o = ft->firstChild() ; o ; o = o->getNext() ) { + for ( SPObject *o = this->firstChild() ; o ; o = o->getNext() ) { if (SP_IS_FLOWREGION(o)) { region = o; break; @@ -188,36 +156,33 @@ void CFlowtext::modified(unsigned int flags) { } } -void CFlowtext::build(SPDocument* doc, Inkscape::XML::Node* repr) { - SPFlowtext* object = this->spflowtext; - - object->_requireSVGVersion(Inkscape::Version(1, 2)); +void SPFlowtext::build(SPDocument* doc, Inkscape::XML::Node* repr) { + this->_requireSVGVersion(Inkscape::Version(1, 2)); CItem::build(doc, repr); - object->readAttr( "inkscape:layoutOptions" ); // must happen after css has been read + this->readAttr( "inkscape:layoutOptions" ); // must happen after css has been read } -void CFlowtext::set(unsigned int key, const gchar* value) { - SPFlowtext* object = this->spflowtext; - SPFlowtext *group = (SPFlowtext *) object; - +void SPFlowtext::set(unsigned int key, const gchar* value) { switch (key) { case SP_ATTR_LAYOUT_OPTIONS: { // deprecated attribute, read for backward compatibility only //XML Tree being directly used while it shouldn't be. - SPCSSAttr *opts = sp_repr_css_attr(group->getRepr(), "inkscape:layoutOptions"); + SPCSSAttr *opts = sp_repr_css_attr(this->getRepr(), "inkscape:layoutOptions"); { gchar const *val = sp_repr_css_property(opts, "justification", NULL); - if (val != NULL && !object->style->text_align.set) { + + if (val != NULL && !this->style->text_align.set) { if ( strcmp(val, "0") == 0 || strcmp(val, "false") == 0 ) { - object->style->text_align.value = SP_CSS_TEXT_ALIGN_LEFT; + this->style->text_align.value = SP_CSS_TEXT_ALIGN_LEFT; } else { - object->style->text_align.value = SP_CSS_TEXT_ALIGN_JUSTIFY; + this->style->text_align.value = SP_CSS_TEXT_ALIGN_JUSTIFY; } - object->style->text_align.set = TRUE; - object->style->text_align.inherit = FALSE; - object->style->text_align.computed = object->style->text_align.value; + + this->style->text_align.set = TRUE; + this->style->text_align.inherit = FALSE; + this->style->text_align.computed = this->style->text_align.value; } } /* no equivalent css attribute for these two (yet) @@ -238,46 +203,52 @@ void CFlowtext::set(unsigned int key, const gchar* value) { */ { // This would probably translate to padding-left, if SPStyle had it. gchar const *val = sp_repr_css_property(opts, "par-indent", NULL); + if ( val == NULL ) { - group->par_indent = 0.0; + this->par_indent = 0.0; } else { - sp_repr_get_double((Inkscape::XML::Node*)opts, "par-indent", &group->par_indent); + sp_repr_get_double((Inkscape::XML::Node*)opts, "par-indent", &this->par_indent); } } + sp_repr_css_attr_unref(opts); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; } + default: CItem::set(key, value); break; } } -Inkscape::XML::Node* CFlowtext::write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags) { - SPFlowtext* object = this->spflowtext; - +Inkscape::XML::Node* SPFlowtext::write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags) { if ( flags & SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { repr = doc->createElement("svg:flowRoot"); } + GSList *l = NULL; - for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) { + + for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) { Inkscape::XML::Node *c_repr = NULL; + if ( SP_IS_FLOWDIV(child) || SP_IS_FLOWPARA(child) || SP_IS_FLOWREGION(child) || SP_IS_FLOWREGIONEXCLUDE(child)) { c_repr = child->updateRepr(doc, NULL, flags); } + if ( c_repr ) { l = g_slist_prepend(l, c_repr); } } + while ( l ) { repr->addChild((Inkscape::XML::Node *) l->data, NULL); Inkscape::GC::release((Inkscape::XML::Node *) l->data); l = g_slist_remove(l, l->data); } } else { - for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) { + for (SPObject *child = this->firstChild() ; child ; child = child->getNext() ) { if ( SP_IS_FLOWDIV(child) || SP_IS_FLOWPARA(child) || SP_IS_FLOWREGION(child) || SP_IS_FLOWREGIONEXCLUDE(child) ) { child->updateRepr(flags); } @@ -289,91 +260,79 @@ Inkscape::XML::Node* CFlowtext::write(Inkscape::XML::Document* doc, Inkscape::XM return repr; } -Geom::OptRect CFlowtext::bbox(Geom::Affine const &transform, SPItem::BBoxType type) { - SPFlowtext* item = this->spflowtext; - - SPFlowtext *group = SP_FLOWTEXT(item); - Geom::OptRect bbox = group->layout.bounds(transform); +Geom::OptRect SPFlowtext::bbox(Geom::Affine const &transform, SPItem::BBoxType type) { + Geom::OptRect bbox = this->layout.bounds(transform); // Add stroke width // FIXME this code is incorrect - if (bbox && type == SPItem::VISUAL_BBOX && !item->style->stroke.isNone()) { + if (bbox && type == SPItem::VISUAL_BBOX && !this->style->stroke.isNone()) { double scale = transform.descrim(); - bbox->expandBy(0.5 * item->style->stroke_width.computed * scale); + bbox->expandBy(0.5 * this->style->stroke_width.computed * scale); } + return bbox; } -void CFlowtext::print(SPPrintContext *ctx) { - SPFlowtext* item = this->spflowtext; - - SPFlowtext *group = SP_FLOWTEXT(item); +void SPFlowtext::print(SPPrintContext *ctx) { Geom::OptRect pbox, bbox, dbox; + pbox = this->geometricBounds(); + bbox = this->desktopVisualBounds(); + dbox = Geom::Rect::from_xywh(Geom::Point(0,0), this->document->getDimensions()); - pbox = item->geometricBounds(); - bbox = item->desktopVisualBounds(); - dbox = Geom::Rect::from_xywh(Geom::Point(0,0), item->document->getDimensions()); - Geom::Affine const ctm (item->i2dt_affine()); + Geom::Affine const ctm (this->i2dt_affine()); - group->layout.print(ctx, pbox, dbox, bbox, ctm); + this->layout.print(ctx, pbox, dbox, bbox, ctm); } -gchar* CFlowtext::description() { - SPFlowtext* item = this->spflowtext; - - Inkscape::Text::Layout const &layout = SP_FLOWTEXT(item)->layout; +gchar* SPFlowtext::description() { + Inkscape::Text::Layout const &layout = SP_FLOWTEXT(this)->layout; int const nChars = layout.iteratorToCharIndex(layout.end()); char const *trunc = (layout.inputTruncated()) ? _(" [truncated]") : ""; - if (SP_FLOWTEXT(item)->has_internal_frame()) { + if (SP_FLOWTEXT(this)->has_internal_frame()) { return g_strdup_printf(ngettext("<b>Flowed text</b> (%d character%s)", "<b>Flowed text</b> (%d characters%s)", nChars), nChars, trunc); } else { return g_strdup_printf(ngettext("<b>Linked flowed text</b> (%d character%s)", "<b>Linked flowed text</b> (%d characters%s)", nChars), nChars, trunc); } } -void CFlowtext::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) { - SPFlowtext* item = this->spflowtext; - +void SPFlowtext::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) { if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_TEXT_BASELINE)) { // Choose a point on the baseline for snapping from or to, with the horizontal position // of this point depending on the text alignment (left vs. right) - Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item); + Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) this); + if (layout != NULL && layout->outputExists()) { boost::optional<Geom::Point> pt = layout->baselineAnchorPoint(); + if (pt) { - p.push_back(Inkscape::SnapCandidatePoint((*pt) * item->i2dt_affine(), Inkscape::SNAPSOURCE_TEXT_ANCHOR, Inkscape::SNAPTARGET_TEXT_ANCHOR)); + p.push_back(Inkscape::SnapCandidatePoint((*pt) * this->i2dt_affine(), Inkscape::SNAPSOURCE_TEXT_ANCHOR, Inkscape::SNAPTARGET_TEXT_ANCHOR)); } } } } -Inkscape::DrawingItem* CFlowtext::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - SPFlowtext* item = this->spflowtext; - - SPFlowtext *group = (SPFlowtext *) item; +Inkscape::DrawingItem* SPFlowtext::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { Inkscape::DrawingGroup *flowed = new Inkscape::DrawingGroup(drawing); flowed->setPickChildren(false); - flowed->setStyle(group->style); + flowed->setStyle(this->style); // pass the bbox of the flowtext object as paintbox (used for paintserver fills) - Geom::OptRect bbox = group->geometricBounds(); - group->layout.show(flowed, bbox); + Geom::OptRect bbox = this->geometricBounds(); + this->layout.show(flowed, bbox); return flowed; } -void CFlowtext::hide(unsigned int key) { +void SPFlowtext::hide(unsigned int key) { CItem::hide(key); } - /* * */ - void SPFlowtext::_buildLayoutInput(SPObject *root, Shape const *exclusion_shape, std::list<Shape> *shapes, SPObject **pending_line_break_object) { Inkscape::Text::Layout::OptionalTextTagAttrs pi; @@ -446,13 +405,14 @@ void SPFlowtext::_buildLayoutInput(SPObject *root, Shape const *exclusion_shape, Shape* SPFlowtext::_buildExclusionShape() const { - Shape *shape = new Shape; - Shape *shape_temp = new Shape; + Shape *shape = new Shape(); + Shape *shape_temp = new Shape(); for (SPObject *child = children ; child ; child = child->getNext() ) { // RH: is it right that this shouldn't be recursive? if ( SP_IS_FLOWREGIONEXCLUDE(child) ) { SPFlowregionExclude *c_child = SP_FLOWREGIONEXCLUDE(child); + if ( c_child->computed && c_child->computed->hasEdges() ) { if (shape->hasEdges()) { shape_temp->Booleen(shape, c_child->computed, bool_op_union); @@ -463,7 +423,9 @@ Shape* SPFlowtext::_buildExclusionShape() const } } } + delete shape_temp; + return shape; } diff --git a/src/sp-flowtext.h b/src/sp-flowtext.h index a3331c76d..c42639fb9 100644 --- a/src/sp-flowtext.h +++ b/src/sp-flowtext.h @@ -9,9 +9,8 @@ #include <2geom/forward.h> #include "libnrtype/Layout-TNG.h" -#define SP_TYPE_FLOWTEXT (sp_flowtext_get_type ()) #define SP_FLOWTEXT(obj) ((SPFlowtext*)obj) -#define SP_IS_FLOWTEXT(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFlowtext))) +#define SP_IS_FLOWTEXT(obj) (dynamic_cast<const SPFlowtext*>((SPObject*)obj)) namespace Inkscape { @@ -20,12 +19,10 @@ class DrawingGroup; } // namespace Inkscape -class CFlowtext; - -class SPFlowtext : public SPItem { +class SPFlowtext : public SPItem, public CItem { public: SPFlowtext(); - CFlowtext* cflowtext; + virtual ~SPFlowtext(); /** Completely recalculates the layout. */ void rebuildLayout(); @@ -54,17 +51,7 @@ private: of this flowroot. */ Shape* _buildExclusionShape() const; -}; - -struct SPFlowtextClass { - SPItemClass parent_class; -}; - -class CFlowtext : public CItem { public: - CFlowtext(SPFlowtext* flowtext); - virtual ~CFlowtext(); - virtual void build(SPDocument* doc, Inkscape::XML::Node* repr); virtual void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); @@ -83,13 +70,8 @@ public: virtual Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); virtual void hide(unsigned int key); virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); -protected: - SPFlowtext* spflowtext; }; - -GType sp_flowtext_get_type (void); - SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, Geom::Point p1, Geom::Point p2); #endif // SEEN_SP_ITEM_FLOWTEXT_H diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index c1fbb1d65..3e3bc257b 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -56,6 +56,16 @@ enum { static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +#include "sp-factory.h" + +namespace { + SPGuide* createGuide() { + return new SPGuide(); + } + + bool guideRegistered = SPFactory::instance().registerObject("sodipodi:guide", createGuide); +} + G_DEFINE_TYPE(SPGuide, sp_guide, G_TYPE_OBJECT); static void sp_guide_class_init(SPGuideClass *gc) 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, "<image> color-profile set to '%s'", value ); + DEBUG_MESSAGE( lcmsFour, "<this> color-profile set to '%s'", value ); } else { - DEBUG_MESSAGE( lcmsFour, "<image> color-profile cleared" ); + DEBUG_MESSAGE( lcmsFour, "<this> 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 <image>'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<Inkscape::DrawingImage *>(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<int>(w, ceil(image->width.computed / vw * w)); - int trimheight = std::min<int>(h, ceil(image->height.computed / vh * h)); - int trimx = std::max<int>(0, floor((image->x.computed - image->ox) / vw * w)); - int trimy = std::max<int>(0, floor((image->y.computed - image->oy) / vh * h)); + int trimwidth = std::min<int>(w, ceil(this->width.computed / vw * w)); + int trimheight = std::min<int>(h, ceil(this->height.computed / vh * h)); + int trimx = std::max<int>(0, floor((this->x.computed - this->ox) / vw * w)); + int trimy = std::max<int>(0, floor((this->y.computed - this->oy) / vh * h)); - double vx = std::max<double>(image->ox, image->x.computed); - double vy = std::max<double>(image->oy, image->y.computed); - double vcw = std::min<double>(image->width.computed, vw); - double vch = std::min<double>(image->height.computed, vh); + double vx = std::max<double>(this->ox, this->x.computed); + double vy = std::max<double>(this->oy, this->y.computed); + double vcw = std::min<double>(this->width.computed, vw); + double vch = std::min<double>(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(_("<b>Image with bad reference</b>: %s"), href_desc) : g_strdup_printf(_("<b>Image</b> %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<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) { - SPImage* item = this->spimage; - +void SPImage::snappoints(std::vector<Inkscape::SnapCandidatePoint> &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<Inkscape::SnapCandidatePoint> &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); } } } diff --git a/src/sp-image.h b/src/sp-image.h index 5fa57ce1c..54bbf19b4 100644 --- a/src/sp-image.h +++ b/src/sp-image.h @@ -14,11 +14,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#define SP_TYPE_IMAGE (sp_image_get_type ()) #define SP_IMAGE(obj) ((SPImage*)obj) -#define SP_IS_IMAGE(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPImage))) - -class CImage; +#define SP_IS_IMAGE(obj) (dynamic_cast<const SPImage*>((SPObject*)obj)) /* SPImage */ @@ -29,10 +26,10 @@ class CImage; #define SP_IMAGE_HREF_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A -class SPImage : public SPItem { +class SPImage : public SPItem, public CItem { public: SPImage(); - CImage* cimage; + virtual ~SPImage(); SVGLength x; SVGLength y; @@ -60,17 +57,6 @@ public: GdkPixbuf *pixbuf; gchar *pixPath; time_t lastMod; -}; - -struct SPImageClass { - SPItemClass parent_class; -}; - - -class CImage : public CItem { -public: - CImage(SPImage* image); - virtual ~CImage(); virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual void release(); @@ -85,14 +71,8 @@ public: virtual Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); virtual Geom::Affine set_transform(Geom::Affine const &transform); - -protected: - SPImage* spimage; }; - -GType sp_image_get_type (void); - /* Return duplicate of curve or NULL */ SPCurve *sp_image_get_curve (SPImage *image); void sp_embed_image(Inkscape::XML::Node *imgnode, GdkPixbuf *pb, Glib::ustring const &mime); |
