linebender / linebender/piet

piet-svg will embed standard fonts in svg files

Open
#593 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted piet-svg
Dominant language
Rust
Stars
1.4k
Forks
98
PR merge metrics
No merged PRs in 30d

Description

Piet-svg will always embed a font when using text, which means that as soon as you use any text you get large files. I would have thought that if I used a standard font like FontFamily::SANS_SERIF, that this would be translated to the system sans-serif font in the svg file. But the generated svg files will contain a font-face definition embedding the entire font:

@font-face {
font-family: "sans-serif";
font-weight: 400;
font-style: normal;
src: url(data:...)
}

I want to use piet to generate a lot of small plots, and wasting half a megabyte per file on font data is unacceptable.

The piet-svg source code says "If we are using a named font, then mark it for inclusion." (piet-svg/src/lib.rs:272), which implies that unnamed fonts (like sans-serif) should not be included. The solution is to actually perform the promised check:

        // If we are using a named font, then mark it for inclusion.
        if !layout.font_face.is_generic() {
            self.text()
                .seen_fonts
                .lock()
                .unwrap()
                .insert(layout.font_face.clone());
        }

It could also make sense to let the user specify if fonts should be embedded, because there can be reasons not to do so (I am thinking of license restrictions for example, or in the context of an application where we know a certain font is available).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in piet-svg/src/lib.rs around line 272, where fonts are marked for inclusion, and review the issue's proposed generic-font check. Verify that generated SVG output using a generic font such as FontFamily::SANS_SERIF no longer embeds a font-face definition, while named fonts retain their existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.