Améliore gestion font pdf manquant

This commit is contained in:
Emmanuel Viennet 2022-11-20 23:03:26 +01:00 committed by iziram
parent 9d64caa749
commit 5018298d12
4 changed files with 20 additions and 21 deletions

View File

@ -184,7 +184,7 @@ def process_field(field, cdict, style, suppress_empty_pars=False, format="pdf"):
# secure_filename dans la classe Logo # secure_filename dans la classe Logo
# log('field: %s' % (text)) # log('field: %s' % (text))
return sco_pdf.makeParas(text, style, suppress_empty=suppress_empty_pars) return sco_pdf.make_paras(text, style, suppress_empty=suppress_empty_pars)
def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"): def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):

View File

@ -49,11 +49,10 @@ Balises img: actuellement interdites.
from reportlab.platypus import KeepTogether, Paragraph, Spacer, Table from reportlab.platypus import KeepTogether, Paragraph, Spacer, Table
from reportlab.lib.units import cm, mm from reportlab.lib.units import cm, mm
from reportlab.lib.colors import Color, blue from reportlab.lib.colors import Color, blue
from app.models import FormSemestre
from app.scodoc.sco_exceptions import ScoBugCatcher
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
from app.scodoc.sco_pdf import SU from app.scodoc.sco_pdf import SU, make_paras
from app.scodoc import sco_preferences from app.scodoc import sco_preferences
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
from app.scodoc.sco_codes_parcours import ( from app.scodoc.sco_codes_parcours import (
@ -143,7 +142,7 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator):
) )
else: else:
H.append("""<p class="bul_abs">Pas d'absences signalées.</p>""") H.append("""<p class="bul_abs">Pas d'absences signalées.</p>""")
story.append(Paragraph(SU("Pas d'absences signalées."), self.CellStyle)) story += make_paras("Pas d'absences signalées.", self.CellStyle)
# ---- APPRECIATIONS # ---- APPRECIATIONS
# le dir. des etud peut ajouter des appreciations, # le dir. des etud peut ajouter des appreciations,

View File

@ -117,7 +117,7 @@ def _splitPara(txt):
return L return L
def makeParas(txt, style, suppress_empty=False): def make_paras(txt: str, style, suppress_empty=False) -> list[Paragraph]:
"""Returns a list of Paragraph instances from a text """Returns a list of Paragraph instances from a text
with one or more <para> ... </para> with one or more <para> ... </para>
""" """
@ -158,9 +158,9 @@ def makeParas(txt, style, suppress_empty=False):
style, style,
) )
] ]
except ValueError as exc2: # probleme font ? essaye sans style except ValueError: # probleme font ? essaye sans style
# recupere font en cause ? # récupère font en cause ?
m = re.match(r".*family/bold/italic for (.*)", e.args[0], re.DOTALL) m = re.match(r".*family/bold/italic for (.*)", exc.args[0], re.DOTALL)
if m: if m:
message = f"police non disponible: {m[1]}" message = f"police non disponible: {m[1]}"
else: else:

View File

@ -94,7 +94,7 @@ def page_footer(canvas, doc, logo, preferences, with_page_numbers=True):
right_foot_style.fontSize = preferences["SCOLAR_FONT_SIZE_FOOT"] right_foot_style.fontSize = preferences["SCOLAR_FONT_SIZE_FOOT"]
right_foot_style.alignment = TA_RIGHT right_foot_style.alignment = TA_RIGHT
p = sco_pdf.makeParas( p = sco_pdf.make_paras(
f"""<para>{preferences["INSTITUTION_NAME"]}</para><para>{ f"""<para>{preferences["INSTITUTION_NAME"]}</para><para>{
preferences["INSTITUTION_ADDRESS"]}</para>""", preferences["INSTITUTION_ADDRESS"]}</para>""",
left_foot_style, left_foot_style,
@ -585,7 +585,7 @@ def pdf_lettre_individuelle(sem, decision, etud: Identite, params, signature=Non
or "" or ""
) % params ) % params
sig = _simulate_br(sig, '<para leftindent="%(htab1)s">') sig = _simulate_br(sig, '<para leftindent="%(htab1)s">')
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
( (
"""<para leftindent="%(htab1)s" spaceBefore="25mm">""" """<para leftindent="%(htab1)s" spaceBefore="25mm">"""
+ sig + sig
@ -602,7 +602,7 @@ def pdf_lettre_individuelle(sem, decision, etud: Identite, params, signature=Non
or "" or ""
) % params ) % params
sig = _simulate_br(sig, '<para leftindent="%(htab1)s">') sig = _simulate_br(sig, '<para leftindent="%(htab1)s">')
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
( (
"""<para leftindent="%(htab1)s" spaceBefore="25mm">""" """<para leftindent="%(htab1)s" spaceBefore="25mm">"""
+ sig + sig
@ -779,7 +779,7 @@ def _pvjury_pdf_type(
bulletStyle.spaceAfter = 5 * mm bulletStyle.spaceAfter = 5 * mm
objects += [Spacer(0, 5 * mm)] objects += [Spacer(0, 5 * mm)]
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
""" """
<para align="center"><b>Procès-verbal de %s du département %s - Session unique %s</b></para> <para align="center"><b>Procès-verbal de %s du département %s - Session unique %s</b></para>
""" """
@ -791,7 +791,7 @@ def _pvjury_pdf_type(
style, style,
) )
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
""" """
<para align="center"><b><i>%s</i></b></para> <para align="center"><b><i>%s</i></b></para>
""" """
@ -800,20 +800,20 @@ def _pvjury_pdf_type(
) )
if showTitle: if showTitle:
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
"""<para align="center"><b>Semestre: %s</b></para>""" % sem["titre"], style """<para align="center"><b>Semestre: %s</b></para>""" % sem["titre"], style
) )
if sco_preferences.get_preference("PV_TITLE_WITH_VDI", formsemestre_id): if sco_preferences.get_preference("PV_TITLE_WITH_VDI", formsemestre_id):
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
"""<para align="center">VDI et Code: %s</para>""" % (VDICode or ""), style """<para align="center">VDI et Code: %s</para>""" % (VDICode or ""), style
) )
if date_jury: if date_jury:
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
"""<para align="center">Jury tenu le %s</para>""" % date_jury, style """<para align="center">Jury tenu le %s</para>""" % date_jury, style
) )
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
"<para>" "<para>"
+ (sco_preferences.get_preference("PV_INTRO", formsemestre_id) or "") + (sco_preferences.get_preference("PV_INTRO", formsemestre_id) or "")
% { % {
@ -828,7 +828,7 @@ def _pvjury_pdf_type(
bulletStyle, bulletStyle,
) )
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
"""<para>Le jury propose les décisions suivantes :</para>""", style """<para>Le jury propose les décisions suivantes :</para>""", style
) )
objects += [Spacer(0, 4 * mm)] objects += [Spacer(0, 4 * mm)]
@ -881,7 +881,7 @@ def _pvjury_pdf_type(
objects.append(Table(Pt, repeatRows=1, colWidths=widths, style=table_style)) objects.append(Table(Pt, repeatRows=1, colWidths=widths, style=table_style))
# Signature du directeur # Signature du directeur
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
"""<para spaceBefore="10mm" align="right"> """<para spaceBefore="10mm" align="right">
%s, %s</para>""" %s, %s</para>"""
% ( % (
@ -894,7 +894,7 @@ def _pvjury_pdf_type(
# Légende des codes # Légende des codes
codes = list(sco_codes_parcours.CODES_EXPL.keys()) codes = list(sco_codes_parcours.CODES_EXPL.keys())
codes.sort() codes.sort()
objects += sco_pdf.makeParas( objects += sco_pdf.make_paras(
"""<para spaceBefore="15mm" fontSize="14"> """<para spaceBefore="15mm" fontSize="14">
<b>Codes utilisés :</b></para>""", <b>Codes utilisés :</b></para>""",
style, style,