diff options
| author | 2020-05-29 02:13:26 +0200 | |
|---|---|---|
| committer | 2020-05-29 02:13:26 +0200 | |
| commit | 8a864fcce9b974c84389a27a4cb2b3242a930750 (patch) | |
| tree | 56920437979012cceb49718f2dd4ce27d5ba5d40 /wgpu/src | |
| parent | e11b5c614f5bf73c137b8b4f24f56047617527eb (diff) | |
| parent | 0cde20b3550ede81bc7ddef628b91eec225aa8af (diff) | |
| download | iced-8a864fcce9b974c84389a27a4cb2b3242a930750.tar.gz iced-8a864fcce9b974c84389a27a4cb2b3242a930750.tar.bz2 iced-8a864fcce9b974c84389a27a4cb2b3242a930750.zip | |
Merge pull request #359 from hecrj/improvement/update-wgpu_glyph
Update `wgpu_glyph` and `glyph_brush`
Diffstat (limited to '')
| -rw-r--r-- | wgpu/src/backend.rs | 19 | ||||
| -rw-r--r-- | wgpu/src/text.rs | 58 | 
2 files changed, 42 insertions, 35 deletions
| diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 88529ddd..29fc8677 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -159,7 +159,6 @@ impl Backend {              for text in layer.text.iter() {                  // Target physical coordinates directly to avoid blurry text                  let text = wgpu_glyph::Section { -                    text: text.content,                      // TODO: We `round` here to avoid rerasterizing text when                      // its position changes slightly. This can make text feel a                      // bit "jumpy". We may be able to do better once we improve @@ -181,12 +180,18 @@ impl Backend {                          (text.bounds.width * scale_factor).ceil(),                          (text.bounds.height * scale_factor).ceil(),                      ), -                    scale: wgpu_glyph::Scale { -                        x: text.size * scale_factor, -                        y: text.size * scale_factor, -                    }, -                    color: text.color, -                    font_id: self.text_pipeline.find_font(text.font), +                    text: vec![wgpu_glyph::Text { +                        text: text.content, +                        scale: wgpu_glyph::ab_glyph::PxScale { +                            x: text.size * scale_factor, +                            y: text.size * scale_factor, +                        }, +                        font_id: self.text_pipeline.find_font(text.font), +                        extra: wgpu_glyph::Extra { +                            color: text.color, +                            z: 0.0, +                        }, +                    }],                      layout: wgpu_glyph::Layout::default()                          .h_align(match text.horizontal_alignment {                              HorizontalAlignment::Left => { diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index d65c0385..5ee7b856 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -1,12 +1,13 @@  use crate::Transformation;  use iced_graphics::font;  use std::{cell::RefCell, collections::HashMap}; +use wgpu_glyph::ab_glyph;  #[derive(Debug)]  pub struct Pipeline { -    draw_brush: RefCell<wgpu_glyph::GlyphBrush<'static, ()>>, +    draw_brush: RefCell<wgpu_glyph::GlyphBrush<()>>,      draw_font_map: RefCell<HashMap<String, wgpu_glyph::FontId>>, -    measure_brush: RefCell<glyph_brush::GlyphBrush<'static, ()>>, +    measure_brush: RefCell<glyph_brush::GlyphBrush<()>>,  }  impl Pipeline { @@ -25,28 +26,25 @@ impl Pipeline {                      .unwrap_or_else(|_| font::FALLBACK.to_vec())              }); -        let load_glyph_brush = |font: Vec<u8>| { -            let builder = -                wgpu_glyph::GlyphBrushBuilder::using_fonts_bytes(vec![ -                    font.clone() -                ])?; +        let font = ab_glyph::FontArc::try_from_vec(default_font) +            .unwrap_or_else(|_| { +                log::warn!( +                    "System font failed to load. Falling back to \ +                    embedded font..." +                ); -            Ok(( -                builder, -                glyph_brush::GlyphBrushBuilder::using_font_bytes(font).build(), -            )) -        }; - -        let (brush_builder, measure_brush) = load_glyph_brush(default_font) -            .unwrap_or_else(|_: wgpu_glyph::rusttype::Error| { -                log::warn!("System font failed to load. Falling back to embedded font..."); - -                load_glyph_brush(font::FALLBACK.to_vec()).expect("Load fallback font") +                ab_glyph::FontArc::try_from_slice(font::FALLBACK) +                    .expect("Load fallback font")              }); -        let draw_brush = brush_builder -            .initial_cache_size((2048, 2048)) -            .build(device, format); +        let draw_brush = +            wgpu_glyph::GlyphBrushBuilder::using_font(font.clone()) +                .initial_cache_size((2048, 2048)) +                .draw_cache_multithread(false) // TODO: Expose as a configuration flag +                .build(device, format); + +        let measure_brush = +            glyph_brush::GlyphBrushBuilder::using_font(font).build();          Pipeline {              draw_brush: RefCell::new(draw_brush), @@ -91,10 +89,13 @@ impl Pipeline {          let wgpu_glyph::FontId(font_id) = self.find_font(font);          let section = wgpu_glyph::Section { -            text: content, -            scale: wgpu_glyph::Scale { x: size, y: size },              bounds: (bounds.width, bounds.height), -            font_id: wgpu_glyph::FontId(font_id), +            text: vec![wgpu_glyph::Text { +                text: content, +                scale: size.into(), +                font_id: wgpu_glyph::FontId(font_id), +                extra: wgpu_glyph::Extra::default(), +            }],              ..Default::default()          }; @@ -139,11 +140,12 @@ impl Pipeline {                      return *font_id;                  } -                // TODO: Find a way to share font data -                let _ = self.measure_brush.borrow_mut().add_font_bytes(bytes); +                let font = ab_glyph::FontArc::try_from_slice(bytes) +                    .expect("Load font"); + +                let _ = self.measure_brush.borrow_mut().add_font(font.clone()); -                let font_id = -                    self.draw_brush.borrow_mut().add_font_bytes(bytes); +                let font_id = self.draw_brush.borrow_mut().add_font(font);                  let _ = self                      .draw_font_map | 
