+ text = bidi.get_display(text, base_dir='L')
+ groups = []
+ for c in text:
+ font = self.get_font_for_char(c)
+ if groups and font is groups[-1][0]:
+ groups[-1][1] += c
+ else:
+ groups.append([font, c])
+
+ return sum(
+ font.getlength(t)
+ for (font, t) in groups
+ ) + self.tracking * len(text)
+
+ def text_with_tracking(self, draw, pos, text, fill=None):
+ x, y = pos
+ for c in bidi.get_display(text, base_dir='L'):
+ cfont = self.get_font_for_char(c)
+ width = cfont.getlength(c)
+ draw.text((x, y), c, fill=fill, font=cfont)
+ x += width + self.tracking
+