def draw(self, context): context.save() context.set_antialias(cairo.ANTIALIAS_NONE) shadow = 5.0 / context.get_matrix()[0] context.set_line_width(1.0 / context.get_matrix()[0]) context.rectangle(self.x, self.y, self.width, self.height) context.set_source_rgb(1.0, 1.0, 1.0) context.fill_preserve() if self.background: surface = cairo.ImageSurface.create_from_png(self.background) width = surface.get_width() height = surface.get_height() context.save() x, y = self.scale(context, width, height) context.set_source_surface(surface, self.x / x, self.y / y) context.paint() context.restore() context.set_source_rgba(1.0, 1.0, 1.0, 0.5) context.paint() context.set_source_rgb(0.0, 0.0, 0.0) dash = list() context.set_dash(dash) context.stroke() Margins.draw(self, context) context.set_source_rgba(0.0, 0.0, 0.0, 0.25) dash = list() context.set_dash(dash) context.set_line_width(shadow) context.move_to(self.x + self.width + shadow / 2.0, self.y + shadow) context.line_to(self.x + self.width + shadow / 2.0, self.y + self.height + shadow / 2.0) context.line_to(self.x + shadow, self.y + self.height + shadow / 2.0) context.stroke() context.restore()
class PrintableData: margins = Margins() def __init__(self, margins: Margins = None): if margins is None: margins = Margins() self.margins = margins def clone(self): raise NotImplementedError def set_from(self, source): self.margins = source.margins.clone()
def __init__(self): Margins.__init__(self) self.background = None
def margins(self) -> Margins: if len(self.boxes) < 4: return Margins() return Margins(self.boxes[0].value(), self.boxes[1].value(), self.boxes[2].value(), self.boxes[3].value())
def __init__(self, margins: Margins = None): if margins is None: margins = Margins() self.margins = margins
def __init__(self, width=10): super().__init__(Margins()) self.width = width