Skip to content

Commit 264acbf

Browse files
committed
Fmt.
1 parent e4de15d commit 264acbf

7 files changed

Lines changed: 214 additions & 140 deletions

File tree

crates/processing_ffi/src/lib.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,8 @@ pub extern "C" fn processing_end_contour(graphics_id: u64) {
993993
#[unsafe(no_mangle)]
994994
pub unsafe extern "C" fn processing_load_font(path_ptr: *const std::ffi::c_char) -> u64 {
995995
error::clear_error();
996-
let path = unsafe { std::ffi::CStr::from_ptr(path_ptr) }
997-
.to_string_lossy();
998-
error::check(|| font_load(&path).map(|e| e.to_bits()))
999-
.unwrap_or(0)
996+
let path = unsafe { std::ffi::CStr::from_ptr(path_ptr) }.to_string_lossy();
997+
error::check(|| font_load(&path).map(|e| e.to_bits())).unwrap_or(0)
1000998
}
1001999

10021000
/// Create a font handle from an existing font family name.
@@ -1007,10 +1005,8 @@ pub unsafe extern "C" fn processing_load_font(path_ptr: *const std::ffi::c_char)
10071005
#[unsafe(no_mangle)]
10081006
pub unsafe extern "C" fn processing_create_font(name_ptr: *const std::ffi::c_char) -> u64 {
10091007
error::clear_error();
1010-
let name = unsafe { std::ffi::CStr::from_ptr(name_ptr) }
1011-
.to_string_lossy();
1012-
error::check(|| font_create(&name).map(|e| e.to_bits()))
1013-
.unwrap_or(0)
1008+
let name = unsafe { std::ffi::CStr::from_ptr(name_ptr) }.to_string_lossy();
1009+
error::check(|| font_create(&name).map(|e| e.to_bits())).unwrap_or(0)
10141010
}
10151011

10161012
/// Query the number of variable font axes for a font.
@@ -1019,8 +1015,7 @@ pub unsafe extern "C" fn processing_create_font(name_ptr: *const std::ffi::c_cha
10191015
pub extern "C" fn processing_font_variation_count(font_id: u64) -> u32 {
10201016
error::clear_error();
10211017
let font_entity = Entity::from_bits(font_id);
1022-
error::check(|| font_variations(font_entity).map(|v| v.len() as u32))
1023-
.unwrap_or(0)
1018+
error::check(|| font_variations(font_entity).map(|v| v.len() as u32)).unwrap_or(0)
10241019
}
10251020

10261021
/// Query variable font axis info.
@@ -1241,8 +1236,7 @@ pub unsafe extern "C" fn processing_text_bounds(
12411236
) {
12421237
error::clear_error();
12431238
let graphics_entity = Entity::from_bits(graphics_id);
1244-
let content = unsafe { std::ffi::CStr::from_ptr(str_ptr) }
1245-
.to_string_lossy();
1239+
let content = unsafe { std::ffi::CStr::from_ptr(str_ptr) }.to_string_lossy();
12461240
if let Some(bounds) =
12471241
error::check(|| graphics_text_bounds(graphics_entity, &content, x, y, None, None))
12481242
{
@@ -1363,9 +1357,7 @@ pub extern "C" fn processing_text_size(graphics_id: u64, size: f32) {
13631357
pub extern "C" fn processing_text_align(graphics_id: u64, h: u8, v: u8) {
13641358
error::clear_error();
13651359
let graphics_entity = Entity::from_bits(graphics_id);
1366-
error::check(|| {
1367-
graphics_text_align(graphics_entity, h, v)
1368-
});
1360+
error::check(|| graphics_text_align(graphics_entity, h, v));
13691361
}
13701362

13711363
/// Set the text leading (line spacing).
@@ -1396,28 +1388,24 @@ pub unsafe extern "C" fn processing_text_width(
13961388
) -> f32 {
13971389
error::clear_error();
13981390
let graphics_entity = Entity::from_bits(graphics_id);
1399-
let content = unsafe { std::ffi::CStr::from_ptr(str_ptr) }
1400-
.to_string_lossy();
1401-
error::check(|| graphics_text_width(graphics_entity, &content))
1402-
.unwrap_or(0.0)
1391+
let content = unsafe { std::ffi::CStr::from_ptr(str_ptr) }.to_string_lossy();
1392+
error::check(|| graphics_text_width(graphics_entity, &content)).unwrap_or(0.0)
14031393
}
14041394

14051395
/// Get the text ascent for the current font size.
14061396
#[unsafe(no_mangle)]
14071397
pub extern "C" fn processing_text_ascent(graphics_id: u64) -> f32 {
14081398
error::clear_error();
14091399
let graphics_entity = Entity::from_bits(graphics_id);
1410-
error::check(|| graphics_text_ascent(graphics_entity))
1411-
.unwrap_or(0.0)
1400+
error::check(|| graphics_text_ascent(graphics_entity)).unwrap_or(0.0)
14121401
}
14131402

14141403
/// Get the text descent for the current font size.
14151404
#[unsafe(no_mangle)]
14161405
pub extern "C" fn processing_text_descent(graphics_id: u64) -> f32 {
14171406
error::clear_error();
14181407
let graphics_entity = Entity::from_bits(graphics_id);
1419-
error::check(|| graphics_text_descent(graphics_entity))
1420-
.unwrap_or(0.0)
1408+
error::check(|| graphics_text_descent(graphics_entity)).unwrap_or(0.0)
14211409
}
14221410

14231411
/// Create an image from raw pixel data.

crates/processing_pyo3/src/graphics.rs

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,23 @@ fn path_commands_to_py(
264264
match cmd {
265265
PathCommand::MoveTo(x, y) => ("M", x, y).into_pyobject(py).unwrap().into_any().unbind(),
266266
PathCommand::LineTo(x, y) => ("L", x, y).into_pyobject(py).unwrap().into_any().unbind(),
267-
PathCommand::QuadTo { cx, cy, x, y } => {
268-
("Q", cx, cy, x, y).into_pyobject(py).unwrap().into_any().unbind()
269-
}
270-
PathCommand::CubicTo { cx1, cy1, cx2, cy2, x, y } => {
271-
("C", cx1, cy1, cx2, cy2, x, y).into_pyobject(py).unwrap().into_any().unbind()
272-
}
267+
PathCommand::QuadTo { cx, cy, x, y } => ("Q", cx, cy, x, y)
268+
.into_pyobject(py)
269+
.unwrap()
270+
.into_any()
271+
.unbind(),
272+
PathCommand::CubicTo {
273+
cx1,
274+
cy1,
275+
cx2,
276+
cy2,
277+
x,
278+
y,
279+
} => ("C", cx1, cy1, cx2, cy2, x, y)
280+
.into_pyobject(py)
281+
.unwrap()
282+
.into_any()
283+
.unbind(),
273284
PathCommand::Close => ("Z",).into_pyobject(py).unwrap().into_any().unbind(),
274285
}
275286
};
@@ -1018,7 +1029,11 @@ impl Graphics {
10181029
let h: f32 = args.get_item(2)?.extract()?;
10191030
(z, Some(w), Some(h))
10201031
}
1021-
_ => return Err(PyRuntimeError::new_err("text() takes 3-6 positional arguments")),
1032+
_ => {
1033+
return Err(PyRuntimeError::new_err(
1034+
"text() takes 3-6 positional arguments",
1035+
));
1036+
}
10221037
};
10231038
graphics_record_command(
10241039
self.entity,
@@ -1035,8 +1050,7 @@ impl Graphics {
10351050
}
10361051

10371052
pub fn text_style(&self, style: u8) -> PyResult<()> {
1038-
graphics_text_style(self.entity, style)
1039-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
1053+
graphics_text_style(self.entity, style).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
10401054
}
10411055

10421056
#[pyo3(signature = (content, x, y, max_w=None, max_h=None))]
@@ -1106,12 +1120,7 @@ impl Graphics {
11061120
/// Extract glyph outlines as path commands (one list per glyph).
11071121
/// Each command is a tuple: ("M", x, y), ("L", x, y), ("Q", cx, cy, x, y),
11081122
/// ("C", cx1, cy1, cx2, cy2, x, y), or ("Z",).
1109-
pub fn text_to_paths(
1110-
&self,
1111-
content: &str,
1112-
x: f32,
1113-
y: f32,
1114-
) -> PyResult<Vec<Vec<Py<PyAny>>>> {
1123+
pub fn text_to_paths(&self, content: &str, x: f32, y: f32) -> PyResult<Vec<Vec<Py<PyAny>>>> {
11151124
let paths = graphics_text_to_paths(self.entity, content, x, y)
11161125
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
11171126
Python::attach(|py| Ok(path_commands_to_py(py, paths)))
@@ -1120,12 +1129,7 @@ impl Graphics {
11201129
/// Extract glyph outlines as per-contour path commands.
11211130
/// Each contour (MoveTo...Close sequence) is a separate list.
11221131
/// Commands use the same tuple shapes as `text_to_paths`.
1123-
pub fn text_to_contours(
1124-
&self,
1125-
content: &str,
1126-
x: f32,
1127-
y: f32,
1128-
) -> PyResult<Vec<Vec<Py<PyAny>>>> {
1132+
pub fn text_to_contours(&self, content: &str, x: f32, y: f32) -> PyResult<Vec<Vec<Py<PyAny>>>> {
11291133
let contours = graphics_text_to_contours(self.entity, content, x, y)
11301134
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
11311135
Python::attach(|py| Ok(path_commands_to_py(py, contours)))
@@ -1146,17 +1150,11 @@ impl Graphics {
11461150
}
11471151

11481152
/// Generate a 3D extruded mesh from text outlines.
1149-
pub fn text_to_model(
1150-
&self,
1151-
content: &str,
1152-
x: f32,
1153-
y: f32,
1154-
depth: f32,
1155-
) -> PyResult<Geometry> {
1153+
pub fn text_to_model(&self, content: &str, x: f32, y: f32, depth: f32) -> PyResult<Geometry> {
11561154
let mesh = graphics_text_to_model(self.entity, content, x, y, depth)
11571155
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
1158-
let entity = geometry_create_from_mesh(mesh)
1159-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
1156+
let entity =
1157+
geometry_create_from_mesh(mesh).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
11601158
Ok(Geometry { entity })
11611159
}
11621160

@@ -1251,13 +1249,11 @@ impl Graphics {
12511249
}
12521250

12531251
pub fn text_ascent(&self) -> PyResult<f32> {
1254-
graphics_text_ascent(self.entity)
1255-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
1252+
graphics_text_ascent(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
12561253
}
12571254

12581255
pub fn text_descent(&self) -> PyResult<f32> {
1259-
graphics_text_descent(self.entity)
1260-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
1256+
graphics_text_descent(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
12611257
}
12621258

12631259
/// Loads an image from a file and returns an Image object.

crates/processing_render/src/lib.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,11 +2335,12 @@ pub fn font_load(path: &str) -> error::Result<Entity> {
23352335

23362336
app_mut(|app| {
23372337
let text_cx = app.world().resource::<TextContext>().clone();
2338-
let family_name = text_cx
2339-
.load_font(data)
2340-
.ok_or(error::ProcessingError::FontLoadError(
2341-
"Could not determine font family name".to_string(),
2342-
))?;
2338+
let family_name =
2339+
text_cx
2340+
.load_font(data)
2341+
.ok_or(error::ProcessingError::FontLoadError(
2342+
"Could not determine font family name".to_string(),
2343+
))?;
23432344
let entity = app.world_mut().spawn(Font { family_name }).id();
23442345
Ok(entity)
23452346
})
@@ -2380,12 +2381,9 @@ pub fn font_variations(font_entity: Entity) -> error::Result<Vec<text::font::Fon
23802381
use text::font::TextContext;
23812382

23822383
app_mut(|app| {
2383-
let font = app
2384-
.world()
2385-
.get::<text::font::Font>(font_entity)
2386-
.ok_or(error::ProcessingError::InvalidArgument(
2387-
"Invalid font entity".to_string(),
2388-
))?;
2384+
let font = app.world().get::<text::font::Font>(font_entity).ok_or(
2385+
error::ProcessingError::InvalidArgument("Invalid font entity".to_string()),
2386+
)?;
23892387
let family = font.family_name.clone();
23902388
let text_cx = app.world().resource::<TextContext>().clone();
23912389
Ok(text_cx.font_variations(&family))
@@ -2397,19 +2395,17 @@ pub fn font_metadata(font_entity: Entity) -> error::Result<text::font::FontMetad
23972395
use text::font::TextContext;
23982396

23992397
app_mut(|app| {
2400-
let font = app
2401-
.world()
2402-
.get::<text::font::Font>(font_entity)
2403-
.ok_or(error::ProcessingError::InvalidArgument(
2404-
"Invalid font entity".to_string(),
2405-
))?;
2398+
let font = app.world().get::<text::font::Font>(font_entity).ok_or(
2399+
error::ProcessingError::InvalidArgument("Invalid font entity".to_string()),
2400+
)?;
24062401
let family = font.family_name.clone();
24072402
let text_cx = app.world().resource::<TextContext>().clone();
24082403
text_cx
24092404
.font_metadata(&family)
2410-
.ok_or(error::ProcessingError::InvalidArgument(
2411-
format!("Font family '{}' not found", family),
2412-
))
2405+
.ok_or(error::ProcessingError::InvalidArgument(format!(
2406+
"Font family '{}' not found",
2407+
family
2408+
)))
24132409
})
24142410
}
24152411

@@ -2424,7 +2420,10 @@ pub fn graphics_text_font(
24242420

24252421
pub fn graphics_text_style(graphics_entity: Entity, style: u8) -> error::Result<()> {
24262422
use render::command::TextStyle;
2427-
graphics_record_command(graphics_entity, DrawCommand::TextStyle(TextStyle::from(style)))
2423+
graphics_record_command(
2424+
graphics_entity,
2425+
DrawCommand::TextStyle(TextStyle::from(style)),
2426+
)
24282427
}
24292428

24302429
pub fn graphics_text_align(graphics_entity: Entity, h: u8, v: u8) -> error::Result<()> {
@@ -2440,7 +2439,10 @@ pub fn graphics_text_align(graphics_entity: Entity, h: u8, v: u8) -> error::Resu
24402439

24412440
pub fn graphics_text_wrap(graphics_entity: Entity, mode: u8) -> error::Result<()> {
24422441
use render::command::TextWrapMode;
2443-
graphics_record_command(graphics_entity, DrawCommand::TextWrap(TextWrapMode::from(mode)))
2442+
graphics_record_command(
2443+
graphics_entity,
2444+
DrawCommand::TextWrap(TextWrapMode::from(mode)),
2445+
)
24442446
}
24452447

24462448
pub fn graphics_text_weight(graphics_entity: Entity, weight: f32) -> error::Result<()> {
@@ -2450,9 +2452,10 @@ pub fn graphics_text_weight(graphics_entity: Entity, weight: f32) -> error::Resu
24502452
fn parse_tag(tag: &str) -> error::Result<[u8; 4]> {
24512453
let bytes = tag.as_bytes();
24522454
if bytes.len() != 4 {
2453-
return Err(error::ProcessingError::InvalidArgument(
2454-
format!("Font tag must be exactly 4 characters, got '{}'", tag),
2455-
));
2455+
return Err(error::ProcessingError::InvalidArgument(format!(
2456+
"Font tag must be exactly 4 characters, got '{}'",
2457+
tag
2458+
)));
24562459
}
24572460
Ok([bytes[0], bytes[1], bytes[2], bytes[3]])
24582461
}
@@ -2470,11 +2473,7 @@ pub fn graphics_clear_text_variations(graphics_entity: Entity) -> error::Result<
24702473
graphics_record_command(graphics_entity, DrawCommand::ClearTextVariations)
24712474
}
24722475

2473-
pub fn graphics_text_feature(
2474-
graphics_entity: Entity,
2475-
tag: &str,
2476-
value: u16,
2477-
) -> error::Result<()> {
2476+
pub fn graphics_text_feature(graphics_entity: Entity, tag: &str, value: u16) -> error::Result<()> {
24782477
let tag = parse_tag(tag)?;
24792478
graphics_record_command(graphics_entity, DrawCommand::TextFeature { tag, value })
24802479
}
@@ -2501,7 +2500,10 @@ fn text_query_state(
25012500
graphics_entity: Entity,
25022501
max_w: Option<f32>,
25032502
max_h: Option<f32>,
2504-
) -> error::Result<(render::primitive::text::OwnedTextParams, text::font::TextContext)> {
2503+
) -> error::Result<(
2504+
render::primitive::text::OwnedTextParams,
2505+
text::font::TextContext,
2506+
)> {
25052507
let state = app
25062508
.world()
25072509
.get::<render::RenderState>(graphics_entity)
@@ -2638,10 +2640,7 @@ pub fn graphics_text_bounds(
26382640
})
26392641
}
26402642

2641-
pub fn graphics_text_line_count(
2642-
graphics_entity: Entity,
2643-
content: &str,
2644-
) -> error::Result<usize> {
2643+
pub fn graphics_text_line_count(graphics_entity: Entity, content: &str) -> error::Result<usize> {
26452644
app_mut(|app| {
26462645
let (params, text_cx) = text_query_state(app, graphics_entity, None, None)?;
26472646
Ok(render::primitive::text::text_line_count(

crates/processing_render/src/render/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,9 @@ pub fn flush_draw_commands(
12031203
state.text_weight = Some(weight);
12041204
}
12051205
DrawCommand::TextVariation { tag, value } => {
1206-
if let Some(existing) = state.text_variations.iter_mut().find(|(t, _)| *t == tag) {
1206+
if let Some(existing) =
1207+
state.text_variations.iter_mut().find(|(t, _)| *t == tag)
1208+
{
12071209
existing.1 = value;
12081210
} else {
12091211
state.text_variations.push((tag, value));
@@ -1213,7 +1215,8 @@ pub fn flush_draw_commands(
12131215
state.text_variations.clear();
12141216
}
12151217
DrawCommand::TextFeature { tag, value } => {
1216-
if let Some(existing) = state.text_features.iter_mut().find(|(t, _)| *t == tag) {
1218+
if let Some(existing) = state.text_features.iter_mut().find(|(t, _)| *t == tag)
1219+
{
12171220
existing.1 = value;
12181221
} else {
12191222
state.text_features.push((tag, value));
@@ -1274,7 +1277,13 @@ pub fn flush_draw_commands(
12741277
&state,
12751278
|mesh, color| {
12761279
primitive::text::text(
1277-
mesh, &content, x, y, color, &text_params.as_params(), &text_cx,
1280+
mesh,
1281+
&content,
1282+
x,
1283+
y,
1284+
color,
1285+
&text_params.as_params(),
1286+
&text_cx,
12781287
);
12791288
},
12801289
&p_material_handles,

0 commit comments

Comments
 (0)