servo / pathfinder

A fast, practical GPU rasterizer for fonts and vector graphics
Apache License 2.0
3.52k stars 198 forks source link

Indirect Outline references #206

Open s3bk opened 5 years ago

s3bk commented 5 years ago

When renderng text, the same glyph outline is repeatedly draw and added to the list of outlines. The result is that exported SVG, PDF and PS files have to repeat a glyph every time it is used, causing the file size to get quite large.

A way to define an outline and draw it by reference (outline_id, transformation) would avoid this. SVG has this mechanism with symbol and use. PostScript is a programming language, so there are many ways to implement this. (a dictionary/list of functions would work) PDF allows is with Form XObjects (and Type1 fonts if one generates a font from the outlines.)

s3bk commented 5 years ago

Implementation idea:

create a new Named struct, that stores the outlines.

Then a mutable reference to Named is passed to the Scene constructor and the following methods are added to Scene:

fn define(&mut self, outline: Outline) -> OutlineId;
fn use(&mut self, outline_id: OutlineId, transformation: Transformation2DF);

This would allow defining new outlines on the fly (no need to define them all before the scene is created).

pcwalton commented 5 years ago

So what I would like to do is to have the notion of Symbols in the Scene. A Symbol (different names would be totally fine) is just an outline that can be reused repeatedly in the scene.

Symbols would also affect rendering via customizable tile caching policies, so that when we draw a glyph once we don't have to draw it again. The tile caching policies I would propose are: (1) no caching; (2) cache and reuse on translations snapping to the nearest, say, 1/4 pixel; (3) cache and reuse for any transform, generating mipmaps on the fly (issue #191).

We don't have to implement tile caching to get started on Symbols, though.