From: buliabyak Date: Wed, 12 Mar 2008 07:57:33 +0000 (+0000) Subject: enable --export-id and --export-area-drawing for PDF export X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=281f415c86e8fdd9d9d6455d247fa5d00d9ccd3b;p=inkscape.git enable --export-id and --export-area-drawing for PDF export --- diff --git a/src/extension/internal/cairo-pdf-out.cpp b/src/extension/internal/cairo-pdf-out.cpp index ed710346f..455230dad 100644 --- a/src/extension/internal/cairo-pdf-out.cpp +++ b/src/extension/internal/cairo-pdf-out.cpp @@ -61,7 +61,20 @@ pdf_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int context.module = mod; /* fixme: This has to go into module constructor somehow */ /* Create new arena */ - mod->base = SP_ITEM(sp_document_root(doc)); + const gchar* exportId = mod->get_param_string("exportId"); + bool exportDrawing = mod->get_param_bool("exportDrawing"); + if (exportId && strcmp(exportId, "")) { + // we want to export the given item only, not page + mod->base = SP_ITEM(doc->getObjectById(exportId)); + mod->set_param_bool("pageBoundingBox", FALSE); + } else { + // we want to export the entire document from root + mod->base = SP_ITEM(sp_document_root(doc)); + if (exportDrawing) + mod->set_param_bool("pageBoundingBox", FALSE); + else + mod->set_param_bool("pageBoundingBox", TRUE); + } 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); @@ -117,7 +130,7 @@ CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const g ext->set_param_bool("textToPath", new_textToPath); } catch(...) { - g_warning("Parameter might not exists"); + g_warning("Parameter might not exist"); } bool old_blurToBitmap = FALSE; @@ -128,7 +141,29 @@ CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const g ext->set_param_bool("blurToBitmap", new_blurToBitmap); } catch(...) { - g_warning("Parameter might not exists"); + g_warning("Parameter might not exist"); + } + + const gchar* old_exportId = NULL; + const gchar* new_exportId = NULL; + try { + old_exportId = ext->get_param_string("exportId"); + new_exportId = mod->get_param_string("exportId"); + ext->set_param_string("exportId", new_exportId); + } + catch(...) { + g_warning("Parameter might not exist"); + } + + bool old_exportDrawing = NULL; + bool new_exportDrawing = NULL; + try { + old_exportDrawing = ext->get_param_bool("exportDrawing"); + new_exportDrawing = mod->get_param_bool("exportDrawing"); + ext->set_param_bool("exportDrawing", new_exportDrawing); + } + catch(...) { + g_warning("Parameter might not exist"); } gchar * final_name; @@ -140,13 +175,25 @@ CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const g ext->set_param_bool("blurToBitmap", old_blurToBitmap); } catch(...) { - g_warning("Parameter might not exists"); + g_warning("Parameter might not exist"); } try { ext->set_param_bool("textToPath", old_textToPath); } catch(...) { - g_warning("Parameter might not exists"); + g_warning("Parameter might not exist"); + } + try { + ext->set_param_string("exportId", old_exportId); + } + catch(...) { + g_warning("Parameter might not exist"); + } + try { + ext->set_param_bool("exportDrawing", old_exportDrawing); + } + catch(...) { + g_warning("Parameter might not exist"); } if (!ret) @@ -172,11 +219,13 @@ CairoPdfOutput::init (void) "org.inkscape.output.pdf.cairo\n" "\n" "" N_("PDF 1.4") "\n" - "\n" + "\n" "false\n" "false\n" - "90\n" - "\n" + "90\n" + "false\n" + "\n" + "\n" ".pdf\n" "application/pdf\n" "" N_("PDF via Cairo (*.pdf)") "\n" diff --git a/src/extension/internal/pdf-cairo.cpp b/src/extension/internal/pdf-cairo.cpp index 620961d3b..f189d6b6b 100644 --- a/src/extension/internal/pdf-cairo.cpp +++ b/src/extension/internal/pdf-cairo.cpp @@ -329,8 +329,9 @@ PrintCairoPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc) d.x1 = _width; d.y1 = _height; } else { - SPItem* doc_item = SP_ITEM(sp_document_root(doc)); - sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE); + // if not page, use our base, which is either root or the item we want to export + SPItem* doc_item = SP_ITEM(mod->base); + sp_item_invoke_bbox(doc_item, &d, sp_item_i2root_affine(doc_item), TRUE); // convert from px to pt d.x0 *= PT_PER_PX; d.x1 *= PT_PER_PX; @@ -340,6 +341,8 @@ PrintCairoPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc) // printf("\n _width:%f _height:%f scale:%f\n", _width, _height, PT_PER_PX); pdf_surface = cairo_pdf_surface_create_for_stream(Inkscape::Extension::Internal::_write_callback, _stream, d.x1-d.x0, d.y1-d.y0); cr = cairo_create(pdf_surface); + // move to the origin + cairo_translate (cr, -d.x0, -d.y0); if (!_bitmap) { cairo_scale(cr, PT_PER_PX, PT_PER_PX); @@ -1037,6 +1040,8 @@ PrintCairoPDF::init(void) "| lp\n" "TRUE\n" "TRUE\n" + "FALSE\n" + "\n" "\n" "", new PrintCairoPDF()); } diff --git a/src/main.cpp b/src/main.cpp index 4580b7271..df62e8d0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -777,7 +777,7 @@ sp_main_console(int argc, char const **argv) if (sp_global_printer) { sp_print_document_to_file(doc, sp_global_printer); } - if (sp_export_png || sp_export_id || sp_export_area_drawing) { + if (sp_export_png) { sp_do_export_png(doc); } if (sp_export_svg) { @@ -1118,7 +1118,7 @@ static void do_export_ps(SPDocument* doc, gchar const* uri, char const* mime) if (i == o.end()) { - g_warning ("Could not find an extension to export this file."); + g_warning ("Could not find an extension to export to MIME type %s.", mime); return; } @@ -1181,10 +1181,27 @@ static void do_export_pdf(SPDocument* doc, gchar const* uri, char const* mime) if (i == o.end()) { - g_warning ("Could not find an extension to export this file."); + g_warning ("Could not find an extension to export to MIME type %s.", mime); return; } + if (sp_export_id) { + SPObject *o = doc->getObjectById(sp_export_id); + if (o == NULL) { + g_warning("Object with id=\"%s\" was not found in the document. Nothing exported.", sp_export_id); + return; + } + (*i)->set_param_string ("exportId", sp_export_id); + } else { + (*i)->set_param_string ("exportId", ""); + } + + if (sp_export_area_drawing) { + (*i)->set_param_bool ("exportDrawing", TRUE); + } else { + (*i)->set_param_bool ("exportDrawing", FALSE); + } + (*i)->save(doc, uri); } @@ -1208,7 +1225,7 @@ static void do_export_emf(SPDocument* doc, gchar const* uri, char const* mime) if (i == o.end()) { - g_warning ("Could not find an extension to export this file."); + g_warning ("Could not find an extension to export to MIME type %s.", mime); return; }