Skip to content

Commit

Permalink
Merge pull request #846 from gtk-rs/bilelmoussaoui/backport-language
Browse files Browse the repository at this point in the history
pango: Backport Language changes
  • Loading branch information
sdroege authored Dec 5, 2022
2 parents 2bcc9a1 + edf607e commit 81ac6fc
Show file tree
Hide file tree
Showing 26 changed files with 225 additions and 134 deletions.
2 changes: 1 addition & 1 deletion cairo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["The gtk-rs Project Developers"]
keywords = ["cairo", "gtk-rs", "gnome", "GUI"]
readme = "README.md"
documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/cairo/"
version = "0.16.4"
version = "0.16.5"
description = "Rust bindings for the Cairo library"
repository = "https://github.com/gtk-rs/gtk-rs-core"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion cairo/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ license = "MIT"
authors = ["The gtk-rs Project Developers"]
homepage = "https://gtk-rs.org/"
description = "FFI bindings to libcairo"
version = "0.16.4"
version = "0.16.5"
keywords = ["cairo", "ffi", "gtk-rs", "gnome"]
repository = "https://github.com/gtk-rs/gtk-rs-core"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["The gtk-rs Project Developers"]
keywords = ["gdk-pixbuf", "gtk-rs", "gnome"]
readme = "README.md"
documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gdk_pixbuf/"
version = "0.16.4"
version = "0.16.5"
description = "Rust bindings for the GdkPixbuf library"
repository = "https://github.com/gtk-rs/gtk-rs-core"
exclude = [
Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ keywords = ["gdk-pixbuf", "ffi", "gtk-rs", "gnome"]
license = "MIT"
name = "gdk-pixbuf-sys"
repository = "https://github.com/gtk-rs/gtk-rs-core"
version = "0.16.4"
version = "0.16.5"
edition = "2021"
rust-version = "1.63"
[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion gio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["The gtk-rs Project Developers"]
keywords = ["glib", "gio", "gtk-rs", "gnome"]
readme = "README.md"
documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gio/"
version = "0.16.4"
version = "0.16.5"
description = "Rust bindings for the Gio library"
repository = "https://github.com/gtk-rs/gtk-rs-core"
exclude = [
Expand Down
2 changes: 1 addition & 1 deletion gio/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ keywords = ["gio", "ffi", "gtk-rs", "gnome"]
license = "MIT"
name = "gio-sys"
repository = "https://github.com/gtk-rs/gtk-rs-core"
version = "0.16.4"
version = "0.16.5"
edition = "2021"
rust-version = "1.63"
[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion glib-build-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["The gtk-rs Project Developers"]
keywords = ["glib", "gio", "gtk-rs", "gnome", "build-dependencies"]
readme = "README.md"
documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/glib-build-tools"
version = "0.16.4"
version = "0.16.5"
description = "Rust bindings for the Gio library, build script utils crate"
repository = "https://github.com/gtk-rs/gtk-rs-core"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion glib-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/glib_macros/"
homepage = "https://gtk-rs.org/"
authors = ["The gtk-rs Project Developers"]
description = "Rust bindings for the GLib library, proc macros crate"
version = "0.16.4"
version = "0.16.5"
keywords = ["glib", "gtk-rs", "gnome", "GUI"]
repository = "https://github.com/gtk-rs/gtk-rs-core"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion glib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ homepage = "https://gtk-rs.org/"
authors = ["The gtk-rs Project Developers"]
description = "Rust bindings for the GLib library"
readme = "README.md"
version = "0.16.4"
version = "0.16.5"
keywords = ["glib", "gtk-rs", "gnome", "GUI"]
repository = "https://github.com/gtk-rs/gtk-rs-core"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion glib/gobject-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ keywords = ["gobject", "ffi", "gtk-rs", "gnome"]
license = "MIT"
name = "gobject-sys"
repository = "https://github.com/gtk-rs/gtk-rs-core"
version = "0.16.4"
version = "0.16.5"
edition = "2021"
rust-version = "1.63"
[package.metadata.docs.rs]
Expand Down
4 changes: 2 additions & 2 deletions glib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub use self::bytes::Bytes;
pub use self::closure::{Closure, RustClosure};
pub use self::error::{BoolError, Error};
pub use self::object::{
BorrowedObject, Cast, Class, InitiallyUnowned, Interface, IsA, Object, ObjectExt, ObjectType,
SendWeakRef, WeakRef,
BorrowedObject, Cast, CastNone, Class, InitiallyUnowned, Interface, IsA, Object, ObjectExt,
ObjectType, SendWeakRef, WeakRef,
};
pub use self::signal::{
signal_handler_block, signal_handler_disconnect, signal_handler_unblock,
Expand Down
73 changes: 73 additions & 0 deletions glib/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,79 @@ pub trait Cast: ObjectType {

impl<T: ObjectType> Cast for T {}

// rustdoc-stripper-ignore-next
/// Convenience trait mirroring `Cast`, implemented on `Option<Object>` types.
///
/// # Warning
/// Inveitably this trait will discard informations about a downcast failure:
/// you don't know if the object was not of the expected type, or if it was `None`.
/// If you need to handle the downcast error, use `Cast` over a `glib::Object`.
///
/// # Example
/// ```ignore
/// let widget: Option<Widget> = list_item.child();
///
/// // Without using `CastNone`
/// let label = widget.unwrap().downcast::<gtk::Label>().unwrap();
///
/// // Using `CastNone` we can avoid the first `unwrap()` call
/// let label = widget.and_downcast::<gtk::Label>().unwrap();
/// ````
pub trait CastNone: Sized {
type Inner;
fn and_downcast<T: ObjectType>(self) -> Option<T>
where
Self::Inner: CanDowncast<T>;
fn and_downcast_ref<T: ObjectType>(&self) -> Option<&T>
where
Self::Inner: CanDowncast<T>;
fn and_upcast<T: ObjectType>(self) -> Option<T>
where
Self::Inner: IsA<T>;
fn and_upcast_ref<T: ObjectType>(&self) -> Option<&T>
where
Self::Inner: IsA<T>;
fn and_dynamic_cast<T: ObjectType>(self) -> Result<T, Self>;
fn and_dynamic_cast_ref<T: ObjectType>(&self) -> Option<&T>;
}
impl<I: ObjectType + Sized> CastNone for Option<I> {
type Inner = I;

fn and_downcast<T: ObjectType>(self) -> Option<T>
where
Self::Inner: CanDowncast<T>,
{
self.and_then(|i| i.downcast().ok())
}

fn and_downcast_ref<T: ObjectType>(&self) -> Option<&T>
where
Self::Inner: CanDowncast<T>,
{
self.as_ref().and_then(|i| i.downcast_ref())
}
fn and_upcast<T: ObjectType>(self) -> Option<T>
where
Self::Inner: IsA<T>,
{
self.map(|i| i.upcast())
}

fn and_upcast_ref<T: ObjectType>(&self) -> Option<&T>
where
Self::Inner: IsA<T>,
{
self.as_ref().map(|i| i.upcast_ref())
}
fn and_dynamic_cast<T: ObjectType>(self) -> Result<T, Self> {
self.ok_or(None)
.and_then(|i| i.dynamic_cast().map_err(|e| Some(e)))
}
fn and_dynamic_cast_ref<T: ObjectType>(&self) -> Option<&T> {
self.as_ref().and_then(|i| i.dynamic_cast_ref())
}
}

// rustdoc-stripper-ignore-next
/// Marker trait for the statically known possibility of downcasting from `Self` to `T`.
pub trait CanDowncast<T> {}
Expand Down
2 changes: 1 addition & 1 deletion glib/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
pub use crate::param_spec::ParamSpecBuilderExt;
pub use crate::{
Cast, Continue, IsA, ObjectExt, ObjectType, ParamSpecType, StaticType, StaticTypeExt,
Cast, CastNone, Continue, IsA, ObjectExt, ObjectType, ParamSpecType, StaticType, StaticTypeExt,
StaticVariantType, ToSendValue, ToValue, ToVariant,
};
2 changes: 1 addition & 1 deletion glib/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ keywords = ["glib", "ffi", "gtk-rs", "gnome"]
license = "MIT"
name = "glib-sys"
repository = "https://github.com/gtk-rs/gtk-rs-core"
version = "0.16.4"
version = "0.16.5"
edition = "2021"
rust-version = "1.63"
[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion graphene/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["The gtk-rs Project Developers"]
keywords = ["graphene", "graphene-rs", "gtk-rs", "gnome", "GUI"]
readme = "README.md"
documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/graphene/"
version = "0.16.4"
version = "0.16.5"
description = "Rust bindings for the Graphene library"
repository = "https://github.com/gtk-rs/gtk-rs-core"
exclude = [
Expand Down
2 changes: 1 addition & 1 deletion graphene/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ keywords = ["graphene", "ffi", "gtk-rs", "gnome"]
license = "MIT"
name = "graphene-sys"
repository = "https://github.com/gtk-rs/gtk-rs-core"
version = "0.16.4"
version = "0.16.5"
edition = "2021"
rust-version = "1.63"
[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion pango/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ homepage = "https://gtk-rs.org/"
authors = ["The gtk-rs Project Developers"]
keywords = ["pango", "gtk-rs", "gnome"]
readme = "README.md"
version = "0.16.4"
version = "0.16.5"
description = "Rust bindings for the Pango library"
repository = "https://github.com/gtk-rs/gtk-rs-core"
license = "MIT"
Expand Down
21 changes: 20 additions & 1 deletion pango/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ manual = [
"Pango.Coverage",
"Pango.GlyphGeometry",
"Pango.GlyphInfo",
"Pango.Language",
"Pango.LayoutDeserializeError",
"Pango.Rectangle",
]
Expand Down Expand Up @@ -332,6 +331,26 @@ concurrency = "send+sync"
name = "glyphs"
const = true

[[object]]
name = "Pango.Language"
status = "generate"
[[object.function]]
pattern = "get_(scripts|preferred)"
manual = true # probably needs annotation fixes upstream (array zero-terminated=1)
[[object.function]]
pattern = "(get_sample_string|includes_script|matches|to_string)"
[[object.function.parameter]]
name = "language"
const = true
[[object.function]]
name = "from_string"
# This only returns NULL when passing NULL
[[object.function.parameter]]
name = "language"
nullable = false
[object.function.return]
nullable = false

[[object]]
name = "Pango.Layout"
status = "generate"
Expand Down
6 changes: 5 additions & 1 deletion pango/src/attr_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ define_attribute_struct!(AttrLanguage, ffi::PangoAttrLanguage, &[AttrType::Langu
impl AttrLanguage {
#[doc(alias = "pango_attr_language_new")]
pub fn new(language: &Language) -> Self {
unsafe { from_glib_full(ffi::pango_attr_language_new(language.to_glib_none().0)) }
unsafe {
from_glib_full(ffi::pango_attr_language_new(mut_override(
language.to_glib_none().0,
)))
}
}

pub fn value(&self) -> Language {
Expand Down
79 changes: 79 additions & 0 deletions pango/src/auto/language.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Script;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Language(Boxed<ffi::PangoLanguage>);

match fn {
copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::pango_language_get_type(), ptr as *mut _) as *mut ffi::PangoLanguage,
free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::pango_language_get_type(), ptr as *mut _),
type_ => || ffi::pango_language_get_type(),
}
}

impl Language {
#[doc(alias = "pango_language_get_sample_string")]
#[doc(alias = "get_sample_string")]
pub fn sample_string(&self) -> glib::GString {
unsafe {
from_glib_none(ffi::pango_language_get_sample_string(mut_override(
self.to_glib_none().0,
)))
}
}

#[doc(alias = "pango_language_includes_script")]
pub fn includes_script(&self, script: Script) -> bool {
unsafe {
from_glib(ffi::pango_language_includes_script(
mut_override(self.to_glib_none().0),
script.into_glib(),
))
}
}

#[doc(alias = "pango_language_matches")]
pub fn matches(&self, range_list: &str) -> bool {
unsafe {
from_glib(ffi::pango_language_matches(
mut_override(self.to_glib_none().0),
range_list.to_glib_none().0,
))
}
}

#[doc(alias = "pango_language_to_string")]
#[doc(alias = "to_string")]
pub fn to_str(&self) -> glib::GString {
unsafe {
from_glib_none(ffi::pango_language_to_string(mut_override(
self.to_glib_none().0,
)))
}
}

#[doc(alias = "pango_language_from_string")]
pub fn from_string(language: &str) -> Language {
unsafe { from_glib_none(ffi::pango_language_from_string(language.to_glib_none().0)) }
}

#[doc(alias = "pango_language_get_default")]
#[doc(alias = "get_default")]
#[allow(clippy::should_implement_trait)]
pub fn default() -> Language {
unsafe { from_glib_none(ffi::pango_language_get_default()) }
}
}

impl fmt::Display for Language {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_str())
}
}
3 changes: 3 additions & 0 deletions pango/src/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub use self::glyph_string::GlyphString;
mod item;
pub use self::item::Item;

mod language;
pub use self::language::Language;

mod layout_iter;
pub use self::layout_iter::LayoutIter;

Expand Down
Loading

0 comments on commit 81ac6fc

Please sign in to comment.