Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user-defined font-family for TextSelection #68

Open
RyanMullins opened this issue Oct 4, 2022 · 2 comments
Open

Support user-defined font-family for TextSelection #68

RyanMullins opened this issue Oct 4, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@RyanMullins
Copy link
Member

RyanMullins commented Oct 4, 2022

It would be nice if Megaplot offered a couple of different font families for TextSelections, similar to CSS font-family, but maybe restricted to a known set since they need to be converted into a texture that gets sampled?

@jimbojw
Copy link
Collaborator

jimbojw commented Oct 4, 2022

This is a reasonable request. Doing it at all is easy. Doing it well would be hard.

Glyphs in Megaplot are implemented by sampling into a Signed Distance Field (SDF) texture which is made and managed by the GlyphMapper class. One of the construction parameters of the GlyphMapper is fontFamily, which currently defaults to 'monospace'. It would be relatively easy to expose fontFamily as an optional construction parameter on the Scene class and pass it through.

However, this introduces the problem of kerning. Currently, issues of kerning are headed off by only supporting a monospace font. Allowing the user to specify an arbitrary typeface introduces the problem of differential character-pair spacing. User-specified fonts might also make glyphs that are wider or narrower than currently expected, or extend beyond the top or bottom of the planned bounding box.

Lastly, there's the issue of loading the font file(s). Rendering to the SDF texture should be delayed until the specified font family has finished loading. Loading may be delayed relative to other page assets. The font family may not load at all (for example if the URL is broken). What to do in these cases is not immediately clear.

Some of these problems are likely to be encountered anyway, even without custom fonts. For example, some languages' characters are especially wide or tall. Eventually the data Megaplot is asked to render will probably include Unicode characters which may render incorrectly or not at all, even using a fixed monospace font.

@RyanMullins
Copy link
Member Author

Yup, totally get the can of worms this could potentially open.

What about a phased approach -- baking in a limited set of fixed width fonts (even just 2), then expanding to user-defined fixed-width fonts, then finally to any user-defined font?

At the moment, all I want is something that looks nicer than Chrome's custom monospace font family. Noto Sans Mono would be great and its license seems to be compatible with Megaplot's use case.

The other two steps in the progression could come (much) later... as in v2 or v3 "later".

@jimbojw jimbojw added the enhancement New feature or request label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants