Allow setting paper background colour
This commit is contained in:
parent
59f7311ede
commit
fc374ad5b6
12
lib/plot.py
12
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):
|
||||
|
|
Loading…
Reference in a new issue