Skip to content

Commit 15f3313

Browse files
committed
core: Include a regular subsetted Noto Sans as the default font
1 parent 9382730 commit 15f3313

File tree

7 files changed

+47
-26
lines changed

7 files changed

+47
-26
lines changed
-72.2 KB
Binary file not shown.

core/assets/noto-sans.fla

-4.79 KB
Binary file not shown.

core/assets/noto-sans.swf

-43.1 KB
Binary file not shown.
51.6 KB
Binary file not shown.

core/assets/unicodes-file.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Download Noto Sans from https://fonts.google.com/noto/specimen/Noto+Sans
2+
# Run `pyftsubset --unicodes-file=unicodes-file.txt NotoSans-Regular.ttf`
3+
0000-007F, # Basic Latin
4+
0080-00FF, # Latin-1 Supplement
5+
0100-017F, # Latin Extended-A
6+
0180-024F, # Latin Extended-B
7+
02B0-02FF, # Spacing Modifier Letters
8+
2000-206F, # General Punctuation
9+
2070-209F, # Superscripts and Subscripts
10+
20A0-20CF, # Currency Symbols
11+
2100-214F, # Letterlike Symbols
12+
2150-218F, # Number Forms
13+
2200-22FF, # Mathematical Operators
14+
# Compress with `cat NotoSans-Regular.subset.ttf | gzip --no-name | tail --bytes=+11 | head --bytes=-8 > notosans-regular.subset.ttf.gz`

core/src/font.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,35 +1074,31 @@ impl Default for TextRenderSettings {
10741074

10751075
#[cfg(test)]
10761076
mod tests {
1077-
use crate::font::{EvalParameters, Font, FontType};
1077+
use crate::font::{EvalParameters, Font, FontDescriptor, FontType};
10781078
use crate::string::WStr;
1079+
use flate2::read::DeflateDecoder;
10791080
use gc_arena::{rootless_arena, Mutation};
1080-
use ruffle_render::backend::{null::NullRenderer, ViewportDimensions};
1081+
use std::borrow::Cow;
1082+
use std::io::Read;
10811083
use swf::Twips;
10821084

1083-
const DEVICE_FONT_TAG: &[u8] = include_bytes!("../assets/noto-sans-definefont3.bin");
1085+
const DEVICE_FONT: &[u8] = include_bytes!("../assets/notosans-regular.subset.ttf.gz");
10841086

10851087
fn with_device_font<F>(callback: F)
10861088
where
10871089
F: for<'gc> FnOnce(&Mutation<'gc>, Font<'gc>),
10881090
{
10891091
rootless_arena(|mc| {
1090-
let mut renderer = NullRenderer::new(ViewportDimensions {
1091-
width: 0,
1092-
height: 0,
1093-
scale_factor: 1.0,
1094-
});
1095-
let mut reader = swf::read::Reader::new(DEVICE_FONT_TAG, 8);
1096-
let device_font = Font::from_swf_tag(
1097-
mc,
1098-
&mut renderer,
1099-
reader
1100-
.read_define_font_2(3)
1101-
.expect("Built-in font should compile"),
1102-
reader.encoding(),
1103-
FontType::Device,
1104-
);
1105-
1092+
let mut data = Vec::new();
1093+
let mut decoder = DeflateDecoder::new(DEVICE_FONT);
1094+
decoder
1095+
.read_to_end(&mut data)
1096+
.expect("default font decompression must succeed");
1097+
1098+
let descriptor = FontDescriptor::from_parts("Noto Sans", false, false);
1099+
let device_font =
1100+
Font::from_font_file(mc, descriptor, Cow::Owned(data), 0, FontType::Device)
1101+
.unwrap();
11061102
callback(mc, device_font);
11071103
})
11081104
}

core/src/player.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use web_time::Instant;
7171
pub const NEWEST_PLAYER_VERSION: u8 = 32;
7272

7373
#[cfg(feature = "default_font")]
74-
pub const FALLBACK_DEVICE_FONT_TAG: &[u8] = include_bytes!("../assets/noto-sans-definefont3.bin");
74+
pub const FALLBACK_DEVICE_FONT: &[u8] = include_bytes!("../assets/notosans-regular.subset.ttf.gz");
7575

7676
#[derive(Collect)]
7777
#[collect(no_drop)]
@@ -2907,12 +2907,23 @@ impl PlayerBuilder {
29072907

29082908
#[cfg(feature = "default_font")]
29092909
{
2910-
let mut font_reader = swf::read::Reader::new(FALLBACK_DEVICE_FONT_TAG, 8);
2911-
let font_tag = font_reader
2912-
.read_define_font_2(3)
2913-
.expect("Built-in font should compile");
2914-
player_lock
2915-
.register_device_font(FontDefinition::SwfTag(font_tag, font_reader.encoding()));
2910+
use flate2::read::DeflateDecoder;
2911+
use std::io::Read;
2912+
2913+
let mut data = Vec::new();
2914+
let mut decoder = DeflateDecoder::new(FALLBACK_DEVICE_FONT);
2915+
decoder
2916+
.read_to_end(&mut data)
2917+
.expect("default font decompression must succeed");
2918+
2919+
player_lock.register_device_font(FontDefinition::FontFile {
2920+
name: "Noto Sans".into(),
2921+
is_bold: false,
2922+
is_italic: false,
2923+
data,
2924+
index: 0,
2925+
});
2926+
29162927
player_lock.set_default_font(DefaultFont::Sans, vec!["Noto Sans".to_string()]);
29172928
player_lock.set_default_font(DefaultFont::Serif, vec!["Noto Sans".to_string()]);
29182929
player_lock.set_default_font(DefaultFont::Typewriter, vec!["Noto Sans".to_string()]);

0 commit comments

Comments
 (0)