Repository: uccser/cs-unplugged

Issue:
Modify Job Badges printable to use one string per badge
Currently the way the strings are broken for translation doesn't support all languages (for example: Māori has a word after the emphasis of the role).


Discussion:

Resolving patch:
diff --git a/csunplugged/resources/generators/JobBadgesResourceGenerator.py b/csunplugged/resources/generators/JobBadgesResourceGenerator.py
--- a/csunplugged/resources/generators/JobBadgesResourceGenerator.py
+++ b/csunplugged/resources/generators/JobBadgesResourceGenerator.py
@@ -1,9 +1,20 @@
 """Class for Job Badges resource generator."""
 
 from PIL import Image, ImageDraw
-from resources.utils.BaseResourceGenerator import BaseResourceGenerator
+from utils.TextBoxDrawer import TextBox, TextBoxDrawer
 from django.utils.translation import ugettext_lazy as _
-from utils.TextBoxDrawer import TextBoxDrawer
+from resources.utils.BaseResourceGenerator import BaseResourceGenerator
+from resources.utils.coords import calculate_box_vertices
+
+FONT_PATH = "static/fonts/PatrickHand-Regular.ttf"
+FONT_SIZE = 200
+TEXTBOX_WIDTH = 1000
+TEXTBOX_HEIGHT = 275
+LABEL_DATA = {
+    "programmer": _("Hello, I'm a Programmer"),
+    "tester": _("Hello, I'm a Tester"),
+    "bot": _("Hello, I'm a Bot"),
+}
 
 
 class JobBadgesResourceGenerator(BaseResourceGenerator):
@@ -15,45 +26,38 @@ def data(self):
         Returns:
             A dictionary of the one page for the resource.
         """
-        path = "static/img/resources/job-badges/job-badges"
-        image_path = "{}.png".format(path)
-        svg_path = "{}.svg".format(path)
+        image_path = "static/img/resources/job-badges/job-badges.png"
         image = Image.open(image_path)
-
         draw = ImageDraw.Draw(image)
-        textbox_drawer = TextBoxDrawer(image, draw, svg_path)
-
-        hello_ids = [
-            "programmer_hello1",
-            "programmer_hello2",
-            "tester_hello1",
-            "tester_hello2",
-            "bot_hello1",
-            "bot_hello2",
-        ]
-
-        for hello_id in hello_ids:
-            textbox_drawer.write_text_box(
-                hello_id,
-                _("Hello, I'm a"),
-                horiz_just="center"
-            )
-
-        for i in range(1, 3):
-            textbox_drawer.write_text_box(
-                "programmer{}".format(i),
-                _("Programmer"),
-                horiz_just="center"
-            )
-            textbox_drawer.write_text_box(
-                "tester{}".format(i),
-                _("Tester"),
-                horiz_just="center"
-            )
-            textbox_drawer.write_text_box(
-                "bot{}".format(i),
-                _("Bot"),
-                horiz_just="center"
-            )
+        textbox_drawer = TextBoxDrawer(image, draw)
+
+        # coordinates of top left point of text box
+        top_left_x_coords = [50, 1200]
+        top_left_y_coord = 100
+
+        # Add text labels
+        for label, label_text in LABEL_DATA.items():
+            for top_left_x_coord in top_left_x_coords:
+                vertices = calculate_box_vertices(
+                    (top_left_x_coord, top_left_y_coord),
+                    TEXTBOX_WIDTH,
+                    TEXTBOX_HEIGHT
+                )
+                box = TextBox(
+                    vertices=vertices,
+                    width=TEXTBOX_WIDTH,
+                    height=TEXTBOX_HEIGHT,
+                    font_path=FONT_PATH,
+                    font_size=FONT_SIZE,
+                )
+                textbox_drawer.write_text_box(
+                    box,
+                    label_text,
+                    horiz_just="center",
+                    vert_just="center",
+                )
+
+            # increase y coord for next name tag down
+            top_left_y_coord += 675
 
         return {"type": "image", "data": image}


Test patch: