Self hosted FLOSS fitness/workout, nutrition and weight tracker
Use OpenSans as the font on the PDF output
Roland Geiderfccb31561d94
diff --git a/wger/manager/pdf.py b/wger/manager/pdf.pyindex 7637eef67..ee0fb11d3 100644--- a/wger/manager/pdf.py+++ b/wger/manager/pdf.py@@ -24,21 +24,21 @@ from django.contrib.auth.decorators import login_requiredfrom django.utils.translation import ugettext as _from wger.manager.models import TrainingSchedule+from wger.manager.utils import styleSheetfrom reportlab.lib.styles import getSampleStyleSheetfrom reportlab.lib.styles import ParagraphStyle+from reportlab.lib.styles import StyleSheet1from reportlab.lib.pagesizes import A4, cm, landscape, portraitfrom reportlab.platypus import Paragraph, SimpleDocTemplate, Tablefrom reportlab.lib import colors+from reportlab.pdfbase.ttfonts import TTFont+from reportlab.pdfbase import pdfmetricsfrom wger.workout_manager import get_versionlogger = logging.getLogger('workout_manager.custom')-'''-PDF functions-'''-@login_requireddef workout_log(request, id):@@ -72,14 +72,6 @@ def workout_log(request, id):# container for the 'Flowable' objectselements = []- # stylesheet- styleSheet = getSampleStyleSheet()-- style = ParagraphStyle(- name='Normal',- #fontName='Helvetica-Bold',- fontSize=8,)-# table data, here we will put the workout infodata = []@@ -119,10 +111,10 @@ def workout_log(request, id):days_of_week = [_(day_of_week.day_of_week) for day_of_week in day.day.select_related()]- P = Paragraph('<para align="center">%(days)s: <strong>%(description)s</strong></para>' %+ P = Paragraph('<para align="center">%(days)s: %(description)s</para>' %{'days': ', '.join(days_of_week),'description': day.description},- styleSheet["Normal"])+ styleSheet["Bold"])data.append([P])@@ -164,7 +156,8 @@ def workout_log(request, id):elif len(setting_data) > 1:out = ', '.join(setting_data)- data.append([set_count, Paragraph(exercise.name, style), out] + [''] * nr_of_weeks)+ data.append([set_count, Paragraph(exercise.name, styleSheet["Small"]), out]+ + [''] * nr_of_weeks)set_count += 1# Note: as above with _('Date'), the _('Impression') has to be here on@@ -184,7 +177,7 @@ def workout_log(request, id):# Set general table styles#('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),#('BOX', (0,0), (-1,-1), 1.25, colors.black),- table_style = [('FONT', (0, 0), (-1, -1), 'Helvetica'),+ table_style = [('FONT', (0, 0), (-1, -1), 'OpenSans'),('FONTSIZE', (0, 0), (-1, -1), 8),('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),@@ -274,7 +267,7 @@ def workout_log(request, id):if workout.comment:P = Paragraph('<para align="center"><strong>%(description)s</strong></para>' %{'description': workout.comment},- styleSheet["Normal"])+ styleSheet["Bold"])elements.append(P)# Fillerdiff --git a/wger/manager/utils.py b/wger/manager/utils.pyindex e7f6a4be3..2e0b74e49 100644--- a/wger/manager/utils.py+++ b/wger/manager/utils.py@@ -12,9 +12,17 @@## You should have received a copy of the GNU Affero General Public License+from os.path import join as path_join++from django.conf import settingsfrom django.utils import translationfrom django.core.exceptions import ObjectDoesNotExist+from reportlab.lib.styles import ParagraphStyle+from reportlab.lib.styles import StyleSheet1+from reportlab.pdfbase.ttfonts import TTFont+from reportlab.pdfbase import pdfmetrics+from wger.exercises.models import Language# ************************@@ -66,3 +74,30 @@ def load_ingredient_languages(request):languages = (language.id, 2)return languages+++# register new truetype fonts for reportlab+pdfmetrics.registerFont(TTFont(+ 'OpenSans', path_join(settings.SITE_ROOT, 'manager/static/fonts/OpenSans-Light.ttf')))+pdfmetrics.registerFont(TTFont(+ 'OpenSans-Bold', path_join(settings.SITE_ROOT, 'manager/static/fonts/OpenSans-Bold.ttf')))+pdfmetrics.registerFont(TTFont(+ 'OpenSans-Regular', path_join(settings.SITE_ROOT, 'manager/static/fonts/OpenSans-Regular.ttf')))++styleSheet = StyleSheet1()+styleSheet.add(ParagraphStyle(+ name='Normal',+ fontName='OpenSans',+ fontSize=10,+ leading=12,+ ))+styleSheet.add(ParagraphStyle(+ parent=styleSheet['Normal'],+ fontSize=8,+ name='Small',+ ))+styleSheet.add(ParagraphStyle(+ parent=styleSheet['Normal'],+ name='Bold',+ fontName='OpenSans-Bold',+ ))diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.pyindex 0b9cebc87..b783595fc 100644--- a/wger/nutrition/views/plan.py+++ b/wger/nutrition/views/plan.py@@ -14,6 +14,7 @@## You should have received a copy of the GNU Affero General Public Licenseimport logging+import datetimefrom django.template import RequestContextfrom django.shortcuts import render_to_response@@ -40,6 +41,7 @@ from reportlab.lib.pagesizes import A4, cmfrom reportlab.platypus import Paragraph, SimpleDocTemplate, Tablefrom reportlab.lib import colors+from wger.manager.utils import styleSheetfrom wger.manager.utils import load_languagefrom wger.workout_manager import get_version@@ -206,7 +208,6 @@ def export_pdf(request, id):# container for the 'Flowable' objectselements = []- styleSheet = getSampleStyleSheet()data = []# Iterate through the Plan@@ -284,14 +285,20 @@ def export_pdf(request, id):elements.append(P)# Print date and info- P = Paragraph('<para align="left">%(date)s - %(created)s v%(version)s</para>' %- {'date': _("Created on the <b>%s</b>") %- plan.creation_date.strftime("%d.%m.%Y"),- 'created': "Workout Manager",- 'version': get_version()},+ created = datetime.date.today().strftime("%d.%m.%Y")+ url = reverse('wger.nutrition.views.plan.view', kwargs={'id': plan.id})+ P = Paragraph('''<para align="left">+ %(date)s -+ <a href="%(url)s">%(url)s</a> -+ %(created)s+ %(version)s+ </para>''' %+ {'date': _("Created on the <b>%s</b>") % created,+ 'created': "wger Workout Manager",+ 'version': get_version(),+ 'url': request.build_absolute_uri(url), },styleSheet["Normal"])elements.append(P)-doc.build(elements)return response