void sp_textpath_to_text(SPObject *tp) { SPObject *text = SP_OBJECT_PARENT(tp); NRRect bbox; sp_item_invoke_bbox(SP_ITEM(text), &bbox, sp_item_i2doc_affine(SP_ITEM(text)), TRUE); Geom::Point xy(bbox.x0, bbox.y0); // make a list of textpath children GSList *tp_reprs = NULL; for (SPObject *o = SP_OBJECT(tp)->firstChild() ; o != NULL; o = o->next) { tp_reprs = g_slist_prepend(tp_reprs, SP_OBJECT_REPR(o)); } for ( GSList *i = tp_reprs ; i ; i = i->next ) { // make a copy of each textpath child Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(SP_OBJECT_REPR(text)->document()); // remove the old repr from under textpath SP_OBJECT_REPR(tp)->removeChild((Inkscape::XML::Node *) i->data); // put its copy under text SP_OBJECT_REPR(text)->addChild(copy, NULL); // fixme: copy id } //remove textpath tp->deleteObject(); g_slist_free(tp_reprs); // set x/y on text /* fixme: Yuck, is this really the right test? */ if (xy[Geom::X] != 1e18 && xy[Geom::Y] != 1e18) { sp_repr_set_svg_double(SP_OBJECT_REPR(text), "x", xy[Geom::X]); sp_repr_set_svg_double(SP_OBJECT_REPR(text), "y", xy[Geom::Y]); } }
void sp_conn_end_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, SPConnEnd *connEndPtr, SPPath *const path, unsigned const handle_ix) { g_return_if_fail(connEndPtr != NULL); SPConnEnd &connEnd = *connEndPtr; connEnd._delete_connection.disconnect(); connEnd._transformed_connection.disconnect(); connEnd._group_connection.disconnect(); if (connEnd.href) { SPObject *refobj = connEnd.ref.getObject(); if (refobj) { connEnd._delete_connection = refobj->connectDelete(sigc::bind(sigc::ptr_fun(&sp_conn_end_deleted), path, handle_ix)); // This allows the connector tool to dive into a group's children // And connect to their children's centers. SPObject *parent = refobj->parent; if (SP_IS_GROUP(parent) && ! SP_IS_LAYER(parent)) { connEnd._group_connection = SP_ITEM(parent)->connectTransformed(sigc::bind(sigc::ptr_fun(&sp_conn_end_shape_move), path)); } connEnd._transformed_connection = SP_ITEM(refobj)->connectTransformed(sigc::bind(sigc::ptr_fun(&sp_conn_end_shape_move), path)); } } }
static void sp_fill_style_widget_paint_dragged (SPPaintSelector *psel, SPWidget *spw) { const GSList *items, *i; SPGradient *vector; gfloat c[5]; if (!spw->inkscape) return; if (g_object_get_data (G_OBJECT (spw), "update")) return; g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (TRUE)); #ifdef SP_FS_VERBOSE g_print ("FillStyleWidget: paint dragged\n"); #endif switch (psel->mode) { case SP_PAINT_SELECTOR_MODE_EMPTY: case SP_PAINT_SELECTOR_MODE_MULTIPLE: case SP_PAINT_SELECTOR_MODE_NONE: g_warning ("file %s: line %d: Paint %d should not emit 'dragged'", __FILE__, __LINE__, psel->mode); break; case SP_PAINT_SELECTOR_MODE_COLOR_RGB: sp_paint_selector_get_rgba_floatv (psel, c); items = sp_widget_get_item_list (spw); for (i = items; i != NULL; i = i->next) { sp_style_set_fill_color_rgba (SP_OBJECT_STYLE (i->data), c[0], c[1], c[2], c[3], TRUE, TRUE); } break; case SP_PAINT_SELECTOR_MODE_COLOR_CMYK: sp_paint_selector_get_cmyka_floatv (psel, c); items = sp_widget_get_item_list (spw); for (i = items; i != NULL; i = i->next) { sp_style_set_fill_color_cmyka (SP_OBJECT_STYLE (i->data), c[0], c[1], c[2], c[3], c[4], TRUE, TRUE); } break; case SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR: vector = sp_paint_selector_get_gradient_vector (psel); vector = sp_gradient_ensure_vector_normalized (vector); items = sp_widget_get_item_list (spw); for (i = items; i != NULL; i = i->next) { SPGradient *lg; lg = sp_item_force_fill_lineargradient_vector (SP_ITEM (i->data), vector); sp_paint_selector_write_lineargradient (psel, SP_LINEARGRADIENT (lg), SP_ITEM (i->data)); } break; case SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL: vector = sp_paint_selector_get_gradient_vector (psel); vector = sp_gradient_ensure_vector_normalized (vector); items = sp_widget_get_item_list (spw); for (i = items; i != NULL; i = i->next) { SPGradient *rg; rg = sp_item_force_fill_radialgradient_vector (SP_ITEM (i->data), vector); sp_paint_selector_write_radialgradient (psel, SP_RADIALGRADIENT (rg), SP_ITEM (i->data)); } break; default: g_warning ("file %s: line %d: Paint selector should not be in mode %d", __FILE__, __LINE__, psel->mode); break; } g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (FALSE)); }
Geom::OptRect SPClipPath::geometricBounds(Geom::Affine const &transform) { Geom::OptRect bbox; for (SPObject *i = firstChild(); i; i = i->getNext()) { if (SP_IS_ITEM(i)) { Geom::OptRect tmp = SP_ITEM(i)->geometricBounds(Geom::Affine(SP_ITEM(i)->transform) * transform); bbox.unionWith(tmp); } } return bbox; }
void SPLPEItem::apply_to_clippath(SPItem *item) { SPClipPath *clipPath = item->clip_ref->getObject(); if(clipPath) { SPObject * clip_data = clipPath->firstChild(); SPCurve * clip_curve = NULL; if (SP_IS_PATH(clip_data)) { clip_curve = SP_PATH(clip_data)->get_original_curve(); } else if(SP_IS_SHAPE(clip_data)) { clip_curve = SP_SHAPE(clip_data)->getCurve(); } else if(SP_IS_GROUP(clip_data)) { apply_to_clip_or_mask_group(SP_ITEM(clip_data), item); return; } if(clip_curve) { bool success = false; if(SP_IS_GROUP(this)){ clip_curve->transform(i2anc_affine(SP_GROUP(item), SP_GROUP(this))); success = this->performPathEffect(clip_curve); clip_curve->transform(i2anc_affine(SP_GROUP(item), SP_GROUP(this)).inverse()); } else { success = this->performPathEffect(clip_curve); } Inkscape::XML::Node *reprClip = clip_data->getRepr(); if (success) { gchar *str = sp_svg_write_path(clip_curve->get_pathvector()); reprClip->setAttribute("d", str); g_free(str); } else { // LPE was unsuccesfull. Read the old 'd'-attribute. if (gchar const * value = reprClip->attribute("d")) { Geom::PathVector pv = sp_svg_read_pathv(value); SPCurve *oldcurve = new SPCurve(pv); if (oldcurve) { SP_SHAPE(clip_data)->setCurve(oldcurve, TRUE); oldcurve->unref(); } } } clip_curve->unref(); } } if(SP_IS_GROUP(item)){ GSList const *item_list = sp_item_group_item_list(SP_GROUP(item)); for ( GSList const *iter = item_list; iter; iter = iter->next ) { SPObject *subitem = static_cast<SPObject *>(iter->data); apply_to_clippath(SP_ITEM(subitem)); } } }
void SPUsePath::refresh_source() { sourceDirty = false; delete originalPath; originalPath = NULL; // le mauvais cas: pas d'attribut d => il faut verifier que c'est une SPShape puis prendre le contour // [tr: The bad case: no d attribute. Must check that it's a SPShape and then take the outline.] SPObject *refobj = sourceObject; if ( refobj == NULL ) return; SPItem *item = SP_ITEM(refobj); SPCurve *curve = NULL; if (SP_IS_SHAPE(item)) { curve = SP_SHAPE(item)->getCurve(); } else if (SP_IS_TEXT(item)) { curve = SP_TEXT(item)->getNormalizedBpath(); } else { return; } if (curve == NULL) return; originalPath = new Path; originalPath->LoadPathVector(curve->get_pathvector(), item->transform, true); curve->unref(); }
/** Applies gradient vector gr to the gradients attached to the selected dragger of drag, or if none, to all objects in selection. If there was no previous gradient on an item, uses gradient type and fill/stroke setting from preferences to create new default (linear: left/right; radial: centered) gradient. */ void gr_apply_gradient (Inkscape::Selection *selection, GrDrag *drag, SPGradient *gr) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); guint new_fill = prefs->getBool("/tools/gradient/newfillorstroke", true); // GRADIENTFIXME: make this work for multiple selected draggers. // First try selected dragger if (drag && drag->selected) { GrDragger *dragger = (GrDragger*) drag->selected->data; for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger GrDraggable *draggable = (GrDraggable *) i->data; gr_apply_gradient_to_item (draggable->item, gr, new_type, new_fill, draggable->fill_or_stroke, !draggable->fill_or_stroke); } return; } // If no drag or no dragger selected, act on selection for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { gr_apply_gradient_to_item (SP_ITEM(i->data), gr, new_type, new_fill, new_fill, !new_fill); } }
static void sp_item_create_link(GtkMenuItem *menuitem, SPItem *item) { g_assert(SP_IS_ITEM(item)); g_assert(!SP_IS_ANCHOR(item)); SPDesktop *desktop = (SPDesktop*)gtk_object_get_data(GTK_OBJECT(menuitem), "desktop"); g_return_if_fail(desktop != NULL); Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc()); Inkscape::XML::Node *repr = xml_doc->createElement("svg:a"); SP_OBJECT_REPR(SP_OBJECT_PARENT(item))->addChild(repr, SP_OBJECT_REPR(item)); SPObject *object = SP_OBJECT_DOCUMENT(item)->getObjectByRepr(repr); g_return_if_fail(SP_IS_ANCHOR(object)); const char *id = SP_OBJECT_REPR(item)->attribute("id"); Inkscape::XML::Node *child = SP_OBJECT_REPR(item)->duplicate(xml_doc); SP_OBJECT(item)->deleteObject(false); repr->addChild(child, NULL); child->setAttribute("id", id); Inkscape::GC::release(repr); Inkscape::GC::release(child); sp_document_done(SP_OBJECT_DOCUMENT(object), SP_VERB_NONE, _("Create link")); sp_object_attributes_dialog(object, "SPAnchor"); sp_desktop_selection(desktop)->set(SP_ITEM(object)); }
Inkscape::DrawingItem *SPClipPath::show(Inkscape::Drawing &drawing, unsigned int key) { Inkscape::DrawingGroup *ai = new Inkscape::DrawingGroup(drawing); display = sp_clippath_view_new_prepend(display, key, ai); for ( SPObject *child = firstChild() ; child ; child = child->getNext() ) { if (SP_IS_ITEM(child)) { Inkscape::DrawingItem *ac = SP_ITEM(child)->invoke_show(drawing, key, SP_ITEM_REFERENCE_FLAGS); if (ac) { /* The order is not important in clippath */ ai->appendChild(ac); } } } if (clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX && display->bbox) { Geom::Affine t = Geom::Scale(display->bbox->dimensions()); t.setTranslation(display->bbox->min()); ai->setChildTransform(t); } ai->setStyle(this->style); return ai; }
/** * Fills in the data for an SPObject from its Inkscape::XML::Node object. * It fills in data such as version, x, y, width, height, etc. * It then calls the object's parent class object's build function. */ static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { SPGroup *group = (SPGroup *) object; SPRoot *root = (SPRoot *) object; //XML Tree being used directly here while it shouldn't be. if ( !object->getRepr()->attribute("version") ) { repr->setAttribute("version", SVG_VERSION); } object->readAttr( "version" ); object->readAttr( "inkscape:version" ); /* It is important to parse these here, so objects will have viewport build-time */ object->readAttr( "x" ); object->readAttr( "y" ); object->readAttr( "width" ); object->readAttr( "height" ); object->readAttr( "viewBox" ); object->readAttr( "preserveAspectRatio" ); object->readAttr( "onload" ); if (((SPObjectClass *) parent_class)->build) (* ((SPObjectClass *) parent_class)->build) (object, document, repr); // Search for first <defs> node for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { if (SP_IS_DEFS(o)) { root->defs = SP_DEFS(o); break; } } // clear transform, if any was read in - SVG does not allow transform= on <svg> SP_ITEM(object)->transform = Geom::identity(); }
NRArenaItem * sp_mask_show (SPMask *mask, NRArena *arena, unsigned int key) { NRArenaItem *ai, *ac; SPObject *child; g_return_val_if_fail (mask != NULL, NULL); g_return_val_if_fail (SP_IS_MASK (mask), NULL); g_return_val_if_fail (arena != NULL, NULL); g_return_val_if_fail (NR_IS_ARENA (arena), NULL); ai = nr_arena_item_new (arena, NR_TYPE_ARENA_GROUP); mask->display = sp_mask_view_new_prepend (mask->display, key, ai); for (child = SP_OBJECTGROUP (mask)->children; child != NULL; child = child->next) { if (SP_IS_ITEM (child)) { ac = sp_item_invoke_show (SP_ITEM (child), arena, key, SP_ITEM_REFERENCE_FLAGS); if (ac) { /* The order is not important in mask */ nr_arena_item_add_child (ai, ac, NULL); nr_arena_item_unref (ac); } } } if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) { NRMatrixF t; nr_matrix_f_set_scale (&t, mask->display->bbox.x1 - mask->display->bbox.x0, mask->display->bbox.y1 - mask->display->bbox.y0); t.c[4] = mask->display->bbox.x0; t.c[5] = mask->display->bbox.y0; nr_arena_group_set_child_transform (NR_ARENA_GROUP (ai), &t); } return ai; }
static void sp_mask_child_added (SPObject *object, SPRepr *child, SPRepr *ref) { SPMask *cp; SPObject *ochild; cp = SP_MASK (object); /* Invoke SPObjectGroup implementation */ ((SPObjectClass *) (parent_class))->child_added (object, child, ref); /* Show new object */ ochild = sp_document_lookup_id (SP_OBJECT_DOCUMENT (object), sp_repr_attr (child, "id")); if (SP_IS_ITEM (ochild)) { SPMaskView *v; for (v = cp->display; v != NULL; v = v->next) { NRArenaItem *ac; ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, SP_ITEM_REFERENCE_FLAGS); if (ac) { nr_arena_item_add_child (v->arenaitem, ac, NULL); nr_arena_item_unref (ac); } } } }
// Create a mask element (using passed elements), add it to <defs> const gchar *SPClipPath::create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform) { Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:clipPath"); repr->setAttribute("clipPathUnits", "userSpaceOnUse"); defsrepr->appendChild(repr); const gchar *id = repr->attribute("id"); SPObject *clip_path_object = document->getObjectById(id); for (GSList *it = reprs; it != NULL; it = it->next) { Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data); SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node)); if (NULL != applyTransform) { Geom::Affine transform (item->transform); transform *= (*applyTransform); item->doWriteTransform(item->getRepr(), transform); } } Inkscape::GC::release(repr); return id; }
void sp_mask_hide (SPMask *cp, unsigned int key) { SPMaskView *v; SPObject *child; g_return_if_fail (cp != NULL); g_return_if_fail (SP_IS_MASK (cp)); for (child = SP_OBJECTGROUP (cp)->children; child != NULL; child = child->next) { if (SP_IS_ITEM (child)) { sp_item_invoke_hide (SP_ITEM (child), key); } } for (v = cp->display; v != NULL; v = v->next) { if (v->key == key) { /* We simply unref and let item to manage this in handler */ cp->display = sp_mask_view_list_remove (cp->display, v); return; } } g_assert_not_reached (); }
static void sp_flowpara_update (SPObject *object, SPCtx *ctx, unsigned int flags) { SPItemCtx *ictx=(SPItemCtx *) ctx; SPItemCtx cctx=*ictx; if (((SPObjectClass *) (flowpara_parent_class))->update) ((SPObjectClass *) (flowpara_parent_class))->update (object, ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; flags &= SP_OBJECT_MODIFIED_CASCADE; GSList* l = NULL; for (SPObject *child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { g_object_ref (G_OBJECT (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); cctx.i2doc = chi.transform * ictx->i2doc; cctx.i2vp = chi.transform * ictx->i2vp; child->updateDisplay((SPCtx *)&cctx, flags); } else { child->updateDisplay(ctx, flags); } } g_object_unref (G_OBJECT (child)); } }
/** Returns the bottommost item from the list which is at the point, or NULL if none. */ SPItem* sp_document_item_from_list_at_point_bottom(unsigned int dkey, SPGroup *group, GSList const *list, Geom::Point const p, bool take_insensitive) { g_return_val_if_fail(group, NULL); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gdouble delta = prefs->getDouble("/options/cursortolerance/value", 1.0); for (SPObject *o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) { if (!SP_IS_ITEM(o)) continue; SPItem *item = SP_ITEM(o); NRArenaItem *arenaitem = sp_item_get_arenaitem(item, dkey); if (arenaitem && nr_arena_item_invoke_pick(arenaitem, p, delta, 1) != NULL && (take_insensitive || item->isVisibleAndUnlocked(dkey))) { if (g_slist_find((GSList *) list, item) != NULL) return item; } if (SP_IS_GROUP(o)) { SPItem *found = sp_document_item_from_list_at_point_bottom(dkey, SP_GROUP(o), list, p, take_insensitive); if (found) return found; } } return NULL; }
/** Returns the topmost non-layer group from the descendants of group which is at point p, or NULL if none. Recurses into layers but not into groups. */ SPItem* find_group_at_point(unsigned int dkey, SPGroup *group, Geom::Point const p) { SPItem *seen = NULL; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gdouble delta = prefs->getDouble("/options/cursortolerance/value", 1.0); for (SPObject *o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) { if (!SP_IS_ITEM(o)) continue; if (SP_IS_GROUP(o) && SP_GROUP(o)->effectiveLayerMode(dkey) == SPGroup::LAYER) { SPItem *newseen = find_group_at_point(dkey, SP_GROUP(o), p); if (newseen) { seen = newseen; } } if (SP_IS_GROUP(o) && SP_GROUP(o)->effectiveLayerMode(dkey) != SPGroup::LAYER ) { SPItem *child = SP_ITEM(o); NRArenaItem *arenaitem = sp_item_get_arenaitem(child, dkey); // seen remembers the last (topmost) of groups pickable at this point if (arenaitem && nr_arena_item_invoke_pick(arenaitem, p, delta, 1) != NULL) { seen = child; } } } return seen; }
/** * Regenerates the draggers list from the current selection; is called when selection is changed or modified */ void VPDrag::updateDraggers () { if (this->dragging) return; // delete old draggers for (GList const* i = this->draggers; i != NULL; i = i->next) { delete ((VPDragger *) i->data); } g_list_free (this->draggers); this->draggers = NULL; g_return_if_fail (this->selection != NULL); for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { SPItem *item = SP_ITEM(i->data); if (!SP_IS_BOX3D (item)) continue; SPBox3D *box = SP_BOX3D (item); VanishingPoint vp; for (int i = 0; i < 3; ++i) { vp.set(box3d_get_perspective(box), Proj::axes[i]); addDragger (vp); } } }
// Create a mask element (using passed elements), add it to <defs> const gchar * sp_clippath_create (GSList *reprs, SPDocument *document, Geom::Matrix const* applyTransform) { Inkscape::XML::Node *defsrepr = SP_OBJECT_REPR (SP_DOCUMENT_DEFS (document)); Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document); Inkscape::XML::Node *repr = xml_doc->createElement("svg:clipPath"); repr->setAttribute("clipPathUnits", "userSpaceOnUse"); defsrepr->appendChild(repr); const gchar *id = repr->attribute("id"); SPObject *clip_path_object = document->getObjectById(id); for (GSList *it = reprs; it != NULL; it = it->next) { Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data); SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node)); if (NULL != applyTransform) { Geom::Matrix transform (item->transform); transform *= (*applyTransform); sp_item_write_transform(item, SP_OBJECT_REPR(item), transform); } } Inkscape::GC::release(repr); return id; }
NRArenaItem * sp_clippath_show(SPClipPath *cp, NRArena *arena, unsigned int key) { g_return_val_if_fail(cp != NULL, NULL); g_return_val_if_fail(SP_IS_CLIPPATH(cp), NULL); g_return_val_if_fail(arena != NULL, NULL); g_return_val_if_fail(NR_IS_ARENA(arena), NULL); NRArenaItem *ai = NRArenaGroup::create(arena); cp->display = sp_clippath_view_new_prepend(cp->display, key, ai); for (SPObject *child = sp_object_first_child(SP_OBJECT(cp)) ; child != NULL; child = SP_OBJECT_NEXT(child)) { if (SP_IS_ITEM(child)) { NRArenaItem *ac = sp_item_invoke_show(SP_ITEM(child), arena, key, SP_ITEM_REFERENCE_FLAGS); if (ac) { /* The order is not important in clippath */ nr_arena_item_add_child(ai, ac, NULL); } } } if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) { Geom::Matrix t(Geom::Scale(cp->display->bbox.x1 - cp->display->bbox.x0, cp->display->bbox.y1 - cp->display->bbox.y0)); t[4] = cp->display->bbox.x0; t[5] = cp->display->bbox.y0; nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), &t); } return ai; }
static bool pdf_render_document_to_file(SPDocument *doc, gchar const *filename, unsigned int level, bool texttopath, bool omittext, bool filtertobitmap, int resolution, const gchar * const exportId, bool exportDrawing, bool exportCanvas, float bleedmargin_px) { doc->ensureUpToDate(); /* Start */ SPItem *base = NULL; bool pageBoundingBox = TRUE; if (exportId && strcmp(exportId, "")) { // we want to export the given item only base = SP_ITEM(doc->getObjectById(exportId)); pageBoundingBox = exportCanvas; } else { // we want to export the entire document from root base = doc->getRoot(); pageBoundingBox = !exportDrawing; } if (!base) { return false; } /* Create new arena */ Inkscape::Drawing drawing; drawing.setExact(true); unsigned dkey = SPItem::display_key_new(1); base->invoke_show(drawing, dkey, SP_ITEM_SHOW_DISPLAY); /* Create renderer and context */ CairoRenderer *renderer = new CairoRenderer(); CairoRenderContext *ctx = renderer->createContext(); ctx->setPDFLevel(level); ctx->setTextToPath(texttopath); ctx->setOmitText(omittext); ctx->setFilterToBitmap(filtertobitmap); ctx->setBitmapResolution(resolution); bool ret = ctx->setPdfTarget (filename); if(ret) { /* Render document */ ret = renderer->setupDocument(ctx, doc, pageBoundingBox, bleedmargin_px, base); if (ret) { renderer->renderItem(ctx, base); ret = ctx->finish(); } } base->invoke_hide(dkey); renderer->destroyContext(ctx); delete renderer; return ret; }
static void sp_image_update_canvas_image(SPImage *image) { SPItem *item = SP_ITEM(image); for (SPItemView *v = item->display; v != NULL; v = v->next) { sp_image_update_arenaitem(image, dynamic_cast<Inkscape::DrawingImage *>(v->arenaitem)); } }
SPItem * SPTagUse::root() { SPObject *orig = child; while (orig && SP_IS_TAG_USE(orig)) { orig = SP_TAG_USE(orig)->child; } if (!orig || !SP_IS_ITEM(orig)) return NULL; return SP_ITEM(orig); }
// Returns the number of filtered items in the list static int count_filtered (GSList *items) { int count=0; SPItem *item=NULL; for (GSList *i = items; i != NULL; i = i->next) { item = SP_ITEM(i->data); count += item->ifilt(); } return count; }
Geom::OptRect Selection::visualBounds() const { std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); Geom::OptRect bbox; for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end(); ++iter) { bbox.unionWith(SP_ITEM(*iter)->desktopVisualBounds()); } return bbox; }
/** * Sets a specific value in the SPFeImage. */ static void sp_feImage_set(SPObject *object, unsigned int key, gchar const *value) { SPFeImage *feImage = SP_FEIMAGE(object); (void)feImage; Inkscape::URI* SVGElem_uri; switch(key) { /*DEAL WITH SETTING ATTRIBUTES HERE*/ case SP_ATTR_XLINK_HREF: if (feImage->href) g_free(feImage->href); feImage->href = (value) ? g_strdup (value) : NULL; if (!feImage->href) return; try{ SVGElem_uri = new Inkscape::URI(feImage->href); feImage->SVGElemRef = new Inkscape::URIReference(feImage->document); feImage->from_element = true; feImage->SVGElemRef->attach(*SVGElem_uri); feImage->SVGElem = SP_ITEM(feImage->SVGElemRef->getObject()); g_free(SVGElem_uri); feImage->_modified_connection = ((SPObject*) feImage->SVGElem)->connectModified(sigc::bind(sigc::ptr_fun(&sp_feImage_elem_modified), object)); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; } catch(const Inkscape::UnsupportedURIException & e) { feImage->from_element = false; g_warning("caught Inkscape::UnsupportedURIException in sp_feImage_set"); break; } case SP_ATTR_X: feImage->x.readOrUnset(value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_Y: feImage->y.readOrUnset(value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_WIDTH: feImage->width.readOrUnset(value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_HEIGHT: feImage->height.readOrUnset(value); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; default: if (((SPObjectClass *) feImage_parent_class)->set) ((SPObjectClass *) feImage_parent_class)->set(object, key, value); break; } }
void sp_knot_holder_add_full (SPKnotHolder *knot_holder, SPKnotHolderSetFunc knot_set, SPKnotHolderGetFunc knot_get, SPKnotShapeType shape, SPKnotModeType mode) { SPKnotHolderEntity *e; SPItem *item; NRPointF sp, dp; NRMatrixF i2d; g_return_if_fail (knot_holder != NULL); g_return_if_fail (knot_set != NULL); g_return_if_fail (knot_get != NULL); item = SP_ITEM (knot_holder->item); #if 0 #define KH_EPSILON 1e-6 /* Precondition for knot_set and knot_get */ { NRPointF p1, p2; knot_get (item, &p1); knot_set (item, &p1, 0); knot_get (item, &p2); g_assert (fabs(p1.x - p2.x) < KH_EPSILON && fabs(p1.y - p2.y) < KH_EPSILON); } #endif /* create new SPKnotHolderEntry */ e = g_new (SPKnotHolderEntity, 1); e->knot = sp_knot_new (knot_holder->desktop); e->knot_set = knot_set; e->knot_get = knot_get; g_object_set (G_OBJECT (e->knot->item), "shape", shape, NULL); g_object_set (G_OBJECT (e->knot->item), "mode", mode, NULL); knot_holder->entity = g_slist_append (knot_holder->entity, e); /* move to current point */ e->knot_get (item, &sp); sp_item_i2d_affine(item, &i2d); dp.x = NR_MATRIX_DF_TRANSFORM_X (&i2d, sp.x, sp.y); dp.y = NR_MATRIX_DF_TRANSFORM_Y (&i2d, sp.x, sp.y); sp_knot_set_position (e->knot, &dp, SP_KNOT_STATE_NORMAL); e->handler_id = g_signal_connect (G_OBJECT (e->knot), "moved", G_CALLBACK (knot_moved_handler), knot_holder); g_signal_connect (G_OBJECT (e->knot), "ungrabbed", G_CALLBACK (knot_ungrabbed_handler), knot_holder); #ifdef KNOT_HOLDER_DEBUG g_signal_connect (ob, "destroy", sp_knot_holder_debug, "SPKnotHolder::knot"); #endif sp_knot_show (e->knot); }
static void GetDest(SPObject* child,Shape **computed) { if ( child == NULL ) return; SPCurve *curve=NULL; Geom::Matrix tr_mat; SPObject* u_child=child; if ( SP_IS_USE(u_child) ) { u_child=SP_USE(u_child)->child; tr_mat = SP_ITEM(u_child)->getRelativeTransform(SP_OBJECT_PARENT(child)); } else { tr_mat = SP_ITEM(u_child)->transform; } if ( SP_IS_SHAPE (u_child) ) { curve = sp_shape_get_curve (SP_SHAPE (u_child)); } else if ( SP_IS_TEXT (u_child) ) { curve = SP_TEXT (u_child)->getNormalizedBpath (); } if ( curve ) { Path* temp=new Path; temp->LoadPathVector(curve->get_pathvector(), tr_mat, true); Shape* n_shp=new Shape; temp->Convert(0.25); temp->Fill(n_shp,0); Shape* uncross=new Shape; SPStyle* style=SP_OBJECT_STYLE(u_child); if ( style && style->fill_rule.computed == SP_WIND_RULE_EVENODD ) { uncross->ConvertToShape(n_shp,fill_oddEven); } else { uncross->ConvertToShape(n_shp,fill_nonZero); } UnionShape(computed, uncross); delete uncross; delete n_shp; delete temp; curve->unref(); } else { // printf("no curve\n"); } }
SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; for ( std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i) { Geom::OptRect obox = SP_ITEM(*i)->desktopPreferredBounds(); if (!obox || obox.isEmpty()) continue; Geom::Rect bbox = *obox; gdouble size = compare == 2 ? bbox.area() : (compare == 1 ? bbox.width() : bbox.height()); size = sml ? size : size * -1; if (size < max) { max = size; ist = SP_ITEM(*i); } } return ist; }
void sp_clippath_get_bbox(SPClipPath *cp, NRRect *bbox, Geom::Matrix const &transform, unsigned const /*flags*/) { SPObject *i; for (i = sp_object_first_child(SP_OBJECT(cp)); i && !SP_IS_ITEM(i); i = SP_OBJECT_NEXT(i)){}; if (!i) return; sp_item_invoke_bbox_full(SP_ITEM(i), bbox, Geom::Matrix(SP_ITEM(i)->transform) * transform, SPItem::GEOMETRIC_BBOX, FALSE); SPObject *i_start = i; while (i != NULL) { if (i != i_start) { NRRect i_box; sp_item_invoke_bbox_full(SP_ITEM(i), &i_box, Geom::Matrix(SP_ITEM(i)->transform) * transform, SPItem::GEOMETRIC_BBOX, FALSE); nr_rect_d_union (bbox, bbox, &i_box); } i = SP_OBJECT_NEXT(i); for (; i && !SP_IS_ITEM(i); i = SP_OBJECT_NEXT(i)){}; } }