Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import os
import re
from datetime import datetime
from io import BytesIO
Expand All @@ -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
Expand All @@ -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'

Expand Down Expand Up @@ -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(
Expand Down
36 changes: 19 additions & 17 deletions FusionIIIT/applications/academic_procedures/api/demand_letter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down
34 changes: 17 additions & 17 deletions FusionIIIT/applications/academic_procedures/api/fee_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions FusionIIIT/applications/academic_procedures/fonts/README.md
Original file line number Diff line number Diff line change
@@ -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.
Loading