[FIX] cm_odex_barcode: fix arabic

This commit is contained in:
Samir Ladoui 2025-02-12 14:12:04 +01:00
parent 887fe8e267
commit 52bacf7986
1 changed files with 3 additions and 2 deletions

View File

@ -49,16 +49,17 @@ class Transaction(models.Model):
def draw_text(draw, text, y_position, font):
""" Draw centered Arabic text """
reshaped_text = arabic_reshaper.reshape(text) # Fix Arabic character joining
bidi_text = get_display(reshaped_text) # Fix right-to-left rendering
# Get text size
text_bbox = draw.textbbox((0, 0), reshaped_text, font=font)
text_bbox = draw.textbbox((0, 0), bidi_text, font=font)
text_width = text_bbox[2] - text_bbox[0]
# Calculate x position for centering
x_position = (image_width - text_width) // 2
# Draw text
draw.text((x_position, y_position), reshaped_text, "black", font=font)
draw.text((x_position, y_position), bidi_text, "black", font=font)
# Draw centered Arabic text
draw_text(draw, "رقم المعاملة : " + (self.name or ''), 20, font)