mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
More font handling cleanup
Group all fields we need to determine a physical font into one FontRequest structure and use that throughout. That way adding more fields will require less changes.
This commit is contained in:
parent
05204a3185
commit
f0289192b7
5 changed files with 42 additions and 63 deletions
|
@ -12,9 +12,7 @@ use super::texture::{AtlasAllocation, TextureAtlas};
|
|||
use super::Vertex;
|
||||
use collections::hash_map::HashMap;
|
||||
use itertools::Itertools;
|
||||
use sixtyfps_corelib::font::Font;
|
||||
use sixtyfps_corelib::font::FontHandle;
|
||||
use sixtyfps_corelib::SharedString;
|
||||
use sixtyfps_corelib::font::{Font, FontHandle, FontRequest};
|
||||
use std::cell::RefCell;
|
||||
use std::{collections, rc::Rc};
|
||||
|
||||
|
@ -28,13 +26,8 @@ pub(crate) struct GlyphCache {
|
|||
}
|
||||
|
||||
impl GlyphCache {
|
||||
pub fn find_font(
|
||||
&self,
|
||||
font_family: &SharedString,
|
||||
pixel_size: f32,
|
||||
) -> Rc<RefCell<CachedFontGlyphs>> {
|
||||
let font =
|
||||
sixtyfps_corelib::font::FONT_CACHE.with(|fc| fc.find_font(font_family, pixel_size));
|
||||
pub fn find_font(&self, request: &FontRequest) -> Rc<RefCell<CachedFontGlyphs>> {
|
||||
let font = sixtyfps_corelib::font::FONT_CACHE.with(|fc| fc.find_font(request));
|
||||
|
||||
let font_handle = font.handle();
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ use lyon::tessellation::{
|
|||
FillAttributes, FillOptions, FillTessellator, StrokeAttributes, StrokeOptions,
|
||||
StrokeTessellator,
|
||||
};
|
||||
use sixtyfps_corelib::{eventloop::ComponentWindow, SharedString};
|
||||
use sixtyfps_corelib::{eventloop::ComponentWindow, font::FontRequest};
|
||||
use sixtyfps_corelib::{
|
||||
graphics::{
|
||||
Color, Frame as GraphicsFrame, GraphicsBackend, GraphicsWindow,
|
||||
|
@ -532,8 +532,8 @@ impl RenderingPrimitivesBuilder for GLRenderingPrimitivesBuilder {
|
|||
Resource::None => SmallVec::new(),
|
||||
}
|
||||
}
|
||||
HighLevelRenderingPrimitive::Text { text, font_family, font_size } => {
|
||||
smallvec![self.create_glyph_runs(text, font_family, *font_size)]
|
||||
HighLevelRenderingPrimitive::Text { text, font_request } => {
|
||||
smallvec![self.create_glyph_runs(text, font_request)]
|
||||
}
|
||||
HighLevelRenderingPrimitive::Path { width, height, elements, stroke_width } => {
|
||||
let mut primitives = SmallVec::new();
|
||||
|
@ -725,10 +725,9 @@ impl GLRenderingPrimitivesBuilder {
|
|||
fn create_glyph_runs(
|
||||
&mut self,
|
||||
text: &str,
|
||||
font_family: &SharedString,
|
||||
pixel_size: f32,
|
||||
font_request: &FontRequest,
|
||||
) -> GLRenderingPrimitive {
|
||||
let cached_glyphs = self.platform_data.glyph_cache.find_font(font_family, pixel_size);
|
||||
let cached_glyphs = self.platform_data.glyph_cache.find_font(font_request);
|
||||
let mut cached_glyphs = cached_glyphs.borrow_mut();
|
||||
let mut atlas = self.texture_atlas.borrow_mut();
|
||||
let glyphs_runs = cached_glyphs.render_glyphs(&self.context, &mut atlas, text);
|
||||
|
@ -739,11 +738,9 @@ impl GLRenderingPrimitivesBuilder {
|
|||
fn create_glyph_runs(
|
||||
&mut self,
|
||||
text: &str,
|
||||
font_family: &SharedString,
|
||||
pixel_size: f32,
|
||||
font_request: &FontRequest,
|
||||
) -> GLRenderingPrimitive {
|
||||
let font =
|
||||
sixtyfps_corelib::font::FONT_CACHE.with(|fc| fc.find_font(font_family, pixel_size));
|
||||
let font = sixtyfps_corelib::font::FONT_CACHE.with(|fc| fc.find_font(font_request));
|
||||
let text_canvas = font.render_text(text);
|
||||
|
||||
let texture = Rc::new(GLTexture::new_from_canvas(&self.context, &text_canvas));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue