summaryrefslogtreecommitdiffstats
path: root/src/display/nr-style.cpp
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-12-11 13:23:47 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-12-11 13:23:47 +0000
commitbf7925c4fde9cb28f5ae432478fd1be6a5bb8727 (patch)
tree45657c1b83b60d7f4b8f13a68e4e3875239c7709 /src/display/nr-style.cpp
parentTurn #defines into enum. (diff)
downloadinkscape-bf7925c4fde9cb28f5ae432478fd1be6a5bb8727.tar.gz
inkscape-bf7925c4fde9cb28f5ae432478fd1be6a5bb8727.zip
Reduce code redundancy.
Diffstat (limited to 'src/display/nr-style.cpp')
-rw-r--r--src/display/nr-style.cpp127
1 files changed, 39 insertions, 88 deletions
diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp
index b25cc80c6..8acc14421 100644
--- a/src/display/nr-style.cpp
+++ b/src/display/nr-style.cpp
@@ -342,93 +342,69 @@ void NRStyle::set(SPStyle *style, SPStyle *context_style)
update();
}
-bool NRStyle::prepareFill(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern)
+cairo_pattern_t* NRStyle::preparePaint(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern, Paint& paint)
{
- // update fill pattern
- if (!fill_pattern) {
- switch (fill.type) {
+ cairo_pattern_t* cpattern = nullptr;
+
+ switch (paint.type) {
case PAINT_SERVER:
if (pattern) {
- fill_pattern = pattern->renderPattern(fill.opacity);
+ cpattern = pattern->renderPattern(paint.opacity);
} else {
- fill_pattern = fill.server->pattern_new(dc.raw(), paintbox, fill.opacity);
+ cpattern = paint.server->pattern_new(dc.raw(), paintbox, paint.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);
- }
+ SPColor const &c = paint.color;
+ cpattern = cairo_pattern_create_rgba(
+ c.v.c[0], c.v.c[1], c.v.c[2], paint.opacity);
+ double red = 0;
+ double green = 0;
+ double blue = 0;
+ double alpha = 0;
+ cairo_pattern_get_rgba(cpattern, &red, &green, &blue, &alpha);
+ }
break;
default:
break;
- }
}
- if (!fill_pattern) return false;
- return true;
+ return cpattern;
}
-void NRStyle::applyFill(Inkscape::DrawingContext &dc)
+bool NRStyle::prepareFill(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern)
{
- dc.setSource(fill_pattern);
- dc.setFillRule(fill_rule);
+ if (!fill_pattern) fill_pattern = preparePaint(dc, paintbox, pattern, fill);
+ return fill_pattern != nullptr;
+}
+
+bool NRStyle::prepareStroke(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern)
+{
+ if (!stroke_pattern) stroke_pattern = preparePaint(dc, paintbox, pattern, stroke);
+ return stroke_pattern != nullptr;
}
bool NRStyle::prepareTextDecorationFill(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern)
{
- // update text decoration pattern
- if (!text_decoration_fill_pattern) {
- switch (text_decoration_fill.type) {
- case PAINT_SERVER:
- if (pattern) {
- text_decoration_fill_pattern = pattern->renderPattern(
- text_decoration_fill.opacity);
- } else {
- text_decoration_fill_pattern = text_decoration_fill.server->pattern_new(dc.raw(),
- paintbox, text_decoration_fill.opacity);
- }
- break;
- case PAINT_COLOR: {
- SPColor const &c = text_decoration_fill.color;
- text_decoration_fill_pattern = cairo_pattern_create_rgba(
- c.v.c[0], c.v.c[1], c.v.c[2], text_decoration_fill.opacity);
- } break;
- default: break;
- }
- }
- if (!text_decoration_fill_pattern) return false;
- return true;
+ if (!text_decoration_fill_pattern) text_decoration_fill_pattern = preparePaint(dc, paintbox, pattern, text_decoration_fill);
+ return text_decoration_fill_pattern != nullptr;
}
-void NRStyle::applyTextDecorationFill(Inkscape::DrawingContext &dc)
+bool NRStyle::prepareTextDecorationStroke(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern)
{
- dc.setSource(text_decoration_fill_pattern);
- // Fill rule does not matter, no intersections.
+ if (!text_decoration_stroke_pattern) text_decoration_stroke_pattern = preparePaint(dc, paintbox, pattern, text_decoration_stroke);
+ return text_decoration_stroke_pattern != nullptr;
}
-bool NRStyle::prepareStroke(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern)
+void NRStyle::applyFill(Inkscape::DrawingContext &dc)
{
- if (!stroke_pattern) {
- switch (stroke.type) {
- case PAINT_SERVER:
- if (pattern) {
- stroke_pattern = pattern->renderPattern(stroke.opacity);
- } else {
- stroke_pattern = stroke.server->pattern_new(dc.raw(), 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;
+ dc.setSource(fill_pattern);
+ dc.setFillRule(fill_rule);
+}
+
+void NRStyle::applyTextDecorationFill(Inkscape::DrawingContext &dc)
+{
+ dc.setSource(text_decoration_fill_pattern);
+ // Fill rule does not matter, no intersections.
}
void NRStyle::applyStroke(Inkscape::DrawingContext &dc)
@@ -441,31 +417,6 @@ void NRStyle::applyStroke(Inkscape::DrawingContext &dc)
cairo_set_dash(dc.raw(), dash, n_dash, dash_offset); // fixme
}
-bool NRStyle::prepareTextDecorationStroke(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern)
-{
- if (!text_decoration_stroke_pattern) {
- switch (text_decoration_stroke.type) {
- case PAINT_SERVER:
- if (pattern) {
- text_decoration_stroke_pattern = pattern->renderPattern(
- text_decoration_stroke.opacity);
- } else {
- text_decoration_stroke_pattern = text_decoration_stroke.server->pattern_new(
- dc.raw(), paintbox, text_decoration_stroke.opacity);
- }
- break;
- case PAINT_COLOR: {
- SPColor const &c = text_decoration_stroke.color;
- text_decoration_stroke_pattern = cairo_pattern_create_rgba(
- c.v.c[0], c.v.c[1], c.v.c[2], text_decoration_stroke.opacity);
- } break;
- default: break;
- }
- }
- if (!text_decoration_stroke_pattern) return false;
- return true;
-}
-
void NRStyle::applyTextDecorationStroke(Inkscape::DrawingContext &dc)
{
dc.setSource(text_decoration_stroke_pattern);