Skip to content

Commit a1ed4ef

Browse files
authored
Merge pull request matplotlib#30512 from QuLogic/pdf-text-subsets
pdf: Improve text with characters outside embedded font limits
2 parents b6be596 + c908bbf commit a1ed4ef

File tree

6 files changed

+149
-210
lines changed

6 files changed

+149
-210
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``PdfFile.multi_byte_charprocs``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated with no replacement.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Improved font embedding in PDF
2+
------------------------------
3+
4+
Both Type 3 and Type 42 fonts (see :ref:`fonts` for more details) are now
5+
embedded into PDFs without limitation. Fonts may be split into multiple
6+
embedded subsets in order to satisfy format limits. Additionally, a corrected
7+
Unicode mapping is added for each.
8+
9+
This means that *all* text should now be selectable and copyable in PDF viewers
10+
that support doing so.

lib/matplotlib/backends/_backend_pdf_ps.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,25 @@ def track_glyph(
205205
self.used.setdefault((font.fname, subset), {})[subset_charcode] = glyph
206206
return (subset, subset_charcode)
207207

208+
def subset_to_unicode(self, index: int,
209+
charcode: CharacterCodeType) -> CharacterCodeType:
210+
"""
211+
Map a subset index and character code to a Unicode character code.
212+
213+
Parameters
214+
----------
215+
index : int
216+
The subset index within a font.
217+
charcode : CharacterCodeType
218+
The character code within a subset to map back.
219+
220+
Returns
221+
-------
222+
CharacterCodeType
223+
The Unicode character code corresponding to the subsetted one.
224+
"""
225+
return index * self.subset_size + charcode
226+
208227

209228
class RendererPDFPSBase(RendererBase):
210229
# The following attributes must be defined by the subclasses:

0 commit comments

Comments
 (0)