From fc374ad5b6c411994a37d81f0dc78baecdc55e88 Mon Sep 17 00:00:00 2001 From: fruchti Date: Sun, 24 Dec 2023 13:53:56 +0100 Subject: [PATCH] Allow setting paper background colour --- lib/plot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/plot.py b/lib/plot.py index 8e3e0dd..c9915bf 100644 --- a/lib/plot.py +++ b/lib/plot.py @@ -16,6 +16,7 @@ class Paper: 'left': 0 } self.set_margins(margins) + self.background_colour = None def set_margins(self, margins=None, top=None, right=None, bottom=None, left=None): @@ -234,15 +235,20 @@ class SVGPlotter(Plotter): def __init__(self, file_name, paper, line_width=0.5, colour=[0, 0, 0, 1]): dpi = 72 + width = paper.width / 25.4 * dpi + height = paper.height / 25.4 * dpi self.file_name = file_name - self.surface = cairo.SVGSurface(file_name, - paper.width / 25.4 * dpi, - paper.height / 25.4 * dpi) + self.surface = cairo.SVGSurface(file_name, width, height) self.context = cairo.Context(self.surface) self.context.scale(dpi / 25.4, dpi / 25.4) self.context.set_line_cap(cairo.LINE_CAP_ROUND) self.context.set_line_join(cairo.LINE_JOIN_ROUND) + if paper.background_colour is not None: + self.context.set_source_rgba(*paper.background_colour) + self.context.rectangle(0, 0, width, height) + self.context.fill() + super().__init__(paper, line_width, colour) def move_to(self, point):