diff --git a/FusionIIIT/applications/academic_procedures/api/bonafide_certificate.py b/FusionIIIT/applications/academic_procedures/api/bonafide_certificate.py index 877a582a0..cdd1bbb72 100644 --- a/FusionIIIT/applications/academic_procedures/api/bonafide_certificate.py +++ b/FusionIIIT/applications/academic_procedures/api/bonafide_certificate.py @@ -1,4 +1,5 @@ import math +import os import re from datetime import datetime from io import BytesIO @@ -11,10 +12,12 @@ from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.utils import timezone -from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY, TA_LEFT, TA_RIGHT +from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY, TA_RIGHT from reportlab.lib.pagesizes import A4 from reportlab.lib.styles import ParagraphStyle from reportlab.lib.units import cm +from reportlab.pdfbase import pdfmetrics +from reportlab.pdfbase.ttfonts import TTFont from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Table, TableStyle from rest_framework import status from rest_framework.authentication import TokenAuthentication @@ -27,6 +30,28 @@ from applications.globals.decorators import role_required from applications.globals.programme_scope import programme_display_name +FONT_DIR = os.path.join(os.path.dirname(__file__), '..', 'fonts') + + +def register_certificate_fonts(): + """Caladea/Carlito stand in for Cambria/Calibri -- metric-compatible and + freely redistributable, unlike the Microsoft originals.""" + if 'Caladea' in pdfmetrics.getRegisteredFontNames(): + return + pdfmetrics.registerFont(TTFont('Caladea', os.path.join(FONT_DIR, 'Caladea-Regular.ttf'))) + pdfmetrics.registerFont(TTFont('Caladea-Bold', os.path.join(FONT_DIR, 'Caladea-Bold.ttf'))) + pdfmetrics.registerFont(TTFont('Carlito', os.path.join(FONT_DIR, 'Carlito-Regular.ttf'))) + pdfmetrics.registerFont(TTFont('Carlito-Bold', os.path.join(FONT_DIR, 'Carlito-Bold.ttf'))) + pdfmetrics.registerFontFamily( + 'Caladea', normal='Caladea', bold='Caladea-Bold', + italic='Caladea', boldItalic='Caladea-Bold') + pdfmetrics.registerFontFamily( + 'Carlito', normal='Carlito', bold='Carlito-Bold', + italic='Carlito', boldItalic='Carlito-Bold') + + +register_certificate_fonts() + #: Both certificates share the table; each screen lists only its own kind. CERTIFICATE_TYPE = 'bonafide' @@ -164,35 +189,35 @@ def render_bonafide_pdf( document = SimpleDocTemplate( output, pagesize=A4, - topMargin=2.5 * cm, + topMargin=3.5 * cm, rightMargin=1.5 * cm, - bottomMargin=2.5 * cm, + bottomMargin=2 * cm, leftMargin=1.5 * cm, title='Bonafide Certificate', author=settings.BONAFIDE_INSTITUTE_NAME, ) header_style = ParagraphStyle( - 'Header', fontName='Helvetica-Bold', fontSize=13.5, - leading=18, alignment=TA_LEFT, + 'Header', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_JUSTIFY, ) header_right_style = ParagraphStyle( 'HeaderRight', parent=header_style, alignment=TA_RIGHT, ) heading_style = ParagraphStyle( - 'Heading', fontName='Helvetica-Bold', fontSize=15, - leading=19, alignment=TA_CENTER, + 'Heading', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_CENTER, ) body_style = ParagraphStyle( - 'Body', fontName='Helvetica', fontSize=13.5, - leading=22, alignment=TA_JUSTIFY, + 'Body', fontName='Caladea', fontSize=12, + leading=20, alignment=TA_JUSTIFY, ) signature_style = ParagraphStyle( - 'Signature', fontName='Helvetica-Bold', fontSize=13.5, - leading=18, alignment=TA_LEFT, + 'Signature', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_JUSTIFY, ) note_style = ParagraphStyle( - 'Note', fontName='Helvetica', fontSize=13.5, - leading=22, alignment=TA_JUSTIFY, + 'Note', fontName='Carlito', fontSize=11, + leading=18, alignment=TA_JUSTIFY, ) header = Table( diff --git a/FusionIIIT/applications/academic_procedures/api/demand_letter.py b/FusionIIIT/applications/academic_procedures/api/demand_letter.py index 6bf4361d8..4809e3040 100644 --- a/FusionIIIT/applications/academic_procedures/api/demand_letter.py +++ b/FusionIIIT/applications/academic_procedures/api/demand_letter.py @@ -11,7 +11,7 @@ from django.shortcuts import get_object_or_404 from django.utils import timezone from reportlab.lib import colors -from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY, TA_LEFT, TA_RIGHT +from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY, TA_RIGHT from reportlab.lib.pagesizes import A4 from reportlab.lib.styles import ParagraphStyle from reportlab.lib.units import cm @@ -109,37 +109,37 @@ def render_demand_letter_pdf(context, semester, academic_year_label, due_date, document = SimpleDocTemplate( output, pagesize=A4, - topMargin=2.5 * cm, + topMargin=3.5 * cm, rightMargin=1.5 * cm, - bottomMargin=2.5 * cm, + bottomMargin=2 * cm, leftMargin=1.5 * cm, title='Demand Letter', author=settings.BONAFIDE_INSTITUTE_NAME, ) header_style = ParagraphStyle( - 'Header', fontName='Helvetica-Bold', fontSize=12, - leading=16, alignment=TA_LEFT, + 'Header', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_JUSTIFY, ) header_right_style = ParagraphStyle( 'HeaderRight', parent=header_style, alignment=TA_RIGHT, ) heading_style = ParagraphStyle( - 'Heading', fontName='Helvetica-Bold', fontSize=13.5, - leading=17, alignment=TA_CENTER, + 'Heading', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_CENTER, ) body_style = ParagraphStyle( - 'Body', fontName='Helvetica', fontSize=12, - leading=18, alignment=TA_JUSTIFY, + 'Body', fontName='Caladea', fontSize=12, + leading=17, alignment=TA_JUSTIFY, ) sub_heading_style = ParagraphStyle( - 'SubHeading', fontName='Helvetica-Bold', fontSize=12, - leading=16, alignment=TA_CENTER, + 'SubHeading', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_CENTER, ) cell_style = ParagraphStyle( - 'Cell', fontName='Helvetica', fontSize=11, leading=14, alignment=TA_LEFT, + 'Cell', fontName='Caladea', fontSize=11, leading=14, alignment=TA_JUSTIFY, ) cell_bold_style = ParagraphStyle( - 'CellBold', parent=cell_style, fontName='Helvetica-Bold', + 'CellBold', parent=cell_style, fontName='Caladea-Bold', ) cell_center_style = ParagraphStyle( 'CellCenter', parent=cell_style, alignment=TA_CENTER, @@ -148,14 +148,16 @@ def render_demand_letter_pdf(context, semester, academic_year_label, due_date, 'CellBoldRight', parent=cell_bold_style, alignment=TA_RIGHT, ) bank_label_style = ParagraphStyle( - 'BankLabel', fontName='Helvetica-Bold', fontSize=11, leading=14, + 'BankLabel', fontName='Caladea-Bold', fontSize=11, leading=14, + alignment=TA_JUSTIFY, ) bank_value_style = ParagraphStyle( - 'BankValue', fontName='Helvetica', fontSize=11, leading=14, + 'BankValue', fontName='Caladea', fontSize=11, leading=14, + alignment=TA_JUSTIFY, ) signature_style = ParagraphStyle( - 'Signature', fontName='Helvetica-Bold', fontSize=12, - leading=16, alignment=TA_LEFT, + 'Signature', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_JUSTIFY, ) header = Table( diff --git a/FusionIIIT/applications/academic_procedures/api/fee_certificate.py b/FusionIIIT/applications/academic_procedures/api/fee_certificate.py index 76adeae68..2208a45f7 100644 --- a/FusionIIIT/applications/academic_procedures/api/fee_certificate.py +++ b/FusionIIIT/applications/academic_procedures/api/fee_certificate.py @@ -17,7 +17,7 @@ from django.shortcuts import get_object_or_404 from django.utils import timezone from reportlab.lib import colors -from reportlab.lib.enums import TA_CENTER, TA_LEFT, TA_RIGHT +from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY, TA_RIGHT from reportlab.lib.pagesizes import A4 from reportlab.lib.styles import ParagraphStyle from reportlab.lib.units import cm @@ -149,44 +149,44 @@ def render_fee_pdf(context, purpose, reference_number, issued_on, rows, document = SimpleDocTemplate( output, pagesize=A4, - topMargin=2.5 * cm, + topMargin=3.5 * cm, rightMargin=1.5 * cm, - bottomMargin=2.5 * cm, + bottomMargin=2 * cm, leftMargin=1.5 * cm, title='Fee Certificate', author=settings.BONAFIDE_INSTITUTE_NAME, ) header_style = ParagraphStyle( - 'Header', fontName='Helvetica-Bold', fontSize=13.5, - leading=18, alignment=TA_LEFT, + 'Header', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_JUSTIFY, ) header_right_style = ParagraphStyle( 'HeaderRight', parent=header_style, alignment=TA_RIGHT, ) heading_style = ParagraphStyle( - 'Heading', fontName='Helvetica-Bold', fontSize=15, - leading=19, alignment=TA_CENTER, + 'Heading', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_CENTER, ) body_style = ParagraphStyle( - 'Body', fontName='Helvetica', fontSize=13.5, - leading=19, alignment=TA_LEFT, + 'Body', fontName='Caladea', fontSize=12, + leading=17, alignment=TA_JUSTIFY, ) bullet_style = ParagraphStyle( - 'Bullet', parent=body_style, fontName='Helvetica-Bold', - leftIndent=0.6 * cm, bulletIndent=0.1 * cm, + 'Bullet', parent=body_style, fontName='Caladea-Bold', fontSize=11, + leading=15, leftIndent=0.6 * cm, bulletIndent=0.1 * cm, ) note_style = ParagraphStyle( - 'Note', parent=body_style, fontName='Helvetica', - leftIndent=0.6 * cm, bulletIndent=0.1 * cm, leading=18, + 'Note', parent=body_style, fontName='Carlito', fontSize=11, + leftIndent=0.6 * cm, bulletIndent=0.1 * cm, leading=15, ) cell_style = ParagraphStyle( # Room for the raised ordinal suffix, which overflows a tighter line. - 'Cell', fontName='Helvetica', fontSize=12.5, leading=16, - alignment=TA_LEFT, + 'Cell', fontName='Caladea', fontSize=11, leading=15, + alignment=TA_JUSTIFY, ) signature_style = ParagraphStyle( - 'Signature', fontName='Helvetica-Bold', fontSize=13.5, - leading=18, alignment=TA_LEFT, + 'Signature', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_JUSTIFY, ) header = Table( diff --git a/FusionIIIT/applications/academic_procedures/api/fee_structure_certificate.py b/FusionIIIT/applications/academic_procedures/api/fee_structure_certificate.py index 08e5960e0..13f4ad360 100644 --- a/FusionIIIT/applications/academic_procedures/api/fee_structure_certificate.py +++ b/FusionIIIT/applications/academic_procedures/api/fee_structure_certificate.py @@ -10,7 +10,7 @@ from django.shortcuts import get_object_or_404 from django.utils import timezone from reportlab.lib import colors -from reportlab.lib.enums import TA_CENTER, TA_LEFT +from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY from reportlab.lib.pagesizes import A4 from reportlab.lib.styles import ParagraphStyle from reportlab.lib.units import cm @@ -38,6 +38,15 @@ ONE_TIME_LABEL = 'One-time payment is paid only once at the time of admission' +ROMAN_NUMERALS = { + 1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V', 6: 'VI', + 7: 'VII', 8: 'VIII', 9: 'IX', 10: 'X', 11: 'XI', 12: 'XII', +} + + +def semester_roman(semester): + return ROMAN_NUMERALS.get(semester, str(semester)) + def session_semesters(semester): odd = semester if semester % 2 else semester - 1 @@ -102,40 +111,44 @@ def render_fee_structure_pdf(context, structure, odd_semester, academic_year_lab document = SimpleDocTemplate( output, pagesize=A4, - topMargin=2.5 * cm, + topMargin=3.5 * cm, rightMargin=1.5 * cm, - bottomMargin=2.5 * cm, + bottomMargin=2 * cm, leftMargin=1.5 * cm, title='Fee Structure Certificate', author=settings.BONAFIDE_INSTITUTE_NAME, ) header_style = ParagraphStyle( - 'Header', fontName='Helvetica-Bold', fontSize=12, leading=16, + 'Header', fontName='Caladea-Bold', fontSize=11, leading=15, + alignment=TA_JUSTIFY, ) header_right_style = ParagraphStyle( 'HeaderRight', parent=header_style, alignment=2, ) label_style = ParagraphStyle( - 'Label', fontName='Helvetica-Bold', fontSize=12, leading=18, + 'Label', fontName='Caladea-Bold', fontSize=11, leading=15, + alignment=TA_JUSTIFY, ) value_style = ParagraphStyle( - 'Value', fontName='Helvetica', fontSize=12, leading=18, + 'Value', fontName='Caladea', fontSize=11, leading=15, + alignment=TA_JUSTIFY, ) note_style = ParagraphStyle( - 'Note', fontName='Helvetica-Bold', fontSize=12, leading=16, + 'Note', fontName='Caladea-Bold', fontSize=11, leading=15, + alignment=TA_JUSTIFY, ) cell_style = ParagraphStyle( - 'Cell', fontName='Helvetica', fontSize=12, leading=15, alignment=TA_LEFT, + 'Cell', fontName='Caladea', fontSize=11, leading=15, alignment=TA_JUSTIFY, ) cell_center_style = ParagraphStyle( 'CellCenter', parent=cell_style, alignment=TA_CENTER, ) cell_bold_style = ParagraphStyle( - 'CellBold', parent=cell_style, fontName='Helvetica-Bold', + 'CellBold', parent=cell_style, fontName='Caladea-Bold', ) signature_style = ParagraphStyle( - 'Signature', fontName='Helvetica-Bold', fontSize=12, - leading=16, alignment=TA_LEFT, + 'Signature', fontName='Caladea-Bold', fontSize=11, + leading=15, alignment=TA_JUSTIFY, ) header = Table( @@ -210,8 +223,8 @@ def value_cell(text): [[ Paragraph('S.No.', cell_bold_style), Paragraph('Fee Head(s)', cell_bold_style), - Paragraph('Semester-I', cell_bold_style), - Paragraph('Semester-II', cell_bold_style), + Paragraph(f'Semester-{semester_roman(odd_semester)}', cell_bold_style), + Paragraph(f'Semester-{semester_roman(odd_semester + 1)}', cell_bold_style), Paragraph('Total', cell_bold_style), ]] + table_rows, colWidths=[1.8 * cm, 6.2 * cm, 2.7 * cm, 3.3 * cm, 3 * cm], hAlign='LEFT', diff --git a/FusionIIIT/applications/academic_procedures/fonts/Caladea-Bold.ttf b/FusionIIIT/applications/academic_procedures/fonts/Caladea-Bold.ttf new file mode 100644 index 000000000..a4a9703fb Binary files /dev/null and b/FusionIIIT/applications/academic_procedures/fonts/Caladea-Bold.ttf differ diff --git a/FusionIIIT/applications/academic_procedures/fonts/Caladea-Regular.ttf b/FusionIIIT/applications/academic_procedures/fonts/Caladea-Regular.ttf new file mode 100644 index 000000000..a490e8f0e Binary files /dev/null and b/FusionIIIT/applications/academic_procedures/fonts/Caladea-Regular.ttf differ diff --git a/FusionIIIT/applications/academic_procedures/fonts/Carlito-Bold.ttf b/FusionIIIT/applications/academic_procedures/fonts/Carlito-Bold.ttf new file mode 100644 index 000000000..67543b5a1 Binary files /dev/null and b/FusionIIIT/applications/academic_procedures/fonts/Carlito-Bold.ttf differ diff --git a/FusionIIIT/applications/academic_procedures/fonts/Carlito-Regular.ttf b/FusionIIIT/applications/academic_procedures/fonts/Carlito-Regular.ttf new file mode 100644 index 000000000..427b95989 Binary files /dev/null and b/FusionIIIT/applications/academic_procedures/fonts/Carlito-Regular.ttf differ diff --git a/FusionIIIT/applications/academic_procedures/fonts/README.md b/FusionIIIT/applications/academic_procedures/fonts/README.md new file mode 100644 index 000000000..d553bb98b --- /dev/null +++ b/FusionIIIT/applications/academic_procedures/fonts/README.md @@ -0,0 +1,5 @@ +Caladea and Carlito are metric-compatible, SIL Open Font License substitutes +for Cambria and Calibri respectively, sourced from Google Fonts +(https://fonts.google.com/specimen/Caladea, https://fonts.google.com/specimen/Carlito). +Cambria and Calibri themselves are proprietary Microsoft fonts and are not +redistributed here.