X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fextension%2Finternal%2Fpdf-cairo.cpp;h=6c2b2ed62382e548af57aa2e5780d24b3825027b;hb=17d87f5698f5c2958d38c6a6207c7b322a7adaf9;hp=0b500864d14c189b1a9bab81a4b0adcac55adae5;hpb=ee526a340556b691b04740ba2fcad279ab34f815;p=inkscape.git diff --git a/src/extension/internal/pdf-cairo.cpp b/src/extension/internal/pdf-cairo.cpp index 0b500864d..6c2b2ed62 100644 --- a/src/extension/internal/pdf-cairo.cpp +++ b/src/extension/internal/pdf-cairo.cpp @@ -6,7 +6,7 @@ /* * Authors: * Miklós Erdélyi - * + * * Based on pdf.cpp * * Licensed under GNU GPL @@ -32,8 +32,6 @@ #include #include -#include - #include #include #include @@ -47,6 +45,7 @@ #include #include "display/nr-arena-item.h" #include "display/canvas-bpath.h" +#include "display/inkscape-cairo.h" #include "sp-item.h" #include "style.h" #include "sp-linear-gradient.h" @@ -55,6 +54,10 @@ #include "libnrtype/font-instance.h" #include "libnrtype/font-style-to-pos.h" +#include "libnr/nr-matrix.h" +#include "libnr/nr-matrix-fns.h" +#include "libnr/nr-matrix-ops.h" + #include #include "pdf-cairo.h" @@ -95,7 +98,7 @@ PrintCairoPDF::~PrintCairoPDF(void) if (cr) cairo_destroy(cr); if (pdf_surface) cairo_surface_destroy(pdf_surface); if (_layout) g_object_unref(_layout); - + /* restore default signal handling for SIGPIPE */ #if !defined(_WIN32) && !defined(__WIN32__) (void) signal(SIGPIPE, SIG_DFL); @@ -313,7 +316,7 @@ PrintCairoPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc) (void) signal(SIGPIPE, SIG_IGN); #endif } - + // test output stream? // width and height in pt @@ -321,34 +324,51 @@ 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"); + Geom::Matrix t (Geom::identity()); if (pageBoundingBox) { d.x0 = d.y0 = 0; 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 + 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; } - printf("%f %f\n", _width, _height); + // 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 = Geom::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); cr = cairo_create(pdf_surface); - + + // move to the origin + cairo_translate (cr, -d.x0, -d.y0); + + // set cairo transform; we must scale the translation values to pt + _concat_transform (cr, t[0], t[1], t[2], t[3], t[4]*PT_PER_PX, t[5]*PT_PER_PX); + if (!_bitmap) { - cairo_scale(cr, PT_PER_PX, PT_PER_PX); - + cairo_scale(cr, PT_PER_PX, PT_PER_PX); + // from now on we can output px, but they will be treated as pt // note that the we do not have to flip the y axis // because Cairo's coordinate system is identical to Inkscape's - } + } return 1; } @@ -359,9 +379,11 @@ PrintCairoPDF::finish(Inkscape::Extension::Print *mod) if (!_stream) return 0; if (_bitmap) return 0; - cairo_show_page(cr); + cairo_show_page(cr); cairo_destroy(cr); + cairo_surface_finish(pdf_surface); + cairo_status_t status = cairo_surface_status(pdf_surface); cairo_surface_destroy(pdf_surface); cr = NULL; pdf_surface = NULL; @@ -373,28 +395,31 @@ PrintCairoPDF::finish(Inkscape::Extension::Print *mod) fclose(_stream); _stream = 0; - return 1; + if (status == CAIRO_STATUS_SUCCESS) + return true; + else + return false; } unsigned int -PrintCairoPDF::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float opacity) +PrintCairoPDF::bind(Inkscape::Extension::Print *mod, Geom::Matrix const *transform, float opacity) { if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - + if (opacity < 1.0) { cairo_push_group(cr); } else { cairo_save(cr); } - _concat_transform(cr, transform->c[0], transform->c[1], transform->c[2], transform->c[3], transform->c[4], transform->c[5]); -// g_printf("bind: (%f) %f %f %f %f %f %f\n", opacity, transform->c[0], transform->c[1], transform->c[2], transform->c[3], transform->c[4], transform->c[5]); + _concat_transform(cr, (*transform)[0], (*transform)[1], (*transform)[2], (*transform)[3], (*transform)[4], (*transform)[5]); + // printf("bind: (%f) %f %f %f %f %f %f\n", opacity, transform->c[0], transform->c[1], transform->c[2], transform->c[3], transform->c[4], transform->c[5]); // remember these to be able to undo them when outputting text - _last_tx = transform->c[4]; - _last_ty = transform->c[5]; - + _last_tx = (*transform)[4]; + _last_ty = (*transform)[5]; + _alpha_stack.push_back(opacity); - + return 1; } @@ -405,7 +430,7 @@ PrintCairoPDF::release(Inkscape::Extension::Print *mod) if (_bitmap) return 0; float opacity = _alpha_stack.back(); - + if (opacity < 1.0) { cairo_pop_group_to_source(cr); cairo_paint_with_alpha(cr, opacity); @@ -433,25 +458,25 @@ PrintCairoPDF::create_pattern_for_paint(SPPaintServer const *const paintserver, { cairo_pattern_t *pattern = NULL; bool apply_bbox2user = false; - + if (SP_IS_LINEARGRADIENT (paintserver)) { SPLinearGradient *lg=SP_LINEARGRADIENT(paintserver); - + sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built - NR::Point p1 (lg->x1.computed, lg->y1.computed); - NR::Point p2 (lg->x2.computed, lg->y2.computed); + Geom::Point p1 (lg->x1.computed, lg->y1.computed); + Geom::Point p2 (lg->x2.computed, lg->y2.computed); if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { // convert to userspace - NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); + Geom::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); p1 *= bbox2user; p2 *= bbox2user; } - + // create linear gradient pattern - pattern = cairo_pattern_create_linear(p1[NR::X], p1[NR::Y], p2[NR::X], p2[NR::Y]); - + pattern = cairo_pattern_create_linear(p1[Geom::X], p1[Geom::Y], p2[Geom::X], p2[Geom::Y]); + // add stops for (gint i = 0; unsigned(i) < lg->vector.stops.size(); i++) { float rgb[3]; @@ -464,21 +489,21 @@ PrintCairoPDF::create_pattern_for_paint(SPPaintServer const *const paintserver, sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built - NR::Point c (rg->cx.computed, rg->cy.computed); - NR::Point f (rg->fx.computed, rg->fy.computed); + Geom::Point c (rg->cx.computed, rg->cy.computed); + Geom::Point f (rg->fx.computed, rg->fy.computed); double r = rg->r.computed; - - NR::Coord const df = hypot(f[NR::X] - c[NR::X], f[NR::Y] - c[NR::Y]); + + Geom::Coord const df = hypot(f[Geom::X] - c[Geom::X], f[Geom::Y] - c[Geom::Y]); if (df >= r) { - f[NR::X] = c[NR::X] + (f[NR::X] - c[NR::X] ) * r / (float) df; - f[NR::Y] = c[NR::Y] + (f[NR::Y] - c[NR::Y] ) * r / (float) df; + f[Geom::X] = c[Geom::X] + (f[Geom::X] - c[Geom::X] ) * r / (float) df; + f[Geom::Y] = c[Geom::Y] + (f[Geom::Y] - c[Geom::Y] ) * r / (float) df; } - + if (pbox && SP_GRADIENT(rg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) apply_bbox2user = true; - + // create radial gradient pattern - pattern = cairo_pattern_create_radial(f[NR::X], f[NR::Y], 0, c[NR::X], c[NR::Y], r); + pattern = cairo_pattern_create_radial(f[Geom::X], f[Geom::Y], 0, c[Geom::X], c[Geom::Y], r); // add stops for (gint i = 0; unsigned(i) < rg->vector.stops.size(); i++) { @@ -487,7 +512,7 @@ PrintCairoPDF::create_pattern_for_paint(SPPaintServer const *const paintserver, cairo_pattern_add_color_stop_rgba(pattern, rg->vector.stops[i].offset, rgb[0], rgb[1], rgb[2], rg->vector.stops[i].opacity * alpha); } } - + if (pattern) { SPGradient *g = SP_GRADIENT(paintserver); @@ -506,7 +531,7 @@ PrintCairoPDF::create_pattern_for_paint(SPPaintServer const *const paintserver, break; } - cairo_matrix_t pattern_matrix; + cairo_matrix_t pattern_matrix; if (g->gradientTransform_set) { // apply gradient transformation cairo_matrix_init(&pattern_matrix, @@ -526,18 +551,18 @@ PrintCairoPDF::create_pattern_for_paint(SPPaintServer const *const paintserver, cairo_matrix_invert(&pattern_matrix); // because Cairo expects a userspace->patternspace matrix cairo_pattern_set_matrix(pattern, &pattern_matrix); } - + return pattern; } void PrintCairoPDF::print_fill_style(cairo_t *cr, SPStyle const *const style, NRRect const *pbox) { - g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_return_if_fail( style->fill.isColor() + || ( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ); - - if (style->fill.type == SP_PAINT_TYPE_COLOR) { + + if (style->fill.isColor()) { float rgb[3]; sp_color_get_rgb_floatv(&style->fill.value.color, rgb); @@ -545,11 +570,11 @@ PrintCairoPDF::print_fill_style(cairo_t *cr, SPStyle const *const style, NRRect cairo_set_source_rgba(cr, rgb[0], rgb[1], rgb[2], alpha); } else { - g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + g_assert( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); cairo_pattern_t *pattern = create_pattern_for_paint(SP_STYLE_FILL_SERVER(style), pbox, 1.0); - + if (pattern) { cairo_set_source(cr, pattern); cairo_pattern_destroy(pattern); @@ -558,36 +583,39 @@ PrintCairoPDF::print_fill_style(cairo_t *cr, SPStyle const *const style, NRRect } unsigned int -PrintCairoPDF::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *const style, +PrintCairoPDF::fill(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *const style, NRRect const *pbox, NRRect const *dbox, NRRect const *bbox) { if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - if ( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { - + if ( style->fill.isColor() + || ( style->fill.isPaintserver() + && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { + float alpha = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); - + cairo_save(cr); - + print_fill_style(cr, style, pbox); - print_bpath(cr, bpath->path); - if (style->fill_rule.value == SP_WIND_RULE_EVENODD) { + + cairo_new_path(cr); + feed_pathvector_to_cairo(cr, pathv); + + if (style->fill_rule.computed == SP_WIND_RULE_EVENODD) { cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); } else { cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING); } if (alpha != 1.0 && - style->fill.type != SP_PAINT_TYPE_COLOR) { + !style->fill.isColor()) { cairo_clip (cr); cairo_paint_with_alpha (cr, alpha); } else { cairo_fill(cr); } - + cairo_restore(cr); } @@ -599,16 +627,16 @@ PrintCairoPDF::print_stroke_style(cairo_t *cr, SPStyle const *style, NRRect cons { float alpha = SP_SCALE24_TO_FLOAT(style->stroke_opacity.value); - if ( style->stroke.type == SP_PAINT_TYPE_COLOR ) { + if ( style->stroke.isColor() ) { float rgb[3]; sp_color_get_rgb_floatv(&style->stroke.value.color, rgb); - + cairo_set_source_rgba(cr, rgb[0], rgb[1], rgb[2], alpha); - } else if ( style->stroke.type == SP_PAINT_TYPE_PAINTSERVER + } else if ( style->stroke.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) { cairo_pattern_t *pattern = create_pattern_for_paint(SP_STYLE_STROKE_SERVER(style), pbox, alpha); - + if (pattern) { cairo_set_source(cr, pattern); cairo_pattern_destroy(pattern); @@ -622,9 +650,9 @@ PrintCairoPDF::print_stroke_style(cairo_t *cr, SPStyle const *style, NRRect cons } else { cairo_set_dash(cr, NULL, 0, 0.0); // disable dashing } - + cairo_set_line_width(cr, style->stroke_width.computed); - + // set line join type cairo_line_join_t join = CAIRO_LINE_JOIN_MITER; switch (style->stroke_linejoin.computed) { @@ -637,9 +665,9 @@ PrintCairoPDF::print_stroke_style(cairo_t *cr, SPStyle const *style, NRRect cons case SP_STROKE_LINEJOIN_BEVEL: join = CAIRO_LINE_JOIN_BEVEL; break; - } + } cairo_set_line_join(cr, join); - + // set line cap type cairo_line_cap_t cap = CAIRO_LINE_CAP_BUTT; switch (style->stroke_linecap.computed) { @@ -652,28 +680,30 @@ PrintCairoPDF::print_stroke_style(cairo_t *cr, SPStyle const *style, NRRect cons case SP_STROKE_LINECAP_SQUARE: cap = CAIRO_LINE_CAP_SQUARE; break; - } + } cairo_set_line_cap(cr, cap); cairo_set_miter_limit(cr, MAX(1, style->stroke_miterlimit.value)); } unsigned int -PrintCairoPDF::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *style, +PrintCairoPDF::stroke(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *style, NRRect const *pbox, NRRect const *dbox, NRRect const *bbox) { if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - if ( style->stroke.type == SP_PAINT_TYPE_COLOR || - ( style->stroke.type == SP_PAINT_TYPE_PAINTSERVER + if ( style->stroke.isColor() || + ( style->stroke.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) ) { - cairo_save(cr); - - print_stroke_style(cr, style, pbox); - print_bpath(cr, bpath->path); + cairo_save(cr); + + cairo_new_path(cr); + print_stroke_style(cr, style, pbox); + + feed_pathvector_to_cairo(cr, pathv); cairo_stroke(cr); - + cairo_restore(cr); } @@ -682,14 +712,14 @@ PrintCairoPDF::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRM unsigned int PrintCairoPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w, unsigned int h, unsigned int rs, - NRMatrix const *transform, SPStyle const *style) + Geom::Matrix const *transform, SPStyle const *style) { if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - + guchar* px_rgba = (guchar*)g_malloc(4 * w * h); if (!px_rgba) return 0; - + float alpha = _alpha_stack.back(); // make a copy of the original pixbuf with premultiplied alpha @@ -699,7 +729,7 @@ PrintCairoPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w guchar const *src = px + i * rs + j * 4; guint32 *dst = (guint32 *)(px_rgba + i * rs + j * 4); guchar r, g, b, alpha_dst; - + // calculate opacity-modified alpha alpha_dst = src[3]; if (alpha != 1.0) @@ -709,26 +739,26 @@ PrintCairoPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w r = src[0]*alpha_dst/255; g = src[1]*alpha_dst/255; b = src[2]*alpha_dst/255; - + *dst = (((alpha_dst) << 24) | (((r)) << 16) | (((g)) << 8) | (b)); } } - + cairo_surface_t *image_surface = cairo_image_surface_create_for_data(px_rgba, CAIRO_FORMAT_ARGB32, w, h, w * 4); if (cairo_surface_status(image_surface)) { g_printf("Error: %s\n", cairo_status_to_string(cairo_surface_status(image_surface))); return 0; } - + cairo_save(cr); - + // scaling by width & height is not needed because it will be done by cairo-pdf // we have to translate down by height also in order to eliminate the last translation done by sp_image_print cairo_matrix_t matrix; cairo_matrix_init(&matrix, - transform->c[0]/w, transform->c[1], - transform->c[2], -transform->c[3]/h, - transform->c[4], transform->c[5] + transform->c[3]); + (*transform)[0]/w, (*transform)[1], + (*transform)[2], -(*transform)[3]/h, + (*transform)[4], (*transform)[5] + (*transform)[3]); cairo_transform(cr, &matrix); cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image_surface); @@ -736,19 +766,19 @@ PrintCairoPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w cairo_set_source(cr, pattern); cairo_pattern_destroy(pattern); - + // set clip region so that the pattern will not be repeated (bug in Cairo prior 1.2.1) cairo_new_path(cr); cairo_rectangle(cr, 0, 0, w, h); cairo_clip(cr); cairo_paint(cr); - + cairo_restore(cr); - + cairo_surface_destroy(image_surface); g_free(px_rgba); - + return 0; } @@ -756,8 +786,8 @@ PrintCairoPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w #ifndef RENDER_WITH_PANGO_CAIRO -NR::Point -PrintCairoPDF::draw_glyphs(cairo_t *cr, NR::Point p, PangoFont *font, PangoGlyphString *glyph_string, +Geom::Point +PrintCairoPDF::draw_glyphs(cairo_t *cr, Geom::Point p, PangoFont *font, PangoGlyphString *glyph_string, bool vertical, bool stroke) { cairo_glyph_t glyph_array[GLYPH_ARRAY_SIZE]; @@ -770,7 +800,7 @@ PrintCairoPDF::draw_glyphs(cairo_t *cr, NR::Point p, PangoFont *font, PangoGlyph int num_invalid_glyphs = 0; for (gint i = 0; i < glyph_string->num_glyphs; i++) { info = &glyph_string->glyphs[i]; - // skip glyphs which are PANGO_GLYPH_EMPTY (0x0FFFFFFF) or have + // skip glyphs which are PANGO_GLYPH_EMPTY (0x0FFFFFFF) or have // the PANGO_GLYPH_UNKNOWN_FLAG (0x10000000) set if (info->glyph == 0x0FFFFFFF || info->glyph & 0x10000000) { num_invalid_glyphs++; @@ -778,8 +808,8 @@ PrintCairoPDF::draw_glyphs(cairo_t *cr, NR::Point p, PangoFont *font, PangoGlyph } glyphs[i - num_invalid_glyphs].index = info->glyph; - glyphs[i - num_invalid_glyphs].x = p[NR::X] + (x_offset + info->geometry.x_offset)/PANGO_SCALE; - glyphs[i - num_invalid_glyphs].y = p[NR::Y] + (y_offset + info->geometry.y_offset)/PANGO_SCALE; + glyphs[i - num_invalid_glyphs].x = p[Geom::X] + (x_offset + info->geometry.x_offset)/PANGO_SCALE; + glyphs[i - num_invalid_glyphs].y = p[Geom::Y] + (y_offset + info->geometry.y_offset)/PANGO_SCALE; if (vertical) { cairo_text_extents_t extents; @@ -798,14 +828,14 @@ PrintCairoPDF::draw_glyphs(cairo_t *cr, NR::Point p, PangoFont *font, PangoGlyph if (glyph_string->num_glyphs > GLYPH_ARRAY_SIZE) g_free(glyphs); - return NR::Point(x_offset, y_offset); + return Geom::Point(x_offset, y_offset); } #endif unsigned int -PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p, +PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, Geom::Point p, SPStyle const *const style) { bool dirty_pattern = false; @@ -817,6 +847,7 @@ PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point // this needs to be there to encounter Cairo's userspace locking semantics for set_source // otherwise gradients won't be shown correctly + // printf("\n _last_tx:%f _last_ty:%f", _last_tx, _last_ty); cairo_translate(cr, -_last_tx, -_last_ty); // create pango layout and context if needed @@ -830,13 +861,13 @@ PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point } // create font instance from style and use it - font_instance *tf = (font_factory::Default())->Face(style->text->font_family.value, font_style_to_pos(*style)); + font_instance *tf = font_factory::Default()->FaceFromStyle(style); if (tf == NULL) { // do something g_printf("Warning: trouble getting font_instance\n"); tf = (font_factory::Default())->Face("sans", font_style_to_pos(*style)); - } + } PangoFontDescription *adjusted = pango_font_description_copy(tf->descr); - + pango_font_description_set_absolute_size(adjusted, (gint)(style->font_size.computed * PANGO_SCALE)); pango_layout_set_font_description(_layout, adjusted); pango_layout_set_text(_layout, text, -1); @@ -883,29 +914,36 @@ PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point matrix.yy = -matrix.xx; cairo_set_font_matrix(cr, &matrix); #endif - - if ( style->fill.type == SP_PAINT_TYPE_COLOR - || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER + + if ( style->fill.isColor() + || ( style->fill.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { // set fill style print_fill_style(cr, style, NULL); #ifndef RENDER_WITH_PANGO_CAIRO - NR::Point cursor(_last_tx, _last_ty); + Geom::Point cursor(_last_tx, _last_ty); for (GSList *tmpList = line->runs; tmpList && tmpList->data; tmpList = tmpList->next) { PangoLayoutRun *run = (PangoLayoutRun *)tmpList->data; cursor += draw_glyphs(cr, cursor, run->item->analysis.font, run->glyphs, dirty_pattern, false) / PANGO_SCALE; } #else cairo_new_path(cr); - cairo_move_to(cr, _last_tx, _last_ty); + // as pango has inverted origin we simulate the moveto and apply the vertical flip + //cairo_move_to(cr, _last_tx, _last_ty); + cairo_translate(cr, _last_tx, _last_ty); + cairo_scale(cr, 1, -1); + cairo_move_to(cr, 0, 0); pango_cairo_show_layout_line(cr, line); + cairo_scale(cr, 1, -1); + cairo_translate(cr, -_last_tx, -_last_ty); + #endif } - if (style->stroke.type == SP_PAINT_TYPE_COLOR - || ( style->stroke.type == SP_PAINT_TYPE_PAINTSERVER + if (style->stroke.isColor() + || ( style->stroke.isPaintserver() && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) ) { // set stroke style @@ -913,15 +951,21 @@ PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point // paint stroke #ifndef RENDER_WITH_PANGO_CAIRO - NR::Point cursor(_last_tx, _last_ty); + Geom::Point cursor(_last_tx, _last_ty); for (GSList *tmpList = line->runs; tmpList && tmpList->data; tmpList = tmpList->next) { PangoLayoutRun *run = (PangoLayoutRun *)tmpList->data; cursor += draw_glyphs(cr, cursor, run->item->analysis.font, run->glyphs, dirty_pattern, true) / PANGO_SCALE; } #else cairo_new_path(cr); - cairo_move_to(cr, _last_tx, _last_ty); + // as pango has inverted origin we simulate the moveto and apply the vertical flip + //cairo_move_to(cr, _last_tx, _last_ty); + cairo_translate(cr, _last_tx, _last_ty); + cairo_scale(cr, 1, -1); + cairo_move_to(cr, 0, 0); pango_cairo_layout_line_path(cr, line); + cairo_scale(cr, 1, -1); + cairo_translate(cr, -_last_tx, -_last_ty); #endif cairo_stroke(cr); } @@ -937,56 +981,18 @@ PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point FcPatternAddBool(fc_pattern, FC_VERTICAL_LAYOUT, FcFalse); } #endif - tf->Unref(); -return 0; + return 0; } /* Helper functions */ -void -PrintCairoPDF::print_bpath(cairo_t *cr, NArtBpath const *bp) -{ - cairo_new_path(cr); - bool closed = false; - while (bp->code != NR_END) { - switch (bp->code) { - case NR_MOVETO: - if (closed) { - cairo_close_path(cr); - } - closed = true; - cairo_move_to(cr, bp->x3, bp->y3); - break; - case NR_MOVETO_OPEN: - if (closed) { - cairo_close_path(cr); - } - closed = false; - cairo_move_to(cr, bp->x3, bp->y3); - break; - case NR_LINETO: - cairo_line_to(cr, bp->x3, bp->y3); - break; - case NR_CURVETO: - cairo_curve_to(cr, bp->x1, bp->y1, bp->x2, bp->y2, bp->x3, bp->y3); - break; - default: - break; - } - bp += 1; - } - if (closed) { - cairo_close_path(cr); - } -} - static void _concat_transform(cairo_t *cr, double xx, double yx, double xy, double yy, double x0, double y0) { cairo_matrix_t matrix; - cairo_matrix_init(&matrix, xx, yx, xy, yy, x0, y0); + cairo_matrix_init(&matrix, xx, yx, xy, yy, x0, y0); cairo_transform(cr, &matrix); } @@ -1017,14 +1023,17 @@ PrintCairoPDF::init(void) { /* PDF out */ (void) Inkscape::Extension::build_from_mem( - "\n" + "\n" "" N_("PDF Print") "\n" "" SP_MODULE_KEY_PRINT_CAIRO_PDF "\n" - "FALSE\n" + "false\n" "72\n" "| lp\n" - "TRUE\n" - "TRUE\n" + "true\n" + "true\n" + "false\n" + "false\n" + "\n" "\n" "", new PrintCairoPDF()); }