Add ResolutionType type
This commit is contained in:
@ -12,6 +12,7 @@ mod metric_type;
|
||||
mod orientation_type;
|
||||
mod pixel_interpolate_method;
|
||||
mod rendering_intent;
|
||||
mod resolution_type;
|
||||
mod resource_type;
|
||||
|
||||
pub use self::alpha_channel_option::AlphaChannelOption;
|
||||
@ -28,4 +29,5 @@ pub use self::metric_type::MetricType;
|
||||
pub use self::orientation_type::OrientationType;
|
||||
pub use self::pixel_interpolate_method::PixelInterpolateMethod;
|
||||
pub use self::rendering_intent::RenderingIntent;
|
||||
pub use self::resolution_type::ResolutionType;
|
||||
pub use self::resource_type::ResourceType;
|
||||
|
||||
38
src/types/resolution_type.rs
Normal file
38
src/types/resolution_type.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum ResolutionType {
|
||||
Undefined = bindings::ResolutionType_UndefinedResolution,
|
||||
PixelsPerInch = bindings::ResolutionType_PixelsPerInchResolution,
|
||||
PixelsPerCentimeter = bindings::ResolutionType_PixelsPerCentimeterResolution,
|
||||
}
|
||||
|
||||
impl Default for ResolutionType {
|
||||
fn default() -> Self {
|
||||
return ResolutionType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResolutionType> for bindings::ResolutionType {
|
||||
fn from(value: ResolutionType) -> Self {
|
||||
return value as bindings::ResolutionType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::ResolutionType> for ResolutionType {
|
||||
fn from(value: bindings::ResolutionType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `ResolutionType` has the same repr as `bindings::ResolutionType` - u32
|
||||
*
|
||||
* If `value` is less than PixelsPerCentimeter than it is in the vaild range and can be safely
|
||||
* reinterpreted as `ResolutionType`
|
||||
*/
|
||||
if value <= bindings::ResolutionType_PixelsPerCentimeterResolution {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return ResolutionType::default();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user