Skip to content

Fix set_font() for PDF and SVG backends#674

Merged
jwiggins merged 1 commit into
masterfrom
fix/file-bench-show-text
Mar 4, 2021
Merged

Fix set_font() for PDF and SVG backends#674
jwiggins merged 1 commit into
masterfrom
fix/file-bench-show-text

Conversation

@jwiggins
Copy link
Copy Markdown
Member

@jwiggins jwiggins commented Mar 3, 2021

Font lookup was a bit screwy with all of the file-based Kiva backends. This fixes set_font for PDF and SVG, at least with respect to the benchmark program.

Comment thread kiva/pdf.py
if not os.path.splitext(filename)[-1] in (".ttf", ".ttc"):
raise

pdfmetrics.registerFont(TTFont(face_name, filename))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this embeds the font in the PDF file. I'm not sure if we want that or not.

PDF has a set of "safe" fonts which come with Acrobat Reader. I think maybe what we want to do in this method is try to map all requested fonts to the nearest match in this list.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this embeds the font in the PDF file.

Based off the link below, I believe this is true as well.

PDF has a set of "safe" fonts which come with Acrobat Reader. I think maybe what we want to do in this method is try to map all requested fonts to the nearest match in this list.

I am unsure about this / why it would be necessary, but my understanding of all this is very much not complete / still growing. When would embedding the font in the PDF file not work or be problematic?

ref: https://www.reportlab.com/docs/reportlab-userguide.pdf
pg. 28 and 49-52

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would embedding the font in the PDF file not work or be problematic?

You're right. It's probably OK.

Copy link
Copy Markdown
Contributor

@aaronayres35 aaronayres35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I re-ran the script and pdf/svg no longer fail for the show_text benchmark. These are the results I see:

Screen Shot 2021-03-04 at 10 27 00 AM

Screen Shot 2021-03-04 at 10 26 51 AM

Admittedly I am not 100% confident in my understanding of all the details of the changes made. Nonetheless, this PR certainly seems to be an incremental improvement, and from what I do understand the changes make sense.

Comment thread kiva/pdf.py
if not os.path.splitext(filename)[-1] in (".ttf", ".ttc"):
raise

pdfmetrics.registerFont(TTFont(face_name, filename))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this embeds the font in the PDF file.

Based off the link below, I believe this is true as well.

PDF has a set of "safe" fonts which come with Acrobat Reader. I think maybe what we want to do in this method is try to map all requested fonts to the nearest match in this list.

I am unsure about this / why it would be necessary, but my understanding of all this is very much not complete / still growing. When would embedding the font in the PDF file not work or be problematic?

ref: https://www.reportlab.com/docs/reportlab-userguide.pdf
pg. 28 and 49-52

@jwiggins jwiggins merged commit 1119f1f into master Mar 4, 2021
@jwiggins
Copy link
Copy Markdown
Member Author

jwiggins commented Mar 4, 2021

Thanks for the review

@jwiggins jwiggins deleted the fix/file-bench-show-text branch March 4, 2021 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants