Skip to content

Commit 35d9337

Browse files
authored
Deprecating font caching mechanism + support for .pkl font files definitions (#347)
1 parent 6dedf61 commit 35d9337

20 files changed

+148
-250
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@ and [PEP 440](https://www.python.org/dev/peps/pep-0440/).
1414
- documentation on combining `borb` & `fpdf2`: [Creating a borb.pdf.document.Document from a FPDF instance](https://pyfpdf.github.io/fpdf2/ExistingPDFs.html)
1515

1616
### Changed
17+
- `fname` is now a required parameter for `FPDF.add_font()`
1718
- `image()` method now insert `.svg` images as PDF paths
19+
- the [defusedxml](https://pypi.org/project/defusedxml/) package was added as dependency in order to make SVG parsing safer
1820
- log level of `_substitute_page_number()` has been lowered from `INFO` to `DEBUG`
1921

2022
### Fixed
2123
- a bug in `get_string_width()` with unicode fonts and Markdown enabled,
2224
resulting in calls to `cell()` / `multi_cell()` with `align="R"` to display nothing - thanks @mcerveny for the fix!
2325
- a bug with incorrect width calculation of markdown text
2426

27+
### Deprecated
28+
- the font caching mechanism, that used the `pickle` module, has been removed, for security reasons,
29+
and because it provided little performance, and only for specific use cases - _cf._ [issue #345](https://github.com/PyFPDF/fpdf2/issues/345).
30+
That means that the `font_cache_dir` optional parameter of `fpdf.FPDF` constructor
31+
and the `uni` optional argument of `FPDF.add_font()` are deprecated.
32+
The `fpdf.fpdf.load_cache` function has also been removed.
33+
34+
To be extra clear: `uni=True` can now be removed from all calls to `FPDF.add_font()`.
35+
If the value of the `fname` argument passed to `add_font()` ends with `.ttf`, it is considered a TrueType font.
36+
2537
## [2.5.0] - 2022-01-22
2638
### Added
2739
Thanks to @torque for contributing this massive new feature:

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
[![Pypi latest version](https://img.shields.io/pypi/v/fpdf2.svg)](https://pypi.python.org/pypi/fpdf2)
33
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
44
[![codecov](https://codecov.io/gh/PyFPDF/fpdf2/branch/master/graph/badge.svg)](https://codecov.io/gh/PyFPDF/fpdf2)
5+
[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
56
[![Downloads per month](https://pepy.tech/badge/fpdf2/month)](https://pepy.tech/project/fpdf2)
67

78
[![Discussions](https://img.shields.io/github/discussions/PyFPDF/fpdf2)](https://github.com/PyFPDF/fpdf2/discussions)

docs/EmojisSymbolsDingbats.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Here is an example using the [DejaVu](https://dejavu-fonts.github.io) font:
1111
import fpdf
1212

1313
pdf = fpdf.FPDF()
14-
pdf.add_font("DejaVuSans", fname="DejaVuSans.ttf", uni=True)
14+
pdf.add_font("DejaVuSans", fname="DejaVuSans.ttf")
1515
pdf.set_font("DejaVuSans", size=64)
1616
pdf.add_page()
1717
pdf.multi_cell(0, txt="".join([chr(0x1F600 + x) for x in range(68)]))

docs/Unicode.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pdf.add_page()
5959
# Add a DejaVu Unicode font (uses UTF-8)
6060
# Supports more than 200 languages. For a coverage status see:
6161
# http://dejavu.svn.sourceforge.net/viewvc/dejavu/trunk/dejavu-fonts/langcover.txt
62-
pdf.add_font('DejaVu', fname='DejaVuSansCondensed.ttf', uni=True)
62+
pdf.add_font('DejaVu', fname='DejaVuSansCondensed.ttf')
6363
pdf.set_font('DejaVu', size=14)
6464

6565
text = u"""
@@ -81,14 +81,14 @@ for txt in text.split('\n'):
8181
# Supports: Bengali, Devanagari, Gujarati,
8282
# Gurmukhi (including the variants for Punjabi)
8383
# Kannada, Malayalam, Oriya, Tamil, Telugu, Tibetan
84-
pdf.add_font('gargi', fname='gargi.ttf', uni=True)
84+
pdf.add_font('gargi', fname='gargi.ttf')
8585
pdf.set_font('gargi', size=14)
8686
pdf.write(8, u'Hindi: नमस्ते दुनिया')
8787
pdf.ln(20)
8888

8989
# Add a AR PL New Sung Unicode font (uses UTF-8)
9090
# The Open Source Chinese Font (also supports other east Asian languages)
91-
pdf.add_font('fireflysung', fname='fireflysung.ttf', uni=True)
91+
pdf.add_font('fireflysung', fname='fireflysung.ttf')
9292
pdf.set_font('fireflysung', size=14)
9393
pdf.write(8, u'Chinese: 你好世界\n')
9494
pdf.write(8, u'Japanese: こんにちは世界\n')
@@ -97,13 +97,13 @@ pdf.ln(10)
9797
# Add a Alee Unicode font (uses UTF-8)
9898
# General purpose Hangul truetype fonts that contain Korean syllable
9999
# and Latin9 (iso8859-15) characters.
100-
pdf.add_font('eunjin', fname='Eunjin.ttf', uni=True)
100+
pdf.add_font('eunjin', fname='Eunjin.ttf')
101101
pdf.set_font('eunjin', size=14)
102102
pdf.write(8, u'Korean: 안녕하세요')
103103
pdf.ln(20)
104104

105105
# Add a Fonts-TLWG (formerly ThaiFonts-Scalable) (uses UTF-8)
106-
pdf.add_font('waree', fname='Waree.ttf', uni=True)
106+
pdf.add_font('waree', fname='Waree.ttf')
107107
pdf.set_font('waree', size=14)
108108
pdf.write(8, u'Thai: สวัสดีชาวโลก')
109109
pdf.ln(20)

0 commit comments

Comments
 (0)