Skip to content

Commit 304c080

Browse files
committed
Use c_int for enums without a type alias
1 parent d2117f9 commit 304c080

File tree

9 files changed

+25
-25
lines changed

9 files changed

+25
-25
lines changed

src/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ptr;
22
use std::{
3-
ffi::{c_uint, CString},
3+
ffi::{c_int, CString},
44
num::NonZero,
55
};
66

@@ -16,7 +16,7 @@ use crate::{
1616
mod native;
1717
pub use native::NativeDevice;
1818

19-
from_enum! { c_uint,
19+
from_enum! { c_int,
2020
#[derive(Debug, Clone, Copy, PartialEq)]
2121
pub enum BlendMode {
2222
/* PDF 1.4 -- standard separable */

src/device/native.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,14 +771,12 @@ unsafe extern "C" fn begin_group<D: NativeDevice>(
771771
with_rust_device::<D, _>(dev, |dev| {
772772
let cs = ManuallyDrop::new(Colorspace::from_raw(color_space));
773773

774-
let blendmode = BlendMode::try_from(blendmode as u32).unwrap();
775-
776774
dev.begin_group(
777775
area.into(),
778776
&cs,
779777
isolated != 0,
780778
knockout != 0,
781-
blendmode,
779+
blendmode.try_into().unwrap(),
782780
alpha,
783781
);
784782
});
@@ -891,7 +889,7 @@ unsafe extern "C" fn begin_metatext<D: NativeDevice>(
891889
text: *const c_char,
892890
) {
893891
with_rust_device::<D, _>(dev, |dev| {
894-
let meta = Metatext::try_from(meta as u32).unwrap();
892+
let meta = Metatext::try_from(meta).unwrap();
895893
let text = unsafe { CStr::from_ptr(text) }.to_str().unwrap();
896894

897895
dev.begin_metatext(meta, text);

src/font.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::ffi::{c_uint, CStr, CString};
1+
use std::ffi::{c_int, CStr, CString};
22
use std::fmt;
33
use std::str::FromStr;
44

55
use mupdf_sys::*;
66

77
use crate::{context, from_enum, Buffer, Error, Matrix, Path};
88

9-
from_enum! { c_uint,
9+
from_enum! { c_int,
1010
#[derive(Debug, Clone, Copy, PartialEq)]
1111
pub enum SimpleFontEncoding {
1212
Latin = PDF_SIMPLE_ENCODING_LATIN,
@@ -23,7 +23,7 @@ from_enum! { u32,
2323
}
2424
}
2525

26-
from_enum! { c_uint,
26+
from_enum! { c_int,
2727
#[derive(Debug, Clone, Copy, PartialEq)]
2828
pub enum CjkFontOrdering {
2929
AdobeCns = FZ_ADOBE_CNS,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ macro_rules! from_enum {
261261

262262
#[allow(non_upper_case_globals)]
263263
fn try_from(value: $c_type) -> Result<Self, Self::Error> {
264-
match value {
264+
match value as _ {
265265
$($value => Ok(Self::$field),)*
266266
_ => Err(Error::UnknownEnumVariant)
267267
}

src/pdf/document.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::convert::TryFrom;
2-
use std::ffi::{c_uint, CStr, CString};
2+
use std::ffi::{c_int, CStr, CString};
33
use std::io::{self, Write};
44
use std::ops::{Deref, DerefMut};
55
use std::ptr::{self, NonNull};
@@ -27,7 +27,7 @@ bitflags! {
2727
}
2828
}
2929

30-
from_enum! { c_uint,
30+
from_enum! { c_int,
3131
#[derive(Debug, Copy, Clone, PartialEq)]
3232
pub enum Encryption {
3333
Aes128 = PDF_ENCRYPT_AES_128,
@@ -180,7 +180,7 @@ impl PdfWriteOptions {
180180
}
181181

182182
pub fn encryption(&self) -> Encryption {
183-
Encryption::try_from(self.inner.do_encrypt as u32).unwrap()
183+
Encryption::try_from(self.inner.do_encrypt).unwrap()
184184
}
185185

186186
pub fn set_encryption(&mut self, value: Encryption) -> &mut Self {

src/stroke_state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ impl StrokeState {
8383
}
8484

8585
pub fn start_cap(&self) -> LineCap {
86-
LineCap::try_from(unsafe { (*self.inner).start_cap as u32 }).unwrap()
86+
LineCap::try_from(unsafe { (*self.inner).start_cap }).unwrap()
8787
}
8888

8989
pub fn dash_cap(&self) -> LineCap {
90-
LineCap::try_from(unsafe { (*self.inner).dash_cap as u32 }).unwrap()
90+
LineCap::try_from(unsafe { (*self.inner).dash_cap }).unwrap()
9191
}
9292

9393
pub fn end_cap(&self) -> LineCap {
94-
LineCap::try_from(unsafe { (*self.inner).end_cap as u32 }).unwrap()
94+
LineCap::try_from(unsafe { (*self.inner).end_cap }).unwrap()
9595
}
9696

9797
pub fn line_join(&self) -> LineJoin {
98-
LineJoin::try_from(unsafe { (*self.inner).linejoin as u32 }).unwrap()
98+
LineJoin::try_from(unsafe { (*self.inner).linejoin }).unwrap()
9999
}
100100

101101
pub fn line_width(&self) -> f32 {

src/system_font.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub unsafe extern "C" fn load_system_cjk_font(
9999
return font;
100100
}
101101
if serif == 1 {
102-
match CjkFontOrdering::try_from(ordering as u32) {
102+
match CjkFontOrdering::try_from(ordering) {
103103
Ok(CjkFontOrdering::AdobeCns) => {
104104
return load_font_by_names(ctx, &["MingLiU"]);
105105
}
@@ -115,7 +115,7 @@ pub unsafe extern "C" fn load_system_cjk_font(
115115
Err(_) => {}
116116
}
117117
} else {
118-
match CjkFontOrdering::try_from(ordering as u32) {
118+
match CjkFontOrdering::try_from(ordering) {
119119
Ok(CjkFontOrdering::AdobeCns) => {
120120
return load_font_by_names(ctx, &["DFKaiShu-SB-Estd-BF"]);
121121
}

src/text.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,17 @@ impl TextSpan {
104104
}
105105

106106
pub fn markup_dir(&self) -> BidiDirection {
107-
unsafe { (*self.inner).markup_dir().try_into().unwrap() }
107+
let markup_dir = unsafe { (*self.inner).markup_dir() };
108+
(markup_dir as fz_bidi_direction).try_into().unwrap()
108109
}
109110

110111
pub fn set_markup_dir(&mut self, dir: BidiDirection) {
111112
unsafe { (*self.inner).set_markup_dir(dir as _) }
112113
}
113114

114115
pub fn language(&self) -> Language {
115-
unsafe { (*self.inner).language().try_into().unwrap() }
116+
let lang = unsafe { (*self.inner).language() };
117+
(lang as fz_text_language).try_into().unwrap()
116118
}
117119

118120
pub fn set_language(&mut self, language: Language) {

src/text_page.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
convert::TryInto,
3-
ffi::{c_int, c_uint, c_void, CString},
3+
ffi::{c_int, c_void, CString},
44
io::Read,
55
marker::PhantomData,
66
ptr::{self, NonNull},
@@ -309,7 +309,7 @@ pub enum SearchHitResponse {
309309
AbortSearch = 1,
310310
}
311311

312-
from_enum! { c_uint,
312+
from_enum! { c_int,
313313
#[derive(Debug, Clone, Copy, PartialEq)]
314314
pub enum TextBlockType {
315315
Text = FZ_STEXT_BLOCK_TEXT,
@@ -327,7 +327,7 @@ pub struct TextBlock<'a> {
327327

328328
impl TextBlock<'_> {
329329
pub fn r#type(&self) -> TextBlockType {
330-
(self.inner.type_ as u32).try_into().unwrap()
330+
self.inner.type_.try_into().unwrap()
331331
}
332332

333333
pub fn bounds(&self) -> Rect {
@@ -336,7 +336,7 @@ impl TextBlock<'_> {
336336

337337
pub fn lines(&self) -> TextLineIter {
338338
unsafe {
339-
if self.inner.type_ == FZ_STEXT_BLOCK_TEXT as i32 {
339+
if self.inner.type_ == FZ_STEXT_BLOCK_TEXT as c_int {
340340
return TextLineIter {
341341
next: self.inner.u.t.first_line,
342342
_marker: PhantomData,

0 commit comments

Comments
 (0)