From: theadib Date: Wed, 26 Dec 2007 02:31:57 +0000 (+0000) Subject: more on cairo ps/pdf options X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4b1c2be41ce8c1a88502c1b1885ad1468646fbff;p=inkscape.git more on cairo ps/pdf options --- diff --git a/src/extension/internal/cairo-pdf-out.cpp b/src/extension/internal/cairo-pdf-out.cpp index 4e7f54c86..b09b4a2fb 100644 --- a/src/extension/internal/cairo-pdf-out.cpp +++ b/src/extension/internal/cairo-pdf-out.cpp @@ -109,9 +109,17 @@ CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const g if (ext == NULL) return; + bool old_textToPath = ext->get_param_bool("textToPath"); + bool new_textToPath = mod->get_param_bool("textToPath"); + ext->set_param_bool("textToPath", new_textToPath); + + bool old_blurToBitmap = ext->get_param_bool("blurToBitmap"); + bool new_blurToBitmap = mod->get_param_bool("blurToBitmap"); + ext->set_param_bool("blurToBitmap", new_blurToBitmap); + gchar * final_name; final_name = g_strdup_printf("> %s", uri); - ret = pdf_print_document_to_file(doc, final_name); + ret = pdf_print_document_to_file(doc, final_name, 0, new_textToPath, new_blurToBitmap); g_free(final_name); if (!ret) @@ -138,11 +146,12 @@ CairoPdfOutput::init (void) "\n" "" N_("PDF 1.4") "\n" "\n" + "true\n" "false\n" "\n" ".pdf\n" "application/pdf\n" - "Cairo PDF (*.pdf)\n" + "PDF via Cairo (*.pdf)\n" "PDF File\n" "\n" "", new CairoPdfOutput()); diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp index 06e0f92c6..5681fda5e 100644 --- a/src/extension/internal/cairo-ps-out.cpp +++ b/src/extension/internal/cairo-ps-out.cpp @@ -51,7 +51,7 @@ CairoPsOutput::check (Inkscape::Extension::Extension * module) } static bool -ps_print_document_to_file(SPDocument *doc, gchar const *filename) +ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int level, bool texttopath, bool filtertobitmap) { CairoRenderer *renderer; CairoRenderContext *ctx; @@ -68,6 +68,10 @@ ps_print_document_to_file(SPDocument *doc, gchar const *filename) /* Create renderer and context */ renderer = new CairoRenderer(); ctx = renderer->createContext(); + ctx->setPSLevel(level); + ctx->setTextToPath(texttopath); + ctx->setFilterToBitmap(filtertobitmap); + bool ret = ctx->setPsTarget(filename); if(ret) { /* Render document */ @@ -106,18 +110,24 @@ CairoPsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gc if (ext == NULL) return; + const gchar *old_level = ext->get_param_enum("PSlevel"); + const gchar *new_level = mod->get_param_enum("PSlevel"); + int level = 1; + bool old_textToPath = ext->get_param_bool("textToPath"); - bool new_val = mod->get_param_bool("textToPath"); - ext->set_param_bool("textToPath", new_val); + bool new_textToPath = mod->get_param_bool("textToPath"); + ext->set_param_bool("textToPath", new_textToPath); bool old_blurToBitmap = ext->get_param_bool("blurToBitmap"); - new_val = mod->get_param_bool("blurToBitmap"); - ext->set_param_bool("blurToBitmap", new_val); + bool new_blurToBitmap = mod->get_param_bool("blurToBitmap"); + ext->set_param_bool("blurToBitmap", new_blurToBitmap); + if(g_ascii_strcasecmp("PS2", new_level) == 0) + level = 0; gchar * final_name; final_name = g_strdup_printf("> %s", uri); - ret = ps_print_document_to_file(doc, final_name); + ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_blurToBitmap); g_free(final_name); ext->set_param_bool("blurToBitmap", old_blurToBitmap); @@ -153,18 +163,18 @@ CairoPsOutput::init (void) "Cairo PS Output\n" "org.inkscape.print.ps.cairo\n" "\n" + "" N_("PostScript 3") "\n" #if (CAIRO_VERSION >= 010502) "" N_("PostScript level 2") "\n" #endif - "" N_("PostScript 3") "\n" "\n" "true\n" "false\n" "\n" ".ps\n" "application/ps\n" - "Cairo PS (*.ps)\n" - "PS File\n" + "PostScript via Cairo (*.ps)\n" + "PostScript File\n" "\n" "", new CairoPsOutput()); diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index 8511973e4..228f596dd 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -104,6 +104,10 @@ static cairo_status_t _write_callback(void *closure, const unsigned char *data, CairoRenderContext::CairoRenderContext(CairoRenderer *parent) : _dpi(72), + _pdf_level(0), + _ps_level(1), + _is_texttopath(FALSE), + _is_filtertobitmap(FALSE), _stream(NULL), _is_valid(FALSE), _vector_based_target(FALSE), @@ -154,6 +158,7 @@ CairoRenderContext::setStateForStyle(SPStyle const *style) // only opacity & overflow is stored for now _state->opacity = SP_SCALE24_TO_FLOAT(style->opacity.value); _state->has_overflow = (style->overflow.set && style->overflow.value != SP_CSS_OVERFLOW_VISIBLE); + _state->has_filtereffect = (style->filter.set != 0) ? TRUE : FALSE; if (style->fill.isPaintserver() || style->stroke.isPaintserver()) _state->merge_opacity = FALSE; @@ -384,6 +389,26 @@ CairoRenderContext::setPsTarget(gchar const *utf8_fn) return true; } +void CairoRenderContext::setPSLevel(unsigned int level) +{ + _ps_level = level; +} + +void CairoRenderContext::setPDFLevel(unsigned int level) +{ + _pdf_level = level; +} + +void CairoRenderContext::setTextToPath(bool texttopath) +{ + _is_texttopath = texttopath; +} + +void CairoRenderContext::setFilterToBitmap(bool filtertobitmap) +{ + _is_filtertobitmap = filtertobitmap; +} + cairo_surface_t* CairoRenderContext::getSurface(void) { @@ -448,6 +473,7 @@ CairoRenderContext::_createState(void) CairoRenderState *state = (CairoRenderState*)g_malloc(sizeof(CairoRenderState)); g_assert( state != NULL ); + state->has_filtereffect = FALSE; state->merge_opacity = TRUE; state->opacity = 1.0; state->need_layer = FALSE; @@ -667,6 +693,9 @@ CairoRenderContext::setupSurface(double width, double height) #ifdef CAIRO_HAS_PS_SURFACE case CAIRO_SURFACE_TYPE_PS: surface = cairo_ps_surface_create_for_stream(Inkscape::Extension::Internal::_write_callback, _stream, width, height); +#if (CAIRO_VERSION >= 010502) + cairo_ps_surface_restrict_to_level (surface, (cairo_ps_level_t)_ps_level); +#endif break; #endif default: @@ -1344,7 +1373,7 @@ CairoRenderContext::_showGlyphs(cairo_t *cr, PangoFont *font, std::vector * * Copyright (C) 2006 Miklos Erdelyi - * + * * Licensed under GNU GPL */ @@ -53,6 +53,7 @@ struct CairoRenderState { unsigned int has_overflow : 1; unsigned int parent_has_userspace : 1; // whether the parent's ctm should be applied float opacity; + bool has_filtereffect; SPClipPath *clip_path; SPMask* mask; @@ -74,18 +75,23 @@ public: RENDER_MODE_NORMAL, RENDER_MODE_CLIP }; - + typedef enum CairoClipMode { CLIP_MODE_PATH, CLIP_MODE_MASK }; - + bool setImageTarget(cairo_format_t format); bool setPdfTarget(gchar const *utf8_fn); bool setPsTarget(gchar const *utf8_fn); /** Set the cairo_surface_t from an external source */ bool setSurfaceTarget(cairo_surface_t *surface, bool is_vector); + void setPSLevel(unsigned int level); + void setPDFLevel(unsigned int level); + void setTextToPath(bool texttopath); + void setFilterToBitmap(bool filtertobitmap); + /** Creates the cairo_surface_t for the context with the given width, height and with the currently set target surface type. */ @@ -101,10 +107,10 @@ public: CairoRenderMode getRenderMode(void) const; void setClipMode(CairoClipMode mode); CairoClipMode getClipMode(void) const; - + void addBpath(NArtBpath const *bp); void setBpath(NArtBpath const *bp); - + void pushLayer(void); void popLayer(void); @@ -136,13 +142,17 @@ public: protected: CairoRenderContext(CairoRenderer *renderer); virtual ~CairoRenderContext(void); - + float _width; float _height; unsigned short _dpi; - + unsigned int _pdf_level; + unsigned int _ps_level; + bool _is_texttopath; + bool _is_filtertobitmap; + FILE *_stream; - + unsigned int _is_valid : 1; unsigned int _vector_based_target : 1; @@ -151,13 +161,13 @@ protected: cairo_surface_type_t _target; cairo_format_t _target_format; PangoLayout *_layout; - + unsigned int _clip_rule : 8; unsigned int _clip_winding_failed : 1; - + GSList *_state_stack; CairoRenderState *_state; // the current state - + CairoRenderer *_renderer; CairoRenderMode _render_mode; @@ -166,13 +176,13 @@ protected: cairo_pattern_t *_createPatternForPaintServer(SPPaintServer const *const paintserver, NRRect const *pbox, float alpha); cairo_pattern_t *_createPatternPainter(SPPaintServer const *const paintserver, NRRect const *pbox); - + unsigned int _showGlyphs(cairo_t *cr, PangoFont *font, std::vector const &glyphtext, bool is_stroke); bool _finishSurfaceSetup(cairo_surface_t *surface); void _setFillStyle(SPStyle const *style, NRRect const *pbox); void _setStrokeStyle(SPStyle const *style, NRRect const *pbox); - + void _initCairoMatrix(cairo_matrix_t *matrix, NRMatrix const *transform); void _concatTransform(cairo_t *cr, double xx, double yx, double xy, double yy, double x0, double y0); void _concatTransform(cairo_t *cr, NRMatrix const *transform); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 418e82b89..dbb898183 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -8,7 +8,7 @@ * Miklos Erdelyi * * Copyright (C) 2006 Miklos Erdelyi - * + * * Licensed under GNU GPL */ @@ -133,7 +133,7 @@ CairoRenderer::createContext(void) void CairoRenderer::destroyContext(CairoRenderContext *ctx) { - delete ctx; + delete ctx; } /* @@ -201,13 +201,13 @@ static void sp_group_render(SPItem *item, CairoRenderContext *ctx) SPGroup *group = SP_GROUP(item); CairoRenderer *renderer = ctx->getRenderer(); TRACE(("group op: %f\n", SP_SCALE24_TO_FLOAT(SP_OBJECT_STYLE(item)->opacity.value))); - + GSList *l = g_slist_reverse(group->childList(false)); while (l) { SPObject *o = SP_OBJECT (l->data); if (SP_IS_ITEM(o)) { renderer->renderItem (ctx, SP_ITEM (o)); - } + } l = g_slist_remove (l, o); } } @@ -273,12 +273,12 @@ static void sp_image_render(SPItem *item, CairoRenderContext *ctx) calculatePreserveAspectRatio (image->aspect_align, image->aspect_clip, (double)w, (double)h, &x, &y, &width, &height); } - + if (image->aspect_clip == SP_ASPECT_SLICE && !ctx->getCurrentState()->has_overflow) { ctx->addClippingRect(image->x.computed, image->y.computed, image->width.computed, image->height.computed); } - nr_matrix_set_translate (&tp, x, y); + nr_matrix_set_translate (&tp, x, y); nr_matrix_set_scale (&s, width / (double)w, height / (double)h); nr_matrix_multiply (&t, &s, &tp); @@ -290,11 +290,11 @@ static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx) SPSymbol *symbol = SP_SYMBOL(item); if (!SP_OBJECT_IS_CLONED (symbol)) return; - + /* Cloned is actually renderable */ ctx->pushState(); ctx->transform(&symbol->c2p); - + // apply viewbox if set if (0 /*symbol->viewBox_set*/) { NRMatrix vb2user; @@ -304,10 +304,10 @@ static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx) y = 0.0; width = 1.0; height = 1.0; - + view_width = symbol->viewBox.x1 - symbol->viewBox.x0; view_height = symbol->viewBox.y1 - symbol->viewBox.y0; - + calculatePreserveAspectRatio(symbol->aspect_align, symbol->aspect_clip, view_width, view_height, &x, &y,&width, &height); @@ -320,7 +320,7 @@ static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx) ctx->transform(&vb2user); } - + sp_group_render(item, ctx); ctx->popState(); } @@ -342,6 +342,11 @@ static void sp_root_render(SPItem *item, CairoRenderContext *ctx) static void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx) { + /* + if(ctx->_state->has_filtereffect) + printf("\nhas filtereffects"); + */ + if (SP_IS_ROOT(item)) { TRACE(("root\n")); return sp_root_render(item, ctx); @@ -375,7 +380,7 @@ CairoRenderer::setStateForItem(CairoRenderContext *ctx, SPItem const *item) { SPStyle const *style = SP_OBJECT_STYLE(item); ctx->setStateForStyle(style); - + CairoRenderState *state = ctx->getCurrentState(); state->clip_path = item->clip_ref->getObject(); state->mask = item->mask_ref->getObject(); @@ -395,7 +400,7 @@ CairoRenderer::renderItem(CairoRenderContext *ctx, SPItem *item) { ctx->pushState(); setStateForItem(ctx, item); - + CairoRenderState *state = ctx->getCurrentState(); state->need_layer = ( state->mask || state->clip_path || state->opacity != 1.0 ); @@ -444,7 +449,7 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc) } } TRACE(("%f x %f\n", ctx->_width, ctx->_height)); - + return ctx->setupSurface(d.x1-d.x0, d.y1-d.y0); } @@ -454,10 +459,10 @@ void CairoRenderer::applyClipPath(CairoRenderContext *ctx, SPClipPath const *cp) { g_assert( ctx != NULL && ctx->_is_valid ); - + if (cp == NULL) return; - + CairoRenderContext::CairoRenderMode saved_mode = ctx->getRenderMode(); ctx->setRenderMode(CairoRenderContext::RENDER_MODE_CLIP); @@ -499,7 +504,7 @@ void CairoRenderer::applyMask(CairoRenderContext *ctx, SPMask const *mask) { g_assert( ctx != NULL && ctx->_is_valid ); - + if (mask == NULL) return; @@ -539,7 +544,7 @@ calculatePreserveAspectRatio(unsigned int aspect_align, unsigned int aspect_clip { if (aspect_align == SP_ASPECT_NONE) return; - + double scalex, scaley, scale; double new_width, new_height; scalex = *width / vp_width; diff --git a/src/extension/internal/ps-out.cpp b/src/extension/internal/ps-out.cpp index dc60af4dd..d59e246b0 100644 --- a/src/extension/internal/ps-out.cpp +++ b/src/extension/internal/ps-out.cpp @@ -86,8 +86,8 @@ PsOutput::init (void) "\n" ".ps\n" "image/x-postscript\n" - "" N_("Postscript (*.ps)") "\n" - "" N_("Postscript File") "\n" + "" N_("PostScript (*.ps)") "\n" + "" N_("PostScript File") "\n" "\n" "", new PsOutput());