@@ -54,7 +54,7 @@ use sys::statics::{LIB, LIB_RESULT};
54
54
#[ cfg( not( feature = "dlopen" ) ) ]
55
55
use sys:: * ;
56
56
57
- use std:: ffi:: { CStr , CString } ;
57
+ use std:: ffi:: { c_int , CStr , CString } ;
58
58
use std:: marker:: PhantomData ;
59
59
use std:: mem;
60
60
use std:: os:: raw:: c_char;
@@ -199,7 +199,7 @@ impl<'fc> Pattern<'fc> {
199
199
Pattern { pat, fc }
200
200
}
201
201
202
- /// Add a key-value pair to this pattern.
202
+ /// Add a key-value pair of type `String` to this pattern.
203
203
///
204
204
/// See useful keys in the [fontconfig reference][1].
205
205
///
@@ -216,6 +216,17 @@ impl<'fc> Pattern<'fc> {
216
216
}
217
217
}
218
218
219
+ /// Add a key-value pair of type `Int` to this pattern
220
+ ///
221
+ /// See useful keys in the [fontconfig reference][1].
222
+ ///
223
+ /// [1]: http://www.freedesktop.org/software/fontconfig/fontconfig-devel/x19.html
224
+ pub fn add_integer ( & mut self , name : & CStr , val : c_int ) {
225
+ unsafe {
226
+ ffi_dispatch ! ( LIB , FcPatternAddInteger , self . pat, name. as_ptr( ) , val) ;
227
+ }
228
+ }
229
+
219
230
/// Get string the value for a key from this pattern.
220
231
pub fn get_string < ' a > ( & ' a self , name : & ' a CStr ) -> Option < & ' a str > {
221
232
unsafe {
@@ -511,6 +522,31 @@ pub fn list_fonts<'fc>(pattern: &Pattern<'fc>, objects: Option<&ObjectSet>) -> F
511
522
}
512
523
}
513
524
525
+ /// Returns a [`FontSet`] containing fonts sorted by closeness to the supplied `pattern`. If `trim` is true, elements in
526
+ /// the list which don't include Unicode coverage not provided by earlier elements in the list are elided.
527
+ ///
528
+ /// See the [fontconfig reference][1] for more details.
529
+ ///
530
+ /// [1]: https://www.freedesktop.org/software/fontconfig/fontconfig-devel/fcfontsort.html
531
+ pub fn sort_fonts < ' fc > ( pattern : & Pattern < ' fc > , trim : bool ) -> FontSet < ' fc > {
532
+ // FcFontSort always returns a (possibly empty) set so we don't need to check this.
533
+ let mut res = sys:: FcResultNoMatch ;
534
+ let unicode_coverage = ptr:: null_mut ( ) ;
535
+ let config = ptr:: null_mut ( ) ;
536
+ unsafe {
537
+ let raw_set = ffi_dispatch ! (
538
+ LIB ,
539
+ FcFontSort ,
540
+ config,
541
+ pattern. pat,
542
+ trim as FcBool ,
543
+ unicode_coverage,
544
+ & mut res
545
+ ) ;
546
+ FontSet :: from_raw ( pattern. fc , raw_set)
547
+ }
548
+ }
549
+
514
550
/// Wrapper around `FcObjectSet`.
515
551
pub struct ObjectSet {
516
552
fcset : * mut sys:: FcObjectSet ,
0 commit comments