diff --git a/bullet/documents/generators/tearoff.py b/bullet/documents/generators/tearoff.py index 22f4552d..13fb6215 100644 --- a/bullet/documents/generators/tearoff.py +++ b/bullet/documents/generators/tearoff.py @@ -170,13 +170,16 @@ def _place_stamp( start_y = (-210 + self.stamp_width + 2) * mm max_width = (self.statement_height - 10) * mm max_height = (self.stamp_width - 2 - 5) * mm + school_length = max_width if max_width > 75 * mm: start_x += (max_width - 75 * mm) / 2 max_width = 75 * mm + school_length = max_width if not include_qr: start_x += max_height / 2 + school_length -= max_height canvas.setFillGray(0) code = code128.Code128( @@ -243,7 +246,10 @@ def _place_stamp( text = canvas.beginText() text.setTextOrigin(start_x, start_y - max_height - 8) text.setFont("IBMPlexMono-Regular", 6) - text.textOut(tearoff.team.display_name_short) + school_chars = ( + int(school_length / mm * 0.77) - 1 + ) # 0.77 is how many characters fit in a mm of space + text.textOut(tearoff.team.get_shortened_display_name(school_chars)) canvas.drawText(text) canvas.restoreState() diff --git a/bullet/users/models/contestants.py b/bullet/users/models/contestants.py index 4fed5e3c..686dd4ff 100644 --- a/bullet/users/models/contestants.py +++ b/bullet/users/models/contestants.py @@ -118,11 +118,14 @@ def display_name(self): @property def display_name_short(self): + return self.get_shortened_display_name() + + def get_shortened_display_name(self, chars=55): if self.name: - return shorten(self.name, 55) + return shorten(self.name, chars) if self.in_school_symbol: - return f"{shorten(str(self.school), 55)} {self.in_school_symbol}" - return shorten(str(self.school), 55) + return f"{shorten(str(self.school), chars)} {self.in_school_symbol}" + return shorten(str(self.school), chars) @property def contact_phone_pretty(self):