diff options
| author | 2023-06-20 06:22:17 +0200 | |
|---|---|---|
| committer | 2023-06-20 06:50:36 +0200 | |
| commit | 5bc7cbf5bca039ec3a4cbe82b161c087a4b39680 (patch) | |
| tree | dff3ec9474b4d598f73e1989681d362fd646cc2e /wgpu/src | |
| parent | 8ae4e28013ac2b4ae1c0a6d3b0672b59692e45d1 (diff) | |
| download | iced-5bc7cbf5bca039ec3a4cbe82b161c087a4b39680.tar.gz iced-5bc7cbf5bca039ec3a4cbe82b161c087a4b39680.tar.bz2 iced-5bc7cbf5bca039ec3a4cbe82b161c087a4b39680.zip | |
Use subpixel glyph positioning and layout linearity
... for offsetting and scaling text
Diffstat (limited to '')
| -rw-r--r-- | wgpu/src/backend.rs | 6 | ||||
| -rw-r--r-- | wgpu/src/text.rs | 43 | 
2 files changed, 18 insertions, 31 deletions
| diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index b524c615..eecba2f1 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -334,12 +334,6 @@ impl Backend {      }  } -impl iced_graphics::Backend for Backend { -    fn trim_measurements(&mut self) { -        self.text_pipeline.trim_measurement_cache() -    } -} -  impl backend::Text for Backend {      const ICON_FONT: Font = Font::with_name("Iced-Icons");      const CHECKMARK_ICON: char = '\u{f00c}'; diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 6a552270..71dcc249 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -18,8 +18,7 @@ pub struct Pipeline {      renderers: Vec<glyphon::TextRenderer>,      atlas: glyphon::TextAtlas,      prepare_layer: usize, -    measurement_cache: RefCell<Cache>, -    render_cache: Cache, +    cache: RefCell<Cache>,  }  impl Pipeline { @@ -47,8 +46,7 @@ impl Pipeline {                  },              ),              prepare_layer: 0, -            measurement_cache: RefCell::new(Cache::new()), -            render_cache: Cache::new(), +            cache: RefCell::new(Cache::new()),          }      } @@ -78,25 +76,25 @@ impl Pipeline {          let font_system = self.font_system.get_mut();          let renderer = &mut self.renderers[self.prepare_layer]; +        let cache = self.cache.get_mut();          let keys: Vec<_> = sections              .iter()              .map(|section| { -                let (key, _) = self.render_cache.allocate( +                let (key, _) = cache.allocate(                      font_system,                      Key {                          content: section.content, -                        size: section.size * scale_factor, +                        size: section.size,                          line_height: f32::from(                              section                                  .line_height                                  .to_absolute(Pixels(section.size)), -                        ) * scale_factor, +                        ),                          font: section.font,                          bounds: Size { -                            width: (section.bounds.width * scale_factor).ceil(), -                            height: (section.bounds.height * scale_factor) -                                .ceil(), +                            width: section.bounds.width, +                            height: section.bounds.height,                          },                          shaping: section.shaping,                      }, @@ -113,14 +111,16 @@ impl Pipeline {                  .iter()                  .zip(keys.iter())                  .filter_map(|(section, key)| { -                    let buffer = -                        self.render_cache.get(key).expect("Get cached buffer"); - -                    let (max_width, total_height) = measure(buffer); +                    let buffer = cache.get(key).expect("Get cached buffer");                      let x = section.bounds.x * scale_factor;                      let y = section.bounds.y * scale_factor; +                    let (max_width, total_height) = measure(buffer); + +                    let max_width = max_width * scale_factor; +                    let total_height = total_height * scale_factor; +                      let left = match section.horizontal_alignment {                          alignment::Horizontal::Left => x,                          alignment::Horizontal::Center => x - max_width / 2.0, @@ -142,14 +142,11 @@ impl Pipeline {                      let clip_bounds = bounds.intersection(§ion_bounds)?; -                    // TODO: Subpixel glyph positioning -                    let left = left.round() as i32; -                    let top = top.round() as i32; -                      Some(glyphon::TextArea {                          buffer,                          left,                          top, +                        scale: scale_factor,                          bounds: glyphon::TextBounds {                              left: clip_bounds.x as i32,                              top: clip_bounds.y as i32, @@ -227,7 +224,7 @@ impl Pipeline {      pub fn end_frame(&mut self) {          self.atlas.trim(); -        self.render_cache.trim(); +        self.cache.get_mut().trim();          self.prepare_layer = 0;      } @@ -241,7 +238,7 @@ impl Pipeline {          bounds: Size,          shaping: Shaping,      ) -> (f32, f32) { -        let mut measurement_cache = self.measurement_cache.borrow_mut(); +        let mut measurement_cache = self.cache.borrow_mut();          let line_height = f32::from(line_height.to_absolute(Pixels(size))); @@ -271,7 +268,7 @@ impl Pipeline {          point: Point,          _nearest_only: bool,      ) -> Option<Hit> { -        let mut measurement_cache = self.measurement_cache.borrow_mut(); +        let mut measurement_cache = self.cache.borrow_mut();          let line_height = f32::from(line_height.to_absolute(Pixels(size))); @@ -291,10 +288,6 @@ impl Pipeline {          Some(Hit::CharOffset(cursor.index))      } - -    pub fn trim_measurement_cache(&mut self) { -        self.measurement_cache.borrow_mut().trim(); -    }  }  fn measure(buffer: &glyphon::Buffer) -> (f32, f32) { | 
