1use glib;
6use glib::translate::*;
7use glib::GString;
8use pango_sys;
9use std::mem;
10use std::ptr;
11use Analysis;
12use AttrIterator;
13use AttrList;
14use Context;
15use Direction;
16use Error;
17use GlyphString;
18use Item;
19use Rectangle;
20use Stretch;
21use Style;
22use Variant;
23use Weight;
24
25#[cfg_attr(feature = "v1_38", deprecated)]
30pub fn config_key_get(key: &str) -> Option<GString> {
31 unsafe { from_glib_full(pango_sys::pango_config_key_get(key.to_glib_none().0)) }
32}
33
34#[cfg_attr(feature = "v1_38", deprecated)]
35pub fn config_key_get_system(key: &str) -> Option<GString> {
36 unsafe { from_glib_full(pango_sys::pango_config_key_get_system(key.to_glib_none().0)) }
37}
38
39pub fn extents_to_pixels(inclusive: Option<&Rectangle>, nearest: Option<&Rectangle>) {
44 unsafe {
45 pango_sys::pango_extents_to_pixels(
46 mut_override(inclusive.to_glib_none().0),
47 mut_override(nearest.to_glib_none().0),
48 );
49 }
50}
51
52pub fn find_base_dir(text: &str) -> Direction {
53 let length = text.len() as i32;
54 unsafe {
55 from_glib(pango_sys::pango_find_base_dir(
56 text.to_glib_none().0,
57 length,
58 ))
59 }
60}
61
62pub fn find_paragraph_boundary(text: &str) -> (i32, i32) {
68 let length = text.len() as i32;
69 unsafe {
70 let mut paragraph_delimiter_index = mem::uninitialized();
71 let mut next_paragraph_start = mem::uninitialized();
72 pango_sys::pango_find_paragraph_boundary(
73 text.to_glib_none().0,
74 length,
75 &mut paragraph_delimiter_index,
76 &mut next_paragraph_start,
77 );
78 (paragraph_delimiter_index, next_paragraph_start)
79 }
80}
81
82#[cfg_attr(feature = "v1_38", deprecated)]
83pub fn get_lib_subdirectory() -> Option<GString> {
84 unsafe { from_glib_none(pango_sys::pango_get_lib_subdirectory()) }
85}
86
87#[cfg_attr(feature = "v1_38", deprecated)]
92pub fn get_sysconf_subdirectory() -> Option<GString> {
93 unsafe { from_glib_none(pango_sys::pango_get_sysconf_subdirectory()) }
94}
95
96pub fn is_zero_width(ch: char) -> bool {
97 unsafe { from_glib(pango_sys::pango_is_zero_width(ch.to_glib())) }
98}
99
100pub fn itemize(
101 context: &Context,
102 text: &str,
103 start_index: i32,
104 length: i32,
105 attrs: &AttrList,
106 cached_iter: Option<&AttrIterator>,
107) -> Vec<Item> {
108 unsafe {
109 FromGlibPtrContainer::from_glib_full(pango_sys::pango_itemize(
110 context.to_glib_none().0,
111 text.to_glib_none().0,
112 start_index,
113 length,
114 attrs.to_glib_none().0,
115 mut_override(cached_iter.to_glib_none().0),
116 ))
117 }
118}
119
120pub fn itemize_with_base_dir(
121 context: &Context,
122 base_dir: Direction,
123 text: &str,
124 start_index: i32,
125 length: i32,
126 attrs: &AttrList,
127 cached_iter: Option<&AttrIterator>,
128) -> Vec<Item> {
129 unsafe {
130 FromGlibPtrContainer::from_glib_full(pango_sys::pango_itemize_with_base_dir(
131 context.to_glib_none().0,
132 base_dir.to_glib(),
133 text.to_glib_none().0,
134 start_index,
135 length,
136 attrs.to_glib_none().0,
137 mut_override(cached_iter.to_glib_none().0),
138 ))
139 }
140}
141
142#[cfg_attr(feature = "v1_38", deprecated)]
156pub fn parse_enum(
157 type_: glib::types::Type,
158 str: Option<&str>,
159 warn: bool,
160) -> Option<(i32, GString)> {
161 unsafe {
162 let mut value = mem::uninitialized();
163 let mut possible_values = ptr::null_mut();
164 let ret = from_glib(pango_sys::pango_parse_enum(
165 type_.to_glib(),
166 str.to_glib_none().0,
167 &mut value,
168 warn.to_glib(),
169 &mut possible_values,
170 ));
171 if ret {
172 Some((value, from_glib_full(possible_values)))
173 } else {
174 None
175 }
176 }
177}
178
179pub fn parse_markup(
180 markup_text: &str,
181 accel_marker: char,
182) -> Result<(AttrList, GString, char), Error> {
183 let length = markup_text.len() as i32;
184 unsafe {
185 let mut attr_list = ptr::null_mut();
186 let mut text = ptr::null_mut();
187 let mut accel_char = mem::uninitialized();
188 let mut error = ptr::null_mut();
189 let _ = pango_sys::pango_parse_markup(
190 markup_text.to_glib_none().0,
191 length,
192 accel_marker.to_glib(),
193 &mut attr_list,
194 &mut text,
195 &mut accel_char,
196 &mut error,
197 );
198 if error.is_null() {
199 Ok((
200 from_glib_full(attr_list),
201 from_glib_full(text),
202 from_glib(accel_char),
203 ))
204 } else {
205 Err(from_glib_full(error))
206 }
207 }
208}
209
210pub fn parse_stretch(str: &str, warn: bool) -> Option<Stretch> {
211 unsafe {
212 let mut stretch = mem::uninitialized();
213 let ret = from_glib(pango_sys::pango_parse_stretch(
214 str.to_glib_none().0,
215 &mut stretch,
216 warn.to_glib(),
217 ));
218 if ret {
219 Some(from_glib(stretch))
220 } else {
221 None
222 }
223 }
224}
225
226pub fn parse_style(str: &str, warn: bool) -> Option<Style> {
227 unsafe {
228 let mut style = mem::uninitialized();
229 let ret = from_glib(pango_sys::pango_parse_style(
230 str.to_glib_none().0,
231 &mut style,
232 warn.to_glib(),
233 ));
234 if ret {
235 Some(from_glib(style))
236 } else {
237 None
238 }
239 }
240}
241
242pub fn parse_variant(str: &str, warn: bool) -> Option<Variant> {
243 unsafe {
244 let mut variant = mem::uninitialized();
245 let ret = from_glib(pango_sys::pango_parse_variant(
246 str.to_glib_none().0,
247 &mut variant,
248 warn.to_glib(),
249 ));
250 if ret {
251 Some(from_glib(variant))
252 } else {
253 None
254 }
255 }
256}
257
258pub fn parse_weight(str: &str, warn: bool) -> Option<Weight> {
259 unsafe {
260 let mut weight = mem::uninitialized();
261 let ret = from_glib(pango_sys::pango_parse_weight(
262 str.to_glib_none().0,
263 &mut weight,
264 warn.to_glib(),
265 ));
266 if ret {
267 Some(from_glib(weight))
268 } else {
269 None
270 }
271 }
272}
273
274pub fn quantize_line_geometry(thickness: &mut i32, position: &mut i32) {
275 unsafe {
276 pango_sys::pango_quantize_line_geometry(thickness, position);
277 }
278}
279
280pub fn shape(text: &str, analysis: &Analysis, glyphs: &mut GlyphString) {
301 let length = text.len() as i32;
302 unsafe {
303 pango_sys::pango_shape(
304 text.to_glib_none().0,
305 length,
306 analysis.to_glib_none().0,
307 glyphs.to_glib_none_mut().0,
308 );
309 }
310}
311
312#[cfg_attr(feature = "v1_38", deprecated)]
318pub fn split_file_list(str: &str) -> Vec<GString> {
319 unsafe {
320 FromGlibPtrContainer::from_glib_full(pango_sys::pango_split_file_list(str.to_glib_none().0))
321 }
322}
323
324#[cfg_attr(feature = "v1_38", deprecated)]
325pub fn trim_string(str: &str) -> Option<GString> {
326 unsafe { from_glib_full(pango_sys::pango_trim_string(str.to_glib_none().0)) }
327}
328
329pub fn unichar_direction(ch: char) -> Direction {
330 unsafe { from_glib(pango_sys::pango_unichar_direction(ch.to_glib())) }
331}
332
333pub fn units_from_double(d: f64) -> i32 {
334 unsafe { pango_sys::pango_units_from_double(d) }
335}
336
337pub fn units_to_double(i: i32) -> f64 {
338 unsafe { pango_sys::pango_units_to_double(i) }
339}
340
341pub fn version() -> i32 {
342 unsafe { pango_sys::pango_version() }
343}
344
345pub fn version_check(
346 required_major: i32,
347 required_minor: i32,
348 required_micro: i32,
349) -> Option<GString> {
350 unsafe {
351 from_glib_none(pango_sys::pango_version_check(
352 required_major,
353 required_minor,
354 required_micro,
355 ))
356 }
357}
358
359pub fn version_string() -> Option<GString> {
360 unsafe { from_glib_none(pango_sys::pango_version_string()) }
361}