summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2008-03-12 07:57:33 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2008-03-12 07:57:33 +0000
commit9a422c34a4e7f1c83379bc21b59150573cf61673 (patch)
treef675baa8427496bfb6ca35b5d326809b6ed5b7c3 /src
parentupdate (diff)
downloadinkscape-9a422c34a4e7f1c83379bc21b59150573cf61673.tar.gz
inkscape-9a422c34a4e7f1c83379bc21b59150573cf61673.zip
enable --export-id and --export-area-drawing for PDF export
(bzr r5063)
Diffstat (limited to 'src')
-rw-r--r--src/extension/internal/cairo-pdf-out.cpp65
-rw-r--r--src/extension/internal/pdf-cairo.cpp9
-rw-r--r--src/main.cpp25
3 files changed, 85 insertions, 14 deletions
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 <textToPath> might not exists");
+ g_warning("Parameter <textToPath> 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 <blurToBitmap> might not exists");
+ g_warning("Parameter <blurToBitmap> 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 <exportId> 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 <exportDrawing> 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 <blurToBitmap> might not exists");
+ g_warning("Parameter <blurToBitmap> might not exist");
}
try {
ext->set_param_bool("textToPath", old_textToPath);
}
catch(...) {
- g_warning("Parameter <textToPath> might not exists");
+ g_warning("Parameter <textToPath> might not exist");
+ }
+ try {
+ ext->set_param_string("exportId", old_exportId);
+ }
+ catch(...) {
+ g_warning("Parameter <exportId> might not exist");
+ }
+ try {
+ ext->set_param_bool("exportDrawing", old_exportDrawing);
+ }
+ catch(...) {
+ g_warning("Parameter <exportDrawing> might not exist");
}
if (!ret)
@@ -172,11 +219,13 @@ CairoPdfOutput::init (void)
"<id>org.inkscape.output.pdf.cairo</id>\n"
"<param name=\"PDFversion\" gui-text=\"" N_("Restrict to PDF version") "\" type=\"enum\" >\n"
"<item value='PDF14'>" N_("PDF 1.4") "</item>\n"
- "</param>\n"
+ "</param>\n"
"<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
"<param name=\"blurToBitmap\" gui-text=\"" N_("Convert blur effects to bitmaps") "\" type=\"boolean\">false</param>\n"
- "<param name=\"resolution\" gui-text=\"" N_("Preferred resolution (DPI) of bitmaps") "\" type=\"int\" min=\"72\" max=\"2400\">90</param>\n"
- "<output>\n"
+ "<param name=\"resolution\" gui-text=\"" N_("Preferred resolution (DPI) of bitmaps") "\" type=\"int\" min=\"72\" max=\"2400\">90</param>\n"
+ "<param name=\"exportDrawing\" gui-text=\"" N_("Export drawing, not page") "\" type=\"boolean\">false</param>\n"
+ "<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID") "\" type=\"string\"></param>\n"
+ "<output>\n"
"<extension>.pdf</extension>\n"
"<mimetype>application/pdf</mimetype>\n"
"<filetypename>" N_("PDF via Cairo (*.pdf)") "</filetypename>\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)
"<param name=\"destination\" type=\"string\">| lp</param>\n"
"<param name=\"pageBoundingBox\" type=\"boolean\">TRUE</param>\n"
"<param name=\"textToPath\" type=\"boolean\">TRUE</param>\n"
+ "<param name=\"exportDrawing\" type=\"boolean\">FALSE</param>\n"
+ "<param name=\"exportId\" type=\"string\"></param>\n"
"<print/>\n"
"</inkscape-extension>", 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;
}