Skip to content

Commit

Permalink
Switch from UTF-16BE encoding to utf-16-be (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C authored Jan 20, 2022
1 parent 798e3d8 commit 9dbffd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and [PEP 440](https://www.python.org/dev/peps/pep-0440/).

### Fixed
- `will_page_break()` & `accept_page_break` are not invoked anymore during a call to `multi_cell(split_only=True)`
- Unicode characters in headings are now properly displayed in the table of content, _cf._ [#320](https://github.com/PyFPDF/fpdf2/issues/320)
- Unicode characters in headings are now properly displayed in the table of content, _cf._ [#320](https://github.com/PyFPDF/fpdf2/issues/320) - thanks @lcomrade

## [2.4.6] - 2021-11-16
### Added
Expand Down
12 changes: 6 additions & 6 deletions fpdf/fpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ def text(self, x, y, txt=""):
# Instead of adding the actual character to the stream its code is
# mapped to a position in the font's subset
txt_mapped += chr(self.current_font["subset"].pick(uni))
txt2 = escape_parens(txt_mapped.encode("UTF-16BE").decode("latin-1"))
txt2 = escape_parens(txt_mapped.encode("utf-16-be").decode("latin-1"))
else:
txt2 = escape_parens(txt)
s = f"BT {x * self.k:.2f} {(self.h - y) * self.k:.2f} Td ({txt2}) Tj ET"
Expand Down Expand Up @@ -2083,7 +2083,7 @@ def cell(
# If multibyte, Tw has no effect - do word spacing using an
# adjustment before each space
if self.ws and self.unifontsubset:
space = escape_parens(" ".encode("UTF-16BE").decode("latin-1"))
space = escape_parens(" ".encode("utf-16-be").decode("latin-1"))
s += " 0 Tw"
for txt_frag, style, underline in styled_txt_frags:
if self.font_style != style:
Expand All @@ -2105,7 +2105,7 @@ def cell(

s += " ["
for i, word in enumerate(words):
word = escape_parens(word.encode("UTF-16BE").decode("latin-1"))
word = escape_parens(word.encode("utf-16-be").decode("latin-1"))
s += f"({word}) "
is_last_word = (i + 1) == len(words)
if not is_last_word:
Expand Down Expand Up @@ -2133,7 +2133,7 @@ def cell(
)

txt_frag_escaped = escape_parens(
txt_frag_mapped.encode("UTF-16BE").decode("latin-1")
txt_frag_mapped.encode("utf-16-be").decode("latin-1")
)
else:
txt_frag_escaped = escape_parens(txt_frag)
Expand Down Expand Up @@ -3051,8 +3051,8 @@ def _substitute_page_number(self):
nb = self.pages_count # total number of pages
substituted = False
# Replace number of pages in fonts using subsets (unicode)
alias = self.str_alias_nb_pages.encode("UTF-16BE")
encoded_nb = str(nb).encode("UTF-16BE")
alias = self.str_alias_nb_pages.encode("utf-16-be")
encoded_nb = str(nb).encode("utf-16-be")
for n in range(1, nb + 1):
page = self.pages[n]
new_content = page["content"].replace(alias, encoded_nb)
Expand Down

0 comments on commit 9dbffd1

Please sign in to comment.