Skip to content

Commit f79e5e5

Browse files
tychedeliacatilac
authored andcommitted
Fmt.
1 parent c36c1d3 commit f79e5e5

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
@@ -1017,10 +1017,8 @@ pub extern "C" fn processing_end_contour(graphics_id: u64) {
10171017
#[unsafe(no_mangle)]
10181018
pub unsafe extern "C" fn processing_load_font(path_ptr: *const std::ffi::c_char) -> u64 {
10191019
error::clear_error();
1020-
let path = unsafe { std::ffi::CStr::from_ptr(path_ptr) }
1021-
.to_string_lossy();
1022-
error::check(|| font_load(&path).map(|e| e.to_bits()))
1023-
.unwrap_or(0)
1020+
let path = unsafe { std::ffi::CStr::from_ptr(path_ptr) }.to_string_lossy();
1021+
error::check(|| font_load(&path).map(|e| e.to_bits())).unwrap_or(0)
10241022
}
10251023

10261024
/// Create a font handle from an existing font family name.
@@ -1031,10 +1029,8 @@ pub unsafe extern "C" fn processing_load_font(path_ptr: *const std::ffi::c_char)
10311029
#[unsafe(no_mangle)]
10321030
pub unsafe extern "C" fn processing_create_font(name_ptr: *const std::ffi::c_char) -> u64 {
10331031
error::clear_error();
1034-
let name = unsafe { std::ffi::CStr::from_ptr(name_ptr) }
1035-
.to_string_lossy();
1036-
error::check(|| font_create(&name).map(|e| e.to_bits()))
1037-
.unwrap_or(0)
1032+
let name = unsafe { std::ffi::CStr::from_ptr(name_ptr) }.to_string_lossy();
1033+
error::check(|| font_create(&name).map(|e| e.to_bits())).unwrap_or(0)
10381034
}
10391035

10401036
/// Query the number of variable font axes for a font.
@@ -1043,8 +1039,7 @@ pub unsafe extern "C" fn processing_create_font(name_ptr: *const std::ffi::c_cha
10431039
pub extern "C" fn processing_font_variation_count(font_id: u64) -> u32 {
10441040
error::clear_error();
10451041
let font_entity = Entity::from_bits(font_id);
1046-
error::check(|| font_variations(font_entity).map(|v| v.len() as u32))
1047-
.unwrap_or(0)
1042+
error::check(|| font_variations(font_entity).map(|v| v.len() as u32)).unwrap_or(0)
10481043
}
10491044

10501045
/// Query variable font axis info.
@@ -1265,8 +1260,7 @@ pub unsafe extern "C" fn processing_text_bounds(
12651260
) {
12661261
error::clear_error();
12671262
let graphics_entity = Entity::from_bits(graphics_id);
1268-
let content = unsafe { std::ffi::CStr::from_ptr(str_ptr) }
1269-
.to_string_lossy();
1263+
let content = unsafe { std::ffi::CStr::from_ptr(str_ptr) }.to_string_lossy();
12701264
if let Some(bounds) =
12711265
error::check(|| graphics_text_bounds(graphics_entity, &content, x, y, None, None))
12721266
{
@@ -1387,9 +1381,7 @@ pub extern "C" fn processing_text_size(graphics_id: u64, size: f32) {
13871381
pub extern "C" fn processing_text_align(graphics_id: u64, h: u8, v: u8) {
13881382
error::clear_error();
13891383
let graphics_entity = Entity::from_bits(graphics_id);
1390-
error::check(|| {
1391-
graphics_text_align(graphics_entity, h, v)
1392-
});
1384+
error::check(|| graphics_text_align(graphics_entity, h, v));
13931385
}
13941386

13951387
/// Set the text leading (line spacing).
@@ -1420,28 +1412,24 @@ pub unsafe extern "C" fn processing_text_width(
14201412
) -> f32 {
14211413
error::clear_error();
14221414
let graphics_entity = Entity::from_bits(graphics_id);
1423-
let content = unsafe { std::ffi::CStr::from_ptr(str_ptr) }
1424-
.to_string_lossy();
1425-
error::check(|| graphics_text_width(graphics_entity, &content))
1426-
.unwrap_or(0.0)
1415+
let content = unsafe { std::ffi::CStr::from_ptr(str_ptr) }.to_string_lossy();
1416+
error::check(|| graphics_text_width(graphics_entity, &content)).unwrap_or(0.0)
14271417
}
14281418

14291419
/// Get the text ascent for the current font size.
14301420
#[unsafe(no_mangle)]
14311421
pub extern "C" fn processing_text_ascent(graphics_id: u64) -> f32 {
14321422
error::clear_error();
14331423
let graphics_entity = Entity::from_bits(graphics_id);
1434-
error::check(|| graphics_text_ascent(graphics_entity))
1435-
.unwrap_or(0.0)
1424+
error::check(|| graphics_text_ascent(graphics_entity)).unwrap_or(0.0)
14361425
}
14371426

14381427
/// Get the text descent for the current font size.
14391428
#[unsafe(no_mangle)]
14401429
pub extern "C" fn processing_text_descent(graphics_id: u64) -> f32 {
14411430
error::clear_error();
14421431
let graphics_entity = Entity::from_bits(graphics_id);
1443-
error::check(|| graphics_text_descent(graphics_entity))
1444-
.unwrap_or(0.0)
1432+
error::check(|| graphics_text_descent(graphics_entity)).unwrap_or(0.0)
14451433
}
14461434

14471435
/// 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
@@ -2401,11 +2401,12 @@ pub fn font_load(path: &str) -> error::Result<Entity> {
24012401

24022402
app_mut(|app| {
24032403
let text_cx = app.world().resource::<TextContext>().clone();
2404-
let family_name = text_cx
2405-
.load_font(data)
2406-
.ok_or(error::ProcessingError::FontLoadError(
2407-
"Could not determine font family name".to_string(),
2408-
))?;
2404+
let family_name =
2405+
text_cx
2406+
.load_font(data)
2407+
.ok_or(error::ProcessingError::FontLoadError(
2408+
"Could not determine font family name".to_string(),
2409+
))?;
24092410
let entity = app.world_mut().spawn(Font { family_name }).id();
24102411
Ok(entity)
24112412
})
@@ -2446,12 +2447,9 @@ pub fn font_variations(font_entity: Entity) -> error::Result<Vec<text::font::Fon
24462447
use text::font::TextContext;
24472448

24482449
app_mut(|app| {
2449-
let font = app
2450-
.world()
2451-
.get::<text::font::Font>(font_entity)
2452-
.ok_or(error::ProcessingError::InvalidArgument(
2453-
"Invalid font entity".to_string(),
2454-
))?;
2450+
let font = app.world().get::<text::font::Font>(font_entity).ok_or(
2451+
error::ProcessingError::InvalidArgument("Invalid font entity".to_string()),
2452+
)?;
24552453
let family = font.family_name.clone();
24562454
let text_cx = app.world().resource::<TextContext>().clone();
24572455
Ok(text_cx.font_variations(&family))
@@ -2463,19 +2461,17 @@ pub fn font_metadata(font_entity: Entity) -> error::Result<text::font::FontMetad
24632461
use text::font::TextContext;
24642462

24652463
app_mut(|app| {
2466-
let font = app
2467-
.world()
2468-
.get::<text::font::Font>(font_entity)
2469-
.ok_or(error::ProcessingError::InvalidArgument(
2470-
"Invalid font entity".to_string(),
2471-
))?;
2464+
let font = app.world().get::<text::font::Font>(font_entity).ok_or(
2465+
error::ProcessingError::InvalidArgument("Invalid font entity".to_string()),
2466+
)?;
24722467
let family = font.family_name.clone();
24732468
let text_cx = app.world().resource::<TextContext>().clone();
24742469
text_cx
24752470
.font_metadata(&family)
2476-
.ok_or(error::ProcessingError::InvalidArgument(
2477-
format!("Font family '{}' not found", family),
2478-
))
2471+
.ok_or(error::ProcessingError::InvalidArgument(format!(
2472+
"Font family '{}' not found",
2473+
family
2474+
)))
24792475
})
24802476
}
24812477

@@ -2490,7 +2486,10 @@ pub fn graphics_text_font(
24902486

24912487
pub fn graphics_text_style(graphics_entity: Entity, style: u8) -> error::Result<()> {
24922488
use render::command::TextStyle;
2493-
graphics_record_command(graphics_entity, DrawCommand::TextStyle(TextStyle::from(style)))
2489+
graphics_record_command(
2490+
graphics_entity,
2491+
DrawCommand::TextStyle(TextStyle::from(style)),
2492+
)
24942493
}
24952494

24962495
pub fn graphics_text_align(graphics_entity: Entity, h: u8, v: u8) -> error::Result<()> {
@@ -2506,7 +2505,10 @@ pub fn graphics_text_align(graphics_entity: Entity, h: u8, v: u8) -> error::Resu
25062505

25072506
pub fn graphics_text_wrap(graphics_entity: Entity, mode: u8) -> error::Result<()> {
25082507
use render::command::TextWrapMode;
2509-
graphics_record_command(graphics_entity, DrawCommand::TextWrap(TextWrapMode::from(mode)))
2508+
graphics_record_command(
2509+
graphics_entity,
2510+
DrawCommand::TextWrap(TextWrapMode::from(mode)),
2511+
)
25102512
}
25112513

25122514
pub fn graphics_text_weight(graphics_entity: Entity, weight: f32) -> error::Result<()> {
@@ -2516,9 +2518,10 @@ pub fn graphics_text_weight(graphics_entity: Entity, weight: f32) -> error::Resu
25162518
fn parse_tag(tag: &str) -> error::Result<[u8; 4]> {
25172519
let bytes = tag.as_bytes();
25182520
if bytes.len() != 4 {
2519-
return Err(error::ProcessingError::InvalidArgument(
2520-
format!("Font tag must be exactly 4 characters, got '{}'", tag),
2521-
));
2521+
return Err(error::ProcessingError::InvalidArgument(format!(
2522+
"Font tag must be exactly 4 characters, got '{}'",
2523+
tag
2524+
)));
25222525
}
25232526
Ok([bytes[0], bytes[1], bytes[2], bytes[3]])
25242527
}
@@ -2536,11 +2539,7 @@ pub fn graphics_clear_text_variations(graphics_entity: Entity) -> error::Result<
25362539
graphics_record_command(graphics_entity, DrawCommand::ClearTextVariations)
25372540
}
25382541

2539-
pub fn graphics_text_feature(
2540-
graphics_entity: Entity,
2541-
tag: &str,
2542-
value: u16,
2543-
) -> error::Result<()> {
2542+
pub fn graphics_text_feature(graphics_entity: Entity, tag: &str, value: u16) -> error::Result<()> {
25442543
let tag = parse_tag(tag)?;
25452544
graphics_record_command(graphics_entity, DrawCommand::TextFeature { tag, value })
25462545
}
@@ -2567,7 +2566,10 @@ fn text_query_state(
25672566
graphics_entity: Entity,
25682567
max_w: Option<f32>,
25692568
max_h: Option<f32>,
2570-
) -> error::Result<(render::primitive::text::OwnedTextParams, text::font::TextContext)> {
2569+
) -> error::Result<(
2570+
render::primitive::text::OwnedTextParams,
2571+
text::font::TextContext,
2572+
)> {
25712573
let state = app
25722574
.world()
25732575
.get::<render::RenderState>(graphics_entity)
@@ -2704,10 +2706,7 @@ pub fn graphics_text_bounds(
27042706
})
27052707
}
27062708

2707-
pub fn graphics_text_line_count(
2708-
graphics_entity: Entity,
2709-
content: &str,
2710-
) -> error::Result<usize> {
2709+
pub fn graphics_text_line_count(graphics_entity: Entity, content: &str) -> error::Result<usize> {
27112710
app_mut(|app| {
27122711
let (params, text_cx) = text_query_state(app, graphics_entity, None, None)?;
27132712
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)