Skip to content

Commit

Permalink
Fix rendering issue of non-ASCII characaters with unicode fonts (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C authored Jun 12, 2021
1 parent 2f2351b commit 3354afb
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/),
and [PEP 440](https://www.python.org/dev/peps/pep-0440/).

## [2.4.1] - not released yet
## [2.4.1] - 2021-06-12
### Fixed
- erroneous page breaks occured for full-width / full-height images
- rendering issue of non-ASCII characaters with unicode fonts

## [2.4.0] - 2021-06-11
### Changed
Expand Down
4 changes: 2 additions & 2 deletions fpdf/fpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
HERE = Path(__file__).resolve().parent

# Global variables
FPDF_VERSION = "2.4.0"
FPDF_VERSION = "2.4.1"
FPDF_FONT_DIR = HERE / "font"

PAGE_FORMATS = {
Expand Down Expand Up @@ -1634,7 +1634,7 @@ def cell(
txt_frag_escaped = escape_parens(
txt_frag.encode("UTF-16BE").decode("latin-1")
)
for char in txt_frag_escaped:
for char in txt_frag:
self.current_font["subset"].append(ord(char))
else:
txt_frag_escaped = escape_parens(txt_frag)
Expand Down
Binary file modified test/cells/cell_markdown_with_ttf_fonts.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified test/end_to_end_legacy/charmap/charmap_first_999_chars-cmss12.pdf
Binary file not shown.
Binary file added test/fonts/render_en_dash.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions test/fonts/test_add_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,13 @@ def test_add_core_fonts():
pdf.add_font("times", style="")
pdf.add_font("courier")
assert pdf.fonts == {} # No fonts added, as all of them are core fonts


def test_render_en_dash(tmp_path): # issue-166
pdf = FPDF()
font_file_path = HERE / "../fonts/Roboto-Regular.ttf"
pdf.add_font("Roboto-Regular", fname=font_file_path, uni=True)
pdf.set_font("Roboto-Regular", size=120)
pdf.add_page()
pdf.cell(w=pdf.epw, txt="–") # U+2013
assert_pdf_equal(pdf, HERE / "render_en_dash.pdf", tmp_path)
Binary file modified test/html/issue_156.pdf
Binary file not shown.

0 comments on commit 3354afb

Please sign in to comment.