Skip to content
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
Type3 PDF Backend works!
  • Loading branch information
aitikgupta committed Aug 13, 2021
commit f12c295101419e0d91f4c2fd9959ac23e1996040
5 changes: 1 addition & 4 deletions lib/matplotlib/_text_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ def layout(string, font, *, kern_mode=KERNING_DEFAULT):
"""
x = 0
prev_glyph_idx = None
print("Inside _text_helpers.py")
# breakpoint()
for char in string:
# print("\nchecking:", char, "\n")
glyph_idx = font.get_char_index(ord(char))
kern = (font.get_kerning(prev_glyph_idx, glyph_idx, kern_mode) / 64
if prev_glyph_idx is not None else 0.)
x += kern
glyph = font.load_glyph(glyph_idx, flags=LOAD_NO_HINTING)
ft_object = font.get_glyph_to_font().get(glyph_idx)
ft_object = font.get_glyph_to_font().get(glyph_idx, font)
yield LayoutItem(ft_object, char, glyph_idx, x, kern)
x += glyph.linearHoriAdvance / 65536
prev_glyph_idx = glyph_idx
36 changes: 21 additions & 15 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,21 +862,28 @@ def fontName(self, fontprop):
"""

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

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)

return Fx
filenames = find_fontsprop(fontprop).values()
first_Fx = None
for fname in filenames:
Fx = self.fontNames.get(fname)
if not first_Fx:
first_Fx = Fx
if Fx is None:
Fx = next(self._internal_font_seq)
self.fontNames[fname] = Fx
_log.debug('Assigning font %s = %r', Fx, fname)
if not first_Fx:
first_Fx = Fx

# find_fontsprop's first value always adheres to
# findfont's value, so technically no behaviour change
return first_Fx

def dviFontName(self, dvifont):
"""
Expand Down Expand Up @@ -1073,7 +1080,6 @@ def _get_xobject_symbol_name(self, filename, symbol_name):
Fx.name.decode(),
os.path.splitext(os.path.basename(filename))[0],
symbol_name])
print("\n\nXOBJECT", x, "\n\n")
return x

_identityToUnicodeCMap = b"""/CIDInit /ProcSet findresource begin
Expand Down Expand Up @@ -2350,7 +2356,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# populate self.fontNames with all fonts
_ = [self.file.fontName(ft_object.fname) for ft_object in self.glyph_to_font.values()]
for char, font in self.char_to_font.items():
print(chr(char), "to:", font.fname)
# print(chr(char), "to:", font.fname)
self.file._character_tracker.track(font, chr(char))
print("\nFONT_TO_CHAR:", self.file._character_tracker.used)
fonttype = mpl.rcParams['pdf.fonttype']
Expand Down Expand Up @@ -2399,7 +2405,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
prev_was_multibyte = True
for item in _text_helpers.layout(
s, font, kern_mode=KERNING_UNFITTED):
print(item.ft_object.fname, item)
print(f"char: {item.char}, x: {item.x}, fname: {item.ft_object.fname}")
if _font_supports_char(fonttype, item.char):
if prev_was_multibyte:
singlebyte_chunks.append((item.ft_object, item.x, []))
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ def find_fontsprop(self, prop, fontext='ttf', directory=None,
See `findfont` for more details.

"""
# print("finding font!")

rc_params = tuple(tuple(rcParams[key]) for key in [
"font.serif", "font.sans-serif", "font.cursive", "font.fantasy",
Expand Down
16 changes: 8 additions & 8 deletions src/ft2font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void FT2Font::set_text(
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
// 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);
// }
Expand Down Expand Up @@ -692,7 +692,6 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph,
charcode_error = FT_Load_Glyph(face, glyph_index, flags);
FT_Glyph thisGlyph;
glyph_error = FT_Get_Glyph(face->glyph, &thisGlyph);

if (charcode_error || glyph_error) {
return false;
}
Expand Down Expand Up @@ -739,16 +738,17 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
{
// search cache first
if (fallback && glyph_to_font.find(glyph_index) != glyph_to_font.end()) {
// printf("load_glyph: Already present in cache.\n");
printf("load_glyph: Already present in cache.\n");
ft_object = glyph_to_font[glyph_index];
return;
} else {
ft_object = this;
}
// can not do fallback without a charcode
// so ignore exact condition fallback == 1

// set as self
ft_object = this;
ft_object->load_glyph(glyph_index, flags);
}

void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
{
if (FT_Error error = FT_Load_Glyph(face, glyph_index, flags)) {
throw_ft_error("Could not load glyph", error);
}
Expand Down