Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit e8de622

Browse files
Velislava Yanchinaromanzes
Velislava Yanchina
authored andcommitted
bind
1 parent 0e38042 commit e8de622

File tree

5 files changed

+95
-4
lines changed

5 files changed

+95
-4
lines changed

Gir.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ single_version_file = true
1010
deprecate_by_min_version = true
1111

1212
generate = [
13-
# "Pango.AttrColor",
1413
# "Pango.AttrFloat",
1514
# "Pango.AttrFontDesc",
1615
# "Pango.AttrFontFeatures",
@@ -72,6 +71,7 @@ manual = [
7271
"GLib.Error",
7372
"Pango.Analysis",
7473
"Pango.AttrClass",
74+
"Pango.AttrColor",
7575
"Pango.Language",
7676
"Pango.Rectangle",
7777
]

src/analysis.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
use glib::translate::*;
66
use pango_sys;
7+
use Attribute;
78
use EngineLang;
89
use EngineShape;
910
use Font;
1011
use Gravity;
1112
use Language;
1213
use Script;
14+
use pango_sys::{PangoAttribute, PangoAttrColor, PangoColor};
1315

1416
#[repr(C)]
1517
pub struct Analysis(pango_sys::PangoAnalysis);
@@ -47,9 +49,11 @@ impl Analysis {
4749
unsafe { from_glib_none(self.0.language) }
4850
}
4951

50-
/*pub fn extra_attrs(&self) -> Vec<LogAttr> {
51-
unsafe { from_glib_none_num_as_vec(self.0.extra_attrs) }
52-
}*/
52+
pub fn extra_attrs(&self) -> Vec<Attribute> {
53+
unsafe {
54+
FromGlibPtrContainer::from_glib_none(self.0.extra_attrs)
55+
}
56+
}
5357
}
5458

5559
#[doc(hidden)]

src/attr_class.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// See the COPYRIGHT file at the top-level directory of this distribution.
33
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
44

5+
use AttrType;
6+
use glib::translate::from_glib;
57
use glib::translate::{FromGlibPtrFull, FromGlibPtrNone, Stash, ToGlibPtr};
68
use pango_sys;
79

@@ -46,8 +48,15 @@ impl FromGlibPtrFull<*const pango_sys::PangoAttrClass> for AttrClass {
4648
}
4749
}
4850

51+
#[derive(Debug)]
4952
pub struct AttrClass(*mut pango_sys::PangoAttrClass);
5053

54+
impl AttrClass {
55+
pub fn get_type(&self) -> AttrType {
56+
unsafe{ from_glib((*self.0).type_) }
57+
}
58+
}
59+
5160
impl PartialEq for AttrClass {
5261
fn eq(&self, other: &AttrClass) -> bool {
5362
self.0 == other.0

src/attr_color.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use glib::translate::from_glib_none;
2+
use glib::translate::from_glib_full;
3+
use glib::translate::{FromGlibPtrFull, FromGlibPtrNone, Stash, ToGlibPtr};
4+
use pango_sys;
5+
use Attribute;
6+
use Color;
7+
8+
#[doc(hidden)]
9+
impl<'a> ToGlibPtr<'a, *mut pango_sys::PangoAttrColor> for &'a AttrColor {
10+
type Storage = &'a AttrColor;
11+
12+
fn to_glib_none(&self) -> Stash<'a, *mut pango_sys::PangoAttrColor, Self> {
13+
Stash(self.0, *self)
14+
}
15+
}
16+
17+
#[doc(hidden)]
18+
impl FromGlibPtrNone<*mut pango_sys::PangoAttrColor> for AttrColor {
19+
unsafe fn from_glib_none(ptr: *mut pango_sys::PangoAttrColor) -> Self {
20+
assert!(!ptr.is_null());
21+
AttrColor(ptr)
22+
}
23+
}
24+
25+
#[doc(hidden)]
26+
impl FromGlibPtrFull<*mut pango_sys::PangoAttrColor> for AttrColor {
27+
unsafe fn from_glib_full(ptr: *mut pango_sys::PangoAttrColor) -> Self {
28+
assert!(!ptr.is_null());
29+
AttrColor(ptr)
30+
}
31+
}
32+
33+
#[doc(hidden)]
34+
impl FromGlibPtrNone<*const pango_sys::PangoAttrColor> for AttrColor {
35+
unsafe fn from_glib_none(ptr: *const pango_sys::PangoAttrColor) -> Self {
36+
assert!(!ptr.is_null());
37+
AttrColor(ptr as *mut _)
38+
}
39+
}
40+
41+
#[doc(hidden)]
42+
impl FromGlibPtrFull<*const pango_sys::PangoAttrColor> for AttrColor {
43+
unsafe fn from_glib_full(ptr: *const pango_sys::PangoAttrColor) -> Self {
44+
assert!(!ptr.is_null());
45+
AttrColor(ptr as *mut _)
46+
}
47+
}
48+
49+
#[derive(Debug)]
50+
pub struct AttrColor(*mut pango_sys::PangoAttrColor);
51+
52+
impl AttrColor {
53+
pub fn get_color(&self) -> Color {
54+
unsafe {
55+
let color: *const pango_sys::PangoColor = &(*self.0).color;
56+
from_glib_none(color)
57+
}
58+
}
59+
}
60+
61+
impl From<Attribute> for AttrColor {
62+
fn from(attribute: Attribute) -> Self {
63+
unsafe {
64+
let attr_color = std::mem::transmute::<*const pango_sys::PangoAttribute, *const pango_sys::PangoAttrColor>(attribute.to_glib_none().0);
65+
from_glib_full(attr_color)
66+
}
67+
}
68+
}
69+
70+
impl PartialEq for AttrColor {
71+
fn eq(&self, other: &AttrColor) -> bool {
72+
self.0 == other.0
73+
}
74+
}
75+
76+
impl Eq for AttrColor {}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub mod analysis;
3333
pub use analysis::Analysis;
3434
pub mod attr_class;
3535
pub use attr_class::AttrClass;
36+
pub mod attr_color;
37+
pub use attr_color::AttrColor;
3638
pub mod attr_iterator;
3739
pub mod attr_list;
3840
pub mod attribute;

0 commit comments

Comments
 (0)