Skip to content

Commit

Permalink
Merge pull request #562 from ratmice/update_svg_kurbo
Browse files Browse the repository at this point in the history
Update kurbo and svg dependencies, fix a clippy warning.
  • Loading branch information
ratmice authored Dec 29, 2023
2 parents 88e8e6c + 9e127c0 commit e78a787
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
10 changes: 5 additions & 5 deletions piet-coregraphics/src/text.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Text related stuff for the coregraphics backend

use std::cell::RefCell;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::ops::{DerefMut, Range, RangeBounds};
use std::rc::Rc;
use std::sync::{Arc, Mutex};

use associative_cache::{AssociativeCache, Capacity64, HashFourWay, RoundRobinReplacement};
use core_foundation::base::TCFType;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub struct CoreGraphicsText {
/// like caching fonts.
#[derive(Clone)]
struct SharedTextState {
inner: Arc<Mutex<TextState>>,
inner: Rc<RefCell<TextState>>,
}

type Cache<K, V> = AssociativeCache<K, V, Capacity64, HashFourWay, RoundRobinReplacement>;
Expand Down Expand Up @@ -468,7 +468,7 @@ impl CoreGraphicsText {
/// In general this should be created once and then cloned and passed around.
pub fn new_with_unique_state() -> CoreGraphicsText {
let collection = FontCollection::new_with_all_fonts();
let inner = Arc::new(Mutex::new(TextState {
let inner = Rc::new(RefCell::new(TextState {
collection,
family_cache: Default::default(),
font_cache: Default::default(),
Expand Down Expand Up @@ -509,7 +509,7 @@ impl SharedTextState {
///
/// This hits a cache before doing a lookup with the system.
fn get_font_family(&self, family_name: &str) -> Option<FontFamily> {
let mut inner = self.inner.lock().unwrap();
let mut inner = self.inner.borrow_mut();
let obj = inner.deref_mut();
let family_cache = &mut obj.family_cache;
let collection = &mut obj.collection;
Expand All @@ -526,7 +526,7 @@ impl SharedTextState {
///
/// This hits a cache before creating the CTFont.
fn get_ct_font(&self, key: &CoreTextFontKey) -> CTFont {
let mut inner = self.inner.lock().unwrap();
let mut inner = self.inner.borrow_mut();
inner
.font_cache
.entry(key)
Expand Down
1 change: 0 additions & 1 deletion piet-direct2d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ impl<'a> D2DRenderContext<'a> {
return;
}
};
let width = width;
self.rt.draw_geometry(&geom, &brush, width, style);
}

Expand Down
2 changes: 1 addition & 1 deletion piet-svg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ font-kit = "0.10.1"
image = { version = "0.24.5", default-features = false, features = ["png"] }
piet = { version = "=0.6.2", path = "../piet" }
rustybuzz = "0.4.0"
svg = "0.10.0"
svg = "0.13.1"

[dev-dependencies]
piet = { version = "=0.6.2", path = "../piet", features = ["samples"] }
18 changes: 8 additions & 10 deletions piet-svg/src/text.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Text functionality for Piet svg backend

use std::{
cell::RefCell,
collections::HashSet,
fs, io,
ops::RangeBounds,
rc::Rc,
sync::{Arc, Mutex},
};

Expand All @@ -24,7 +26,7 @@ type Result<T> = std::result::Result<T, Error>;
/// SVG text (partially implemented)
#[derive(Clone)]
pub struct Text {
source: Arc<Mutex<MultiSource>>,
source: Rc<RefCell<MultiSource>>,
/// Fonts we have seen this frame, and so need to embed in the SVG.
///
/// We only include named font families - system defaults like SANS_SERIF are assumed to be
Expand All @@ -36,7 +38,7 @@ impl Text {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Text {
source: Arc::new(Mutex::new(MultiSource::from_sources(vec![
source: Rc::new(RefCell::new(MultiSource::from_sources(vec![
Box::new(SystemSource::new()),
Box::new(MemSource::empty()),
]))),
Expand All @@ -47,8 +49,7 @@ impl Text {
pub(crate) fn font_data(&self, face: &FontFace) -> Result<Arc<Vec<u8>>> {
let handle = self
.source
.lock()
.unwrap()
.borrow()
.select_best_match(&[face.to_fk_family()], &face.to_props())
.map_err(|_| Error::FontLoadingFailed)?;
load_font_data(handle).map_err(|_| Error::FontLoadingFailed)
Expand All @@ -64,8 +65,7 @@ impl piet::Text for Text {

if self
.source
.lock()
.unwrap()
.borrow()
.select_best_match(&[FamilyName::Title(family_name.into())], &Properties::new())
.is_ok()
{
Expand All @@ -76,7 +76,7 @@ impl piet::Text for Text {
}

fn load_font(&mut self, data: &[u8]) -> Result<FontFamily> {
let mut multi_source = self.source.lock().unwrap();
let mut multi_source = self.source.borrow_mut();
let source = multi_source
.find_source_mut::<MemSource>()
.expect("mem source");
Expand Down Expand Up @@ -189,9 +189,7 @@ impl TextLayout {
/// will depend on available fonts, conformance of renderer, DPI, etc), but it is the best we
/// can do.
fn from_builder(builder: TextLayoutBuilder) -> Result<Self> {
let face_bytes = builder
.font_face
.load(&*builder.ctx.source.lock().unwrap())?;
let face_bytes = builder.font_face.load(&*builder.ctx.source.borrow())?;
let mut face = Face::from_slice(&face_bytes, 0).ok_or(Error::FontLoadingFailed)?;
// number of pixels in a point
// I think we're OK to assume 96 DPI, because the actual SVG renderer will scale for HIDPI
Expand Down
2 changes: 1 addition & 1 deletion piet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include = ["src/**/*", "Cargo.toml", "snapshots/resources/*"]

[dependencies]
image = { version = "0.24.5", optional = true, default-features = false }
kurbo = "0.9"
kurbo = "0.10.4"
pico-args = { version = "0.4.2", optional = true }
png = { version = "0.17.7", optional = true }
os_info = { version = "3.6.0", optional = true, default-features = false }
Expand Down

0 comments on commit e78a787

Please sign in to comment.