use super::*;
impl Default for NativeSystemFont {
fn default() -> Self {
Self::deterministic()
}
}
impl NativeSystemFont {
#[must_use]
pub fn system() -> Self {
Self {
info: probe_system_font(),
deterministic_only: false,
}
}
#[must_use]
pub fn deterministic() -> Self {
Self {
info: SystemFontInfo::new(
FontRenderBackend::DeterministicBitmap,
FONT_FAMILY_DETERMINISTIC.to_string(),
true,
false,
),
deterministic_only: true,
}
}
#[must_use]
pub fn thread_fallback_font_loads() -> usize {
THREAD_FALLBACK_FONT_LOADS.with(Cell::get)
}
}
impl SystemFontProvider for NativeSystemFont {
fn font_info(&self) -> SystemFontInfo {
self.get_info().clone()
}
fn rasterize(&self, key: GlyphKey) -> Option<RasterizedGlyph> {
if !self.get_deterministic_only()
&& let Some(native_glyph) = rasterize_native_glyph(key)
{
return Some(native_glyph);
}
Some(rasterize_glyph(key))
}
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
impl CoreTextFontCache {
#[must_use]
pub(crate) const fn new() -> Self {
Self {
gray_space: null_mut(),
scratch_ctx: null_mut(),
scratch_buf: Vec::new(),
scratch_w: 0,
scratch_h: 0,
fonts: Vec::new(),
}
}
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
impl Drop for CoreTextFontCache {
fn drop(&mut self) {
let Self {
gray_space,
scratch_ctx,
fonts,
..
} = self;
release_coretext_cache(*gray_space, *scratch_ctx, fonts);
*scratch_ctx = null_mut();
*gray_space = null_mut();
}
}
#[cfg(any(target_os = "linux", target_os = "android"))]
impl FtLazyFace {
#[must_use]
pub(crate) const fn unprobed() -> Self {
Self {
probed: false,
face: null_mut(),
last_size_px: 0,
}
}
#[must_use]
pub(crate) const fn loaded(face: *mut FtFaceRec) -> Self {
Self {
probed: true,
face,
last_size_px: 0,
}
}
}
#[cfg(target_arch = "wasm32")]
impl WebFontScratch {
#[must_use]
pub(crate) const fn new() -> Self {
Self {
canvas: None,
ctx2d: None,
width: 0,
height: 0,
last_font: String::new(),
}
}
}
#[cfg(target_os = "windows")]
impl Win32FontCache {
#[must_use]
pub(crate) const fn new() -> Self {
Self {
hdc: null_mut(),
fonts: Vec::new(),
raw_buf: Vec::new(),
}
}
}
#[cfg(target_os = "windows")]
impl Drop for Win32FontCache {
fn drop(&mut self) {
let Self { hdc, fonts, .. } = self;
release_win32_cache(*hdc, fonts);
*hdc = null_mut();
}
}