Debian Codegraph @

third_party/rust/dwrote/src/types.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 /* this is include!()'d in lib.rs */
6 use std::mem;
7 use winapi::um::dwrite::{DWRITE_FONT_STYLE, DWRITE_FONT_WEIGHT, DWRITE_FONT_STRETCH};
8
9 // mirrors DWRITE_FONT_WEIGHT
10 #[cfg_attr(feature = "serde_serialization", derive(Deserialize, Serialize))]
11 #[derive(PartialEq, Debug, Clone, Copy)]
12 pub enum FontWeight {
13 Thin,
14 ExtraLight,
15 Light,
16 SemiLight,
17 Regular,
18 Medium,
19 SemiBold,
20 Bold,
21 ExtraBold,
22 Black,
23 ExtraBlack,
24 Unknown(u32)
25 }
26
27 impl FontWeight {
28 fn t(&self) -> DWRITE_FONT_WEIGHT {
29 unsafe { mem::transmute::<u32, DWRITE_FONT_WEIGHT>(self.to_u32()) }
30 }
31 pub fn to_u32(&self) -> u32 {
32 match self {
33 FontWeight::Thin=> 100,
34 FontWeight::ExtraLight=> 200,
35 FontWeight::Light=> 300,
36 FontWeight::SemiLight=> 350,
37 FontWeight::Regular=> 400,
38 FontWeight::Medium=> 500,
39 FontWeight::SemiBold=> 600,
40 FontWeight::Bold=> 700,
41 FontWeight::ExtraBold=> 800,
42 FontWeight::Black=> 900,
43 FontWeight::ExtraBlack=> 950,
44 FontWeight::Unknown(v) => *v as u32
45 }
46 }
47 pub fn from_u32(v: u32) -> FontWeight {
48 match v {
49 100 => FontWeight::Thin,
50 200 => FontWeight::ExtraLight,
51 300 => FontWeight::Light,
52 350 => FontWeight::SemiLight,
53 400 => FontWeight::Regular,
54 500 => FontWeight::Medium,
55 600 => FontWeight::SemiBold,
56 700 => FontWeight::Bold,
57 800 => FontWeight::ExtraBold,
58 900 => FontWeight::Black,
59 950 => FontWeight::ExtraBlack,
60 _ => FontWeight::Unknown(v)
61 }
62 }
63 }
64
65 // mirrors DWRITE_FONT_STRETCH
66 #[repr(u32)]
67 #[cfg_attr(feature = "serde_serialization", derive(Deserialize, Serialize))]
68 #[derive(PartialEq, Debug, Clone, Copy)]
69 pub enum FontStretch {
70 Undefined = 0,
71 UltraCondensed = 1,
72 ExtraCondensed = 2,
73 Condensed = 3,
74 SemiCondensed = 4,
75 Normal = 5,
76 SemiExpanded = 6,
77 Expanded = 7,
78 ExtraExpanded = 8,
79 UltraExpanded = 9,
80 }
81
82 impl FontStretch {
83 fn t(&self) -> DWRITE_FONT_STRETCH {
84 unsafe { mem::transmute::<FontStretch, DWRITE_FONT_STRETCH>(*self) }
85 }
86 pub fn to_u32(&self) -> u32 { unsafe { mem::transmute::<FontStretch, u32>(*self) } }
87 pub fn from_u32(v: u32) -> FontStretch { unsafe { mem::transmute::<u32, FontStretch>(v) } }
88 }
89
90 // mirrors DWRITE_FONT_STYLE
91 #[repr(u32)]
92 #[cfg_attr(feature = "serde_serialization", derive(Deserialize, Serialize))]
93 #[derive(PartialEq, Debug, Clone, Copy)]
94 pub enum FontStyle {
95 Normal = 0,
96 Oblique = 1,
97 Italic = 2,
98 }
99
100 impl FontStyle {
101 fn t(&self) -> DWRITE_FONT_STYLE {
102 unsafe { mem::transmute::<FontStyle, DWRITE_FONT_STYLE>(*self) }
103 }
104 pub fn to_u32(&self) -> u32 { unsafe { mem::transmute::<FontStyle, u32>(*self) } }
105 pub fn from_u32(v: u32) -> FontStyle { unsafe { mem::transmute::<u32, FontStyle>(v) } }
106 }
107
108 // mirrors DWRITE_FONT_SIMULATIONS
109 #[repr(u32)]
110 #[derive(PartialEq, Debug, Clone, Copy)]
111 pub enum FontSimulations {
112 None = winapi::um::dwrite::DWRITE_FONT_SIMULATIONS_NONE,
113 Bold = winapi::um::dwrite::DWRITE_FONT_SIMULATIONS_BOLD,
114 Oblique = winapi::um::dwrite::DWRITE_FONT_SIMULATIONS_OBLIQUE,
115 BoldOblique = winapi::um::dwrite::DWRITE_FONT_SIMULATIONS_BOLD |
116 winapi::um::dwrite::DWRITE_FONT_SIMULATIONS_OBLIQUE,
117 }
118
119 #[cfg_attr(feature = "serde_serialization", derive(Deserialize, Serialize))]
120 #[derive(PartialEq, Debug, Clone)]
121 pub struct FontDescriptor {
122 pub family_name: String,
123 pub weight: FontWeight,
124 pub stretch: FontStretch,
125 pub style: FontStyle,
126 }