comparison musiccutter.py @ 17:c50427f1da2d

- Draw vertical time lines. - Draw box around the page. - Refactor text drawing code.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 20 Apr 2016 08:35:44 +0930
parents 20337b22977d
children cf93a76eda92
comparison
equal deleted inserted replaced
16:20337b22977d 17:c50427f1da2d
87 print ev 87 print ev
88 88
89 print 'Playable count:', playablecount 89 print 'Playable count:', playablecount
90 print 'Unplayable count:', unplayablecount 90 print 'Unplayable count:', unplayablecount
91 91
92 for i in range(len(pdfs)): 92 for pindx in range(len(pdfs)):
93 pdf = pdfs[i] 93 pdf = pdfs[pindx]
94 # Add title and page number 94 # Add title and page number
95 tobj = pdf.beginText() 95 Midi2PDF.textHelper(pdf, 25 * mm, 1 * mm, ENGRAVE_COLOUR, True, self.fontname, self.fontsize, '%s (%d / %d)' % (title, pindx + 1, npages))
96 tobj.setTextOrigin(50 * mm, 1 * mm)
97 tobj.setFont(self.fontname, self.fontsize)
98 tobj.setFillColor(ENGRAVE_COLOUR)
99 tobj.setStrokeColor(ENGRAVE_COLOUR)
100 tobj.textLine('%s (%d / %d)' % (title, i + 1, npages))
101 pdf.drawText(tobj)
102 96
103 # Draw rect around page 97 pdf.saveState() # Not really necessary since this is last thing we do
104 pdf.saveState()
105 pdf.setLineWidth(0) 98 pdf.setLineWidth(0)
106 #pdf.rect(0, 0, self.pagewidth * mm, self.pageheight * mm, fill = False, stroke = True) 99
107 # Draw lines per note 100 # Draw lines per note
108 for slot in sorted(self.slot2note.keys()): 101 for slot in sorted(self.slot2note.keys()):
109 ofs = (self.offset + slot * self.pitch) * mm 102 ofs = (self.offset + slot * self.pitch) * mm
110 pdf.line(0, ofs, self.pagewidth * mm, ofs) 103 pdf.line(0, ofs, self.pagewidth * mm, ofs)
111 # Note name 104 # Note name
112 tobj = pdf.beginText() 105 Midi2PDF.textHelper(pdf, 0 * mm, ofs + 1 * mm, ENGRAVE_COLOUR, False, self.fontname, self.fontsize, self.slot2note[slot])
113 tobj.setTextRenderMode(1)
114 tobj.setTextOrigin(0 * mm, ofs + 1 * mm)
115 tobj.setFont(self.fontname, self.fontsize)
116 tobj.setFillColor(ENGRAVE_COLOUR)
117 tobj.setStrokeColor(ENGRAVE_COLOUR)
118 tobj.textLine('%s' % (self.slot2note[slot]))
119 pdf.drawText(tobj)
120 pdf.restoreState() 106 pdf.restoreState()
121 pdf.save() 107 pdf.save()
122 108
123 # http://newt.phys.unsw.edu.au/jw/notes.html 109 # http://newt.phys.unsw.edu.au/jw/notes.html
124 @staticmethod 110 @staticmethod
181 pdf.setStrokeColor(CUT_COLOUR) 167 pdf.setStrokeColor(CUT_COLOUR)
182 pdf.setLineWidth(0) 168 pdf.setLineWidth(0)
183 pdf.rect(x * mm, y * mm, w * mm, h * mm, fill = False, stroke = True) 169 pdf.rect(x * mm, y * mm, w * mm, h * mm, fill = False, stroke = True)
184 pdf.restoreState() 170 pdf.restoreState()
185 171
172 @staticmethod
173 def textHelper(pdf, x, y, colour, fill, fontname, fontsize, text):
174 tobj = pdf.beginText()
175 tobj.setTextOrigin(x, y)
176 tobj.setFont(fontname, fontsize)
177 tobj.setStrokeColor(colour)
178 tobj.setFillColor(colour)
179 if fill:
180 tobj.setTextRenderMode(0)
181 else:
182 tobj.setTextRenderMode(1)
183 tobj.textLine(text)
184 pdf.drawText(tobj)
185
186 if __name__ == '__main__': 186 if __name__ == '__main__':
187 main() 187 main()