From: buliabyak Date: Wed, 16 Apr 2008 06:43:33 +0000 (+0000) Subject: make sure --export-area-canvas works for pdf export too X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=99075926c1b3d64a38b5550b65ea98cb80f39992;p=inkscape.git make sure --export-area-canvas works for pdf export too --- diff --git a/src/extension/internal/cairo-pdf-out.cpp b/src/extension/internal/cairo-pdf-out.cpp index b6ae0b6b2..71e9eda17 100644 --- a/src/extension/internal/cairo-pdf-out.cpp +++ b/src/extension/internal/cairo-pdf-out.cpp @@ -63,10 +63,14 @@ pdf_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int /* Create new arena */ const gchar* exportId = mod->get_param_string("exportId"); bool exportDrawing = mod->get_param_bool("exportDrawing"); + bool exportCanvas = mod->get_param_bool("exportCanvas"); if (exportId && strcmp(exportId, "")) { - // we want to export the given item only, not page + // we want to export the given item only mod->base = SP_ITEM(doc->getObjectById(exportId)); - mod->set_param_bool("pageBoundingBox", FALSE); + if (exportCanvas) + mod->set_param_bool("pageBoundingBox", TRUE); + else + mod->set_param_bool("pageBoundingBox", FALSE); } else { // we want to export the entire document from root mod->base = SP_ITEM(sp_document_root(doc)); @@ -166,6 +170,17 @@ CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const g g_warning("Parameter might not exist"); } + bool old_exportCanvas = false; + bool new_exportCanvas = false; + try { + old_exportCanvas = ext->get_param_bool("exportCanvas"); + new_exportCanvas = mod->get_param_bool("exportCanvas"); + ext->set_param_bool("exportCanvas", new_exportCanvas); + } + catch(...) { + g_warning("Parameter might not exist"); + } + gchar * final_name; final_name = g_strdup_printf("> %s", uri); ret = pdf_print_document_to_file(doc, final_name, 0, new_textToPath, new_blurToBitmap); @@ -195,6 +210,12 @@ CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const g catch(...) { g_warning("Parameter might not exist"); } + try { + ext->set_param_bool("exportCanvas", old_exportCanvas); + } + catch(...) { + g_warning("Parameter might not exist"); + } if (!ret) throw Inkscape::Extension::Output::save_failed(); @@ -224,6 +245,7 @@ CairoPdfOutput::init (void) "false\n" "90\n" "false\n" + "false\n" "\n" "\n" ".pdf\n" diff --git a/src/extension/internal/pdf-cairo.cpp b/src/extension/internal/pdf-cairo.cpp index 9d2608f22..f2a8483c2 100644 --- a/src/extension/internal/pdf-cairo.cpp +++ b/src/extension/internal/pdf-cairo.cpp @@ -325,8 +325,8 @@ PrintCairoPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc) _height = sp_document_height(doc) * PT_PER_PX; NRRect d; - bool pageBoundingBox; - pageBoundingBox = mod->get_param_bool("pageBoundingBox"); + bool pageBoundingBox = mod->get_param_bool("pageBoundingBox"); + SPItem* doc_item = SP_ITEM(mod->base); // printf("Page Bounding Box: %s\n", pageBoundingBox ? "TRUE" : "FALSE"); NR::Matrix t (NR::identity()); if (pageBoundingBox) { @@ -335,24 +335,23 @@ PrintCairoPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc) d.y1 = _height; } else { // 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_i2doc_affine (doc_item), TRUE); // convert from px to pt d.x0 *= PT_PER_PX; d.x1 *= PT_PER_PX; d.y0 *= PT_PER_PX; d.y1 *= PT_PER_PX; + } - // When rendering a standalone object, we must set cairo's transform to the accumulated - // ancestor transform of that item - e.g. it may be rotated or skewed by its parent group, and - // we must reproduce that in the export even though we start traversing the tree from the - // object itself, ignoring its ancestors + // When rendering a standalone object, we must set cairo's transform to the accumulated + // ancestor transform of that item - e.g. it may be rotated or skewed by its parent group, and + // we must reproduce that in the export even though we start traversing the tree from the + // object itself, ignoring its ancestors - // complete transform, including doc_item's own transform - t = sp_item_i2doc_affine (doc_item); - // subreact doc_item's transform (comes first) from it - t = NR::Matrix(doc_item->transform).inverse() * t; - } + // complete transform, including doc_item's own transform + t = sp_item_i2doc_affine (doc_item); + // subreact doc_item's transform (comes first) from it + t = NR::Matrix(doc_item->transform).inverse() * t; // create cairo context pdf_surface = cairo_pdf_surface_create_for_stream(Inkscape::Extension::Internal::_write_callback, _stream, d.x1-d.x0, d.y1-d.y0); @@ -1061,6 +1060,7 @@ PrintCairoPDF::init(void) "TRUE\n" "TRUE\n" "FALSE\n" + "FALSE\n" "\n" "\n" "", new PrintCairoPDF()); diff --git a/src/main.cpp b/src/main.cpp index b5ed8305d..bf1662c31 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1255,6 +1255,12 @@ static void do_export_pdf(SPDocument* doc, gchar const* uri, char const* mime) (*i)->set_param_bool ("exportDrawing", FALSE); } + if (sp_export_area_canvas) { + (*i)->set_param_bool ("exportCanvas", TRUE); + } else { + (*i)->set_param_bool ("exportCanvas", FALSE); + } + (*i)->save(doc, uri); }