1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// This file is auto-generated by rute_gen. DO NOT EDIT.
use std::cell::Cell;
use std::rc::Rc;
#[allow(unused_imports)]
use std::marker::PhantomData;
#[allow(unused_imports)]
use std::os::raw::c_void;
#[allow(unused_imports)]
use std::mem::transmute;
#[allow(unused_imports)]
use std::ffi::{CStr, CString};
use rute_ffi_base::*;
#[allow(unused_imports)]
use auto::*;
/// **Notice these docs are heavy WIP and not very relevent yet**
///
/// The QFontInfo class provides the same access functions as QFont,
/// e.g. family(), pointSize(), italic(), weight(), fixedPitch(),
/// styleHint() etc. But whilst the QFont access functions return the
/// values that were set, a QFontInfo object returns the values that
/// apply to the font that will actually be used to draw the text.
///
/// For example, when the program asks for a 25pt Courier font on a
/// machine that has a non-scalable 24pt Courier font, QFont will
/// (normally) use the 24pt Courier for rendering. In this case,
/// QFont::pointSize() returns 25 and QFontInfo::pointSize() returns
/// 24.
///
/// There are three ways to create a QFontInfo object.
/// * Calling the QFontInfo constructor with a QFont creates a font info object for a screen-compatible font, i.e. the font cannot be a printer font. If the font is changed later, the font info object is *not* updated. (Note: If you use a printer font the values returned may be inaccurate. Printer fonts are not always accessible so the nearest screen font is used if a printer font is supplied.)
/// * QWidget::fontInfo() returns the font info for a widget's font. This is equivalent to calling QFontInfo(widget->font()). If the widget's font is changed later, the font info object is *not* updated.
/// * QPainter::fontInfo() returns the font info for a painter's current font. If the painter's font is changed later, the font info object is *not* updated.
///
/// **See also:** QFont
/// QFontMetrics
/// QFontDatabase
/// # Licence
///
/// The documentation is an adoption of the original [Qt Documentation](http://doc.qt.io/) and provided herein is licensed under the terms of the [GNU Free Documentation License version 1.3](http://www.gnu.org/licenses/fdl.html) as published by the Free Software Foundation.
#[derive(Clone)]
pub struct FontInfo<'a> {
#[doc(hidden)]
pub data: Rc<Cell<Option<*const RUBase>>>,
#[doc(hidden)]
pub all_funcs: *const RUFontInfoAllFuncs,
#[doc(hidden)]
pub owned: bool,
#[doc(hidden)]
pub _marker: PhantomData<::std::cell::Cell<&'a ()>>,
}
impl<'a> FontInfo<'a> {
#[allow(dead_code)]
pub(crate) fn new_from_rc(ffi_data: RUFontInfo) -> FontInfo<'a> {
FontInfo {
data: unsafe { Rc::from_raw(ffi_data.host_data as *const Cell<Option<*const RUBase>>) },
all_funcs: ffi_data.all_funcs,
owned: false,
_marker: PhantomData,
}
}
#[allow(dead_code)]
pub(crate) fn new_from_owned(ffi_data: RUFontInfo) -> FontInfo<'a> {
FontInfo {
data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
all_funcs: ffi_data.all_funcs,
owned: true,
_marker: PhantomData,
}
}
#[allow(dead_code)]
pub(crate) fn new_from_temporary(ffi_data: RUFontInfo) -> FontInfo<'a> {
FontInfo {
data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
all_funcs: ffi_data.all_funcs,
owned: false,
_marker: PhantomData,
}
}
///
/// Swaps this font info instance with *other.* This function is very
/// fast and never fails.
pub fn swap<F: FontInfoTrait<'a>>(&self, other: &F) -> &Self {
let (obj_other_1, _funcs) = other.get_font_info_obj_funcs();
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
((*funcs).swap)(obj_data, obj_other_1);
}
self
}
///
/// Returns the family name of the matched window system font.
///
/// **See also:** QFont::family()
pub fn family(&self) -> String {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).family)(obj_data);
let ret_val = CStr::from_ptr(ret_val).to_string_lossy().into_owned();
ret_val
}
}
///
/// Returns the style name of the matched window system font on
/// systems that support it.
///
/// **See also:** QFont::styleName()
pub fn style_name(&self) -> String {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).style_name)(obj_data);
let ret_val = CStr::from_ptr(ret_val).to_string_lossy().into_owned();
ret_val
}
}
///
/// Returns the pixel size of the matched window system font.
///
/// **See also:** QFont::pointSize()
pub fn pixel_size(&self) -> i32 {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).pixel_size)(obj_data);
ret_val
}
}
///
/// Returns the point size of the matched window system font.
///
/// **See also:** pointSizeF()
/// QFont::pointSize()
///
/// Returns the point size of the matched window system font.
///
/// **See also:** QFont::pointSizeF()
pub fn point_size(&self) -> i32 {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).point_size)(obj_data);
ret_val
}
}
///
/// Returns the point size of the matched window system font.
///
/// **See also:** QFont::pointSizeF()
pub fn point_size_f(&self) -> f32 {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).point_size_f)(obj_data);
ret_val
}
}
///
/// Returns the italic value of the matched window system font.
///
/// **See also:** QFont::italic()
pub fn italic(&self) -> bool {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).italic)(obj_data);
ret_val
}
}
///
/// Returns the style name of the matched window system font on
/// systems that support it.
///
/// **See also:** QFont::styleName()
///
/// Returns the style value of the matched window system font.
///
/// **See also:** QFont::style()
///
/// Returns the style of the matched window system font.
///
/// Currently only returns the style hint set in QFont.
///
/// **See also:** QFont::styleHint()
/// QFont::StyleHint
///
/// Returns the weight of the matched window system font.
///
/// **See also:** QFont::weight()
/// bold()
pub fn weight(&self) -> i32 {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).weight)(obj_data);
ret_val
}
}
///
/// Returns `true` if weight() would return a value greater than
/// QFont::Normal; otherwise returns `false.`
///
/// **See also:** weight()
/// QFont::bold()
pub fn bold(&self) -> bool {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).bold)(obj_data);
ret_val
}
}
pub fn underline(&self) -> bool {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).underline)(obj_data);
ret_val
}
}
pub fn overline(&self) -> bool {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).overline)(obj_data);
ret_val
}
}
///
/// Returns the fixed pitch value of the matched window system font.
///
/// **See also:** QFont::fixedPitch()
pub fn fixed_pitch(&self) -> bool {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).fixed_pitch)(obj_data);
ret_val
}
}
///
/// Returns the style of the matched window system font.
///
/// Currently only returns the style hint set in QFont.
///
/// **See also:** QFont::styleHint()
/// QFont::StyleHint
pub fn style_hint(&self) -> StyleHint {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).style_hint)(obj_data);
let ret_val = StyleHint::from_bits_truncate(ret_val);
ret_val
}
}
///
/// Returns `true` if the font is a raw mode font; otherwise returns
/// false.
///
/// If it is a raw mode font, all other functions in QFontInfo will
/// return the same values set in the QFont, regardless of the font
/// actually used.
///
/// **See also:** QFont::rawMode()
pub fn raw_mode(&self) -> bool {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).raw_mode)(obj_data);
ret_val
}
}
///
/// Returns `true` if the matched window system font is exactly the same
/// as the one specified by the font; otherwise returns `false.`
///
/// **See also:** QFont::exactMatch()
pub fn exact_match(&self) -> bool {
let (obj_data, funcs) = self.get_font_info_obj_funcs();
unsafe {
let ret_val = ((*funcs).exact_match)(obj_data);
ret_val
}
}
pub fn build(&self) -> Self {
self.clone()
}
}
pub trait FontInfoTrait<'a> {
#[inline]
#[doc(hidden)]
fn get_font_info_obj_funcs(&self) -> (*const RUBase, *const RUFontInfoFuncs);
}
impl<'a> FontInfoTrait<'a> for FontInfo<'a> {
#[doc(hidden)]
fn get_font_info_obj_funcs(&self) -> (*const RUBase, *const RUFontInfoFuncs) {
let obj = self.data.get().unwrap();
unsafe { (obj, (*self.all_funcs).font_info_funcs) }
}
}