Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement multi-font embedding for PDF Backend #20804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aitikgupta wants to merge 31 commits into matplotlib:main from aitikgupta:pdf-fallback
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d0906aa
Parse fallback_list through wrapper
aitikgupta Jul 25, 2021
f6f2fd7
Define new/modify previous FT2Font functions
aitikgupta Jul 25, 2021
5199773
Implement new/modify previous FT2Font functions
aitikgupta Jul 25, 2021
88da97f
Parse multiple fonts for a single FT2Font object
aitikgupta Jul 25, 2021
c6c3a45
Trigger font fallback for Agg backend
aitikgupta Jul 25, 2021
e868fbc
Remove prints
aitikgupta Aug 7, 2021
4230469
Cleanup wrapper
aitikgupta Aug 7, 2021
991c796
Remove stale prints
aitikgupta Aug 7, 2021
fa385eb
Do not warn for get_char_index
aitikgupta Aug 7, 2021
471ae8c
Left != Right kerning comment
aitikgupta Aug 7, 2021
86878c8
Windows compiler fix
aitikgupta Aug 7, 2021
5ccb7de
Add fallback test for Agg backend
aitikgupta Aug 13, 2021
ed495d3
Debug fontNames
aitikgupta Jul 28, 2021
d87ada8
Segfaults on exit
aitikgupta Jul 29, 2021
adebae4
More work on PDF backend
aitikgupta Jul 31, 2021
9983c66
Implement another approach
aitikgupta Aug 1, 2021
2ef863e
Revisit the approach
aitikgupta Aug 3, 2021
f12c295
Type3 PDF Backend works!
aitikgupta Aug 6, 2021
1327b82
Type42 PDF fallback works!
aitikgupta Aug 6, 2021
799ffde
Create a fill_glyphs method
aitikgupta Aug 7, 2021
7ce1805
Use fill_glyphs instead of set_text
aitikgupta Aug 7, 2021
ac1c9c9
Cleanup wrapper
aitikgupta Aug 7, 2021
8a30aaf
Few cleanups
aitikgupta Aug 7, 2021
e675047
Rebase from Agg backend
aitikgupta Aug 7, 2021
1b53070
Specify font number for TTC fonts
aitikgupta Aug 13, 2021
0e0d92c
Flake8 fixes
aitikgupta Aug 13, 2021
cb50510
Add multi-font tests for PDF backend
aitikgupta Aug 13, 2021
70b0e18
Add baseline images
aitikgupta Aug 13, 2021
42b6d6f
Merge branch 'master' into pdf-fallback
aitikgupta Aug 13, 2021
8fd0729
Fix memory leak and render tofu
aitikgupta Aug 17, 2021
7c88286
Check if fallback font is available
aitikgupta Aug 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Segfaults on exit
  • Loading branch information
aitikgupta committed Aug 13, 2021
commit d87ada85783b108dbd4b49da49dd32d2d92f856a
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_agg.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
return None
# We pass '0' for angle here, since it will be rotated (in raster
# space) in the following call to draw_text_image).
print("BEFORE")
font.set_text(s, 0, flags=flags)
font.draw_glyphs_to_bitmap(
antialiased=mpl.rcParams['text.antialiased'])
Expand Down
29 changes: 18 additions & 11 deletions lib/matplotlib/backends/backend_pdf.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
GraphicsContextBase, RendererBase)
from matplotlib.backends.backend_mixed import MixedModeRenderer
from matplotlib.figure import Figure
from matplotlib.font_manager import findfont, get_font
from matplotlib.font_manager import findfont, find_fontsprop, get_font
from matplotlib.afm import AFM
import matplotlib.type1font as type1font
import matplotlib.dviread as dviread
Expand Down Expand Up @@ -861,20 +861,24 @@ def fontName(self, fontprop):
"""

if isinstance(fontprop, str):
filename = fontprop
filename = [fontprop]
elif mpl.rcParams['pdf.use14corefonts']:
filename = findfont(
fontprop, fontext='afm', directory=RendererPdf._afm_font_dir)
filename = find_fontsprop(
fontprop, fontext='afm', directory=RendererPdf._afm_font_dir
).values()
else:
filename = findfont(fontprop)
filename = find_fontsprop(fontprop).values()

Fx = self.fontNames.get(filename)
if Fx is None:
Fx = next(self._internal_font_seq)
self.fontNames[filename] = Fx
_log.debug('Assigning font %s = %r', Fx, filename)
Fxs = []
for fname in filename:
Fx = self.fontNames.get(fname)
if Fx is None:
Fx = next(self._internal_font_seq)
self.fontNames[fname] = Fx
_log.debug('Assigning font %s = %r', Fx, fname)
Fxs.append(Fx)

return Fx
return Fxs[0]

def dviFontName(self, dvifont):
"""
Expand Down Expand Up @@ -1066,6 +1070,9 @@ def createType1Descriptor(self, t1font, fontfile):

def _get_xobject_symbol_name(self, filename, symbol_name):
Fx = self.fontName(filename)
# TODO: XObject symbol name should be multiple names?
# list(map(lambda x: x.name.decode(), Fxs))
# Fx = Fxs[0]
return "-".join([
Fx.name.decode(),
os.path.splitext(os.path.basename(filename))[0],
Expand Down
5 changes: 5 additions & 0 deletions src/ft2font.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ void FT2Font::set_text(
if (bbox.xMin > bbox.xMax) {
bbox.xMin = bbox.yMin = bbox.xMax = bbox.yMax = 0;
}
printf("\nMap: \n");
// print out num_glyphs for the final FT2Font so its easy to track
for (std::pair<const FT_UInt, FT2Font *> &x: glyph_to_font) {
printf("%u: %lu \n", x.first, x.second->get_face()->num_glyphs);
}
}

void FT2Font::fill_glyphs(
Expand Down

AltStyle によって変換されたページ (->オリジナル) /