autocommit 2022-03-23 15:56:15 CET
This commit is contained in:
parent
63be47a9fb
commit
5e9e8c3a94
9 changed files with 479 additions and 290 deletions
244
Cargo.lock
generated
244
Cargo.lock
generated
|
|
@ -116,45 +116,12 @@ version = "1.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cairo-rs"
|
|
||||||
version = "0.15.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "129e928d3eda625f53ce257589efbe5143416875fd01bddd08c8c6feb8b9962b"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cairo-sys-rs",
|
|
||||||
"glib",
|
|
||||||
"libc",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cairo-sys-rs"
|
|
||||||
version = "0.15.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3c55d429bef56ac9172d25fecb85dc8068307d17acd74b377866b7a1ef25d3c8"
|
|
||||||
dependencies = [
|
|
||||||
"glib-sys",
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.72"
|
version = "1.0.72"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-expr"
|
|
||||||
version = "0.10.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5e068cb2806bbc15b439846dc16c5f89f8599f2c3e4d73d4449d38f9b2f0b6c5"
|
|
||||||
dependencies = [
|
|
||||||
"smallvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
|
|
@ -202,32 +169,12 @@ dependencies = [
|
||||||
"termcolor",
|
"termcolor",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-channel"
|
|
||||||
version = "0.3.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
|
|
||||||
dependencies = [
|
|
||||||
"futures-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-core"
|
name = "futures-core"
|
||||||
version = "0.3.21"
|
version = "0.3.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
|
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-executor"
|
|
||||||
version = "0.3.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
|
|
||||||
dependencies = [
|
|
||||||
"futures-core",
|
|
||||||
"futures-task",
|
|
||||||
"futures-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-macro"
|
name = "futures-macro"
|
||||||
version = "0.3.21"
|
version = "0.3.21"
|
||||||
|
|
@ -276,68 +223,6 @@ version = "0.26.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
|
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glib"
|
|
||||||
version = "0.15.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a826fad715b57834920839d7a594c3b5e416358c7d790bdaba847a40d7c1d96d"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"futures-channel",
|
|
||||||
"futures-core",
|
|
||||||
"futures-executor",
|
|
||||||
"futures-task",
|
|
||||||
"glib-macros",
|
|
||||||
"glib-sys",
|
|
||||||
"gobject-sys",
|
|
||||||
"libc",
|
|
||||||
"once_cell",
|
|
||||||
"smallvec",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glib-macros"
|
|
||||||
version = "0.15.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dac4d47c544af67747652ab1865ace0ffa1155709723ac4f32e97587dd4735b2"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"heck",
|
|
||||||
"proc-macro-crate",
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glib-sys"
|
|
||||||
version = "0.15.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ef4b192f8e65e9cf76cbf4ea71fa8e3be4a0e18ffe3d68b8da6836974cc5bad4"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gobject-sys"
|
|
||||||
version = "0.15.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0d57ce44246becd17153bd035ab4d32cfee096a657fc01f2231c9278378d1e0a"
|
|
||||||
dependencies = [
|
|
||||||
"glib-sys",
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "heck"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.19"
|
version = "0.1.19"
|
||||||
|
|
@ -370,7 +255,6 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"bstr",
|
"bstr",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"cairo-rs",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"default-config",
|
"default-config",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
|
@ -382,8 +266,6 @@ dependencies = [
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"pango",
|
|
||||||
"pangocairo",
|
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"rand",
|
"rand",
|
||||||
"repc",
|
"repc",
|
||||||
|
|
@ -492,58 +374,6 @@ version = "1.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pango"
|
|
||||||
version = "0.15.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "22e4045548659aee5313bde6c582b0d83a627b7904dd20dc2d9ef0895d414e4f"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"glib",
|
|
||||||
"libc",
|
|
||||||
"once_cell",
|
|
||||||
"pango-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pango-sys"
|
|
||||||
version = "0.15.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2a00081cde4661982ed91d80ef437c20eacaf6aa1a5962c0279ae194662c3aa"
|
|
||||||
dependencies = [
|
|
||||||
"glib-sys",
|
|
||||||
"gobject-sys",
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pangocairo"
|
|
||||||
version = "0.15.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7876a45c1f1d1a75a2601dc6d9ef2cb5a8be0e3d76f909d82450759929035366"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cairo-rs",
|
|
||||||
"glib",
|
|
||||||
"libc",
|
|
||||||
"pango",
|
|
||||||
"pangocairo-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pangocairo-sys"
|
|
||||||
version = "0.15.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "78cf746594916c81d5f739af9335c5f55a1f4606d80b3e1d821f18cf95a29494"
|
|
||||||
dependencies = [
|
|
||||||
"cairo-sys-rs",
|
|
||||||
"glib-sys",
|
|
||||||
"libc",
|
|
||||||
"pango-sys",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project"
|
name = "pin-project"
|
||||||
version = "1.0.10"
|
version = "1.0.10"
|
||||||
|
|
@ -576,52 +406,12 @@ version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pkg-config"
|
|
||||||
version = "0.3.24"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.16"
|
version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-crate"
|
|
||||||
version = "1.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a"
|
|
||||||
dependencies = [
|
|
||||||
"thiserror",
|
|
||||||
"toml",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.36"
|
version = "1.0.36"
|
||||||
|
|
@ -714,12 +504,6 @@ version = "0.1.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
|
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde"
|
|
||||||
version = "1.0.136"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
|
|
@ -743,19 +527,6 @@ dependencies = [
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "system-deps"
|
|
||||||
version = "6.0.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1a45a1c4c9015217e12347f2a411b57ce2c4fc543913b14b6fe40483328e709"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-expr",
|
|
||||||
"heck",
|
|
||||||
"pkg-config",
|
|
||||||
"toml",
|
|
||||||
"version-compare",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "termcolor"
|
name = "termcolor"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
|
|
@ -796,15 +567,6 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml"
|
|
||||||
version = "0.5.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uapi"
|
name = "uapi"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
|
|
@ -837,12 +599,6 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "version-compare"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,6 @@ backtrace = { version = "0.3.64", optional = true }
|
||||||
byteorder = "1.4.3"
|
byteorder = "1.4.3"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
bincode = "2.0.0-beta.3"
|
bincode = "2.0.0-beta.3"
|
||||||
pangocairo = "0.15.1"
|
|
||||||
cairo-rs = { version = "0.15.1", features = ["png"] }
|
|
||||||
pango = { version = "0.15.2", features = ["v1_44"] }
|
|
||||||
jay-config = { path = "jay-config" }
|
jay-config = { path = "jay-config" }
|
||||||
default-config = { path = "default-config" }
|
default-config = { path = "default-config" }
|
||||||
pin-project = "1.0.10"
|
pin-project = "1.0.10"
|
||||||
|
|
@ -45,8 +42,8 @@ repc = "0.1.1"
|
||||||
anyhow = "1.0.52"
|
anyhow = "1.0.52"
|
||||||
bstr = "0.2.17"
|
bstr = "0.2.17"
|
||||||
|
|
||||||
[profile.dev.build-override]
|
#[profile.dev.build-override]
|
||||||
opt-level = 3
|
#opt-level = 3
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
rc_tracking = ["backtrace"]
|
rc_tracking = ["backtrace"]
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ mod xkbcommon;
|
||||||
#[path = "../src/libinput/consts.rs"]
|
#[path = "../src/libinput/consts.rs"]
|
||||||
mod libinput;
|
mod libinput;
|
||||||
|
|
||||||
|
#[path = "../src/pango/consts.rs"]
|
||||||
|
mod pango;
|
||||||
|
|
||||||
fn get_target() -> repc::Target {
|
fn get_target() -> repc::Target {
|
||||||
let rustc_target = env::var("TARGET").unwrap();
|
let rustc_target = env::var("TARGET").unwrap();
|
||||||
repc::TARGET_MAP
|
repc::TARGET_MAP
|
||||||
|
|
@ -40,11 +43,11 @@ fn get_enum_ty(variants: Vec<i128>) -> anyhow::Result<u64> {
|
||||||
Ok(ty.layout.size_bits)
|
Ok(ty.layout.size_bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_ty<W: Write>(f: &mut W, vals: &[u32], ty: &str) -> anyhow::Result<()> {
|
fn write_ty<W: Write>(f: &mut W, vals: &[i32], ty: &str) -> anyhow::Result<()> {
|
||||||
let variants: Vec<_> = vals.iter().cloned().map(|v| v as i128).collect();
|
let variants: Vec<_> = vals.iter().cloned().map(|v| v as i128).collect();
|
||||||
let size = get_enum_ty(variants)?;
|
let size = get_enum_ty(variants)?;
|
||||||
writeln!(f, "#[allow(dead_code)]")?;
|
writeln!(f, "#[allow(dead_code)]")?;
|
||||||
writeln!(f, "pub type {} = u{};", ty, size)?;
|
writeln!(f, "pub type {} = i{};", ty, size)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,6 +264,12 @@ pub fn main() -> anyhow::Result<()> {
|
||||||
write_ty(&mut f, pixman::FORMATS, "PixmanFormat")?;
|
write_ty(&mut f, pixman::FORMATS, "PixmanFormat")?;
|
||||||
write_ty(&mut f, pixman::OPS, "PixmanOp")?;
|
write_ty(&mut f, pixman::OPS, "PixmanOp")?;
|
||||||
|
|
||||||
|
let mut f = open("pango_tys.rs")?;
|
||||||
|
write_ty(&mut f, pango::CAIRO_FORMATS, "cairo_format_t")?;
|
||||||
|
write_ty(&mut f, pango::CAIRO_STATUSES, "cairo_status_t")?;
|
||||||
|
write_ty(&mut f, pango::CAIRO_OPERATORS, "cairo_operator_t")?;
|
||||||
|
write_ty(&mut f, pango::PANGO_ELLIPSIZE_MODES, "PangoEllipsizeMode_")?;
|
||||||
|
|
||||||
let mut f = open("xkbcommon_tys.rs")?;
|
let mut f = open("xkbcommon_tys.rs")?;
|
||||||
write_ty(&mut f, xkbcommon::XKB_LOG_LEVEL, "xkb_log_level")?;
|
write_ty(&mut f, xkbcommon::XKB_LOG_LEVEL, "xkb_log_level")?;
|
||||||
write_ty(&mut f, xkbcommon::XKB_CONTEXT_FLAGS, "xkb_context_flags")?;
|
write_ty(&mut f, xkbcommon::XKB_CONTEXT_FLAGS, "xkb_context_flags")?;
|
||||||
|
|
|
||||||
|
|
@ -186,15 +186,15 @@ macro_rules! linear_ids {
|
||||||
macro_rules! cenum {
|
macro_rules! cenum {
|
||||||
($name:ident, $uc:ident; $($name2:ident = $val:expr,)*) => {
|
($name:ident, $uc:ident; $($name2:ident = $val:expr,)*) => {
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct $name(pub(super) u32);
|
pub struct $name(pub(super) i32);
|
||||||
|
|
||||||
impl $name {
|
impl $name {
|
||||||
pub fn raw(self) -> u32 {
|
pub fn raw(self) -> i32 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const $uc: &[u32] = &[$($val,)*];
|
pub const $uc: &[i32] = &[$($val,)*];
|
||||||
|
|
||||||
$(
|
$(
|
||||||
pub const $name2: $name = $name($val);
|
pub const $name2: $name = $name($val);
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ mod wire_xcon;
|
||||||
mod xcon;
|
mod xcon;
|
||||||
mod xkbcommon;
|
mod xkbcommon;
|
||||||
mod xwayland;
|
mod xwayland;
|
||||||
|
mod pango;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::builder()
|
env_logger::builder()
|
||||||
|
|
|
||||||
317
src/pango.rs
Normal file
317
src/pango.rs
Normal file
|
|
@ -0,0 +1,317 @@
|
||||||
|
#![allow(non_camel_case_types)]
|
||||||
|
|
||||||
|
use std::cell::Cell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use thiserror::Error;
|
||||||
|
use uapi::{c, IntoUstr};
|
||||||
|
use crate::pango::consts::{CairoFormat, CairoOperator, PangoEllipsizeMode};
|
||||||
|
|
||||||
|
pub mod consts;
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/pango_tys.rs"));
|
||||||
|
|
||||||
|
#[link(name = "cairo")]
|
||||||
|
extern {
|
||||||
|
type cairo_surface_t;
|
||||||
|
type cairo_t;
|
||||||
|
|
||||||
|
fn cairo_image_surface_create(
|
||||||
|
format: cairo_format_t,
|
||||||
|
width: c::c_int,
|
||||||
|
height: c::c_int,
|
||||||
|
) -> *mut cairo_surface_t;
|
||||||
|
fn cairo_image_surface_get_height(surface: *mut cairo_surface_t) -> c::c_int;
|
||||||
|
fn cairo_image_surface_get_stride(surface: *mut cairo_surface_t) -> c::c_int;
|
||||||
|
fn cairo_image_surface_get_data(surface: *mut cairo_surface_t) -> *mut u8;
|
||||||
|
|
||||||
|
fn cairo_surface_destroy(surface: *mut cairo_surface_t);
|
||||||
|
fn cairo_surface_status(surface: *mut cairo_surface_t) -> cairo_status_t;
|
||||||
|
fn cairo_surface_flush(surface: *mut cairo_surface_t);
|
||||||
|
|
||||||
|
fn cairo_create(surface: *mut cairo_surface_t) -> *mut cairo_t;
|
||||||
|
fn cairo_status(cairo: *mut cairo_t) -> cairo_status_t;
|
||||||
|
fn cairo_destroy(cairo: *mut cairo_t);
|
||||||
|
|
||||||
|
fn cairo_set_operator(cr: *mut cairo_t, op: cairo_operator_t);
|
||||||
|
fn cairo_set_source_rgba(
|
||||||
|
cr: *mut cairo_t,
|
||||||
|
red: f64,
|
||||||
|
green: f64,
|
||||||
|
blue: f64,
|
||||||
|
alpha: f64,
|
||||||
|
);
|
||||||
|
fn cairo_move_to(cr: *mut cairo_t, x: f64, y: f64);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[link(name = "pangocairo-1.0")]
|
||||||
|
extern {
|
||||||
|
type PangoContext_;
|
||||||
|
|
||||||
|
fn pango_cairo_create_context(cr: *mut cairo_t) -> *mut PangoContext_;
|
||||||
|
fn pango_cairo_show_layout(cr: *mut cairo_t, layout: *mut PangoLayout_);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[link(name = "gobject-2.0")]
|
||||||
|
extern {
|
||||||
|
type GObject;
|
||||||
|
|
||||||
|
fn g_object_unref(object: *mut GObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[link(name = "pango-1.0")]
|
||||||
|
extern {
|
||||||
|
type PangoFontDescription_;
|
||||||
|
type PangoLayout_;
|
||||||
|
|
||||||
|
fn pango_font_description_from_string(str: *const c::c_char) -> *mut PangoFontDescription_;
|
||||||
|
fn pango_font_description_free(desc: *mut PangoFontDescription_);
|
||||||
|
|
||||||
|
fn pango_layout_new(context: *mut PangoContext_) -> *mut PangoLayout_;
|
||||||
|
fn pango_layout_set_width(layout: *mut PangoLayout_, width: c::c_int);
|
||||||
|
fn pango_layout_set_ellipsize(layout: *mut PangoLayout_, ellipsize: PangoEllipsizeMode_);
|
||||||
|
fn pango_layout_set_font_description(
|
||||||
|
layout: *mut PangoLayout_,
|
||||||
|
desc: *const PangoFontDescription_,
|
||||||
|
);
|
||||||
|
fn pango_layout_set_text(layout: *mut PangoLayout_, text: *const c::c_char, length: c::c_int);
|
||||||
|
fn pango_layout_get_pixel_size(
|
||||||
|
layout: *mut PangoLayout_,
|
||||||
|
width: *mut c::c_int,
|
||||||
|
height: *mut c::c_int,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum PangoError {
|
||||||
|
#[error("Could not create an image surface: {0}")]
|
||||||
|
CreateSurface(u32),
|
||||||
|
#[error("Could not create a cairo context: {0}")]
|
||||||
|
CreateCairo(u32),
|
||||||
|
#[error("Could not create a pangocairo context")]
|
||||||
|
CreatePangoCairo,
|
||||||
|
#[error("Could not create a pango layout")]
|
||||||
|
CreateLayout,
|
||||||
|
#[error("Could not retrieve image data")]
|
||||||
|
GetData,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CairoImageSurface {
|
||||||
|
s: *mut cairo_surface_t,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CairoImageSurface {
|
||||||
|
pub fn new_image_surface(format: CairoFormat, width: i32, height: i32) -> Result<Rc<Self>, PangoError> {
|
||||||
|
unsafe {
|
||||||
|
let s = cairo_image_surface_create(format.raw() as _, width as _, height as _);
|
||||||
|
let status = cairo_surface_status(s);
|
||||||
|
if status != 0 {
|
||||||
|
return Err(PangoError::CreateSurface(status as _));
|
||||||
|
}
|
||||||
|
Ok(Rc::new(Self {
|
||||||
|
s,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_context(self: &Rc<Self>) -> Result<Rc<CairoContext>, PangoError> {
|
||||||
|
unsafe {
|
||||||
|
let c = cairo_create(self.s);
|
||||||
|
let status = cairo_status(c);
|
||||||
|
if status != 0 {
|
||||||
|
return Err(PangoError::CreateCairo(status as _));
|
||||||
|
}
|
||||||
|
Ok(Rc::new(CairoContext {
|
||||||
|
_s: self.clone(),
|
||||||
|
c,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn flush(&self) {
|
||||||
|
unsafe {
|
||||||
|
cairo_surface_flush(self.s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn height(&self) -> i32 {
|
||||||
|
unsafe {
|
||||||
|
cairo_image_surface_get_height(self.s) as _
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stride(&self) -> i32 {
|
||||||
|
unsafe {
|
||||||
|
cairo_image_surface_get_stride(self.s) as _
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn data(&self) -> Result<&[Cell<u8>], PangoError> {
|
||||||
|
unsafe {
|
||||||
|
let d = cairo_image_surface_get_data(self.s);
|
||||||
|
if d.is_null() {
|
||||||
|
return Err(PangoError::GetData);
|
||||||
|
}
|
||||||
|
let size = self.height() as usize * self.stride() as usize;
|
||||||
|
Ok(std::slice::from_raw_parts(d.cast(), size))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for CairoImageSurface {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
cairo_surface_destroy(self.s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CairoContext {
|
||||||
|
_s: Rc<CairoImageSurface>,
|
||||||
|
c: *mut cairo_t,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CairoContext {
|
||||||
|
pub fn create_pango_context(self: &Rc<Self>) -> Result<Rc<PangoCairoContext>, PangoError> {
|
||||||
|
unsafe {
|
||||||
|
let p = pango_cairo_create_context(self.c);
|
||||||
|
if p.is_null() {
|
||||||
|
return Err(PangoError::CreatePangoCairo);
|
||||||
|
}
|
||||||
|
Ok(Rc::new(PangoCairoContext {
|
||||||
|
c: self.clone(),
|
||||||
|
p,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_operator(&self, op: CairoOperator) {
|
||||||
|
unsafe {
|
||||||
|
cairo_set_operator(self.c, op.raw() as _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_source_rgba(&self, r: f64, g: f64, b: f64, a: f64) {
|
||||||
|
unsafe {
|
||||||
|
cairo_set_source_rgba(self.c, r, g, b, a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn move_to(&self, x: f64, y: f64) {
|
||||||
|
unsafe {
|
||||||
|
cairo_move_to(self.c, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for CairoContext {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
cairo_destroy(self.c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PangoCairoContext {
|
||||||
|
c: Rc<CairoContext>,
|
||||||
|
p: *mut PangoContext_,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PangoCairoContext {
|
||||||
|
pub fn create_layout(self: &Rc<Self>) -> Result<PangoLayout, PangoError> {
|
||||||
|
unsafe {
|
||||||
|
let l = pango_layout_new(self.p as _);
|
||||||
|
if l.is_null() {
|
||||||
|
return Err(PangoError::CreateLayout);
|
||||||
|
}
|
||||||
|
Ok(PangoLayout {
|
||||||
|
c: self.clone(),
|
||||||
|
l: l,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for PangoCairoContext {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
g_object_unref(self.p as _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PangoFontDescription {
|
||||||
|
s: *mut PangoFontDescription_,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PangoFontDescription {
|
||||||
|
pub fn from_string<'a>(s: impl IntoUstr<'a>) -> Self {
|
||||||
|
let s = s.into_ustr();
|
||||||
|
Self {
|
||||||
|
s: unsafe {
|
||||||
|
pango_font_description_from_string(s.as_ptr())
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for PangoFontDescription {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
pango_font_description_free(self.s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PangoLayout {
|
||||||
|
c: Rc<PangoCairoContext>,
|
||||||
|
l: *mut PangoLayout_,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PangoLayout {
|
||||||
|
pub fn set_width(&self, width: i32) {
|
||||||
|
unsafe {
|
||||||
|
pango_layout_set_width(self.l, width as _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_ellipsize(&self, ellipsize: PangoEllipsizeMode) {
|
||||||
|
unsafe {
|
||||||
|
pango_layout_set_ellipsize(self.l, ellipsize.raw() as _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_font_description(&self, fd: &PangoFontDescription) {
|
||||||
|
unsafe {
|
||||||
|
pango_layout_set_font_description(self.l, fd.s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_text(&self, text: &str) {
|
||||||
|
unsafe {
|
||||||
|
pango_layout_set_text(self.l, text.as_ptr() as _, text.len() as _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pixel_size(&self) -> (i32, i32) {
|
||||||
|
unsafe {
|
||||||
|
let mut w = 0;
|
||||||
|
let mut h = 0;
|
||||||
|
pango_layout_get_pixel_size(self.l, &mut w, &mut h);
|
||||||
|
(w as _, h as _)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_layout(&self) {
|
||||||
|
unsafe {
|
||||||
|
pango_cairo_show_layout(self.c.c.c, self.l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for PangoLayout {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
g_object_unref(self.l as _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
109
src/pango/consts.rs
Normal file
109
src/pango/consts.rs
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
cenum! {
|
||||||
|
CairoFormat, CAIRO_FORMATS;
|
||||||
|
|
||||||
|
CAIRO_FORMAT_INVALID = -1,
|
||||||
|
CAIRO_FORMAT_ARGB32 = 0,
|
||||||
|
CAIRO_FORMAT_RGB24 = 1,
|
||||||
|
CAIRO_FORMAT_A8 = 2,
|
||||||
|
CAIRO_FORMAT_A1 = 3,
|
||||||
|
CAIRO_FORMAT_RGB16_565 = 4,
|
||||||
|
CAIRO_FORMAT_RGB30 = 5,
|
||||||
|
CAIRO_FORMAT_RGB96F = 6,
|
||||||
|
CAIRO_FORMAT_RGBA128F = 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
cenum! {
|
||||||
|
CairoStatus, CAIRO_STATUSES;
|
||||||
|
|
||||||
|
CAIRO_STATUS_SUCCESS = 0,
|
||||||
|
CAIRO_STATUS_NO_MEMORY = 1,
|
||||||
|
CAIRO_STATUS_INVALID_RESTORE = 2,
|
||||||
|
CAIRO_STATUS_INVALID_POP_GROUP = 3,
|
||||||
|
CAIRO_STATUS_NO_CURRENT_POINT = 4,
|
||||||
|
CAIRO_STATUS_INVALID_MATRIX = 5,
|
||||||
|
CAIRO_STATUS_INVALID_STATUS = 6,
|
||||||
|
CAIRO_STATUS_NULL_POINTER = 7,
|
||||||
|
CAIRO_STATUS_INVALID_STRING = 8,
|
||||||
|
CAIRO_STATUS_INVALID_PATH_DATA = 9,
|
||||||
|
CAIRO_STATUS_READ_ERROR = 10,
|
||||||
|
CAIRO_STATUS_WRITE_ERROR = 11,
|
||||||
|
CAIRO_STATUS_SURFACE_FINISHED = 12,
|
||||||
|
CAIRO_STATUS_SURFACE_TYPE_MISMATCH = 13,
|
||||||
|
CAIRO_STATUS_PATTERN_TYPE_MISMATCH = 14,
|
||||||
|
CAIRO_STATUS_INVALID_CONTENT = 15,
|
||||||
|
CAIRO_STATUS_INVALID_FORMAT = 16,
|
||||||
|
CAIRO_STATUS_INVALID_VISUAL = 17,
|
||||||
|
CAIRO_STATUS_FILE_NOT_FOUND = 18,
|
||||||
|
CAIRO_STATUS_INVALID_DASH = 19,
|
||||||
|
CAIRO_STATUS_INVALID_DSC_COMMENT = 20,
|
||||||
|
CAIRO_STATUS_INVALID_INDEX = 21,
|
||||||
|
CAIRO_STATUS_CLIP_NOT_REPRESENTABLE = 22,
|
||||||
|
CAIRO_STATUS_TEMP_FILE_ERROR = 23,
|
||||||
|
CAIRO_STATUS_INVALID_STRIDE = 24,
|
||||||
|
CAIRO_STATUS_FONT_TYPE_MISMATCH = 25,
|
||||||
|
CAIRO_STATUS_USER_FONT_IMMUTABLE = 26,
|
||||||
|
CAIRO_STATUS_USER_FONT_ERROR = 27,
|
||||||
|
CAIRO_STATUS_NEGATIVE_COUNT = 28,
|
||||||
|
CAIRO_STATUS_INVALID_CLUSTERS = 29,
|
||||||
|
CAIRO_STATUS_INVALID_SLANT = 30,
|
||||||
|
CAIRO_STATUS_INVALID_WEIGHT = 31,
|
||||||
|
CAIRO_STATUS_INVALID_SIZE = 32,
|
||||||
|
CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED = 33,
|
||||||
|
CAIRO_STATUS_DEVICE_TYPE_MISMATCH = 34,
|
||||||
|
CAIRO_STATUS_DEVICE_ERROR = 35,
|
||||||
|
CAIRO_STATUS_INVALID_MESH_CONSTRUCTION = 36,
|
||||||
|
CAIRO_STATUS_DEVICE_FINISHED = 37,
|
||||||
|
CAIRO_STATUS_JBIG2_GLOBAL_MISSING = 38,
|
||||||
|
CAIRO_STATUS_PNG_ERROR = 39,
|
||||||
|
CAIRO_STATUS_FREETYPE_ERROR = 40,
|
||||||
|
CAIRO_STATUS_WIN32_GDI_ERROR = 41,
|
||||||
|
CAIRO_STATUS_TAG_ERROR = 42,
|
||||||
|
CAIRO_STATUS_LAST_STATUS = 43,
|
||||||
|
}
|
||||||
|
|
||||||
|
cenum! {
|
||||||
|
CairoOperator, CAIRO_OPERATORS;
|
||||||
|
|
||||||
|
CAIRO_OPERATOR_CLEAR = 0,
|
||||||
|
CAIRO_OPERATOR_SOURCE = 1,
|
||||||
|
CAIRO_OPERATOR_OVER = 2,
|
||||||
|
CAIRO_OPERATOR_IN = 3,
|
||||||
|
CAIRO_OPERATOR_OUT = 4,
|
||||||
|
CAIRO_OPERATOR_ATOP = 5,
|
||||||
|
CAIRO_OPERATOR_DEST = 6,
|
||||||
|
CAIRO_OPERATOR_DEST_OVER = 7,
|
||||||
|
CAIRO_OPERATOR_DEST_IN = 8,
|
||||||
|
CAIRO_OPERATOR_DEST_OUT = 9,
|
||||||
|
CAIRO_OPERATOR_DEST_ATOP = 10,
|
||||||
|
CAIRO_OPERATOR_XOR = 11,
|
||||||
|
CAIRO_OPERATOR_ADD = 12,
|
||||||
|
CAIRO_OPERATOR_SATURATE = 13,
|
||||||
|
CAIRO_OPERATOR_MULTIPLY = 14,
|
||||||
|
CAIRO_OPERATOR_SCREEN = 15,
|
||||||
|
CAIRO_OPERATOR_OVERLAY = 16,
|
||||||
|
CAIRO_OPERATOR_DARKEN = 17,
|
||||||
|
CAIRO_OPERATOR_LIGHTEN = 18,
|
||||||
|
CAIRO_OPERATOR_COLOR_DODGE = 19,
|
||||||
|
CAIRO_OPERATOR_COLOR_BURN = 20,
|
||||||
|
CAIRO_OPERATOR_HARD_LIGHT = 21,
|
||||||
|
CAIRO_OPERATOR_SOFT_LIGHT = 22,
|
||||||
|
CAIRO_OPERATOR_DIFFERENCE = 23,
|
||||||
|
CAIRO_OPERATOR_EXCLUSION = 24,
|
||||||
|
CAIRO_OPERATOR_HSL_HUE = 25,
|
||||||
|
CAIRO_OPERATOR_HSL_SATURATION = 26,
|
||||||
|
CAIRO_OPERATOR_HSL_COLOR = 27,
|
||||||
|
CAIRO_OPERATOR_HSL_LUMINOSITY = 28,
|
||||||
|
}
|
||||||
|
|
||||||
|
cenum! {
|
||||||
|
PangoEllipsizeMode, PANGO_ELLIPSIZE_MODES;
|
||||||
|
|
||||||
|
PANGO_ELLIPSIZE_NONE = 0,
|
||||||
|
PANGO_ELLIPSIZE_START = 1,
|
||||||
|
PANGO_ELLIPSIZE_MIDDLE = 2,
|
||||||
|
PANGO_ELLIPSIZE_END = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const PANGO_SCALE: i32 = 1024;
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
pub const fn format(bpp: u32, ty: u32, a: u32, r: u32, g: u32, b: u32) -> u32 {
|
pub const fn format(bpp: u32, ty: u32, a: u32, r: u32, g: u32, b: u32) -> i32 {
|
||||||
(bpp << 24) | (ty << 16) | (a << 12) | (r << 8) | (g << 4) | b
|
((bpp << 24) | (ty << 16) | (a << 12) | (r << 8) | (g << 4) | b) as i32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn format_byte(bpp: u32, ty: u32, a: u32, r: u32, g: u32, b: u32) -> u32 {
|
pub const fn format_byte(bpp: u32, ty: u32, a: u32, r: u32, g: u32, b: u32) -> i32 {
|
||||||
((bpp >> 3) << 24)
|
(((bpp >> 3) << 24)
|
||||||
| (3 << 22)
|
| (3 << 22)
|
||||||
| (ty << 16)
|
| (ty << 16)
|
||||||
| ((a >> 3) << 12)
|
| ((a >> 3) << 12)
|
||||||
| ((r >> 3) << 8)
|
| ((r >> 3) << 8)
|
||||||
| ((g >> 3) << 4)
|
| ((g >> 3) << 4)
|
||||||
| (b >> 3)
|
| (b >> 3)) as i32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn format_reshift(val: u32, ofs: u32, num: u32) -> u32 {
|
pub const fn format_reshift(val: u32, ofs: u32, num: u32) -> u32 {
|
||||||
|
|
|
||||||
62
src/text.rs
62
src/text.rs
|
|
@ -2,27 +2,25 @@ use crate::format::ARGB8888;
|
||||||
use crate::render::{RenderContext, Texture};
|
use crate::render::{RenderContext, Texture};
|
||||||
use crate::theme::Color;
|
use crate::theme::Color;
|
||||||
use crate::RenderError;
|
use crate::RenderError;
|
||||||
use cairo::{ImageSurface, Operator};
|
|
||||||
use pango::{EllipsizeMode, Layout};
|
|
||||||
use pangocairo::cairo::Format;
|
|
||||||
use pangocairo::pango::FontDescription;
|
|
||||||
use pangocairo::{cairo, pango};
|
|
||||||
use std::mem;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use crate::pango::{CairoImageSurface, PangoError, PangoFontDescription};
|
||||||
|
use crate::pango::consts::{CAIRO_FORMAT_ARGB32, CAIRO_OPERATOR_SOURCE, PANGO_ELLIPSIZE_END, PANGO_SCALE};
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum TextError {
|
pub enum TextError {
|
||||||
#[error("Could not create a cairo image")]
|
#[error("Could not create a cairo image")]
|
||||||
CreateImage(#[source] cairo::Error),
|
CreateImage(#[source] PangoError),
|
||||||
#[error("Could not create a cairo context")]
|
#[error("Could not create a cairo context")]
|
||||||
CairoContext(#[source] cairo::Error),
|
CairoContext(#[source] PangoError),
|
||||||
#[error("Could not create a pango context")]
|
#[error("Could not create a pango context")]
|
||||||
PangoContext,
|
PangoContext(#[source] PangoError),
|
||||||
|
#[error("Could not create a pango layout")]
|
||||||
|
CreateLayout(#[source] PangoError),
|
||||||
#[error("Could not import the rendered text")]
|
#[error("Could not import the rendered text")]
|
||||||
RenderError(#[source] RenderError),
|
RenderError(#[source] RenderError),
|
||||||
#[error("Could not access the cairo image data")]
|
#[error("Could not access the cairo image data")]
|
||||||
ImageData,
|
ImageData(#[source] PangoError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(
|
pub fn render(
|
||||||
|
|
@ -33,37 +31,39 @@ pub fn render(
|
||||||
text: &str,
|
text: &str,
|
||||||
color: Color,
|
color: Color,
|
||||||
) -> Result<Rc<Texture>, TextError> {
|
) -> Result<Rc<Texture>, TextError> {
|
||||||
let image = match ImageSurface::create(Format::ARgb32, width, height) {
|
let image = match CairoImageSurface::new_image_surface(CAIRO_FORMAT_ARGB32, width, height) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => return Err(TextError::CreateImage(e)),
|
Err(e) => return Err(TextError::CreateImage(e)),
|
||||||
};
|
};
|
||||||
let cctx = match cairo::Context::new(&image) {
|
let cctx = match image.create_context() {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => return Err(TextError::CairoContext(e)),
|
Err(e) => return Err(TextError::CairoContext(e)),
|
||||||
};
|
};
|
||||||
let pctx = match pangocairo::create_context(&cctx) {
|
let pctx = match cctx.create_pango_context() {
|
||||||
Some(c) => c,
|
Ok(c) => c,
|
||||||
_ => return Err(TextError::PangoContext),
|
Err(e) => return Err(TextError::PangoContext(e)),
|
||||||
};
|
};
|
||||||
let fd = FontDescription::from_string(font);
|
let fd = PangoFontDescription::from_string(font);
|
||||||
let layout = Layout::new(&pctx);
|
let layout = match pctx.create_layout() {
|
||||||
layout.set_width((width - 2).max(0) * pango::SCALE);
|
Ok(l) => l,
|
||||||
layout.set_ellipsize(EllipsizeMode::End);
|
Err(e) => return Err(TextError::CreateLayout(e)),
|
||||||
layout.set_font_description(Some(&fd));
|
};
|
||||||
|
layout.set_width((width - 2).max(0) * PANGO_SCALE);
|
||||||
|
layout.set_ellipsize(PANGO_ELLIPSIZE_END);
|
||||||
|
layout.set_font_description(&fd);
|
||||||
layout.set_text(text);
|
layout.set_text(text);
|
||||||
let font_height = layout.pixel_size().1;
|
let font_height = layout.pixel_size().1;
|
||||||
cctx.set_operator(Operator::Source);
|
cctx.set_operator(CAIRO_OPERATOR_SOURCE);
|
||||||
cctx.set_source_rgba(color.r as _, color.g as _, color.b as _, color.a as _);
|
cctx.set_source_rgba(color.r as _, color.g as _, color.b as _, color.a as _);
|
||||||
cctx.move_to(1.0, ((height - font_height) / 2) as f64);
|
cctx.move_to(1.0, ((height - font_height) / 2) as f64);
|
||||||
pangocairo::show_layout(&cctx, &layout);
|
layout.show_layout();
|
||||||
let mut texture = None;
|
image.flush();
|
||||||
let _ = image.with_data(|d| unsafe {
|
let data = match image.data() {
|
||||||
let d = mem::transmute(d);
|
Ok(d) => d,
|
||||||
texture = Some(ctx.shmem_texture(d, ARGB8888, width, height, image.stride()));
|
Err(e) => return Err(TextError::ImageData(e)),
|
||||||
});
|
};
|
||||||
match texture {
|
match ctx.shmem_texture(data, ARGB8888, width, height, image.stride()) {
|
||||||
Some(Ok(t)) => Ok(t),
|
Ok(t) => Ok(t),
|
||||||
Some(Err(e)) => Err(TextError::RenderError(e)),
|
Err(e) => Err(TextError::RenderError(e)),
|
||||||
None => Err(TextError::ImageData),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue