summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ba32f76)
raw | patch | inline | side by side (parent: ba32f76)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Fri, 29 Aug 2008 00:46:35 +0000 (00:46 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Fri, 29 Aug 2008 00:46:35 +0000 (00:46 +0000) |
index e5615897070e5feee2e6a0ed5337162964ab3e9d..6a7295dd85cffad9a5791185021059fb45219594 100644 (file)
ctx = renderer->createContext();
/* Render document */
- bool ret = renderer->setupDocument(ctx, doc);
+ bool ret = renderer->setupDocument(ctx, doc, TRUE, NULL);
if (ret) {
renderer->renderItem(ctx, base);
ctx->saveAsPng(filename);
index 735c3cf7a87b7ad31e98dedd6cbc7e96dcd4d31e..fa35079f91393c14c5d6e4fbe9af2d9d86523ddd 100644 (file)
bool ret = ctx->setPsTarget(filename);
if(ret) {
/* Render document */
- ret = renderer->setupDocument(ctx, doc);
+ ret = renderer->setupDocument(ctx, doc, TRUE, NULL);
if (ret) {
renderer->renderItem(ctx, base);
ret = ctx->finish();
diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp
index 6c727a479bfed238307c04d04ba0760fd809b69c..788791c31cdc2e5cbd89d7bce53fab46aa16e2e2 100644 (file)
bool
CairoRendererPdfOutput::check (Inkscape::Extension::Extension * module)
{
- return TRUE;
+ if (NULL == Inkscape::Extension::db.get("org.inkscape.output.pdf.cairorenderer"))
+ return FALSE;
+
+ return TRUE;
}
static bool
-pdf_render_document_to_file(SPDocument *doc, gchar const *filename)
+pdf_render_document_to_file(SPDocument *doc, gchar const *filename, unsigned int level,
+ bool texttopath, bool filtertobitmap, int resolution,
+ const gchar * const exportId, bool exportDrawing, bool exportCanvas)
{
sp_document_ensure_up_to_date(doc);
/* 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 = SP_ITEM(sp_document_root(doc));
+ pageBoundingBox = !exportDrawing;
+ }
+
+ if (!base)
+ return false;
+
/* 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 */
CairoRenderer *renderer = new CairoRenderer();
CairoRenderContext *ctx = renderer->createContext();
- ctx->setPdfTarget (filename);
- bool ret = renderer->setupDocument(ctx, doc);
- if (ret) {
- renderer->renderItem(ctx, base);
- ret = ctx->finish();
+ ctx->setPDFLevel(level);
+ ctx->setTextToPath(texttopath);
+ ctx->setFilterToBitmap(filtertobitmap);
+ ctx->setBitmapResolution(resolution);
+
+ bool ret = ctx->setPdfTarget (filename);
+ if(ret) {
+ /* Render document */
+ ret = renderer->setupDocument(ctx, doc, pageBoundingBox, base);
+ if (ret) {
+ renderer->renderItem(ctx, base);
+ ret = ctx->finish();
+ }
}
/* Release arena */
/**
\brief This function calls the output module with the filename
- \param mod unused
- \param doc Document to be saved
- \param uri Filename to save to (probably will end in .png)
+ \param mod unused
+ \param doc Document to be saved
+ \param uri Filename to save to (probably will end in .pdf)
- The most interesting thing that this function does is just attach
- an '>' on the front of the filename. This is the syntax used to
- tell the printing system to save to file.
+ The most interesting thing that this function does is just attach
+ an '>' on the front of the filename. This is the syntax used to
+ tell the printing system to save to file.
*/
void
CairoRendererPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
{
+ Inkscape::Extension::Extension * ext;
+ unsigned int ret;
+
+ ext = Inkscape::Extension::db.get("org.inkscape.output.pdf.cairorenderer");
+ if (ext == NULL)
+ return;
+
+ const gchar *new_level = NULL;
+ int level = 0;
+ try {
+ new_level = mod->get_param_enum("PDFversion");
+// if((new_level != NULL) && (g_ascii_strcasecmp("PDF-1.x", new_level) == 0))
+// level = 1;
+ }
+ catch(...) {
+// g_warning("Parameter <PDFversion> might not exists");
+ }
+
+ bool new_textToPath = FALSE;
+ try {
+ new_textToPath = mod->get_param_bool("textToPath");
+ }
+ catch(...) {
+ g_warning("Parameter <textToPath> might not exists");
+ }
+
+ bool new_blurToBitmap = FALSE;
+ try {
+ new_blurToBitmap = mod->get_param_bool("blurToBitmap");
+ }
+ catch(...) {
+ g_warning("Parameter <blurToBitmap> might not exists");
+ }
+
+ int new_bitmapResolution = 72;
+ try {
+ new_bitmapResolution = mod->get_param_int("resolution");
+ }
+ catch(...) {
+ g_warning("Parameter <resolution> might not exists");
+ }
+
+ const gchar *new_exportId = NULL;
+ try {
+ new_exportId = mod->get_param_string("exportId");
+ }
+ catch(...) {
+ g_warning("Parameter <exportId> might not exists");
+ }
+
+ bool new_exportDrawing = FALSE;
+ try {
+ new_exportDrawing = mod->get_param_bool("exportDrawing");
+ }
+ catch(...) {
+ g_warning("Parameter <exportDrawing> might not exists");
+ }
+
+ bool new_exportCanvas = FALSE;
+ try {
+ new_exportCanvas = mod->get_param_bool("exportCanvas");
+ }
+ catch(...) {
+ g_warning("Parameter <exportCanvas> might not exists");
+ }
+
gchar * final_name;
final_name = g_strdup_printf("> %s", uri);
- bool ret = pdf_render_document_to_file(doc, final_name);
+ ret = pdf_render_document_to_file(doc, final_name, level,
+ new_textToPath, new_blurToBitmap, new_bitmapResolution,
+ new_exportId, new_exportDrawing, new_exportCanvas);
g_free(final_name);
if (!ret)
throw Inkscape::Extension::Output::save_failed();
- return;
+ return;
}
+#include "clear-n_.h"
+
/**
\brief A function allocate a copy of this function.
{
Inkscape::Extension::build_from_mem(
"<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
- "<name>Cairo PDF Output (experimental)</name>\n"
+ "<name>Cairo PDF Output (experimental)</name>\n"
"<id>org.inkscape.output.pdf.cairorenderer</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 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"
+ "<param name=\"exportDrawing\" gui-text=\"" N_("Export drawing, not page") "\" type=\"boolean\">false</param>\n"
+ "<param name=\"exportCanvas\" gui-text=\"" N_("Export canvas") "\" 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"
index 8c27632e11a9fb8bcc9a9263a025fb361f8988e8..8d4b95f855b2dcb81422f23ec5a5d0a84f16435b 100644 (file)
}
bool
-CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc)
+CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool pageBoundingBox, SPItem *base)
{
g_assert( ctx != NULL );
}
NRRect d;
- bool pageBoundingBox = true;
- if (pageBoundingBox) {
+ if (pageBoundingBox || !base) {
d.x0 = d.y0 = 0;
d.x1 = ceil(ctx->_width);
d.y1 = ceil(ctx->_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);
+ sp_item_invoke_bbox(base, &d, sp_item_i2r_affine(base), TRUE);
if (ctx->_vector_based_target) {
// convert from px to pt
d.x0 *= PT_PER_PX;
}
TRACE(("%f x %f\n", ctx->_width, ctx->_height));
- return ctx->setupSurface(d.x1-d.x0, d.y1-d.y0);
+ bool ret = ctx->setupSurface(d.x1-d.x0, d.y1-d.y0);
+
+ if (ret && !pageBoundingBox && base)
+ {
+ Geom::Matrix tp(Geom::Translate(-d.x0 * (ctx->_vector_based_target ? PX_PER_PT : 1.0),
+ (d.y1 - ctx->_height) * (ctx->_vector_based_target ? PX_PER_PT : 1.0)));
+ ctx->transform(&tp);
+
+ ctx->_width = d.x1 - d.x0;
+ ctx->_height = d.y1 - d.y0;
+ }
+
+ return ret;
}
#include "macros.h" // SP_PRINT_*
index 4056a8697dbd5d2026798458af68c111720b01e7..14747240708b280a166a1e1d09ec53a8b144ce4f 100644 (file)
/** Initializes the CairoRenderContext according to the specified
SPDocument. A set*Target function can only be called on the context
before setupDocument. */
- bool setupDocument(CairoRenderContext *ctx, SPDocument *doc);
+ bool setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool pageBoundingBox, SPItem *base);
/** Traverses the object tree and invokes the render methods. */
void renderItem(CairoRenderContext *ctx, SPItem *item);
index d45f1374e96697d76fba0d3c5b8d86a7bf3c70ab..474b57306f17266e279addb587f973f0076a2063 100644 (file)
--- a/src/ui/dialog/print.cpp
+++ b/src/ui/dialog/print.cpp
#endif
bool ret = ctx->setSurfaceTarget (surface, true); if (ret) {
- ret = renderer.setupDocument (ctx, junk->_doc);
+ ret = renderer.setupDocument (ctx, junk->_doc, TRUE, NULL);
if (ret) {
renderer.renderItem(ctx, junk->_base);
ret = ctx->finish();