mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
fonts: Instantiate system fonts using system font loaders (#33747)
System fonts used to be instantiated using the system font loader and this change restores that behavior. In addition, on macOS and FreeType platforms font data for system fonts is loaded using memory mapping. The benefit is that system font loaders typically are able to cache fonts in system memory (using memory mapping, for instance) and we'd like to load them in a the way most compatible with other applications. On my Linux system, this manages to get the overhead of loading a very large font down from 10ms to approximately 1ms. Subsequent runs show even less overhead. We've measured similar gains on macOS systems. Currently, system font data must be loaded into memory manually for canvas and this is unlikely to change even with a switch to `vello`. The use of explicit memmory mapping should help in this case -- though it probably won't be possible to use this properly on macOS and Windows if we ever want to load fonts from TTCs properly. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
parent
4564ce2fcc
commit
0553789d48
24 changed files with 771 additions and 810 deletions
|
@ -14,15 +14,41 @@ pub mod platform;
|
|||
mod shaper;
|
||||
mod system_font_service;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use font::*;
|
||||
pub use font_context::*;
|
||||
pub use font_store::*;
|
||||
pub use font_template::*;
|
||||
pub use glyph::*;
|
||||
use ipc_channel::ipc::IpcSharedMemory;
|
||||
pub use platform::LocalFontIdentifier;
|
||||
pub use shaper::*;
|
||||
pub use system_font_service::*;
|
||||
use unicode_properties::{emoji, EmojiStatus, UnicodeEmoji};
|
||||
|
||||
/// A data structure to store data for fonts. Data is stored internally in an
|
||||
/// [`IpcSharedMemory`] handle, so that it can be send without serialization
|
||||
/// across IPC channels.
|
||||
#[derive(Clone)]
|
||||
pub struct FontData(pub(crate) Arc<IpcSharedMemory>);
|
||||
|
||||
impl FontData {
|
||||
pub fn from_bytes(bytes: &[u8]) -> Self {
|
||||
Self(Arc::new(IpcSharedMemory::from_bytes(bytes)))
|
||||
}
|
||||
|
||||
pub(crate) fn as_ipc_shared_memory(&self) -> Arc<IpcSharedMemory> {
|
||||
self.0.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for FontData {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
&**self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether or not font fallback selection prefers the emoji or text representation
|
||||
/// of a character. If `None` then either presentation is acceptable.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue