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

web: Add defaultFonts and fontSources config options #13604

Merged
merged 2 commits into from Oct 30, 2023

Conversation

Dinnerbone
Copy link
Contributor

@Dinnerbone Dinnerbone commented Oct 18, 2023

Font sources

image

Each URL provided to this config option will try to eagerly load as a font source.
If the URL cannot load, it will be ignored (but a warning will print).
If the URL cannot parse into a valid font, it will be ignored (but a warning will print).

Right now it only supports fonts embeded inside SWFs. Any number of fonts can be inside a single SWF, but they need to be embedded with DefineFont2 and you need to make sure it's actually inside the swf (not stripped out by not being used).
A future PR will enable TTF/OTF support.

How to make a font SWF

1. Create a new document in Flash Pro or Animate, make sure it's ActionScript 3.

image

2. On the right hand side, click the Library tab and right click somewhere in the big empty space, and hit New Font

image

3. Set the name, pick the font and style from the list, and then choose which characters you want to embed. Only these characters will be available to use from this font.

image

4. In the ActionScript tab, check "Export for ActionScript" to make sure it stays inside the swf, and make sure it's "DF3" not "DF4".

image

5. Export the SWF. Make sure you export it as a SWF

image
image

6. Configure Ruffle to load that SWF as a font source.

window.RufflePlayer.config = {
    fontSources: ["my-big-fonts.swf"]
}

Default fonts

image

There are 3 "default" device fonts in Flash. _sans, _serif, _typewriter. In Ruffle they are our Noto Sans fallback unless configured otherwise.

To change that, set:

window.RufflePlayer.config = {
    defaultFonts: {
        sans: ["Caveat"]
    }
}

The font in question needs to be loaded with fontSources or it won't be found.

@Dinnerbone
Copy link
Contributor Author

(I spent a long time trying to get the internal config right but that ended up being a rabbit hole for another PR. We shouldn't pass the user set config all the way down to rust.)

Copy link
Member

@sleepycatcoding sleepycatcoding left a comment

Choose a reason for hiding this comment

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

Looks good to me!

web/src/lib.rs Outdated Show resolved Hide resolved
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.

None yet

2 participants