From cf6ce8045cd7a019c263d557fd2ea6c3b8a0e669 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Mon, 28 Jun 2010 02:37:10 +0200 Subject: Text rendering. Factor out style handling into nr-style.h (bzr r9508.1.5) --- src/display/nr-style.cpp | 218 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 src/display/nr-style.cpp (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp new file mode 100644 index 000000000..c15dd78a3 --- /dev/null +++ b/src/display/nr-style.cpp @@ -0,0 +1,218 @@ +/** + * @file + * @brief Style information for rendering + *//* + * Authors: + * Krzysztof Kosiński + * + * Copyright (C) 2010 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "display/nr-style.h" +#include "style.h" +#include "sp-paint-server.h" +#include "display/canvas-bpath.h" // contains SPStrokeJoinType, SPStrokeCapType etc. (WTF!) + +void NRStyle::Paint::clear() +{ + if (server) { + sp_object_unref(server, NULL); + server = NULL; + } + type = PAINT_NONE; +} + +void NRStyle::Paint::set(SPColor const &c) +{ + clear(); + type = PAINT_COLOR; + color = c; +} + +void NRStyle::Paint::set(SPPaintServer *ps) +{ + clear(); + if (ps) { + type = PAINT_SERVER; + server = ps; + sp_object_ref(server, NULL); + } +} + +NRStyle::NRStyle() + : fill() + , stroke() + , stroke_width(0.0) + , miter_limit(0.0) + , n_dash(0) + , dash(NULL) + , dash_offset(0.0) + , fill_rule(CAIRO_FILL_RULE_EVEN_ODD) + , line_cap(CAIRO_LINE_CAP_BUTT) + , line_join(CAIRO_LINE_JOIN_MITER) +{} + +NRStyle::~NRStyle() +{ + cairo_pattern_destroy(fill_pattern); + cairo_pattern_destroy(stroke_pattern); + if (dash) delete dash; +} + +void NRStyle::set(SPStyle *style) +{ + if ( style->fill.isPaintserver() ) { + fill.set(style->getFillPaintServer()); + } else if ( style->fill.isColor() ) { + fill.set(style->fill.value.color); + } else if ( style->fill.isNone() ) { + fill.clear(); + } else { + g_assert_not_reached(); + } + fill.opacity = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); + + switch (style->fill_rule.computed) { + case SP_WIND_RULE_EVENODD: + fill_rule = CAIRO_FILL_RULE_EVEN_ODD; + break; + case SP_WIND_RULE_NONZERO: + fill_rule = CAIRO_FILL_RULE_WINDING; + break; + default: + g_assert_not_reached(); + } + + if ( style->stroke.isPaintserver() ) { + stroke.set(style->getStrokePaintServer()); + } else if ( style->stroke.isColor() ) { + stroke.set(style->stroke.value.color); + } else if ( style->stroke.isNone() ) { + stroke.clear(); + } else { + g_assert_not_reached(); + } + stroke.opacity = SP_SCALE24_TO_FLOAT(style->stroke_opacity.value); + stroke_width = style->stroke_width.computed; + switch (style->stroke_linecap.computed) { + case SP_STROKE_LINECAP_ROUND: + line_cap = CAIRO_LINE_CAP_ROUND; + break; + case SP_STROKE_LINECAP_SQUARE: + line_cap = CAIRO_LINE_CAP_SQUARE; + break; + case SP_STROKE_LINECAP_BUTT: + line_cap = CAIRO_LINE_CAP_BUTT; + break; + default: + g_assert_not_reached(); + } + switch (style->stroke_linejoin.computed) { + case SP_STROKE_LINEJOIN_ROUND: + line_join = CAIRO_LINE_JOIN_ROUND; + break; + case SP_STROKE_LINEJOIN_BEVEL: + line_join = CAIRO_LINE_JOIN_BEVEL; + break; + case SP_STROKE_LINEJOIN_MITER: + line_join = CAIRO_LINE_JOIN_MITER; + break; + default: + g_assert_not_reached(); + } + miter_limit = style->stroke_miterlimit.value; + + delete [] dash; + + n_dash = style->stroke_dash.n_dash; + if (n_dash != 0) { + dash_offset = style->stroke_dash.offset; + dash = new double[n_dash]; + for (unsigned int i = 0; i < n_dash; ++i) { + dash[i] = style->stroke_dash.dash[i]; + } + } else { + dash_offset = 0.0; + dash = NULL; + } + + opacity = SP_SCALE24_TO_FLOAT(style->opacity.value); + + update(); +} + +bool NRStyle::prepareFill(cairo_t *ct, NRRect *paintbox) +{ + // update fill pattern + if (!fill_pattern) { + switch (fill.type) { + case PAINT_SERVER: + fill_pattern = sp_paint_server_create_pattern(fill.server, ct, paintbox, fill.opacity); + break; + case PAINT_COLOR: { + SPColor const &c = fill.color; + fill_pattern = cairo_pattern_create_rgba( + c.v.c[0], c.v.c[1], c.v.c[2], fill.opacity); + } break; + default: break; + } + } + if (!fill_pattern) return false; + return true; +} + +void NRStyle::applyFill(cairo_t *ct) +{ + cairo_set_source(ct, fill_pattern); + cairo_set_fill_rule(ct, fill_rule); +} + +bool NRStyle::prepareStroke(cairo_t *ct, NRRect *paintbox) +{ + if (!stroke_pattern) { + switch (stroke.type) { + case PAINT_SERVER: + stroke_pattern = sp_paint_server_create_pattern(stroke.server, ct, paintbox, stroke.opacity); + break; + case PAINT_COLOR: { + SPColor const &c = stroke.color; + stroke_pattern = cairo_pattern_create_rgba( + c.v.c[0], c.v.c[1], c.v.c[2], stroke.opacity); + } break; + default: break; + } + } + if (!stroke_pattern) return false; + return true; +} + +void NRStyle::applyStroke(cairo_t *ct) +{ + cairo_set_source(ct, stroke_pattern); + cairo_set_line_width(ct, stroke_width); + cairo_set_line_cap(ct, line_cap); + cairo_set_line_join(ct, line_join); + cairo_set_miter_limit(ct, miter_limit); + cairo_set_dash(ct, dash, n_dash, dash_offset); +} + +void NRStyle::update() +{ + // force pattern update + cairo_pattern_destroy(fill_pattern); + cairo_pattern_destroy(stroke_pattern); + fill_pattern = NULL; + stroke_pattern = NULL; +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : -- cgit v1.2.3 From b80e2b5bb72ebb814745bd58ccf10bfa617dd7e9 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 7 Jul 2010 20:08:47 +0200 Subject: Fix group opacity (bzr r9508.1.13) --- src/display/nr-style.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index c15dd78a3..bf2f2d305 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -137,8 +137,6 @@ void NRStyle::set(SPStyle *style) dash = NULL; } - opacity = SP_SCALE24_TO_FLOAT(style->opacity.value); - update(); } -- cgit v1.2.3 From 267b81d9fd0d1254a80b008c26237fbe4bd93610 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 6 Aug 2010 01:23:28 +0200 Subject: Minor cleanups (bzr r9508.1.51) --- src/display/nr-style.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index bf2f2d305..40366f5d3 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -55,8 +55,8 @@ NRStyle::NRStyle() NRStyle::~NRStyle() { - cairo_pattern_destroy(fill_pattern); - cairo_pattern_destroy(stroke_pattern); + if (fill_pattern) cairo_pattern_destroy(fill_pattern); + if (stroke_pattern) cairo_pattern_destroy(stroke_pattern); if (dash) delete dash; } @@ -123,7 +123,7 @@ void NRStyle::set(SPStyle *style) } miter_limit = style->stroke_miterlimit.value; - delete [] dash; + if (dash) delete [] dash; n_dash = style->stroke_dash.n_dash; if (n_dash != 0) { -- cgit v1.2.3 From 3e80b896214d68d84a475b0c780f6770ad6ae397 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 9 Apr 2011 03:46:06 +0200 Subject: Initialize cached patterns to NULL in NRStyle, should fix crashes (bzr r9508.1.80) --- src/display/nr-style.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 40366f5d3..72fa0c444 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -51,6 +51,8 @@ NRStyle::NRStyle() , fill_rule(CAIRO_FILL_RULE_EVEN_ODD) , line_cap(CAIRO_LINE_CAP_BUTT) , line_join(CAIRO_LINE_JOIN_MITER) + , fill_pattern(NULL) + , stroke_pattern(NULL) {} NRStyle::~NRStyle() @@ -198,8 +200,8 @@ void NRStyle::applyStroke(cairo_t *ct) void NRStyle::update() { // force pattern update - cairo_pattern_destroy(fill_pattern); - cairo_pattern_destroy(stroke_pattern); + if (fill_pattern) cairo_pattern_destroy(fill_pattern); + if (stroke_pattern) cairo_pattern_destroy(stroke_pattern); fill_pattern = NULL; stroke_pattern = NULL; } -- cgit v1.2.3 From 328fad57dbfb65e3bd31062021d5cc3081e68515 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 22 Jul 2011 04:09:27 +0200 Subject: Replace direct use of Cairo contexts and surfaces in the rendering tree with wrappers which keep some extra information about the surface, amd NRRect and NRRectL use with Geom::Rect and Geom::IntRect. Should simplify implementing filter primitive subregions. (bzr r10347.1.17) --- src/display/nr-style.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 72fa0c444..fa5dd0d98 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -13,6 +13,8 @@ #include "style.h" #include "sp-paint-server.h" #include "display/canvas-bpath.h" // contains SPStrokeJoinType, SPStrokeCapType etc. (WTF!) +#include "display/drawing-context.h" +#include "libnr/nr-rect.h" void NRStyle::Paint::clear() { @@ -142,14 +144,15 @@ void NRStyle::set(SPStyle *style) update(); } -bool NRStyle::prepareFill(cairo_t *ct, NRRect *paintbox) +bool NRStyle::prepareFill(Inkscape::DrawingContext &ct, Geom::OptRect const &paintbox) { // update fill pattern if (!fill_pattern) { switch (fill.type) { - case PAINT_SERVER: - fill_pattern = sp_paint_server_create_pattern(fill.server, ct, paintbox, fill.opacity); - break; + case PAINT_SERVER: { + NRRect pb(paintbox); + fill_pattern = sp_paint_server_create_pattern(fill.server, ct.raw(), &pb, fill.opacity); + } break; case PAINT_COLOR: { SPColor const &c = fill.color; fill_pattern = cairo_pattern_create_rgba( @@ -162,19 +165,20 @@ bool NRStyle::prepareFill(cairo_t *ct, NRRect *paintbox) return true; } -void NRStyle::applyFill(cairo_t *ct) +void NRStyle::applyFill(Inkscape::DrawingContext &ct) { - cairo_set_source(ct, fill_pattern); - cairo_set_fill_rule(ct, fill_rule); + ct.setSource(fill_pattern); + ct.setFillRule(fill_rule); } -bool NRStyle::prepareStroke(cairo_t *ct, NRRect *paintbox) +bool NRStyle::prepareStroke(Inkscape::DrawingContext &ct, Geom::OptRect const &paintbox) { if (!stroke_pattern) { switch (stroke.type) { - case PAINT_SERVER: - stroke_pattern = sp_paint_server_create_pattern(stroke.server, ct, paintbox, stroke.opacity); - break; + case PAINT_SERVER: { + NRRect pb(paintbox); + stroke_pattern = sp_paint_server_create_pattern(stroke.server, ct.raw(), &pb, stroke.opacity); + } break; case PAINT_COLOR: { SPColor const &c = stroke.color; stroke_pattern = cairo_pattern_create_rgba( @@ -187,14 +191,14 @@ bool NRStyle::prepareStroke(cairo_t *ct, NRRect *paintbox) return true; } -void NRStyle::applyStroke(cairo_t *ct) +void NRStyle::applyStroke(Inkscape::DrawingContext &ct) { - cairo_set_source(ct, stroke_pattern); - cairo_set_line_width(ct, stroke_width); - cairo_set_line_cap(ct, line_cap); - cairo_set_line_join(ct, line_join); - cairo_set_miter_limit(ct, miter_limit); - cairo_set_dash(ct, dash, n_dash, dash_offset); + ct.setSource(stroke_pattern); + ct.setLineWidth(stroke_width); + ct.setLineCap(line_cap); + ct.setLineJoin(line_join); + ct.setMiterLimit(miter_limit); + cairo_set_dash(ct.raw(), dash, n_dash, dash_offset); // fixme } void NRStyle::update() -- cgit v1.2.3 From 79012ca437ff3d7c25e4d164b1b9c3dccc2b4b7f Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 27 Aug 2011 15:20:17 +0200 Subject: Remove NRRect from paint servers and temporary calculations (bzr r10582.1.4) --- src/display/nr-style.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index fa5dd0d98..9db52ea7e 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -150,8 +150,7 @@ bool NRStyle::prepareFill(Inkscape::DrawingContext &ct, Geom::OptRect const &pai if (!fill_pattern) { switch (fill.type) { case PAINT_SERVER: { - NRRect pb(paintbox); - fill_pattern = sp_paint_server_create_pattern(fill.server, ct.raw(), &pb, fill.opacity); + fill_pattern = sp_paint_server_create_pattern(fill.server, ct.raw(), paintbox, fill.opacity); } break; case PAINT_COLOR: { SPColor const &c = fill.color; @@ -176,8 +175,7 @@ bool NRStyle::prepareStroke(Inkscape::DrawingContext &ct, Geom::OptRect const &p if (!stroke_pattern) { switch (stroke.type) { case PAINT_SERVER: { - NRRect pb(paintbox); - stroke_pattern = sp_paint_server_create_pattern(stroke.server, ct.raw(), &pb, stroke.opacity); + stroke_pattern = sp_paint_server_create_pattern(stroke.server, ct.raw(), paintbox, stroke.opacity); } break; case PAINT_COLOR: { SPColor const &c = stroke.color; -- cgit v1.2.3 From d6af1140ee108cc7d7fb6e0ba89ff7e30bb7ad3a Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 27 Aug 2011 18:05:32 +0200 Subject: Completely remove NRRect, NRRectL, in-svg-plane.h (bzr r10582.1.6) --- src/display/nr-style.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 9db52ea7e..6e8ccb030 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -14,7 +14,6 @@ #include "sp-paint-server.h" #include "display/canvas-bpath.h" // contains SPStrokeJoinType, SPStrokeCapType etc. (WTF!) #include "display/drawing-context.h" -#include "libnr/nr-rect.h" void NRStyle::Paint::clear() { -- cgit v1.2.3 From b0c0eed3b05e20673469dc7b70cf3a92a42429b2 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 2 Oct 2011 01:34:59 -0700 Subject: Removing redundant doxygen @brief tag. (bzr r10656) --- src/display/nr-style.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 6e8ccb030..86102f9e8 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -1,6 +1,6 @@ /** * @file - * @brief Style information for rendering + * Style information for rendering. *//* * Authors: * Krzysztof Kosiński -- cgit v1.2.3