Skip to content

SKETCH-2728: Adding fallback font names to generated SVG files#302

Merged
KevKeating merged 1 commit intoschrodinger:mainfrom
KevKeating:pr/SKETCH-2728
Apr 13, 2026
Merged

SKETCH-2728: Adding fallback font names to generated SVG files#302
KevKeating merged 1 commit intoschrodinger:mainfrom
KevKeating:pr/SKETCH-2728

Conversation

@KevKeating
Copy link
Copy Markdown
Collaborator

Description

@rachelnwalker finally figured out why the images in Live Design's first column aren't using the correct font: those images are rendered as SVGs, which means that the font will only be correct if the user has Arimo installed as a system-wide font. If not, the web browser doesn't know enough about Arimo to even know that it's sans serif, so it winds up replacing it with a serif font. To fix this, I've added a list of fallback fonts, including Arial and Helvetica, to the SVG file. We're only including the font name in the SVG file, not the font itself, so we don't need to worry about font licensing. With this change, the generated SVGs look correct if I open them up in my web browser, and @juzerzarif confirmed that he sees the same thing.

My first attempt at this was to specify the alternate fonts as QFont families, but QSvgGenerator ignores these. (I checked in the Qt source code and confirmed that's the expected, but unfortunate, behavior.) As a result, I added some logic to our SVG post processing to manually add in the additional font names.

I'm assuming that we'll want to add this commit to the release branch in both sketcher and mmshare. I don't think I have permissions to merge a PR directly into the release branch on sketcher, but I can cherry-pick and manually push after this gets merged into main. When I put up an mmshare PR, I'll do that against the release branch so it can go through engineering approval.

Testing Done

I saved an SVG from Sketcher and confirmed that it looks correct. I also updated the SVG unit test to include a check for the font list.

Comment on lines +387 to +389
* Post-process the contents of the SVG file after Qt has generated it
* @param svg_data The contents of the SVG file
* @param opts The options used to render the SVG
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to include here the goals of the post-processing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I thought about doing that, but it seemed like any description here would become stale far more quickly than the comments that are above each block of code in the body of the function.

@KevKeating KevKeating added this pull request to the merge queue Apr 13, 2026
Merged via the queue into schrodinger:main with commit d5b645b Apr 13, 2026
6 checks passed
@KevKeating KevKeating deleted the pr/SKETCH-2728 branch April 13, 2026 19:07
KevKeating added a commit that referenced this pull request Apr 13, 2026
* Linked Case: SKETCH-2728, SKETCH-2682, LDID8-1488

### Description

@rachelnwalker finally figured out why the images in Live Design's first
column aren't using the correct font: those images are rendered as SVGs,
which means that the font will only be correct if the user has Arimo
installed as a system-wide font. If not, the web browser doesn't know
enough about Arimo to even know that it's sans serif, so it winds up
replacing it with a serif font. To fix this, I've added a list of
fallback fonts, including Arial and Helvetica, to the SVG file. We're
only including the font name in the SVG file, not the font itself, so we
don't need to worry about font licensing. With this change, the
generated SVGs look correct if I open them up in my web browser, and
@juzerzarif confirmed that he sees the same thing.

My first attempt at this was to specify the alternate fonts as QFont
families, but QSvgGenerator ignores these. (I checked in the Qt source
code and confirmed that's the expected, but unfortunate, behavior.) As a
result, I added some logic to our SVG post processing to manually add in
the additional font names.

I'm assuming that we'll want to add this commit to the release branch in
both `sketcher` and `mmshare`. I don't think I have permissions to merge
a PR directly into the release branch on `sketcher`, but I can
cherry-pick and manually push after this gets merged into `main`. When I
put up an `mmshare` PR, I'll do that against the release branch so it
can go through engineering approval.

### Testing Done
I saved an SVG from Sketcher and confirmed that it looks correct. I also
updated the SVG unit test to include a check for the font list.
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.

4 participants