Skip to content

Commit

Permalink
Start fixing clippy issues
Browse files Browse the repository at this point in the history
This mainly addresses issues that can automatically be fixed by `clippy`.
  • Loading branch information
mrobinson committed Oct 8, 2024
1 parent 18f10eb commit 27f2859
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
14 changes: 7 additions & 7 deletions src/font_collection_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ unsafe extern "system" fn CustomFontCollectionLoaderImpl_CreateEnumeratorFromKey
out_enumerator: *mut *mut IDWriteFontFileEnumerator,
) -> HRESULT {
let this = CustomFontCollectionLoaderImpl::from_interface(this);
let enumerator = CustomFontFileEnumeratorImpl::new((*this).font_files.clone());
let enumerator = CustomFontFileEnumeratorImpl::new(this.font_files.clone());
let enumerator = ComPtr::<IDWriteFontFileEnumerator>::from_raw(enumerator.into_interface());
*out_enumerator = enumerator.as_raw();
mem::forget(enumerator);
Expand Down Expand Up @@ -129,10 +129,10 @@ unsafe extern "system" fn CustomFontFileEnumeratorImpl_GetCurrentFontFile(
out_font_file: *mut *mut IDWriteFontFile,
) -> HRESULT {
let this = CustomFontFileEnumeratorImpl::from_interface(this);
if (*this).index < 0 || (*this).index >= (*this).font_files.len() as isize {
if this.index < 0 || this.index >= this.font_files.len() as isize {
return E_INVALIDARG;
}
let new_font_file = (*this).font_files[(*this).index as usize].clone();
let new_font_file = this.font_files[this.index as usize].clone();
*out_font_file = new_font_file.as_raw();
mem::forget(new_font_file);
S_OK
Expand All @@ -144,11 +144,11 @@ unsafe extern "system" fn CustomFontFileEnumeratorImpl_MoveNext(
has_current_file: *mut BOOL,
) -> HRESULT {
let this = CustomFontFileEnumeratorImpl::from_interface(this);
let font_file_count = (*this).font_files.len() as isize;
if (*this).index < font_file_count {
(*this).index += 1
let font_file_count = this.font_files.len() as isize;
if this.index < font_file_count {
this.index += 1
}
*has_current_file = if (*this).index >= 0 && (*this).index < font_file_count {
*has_current_file = if this.index >= 0 && this.index < font_file_count {
TRUE
} else {
FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/font_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl FontFile {
}
}
self.face_type = face_type;
num_faces as u32
num_faces
}

pub fn take(native: ComPtr<IDWriteFontFile>) -> FontFile {
Expand Down
4 changes: 2 additions & 2 deletions src/font_file_loader_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::com_helpers::*;

struct FontFileLoader;

const FontFileLoaderVtbl: &'static IDWriteFontFileLoaderVtbl = &IDWriteFontFileLoaderVtbl {
const FontFileLoaderVtbl: &IDWriteFontFileLoaderVtbl = &IDWriteFontFileLoaderVtbl {
parent: implement_iunknown!(static IDWriteFontFileLoader, FontFileLoader),
CreateStreamFromKey: {
unsafe extern "system" fn CreateStreamFromKey(
Expand Down Expand Up @@ -83,7 +83,7 @@ struct FontFileStream {
data: Arc<Vec<u8>>,
}

const FontFileStreamVtbl: &'static IDWriteFontFileStreamVtbl = &IDWriteFontFileStreamVtbl {
const FontFileStreamVtbl: &IDWriteFontFileStreamVtbl = &IDWriteFontFileStreamVtbl {
parent: implement_iunknown!(IDWriteFontFileStream, FontFileStream),
ReadFileFragment: {
unsafe extern "system" fn ReadFileFragment(
Expand Down
8 changes: 4 additions & 4 deletions src/geometry_sink_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ unsafe extern "system" fn GeometrySinkImpl_BeginFigure(
_: D2D1_FIGURE_BEGIN,
) {
let this = GeometrySinkImpl::from_interface(this);
(*this)
this
.outline_builder
.move_to(start_point.x, start_point.y)
}
Expand All @@ -75,7 +75,7 @@ unsafe extern "system" fn GeometrySinkImpl_EndFigure(
) {
let this = GeometrySinkImpl::from_interface(this);
if figure_end == D2D1_FIGURE_END_CLOSED {
(*this).outline_builder.close()
this.outline_builder.close()
}
}

Expand All @@ -87,7 +87,7 @@ unsafe extern "system" fn GeometrySinkImpl_AddLines(
let this = GeometrySinkImpl::from_interface(this);
let points = slice::from_raw_parts(points, points_count as usize);
for point in points {
(*this).outline_builder.line_to(point.x, point.y)
this.outline_builder.line_to(point.x, point.y)
}
}

Expand All @@ -99,7 +99,7 @@ unsafe extern "system" fn GeometrySinkImpl_AddBeziers(
let this = GeometrySinkImpl::from_interface(this);
let beziers = slice::from_raw_parts(beziers, beziers_count as usize);
for bezier in beziers {
(*this).outline_builder.curve_to(
this.outline_builder.curve_to(
bezier.point1.x,
bezier.point1.y,
bezier.point2.x,
Expand Down
15 changes: 7 additions & 8 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ fn test_system_family_iter() {
assert!(count > 0);
assert!(system_fc
.families_iter()
.find(|f| f.name() == "Arial")
.is_some());
.any(|f| f.name() == "Arial"));
}

#[test]
Expand Down Expand Up @@ -47,10 +46,10 @@ fn test_get_font_file_bytes() {
);
let face = arial_font.create_font_face();
let files = face.get_files();
assert!(files.len() > 0);
assert!(!files.is_empty());

let bytes = files[0].get_font_file_bytes();
assert!(bytes.len() > 0);
assert!(!bytes.is_empty());
}

#[test]
Expand Down Expand Up @@ -86,10 +85,10 @@ fn test_create_font_file_from_bytes() {
);
let face = arial_font.create_font_face();
let files = face.get_files();
assert!(files.len() > 0);
assert!(!files.is_empty());

let bytes = files[0].get_font_file_bytes();
assert!(bytes.len() > 0);
assert!(!bytes.is_empty());

// now go back
let new_font = FontFile::new_from_data(Arc::new(bytes));
Expand Down Expand Up @@ -148,8 +147,8 @@ fn test_glyph_image() {
let rp = RenderingParams::create_for_primary_monitor();
rt.set_pixels_per_dip(device_pixel_ratio);
rt.draw_glyph_run(
x as f32,
y as f32,
x,
y,
DWRITE_MEASURING_MODE_NATURAL,
&face,
em_size,
Expand Down
6 changes: 3 additions & 3 deletions src/text_analysis_source_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait TextAnalysisSourceMethods {
///
/// Return locale and length of text (in utf-16 code units) for which the
/// locale is valid.
fn get_locale_name<'a>(&'a self, text_position: u32) -> (Cow<'a, str>, u32);
fn get_locale_name(&self, text_position: u32) -> (Cow<'_, str>, u32);

/// Get the text direction for the paragraph.
fn get_paragraph_reading_direction(&self) -> DWRITE_READING_DIRECTION;
Expand Down Expand Up @@ -80,7 +80,7 @@ impl<'a> CustomTextAnalysisSourceImpl<'a> {
inner: Box<dyn TextAnalysisSourceMethods + 'a>,
text: Cow<'a, [wchar_t]>,
) -> CustomTextAnalysisSourceImpl<'a> {
assert!(text.len() <= (std::u32::MAX as usize));
assert!(text.len() <= (u32::MAX as usize));
CustomTextAnalysisSourceImpl {
_refcount: AtomicUsize::new(1),
inner,
Expand All @@ -100,7 +100,7 @@ impl<'a> CustomTextAnalysisSourceImpl<'a> {
text: Cow<'a, [wchar_t]>,
number_subst: NumberSubstitution,
) -> CustomTextAnalysisSourceImpl<'a> {
assert!(text.len() <= (std::u32::MAX as usize));
assert!(text.len() <= (u32::MAX as usize));
CustomTextAnalysisSourceImpl {
_refcount: AtomicUsize::new(1),
inner,
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl FontWeight {
FontWeight::ExtraBold=> 800,
FontWeight::Black=> 900,
FontWeight::ExtraBlack=> 950,
FontWeight::Unknown(v) => *v as u32
FontWeight::Unknown(v) => { *v }
}
}
pub fn from_u32(v: u32) -> FontWeight {
Expand Down

0 comments on commit 27f2859

Please sign in to comment.