Skip to content

Commit ee219a4

Browse files
committed
feat: allow modifying lerner name size on PDF certificate
1 parent f21293f commit ee219a4

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Unreleased
1616

1717
*
1818

19+
0.2.4 - 2025-09-07
20+
21+
Added
22+
=====
23+
24+
* Option to customize the learner's name size on the PDF certificate.
25+
1926
0.2.3 - 2025-08-18
2027

2128
Modified

learning_credentials/generators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def hex_to_rgb(hex_color: str) -> tuple[float, float, float]:
8989
pdf_canvas = canvas.Canvas(io.BytesIO(), pagesize=(template_width, template_height))
9090

9191
# Write the learner name.
92-
pdf_canvas.setFont(font, 32)
92+
pdf_canvas.setFont(font, options.get('name_size', 32))
9393
name_color = options.get('name_color', '#000')
9494
pdf_canvas.setFillColorRGB(*hex_to_rgb(name_color))
9595

@@ -184,6 +184,7 @@ def generate_pdf_credential(
184184
- font: The name of the font to use.
185185
- name_y: The Y coordinate of the name on the credential (vertical position on the template).
186186
- name_color: The color of the name on the credential (hexadecimal color code).
187+
- name_size: The font size of the name on the credential. The default value is 32.
187188
- context_name: Specify the custom course or Learning Path name.
188189
- context_name_y: The Y coordinate of the context name on the credential (vertical position on the template).
189190
- context_name_color: The color of the context name on the credential (hexadecimal color code).

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "learning-credentials"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
description = "A pluggable service for preparing Open edX credentials."
55
dynamic = ["readme"]
66
requires-python = ">=3.11"

tests/test_generators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def test_register_font_with_custom_font(mock_register_font: Mock, mock_font_clas
7676
'context_name_color': '#9B192A',
7777
'issue_date_color': '#f59a8e',
7878
'context_name_size': 20,
79+
'name_size': 24,
7980
},
8081
{
8182
'name_color': (17 / 255, 34 / 255, 51 / 255),
@@ -131,7 +132,7 @@ def test_write_text_on_template(mock_canvas_class: Mock, context_name: str, opti
131132
assert canvas_object.drawString.call_count == 3 + context_name.count('\n')
132133

133134
# Check the calls to setFont, setFillColorRGB and drawString methods on Canvas object
134-
assert canvas_object.setFont.call_args_list[0] == call(font, 32)
135+
assert canvas_object.setFont.call_args_list[0] == call(font, options.get('name_size', 32))
135136
assert canvas_object.setFillColorRGB.call_args_list[0] == call(*expected_name_color)
136137
assert canvas_object.drawString.call_args_list[0] == call(expected_name_x, expected_name_y, username)
137138
assert mock_canvas_class.return_value.stringWidth.mock_calls[0][1] == (username,)

0 commit comments

Comments
 (0)