add WguiFontSystem, remove FONT_SYSTEM singleton, custom fonts, add Light font weight
there are a few gzip-compressed ttf as for now, looks like variable fonts aren't parsed properly by cosmic_text. Not sure why. Also, we probably need to have a fallback for CJK characters in the future, or just fallback to the built-in ones in the OS.
This commit is contained in:
@@ -7,13 +7,14 @@ use vulkano::pipeline::graphics::viewport;
|
||||
|
||||
use crate::{
|
||||
drawing::{self},
|
||||
font_config,
|
||||
gfx::{WGfx, cmd::GfxCommandBuffer},
|
||||
};
|
||||
|
||||
use super::{
|
||||
rect::{RectPipeline, RectRenderer},
|
||||
text::{
|
||||
DEFAULT_METRICS, FONT_SYSTEM, SWASH_CACHE, TextArea, TextBounds,
|
||||
DEFAULT_METRICS, SWASH_CACHE, TextArea, TextBounds,
|
||||
text_atlas::{TextAtlas, TextPipeline},
|
||||
text_renderer::TextRenderer,
|
||||
},
|
||||
@@ -51,6 +52,7 @@ impl RendererPass<'_> {
|
||||
|
||||
fn submit(
|
||||
&mut self,
|
||||
font_system: &font_config::WguiFontSystem,
|
||||
gfx: &Arc<WGfx>,
|
||||
viewport: &mut Viewport,
|
||||
cmd_buf: &mut GfxCommandBuffer,
|
||||
@@ -90,7 +92,7 @@ impl RendererPass<'_> {
|
||||
self.rect_renderer.render(gfx, viewport, &vk_scissor, cmd_buf)?;
|
||||
|
||||
{
|
||||
let mut font_system = FONT_SYSTEM.lock();
|
||||
let mut font_system = font_system.system.lock();
|
||||
let mut swash_cache = SWASH_CACHE.lock();
|
||||
|
||||
self.text_renderer.prepare(
|
||||
@@ -217,6 +219,7 @@ impl Context {
|
||||
|
||||
pub fn draw(
|
||||
&mut self,
|
||||
font_system: &font_config::WguiFontSystem,
|
||||
shared: &mut SharedContext,
|
||||
cmd_buf: &mut GfxCommandBuffer,
|
||||
primitives: &[drawing::RenderPrimitive],
|
||||
@@ -302,7 +305,13 @@ impl Context {
|
||||
};
|
||||
|
||||
for mut pass in passes {
|
||||
pass.submit(&shared.gfx, &mut self.viewport, cmd_buf, &mut atlas.text_atlas)?;
|
||||
pass.submit(
|
||||
font_system,
|
||||
&shared.gfx,
|
||||
&mut self.viewport,
|
||||
cmd_buf,
|
||||
&mut atlas.text_atlas,
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
|
||||
@@ -13,7 +13,6 @@ use parking_lot::Mutex;
|
||||
|
||||
use crate::drawing::{self};
|
||||
|
||||
pub static FONT_SYSTEM: LazyLock<Mutex<FontSystem>> = LazyLock::new(|| Mutex::new(FontSystem::new()));
|
||||
pub static SWASH_CACHE: LazyLock<Mutex<SwashCache>> = LazyLock::new(|| Mutex::new(SwashCache::new()));
|
||||
|
||||
/// Used in case no `font_size` is defined
|
||||
@@ -102,6 +101,7 @@ impl From<FontStyle> for Style {
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub enum FontWeight {
|
||||
Light,
|
||||
#[default]
|
||||
Normal,
|
||||
Bold,
|
||||
@@ -110,6 +110,7 @@ pub enum FontWeight {
|
||||
impl From<FontWeight> for Weight {
|
||||
fn from(value: FontWeight) -> Self {
|
||||
match value {
|
||||
FontWeight::Light => Self::LIGHT,
|
||||
FontWeight::Normal => Self::NORMAL,
|
||||
FontWeight::Bold => Self::BOLD,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user