pango/coverage.rs
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
// Take a look at the license at the top of the repository in the LICENSE file.
use std::{mem, ptr};
use glib::translate::*;
use crate::{ffi, CoverageLevel};
#[cfg(feature = "v1_44")]
glib::wrapper! {
/// A [`Coverage`][crate::Coverage] structure is a map from Unicode characters
/// to [`CoverageLevel`][crate::CoverageLevel] values.
///
/// It is often necessary in Pango to determine if a particular
/// font can represent a particular character, and also how well
/// it can represent that character. The [`Coverage`][crate::Coverage] is a data
/// structure that is used to represent that information. It is an
/// opaque structure with no public fields.
#[doc(alias = "PangoCoverage")]
pub struct Coverage(Object<ffi::PangoCoverage>);
match fn {
type_ => || ffi::pango_coverage_get_type(),
}
}
// There was no get_type() function before 1.44
#[cfg(not(feature = "v1_44"))]
glib::wrapper! {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[doc(alias = "PangoCoverage")]
pub struct Coverage(Shared<ffi::PangoCoverage>);
match fn {
ref => |ptr| ffi::pango_coverage_ref(ptr),
unref => |ptr| ffi::pango_coverage_unref(ptr),
}
}
impl Coverage {
/// Create a new [`Coverage`][crate::Coverage]
///
/// # Returns
///
/// the newly allocated [`Coverage`][crate::Coverage], initialized
/// to [`CoverageLevel::None`][crate::CoverageLevel::None] with a reference count of one, which
/// should be freed with `Pango::Coverage::unref()`.
#[doc(alias = "pango_coverage_new")]
pub fn new() -> Self {
unsafe { from_glib_full(ffi::pango_coverage_new()) }
}
#[doc(alias = "pango_coverage_copy")]
pub fn copy(&self) -> Option<Coverage> {
unsafe { from_glib_full(ffi::pango_coverage_copy(self.to_glib_none().0)) }
}
/// Determine whether a particular index is covered by @self.
/// ## `index_`
/// the index to check
///
/// # Returns
///
/// the coverage level of @self for character @index_.
#[doc(alias = "pango_coverage_get")]
pub fn get(&self, index_: i32) -> CoverageLevel {
unsafe { from_glib(ffi::pango_coverage_get(self.to_glib_none().0, index_)) }
}
/// Set the coverage for each index in @self to be the max (better)
/// value of the current coverage for the index and the coverage for
/// the corresponding index in @other.
///
/// # Deprecated since 1.44
///
/// This function does nothing
/// ## `other`
/// another [`Coverage`][crate::Coverage]
#[cfg_attr(feature = "v1_44", deprecated)]
#[doc(alias = "pango_coverage_max")]
pub fn max(&self, other: &Coverage) {
unsafe {
ffi::pango_coverage_max(self.to_glib_none().0, other.to_glib_none().0);
}
}
/// Modify a particular index within @self
/// ## `index_`
/// the index to modify
/// ## `level`
/// the new level for @index_
#[doc(alias = "pango_coverage_set")]
pub fn set(&self, index_: i32, level: CoverageLevel) {
unsafe {
ffi::pango_coverage_set(self.to_glib_none().0, index_, level.into_glib());
}
}
/// Convert a [`Coverage`][crate::Coverage] structure into a flat binary format.
///
/// # Deprecated since 1.44
///
/// This returns [`None`]
///
/// # Returns
///
///
/// ## `bytes`
///
/// location to store result (must be freed with g_free())
#[cfg_attr(feature = "v1_44", deprecated)]
#[doc(alias = "pango_coverage_to_bytes")]
pub fn to_bytes(&self) -> Vec<u8> {
unsafe {
let mut bytes = ptr::null_mut();
let mut n_bytes = mem::MaybeUninit::uninit();
ffi::pango_coverage_to_bytes(self.to_glib_none().0, &mut bytes, n_bytes.as_mut_ptr());
FromGlibContainer::from_glib_full_num(bytes, n_bytes.assume_init() as usize)
}
}
/// Convert data generated from [`to_bytes()`][Self::to_bytes()]
/// back to a [`Coverage`][crate::Coverage].
///
/// # Deprecated since 1.44
///
/// This returns [`None`]
/// ## `bytes`
/// binary data
/// representing a [`Coverage`][crate::Coverage]
///
/// # Returns
///
/// a newly allocated [`Coverage`][crate::Coverage]
#[cfg_attr(feature = "v1_44", deprecated)]
#[doc(alias = "pango_coverage_from_bytes")]
pub fn from_bytes(bytes: &[u8]) -> Option<Coverage> {
let n_bytes = bytes.len() as i32;
unsafe {
from_glib_full(ffi::pango_coverage_from_bytes(
bytes.to_glib_none().0,
n_bytes,
))
}
}
}
impl Default for Coverage {
fn default() -> Self {
Self::new()
}
}