Skip to content

vg/vgsvg: add switch to embed fonts to SVG plot#705

Merged
sbinet merged 5 commits intogonum:masterfrom
sbinet-gonum:svg-font-embed
Jul 1, 2021
Merged

vg/vgsvg: add switch to embed fonts to SVG plot#705
sbinet merged 5 commits intogonum:masterfrom
sbinet-gonum:svg-font-embed

Conversation

@sbinet
Copy link
Member

@sbinet sbinet commented Jun 18, 2021

Fixes #703.

@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2021

Codecov Report

Merging #705 (e774a24) into master (bd0e370) will increase coverage by 0.04%.
The diff coverage is 75.19%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #705      +/-   ##
==========================================
+ Coverage   71.91%   71.96%   +0.04%     
==========================================
  Files          56       58       +2     
  Lines        4957     5272     +315     
==========================================
+ Hits         3565     3794     +229     
- Misses       1206     1281      +75     
- Partials      186      197      +11     
Impacted Files Coverage Δ
vg/vgsvg/vgsvg.go 65.59% <75.19%> (+5.01%) ⬆️
vg/vggio/context.go 100.00% <0.00%> (ø)
vg/vggio/vggio.go 67.37% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd0e370...e774a24. Read the comment docs.

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

PTAL.

Copy link
Member

@kortschak kortschak left a comment

Choose a reason for hiding this comment

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

We still need docs for the case when the fonts aren't embedded, otherwise we are bound to see issues from people complaining about the effect that I show in this comment.

Copy link
Member

@kortschak kortschak left a comment

Choose a reason for hiding this comment

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

Sorry, I missed these, but the golden files need regeneration anyway.

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

PTAL.

I've added a simple mechanism that should preserve the old behaviour when relying on the Liberation <==> Times/Helvetica/Courier association map.
could you confirm?

@kortschak
Copy link
Member

No, that doesn't fix the issue.

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

(sorry, comments/PRs crossed each others... PS4 should address your latest comments)

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

ok. I'll remove the mechanism and add a comment linking to the example, then.

where should I hang it?
on vgsvg.Canvas, vgsvg.New or at the package level?

@kortschak
Copy link
Member

I would suggest that there also be documentation for installation of the liberation fonts, both in the package-level docs and in a README for the package.

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

installing fonts is widely OS (flavour) dependent... (and I actually don't know how to install fonts on darwin nor Windows nor *BSDs...)
I've just redirected to the wikipedia page for now.

(alternatively, we could switch to "embed-fonts=true", like for PDFs: this would make vgsvg do the "right thing" by default.)

@kortschak
Copy link
Member

Yeah, I think just embedding it probably the right thing to do. I just checked my install and I do have them installed, so even then we can't guaranteed the correct behaviour.

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

PTAL

kortschak
kortschak previously approved these changes Jun 24, 2021
Copy link
Member

@kortschak kortschak left a comment

Choose a reason for hiding this comment

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

The fonts in the originally incorrectly rendering fonts are still incorrectly rendering, but this has gone on long enough, so I'll approve.

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

ok. thanks.

out of curiosity, what's your setup? (browser, OS)

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

(the force-push is just to lump the PSxxx commits together)

@kortschak
Copy link
Member

ff89.0.1 on ubuntu 18.04.4.

kortschak
kortschak previously approved these changes Jun 24, 2021
@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

aha!
I can reproduce with ff89 on my archlinux system.

it seems that the culprit is specifying

  • font-family: Liberation, serif; or
  • font-family: Liberation, serif, Times;

instead of, say: font-family: Liberation, Times;

let me see if there isn't some deeper flaw at work...

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

aha!
for firefox (but it also works on my Chromium browser), it should read:
font-family: Liberation Serif;
(or all lower case: font-family: liberation serif;)
it would otherwise switch to its default font "DejaVu" which obviously doesn't metrically match with Liberation/Times.

I'll fix that.
but perhaps we could then switch back the default to "embed=false" ?

@kortschak
Copy link
Member

kortschak commented Jun 24, 2021

but perhaps we could then switch back the default to "embed=false" ?

If it works with that, then SGTM

@sbinet
Copy link
Member Author

sbinet commented Jun 24, 2021

PTAL.

now svgFontDescr will generate the correct font-family name directly from the underlying raw SFNT data (using sfnt.NameIDFamily) and handle the mismatch of meaning for font-variant between SVG and gonum/plot/font.

sbinet added 4 commits July 1, 2021 11:30
This CL drops the use of the internal fontMap that was associating some
pre-defined set of fonts with a set of SVG naming schemes (derived from
PostScript).
Instead, use the informations contained in plot/font.Font to derive the
expected SVG font-family (and friends) font style string.

Updates gonum#702.
@sbinet
Copy link
Member Author

sbinet commented Jul 1, 2021

PTAL (just rebased off the new master)

Copy link
Member

@kortschak kortschak left a comment

Choose a reason for hiding this comment

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

🎉

@sbinet sbinet merged commit b2d2027 into gonum:master Jul 1, 2021
@sbinet sbinet deleted the svg-font-embed branch July 1, 2021 11:29
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.

vg/vgsvg: consider adding the ability to embed fonts in SVG

3 participants