mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 12:31:37 +02:00
🎉 Swap default font for source sans (wasm)
This commit is contained in:
parent
2470c1788e
commit
90cb0357c6
6 changed files with 34 additions and 15 deletions
|
@ -253,7 +253,6 @@
|
|||
|
||||
(defn get-variant
|
||||
[{:keys [variants] :as font} font-variant-id]
|
||||
(prn "get-variant" font-variant-id fonts)
|
||||
(or (d/seek #(= (:id %) font-variant-id) variants)
|
||||
(get-default-variant font)))
|
||||
|
||||
|
|
Binary file not shown.
BIN
render-wasm/src/fonts/sourcesanspro-regular.ttf
Normal file
BIN
render-wasm/src/fonts/sourcesanspro-regular.ttf
Normal file
Binary file not shown.
|
@ -1,12 +1,22 @@
|
|||
use skia_safe::{self as skia, textlayout, Font, FontMgr};
|
||||
|
||||
use crate::shapes::FontFamily;
|
||||
use crate::shapes::{FontFamily, FontStyle};
|
||||
use crate::uuid::Uuid;
|
||||
|
||||
const DEFAULT_FONT_BYTES: &[u8] = include_bytes!("../fonts/RobotoMono-Regular.ttf");
|
||||
const EMOJI_FONT_BYTES: &[u8] = include_bytes!("../fonts/NotoColorEmoji-Regular.ttf");
|
||||
pub static DEFAULT_FONT: &'static str = "robotomono-regular";
|
||||
pub static DEFAULT_EMOJI_FONT: &'static str = "noto-color-emoji";
|
||||
|
||||
const DEFAULT_FONT_BYTES: &[u8] = include_bytes!("../fonts/sourcesanspro-regular.ttf");
|
||||
|
||||
pub fn default_font() -> String {
|
||||
let family = FontFamily::new(default_font_uuid(), 400, FontStyle::Normal);
|
||||
format!("{}", family)
|
||||
}
|
||||
|
||||
fn default_font_uuid() -> Uuid {
|
||||
Uuid::nil()
|
||||
}
|
||||
|
||||
pub struct FontStore {
|
||||
font_mgr: FontMgr,
|
||||
font_provider: textlayout::TypefaceFontProvider,
|
||||
|
@ -18,25 +28,19 @@ impl FontStore {
|
|||
pub fn new() -> Self {
|
||||
let font_mgr = FontMgr::new();
|
||||
|
||||
let mut font_provider = skia::textlayout::TypefaceFontProvider::new();
|
||||
|
||||
let default_font = font_mgr
|
||||
.new_from_data(DEFAULT_FONT_BYTES, None)
|
||||
.expect("Failed to load font");
|
||||
|
||||
font_provider.register_typeface(default_font, DEFAULT_FONT);
|
||||
let mut font_provider = load_default_provider(&font_mgr);
|
||||
|
||||
// TODO: Load emoji font lazily
|
||||
let emoji_font = font_mgr
|
||||
.new_from_data(EMOJI_FONT_BYTES, None)
|
||||
.expect("Failed to load font");
|
||||
|
||||
font_provider.register_typeface(emoji_font, DEFAULT_EMOJI_FONT);
|
||||
|
||||
let mut font_collection = skia::textlayout::FontCollection::new();
|
||||
font_collection.set_default_font_manager(FontMgr::from(font_provider.clone()), None);
|
||||
|
||||
let debug_typeface = font_provider
|
||||
.match_family_style("robotomono-regular", skia::FontStyle::default())
|
||||
.match_family_style(default_font().as_str(), skia::FontStyle::default())
|
||||
.unwrap();
|
||||
|
||||
let debug_font = skia::Font::new(debug_typeface, 10.0);
|
||||
|
@ -85,3 +89,15 @@ impl FontStore {
|
|||
self.font_provider.family_names().any(|x| x == serialized)
|
||||
}
|
||||
}
|
||||
|
||||
fn load_default_provider(font_mgr: &FontMgr) -> skia::textlayout::TypefaceFontProvider {
|
||||
let mut font_provider = skia::textlayout::TypefaceFontProvider::new();
|
||||
|
||||
let family = FontFamily::new(default_font_uuid(), 400, FontStyle::Normal);
|
||||
let font = font_mgr
|
||||
.new_from_data(DEFAULT_FONT_BYTES, None)
|
||||
.expect("Failed to load font");
|
||||
font_provider.register_typeface(font, family.alias().as_str());
|
||||
|
||||
font_provider
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ impl FontFamily {
|
|||
pub fn new(id: Uuid, weight: u32, style: FontStyle) -> Self {
|
||||
Self { id, style, weight }
|
||||
}
|
||||
|
||||
pub fn alias(&self) -> String {
|
||||
format!("{}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FontFamily {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
math::Rect,
|
||||
render::{DEFAULT_EMOJI_FONT, DEFAULT_FONT},
|
||||
render::{default_font, DEFAULT_EMOJI_FONT},
|
||||
};
|
||||
use skia_safe::{
|
||||
self as skia,
|
||||
|
@ -133,7 +133,7 @@ impl TextLeaf {
|
|||
style.set_font_size(self.font_size);
|
||||
style.set_font_families(&[
|
||||
self.serialized_font_family(),
|
||||
DEFAULT_FONT.to_string(),
|
||||
default_font(),
|
||||
DEFAULT_EMOJI_FONT.to_string(),
|
||||
]);
|
||||
style
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue