Skip to content

Commit ae63ee7

Browse files
authored
feat: improve school name shortening on tearoffs (#1005)
1 parent 814d5e2 commit ae63ee7

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

bullet/documents/generators/tearoff.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,16 @@ def _place_stamp(
170170
start_y = (-210 + self.stamp_width + 2) * mm
171171
max_width = (self.statement_height - 10) * mm
172172
max_height = (self.stamp_width - 2 - 5) * mm
173+
school_length = max_width
173174

174175
if max_width > 75 * mm:
175176
start_x += (max_width - 75 * mm) / 2
176177
max_width = 75 * mm
178+
school_length = max_width
177179

178180
if not include_qr:
179181
start_x += max_height / 2
182+
school_length -= max_height
180183

181184
canvas.setFillGray(0)
182185
code = code128.Code128(
@@ -243,7 +246,10 @@ def _place_stamp(
243246
text = canvas.beginText()
244247
text.setTextOrigin(start_x, start_y - max_height - 8)
245248
text.setFont("IBMPlexMono-Regular", 6)
246-
text.textOut(tearoff.team.display_name_short)
249+
school_chars = (
250+
int(school_length / mm * 0.77) - 1
251+
) # 0.77 is how many characters fit in a mm of space
252+
text.textOut(tearoff.team.get_shortened_display_name(school_chars))
247253
canvas.drawText(text)
248254

249255
canvas.restoreState()

bullet/users/models/contestants.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ def display_name(self):
118118

119119
@property
120120
def display_name_short(self):
121+
return self.get_shortened_display_name()
122+
123+
def get_shortened_display_name(self, chars=55):
121124
if self.name:
122-
return shorten(self.name, 55)
125+
return shorten(self.name, chars)
123126
if self.in_school_symbol:
124-
return f"{shorten(str(self.school), 55)} {self.in_school_symbol}"
125-
return shorten(str(self.school), 55)
127+
return f"{shorten(str(self.school), chars)} {self.in_school_symbol}"
128+
return shorten(str(self.school), chars)
126129

127130
@property
128131
def contact_phone_pretty(self):

0 commit comments

Comments
 (0)