# HG changeset patch # User Daniel O'Connor # Date 1461107144 -34200 # Node ID c50427f1da2d6b1670235e4a4170349cde346dac # Parent 20337b22977dadc37fdc0b38e6a633b91485327f - Draw vertical time lines. - Draw box around the page. - Refactor text drawing code. diff -r 20337b22977d -r c50427f1da2d musiccutter.py --- a/musiccutter.py Thu Apr 14 09:48:08 2016 +0930 +++ b/musiccutter.py Wed Apr 20 08:35:44 2016 +0930 @@ -89,34 +89,20 @@ print 'Playable count:', playablecount print 'Unplayable count:', unplayablecount - for i in range(len(pdfs)): - pdf = pdfs[i] + for pindx in range(len(pdfs)): + pdf = pdfs[pindx] # Add title and page number - tobj = pdf.beginText() - tobj.setTextOrigin(50 * mm, 1 * mm) - tobj.setFont(self.fontname, self.fontsize) - tobj.setFillColor(ENGRAVE_COLOUR) - tobj.setStrokeColor(ENGRAVE_COLOUR) - tobj.textLine('%s (%d / %d)' % (title, i + 1, npages)) - pdf.drawText(tobj) + Midi2PDF.textHelper(pdf, 25 * mm, 1 * mm, ENGRAVE_COLOUR, True, self.fontname, self.fontsize, '%s (%d / %d)' % (title, pindx + 1, npages)) - # Draw rect around page - pdf.saveState() + pdf.saveState() # Not really necessary since this is last thing we do pdf.setLineWidth(0) - #pdf.rect(0, 0, self.pagewidth * mm, self.pageheight * mm, fill = False, stroke = True) + # Draw lines per note for slot in sorted(self.slot2note.keys()): ofs = (self.offset + slot * self.pitch) * mm pdf.line(0, ofs, self.pagewidth * mm, ofs) # Note name - tobj = pdf.beginText() - tobj.setTextRenderMode(1) - tobj.setTextOrigin(0 * mm, ofs + 1 * mm) - tobj.setFont(self.fontname, self.fontsize) - tobj.setFillColor(ENGRAVE_COLOUR) - tobj.setStrokeColor(ENGRAVE_COLOUR) - tobj.textLine('%s' % (self.slot2note[slot])) - pdf.drawText(tobj) + Midi2PDF.textHelper(pdf, 0 * mm, ofs + 1 * mm, ENGRAVE_COLOUR, False, self.fontname, self.fontsize, self.slot2note[slot]) pdf.restoreState() pdf.save() @@ -183,5 +169,19 @@ pdf.rect(x * mm, y * mm, w * mm, h * mm, fill = False, stroke = True) pdf.restoreState() + @staticmethod + def textHelper(pdf, x, y, colour, fill, fontname, fontsize, text): + tobj = pdf.beginText() + tobj.setTextOrigin(x, y) + tobj.setFont(fontname, fontsize) + tobj.setStrokeColor(colour) + tobj.setFillColor(colour) + if fill: + tobj.setTextRenderMode(0) + else: + tobj.setTextRenderMode(1) + tobj.textLine(text) + pdf.drawText(tobj) + if __name__ == '__main__': main()