diff options
Diffstat (limited to 'ptlayout.py')
-rw-r--r-- | ptlayout.py | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/ptlayout.py b/ptlayout.py index f9518b7..2d0a3ea 100644 --- a/ptlayout.py +++ b/ptlayout.py @@ -58,14 +58,19 @@ class PTLText(PTLayoutElem): w = size[0] matrix = cctx.get_matrix() - if self.mode == 'left': + if self.mode == 'right': cctx.rotate(90. * pi / 180.) cctx.translate((h - size[0]) / 2, -size[1]) w = size[1] - elif self.mode == 'right': + elif self.mode == 'left': cctx.rotate(-90. * pi / 180.) cctx.translate(-h + (h - size[0]) / 2, 0) w = size[1] + elif self.mode == 'down': + cctx.rotate(pi) + cctx.translate(-size[0], -(h + size[1]) / 2) + else: + cctx.translate(0, (h - size[1]) / 2) pctx.update_layout(layout) pctx.show_layout(layout) @@ -78,7 +83,8 @@ class PTLQRCode(PTLayoutElem): super(PTLQRCode, self).__init__() self.qrcontent = '' self.hborder = 4 - self.invert = True + self.vborder = 4 + self.invert = False def properties(self): return [ @@ -92,16 +98,16 @@ class PTLQRCode(PTLayoutElem): return self._render(cctx, False, h) def _render(self, cctx, sizeonly, h): - qr = qrcode.QRCode(border = 0) + qr = qrcode.QRCode(border = 0, error_correction = qrcode.ERROR_CORRECT_L) qr.add_data(self.qrcontent) qr.make(fit = True) qm = qr.get_matrix() qmlen = len(qm) - bpp = h / qmlen - if sizeonly: return (bpp * qmlen + self.hborder * 2, bpp * qmlen) + bpp = (h - self.vborder) / qmlen + if sizeonly: return (bpp * qmlen + self.hborder * 2, bpp * qmlen + self.vborder * 2) if self.invert: - cctx.rectangle(0, 0, bpp * qmlen + self.hborder * 2, h) + cctx.rectangle(0, 0, bpp * qmlen + self.hborder * 2, h + self.vborder * 2) cctx.fill() cctx.set_source_rgba(1.0, 1.0, 1.0, 0.0) @@ -113,7 +119,7 @@ class PTLQRCode(PTLayoutElem): cctx.fill() cctx.set_source_rgba(0.0, 0.0, 0.0, 1.0) - return bpp * qmlen + return bpp * qmlen + self.hborder * 2 class PTLContainer(PTLayoutElem): def __init__(self): @@ -126,13 +132,31 @@ class PTLContainer(PTLayoutElem): def add(self, child): self._children.append(child) +class PTLHSpace(PTLContainer): + def __init__(self): + super(PTLHSpace, self).__init__() + self.spacing = '5' + + def prep_size(self, hh): + return (int(self.spacing), 0) + + def render(self, cctx, h): + return int(self.spacing) + + def properties(self): + return [ + ('spacing', 'text'), + ] + class PTLHSeq(PTLContainer): def __init__(self): super(PTLHSeq, self).__init__() self.spacing = 5 def prep_size(self, hh): - w, h = len(self._children) * self.spacing, 0 + if len(self._children) == 0: + return (0,0) + w, h = (len(self._children) - 1) * self.spacing, 0 for k in self._children: cw, ch = k.prep_size(hh) w += cw @@ -164,7 +188,7 @@ class PTLVStack(PTLContainer): for i, k in enumerate(self._children): vpos = int(h / float(len(self._children)) * i) cctx.translate(0, vpos) - cw = k.render(cctx, h) + cw = k.render(cctx, h / float(len(self._children))) w = max(cw, w) cctx.translate(0, -vpos) return w |