void sp_print_document(Gtk::Window& parentWindow, SPDocument *doc) { sp_document_ensure_up_to_date(doc); // Build arena SPItem *base = SP_ITEM(sp_document_root(doc)); NRArena *arena = NRArena::create(); unsigned int dkey = sp_item_display_key_new(1); NRArenaItem *root = sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY); // Run print dialog Inkscape::UI::Dialog::Print printop(doc,base); Gtk::PrintOperationResult res = printop.run(Gtk::PRINT_OPERATION_ACTION_PRINT_DIALOG, parentWindow); (void)res; // TODO handle this // Release arena sp_item_invoke_hide(base, dkey); nr_object_unref((NRObject *) arena); }
void sp_print_document_to_file(SPDocument *doc, gchar const *filename) { Inkscape::Extension::Print *mod; SPPrintContext context; gchar const *oldconst; gchar *oldoutput; unsigned int ret; sp_document_ensure_up_to_date(doc); mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_PS); oldconst = mod->get_param_string("destination"); oldoutput = g_strdup(oldconst); mod->set_param_string("destination", (gchar *)filename); /* Start */ context.module = mod; /* fixme: This has to go into module constructor somehow */ /* Create new arena */ mod->base = SP_ITEM(sp_document_root(doc)); mod->arena = NRArena::create(); mod->dkey = sp_item_display_key_new(1); mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY); /* Print document */ ret = mod->begin(doc); sp_item_invoke_print(mod->base, &context); ret = mod->finish(); /* Release arena */ sp_item_invoke_hide(mod->base, mod->dkey); mod->base = NULL; mod->root = NULL; nr_object_unref((NRObject *) mod->arena); mod->arena = NULL; /* end */ mod->set_param_string("destination", oldoutput); g_free(oldoutput); return; }
/** \return None \brief This is the function that does all of the SVG saves in Inkscape. It detects whether it should do a Inkscape namespace save internally. \param mod Extension to use. \param doc Document to save. \param uri The filename to save the file to. This function first checks it's parameters, and makes sure that we're getting good data. It also checks the module ID of the incoming module to figure out if this is save should include the Inkscape namespace stuff or not. The result of that comparison is stored in the spns variable. If there is not to be Inkscape name spaces a new document is created without. (I think, I'm not sure on this code) All of the internally referenced imageins are also set to relative paths in the file. And the file is saved. This really needs to be fleshed out more, but I don't quite understand all of this code. I just stole it. */ void Svg::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) { g_return_if_fail(doc != NULL); g_return_if_fail(uri != NULL); gchar *save_path = g_path_get_dirname (uri); gboolean const spns = (!mod->get_id() || !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE) || !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE)); Inkscape::XML::Document *rdoc = NULL; Inkscape::XML::Node *repr = NULL; if (spns) { repr = sp_document_repr_root (doc); } else { rdoc = sp_repr_document_new ("svg:svg"); repr = rdoc->root(); repr = sp_document_root (doc)->updateRepr(rdoc, repr, SP_OBJECT_WRITE_BUILD); } Inkscape::IO::fixupHrefs( doc, save_path, spns ); gboolean const s = sp_repr_save_file (repr->document(), uri, SP_SVG_NS_URI); if (s == FALSE) { throw Inkscape::Extension::Output::save_failed(); } if (!spns) { Inkscape::GC::release(rdoc); } g_free(save_path); return; }
static bool png_render_document_to_file(SPDocument *doc, gchar const *filename) { CairoRenderer *renderer; CairoRenderContext *ctx; sp_document_ensure_up_to_date(doc); /* Start */ /* Create new arena */ SPItem *base = SP_ITEM(sp_document_root(doc)); NRArena *arena = NRArena::create(); unsigned dkey = sp_item_display_key_new(1); NRArenaItem *root = sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY); /* Create renderer and context */ renderer = new CairoRenderer(); ctx = renderer->createContext(); /* Render document */ bool ret = renderer->setupDocument(ctx, doc, TRUE, NULL); if (ret) { renderer->renderItem(ctx, base); ctx->saveAsPng(filename); ret = ctx->finish(); } renderer->destroyContext(ctx); /* Release arena */ sp_item_invoke_hide(base, dkey); nr_object_unref((NRObject *) arena); /* end */ delete renderer; return ret; }
void sp_print_preview_document(SPDocument *doc) { Inkscape::Extension::Print *mod; unsigned int ret; sp_document_ensure_up_to_date(doc); mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_DEFAULT); ret = mod->set_preview(); if (ret) { SPPrintContext context; context.module = mod; /* fixme: This has to go into module constructor somehow */ /* Create new arena */ mod->base = SP_ITEM(sp_document_root(doc)); mod->arena = NRArena::create(); mod->dkey = sp_item_display_key_new(1); mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY); /* Print document */ ret = mod->begin(doc); sp_item_invoke_print(mod->base, &context); ret = mod->finish(); /* Release arena */ sp_item_invoke_hide(mod->base, mod->dkey); mod->base = NULL; mod->root = NULL; nr_object_unref((NRObject *) mod->arena); mod->arena = NULL; } return; }
void sp_align_arrange_clicked (GtkWidget *widget, const gchar *aligns) { float mx0, mx1, my0, my1; float sx0, sx1, sy0, sy1; SPDesktop * desktop; SPSelection * selection; GSList * slist; SPItem * master, * item; NRRectF b; NRPointF mp, sp; GSList * l; gboolean changed; mx0 = 0.5 * aligns[0]; mx1 = 0.5 * aligns[1]; my0 = 0.5 * aligns[2]; my1 = 0.5 * aligns[3]; sx0 = 0.5 * aligns[4]; sx1 = 0.5 * aligns[5]; sy0 = 0.5 * aligns[6]; sy1 = 0.5 * aligns[7]; desktop = SP_ACTIVE_DESKTOP; if (!desktop) return; selection = SP_DT_SELECTION (desktop); slist = (GSList *) sp_selection_item_list (selection); if (!slist) return; switch (base) { case SP_ALIGN_LAST: case SP_ALIGN_FIRST: case SP_ALIGN_BIGGEST: case SP_ALIGN_SMALLEST: if (!slist->next) return; slist = g_slist_copy (slist); master = sp_quick_align_find_master (slist, (mx0 != 0.0) || (mx1 != 0.0)); slist = g_slist_remove (slist, master); sp_item_bbox_desktop (master, &b); mp.x = mx0 * b.x0 + mx1 * b.x1; mp.y = my0 * b.y0 + my1 * b.y1; break; case SP_ALIGN_PAGE: slist = g_slist_copy (slist); mp.x = mx1 * sp_document_width (SP_DT_DOCUMENT (desktop)); mp.y = my1 * sp_document_height (SP_DT_DOCUMENT (desktop)); break; case SP_ALIGN_DRAWING: slist = g_slist_copy (slist); sp_item_bbox_desktop ((SPItem *) sp_document_root (SP_DT_DOCUMENT (desktop)), &b); mp.x = mx0 * b.x0 + mx1 * b.x1; mp.y = my0 * b.y0 + my1 * b.y1; break; case SP_ALIGN_SELECTION: slist = g_slist_copy (slist); sp_selection_bbox (selection, &b); mp.x = mx0 * b.x0 + mx1 * b.x1; mp.y = my0 * b.y0 + my1 * b.y1; break; default: g_assert_not_reached (); break; }; changed = FALSE; for (l = slist; l != NULL; l = l->next) { item = (SPItem *) l->data; sp_item_bbox_desktop (item, &b); sp.x = sx0 * b.x0 + sx1 * b.x1; sp.y = sy0 * b.y0 + sy1 * b.y1; if ((fabs (mp.x - sp.x) > 1e-9) || (fabs (mp.y - sp.y) > 1e-9)) { sp_item_move_rel (item, mp.x - sp.x, mp.y - sp.y); changed = TRUE; } } g_slist_free (slist); if (changed) { sp_selection_changed (selection); sp_document_done (SP_DT_DOCUMENT (desktop)); } }