Skip to content

Commit 3cc2aa8

Browse files
authored
Fix text node thread locals not being updated (#3173)
1 parent 75ad8d4 commit 3cc2aa8

1 file changed

Lines changed: 26 additions & 27 deletions

File tree

node-graph/gcore/src/text/to_path.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -176,33 +176,32 @@ fn render_glyph_run(glyph_run: &GlyphRun<'_, ()>, path_builder: &mut PathBuilder
176176
}
177177

178178
fn layout_text(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingConfig) -> Option<Layout<()>> {
179-
let font_cx = FONT_CONTEXT.with(Clone::clone);
180-
let mut font_cx = font_cx.borrow_mut();
181-
let layout_cx = LAYOUT_CONTEXT.with(Clone::clone);
182-
let mut layout_cx = layout_cx.borrow_mut();
183-
184-
let font_family = font_data.and_then(|font_data| {
185-
font_cx
186-
.collection
187-
.register_fonts(font_data, None)
188-
.first()
189-
.and_then(|(family_id, _)| font_cx.collection.family_name(*family_id).map(String::from))
190-
})?;
191-
192-
const DISPLAY_SCALE: f32 = 1.;
193-
let mut builder = layout_cx.ranged_builder(&mut font_cx, str, DISPLAY_SCALE, false);
194-
195-
builder.push_default(StyleProperty::FontSize(typesetting.font_size as f32));
196-
builder.push_default(StyleProperty::LetterSpacing(typesetting.character_spacing as f32));
197-
builder.push_default(StyleProperty::FontStack(parley::FontStack::Single(parley::FontFamily::Named(std::borrow::Cow::Owned(font_family)))));
198-
builder.push_default(LineHeight::FontSizeRelative(typesetting.line_height_ratio as f32));
199-
200-
let mut layout: Layout<()> = builder.build(str);
201-
202-
layout.break_all_lines(typesetting.max_width.map(|mw| mw as f32));
203-
layout.align(typesetting.max_width.map(|max_w| max_w as f32), typesetting.align.into(), AlignmentOptions::default());
204-
205-
Some(layout)
179+
FONT_CONTEXT.with_borrow_mut(|mut font_cx| {
180+
LAYOUT_CONTEXT.with_borrow_mut(|layout_cx| {
181+
let font_family = font_data.and_then(|font_data| {
182+
font_cx
183+
.collection
184+
.register_fonts(font_data, None)
185+
.first()
186+
.and_then(|(family_id, _)| font_cx.collection.family_name(*family_id).map(String::from))
187+
})?;
188+
189+
const DISPLAY_SCALE: f32 = 1.;
190+
let mut builder = layout_cx.ranged_builder(&mut font_cx, str, DISPLAY_SCALE, false);
191+
192+
builder.push_default(StyleProperty::FontSize(typesetting.font_size as f32));
193+
builder.push_default(StyleProperty::LetterSpacing(typesetting.character_spacing as f32));
194+
builder.push_default(StyleProperty::FontStack(parley::FontStack::Single(parley::FontFamily::Named(std::borrow::Cow::Owned(font_family)))));
195+
builder.push_default(LineHeight::FontSizeRelative(typesetting.line_height_ratio as f32));
196+
197+
let mut layout: Layout<()> = builder.build(str);
198+
199+
layout.break_all_lines(typesetting.max_width.map(|mw| mw as f32));
200+
layout.align(typesetting.max_width.map(|max_w| max_w as f32), typesetting.align.into(), AlignmentOptions::default());
201+
202+
Some(layout)
203+
})
204+
})
206205
}
207206

208207
pub fn to_path(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingConfig, per_glyph_instances: bool) -> Table<Vector> {

0 commit comments

Comments
 (0)