Update cosmic-text and resvg (#2416)

* Update `cosmic-text`, `glyphon`, and `resvg`

* Fix slow font fallback with `Shaping::Basic` in `cosmic-text`

* Update `cosmic-text` and `resvg`

* Update `cosmic-text`

* Fix `SelectAll` action in `editor`

* Fix some panics in `graphics::text::editor`

* Remove empty `if` statement in `tiny_skia::vector`

* Update `cosmic-text`, `glyphon`, and `rustc-hash`
This commit is contained in:
Héctor Ramón 2024-07-17 13:00:00 +02:00 committed by GitHub
parent b518e30610
commit 616689ca54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 187 additions and 222 deletions

View file

@ -439,9 +439,13 @@ impl Engine {
let transformation = transformation * *local_transformation;
let (width, height) = buffer.size();
let physical_bounds =
Rectangle::new(raw.position, Size::new(width, height))
* transformation;
let physical_bounds = Rectangle::new(
raw.position,
Size::new(
width.unwrap_or(clip_bounds.width),
height.unwrap_or(clip_bounds.height),
),
) * transformation;
if !clip_bounds.intersects(&physical_bounds) {
return;

View file

@ -169,7 +169,13 @@ impl Pipeline {
font_system.raw(),
&mut self.glyph_cache,
buffer,
Rectangle::new(position, Size::new(width, height)),
Rectangle::new(
position,
Size::new(
width.unwrap_or(pixels.width() as f32),
height.unwrap_or(pixels.height() as f32),
),
),
color,
alignment::Horizontal::Left,
alignment::Vertical::Top,

View file

@ -1,8 +1,7 @@
use crate::core::svg::{Data, Handle};
use crate::core::{Color, Rectangle, Size};
use crate::graphics::text;
use resvg::usvg::{self, TreeTextToPath};
use resvg::usvg;
use rustc_hash::{FxHashMap, FxHashSet};
use tiny_skia::Transform;
@ -80,35 +79,28 @@ struct RasterKey {
impl Cache {
fn load(&mut self, handle: &Handle) -> Option<&usvg::Tree> {
use usvg::TreeParsing;
let id = handle.id();
if let hash_map::Entry::Vacant(entry) = self.trees.entry(id) {
let mut svg = match handle.data() {
let svg = match handle.data() {
Data::Path(path) => {
fs::read_to_string(path).ok().and_then(|contents| {
usvg::Tree::from_str(
&contents,
&usvg::Options::default(),
&usvg::Options::default(), // TODO: Set usvg::Options::fontdb
)
.ok()
})
}
Data::Bytes(bytes) => {
usvg::Tree::from_data(bytes, &usvg::Options::default()).ok()
usvg::Tree::from_data(
bytes,
&usvg::Options::default(), // TODO: Set usvg::Options::fontdb
)
.ok()
}
};
if let Some(svg) = &mut svg {
if svg.has_text_nodes() {
let mut font_system =
text::font_system().write().expect("Write font system");
svg.convert_text(font_system.raw().db_mut());
}
}
let _ = entry.insert(svg);
}
@ -118,11 +110,9 @@ impl Cache {
fn viewport_dimensions(&mut self, handle: &Handle) -> Option<Size<u32>> {
let tree = self.load(handle)?;
let size = tree.size();
Some(Size::new(
tree.size.width() as u32,
tree.size.height() as u32,
))
Some(Size::new(size.width() as u32, size.height() as u32))
}
fn draw(
@ -147,7 +137,7 @@ impl Cache {
let mut image = tiny_skia::Pixmap::new(size.width, size.height)?;
let tree_size = tree.size.to_int_size();
let tree_size = tree.size().to_int_size();
let target_size = if size.width > size.height {
tree_size.scale_to_width(size.width)
@ -167,7 +157,7 @@ impl Cache {
tiny_skia::Transform::default()
};
resvg::Tree::from_usvg(tree).render(transform, &mut image.as_mut());
resvg::render(tree, transform, &mut image.as_mut());
if let Some([r, g, b, _]) = key.color {
// Apply color filter