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:
parent
b518e30610
commit
616689ca54
10 changed files with 187 additions and 222 deletions
|
|
@ -1,10 +1,9 @@
|
|||
use crate::core::svg;
|
||||
use crate::core::{Color, Size};
|
||||
use crate::graphics::text;
|
||||
use crate::image::atlas::{self, Atlas};
|
||||
|
||||
use resvg::tiny_skia;
|
||||
use resvg::usvg::{self, TreeTextToPath};
|
||||
use resvg::usvg;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use std::fs;
|
||||
|
||||
|
|
@ -21,7 +20,7 @@ impl Svg {
|
|||
pub fn viewport_dimensions(&self) -> Size<u32> {
|
||||
match self {
|
||||
Svg::Loaded(tree) => {
|
||||
let size = tree.size;
|
||||
let size = tree.size();
|
||||
|
||||
Size::new(size.width() as u32, size.height() as u32)
|
||||
}
|
||||
|
|
@ -45,38 +44,33 @@ type ColorFilter = Option<[u8; 4]>;
|
|||
impl Cache {
|
||||
/// Load svg
|
||||
pub fn load(&mut self, handle: &svg::Handle) -> &Svg {
|
||||
use usvg::TreeParsing;
|
||||
|
||||
if self.svgs.contains_key(&handle.id()) {
|
||||
return self.svgs.get(&handle.id()).unwrap();
|
||||
}
|
||||
|
||||
let mut svg = match handle.data() {
|
||||
let svg = match handle.data() {
|
||||
svg::Data::Path(path) => fs::read_to_string(path)
|
||||
.ok()
|
||||
.and_then(|contents| {
|
||||
usvg::Tree::from_str(&contents, &usvg::Options::default())
|
||||
.ok()
|
||||
usvg::Tree::from_str(
|
||||
&contents,
|
||||
&usvg::Options::default(), // TODO: Set usvg::Options::fontdb
|
||||
)
|
||||
.ok()
|
||||
})
|
||||
.map(Svg::Loaded)
|
||||
.unwrap_or(Svg::NotFound),
|
||||
svg::Data::Bytes(bytes) => {
|
||||
match usvg::Tree::from_data(bytes, &usvg::Options::default()) {
|
||||
match usvg::Tree::from_data(
|
||||
bytes,
|
||||
&usvg::Options::default(), // TODO: Set usvg::Options::fontdb
|
||||
) {
|
||||
Ok(tree) => Svg::Loaded(tree),
|
||||
Err(_) => Svg::NotFound,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Svg::Loaded(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());
|
||||
}
|
||||
}
|
||||
|
||||
self.should_trim = true;
|
||||
|
||||
let _ = self.svgs.insert(handle.id(), svg);
|
||||
|
|
@ -127,7 +121,7 @@ impl Cache {
|
|||
// It would be cool to be able to smooth resize the `svg` example.
|
||||
let mut img = tiny_skia::Pixmap::new(width, height)?;
|
||||
|
||||
let tree_size = tree.size.to_int_size();
|
||||
let tree_size = tree.size().to_int_size();
|
||||
|
||||
let target_size = if width > height {
|
||||
tree_size.scale_to_width(width)
|
||||
|
|
@ -147,8 +141,7 @@ impl Cache {
|
|||
tiny_skia::Transform::default()
|
||||
};
|
||||
|
||||
resvg::Tree::from_usvg(tree)
|
||||
.render(transform, &mut img.as_mut());
|
||||
resvg::render(tree, transform, &mut img.as_mut());
|
||||
|
||||
let mut rgba = img.take();
|
||||
|
||||
|
|
|
|||
|
|
@ -585,7 +585,13 @@ fn prepare(
|
|||
|
||||
(
|
||||
buffer.as_ref(),
|
||||
Rectangle::new(raw.position, Size::new(width, height)),
|
||||
Rectangle::new(
|
||||
raw.position,
|
||||
Size::new(
|
||||
width.unwrap_or(layer_bounds.width),
|
||||
height.unwrap_or(layer_bounds.height),
|
||||
),
|
||||
),
|
||||
alignment::Horizontal::Left,
|
||||
alignment::Vertical::Top,
|
||||
raw.color,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue