33import datetime
44import json
55import logging
6+ import os
7+ from django .conf import settings
68from django .contrib .auth import get_user_model
79from celery import shared_task
810from reportlab .lib .enums import TA_LEFT
911from reportlab .lib .pagesizes import A4
1012from reportlab .lib .styles import getSampleStyleSheet , ParagraphStyle
1113from reportlab .platypus import Paragraph , Spacer , SimpleDocTemplate
14+ from reportlab .pdfbase import pdfmetrics
15+ from reportlab .pdfbase .ttfonts import TTFont
1216
1317from bims .scripts .species_keys import (
1418 ACCEPTED_TAXON , TAXON_RANK ,
@@ -284,15 +288,31 @@ def __init__(self, get_data, user=None):
284288 def get_checklist_paragraphs (taxon_group , taxonomies ):
285289 """
286290 Build a list of Paragraph objects for the textual "checklist" portion,
287- using Times-style fonts.
291+ using CormorantGaramond Serif fonts.
288292 """
293+ font_dir = os .path .join (settings .STATIC_ROOT , 'fonts' , 'garamond' )
294+ pdfmetrics .registerFont (TTFont ('Garamond' , os .path .join (font_dir , 'EBGaramond-Regular.ttf' )))
295+ pdfmetrics .registerFont (TTFont ('Garamond-Bold' , os .path .join (font_dir , 'EBGaramond-Bold.ttf' )))
296+ pdfmetrics .registerFont (TTFont ('Garamond-Italic' , os .path .join (font_dir , 'EBGaramond-Italic.ttf' )))
297+ pdfmetrics .registerFont (TTFont ('Garamond-BoldItalic' , os .path .join (font_dir , 'EBGaramond-BoldItalic.ttf' )))
298+
299+ # Register font family so <i> and <b> tags work in Paragraphs
300+ from reportlab .pdfbase .pdfmetrics import registerFontFamily
301+ registerFontFamily (
302+ 'Garamond' ,
303+ normal = 'Garamond' ,
304+ bold = 'Garamond-Bold' ,
305+ italic = 'Garamond-Italic' ,
306+ boldItalic = 'Garamond-BoldItalic'
307+ )
308+
289309 # Get the default stylesheet
290310 styles = getSampleStyleSheet ()
291311
292312 title_style = ParagraphStyle (
293313 name = "TitleStyle" ,
294314 parent = styles ['Normal' ],
295- fontName = 'Times -Bold' ,
315+ fontName = 'Garamond -Bold' ,
296316 fontSize = 22 ,
297317 leading = 22 ,
298318 alignment = TA_LEFT ,
@@ -301,7 +321,7 @@ def get_checklist_paragraphs(taxon_group, taxonomies):
301321 generated_style = ParagraphStyle (
302322 name = "GeneratedStyle" ,
303323 parent = styles ['Normal' ],
304- fontName = 'Times -Italic' ,
324+ fontName = 'Garamond -Italic' ,
305325 fontSize = 10 ,
306326 leading = 12 ,
307327 alignment = TA_LEFT ,
@@ -310,26 +330,26 @@ def get_checklist_paragraphs(taxon_group, taxonomies):
310330 genus_style = ParagraphStyle (
311331 name = "GenusStyle" ,
312332 parent = styles ['Normal' ],
313- fontName = 'Times -Bold' ,
333+ fontName = 'Garamond -Bold' ,
314334 fontSize = 12 ,
315335 leading = 14 ,
316336 )
317337
318338 species_style = ParagraphStyle (
319339 name = "SpeciesStyle" ,
320340 parent = styles ['Normal' ],
321- fontName = 'Times-Roman ' ,
341+ fontName = 'Garamond ' ,
322342 fontSize = 11 ,
323343 leading = 14 ,
324344 )
325345
326346 heading_style = ParagraphStyle (
327347 name = "HeadingStyle" , parent = styles ['Normal' ],
328- fontName = 'Times -Bold' , fontSize = 12 , leading = 14 , alignment = TA_LEFT ,
348+ fontName = 'Garamond -Bold' , fontSize = 12 , leading = 14 , alignment = TA_LEFT ,
329349 )
330350 citation_style = ParagraphStyle (
331351 name = "CitationStyle" , parent = styles ['Normal' ],
332- fontName = 'Times-Roman ' , fontSize = 10 , leading = 12 , alignment = TA_LEFT ,
352+ fontName = 'Garamond ' , fontSize = 10 , leading = 12 , alignment = TA_LEFT ,
333353 )
334354
335355 paragraphs = []
0 commit comments