Skip to content

Commit

Permalink
Merge pull request #12 from WadeBarnes/upgrade-dependencies
Browse files Browse the repository at this point in the history
Upgrade to the latest version of WeasyPrint
  • Loading branch information
WadeBarnes authored Jul 30, 2024
2 parents 2c05b72 + 16eb33c commit e109561
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM ubuntu:18.04
#FROM python:3.6-stretch
FROM python:3.12

#RUN echo "deb http://ftp.debian.org/debian stretch main contrib" > /etc/apt/sources.list

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: WeasyPrint HTML to PDF/PNG Microservice
description: A ready to use, OpenShift compatible, HTML to PDF/PNG microservice for your application.
author: WadeBarnes
resourceType: Components
personas:
personas:
- Developer
- Product Owner
- Designer
Expand All @@ -26,6 +26,12 @@ Pre-built images can be found here; [bcgovimages/weasyprint](https://hub.docker.

# Usage - Docker Example

Build the docker image

```
docker build --no-cache -f Dockerfile -t bcgovimages/weasyprint .
```

Run the docker image, exposing port 5001

```
Expand Down
16 changes: 7 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@

from flask import Flask, request, make_response
from weasyprint import HTML
from weasyprint.fonts import FontConfiguration
from weasyprint.text.fonts import FontConfiguration
from fonts import css_for_extra_fonts

app = Flask('pdf')

@app.route('/health')
def index():
return 'ok'


@app.before_first_request
def setup_logging():
with app.app_context():
logging.addLevelName(logging.DEBUG, "\033[1;36m%s\033[1;0m" % logging.getLevelName(logging.DEBUG))
logging.addLevelName(logging.INFO, "\033[1;32m%s\033[1;0m" % logging.getLevelName(logging.INFO))
logging.addLevelName(logging.WARNING, "\033[1;33m%s\033[1;0m" % logging.getLevelName(logging.WARNING))
Expand All @@ -31,6 +24,11 @@ def setup_logging():
app.logger.setLevel(logging.DEBUG)


@app.route('/health')
def index():
return 'ok'


@app.route('/')
def home():
return '''
Expand Down
10 changes: 9 additions & 1 deletion fonts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from weasyprint import CSS
from weasyprint.fonts import FontConfiguration
from weasyprint.text.fonts import FontConfiguration

def css_for_extra_fonts():
font_config = FontConfiguration()
Expand All @@ -12,6 +12,10 @@ def css_for_extra_fonts():
font-family: 'BC Sans Bold';
src: local('BCSans-Bold');
}
@font-face {
font-family: 'BC Sans Light';
src: local('BCSans-Light');
}
@font-face {
font-family: 'BC Sans Bold Italic';
src: local('BCSans-BoldItalic');
Expand All @@ -20,6 +24,10 @@ def css_for_extra_fonts():
font-family: 'BC Sans Italic';
src: local('BCSans-Italic');
}
@font-face {
font-family: 'BC Sans Light Italic';
src: local('BCSans-LightItalic');
}
@font-face {
font-family: 'Noto Sans Light';
src: local('NotoSans-Light');
Expand Down
Binary file modified fonts/BCSans-Bold.otf
Binary file not shown.
Binary file modified fonts/BCSans-BoldItalic.otf
Binary file not shown.
Binary file modified fonts/BCSans-Italic.otf
Binary file not shown.
Binary file added fonts/BCSans-Light.otf
Binary file not shown.
Binary file added fonts/BCSans-LightItalic.otf
Binary file not shown.
Binary file modified fonts/BCSans-Regular.otf
Binary file not shown.
25 changes: 25 additions & 0 deletions fonts/FONTLOG_README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FONTLOG for the BC Sans font (2.0)

This file provides detailed information on the BC Sans font software.
This information should be distributed along with the BC Sans fonts and any derivative works.

Basic Font Information:
BC Sans is a Unicode typeface family that supports languages that use the Latin and syllabic scripts, and it's variants.
BC Sans is a modified version of Noto Sans, developed by Google. Modifications have been done to provide support for Indigenous languages unique to British Columbia.
BC Sans (2.0) comes in six styles: light, light italic, regular, italic, bold, and bold italic.

Version Log:
BC Sans Font Family Version 2.0
Government of British Columbia
May 2023

Acknowledgements:
N: Chris Harvey
E: [email protected]
W: http://www.languagegeek.com
D: Contributor

N: FirstVoices (An initiative of First Peoples' Cultural Coucil)
E: [email protected]
W: https://www.firstvoices.com
D: Contributor
5 changes: 3 additions & 2 deletions fonts/LICENSE_OFL.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
This Font Software is licensed under the SIL Open Font License,
Version 1.1.
Copyright (c) 2015, Google Inc.
Copyright (c) 2023, Province of B.C. 2023

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gunicorn==19.9.0
WeasyPrint==52.3
flask==1.0.1
gunicorn==22.0.0
WeasyPrint==62.3
flask==3.0.3

0 comments on commit e109561

Please sign in to comment.