Backed out 2 changesets (bug 1949858) for causing WebRender failures. CLOSED TREE

Backed out changeset 311381302426 (bug 1949858)
Backed out changeset a43a261a4dbb (bug 1949858)
This commit is contained in:
Butkovits Atila
2025-02-24 16:55:15 +02:00
parent e8b4ce1342
commit d1846f9d0f
59 changed files with 1003 additions and 1271 deletions

62
Cargo.lock generated
View File

@@ -335,7 +335,7 @@ dependencies = [
"base64 0.21.3", "base64 0.21.3",
"bitflags 1.999.999", "bitflags 1.999.999",
"cfg-if", "cfg-if",
"core-foundation 0.9.999", "core-foundation",
"devd-rs", "devd-rs",
"libc", "libc",
"libudev", "libudev",
@@ -951,16 +951,9 @@ dependencies = [
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.999" version = "0.9.4"
dependencies = [
"core-foundation 0.10.0",
]
[[package]]
name = "core-foundation"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [ dependencies = [
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@@ -968,48 +961,41 @@ dependencies = [
[[package]] [[package]]
name = "core-foundation-sys" name = "core-foundation-sys"
version = "0.8.7" version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]] [[package]]
name = "core-graphics" name = "core-graphics"
version = "0.24.0" version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1" checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212"
dependencies = [ dependencies = [
"bitflags 2.7.0", "bitflags 1.999.999",
"core-foundation 0.10.0", "core-foundation",
"core-graphics-types 0.2.0", "core-graphics-types",
"foreign-types", "foreign-types",
"libc", "libc",
] ]
[[package]] [[package]]
name = "core-graphics-types" name = "core-graphics-types"
version = "0.1.999" version = "0.1.3"
dependencies = [
"core-graphics-types 0.2.0",
]
[[package]]
name = "core-graphics-types"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf"
dependencies = [ dependencies = [
"bitflags 2.7.0", "bitflags 1.999.999",
"core-foundation 0.10.0", "core-foundation",
"libc", "libc",
] ]
[[package]] [[package]]
name = "core-text" name = "core-text"
version = "21.0.0" version = "20.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a593227b66cbd4007b2a050dfdd9e1d1318311409c8d600dc82ba1b15ca9c130" checksum = "c9d2790b5c08465d49f8dc05c8bcae9fea467855947db39b0f8145c091aaced5"
dependencies = [ dependencies = [
"core-foundation 0.10.0", "core-foundation",
"core-graphics", "core-graphics",
"foreign-types", "foreign-types",
"libc", "libc",
@@ -1047,7 +1033,7 @@ name = "coremidi"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/chris-zen/coremidi.git?rev=fc68464b5445caf111e41f643a2e69ccce0b4f83#fc68464b5445caf111e41f643a2e69ccce0b4f83" source = "git+https://github.com/chris-zen/coremidi.git?rev=fc68464b5445caf111e41f643a2e69ccce0b4f83#fc68464b5445caf111e41f643a2e69ccce0b4f83"
dependencies = [ dependencies = [
"core-foundation 0.9.999", "core-foundation",
"core-foundation-sys", "core-foundation-sys",
"coremidi-sys", "coremidi-sys",
] ]
@@ -3228,7 +3214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "861c6093cbc05599e66436aedf380bb0a23cec2180738393d3a340b80dd135ef" checksum = "861c6093cbc05599e66436aedf380bb0a23cec2180738393d3a340b80dd135ef"
dependencies = [ dependencies = [
"cgl", "cgl",
"core-foundation 0.9.999", "core-foundation",
"leaky-cow", "leaky-cow",
"libc", "libc",
] ]
@@ -3810,7 +3796,7 @@ checksum = "f569fb946490b5743ad69813cb19629130ce9374034abe31614a36402d18f99e"
dependencies = [ dependencies = [
"bitflags 2.7.0", "bitflags 2.7.0",
"block", "block",
"core-graphics-types 0.1.999", "core-graphics-types",
"foreign-types", "foreign-types",
"log", "log",
"objc", "objc",
@@ -4804,7 +4790,7 @@ name = "osclientcerts"
version = "0.1.4" version = "0.1.4"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"core-foundation 0.9.999", "core-foundation",
"env_logger", "env_logger",
"lazy_static", "lazy_static",
"libloading", "libloading",
@@ -7233,7 +7219,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"app_units", "app_units",
"bincode", "bincode",
"core-foundation 0.10.0", "core-foundation",
"core-graphics", "core-graphics",
"dirs", "dirs",
"dwrote", "dwrote",
@@ -7324,7 +7310,7 @@ dependencies = [
"bitflags 2.7.0", "bitflags 2.7.0",
"block", "block",
"cfg_aliases", "cfg_aliases",
"core-graphics-types 0.1.999", "core-graphics-types",
"gpu-alloc", "gpu-alloc",
"gpu-allocator", "gpu-allocator",
"gpu-descriptor", "gpu-descriptor",
@@ -7538,7 +7524,7 @@ dependencies = [
name = "wr_glyph_rasterizer" name = "wr_glyph_rasterizer"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"core-foundation 0.10.0", "core-foundation",
"core-graphics", "core-graphics",
"core-text", "core-text",
"dwrote", "dwrote",

View File

@@ -185,13 +185,6 @@ js-sys = { path = "build/rust/dummy-web/js-sys" }
wasm-bindgen = { path = "build/rust/dummy-web/wasm-bindgen" } wasm-bindgen = { path = "build/rust/dummy-web/wasm-bindgen" }
web-sys = { path = "build/rust/dummy-web/web-sys" } web-sys = { path = "build/rust/dummy-web/web-sys" }
# Upgrade `core-foundation` 0.9.* to 0.10.
core-foundation = { path = "build/rust/core-foundation" }
# Patch `core-graphics-types` 0.1.* to 0.2.
core-graphics-types = { path = "build/rust/core-graphics-types" }
# Overrides to allow easier use of common internal crates. # Overrides to allow easier use of common internal crates.
moz_asserts = { path = "mozglue/static/rust/moz_asserts" } moz_asserts = { path = "mozglue/static/rust/moz_asserts" }

View File

@@ -1,19 +0,0 @@
[package]
name = "core-foundation"
version = "0.9.999"
edition = "2018"
license = "MIT or APACHE-2.0"
[lib]
path = "lib.rs"
[dependencies.core-foundation]
version = "0.10.0"
default-features = false
[features]
default = ["core-foundation/default"]
link = ["core-foundation/link"]
mac_os_10_7_support = ["core-foundation/mac_os_10_7_support"]
mac_os_10_8_features = ["core-foundation/mac_os_10_8_features"]
with-uuid = ["core-foundation/with-uuid"]

View File

@@ -1,5 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
pub use core_foundation::*;

View File

@@ -1,16 +0,0 @@
[package]
name = "core-graphics-types"
version = "0.1.999"
edition = "2018"
license = "MIT or APACHE-2.0"
[lib]
path = "lib.rs"
[dependencies.core-graphics-types]
version = "0.2.0"
default-features = false
[features]
default = ["core-graphics-types/default"]
link = ["core-graphics-types/link"]

View File

@@ -1,5 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
pub use core_graphics_types::*;

View File

@@ -35,7 +35,7 @@ dwrote = "0.11"
winapi = "0.3" winapi = "0.3"
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation = "0.10" core-foundation = "0.9"
core-graphics = "0.24" core-graphics = "0.23"
foreign-types = "0.5.0" foreign-types = "0.5.0"
objc = "0.2" objc = "0.2"

59
gfx/wr/Cargo.lock generated
View File

@@ -445,7 +445,7 @@ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"block", "block",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"core-graphics-types 0.1.2", "core-graphics-types",
"foreign-types 0.3.2", "foreign-types 0.3.2",
"libc", "libc",
"objc", "objc",
@@ -498,17 +498,7 @@ version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3"
dependencies = [ dependencies = [
"core-foundation-sys 0.8.7", "core-foundation-sys 0.8.3",
"libc",
]
[[package]]
name = "core-foundation"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63"
dependencies = [
"core-foundation-sys 0.8.7",
"libc", "libc",
] ]
@@ -520,9 +510,9 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
[[package]] [[package]]
name = "core-foundation-sys" name = "core-foundation-sys"
version = "0.8.7" version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]] [[package]]
name = "core-graphics" name = "core-graphics"
@@ -544,20 +534,20 @@ checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"core-graphics-types 0.1.2", "core-graphics-types",
"foreign-types 0.3.2", "foreign-types 0.3.2",
"libc", "libc",
] ]
[[package]] [[package]]
name = "core-graphics" name = "core-graphics"
version = "0.24.0" version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1" checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 1.3.2",
"core-foundation 0.10.0", "core-foundation 0.9.2",
"core-graphics-types 0.2.0", "core-graphics-types",
"foreign-types 0.5.0", "foreign-types 0.5.0",
"libc", "libc",
] ]
@@ -573,17 +563,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "core-graphics-types"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb"
dependencies = [
"bitflags 2.4.2",
"core-foundation 0.10.0",
"libc",
]
[[package]] [[package]]
name = "core-text" name = "core-text"
version = "19.2.0" version = "19.2.0"
@@ -598,12 +577,12 @@ dependencies = [
[[package]] [[package]]
name = "core-text" name = "core-text"
version = "21.0.0" version = "20.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a593227b66cbd4007b2a050dfdd9e1d1318311409c8d600dc82ba1b15ca9c130" checksum = "c9d2790b5c08465d49f8dc05c8bcae9fea467855947db39b0f8145c091aaced5"
dependencies = [ dependencies = [
"core-foundation 0.10.0", "core-foundation 0.9.2",
"core-graphics 0.24.0", "core-graphics 0.23.1",
"foreign-types 0.5.0", "foreign-types 0.5.0",
"libc", "libc",
] ]
@@ -3523,9 +3502,9 @@ dependencies = [
name = "wr_glyph_rasterizer" name = "wr_glyph_rasterizer"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"core-foundation 0.10.0", "core-foundation 0.9.2",
"core-graphics 0.24.0", "core-graphics 0.23.1",
"core-text 21.0.0", "core-text 20.1.0",
"dwrote", "dwrote",
"env_logger", "env_logger",
"euclid", "euclid",
@@ -3565,8 +3544,8 @@ dependencies = [
"cc", "cc",
"chrono", "chrono",
"clap", "clap",
"core-foundation 0.10.0", "core-foundation 0.9.2",
"core-graphics 0.24.0", "core-graphics 0.23.1",
"crossbeam", "crossbeam",
"dwrote", "dwrote",
"env_logger", "env_logger",

View File

@@ -45,7 +45,7 @@ libc = "0.2"
dwrote = "0.11" dwrote = "0.11"
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation = "0.10.0" core-foundation = "0.9.2"
core-graphics = "0.24" core-graphics = "0.23"
core-text = { version = "21", default-features = false } core-text = { version = "20.1", default-features = false }
objc = "0.2" objc = "0.2"

View File

@@ -39,8 +39,8 @@ default-features = false
features = ["png"] features = ["png"]
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
core-graphics = "0.24" core-graphics = "0.23"
core-foundation = "0.10" core-foundation = "0.9"
[features] [features]
default = [ "env_logger" ] default = [ "env_logger" ]

View File

@@ -1 +1 @@
{"files":{"Cargo.toml":"8f18dba99a0470c9d6b59917291e7ece5465b3a05def7c244217bfa56867c8cc","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/array.rs":"4d469ca3f6aceb42dfaf7b26aa9ef14a8ebce05e02d0beda985fa32f2ec48963","src/attributed_string.rs":"7042f3fbf6904efecb15f01ce2e96eecf84973e0fef9be4c10d14944b0f90a24","src/bag.rs":"dec9ff467ac713526c3be8148ae41b21ab8840f393733bb53c77224ef089787c","src/base.rs":"5d0dee358519712e881e2edbea0ca6d3539958ed1ff3d70aa136af7e25292f22","src/binary_heap.rs":"0565125dbdb1fa578888e00f5b195ab91f0bf65881eabcd39de99ca811d756de","src/bit_vector.rs":"dcdaa573d90b25bdc6b98f2330110e8591b7c329601643dcc6aa23b1b9ec7210","src/bundle.rs":"83ac9d7c45f06161767588c465eed086a773714734da0614d98d000326df3603","src/calendar.rs":"b73796956e50d92f0479479e84246712804537d694e4cdd01d5440e5fbcbd333","src/characterset.rs":"ba60f78884cd860e151df35c1953bcd6eae46d9f27c36584b66e508e2301a7a8","src/data.rs":"fe4e2effbfd9348575507d06aa53cd583808c908f9e03ac1a076b077230c9c01","src/date.rs":"971d681f6eeefa3764d8a43e53cbf7c937c419331207c7bb003a25c9b0b0722f","src/date_formatter.rs":"05e84ac3cf4c0daae2e939a9bedddfd10dd5309ea1536bf8241de41971d11f8a","src/dictionary.rs":"ac23d99208131049c82c13b37a99b4fd129224d1dafcd65ff2f9de200d73e9d1","src/error.rs":"b523faa8c498e1115c72e71a10e7a3bf8bcc01588cb02e70dc9fd45cbdaa35f6","src/file_security.rs":"542c5d8eef22424479abcb448601611d85c9cc96e41cd6cd6de5ea3efe1213a6","src/filedescriptor.rs":"706eebde408713cc49bbab078e86fe51e95fe29b167420bbcbb573847dcf29e2","src/lib.rs":"5c14390b7b45c769ea53664621c1a9f5fa39fda509288d9e13018170213bbe4b","src/locale.rs":"372190a9cb5659fba0b92598c5dcbdaa3f90b29b3440ddcfe77931e85c1f96d9","src/mach_port.rs":"e52c2ce794e82ebeeb0cba170902409f18626b7d9e29d6dcd333e9c13411408a","src/messageport.rs":"d8e342f0eabe47f6f4746fdbf996bf9008b4b5f1fa24e0bc4ecd73b2de81b234","src/notification_center.rs":"0ab30523bc4ac799016970c9c59594cbb3afeda054705c15d0979eb07abb7c7d","src/number.rs":"28b10c9d2361cac18549ef66839f595e98490096e756e9a7f25536b6ceb1f687","src/number_formatter.rs":"024fbd3b2ecaecf19cfdb463e0f0096d1fa28bc4ce636659e53459d1b01af658","src/plugin.rs":"0904b1b4b882e626d5d63ac91c540dfdf65f5f4428cf38c9def6acfc7ed84cd3","src/preferences.rs":"49d8ac0c669a01678fa0dc26d6cb13bc72004c8422e525bf3e26f01feb5a3693","src/propertylist.rs":"f7f12cb8c67098e5b96cb8a63b4a947549a2cbf7a6523ce314141b4f8cc202c4","src/runloop.rs":"8fa6e5e74a013f8101d5a4f6616818573adc7ed197e28b799dca4c3a1cedaac9","src/set.rs":"0e619ec75a6b975be6b6d59ed3b01c803dd635020288b178db949b1c45442d17","src/socket.rs":"b67737b8c04142fa4d198c19f0867fd653837e529bf2665e78750c94f469a793","src/stream.rs":"f9b1099191010a96ce0aadcc22385732710dfc1521873096a9db67ad80472e36","src/string.rs":"fa46e7b7865709494bb05c9c7c6006f165fafa956ab41f053af0e4b41904efa4","src/string_tokenizer.rs":"0da4ae1a841591871602f21cc1c9b51289a0514a255b269e4b61afdeb0097c10","src/timezone.rs":"f584ea76627f12f33eba25d7ea054c2d2c10a2d96474fce12858ccb4bdf688c1","src/tree.rs":"50d513ea1801797c549218c51f5ebf77be4cf80901b12ce3ba0a223c602995d4","src/url.rs":"cb08b0bd24708e6572711f4f82b88370e811aabf4f58f22c34f0f873a44c7486","src/url_enumerator.rs":"bd531f31f6c62b2849d5ccbc82bfc3ae3866c4cdd6768b6c2fe380f24c290540","src/user_notification.rs":"e86b052817028847e62121752e7d58f8ed6f8ad15f5ef947c1fa93bbd0fcbf26","src/uuid.rs":"48af493dc6c8b00d804d6ae92a2fd71eabdae8a2be0500baaa55ce56345c350a","src/xml_node.rs":"c7894a4d08f695ba75d539b3c8d6cc3a90544000786fe3f9cd9c02ad7541213b","src/xml_parser.rs":"ac8a3d2c71ec8ec80603ce5ef214147c0e93bed211c1559a47f14fc31cb0bbaf"},"package":"773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"} {"files":{"Cargo.toml":"f8b5e9fa6c6bbfad4e3c0acfbad03f05cbd98073e664e3ad2fe16a56dd492aa1","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/array.rs":"4d469ca3f6aceb42dfaf7b26aa9ef14a8ebce05e02d0beda985fa32f2ec48963","src/attributed_string.rs":"7042f3fbf6904efecb15f01ce2e96eecf84973e0fef9be4c10d14944b0f90a24","src/bag.rs":"dec9ff467ac713526c3be8148ae41b21ab8840f393733bb53c77224ef089787c","src/base.rs":"5d0dee358519712e881e2edbea0ca6d3539958ed1ff3d70aa136af7e25292f22","src/binary_heap.rs":"0565125dbdb1fa578888e00f5b195ab91f0bf65881eabcd39de99ca811d756de","src/bit_vector.rs":"dcdaa573d90b25bdc6b98f2330110e8591b7c329601643dcc6aa23b1b9ec7210","src/bundle.rs":"83ac9d7c45f06161767588c465eed086a773714734da0614d98d000326df3603","src/calendar.rs":"b73796956e50d92f0479479e84246712804537d694e4cdd01d5440e5fbcbd333","src/characterset.rs":"ba60f78884cd860e151df35c1953bcd6eae46d9f27c36584b66e508e2301a7a8","src/data.rs":"fe4e2effbfd9348575507d06aa53cd583808c908f9e03ac1a076b077230c9c01","src/date.rs":"971d681f6eeefa3764d8a43e53cbf7c937c419331207c7bb003a25c9b0b0722f","src/date_formatter.rs":"05e84ac3cf4c0daae2e939a9bedddfd10dd5309ea1536bf8241de41971d11f8a","src/dictionary.rs":"ac23d99208131049c82c13b37a99b4fd129224d1dafcd65ff2f9de200d73e9d1","src/error.rs":"b523faa8c498e1115c72e71a10e7a3bf8bcc01588cb02e70dc9fd45cbdaa35f6","src/file_security.rs":"542c5d8eef22424479abcb448601611d85c9cc96e41cd6cd6de5ea3efe1213a6","src/filedescriptor.rs":"706eebde408713cc49bbab078e86fe51e95fe29b167420bbcbb573847dcf29e2","src/lib.rs":"8ae5082d92ebf6b1a53332211b87986aa7228534f5e341b62100e522b7fcadec","src/locale.rs":"372190a9cb5659fba0b92598c5dcbdaa3f90b29b3440ddcfe77931e85c1f96d9","src/mach_port.rs":"e52c2ce794e82ebeeb0cba170902409f18626b7d9e29d6dcd333e9c13411408a","src/messageport.rs":"d8e342f0eabe47f6f4746fdbf996bf9008b4b5f1fa24e0bc4ecd73b2de81b234","src/notification_center.rs":"0ab30523bc4ac799016970c9c59594cbb3afeda054705c15d0979eb07abb7c7d","src/number.rs":"28b10c9d2361cac18549ef66839f595e98490096e756e9a7f25536b6ceb1f687","src/number_formatter.rs":"024fbd3b2ecaecf19cfdb463e0f0096d1fa28bc4ce636659e53459d1b01af658","src/plugin.rs":"0904b1b4b882e626d5d63ac91c540dfdf65f5f4428cf38c9def6acfc7ed84cd3","src/preferences.rs":"49d8ac0c669a01678fa0dc26d6cb13bc72004c8422e525bf3e26f01feb5a3693","src/propertylist.rs":"f7f12cb8c67098e5b96cb8a63b4a947549a2cbf7a6523ce314141b4f8cc202c4","src/runloop.rs":"8fa6e5e74a013f8101d5a4f6616818573adc7ed197e28b799dca4c3a1cedaac9","src/set.rs":"0e619ec75a6b975be6b6d59ed3b01c803dd635020288b178db949b1c45442d17","src/socket.rs":"b67737b8c04142fa4d198c19f0867fd653837e529bf2665e78750c94f469a793","src/stream.rs":"f9b1099191010a96ce0aadcc22385732710dfc1521873096a9db67ad80472e36","src/string.rs":"fa46e7b7865709494bb05c9c7c6006f165fafa956ab41f053af0e4b41904efa4","src/string_tokenizer.rs":"0da4ae1a841591871602f21cc1c9b51289a0514a255b269e4b61afdeb0097c10","src/timezone.rs":"f584ea76627f12f33eba25d7ea054c2d2c10a2d96474fce12858ccb4bdf688c1","src/tree.rs":"50d513ea1801797c549218c51f5ebf77be4cf80901b12ce3ba0a223c602995d4","src/url.rs":"cb08b0bd24708e6572711f4f82b88370e811aabf4f58f22c34f0f873a44c7486","src/url_enumerator.rs":"bd531f31f6c62b2849d5ccbc82bfc3ae3866c4cdd6768b6c2fe380f24c290540","src/user_notification.rs":"e86b052817028847e62121752e7d58f8ed6f8ad15f5ef947c1fa93bbd0fcbf26","src/uuid.rs":"48af493dc6c8b00d804d6ae92a2fd71eabdae8a2be0500baaa55ce56345c350a","src/xml_node.rs":"c7894a4d08f695ba75d539b3c8d6cc3a90544000786fe3f9cd9c02ad7541213b","src/xml_parser.rs":"ac8a3d2c71ec8ec80603ce5ef214147c0e93bed211c1559a47f14fc31cb0bbaf"},"package":"06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"}

View File

@@ -12,16 +12,10 @@
[package] [package]
edition = "2018" edition = "2018"
name = "core-foundation-sys" name = "core-foundation-sys"
version = "0.8.7" version = "0.8.6"
authors = ["The Servo Project Developers"] authors = ["The Servo Project Developers"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Bindings to Core Foundation for macOS" description = "Bindings to Core Foundation for macOS"
homepage = "https://github.com/servo/core-foundation-rs" homepage = "https://github.com/servo/core-foundation-rs"
readme = false
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
repository = "https://github.com/servo/core-foundation-rs" repository = "https://github.com/servo/core-foundation-rs"
@@ -29,10 +23,6 @@ repository = "https://github.com/servo/core-foundation-rs"
all-features = true all-features = true
default-target = "x86_64-apple-darwin" default-target = "x86_64-apple-darwin"
[lib]
name = "core_foundation_sys"
path = "src/lib.rs"
[dependencies] [dependencies]
[features] [features]

View File

@@ -23,13 +23,7 @@
// https://github.com/rust-lang/lang-team/issues/102 // https://github.com/rust-lang/lang-team/issues/102
#[cfg_attr( #[cfg_attr(
all( all(
any( any(target_os = "macos", target_os = "ios", target_os = "tvos"),
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
),
feature = "link" feature = "link"
), ),
link(name = "CoreFoundation", kind = "framework") link(name = "CoreFoundation", kind = "framework")

View File

@@ -1 +1 @@
{"files":{"Cargo.toml":"6434efeab4199cd76aacf3061bdafb6083e15cf815f00e750cf0e05c55e22ffb","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/array.rs":"1ec64187ec7c3ff0a9cf9739fb83d1f0b6141d827e4f21a14203b7058ca12056","src/attributed_string.rs":"7c129d266872bf9e0f8cbd9477d8cc27405b806395e59e1647bedf9af06f8949","src/base.rs":"7ec2afcbc200aabaa01687efce2eb27c9effc9eae64d3c579827de731fbd290e","src/boolean.rs":"60aef5be531e867f03524c32a88609100d07d9166184545feab760af9eb3d7ec","src/bundle.rs":"c534b2e05a7e6a8f8232e925f5821657bd57b3019c6f85ab84a7606f5cc70140","src/characterset.rs":"12fd3f2b0444070a6932d8ddec58aae2479e77bcd2028d85eb40e8d7635beac8","src/data.rs":"15464aea7002a2a247b492e0c9fa402ff6867540fa33bc00feec88e07609f722","src/date.rs":"e2a15f5c304ddcb78facd3d70c41e9b7ad4be483723f686592756767904a31d0","src/dictionary.rs":"617ef92eb6334ab838e40b050fdfc5a037865d44cdf44d321a1f8ab52808e161","src/error.rs":"433982fb7b421f5bf386d7eba22a7ffb8673486bb6455ff3fa30c875b064f718","src/filedescriptor.rs":"c06e68963bf6d71ffd95f08b74fcf5fa24e088bf336dd6de7923f25ea4868342","src/lib.rs":"b3b1fbbebfe65c89365cfa30b4f83bb416d96ac33bd9b3636a25a852908beb60","src/mach_port.rs":"e5400039696a70bdc0e6e14b1a68c493b741136945ce0eb67208cd4d0f895e1b","src/number.rs":"48e2efe219a7eaa4bc7bc3a48fa45f32fbbfd6363620838fef16a98b86e05061","src/propertylist.rs":"23e9a42d506983374d0c3439ab80407bbd472a3487812693a411597ff5eb1bd8","src/runloop.rs":"ff5bbb8a145befa7f244d937161d87f059ea60c9c482ab32e845222ee6fabf34","src/set.rs":"39e41a3d4f9e4dd50864a9c3581508e1b09549dc89d57fa84935964d98469bad","src/string.rs":"3b25b169d0f18dae66e6f123a116a04c79096f9e44e4221d4dbdcea4e152355c","src/timezone.rs":"1930ae99f2553d353b6d79f31f26f8df3f3af9eaadeff8f374b4aa9b91a214e9","src/url.rs":"dc125dd95e9b8386770b89f5437ab904ceff0843e1bf820f548bddfc31e1c40c","src/uuid.rs":"f9720e2e4369e1b22c1dc9bcbb49a38a824ad5eb92cd7fae86d79c3ce1d1a384","tests/use_macro_outside_crate.rs":"c172fa1edb4f228e13de7cf6101b5c057aa88b0c148d58f460369cb38ca7e5cb"},"package":"b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63"} {"files":{"Cargo.toml":"2e85272c5cffb75aadcbb83d8ca1a619af3ccb9d810c1e07349f3b618fa05b7e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/array.rs":"1ec64187ec7c3ff0a9cf9739fb83d1f0b6141d827e4f21a14203b7058ca12056","src/attributed_string.rs":"7c129d266872bf9e0f8cbd9477d8cc27405b806395e59e1647bedf9af06f8949","src/base.rs":"7ec2afcbc200aabaa01687efce2eb27c9effc9eae64d3c579827de731fbd290e","src/boolean.rs":"60aef5be531e867f03524c32a88609100d07d9166184545feab760af9eb3d7ec","src/bundle.rs":"00f7ae30df3cc59079e771da0eda2b1972f52b13cc7bd95ae48b0e9bd1836ff4","src/characterset.rs":"126884d51e75db5be4cb2988f4e97e0e1b592c900e0158082d8c0dda7a453b0f","src/data.rs":"bfaa4427b6bc4c838188506ee154622983bbfcc10641be3f58525b89a854d4cd","src/date.rs":"d1ec3f918cf6c62d0e36d50d495c125d275a9a89442a740eea5d41dcc71a96fa","src/dictionary.rs":"f6d73c08fa9afd30d1df70cceea55dd30c7b81b8a78117d8843f1b3390051dca","src/error.rs":"433982fb7b421f5bf386d7eba22a7ffb8673486bb6455ff3fa30c875b064f718","src/filedescriptor.rs":"d3ece69ff461b215f7ff98dc6139723c4a5a53849a9747cccd24e72c185c4ffd","src/lib.rs":"92502d5f7d0e2ba266ec3531c01dd996e1832f1e6e9e66b10596e6fb870480cb","src/mach_port.rs":"e5400039696a70bdc0e6e14b1a68c493b741136945ce0eb67208cd4d0f895e1b","src/number.rs":"48e2efe219a7eaa4bc7bc3a48fa45f32fbbfd6363620838fef16a98b86e05061","src/propertylist.rs":"23e9a42d506983374d0c3439ab80407bbd472a3487812693a411597ff5eb1bd8","src/runloop.rs":"ff5bbb8a145befa7f244d937161d87f059ea60c9c482ab32e845222ee6fabf34","src/set.rs":"39e41a3d4f9e4dd50864a9c3581508e1b09549dc89d57fa84935964d98469bad","src/string.rs":"3b25b169d0f18dae66e6f123a116a04c79096f9e44e4221d4dbdcea4e152355c","src/timezone.rs":"7b8e46bde9e8aa71a906ab26b8ff7b6251568ebf210bab10d11c6ba0ce64ecd5","src/url.rs":"dc125dd95e9b8386770b89f5437ab904ceff0843e1bf820f548bddfc31e1c40c","src/uuid.rs":"e290c592871b7cea6ec09d2b3e34ec9033968dda725cf49e410535f79d2b41f8","tests/use_macro_outside_crate.rs":"ed5e74ac9e988f2609c0b785189f1e6368d693f6401603ad065521f3ab51df94"},"package":"91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"}

View File

@@ -12,16 +12,10 @@
[package] [package]
edition = "2018" edition = "2018"
name = "core-foundation" name = "core-foundation"
version = "0.10.0" version = "0.9.4"
authors = ["The Servo Project Developers"] authors = ["The Servo Project Developers"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Bindings to Core Foundation for macOS" description = "Bindings to Core Foundation for macOS"
homepage = "https://github.com/servo/core-foundation-rs" homepage = "https://github.com/servo/core-foundation-rs"
readme = false
keywords = [ keywords = [
"macos", "macos",
"framework", "framework",
@@ -35,23 +29,19 @@ repository = "https://github.com/servo/core-foundation-rs"
all-features = true all-features = true
default-target = "x86_64-apple-darwin" default-target = "x86_64-apple-darwin"
[lib] [dependencies.chrono]
name = "core_foundation" version = "0.4"
path = "src/lib.rs" optional = true
[[test]]
name = "use_macro_outside_crate"
path = "tests/use_macro_outside_crate.rs"
[dependencies.core-foundation-sys] [dependencies.core-foundation-sys]
version = "0.8.7" version = "0.8.6"
default-features = false default-features = false
[dependencies.libc] [dependencies.libc]
version = "0.2" version = "0.2"
[dependencies.uuid] [dependencies.uuid]
version = "1" version = "0.5"
optional = true optional = true
[features] [features]
@@ -59,4 +49,5 @@ default = ["link"]
link = ["core-foundation-sys/link"] link = ["core-foundation-sys/link"]
mac_os_10_7_support = ["core-foundation-sys/mac_os_10_7_support"] mac_os_10_7_support = ["core-foundation-sys/mac_os_10_7_support"]
mac_os_10_8_features = ["core-foundation-sys/mac_os_10_8_features"] mac_os_10_8_features = ["core-foundation-sys/mac_os_10_8_features"]
with-chrono = ["chrono"]
with-uuid = ["uuid"] with-uuid = ["uuid"]

View File

@@ -189,7 +189,7 @@ fn safari_private_frameworks_url() {
} }
#[test] #[test]
fn non_existent_bundle() { fn non_existant_bundle() {
use crate::string::CFString; use crate::string::CFString;
use crate::url::{kCFURLPOSIXPathStyle, CFURL}; use crate::url::{kCFURLPOSIXPathStyle, CFURL};

View File

@@ -14,7 +14,7 @@ pub use core_foundation_sys::characterset::*;
use crate::base::TCFType; use crate::base::TCFType;
declare_TCFType! { declare_TCFType! {
/// An immutable set of Unicode characters. /// An immutable set of Unicde characters.
CFCharacterSet, CFCharacterSetRef CFCharacterSet, CFCharacterSetRef
} }
impl_TCFType!(CFCharacterSet, CFCharacterSetRef, CFCharacterSetGetTypeID); impl_TCFType!(CFCharacterSet, CFCharacterSetRef, CFCharacterSetGetTypeID);

View File

@@ -81,14 +81,7 @@ impl CFData {
/// read-only. /// read-only.
#[inline] #[inline]
pub fn bytes(&self) -> &[u8] { pub fn bytes(&self) -> &[u8] {
unsafe { unsafe { slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize) }
let ptr = CFDataGetBytePtr(self.0);
// Rust slice must never have a NULL pointer
if ptr.is_null() {
return &[];
}
slice::from_raw_parts(ptr, self.len() as usize)
}
} }
/// Returns the length of this byte buffer. /// Returns the length of this byte buffer.

View File

@@ -14,6 +14,9 @@ pub use core_foundation_sys::date::*;
use crate::base::TCFType; use crate::base::TCFType;
#[cfg(feature = "with-chrono")]
use chrono::NaiveDateTime;
declare_TCFType! { declare_TCFType! {
/// A date. /// A date.
CFDate, CFDateRef CFDate, CFDateRef
@@ -40,6 +43,26 @@ impl CFDate {
pub fn abs_time(&self) -> CFAbsoluteTime { pub fn abs_time(&self) -> CFAbsoluteTime {
unsafe { CFDateGetAbsoluteTime(self.0) } unsafe { CFDateGetAbsoluteTime(self.0) }
} }
#[cfg(feature = "with-chrono")]
pub fn naive_utc(&self) -> NaiveDateTime {
let ts = unsafe { self.abs_time() + kCFAbsoluteTimeIntervalSince1970 };
let (secs, nanos) = if ts.is_sign_positive() {
(ts.trunc() as i64, ts.fract())
} else {
// nanoseconds can't be negative in NaiveDateTime
(ts.trunc() as i64 - 1, 1.0 - ts.fract().abs())
};
NaiveDateTime::from_timestamp(secs, (nanos * 1e9).floor() as u32)
}
#[cfg(feature = "with-chrono")]
pub fn from_naive_utc(time: NaiveDateTime) -> CFDate {
let secs = time.timestamp();
let nanos = time.timestamp_subsec_nanos();
let ts = unsafe { secs as f64 + (nanos as f64 / 1e9) - kCFAbsoluteTimeIntervalSince1970 };
CFDate::new(ts)
}
} }
#[cfg(test)] #[cfg(test)]
@@ -47,6 +70,18 @@ mod test {
use super::CFDate; use super::CFDate;
use std::cmp::Ordering; use std::cmp::Ordering;
#[cfg(feature = "with-chrono")]
use chrono::NaiveDateTime;
#[cfg(feature = "with-chrono")]
fn approx_eq(a: f64, b: f64) -> bool {
use std::f64;
let same_sign = a.is_sign_positive() == b.is_sign_positive();
let equal = ((a - b).abs() / f64::min(a.abs() + b.abs(), f64::MAX)) < f64::EPSILON;
same_sign && equal
}
#[test] #[test]
fn date_comparison() { fn date_comparison() {
let now = CFDate::now(); let now = CFDate::now();
@@ -62,4 +97,25 @@ mod test {
let same_time = CFDate::new(now.abs_time()); let same_time = CFDate::new(now.abs_time());
assert_eq!(now, same_time); assert_eq!(now, same_time);
} }
#[test]
#[cfg(feature = "with-chrono")]
fn date_chrono_conversion_positive() {
let date = CFDate::now();
let datetime = date.naive_utc();
let converted = CFDate::from_naive_utc(datetime);
assert!(approx_eq(date.abs_time(), converted.abs_time()));
}
#[test]
#[cfg(feature = "with-chrono")]
fn date_chrono_conversion_negative() {
use super::kCFAbsoluteTimeIntervalSince1970;
let ts = unsafe { kCFAbsoluteTimeIntervalSince1970 - 420.0 };
let date = CFDate::new(ts);
let datetime: NaiveDateTime = date.naive_utc();
let converted = CFDate::from_naive_utc(datetime);
assert!(approx_eq(date.abs_time(), converted.abs_time()));
}
} }

View File

@@ -21,7 +21,7 @@ use crate::base::{CFIndexConvertible, TCFType};
use crate::base::{FromVoid, ItemRef, ToVoid}; use crate::base::{FromVoid, ItemRef, ToVoid};
use crate::ConcreteCFType; use crate::ConcreteCFType;
// consume the type parameters with `PhantomData` // consume the type parameters with PhantomDatas
pub struct CFDictionary<K = *const c_void, V = *const c_void>( pub struct CFDictionary<K = *const c_void, V = *const c_void>(
CFDictionaryRef, CFDictionaryRef,
PhantomData<K>, PhantomData<K>,
@@ -148,7 +148,7 @@ impl<K, V> CFDictionary<K, V> {
} }
} }
// consume the type parameters with `PhantomData` // consume the type parameters with PhantomDatas
pub struct CFMutableDictionary<K = *const c_void, V = *const c_void>( pub struct CFMutableDictionary<K = *const c_void, V = *const c_void>(
CFMutableDictionaryRef, CFMutableDictionaryRef,
PhantomData<K>, PhantomData<K>,

View File

@@ -97,6 +97,8 @@ impl AsRawFd for CFFileDescriptor {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
extern crate libc;
use super::*; use super::*;
use crate::runloop::CFRunLoop; use crate::runloop::CFRunLoop;
use core_foundation_sys::base::CFOptionFlags; use core_foundation_sys::base::CFOptionFlags;

View File

@@ -15,6 +15,12 @@
//! It also provides a framework for other crates to use when wrapping //! It also provides a framework for other crates to use when wrapping
//! other frameworks that use the CoreFoundation framework. //! other frameworks that use the CoreFoundation framework.
extern crate core_foundation_sys;
extern crate libc;
#[cfg(feature = "with-chrono")]
extern crate chrono;
use crate::base::TCFType; use crate::base::TCFType;
pub unsafe trait ConcreteCFType: TCFType {} pub unsafe trait ConcreteCFType: TCFType {}
@@ -26,7 +32,7 @@ pub unsafe trait ConcreteCFType: TCFType {}
/// provided using the [`impl_TCFType`] macro. /// provided using the [`impl_TCFType`] macro.
/// ///
/// ``` /// ```
/// use core_foundation::{declare_TCFType, impl_TCFType}; /// #[macro_use] extern crate core_foundation;
/// // Make sure that the `TCFType` trait is in scope. /// // Make sure that the `TCFType` trait is in scope.
/// use core_foundation::base::{CFTypeID, TCFType}; /// use core_foundation::base::{CFTypeID, TCFType};
/// ///

View File

@@ -16,6 +16,9 @@ use crate::base::TCFType;
use crate::date::{CFDate, CFTimeInterval}; use crate::date::{CFDate, CFTimeInterval};
use crate::string::CFString; use crate::string::CFString;
#[cfg(feature = "with-chrono")]
use chrono::{FixedOffset, NaiveDateTime};
declare_TCFType! { declare_TCFType! {
/// A time zone. /// A time zone.
CFTimeZone, CFTimeZoneRef CFTimeZone, CFTimeZoneRef
@@ -53,6 +56,17 @@ impl CFTimeZone {
unsafe { CFTimeZoneGetSecondsFromGMT(self.0, date.abs_time()) } unsafe { CFTimeZoneGetSecondsFromGMT(self.0, date.abs_time()) }
} }
#[cfg(feature = "with-chrono")]
pub fn offset_at_date(&self, date: NaiveDateTime) -> FixedOffset {
let date = CFDate::from_naive_utc(date);
FixedOffset::east(self.seconds_from_gmt(date) as i32)
}
#[cfg(feature = "with-chrono")]
pub fn from_offset(offset: FixedOffset) -> CFTimeZone {
CFTimeZone::new(offset.local_minus_utc() as f64)
}
/// The timezone database ID that identifies the time zone. E.g. `"America/Los_Angeles" `or /// The timezone database ID that identifies the time zone. E.g. `"America/Los_Angeles" `or
/// `"Europe/Paris"`. /// `"Europe/Paris"`.
pub fn name(&self) -> CFString { pub fn name(&self) -> CFString {
@@ -64,10 +78,22 @@ impl CFTimeZone {
mod test { mod test {
use super::CFTimeZone; use super::CFTimeZone;
#[cfg(feature = "with-chrono")]
use chrono::{FixedOffset, NaiveDateTime};
#[test] #[test]
fn timezone_comparison() { fn timezone_comparison() {
let system = CFTimeZone::system(); let system = CFTimeZone::system();
let default = CFTimeZone::default(); let default = CFTimeZone::default();
assert_eq!(system, default); assert_eq!(system, default);
} }
#[test]
#[cfg(feature = "with-chrono")]
fn timezone_chrono_conversion() {
let offset = FixedOffset::west(28800);
let tz = CFTimeZone::from_offset(offset);
let converted = tz.offset_at_date(NaiveDateTime::from_timestamp(0, 0));
assert_eq!(offset, converted);
}
} }

View File

@@ -9,13 +9,16 @@
//! Core Foundation UUID objects. //! Core Foundation UUID objects.
#[cfg(feature = "with-uuid")]
extern crate uuid;
use core_foundation_sys::base::kCFAllocatorDefault; use core_foundation_sys::base::kCFAllocatorDefault;
pub use core_foundation_sys::uuid::*; pub use core_foundation_sys::uuid::*;
use crate::base::TCFType; use crate::base::TCFType;
#[cfg(feature = "with-uuid")] #[cfg(feature = "with-uuid")]
use uuid::Uuid; use self::uuid::Uuid;
declare_TCFType! { declare_TCFType! {
/// A UUID. /// A UUID.
@@ -48,7 +51,7 @@ impl From<CFUUID> for Uuid {
b.byte0, b.byte1, b.byte2, b.byte3, b.byte4, b.byte5, b.byte6, b.byte7, b.byte8, b.byte0, b.byte1, b.byte2, b.byte3, b.byte4, b.byte5, b.byte6, b.byte7, b.byte8,
b.byte9, b.byte10, b.byte11, b.byte12, b.byte13, b.byte14, b.byte15, b.byte9, b.byte10, b.byte11, b.byte12, b.byte13, b.byte14, b.byte15,
]; ];
Uuid::from_bytes(bytes) Uuid::from_bytes(&bytes).unwrap()
} }
} }

View File

@@ -1,5 +1,7 @@
#[macro_use]
extern crate core_foundation;
use core_foundation::base::{CFComparisonResult, TCFType}; use core_foundation::base::{CFComparisonResult, TCFType};
use core_foundation::{declare_TCFType, impl_CFComparison, impl_CFTypeDescription, impl_TCFType};
use std::os::raw::c_void; use std::os::raw::c_void;
// sys equivalent stuff that must be declared // sys equivalent stuff that must be declared

View File

@@ -1 +1 @@
{"files":{"Cargo.toml":"3e037c711ddf0b568732aa2b8b4a7f66ecd5a72bdb59055329636ebe8c895628","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/base.rs":"7e4e9c23f874443d0095f82d2786dc65b6b6635cbe8b3514999be80445a92bc8","src/geometry.rs":"7eda026c3db65cac836531565f85120132ab1ec84f76467a68ff040b8dc437c4","src/lib.rs":"82b8fd756d805d5fc9dc8210fe1faaee94ed905fe21f58dc2114eac2c840981b"},"package":"3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb"} {"files":{"Cargo.toml":"a49bc6534c1e5be53c72f3016ff7f64509a5570868dc943178c75b541fa839da","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/base.rs":"7e4e9c23f874443d0095f82d2786dc65b6b6635cbe8b3514999be80445a92bc8","src/geometry.rs":"7eda026c3db65cac836531565f85120132ab1ec84f76467a68ff040b8dc437c4","src/lib.rs":"42baf24c75dc6627bd4ca8481c503febf54e7eafa50cce40804042ddc74881c8"},"package":"45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf"}

View File

@@ -12,31 +12,21 @@
[package] [package]
edition = "2018" edition = "2018"
name = "core-graphics-types" name = "core-graphics-types"
version = "0.2.0" version = "0.1.3"
authors = ["The Servo Project Developers"] authors = ["The Servo Project Developers"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Bindings for some fundamental Core Graphics types" description = "Bindings for some fundamental Core Graphics types"
homepage = "https://github.com/servo/core-foundation-rs" homepage = "https://github.com/servo/core-foundation-rs"
readme = false
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
repository = "https://github.com/servo/core-foundation-rs" repository = "https://github.com/servo/core-foundation-rs"
[package.metadata.docs.rs] [package.metadata.docs.rs]
default-target = "x86_64-apple-darwin" default-target = "x86_64-apple-darwin"
[lib]
name = "core_graphics_types"
path = "src/lib.rs"
[dependencies.bitflags] [dependencies.bitflags]
version = "2" version = "1.0"
[dependencies.core-foundation] [dependencies.core-foundation]
version = "0.10" version = "0.9.4"
default-features = false default-features = false
[dependencies.libc] [dependencies.libc]

View File

@@ -7,5 +7,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
extern crate core_foundation;
extern crate libc;
pub mod base; pub mod base;
pub mod geometry; pub mod geometry;

View File

@@ -1 +1 @@
{"files":{"COPYRIGHT":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"cc2978c2caecf2565b6d4792f644f6c7882d2983d4d5f793a9f589a21c9c97c6","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","README.md":"d4647555c91dc60ca40c14acdce19bba60cfacc6bb69737f71e3be41e39bf0aa","src/access.rs":"b78ebb3ece8c0e5d3ec49ed664d9453e6b1b8dec4d5831b5380f05937c283526","src/base.rs":"838683ff67253f4aff1d4b4177531210ca73d4e61f05c5d96a8f196b2a88c787","src/color.rs":"e809b71d60fc25005171f650c06820a24570db9a5d6b92f2be4270797f226708","src/color_space.rs":"be7eaf9d77ddd0b27666aa269e6510baa2661a19a2c27edf16af974b879df67b","src/context.rs":"0698858cf2e844455685738f873607c1d78812a068304b02bd111a83b0dd467b","src/data_provider.rs":"4140916cb88a706cec35f600801705cff2547ccf1287757758931b8cb9ee9879","src/display.rs":"9da9eb0ecbc5c720e54aeac77e49c8423a27605275f498d0e7fbd0bf41b67ed5","src/event.rs":"1a03f1f407e59c05654525d70f280e9e3eedeef00431bda9b2b7d4c4739e2b4d","src/event_source.rs":"c924f6287e1e83e8aeeddc27456b4ba91b3e8b28be9d5b5d320b62a3502edfe9","src/font.rs":"2c5fccbb94760a216197eac4f24ee01b59438f9fc17b2f4527b9f6a13a650b0c","src/geometry.rs":"5b68fa373ab116aba741e1b21dfe6d13f92b2d49f7d00a4ebe6cef19b4987caa","src/gradient.rs":"a8b6a4628e69eedaa4fc1a6dfaf2b6ae13704e9f761894632c733f5147f2a2f4","src/image.rs":"f79e19cbca11db331a11a8169e0d33b1d519c989b02684f1e610fead93adbc23","src/lib.rs":"c42c8eca7f73bc03b58c1aab38d34d8ea6beaf4efce9c0cd2d7efc2ca5ec3848","src/path.rs":"cf69a1d0c8dab96bf7b85e44ec0b64c025add36f2c81c62c6b11e9c90b22ffae","src/private.rs":"1d4c2b5b6241a0c82858ca0e7abaed1ec2cd3478db6f40a8c635f5f6b703d4fa","src/sys.rs":"6cda2b2d1cc43cb9585503ef7ca5dfc705900e37c359e03d732838cec4e73bcd","src/window.rs":"fbc0feef58c3a703ceff651842eaaa63903d5d5c0f5841e6dcdec0d37d630da7"},"package":"fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1"} {"files":{"COPYRIGHT":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"3bd0c7d76d294587f2928231ecff8824cdafafded65561434d2698d1cc649cc7","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","README.md":"6745c3c38183d2eda9b1fa265fb0a95018db5c110cbabc00b32327d951bbe2ea","src/access.rs":"919937f8fe61966543c602e30d5d59d61e0b7313bb6b33c25aa600ec5e43345e","src/base.rs":"838683ff67253f4aff1d4b4177531210ca73d4e61f05c5d96a8f196b2a88c787","src/color.rs":"4c8ec4ab828cbc1b2a1538a34a51f5b380927f2f1daf187dff6f732f57a43656","src/color_space.rs":"6a0be06bb7ecdf9d20c461912359d22e0ffd7151c6977a8d9b3b0efdd7929442","src/context.rs":"93d543bd2b77ee6b3132b4378b1652576354fae9bb675cde63e0347d81fec334","src/data_provider.rs":"88e1cdd75c35cff44150f0aac75de6ac715acbf4328abef1b2f191b54401c650","src/display.rs":"391f24669ad1ad5dcd6d15b5e418b6b07731186d3c18d94c8c0935ab348fb3b9","src/event.rs":"90425316094ea2dba724451a1cb0f8008fce64ab746e79a28258a773c67f158b","src/event_source.rs":"a81f8bbd41bf4c4e3e91d6a6eab31356728fbf08787aca899ed03259808dfe4a","src/font.rs":"43cad7dfcc49f5f2de408146c6e38843b2d0092b3f5880fbf80e43e18b100f25","src/geometry.rs":"8e12dc89835406bfa514de8fb58f5fd435724d1ddb97dc3a70392efbcf1c42ed","src/gradient.rs":"dd957f14b77d448fa1e51c2e67849364062aa1d5bd60405f060f9a094c628061","src/image.rs":"72076f34a805b1d2336e425cc29d2ec3583046b847e9284ef7413f7eca2acb9a","src/lib.rs":"ca6aabcc5f307a9b15cd3e531d7fb9f54bdf58d9717d38e007e4facf1ca8c9a4","src/path.rs":"9389719ee257d86f50075b294b1b9df8fb3fc93b3442deee868e188489613a2d","src/private.rs":"da3fd61338bab2d8e26aa5433b2e18ecd2a0a408c62e1ac2b33a0f87f2dad88a","src/sys.rs":"3077395beb77193530b713aa681cb61f7b86fa79e4e4060133b6d61cf9f47e09","src/window.rs":"2f6c3dc958ae2c0c9e2fc5033300b96e60ed0abee9823ea1f03797d64df0911a"},"package":"970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212"}

View File

@@ -10,15 +10,9 @@
# See Cargo.toml.orig for the original contents. # See Cargo.toml.orig for the original contents.
[package] [package]
edition = "2018"
name = "core-graphics" name = "core-graphics"
version = "0.24.0" version = "0.23.1"
authors = ["The Servo Project Developers"] authors = ["The Servo Project Developers"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Bindings to Core Graphics for macOS" description = "Bindings to Core Graphics for macOS"
homepage = "https://github.com/servo/core-foundation-rs" homepage = "https://github.com/servo/core-foundation-rs"
readme = "README.md" readme = "README.md"
@@ -26,23 +20,16 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/servo/core-foundation-rs" repository = "https://github.com/servo/core-foundation-rs"
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true
default-target = "x86_64-apple-darwin" default-target = "x86_64-apple-darwin"
[lib]
name = "core_graphics"
path = "src/lib.rs"
[dependencies.bitflags] [dependencies.bitflags]
version = "2" version = "1.0"
[dependencies.core-foundation] [dependencies.core-foundation]
version = "0.10" version = "0.9"
default-features = false
[dependencies.core-graphics-types] [dependencies.core-graphics-types]
version = "0.2" version = "0.1"
default-features = false
[dependencies.foreign-types] [dependencies.foreign-types]
version = "0.5.0" version = "0.5.0"
@@ -51,10 +38,6 @@ version = "0.5.0"
version = "0.2" version = "0.2"
[features] [features]
default = ["link"] default = []
elcapitan = [] elcapitan = []
highsierra = [] highsierra = []
link = [
"core-foundation/link",
"core-graphics-types/link",
]

View File

@@ -1 +1,3 @@
# core-graphics-rs # core-graphics-rs
[![Build Status](https://travis-ci.com/servo/core-graphics-rs.svg?branch=master)](https://travis-ci.com/servo/core-graphics-rs)

View File

@@ -1,4 +1,4 @@
pub use crate::base::boolean_t; pub use base::boolean_t;
#[derive(Default)] #[derive(Default)]
pub struct ScreenCaptureAccess; pub struct ScreenCaptureAccess;
@@ -11,14 +11,14 @@ impl ScreenCaptureAccess {
unsafe { CGRequestScreenCaptureAccess() == 1 } unsafe { CGRequestScreenCaptureAccess() == 1 }
} }
/// Return `true` if has access /// Return true if has access
#[inline] #[inline]
pub fn preflight(&self) -> bool { pub fn preflight(&self) -> bool {
unsafe { CGPreflightScreenCaptureAccess() == 1 } unsafe { CGPreflightScreenCaptureAccess() == 1 }
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern "C" {
// Screen Capture Access // Screen Capture Access
fn CGRequestScreenCaptureAccess() -> boolean_t; fn CGRequestScreenCaptureAccess() -> boolean_t;

View File

@@ -7,35 +7,29 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use super::sys::CGColorRef; use core_foundation::base::{CFTypeID};
use crate::base::CGFloat; use base::CGFloat;
use core_foundation::base::CFTypeID;
use core_foundation::base::TCFType; use core_foundation::base::TCFType;
use core_foundation::{declare_TCFType, impl_TCFType}; use super::sys::{CGColorRef};
pub use super::sys::CGColorRef as SysCGColorRef; pub use super::sys::CGColorRef as SysCGColorRef;
declare_TCFType! { declare_TCFType!{
CGColor, CGColorRef CGColor, CGColorRef
} }
impl_TCFType!(CGColor, CGColorRef, CGColorGetTypeID); impl_TCFType!(CGColor, CGColorRef, CGColorGetTypeID);
impl CGColor { impl CGColor {
pub fn rgb(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> Self { pub fn rgb(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> Self {
unsafe { unsafe {
let ptr = CGColorCreateGenericRGB(red, green, blue, alpha); let ptr = CGColorCreateGenericRGB(red, green, blue, alpha);
CGColor::wrap_under_create_rule(ptr) CGColor::wrap_under_create_rule(ptr)
} }
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
fn CGColorCreateGenericRGB( fn CGColorCreateGenericRGB(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> ::sys::CGColorRef;
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
) -> crate::sys::CGColorRef;
fn CGColorGetTypeID() -> CFTypeID; fn CGColorGetTypeID() -> CFTypeID;
} }

View File

@@ -9,12 +9,12 @@
use core_foundation::base::{CFRelease, CFRetain, CFTypeID}; use core_foundation::base::{CFRelease, CFRetain, CFTypeID};
use core_foundation::string::CFStringRef; use core_foundation::string::CFStringRef;
use foreign_types::{foreign_type, ForeignType}; use foreign_types::ForeignType;
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGColorSpace { pub unsafe type CGColorSpace {
type CType = crate::sys::CGColorSpace; type CType = ::sys::CGColorSpace;
fn drop = |p| CFRelease(p as *mut _); fn drop = |p| CFRelease(p as *mut _);
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
@@ -22,17 +22,15 @@ foreign_type! {
impl CGColorSpace { impl CGColorSpace {
pub fn type_id() -> CFTypeID { pub fn type_id() -> CFTypeID {
unsafe { CGColorSpaceGetTypeID() } unsafe {
CGColorSpaceGetTypeID()
}
} }
pub fn create_with_name(name: CFStringRef) -> Option<CGColorSpace> { pub fn create_with_name(name: CFStringRef) -> Option<CGColorSpace> {
unsafe { unsafe {
let p = CGColorSpaceCreateWithName(name); let p = CGColorSpaceCreateWithName(name);
if !p.is_null() { if !p.is_null() {Some(CGColorSpace::from_ptr(p))} else {None}
Some(CGColorSpace::from_ptr(p))
} else {
None
}
} }
} }
@@ -53,8 +51,8 @@ impl CGColorSpace {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
/// The Display P3 color space, created by Apple. /// The Display P3 color space, created by Apple.
pub static kCGColorSpaceDisplayP3: CFStringRef; pub static kCGColorSpaceDisplayP3: CFStringRef;
/// The Display P3 color space, using the HLG transfer function. /// The Display P3 color space, using the HLG transfer function.
@@ -111,8 +109,9 @@ extern "C" {
/// The name of the generic gray color space. /// The name of the generic gray color space.
pub static kCGColorSpaceGenericGray: CFStringRef; pub static kCGColorSpaceGenericGray: CFStringRef;
fn CGColorSpaceCreateDeviceRGB() -> crate::sys::CGColorSpaceRef; fn CGColorSpaceCreateDeviceRGB() -> ::sys::CGColorSpaceRef;
fn CGColorSpaceCreateDeviceGray() -> crate::sys::CGColorSpaceRef; fn CGColorSpaceCreateDeviceGray() -> ::sys::CGColorSpaceRef;
fn CGColorSpaceCreateWithName(name: CFStringRef) -> crate::sys::CGColorSpaceRef; fn CGColorSpaceCreateWithName(name: CFStringRef) -> ::sys::CGColorSpaceRef;
fn CGColorSpaceGetTypeID() -> CFTypeID; fn CGColorSpaceGetTypeID() -> CFTypeID;
} }

View File

@@ -7,23 +7,23 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::base::CGFloat; use base::CGFloat;
use crate::color::CGColor; use color_space::CGColorSpace;
use crate::color_space::CGColorSpace;
use crate::font::{CGFont, CGGlyph};
use crate::geometry::{CGPoint, CGSize};
use crate::gradient::{CGGradient, CGGradientDrawingOptions};
use crate::path::CGPathRef;
use core_foundation::base::{CFTypeID, TCFType}; use core_foundation::base::{CFTypeID, TCFType};
use font::{CGFont, CGGlyph};
use geometry::{CGPoint, CGSize};
use gradient::{CGGradient, CGGradientDrawingOptions};
use color::CGColor;
use path::CGPathRef;
use libc::{c_int, size_t}; use libc::{c_int, size_t};
use std::os::raw::c_void; use std::os::raw::c_void;
use crate::geometry::{CGAffineTransform, CGRect};
use crate::image::CGImage;
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
use std::cmp; use std::cmp;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
use geometry::{CGAffineTransform, CGRect};
use image::CGImage;
use foreign_types::{ForeignType, ForeignTypeRef};
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
@@ -68,7 +68,7 @@ pub enum CGTextDrawingMode {
CGTextFillClip, CGTextFillClip,
CGTextStrokeClip, CGTextStrokeClip,
CGTextFillStrokeClip, CGTextFillStrokeClip,
CGTextClip, CGTextClip
} }
#[repr(C)] #[repr(C)]
@@ -110,7 +110,7 @@ pub enum CGInterpolationQuality {
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGContext { pub unsafe type CGContext {
type CType = crate::sys::CGContext; type CType = ::sys::CGContext;
fn drop = |cs| CGContextRelease(cs); fn drop = |cs| CGContextRelease(cs);
fn clone = |p| CGContextRetain(p); fn clone = |p| CGContextRetain(p);
} }
@@ -118,44 +118,43 @@ foreign_type! {
impl CGContext { impl CGContext {
pub fn type_id() -> CFTypeID { pub fn type_id() -> CFTypeID {
unsafe { CGContextGetTypeID() } unsafe {
CGContextGetTypeID()
}
} }
/// Creates a `CGContext` instance from an existing [`CGContextRef`] pointer. /// Creates a `CGContext` instance from an existing [`CGContextRef`] pointer.
/// ///
/// This function will internally call [`CGRetain`] and hence there is no need to call it explicitly. /// This funtion will internally call [`CGRetain`] and hence there is no need to call it explicitly.
/// ///
/// This function is particularly useful for cases when the context is not instantiated/managed /// This function is particularly useful for cases when the context is not instantiated/managed
/// by the caller, but it's retrieve via other means (e.g., by calling the method [`NSGraphicsContext::CGContext`] /// by the caller, but it's retrieve via other means (e.g., by calling the method [`NSGraphicsContext::CGContext`]
/// in a cocoa application). /// in a cocoa application).
/// ///
/// [`CGContextRef`]: https://developer.apple.com/documentation/coregraphics/cgcontextref /// [`CGContextRef`]: https://developer.apple.com/documentation/coregraphics/cgcontextref
/// [`CGRetain`]: https://developer.apple.com/documentation/coregraphics/1586506-cgcontextretain /// [`CGRetain`]: https://developer.apple.com/documentation/coregraphics/1586506-cgcontextretain
/// [`NSGraphicsContext::CGContext`]: https://developer.apple.com/documentation/appkit/nsgraphicscontext/1535352-currentcontext /// [`NSGraphicsContext::CGContext`]: https://developer.apple.com/documentation/appkit/nsgraphicscontext/1535352-currentcontext
pub unsafe fn from_existing_context_ptr(ctx: *mut crate::sys::CGContext) -> CGContext { pub unsafe fn from_existing_context_ptr(ctx: *mut ::sys::CGContext) -> CGContext {
CGContextRetain(ctx); CGContextRetain(ctx);
Self::from_ptr(ctx) Self::from_ptr(ctx)
} }
pub fn create_bitmap_context( pub fn create_bitmap_context(data: Option<*mut c_void>,
data: Option<*mut c_void>, width: size_t,
width: size_t, height: size_t,
height: size_t, bits_per_component: size_t,
bits_per_component: size_t, bytes_per_row: size_t,
bytes_per_row: size_t, space: &CGColorSpace,
space: &CGColorSpace, bitmap_info: u32)
bitmap_info: u32, -> CGContext {
) -> CGContext {
unsafe { unsafe {
let result = CGBitmapContextCreate( let result = CGBitmapContextCreate(data.unwrap_or(ptr::null_mut()),
data.unwrap_or(ptr::null_mut()), width,
width, height,
height, bits_per_component,
bits_per_component, bytes_per_row,
bytes_per_row, space.as_ptr(),
space.as_ptr(), bitmap_info);
bitmap_info,
);
assert!(!result.is_null()); assert!(!result.is_null());
Self::from_ptr(result) Self::from_ptr(result)
} }
@@ -164,32 +163,41 @@ impl CGContext {
pub fn data(&mut self) -> &mut [u8] { pub fn data(&mut self) -> &mut [u8] {
unsafe { unsafe {
slice::from_raw_parts_mut( slice::from_raw_parts_mut(
CGBitmapContextGetData(self.as_ptr()) as *mut u8, CGBitmapContextGetData(self.as_ptr()) as *mut u8,
self.height() * self.bytes_per_row(), (self.height() * self.bytes_per_row()) as usize)
)
} }
} }
} }
impl CGContextRef { impl CGContextRef {
pub fn flush(&self) { pub fn flush(&self) {
unsafe { CGContextFlush(self.as_ptr()) } unsafe {
CGContextFlush(self.as_ptr())
}
} }
pub fn width(&self) -> size_t { pub fn width(&self) -> size_t {
unsafe { CGBitmapContextGetWidth(self.as_ptr()) } unsafe {
CGBitmapContextGetWidth(self.as_ptr())
}
} }
pub fn height(&self) -> size_t { pub fn height(&self) -> size_t {
unsafe { CGBitmapContextGetHeight(self.as_ptr()) } unsafe {
CGBitmapContextGetHeight(self.as_ptr())
}
} }
pub fn bytes_per_row(&self) -> size_t { pub fn bytes_per_row(&self) -> size_t {
unsafe { CGBitmapContextGetBytesPerRow(self.as_ptr()) } unsafe {
CGBitmapContextGetBytesPerRow(self.as_ptr())
}
} }
pub fn clip_bounding_box(&self) -> CGRect { pub fn clip_bounding_box(&self) -> CGRect {
unsafe { CGContextGetClipBoundingBox(self.as_ptr()) } unsafe {
CGContextGetClipBoundingBox(self.as_ptr())
}
} }
pub fn set_fill_color(&self, color: &CGColor) { pub fn set_fill_color(&self, color: &CGColor) {
@@ -199,29 +207,33 @@ impl CGContextRef {
} }
pub fn set_rgb_fill_color(&self, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { pub fn set_rgb_fill_color(&self, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
unsafe { CGContextSetRGBFillColor(self.as_ptr(), red, green, blue, alpha) } unsafe {
CGContextSetRGBFillColor(self.as_ptr(), red, green, blue, alpha)
}
} }
pub fn set_rgb_stroke_color( pub fn set_rgb_stroke_color(&self, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
&self, unsafe {
red: CGFloat, CGContextSetRGBStrokeColor(self.as_ptr(), red, green, blue, alpha)
green: CGFloat, }
blue: CGFloat,
alpha: CGFloat,
) {
unsafe { CGContextSetRGBStrokeColor(self.as_ptr(), red, green, blue, alpha) }
} }
pub fn set_gray_fill_color(&self, gray: CGFloat, alpha: CGFloat) { pub fn set_gray_fill_color(&self, gray: CGFloat, alpha: CGFloat) {
unsafe { CGContextSetGrayFillColor(self.as_ptr(), gray, alpha) } unsafe {
CGContextSetGrayFillColor(self.as_ptr(), gray, alpha)
}
} }
pub fn set_blend_mode(&self, blend_mode: CGBlendMode) { pub fn set_blend_mode(&self, blend_mode: CGBlendMode) {
unsafe { CGContextSetBlendMode(self.as_ptr(), blend_mode) } unsafe {
CGContextSetBlendMode(self.as_ptr(), blend_mode)
}
} }
pub fn set_allows_font_smoothing(&self, allows_font_smoothing: bool) { pub fn set_allows_font_smoothing(&self, allows_font_smoothing: bool) {
unsafe { CGContextSetAllowsFontSmoothing(self.as_ptr(), allows_font_smoothing) } unsafe {
CGContextSetAllowsFontSmoothing(self.as_ptr(), allows_font_smoothing)
}
} }
pub fn set_font_smoothing_style(&self, style: i32) { pub fn set_font_smoothing_style(&self, style: i32) {
@@ -231,23 +243,26 @@ impl CGContextRef {
} }
pub fn set_should_smooth_fonts(&self, should_smooth_fonts: bool) { pub fn set_should_smooth_fonts(&self, should_smooth_fonts: bool) {
unsafe { CGContextSetShouldSmoothFonts(self.as_ptr(), should_smooth_fonts) } unsafe {
CGContextSetShouldSmoothFonts(self.as_ptr(), should_smooth_fonts)
}
} }
pub fn set_allows_antialiasing(&self, allows_antialiasing: bool) { pub fn set_allows_antialiasing(&self, allows_antialiasing: bool) {
unsafe { CGContextSetAllowsAntialiasing(self.as_ptr(), allows_antialiasing) } unsafe {
CGContextSetAllowsAntialiasing(self.as_ptr(), allows_antialiasing)
}
} }
pub fn set_should_antialias(&self, should_antialias: bool) { pub fn set_should_antialias(&self, should_antialias: bool) {
unsafe { CGContextSetShouldAntialias(self.as_ptr(), should_antialias) } unsafe {
CGContextSetShouldAntialias(self.as_ptr(), should_antialias)
}
} }
pub fn set_allows_font_subpixel_quantization(&self, allows_font_subpixel_quantization: bool) { pub fn set_allows_font_subpixel_quantization(&self, allows_font_subpixel_quantization: bool) {
unsafe { unsafe {
CGContextSetAllowsFontSubpixelQuantization( CGContextSetAllowsFontSubpixelQuantization(self.as_ptr(), allows_font_subpixel_quantization)
self.as_ptr(),
allows_font_subpixel_quantization,
)
} }
} }
@@ -259,10 +274,7 @@ impl CGContextRef {
pub fn set_allows_font_subpixel_positioning(&self, allows_font_subpixel_positioning: bool) { pub fn set_allows_font_subpixel_positioning(&self, allows_font_subpixel_positioning: bool) {
unsafe { unsafe {
CGContextSetAllowsFontSubpixelPositioning( CGContextSetAllowsFontSubpixelPositioning(self.as_ptr(), allows_font_subpixel_positioning)
self.as_ptr(),
allows_font_subpixel_positioning,
)
} }
} }
@@ -273,27 +285,39 @@ impl CGContextRef {
} }
pub fn set_text_drawing_mode(&self, mode: CGTextDrawingMode) { pub fn set_text_drawing_mode(&self, mode: CGTextDrawingMode) {
unsafe { CGContextSetTextDrawingMode(self.as_ptr(), mode) } unsafe {
CGContextSetTextDrawingMode(self.as_ptr(), mode)
}
} }
pub fn set_line_cap(&self, cap: CGLineCap) { pub fn set_line_cap(&self, cap: CGLineCap) {
unsafe { CGContextSetLineCap(self.as_ptr(), cap) } unsafe {
CGContextSetLineCap(self.as_ptr(), cap)
}
} }
pub fn set_line_dash(&self, phase: CGFloat, lengths: &[CGFloat]) { pub fn set_line_dash(&self, phase: CGFloat, lengths: &[CGFloat]) {
unsafe { CGContextSetLineDash(self.as_ptr(), phase, lengths.as_ptr(), lengths.len()) } unsafe {
CGContextSetLineDash(self.as_ptr(), phase, lengths.as_ptr(), lengths.len())
}
} }
pub fn set_line_join(&self, join: CGLineJoin) { pub fn set_line_join(&self, join: CGLineJoin) {
unsafe { CGContextSetLineJoin(self.as_ptr(), join) } unsafe {
CGContextSetLineJoin(self.as_ptr(), join)
}
} }
pub fn set_line_width(&self, width: CGFloat) { pub fn set_line_width(&self, width: CGFloat) {
unsafe { CGContextSetLineWidth(self.as_ptr(), width) } unsafe {
CGContextSetLineWidth(self.as_ptr(), width)
}
} }
pub fn set_miter_limit(&self, limit: CGFloat) { pub fn set_miter_limit(&self, limit: CGFloat) {
unsafe { CGContextSetMiterLimit(self.as_ptr(), limit) } unsafe {
CGContextSetMiterLimit(self.as_ptr(), limit)
}
} }
pub fn add_path(&self, path: &CGPathRef) { pub fn add_path(&self, path: &CGPathRef) {
@@ -302,23 +326,30 @@ impl CGContextRef {
} }
} }
pub fn add_curve_to_point( pub fn add_curve_to_point(&self,
&self, cp1x: CGFloat,
cp1x: CGFloat, cp1y: CGFloat,
cp1y: CGFloat, cp2x: CGFloat,
cp2x: CGFloat, cp2y: CGFloat,
cp2y: CGFloat, x: CGFloat,
x: CGFloat, y: CGFloat) {
y: CGFloat,
) {
unsafe { unsafe {
CGContextAddCurveToPoint(self.as_ptr(), cp1x, cp1y, cp2x, cp2y, x, y); CGContextAddCurveToPoint(self.as_ptr(),
cp1x, cp1y,
cp2x, cp2y,
x, y);
} }
} }
pub fn add_quad_curve_to_point(&self, cpx: CGFloat, cpy: CGFloat, x: CGFloat, y: CGFloat) { pub fn add_quad_curve_to_point(&self,
cpx: CGFloat,
cpy: CGFloat,
x: CGFloat,
y: CGFloat) {
unsafe { unsafe {
CGContextAddQuadCurveToPoint(self.as_ptr(), cpx, cpy, x, y); CGContextAddQuadCurveToPoint(self.as_ptr(),
cpx, cpy,
x, y);
} }
} }
@@ -329,7 +360,7 @@ impl CGContextRef {
} }
pub fn begin_path(&self) { pub fn begin_path(&self) {
unsafe { unsafe {
CGContextBeginPath(self.as_ptr()); CGContextBeginPath(self.as_ptr());
} }
} }
@@ -389,51 +420,75 @@ impl CGContextRef {
} }
pub fn fill_rect(&self, rect: CGRect) { pub fn fill_rect(&self, rect: CGRect) {
unsafe { CGContextFillRect(self.as_ptr(), rect) } unsafe {
CGContextFillRect(self.as_ptr(), rect)
}
} }
pub fn fill_rects(&self, rects: &[CGRect]) { pub fn fill_rects(&self, rects: &[CGRect]) {
unsafe { CGContextFillRects(self.as_ptr(), rects.as_ptr(), rects.len()) } unsafe {
CGContextFillRects(self.as_ptr(), rects.as_ptr(), rects.len())
}
} }
pub fn clear_rect(&self, rect: CGRect) { pub fn clear_rect(&self, rect: CGRect) {
unsafe { CGContextClearRect(self.as_ptr(), rect) } unsafe {
CGContextClearRect(self.as_ptr(), rect)
}
} }
pub fn stroke_rect(&self, rect: CGRect) { pub fn stroke_rect(&self, rect: CGRect) {
unsafe { CGContextStrokeRect(self.as_ptr(), rect) } unsafe {
CGContextStrokeRect(self.as_ptr(), rect)
}
} }
pub fn stroke_rect_with_width(&self, rect: CGRect, width: CGFloat) { pub fn stroke_rect_with_width(&self, rect: CGRect, width: CGFloat) {
unsafe { CGContextStrokeRectWithWidth(self.as_ptr(), rect, width) } unsafe {
CGContextStrokeRectWithWidth(self.as_ptr(), rect, width)
}
} }
pub fn clip_to_rect(&self, rect: CGRect) { pub fn clip_to_rect(&self, rect: CGRect) {
unsafe { CGContextClipToRect(self.as_ptr(), rect) } unsafe {
CGContextClipToRect(self.as_ptr(), rect)
}
} }
pub fn clip_to_rects(&self, rects: &[CGRect]) { pub fn clip_to_rects(&self, rects: &[CGRect]) {
unsafe { CGContextClipToRects(self.as_ptr(), rects.as_ptr(), rects.len()) } unsafe {
CGContextClipToRects(self.as_ptr(), rects.as_ptr(), rects.len())
}
} }
pub fn clip_to_mask(&self, rect: CGRect, image: &CGImage) { pub fn clip_to_mask(&self, rect: CGRect, image: &CGImage) {
unsafe { CGContextClipToMask(self.as_ptr(), rect, image.as_ptr()) } unsafe {
CGContextClipToMask(self.as_ptr(), rect, image.as_ptr())
}
} }
pub fn replace_path_with_stroked_path(&self) { pub fn replace_path_with_stroked_path(&self) {
unsafe { CGContextReplacePathWithStrokedPath(self.as_ptr()) } unsafe {
CGContextReplacePathWithStrokedPath(self.as_ptr())
}
} }
pub fn fill_ellipse_in_rect(&self, rect: CGRect) { pub fn fill_ellipse_in_rect(&self, rect: CGRect) {
unsafe { CGContextFillEllipseInRect(self.as_ptr(), rect) } unsafe {
CGContextFillEllipseInRect(self.as_ptr(), rect)
}
} }
pub fn stroke_ellipse_in_rect(&self, rect: CGRect) { pub fn stroke_ellipse_in_rect(&self, rect: CGRect) {
unsafe { CGContextStrokeEllipseInRect(self.as_ptr(), rect) } unsafe {
CGContextStrokeEllipseInRect(self.as_ptr(), rect)
}
} }
pub fn stroke_line_segments(&self, points: &[CGPoint]) { pub fn stroke_line_segments(&self, points: &[CGPoint]) {
unsafe { CGContextStrokeLineSegments(self.as_ptr(), points.as_ptr(), points.len()) } unsafe {
CGContextStrokeLineSegments(self.as_ptr(), points.as_ptr(), points.len())
}
} }
pub fn set_interpolation_quality(&self, quality: CGInterpolationQuality) { pub fn set_interpolation_quality(&self, quality: CGInterpolationQuality) {
@@ -443,7 +498,10 @@ impl CGContextRef {
} }
pub fn get_interpolation_quality(&self) -> CGInterpolationQuality { pub fn get_interpolation_quality(&self) -> CGInterpolationQuality {
unsafe { CGContextGetInterpolationQuality(self.as_ptr()) } unsafe {
CGContextGetInterpolationQuality(self.as_ptr())
}
} }
pub fn draw_image(&self, rect: CGRect, image: &CGImage) { pub fn draw_image(&self, rect: CGRect, image: &CGImage) {
@@ -462,30 +520,36 @@ impl CGContextRef {
} }
pub fn set_font(&self, font: &CGFont) { pub fn set_font(&self, font: &CGFont) {
unsafe { CGContextSetFont(self.as_ptr(), font.as_ptr()) } unsafe {
CGContextSetFont(self.as_ptr(), font.as_ptr())
}
} }
pub fn set_font_size(&self, size: CGFloat) { pub fn set_font_size(&self, size: CGFloat) {
unsafe { CGContextSetFontSize(self.as_ptr(), size) } unsafe {
CGContextSetFontSize(self.as_ptr(), size)
}
} }
pub fn set_text_matrix(&self, t: &CGAffineTransform) { pub fn set_text_matrix(&self, t: &CGAffineTransform) {
unsafe { CGContextSetTextMatrix(self.as_ptr(), *t) } unsafe {
CGContextSetTextMatrix(self.as_ptr(), *t)
}
} }
pub fn set_text_position(&self, x: CGFloat, y: CGFloat) { pub fn set_text_position(&self, x: CGFloat, y: CGFloat) {
unsafe { CGContextSetTextPosition(self.as_ptr(), x, y) } unsafe {
CGContextSetTextPosition(self.as_ptr(), x, y)
}
} }
pub fn show_glyphs_at_positions(&self, glyphs: &[CGGlyph], positions: &[CGPoint]) { pub fn show_glyphs_at_positions(&self, glyphs: &[CGGlyph], positions: &[CGPoint]) {
unsafe { unsafe {
let count = cmp::min(glyphs.len(), positions.len()); let count = cmp::min(glyphs.len(), positions.len());
CGContextShowGlyphsAtPositions( CGContextShowGlyphsAtPositions(self.as_ptr(),
self.as_ptr(), glyphs.as_ptr(),
glyphs.as_ptr(), positions.as_ptr(),
positions.as_ptr(), count)
count,
)
} }
} }
@@ -520,50 +584,26 @@ impl CGContextRef {
} }
pub fn get_ctm(&self) -> CGAffineTransform { pub fn get_ctm(&self) -> CGAffineTransform {
unsafe { CGContextGetCTM(self.as_ptr()) }
}
pub fn concat_ctm(&self, transform: CGAffineTransform) {
unsafe { CGContextConcatCTM(self.as_ptr(), transform) }
}
pub fn draw_linear_gradient(
&self,
gradient: &CGGradient,
start_point: CGPoint,
end_point: CGPoint,
options: CGGradientDrawingOptions,
) {
unsafe { unsafe {
CGContextDrawLinearGradient( CGContextGetCTM(self.as_ptr())
self.as_ptr(),
gradient.as_ptr(),
start_point,
end_point,
options,
);
} }
} }
pub fn draw_radial_gradient( pub fn concat_ctm(&self, transform: CGAffineTransform) {
&self,
gradient: &CGGradient,
start_center: CGPoint,
start_radius: CGFloat,
end_center: CGPoint,
end_radius: CGFloat,
options: CGGradientDrawingOptions,
) {
unsafe { unsafe {
CGContextDrawRadialGradient( CGContextConcatCTM(self.as_ptr(), transform)
self.as_ptr(), }
gradient.as_ptr(), }
start_center,
start_radius, pub fn draw_linear_gradient(&self, gradient: &CGGradient, start_point: CGPoint, end_point: CGPoint, options: CGGradientDrawingOptions) {
end_center, unsafe {
end_radius, CGContextDrawLinearGradient(self.as_ptr(), gradient.as_ptr(), start_point, end_point, options);
options, }
); }
pub fn draw_radial_gradient(&self, gradient: &CGGradient, start_center: CGPoint, start_radius: CGFloat, end_center: CGPoint, end_radius: CGFloat, options: CGGradientDrawingOptions) {
unsafe {
CGContextDrawRadialGradient(self.as_ptr(), gradient.as_ptr(), start_center, start_radius, end_center, end_radius, options);
} }
} }
@@ -588,21 +628,17 @@ impl CGContextRef {
#[test] #[test]
fn create_bitmap_context_test() { fn create_bitmap_context_test() {
use crate::geometry::*; use geometry::*;
let cs = CGColorSpace::create_device_rgb(); let cs = CGColorSpace::create_device_rgb();
let ctx = CGContext::create_bitmap_context( let ctx = CGContext::create_bitmap_context(None,
None, 16, 8,
16, 8, 0,
8, &cs,
8, ::base::kCGImageAlphaPremultipliedLast);
0, ctx.set_rgb_fill_color(1.,0.,1.,1.);
&cs,
crate::base::kCGImageAlphaPremultipliedLast,
);
ctx.set_rgb_fill_color(1., 0., 1., 1.);
ctx.set_miter_limit(4.); ctx.set_miter_limit(4.);
ctx.fill_rect(CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(8., 8.))); ctx.fill_rect(CGRect::new(&CGPoint::new(0.,0.), &CGSize::new(8.,8.)));
let img = ctx.create_image().unwrap(); let img = ctx.create_image().unwrap();
assert_eq!(16, img.width()); assert_eq!(16, img.width());
assert_eq!(8, img.height()); assert_eq!(8, img.height());
@@ -615,179 +651,140 @@ fn create_bitmap_context_test() {
assert_eq!(255, data.bytes()[3]); assert_eq!(255, data.bytes()[3]);
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
fn CGContextRetain(c: crate::sys::CGContextRef) -> crate::sys::CGContextRef; fn CGContextRetain(c: ::sys::CGContextRef) -> ::sys::CGContextRef;
fn CGContextRelease(c: crate::sys::CGContextRef); fn CGContextRelease(c: ::sys::CGContextRef);
fn CGBitmapContextCreate( fn CGBitmapContextCreate(data: *mut c_void,
data: *mut c_void, width: size_t,
width: size_t, height: size_t,
height: size_t, bitsPerComponent: size_t,
bitsPerComponent: size_t, bytesPerRow: size_t,
bytesPerRow: size_t, space: ::sys::CGColorSpaceRef,
space: crate::sys::CGColorSpaceRef, bitmapInfo: u32)
bitmapInfo: u32, -> ::sys::CGContextRef;
) -> crate::sys::CGContextRef; fn CGBitmapContextGetData(context: ::sys::CGContextRef) -> *mut c_void;
fn CGBitmapContextGetData(context: crate::sys::CGContextRef) -> *mut c_void; fn CGBitmapContextGetWidth(context: ::sys::CGContextRef) -> size_t;
fn CGBitmapContextGetWidth(context: crate::sys::CGContextRef) -> size_t; fn CGBitmapContextGetHeight(context: ::sys::CGContextRef) -> size_t;
fn CGBitmapContextGetHeight(context: crate::sys::CGContextRef) -> size_t; fn CGBitmapContextGetBytesPerRow(context: ::sys::CGContextRef) -> size_t;
fn CGBitmapContextGetBytesPerRow(context: crate::sys::CGContextRef) -> size_t; fn CGBitmapContextCreateImage(context: ::sys::CGContextRef) -> ::sys::CGImageRef;
fn CGBitmapContextCreateImage(context: crate::sys::CGContextRef) -> crate::sys::CGImageRef;
fn CGContextGetTypeID() -> CFTypeID; fn CGContextGetTypeID() -> CFTypeID;
fn CGContextGetClipBoundingBox(c: crate::sys::CGContextRef) -> CGRect; fn CGContextGetClipBoundingBox(c: ::sys::CGContextRef) -> CGRect;
fn CGContextFlush(c: crate::sys::CGContextRef); fn CGContextFlush(c: ::sys::CGContextRef);
fn CGContextSetBlendMode(c: crate::sys::CGContextRef, blendMode: CGBlendMode); fn CGContextSetBlendMode(c: ::sys::CGContextRef, blendMode: CGBlendMode);
fn CGContextSetAllowsFontSmoothing(c: crate::sys::CGContextRef, allowsFontSmoothing: bool); fn CGContextSetAllowsFontSmoothing(c: ::sys::CGContextRef, allowsFontSmoothing: bool);
fn CGContextSetShouldSmoothFonts(c: crate::sys::CGContextRef, shouldSmoothFonts: bool); fn CGContextSetShouldSmoothFonts(c: ::sys::CGContextRef, shouldSmoothFonts: bool);
fn CGContextSetFontSmoothingStyle(c: crate::sys::CGContextRef, style: c_int); fn CGContextSetFontSmoothingStyle(c: ::sys::CGContextRef, style: c_int);
fn CGContextSetAllowsAntialiasing(c: crate::sys::CGContextRef, allowsAntialiasing: bool); fn CGContextSetAllowsAntialiasing(c: ::sys::CGContextRef, allowsAntialiasing: bool);
fn CGContextSetShouldAntialias(c: crate::sys::CGContextRef, shouldAntialias: bool); fn CGContextSetShouldAntialias(c: ::sys::CGContextRef, shouldAntialias: bool);
fn CGContextSetAllowsFontSubpixelQuantization( fn CGContextSetAllowsFontSubpixelQuantization(c: ::sys::CGContextRef,
c: crate::sys::CGContextRef, allowsFontSubpixelQuantization: bool);
allowsFontSubpixelQuantization: bool, fn CGContextSetShouldSubpixelQuantizeFonts(c: ::sys::CGContextRef,
); shouldSubpixelQuantizeFonts: bool);
fn CGContextSetShouldSubpixelQuantizeFonts( fn CGContextSetAllowsFontSubpixelPositioning(c: ::sys::CGContextRef,
c: crate::sys::CGContextRef, allowsFontSubpixelPositioning: bool);
shouldSubpixelQuantizeFonts: bool, fn CGContextSetShouldSubpixelPositionFonts(c: ::sys::CGContextRef,
); shouldSubpixelPositionFonts: bool);
fn CGContextSetAllowsFontSubpixelPositioning( fn CGContextSetTextDrawingMode(c: ::sys::CGContextRef, mode: CGTextDrawingMode);
c: crate::sys::CGContextRef, fn CGContextSetFillColorWithColor(c: ::sys::CGContextRef, color: ::sys::CGColorRef);
allowsFontSubpixelPositioning: bool, fn CGContextSetLineCap(c: ::sys::CGContextRef, cap: CGLineCap);
); fn CGContextSetLineDash(c: ::sys::CGContextRef, phase: CGFloat, lengths: *const CGFloat, count: size_t);
fn CGContextSetShouldSubpixelPositionFonts( fn CGContextSetLineJoin(c: ::sys::CGContextRef, join: CGLineJoin);
c: crate::sys::CGContextRef, fn CGContextSetLineWidth(c: ::sys::CGContextRef, width: CGFloat);
shouldSubpixelPositionFonts: bool, fn CGContextSetMiterLimit(c: ::sys::CGContextRef, limit: CGFloat);
);
fn CGContextSetTextDrawingMode(c: crate::sys::CGContextRef, mode: CGTextDrawingMode);
fn CGContextSetFillColorWithColor(c: crate::sys::CGContextRef, color: crate::sys::CGColorRef);
fn CGContextSetLineCap(c: crate::sys::CGContextRef, cap: CGLineCap);
fn CGContextSetLineDash(
c: crate::sys::CGContextRef,
phase: CGFloat,
lengths: *const CGFloat,
count: size_t,
);
fn CGContextSetLineJoin(c: crate::sys::CGContextRef, join: CGLineJoin);
fn CGContextSetLineWidth(c: crate::sys::CGContextRef, width: CGFloat);
fn CGContextSetMiterLimit(c: crate::sys::CGContextRef, limit: CGFloat);
fn CGContextAddPath(c: crate::sys::CGContextRef, path: crate::sys::CGPathRef); fn CGContextAddPath(c: ::sys::CGContextRef, path: ::sys::CGPathRef);
fn CGContextAddCurveToPoint( fn CGContextAddCurveToPoint(c: ::sys::CGContextRef,
c: crate::sys::CGContextRef, cp1x: CGFloat,
cp1x: CGFloat, cp1y: CGFloat,
cp1y: CGFloat, cp2x: CGFloat,
cp2x: CGFloat, cp2y: CGFloat,
cp2y: CGFloat, x: CGFloat,
x: CGFloat, y: CGFloat);
y: CGFloat, fn CGContextAddQuadCurveToPoint(c: ::sys::CGContextRef,
); cpx: CGFloat,
fn CGContextAddQuadCurveToPoint( cpy: CGFloat,
c: crate::sys::CGContextRef, x: CGFloat,
cpx: CGFloat, y: CGFloat);
cpy: CGFloat, fn CGContextAddLineToPoint(c: ::sys::CGContextRef,
x: CGFloat, x: CGFloat,
y: CGFloat, y: CGFloat);
); fn CGContextBeginPath(c: ::sys::CGContextRef);
fn CGContextAddLineToPoint(c: crate::sys::CGContextRef, x: CGFloat, y: CGFloat); fn CGContextClosePath(c: ::sys::CGContextRef);
fn CGContextBeginPath(c: crate::sys::CGContextRef); fn CGContextMoveToPoint(c: ::sys::CGContextRef,
fn CGContextClosePath(c: crate::sys::CGContextRef); x: CGFloat,
fn CGContextMoveToPoint(c: crate::sys::CGContextRef, x: CGFloat, y: CGFloat); y: CGFloat);
fn CGContextDrawPath(c: crate::sys::CGContextRef, mode: CGPathDrawingMode); fn CGContextDrawPath(c: ::sys::CGContextRef, mode: CGPathDrawingMode);
fn CGContextFillPath(c: crate::sys::CGContextRef); fn CGContextFillPath(c: ::sys::CGContextRef);
fn CGContextEOFillPath(c: crate::sys::CGContextRef); fn CGContextEOFillPath(c: ::sys::CGContextRef);
fn CGContextClip(c: crate::sys::CGContextRef); fn CGContextClip(c: ::sys::CGContextRef);
fn CGContextEOClip(c: crate::sys::CGContextRef); fn CGContextEOClip(c: ::sys::CGContextRef);
fn CGContextResetClip(c: crate::sys::CGContextRef); fn CGContextResetClip(c: ::sys::CGContextRef);
fn CGContextStrokePath(c: crate::sys::CGContextRef); fn CGContextStrokePath(c: ::sys::CGContextRef);
fn CGContextSetRGBFillColor( fn CGContextSetRGBFillColor(context: ::sys::CGContextRef,
context: crate::sys::CGContextRef, red: CGFloat,
red: CGFloat, green: CGFloat,
green: CGFloat, blue: CGFloat,
blue: CGFloat, alpha: CGFloat);
alpha: CGFloat, fn CGContextSetRGBStrokeColor(context: ::sys::CGContextRef,
); red: CGFloat,
fn CGContextSetRGBStrokeColor( green: CGFloat,
context: crate::sys::CGContextRef, blue: CGFloat,
red: CGFloat, alpha: CGFloat);
green: CGFloat, fn CGContextSetGrayFillColor(context: ::sys::CGContextRef, gray: CGFloat, alpha: CGFloat);
blue: CGFloat, fn CGContextClearRect(context: ::sys::CGContextRef,
alpha: CGFloat, rect: CGRect);
); fn CGContextFillRect(context: ::sys::CGContextRef,
fn CGContextSetGrayFillColor(context: crate::sys::CGContextRef, gray: CGFloat, alpha: CGFloat); rect: CGRect);
fn CGContextClearRect(context: crate::sys::CGContextRef, rect: CGRect); fn CGContextFillRects(context: ::sys::CGContextRef,
fn CGContextFillRect(context: crate::sys::CGContextRef, rect: CGRect); rects: *const CGRect,
fn CGContextFillRects(context: crate::sys::CGContextRef, rects: *const CGRect, count: size_t); count: size_t);
fn CGContextStrokeRect(context: crate::sys::CGContextRef, rect: CGRect); fn CGContextStrokeRect(context: ::sys::CGContextRef,
fn CGContextStrokeRectWithWidth( rect: CGRect);
context: crate::sys::CGContextRef, fn CGContextStrokeRectWithWidth(context: ::sys::CGContextRef,
rect: CGRect, rect: CGRect,
width: CGFloat, width: CGFloat);
); fn CGContextClipToRect(context: ::sys::CGContextRef,
fn CGContextClipToRect(context: crate::sys::CGContextRef, rect: CGRect); rect: CGRect);
fn CGContextClipToRects(context: crate::sys::CGContextRef, rects: *const CGRect, count: size_t); fn CGContextClipToRects(context: ::sys::CGContextRef,
fn CGContextClipToMask( rects: *const CGRect,
ctx: crate::sys::CGContextRef, count: size_t);
rect: CGRect, fn CGContextClipToMask(ctx: ::sys::CGContextRef, rect: CGRect, mask: ::sys::CGImageRef);
mask: crate::sys::CGImageRef, fn CGContextReplacePathWithStrokedPath(context: ::sys::CGContextRef);
); fn CGContextFillEllipseInRect(context: ::sys::CGContextRef,
fn CGContextReplacePathWithStrokedPath(context: crate::sys::CGContextRef); rect: CGRect);
fn CGContextFillEllipseInRect(context: crate::sys::CGContextRef, rect: CGRect); fn CGContextStrokeEllipseInRect(context: ::sys::CGContextRef,
fn CGContextStrokeEllipseInRect(context: crate::sys::CGContextRef, rect: CGRect); rect: CGRect);
fn CGContextStrokeLineSegments( fn CGContextStrokeLineSegments(context: ::sys::CGContextRef,
context: crate::sys::CGContextRef, points: *const CGPoint,
points: *const CGPoint, count: size_t);
count: size_t, fn CGContextDrawImage(c: ::sys::CGContextRef, rect: CGRect, image: ::sys::CGImageRef);
); fn CGContextSetInterpolationQuality(c: ::sys::CGContextRef, quality: CGInterpolationQuality);
fn CGContextDrawImage(c: crate::sys::CGContextRef, rect: CGRect, image: crate::sys::CGImageRef); fn CGContextGetInterpolationQuality(c: ::sys::CGContextRef) -> CGInterpolationQuality;
fn CGContextSetInterpolationQuality( fn CGContextSetFont(c: ::sys::CGContextRef, font: ::sys::CGFontRef);
c: crate::sys::CGContextRef, fn CGContextSetFontSize(c: ::sys::CGContextRef, size: CGFloat);
quality: CGInterpolationQuality, fn CGContextSetTextMatrix(c: ::sys::CGContextRef, t: CGAffineTransform);
); fn CGContextSetTextPosition(c: ::sys::CGContextRef, x: CGFloat, y: CGFloat);
fn CGContextGetInterpolationQuality(c: crate::sys::CGContextRef) -> CGInterpolationQuality; fn CGContextShowGlyphsAtPositions(c: ::sys::CGContextRef,
fn CGContextSetFont(c: crate::sys::CGContextRef, font: crate::sys::CGFontRef); glyphs: *const CGGlyph,
fn CGContextSetFontSize(c: crate::sys::CGContextRef, size: CGFloat); positions: *const CGPoint,
fn CGContextSetTextMatrix(c: crate::sys::CGContextRef, t: CGAffineTransform); count: size_t);
fn CGContextSetTextPosition(c: crate::sys::CGContextRef, x: CGFloat, y: CGFloat);
fn CGContextShowGlyphsAtPositions(
c: crate::sys::CGContextRef,
glyphs: *const CGGlyph,
positions: *const CGPoint,
count: size_t,
);
fn CGContextSaveGState(c: crate::sys::CGContextRef); fn CGContextSaveGState(c: ::sys::CGContextRef);
fn CGContextRestoreGState(c: crate::sys::CGContextRef); fn CGContextRestoreGState(c: ::sys::CGContextRef);
fn CGContextTranslateCTM(c: crate::sys::CGContextRef, tx: CGFloat, ty: CGFloat); fn CGContextTranslateCTM(c: ::sys::CGContextRef, tx: CGFloat, ty: CGFloat);
fn CGContextScaleCTM(c: crate::sys::CGContextRef, sx: CGFloat, sy: CGFloat); fn CGContextScaleCTM(c: ::sys::CGContextRef, sx: CGFloat, sy: CGFloat);
fn CGContextRotateCTM(c: crate::sys::CGContextRef, angle: CGFloat); fn CGContextRotateCTM(c: ::sys::CGContextRef, angle: CGFloat);
fn CGContextGetCTM(c: crate::sys::CGContextRef) -> CGAffineTransform; fn CGContextGetCTM(c: ::sys::CGContextRef) -> CGAffineTransform;
fn CGContextConcatCTM(c: crate::sys::CGContextRef, transform: CGAffineTransform); fn CGContextConcatCTM(c: ::sys::CGContextRef, transform: CGAffineTransform);
fn CGContextDrawLinearGradient( fn CGContextDrawLinearGradient(c: ::sys::CGContextRef, gradient: ::sys::CGGradientRef, startPoint: CGPoint, endPoint: CGPoint, options: CGGradientDrawingOptions);
c: crate::sys::CGContextRef, fn CGContextDrawRadialGradient(c: ::sys::CGContextRef, gradient: ::sys::CGGradientRef, startCenter: CGPoint, startRadius: CGFloat, endCenter:CGPoint, endRadius:CGFloat, options: CGGradientDrawingOptions);
gradient: crate::sys::CGGradientRef,
startPoint: CGPoint,
endPoint: CGPoint,
options: CGGradientDrawingOptions,
);
fn CGContextDrawRadialGradient(
c: crate::sys::CGContextRef,
gradient: crate::sys::CGGradientRef,
startCenter: CGPoint,
startRadius: CGFloat,
endCenter: CGPoint,
endRadius: CGFloat,
options: CGGradientDrawingOptions,
);
fn CGContextSetShadow(c: crate::sys::CGContextRef, offset: CGSize, blur: CGFloat); fn CGContextSetShadow(c: ::sys::CGContextRef, offset: CGSize, blur: CGFloat);
fn CGContextSetShadowWithColor( fn CGContextSetShadowWithColor(c: ::sys::CGContextRef, offset: CGSize, blur: CGFloat, color: ::sys::CGColorRef);
c: crate::sys::CGContextRef,
offset: CGSize,
blur: CGFloat,
color: crate::sys::CGColorRef,
);
fn CGContextSetAlpha(c: crate::sys::CGContextRef, alpha: CGFloat); fn CGContextSetAlpha(c: ::sys::CGContextRef, alpha: CGFloat);
} }

View File

@@ -10,37 +10,30 @@
use core_foundation::base::{CFRelease, CFRetain, CFTypeID, TCFType}; use core_foundation::base::{CFRelease, CFRetain, CFTypeID, TCFType};
use core_foundation::data::{CFData, CFDataRef}; use core_foundation::data::{CFData, CFDataRef};
use libc::{off_t, size_t}; use libc::{size_t, off_t};
use std::mem; use std::mem;
use std::os::raw::c_void;
use std::ptr; use std::ptr;
use std::sync::Arc; use std::sync::Arc;
use std::os::raw::c_void;
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef}; use foreign_types::{ForeignType, ForeignTypeRef};
pub type CGDataProviderGetBytesCallback = pub type CGDataProviderGetBytesCallback = Option<unsafe extern fn (*mut c_void, *mut c_void, size_t) -> size_t>;
Option<unsafe extern "C" fn(*mut c_void, *mut c_void, size_t) -> size_t>; pub type CGDataProviderReleaseInfoCallback = Option<unsafe extern fn (*mut c_void)>;
pub type CGDataProviderReleaseInfoCallback = Option<unsafe extern "C" fn(*mut c_void)>; pub type CGDataProviderRewindCallback = Option<unsafe extern fn (*mut c_void)>;
pub type CGDataProviderRewindCallback = Option<unsafe extern "C" fn(*mut c_void)>; pub type CGDataProviderSkipBytesCallback = Option<unsafe extern fn (*mut c_void, size_t)>;
pub type CGDataProviderSkipBytesCallback = Option<unsafe extern "C" fn(*mut c_void, size_t)>; pub type CGDataProviderSkipForwardCallback = Option<unsafe extern fn (*mut c_void, off_t) -> off_t>;
pub type CGDataProviderSkipForwardCallback =
Option<unsafe extern "C" fn(*mut c_void, off_t) -> off_t>;
pub type CGDataProviderGetBytePointerCallback = pub type CGDataProviderGetBytePointerCallback = Option<unsafe extern fn (*mut c_void) -> *mut c_void>;
Option<unsafe extern "C" fn(*mut c_void) -> *mut c_void>; pub type CGDataProviderGetBytesAtOffsetCallback = Option<unsafe extern fn (*mut c_void, *mut c_void, size_t, size_t)>;
pub type CGDataProviderGetBytesAtOffsetCallback = pub type CGDataProviderReleaseBytePointerCallback = Option<unsafe extern fn (*mut c_void, *const c_void)>;
Option<unsafe extern "C" fn(*mut c_void, *mut c_void, size_t, size_t)>; pub type CGDataProviderReleaseDataCallback = Option<unsafe extern fn (*mut c_void, *const c_void, size_t)>;
pub type CGDataProviderReleaseBytePointerCallback = pub type CGDataProviderGetBytesAtPositionCallback = Option<unsafe extern fn (*mut c_void, *mut c_void, off_t, size_t)>;
Option<unsafe extern "C" fn(*mut c_void, *const c_void)>;
pub type CGDataProviderReleaseDataCallback =
Option<unsafe extern "C" fn(*mut c_void, *const c_void, size_t)>;
pub type CGDataProviderGetBytesAtPositionCallback =
Option<unsafe extern "C" fn(*mut c_void, *mut c_void, off_t, size_t)>;
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGDataProvider { pub unsafe type CGDataProvider {
type CType = crate::sys::CGDataProvider; type CType = ::sys::CGDataProvider;
fn drop = |cs| CFRelease(cs as *mut _); fn drop = |cs| CFRelease(cs as *mut _);
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
@@ -48,7 +41,9 @@ foreign_type! {
impl CGDataProvider { impl CGDataProvider {
pub fn type_id() -> CFTypeID { pub fn type_id() -> CFTypeID {
unsafe { CGDataProviderGetTypeID() } unsafe {
CGDataProviderGetTypeID()
}
} }
/// Creates a data provider from the given reference-counted buffer. /// Creates a data provider from the given reference-counted buffer.
@@ -89,9 +84,7 @@ impl CGDataProvider {
return CGDataProvider::from_ptr(data_provider); return CGDataProvider::from_ptr(data_provider);
unsafe extern "C" fn release(info: *mut c_void, _: *const c_void, _: size_t) { unsafe extern "C" fn release(info: *mut c_void, _: *const c_void, _: size_t) {
drop(mem::transmute::<*mut c_void, Box<Box<dyn CustomData>>>( drop(mem::transmute::<*mut c_void, Box<Box<dyn CustomData>>>(info))
info,
))
} }
} }
} }
@@ -106,10 +99,10 @@ impl CGDataProviderRef {
/// Encapsulates custom data that can be wrapped. /// Encapsulates custom data that can be wrapped.
pub trait CustomData { pub trait CustomData {
/// Returns a pointer to the start of the custom data. This pointer *must not change* during /// Returns a pointer to the start of the custom data. This pointer *must not change* during
/// the lifespan of this `CustomData`. /// the lifespan of this CustomData.
unsafe fn ptr(&self) -> *const u8; unsafe fn ptr(&self) -> *const u8;
/// Returns the length of this custom data. This value must not change during the lifespan of /// Returns the length of this custom data. This value must not change during the lifespan of
/// this `CustomData`. /// this CustomData.
unsafe fn len(&self) -> usize; unsafe fn len(&self) -> usize;
} }
@@ -141,10 +134,7 @@ fn test_data_provider() {
} }
let dropped = Arc::new(AtomicBool::default()); let dropped = Arc::new(AtomicBool::default());
let l = Arc::new(VecWrapper { let l = Arc::new(VecWrapper {inner: vec![5], dropped: dropped.clone() });
inner: vec![5],
dropped: dropped.clone(),
});
let m = l.clone(); let m = l.clone();
let dp = CGDataProvider::from_buffer(l); let dp = CGDataProvider::from_buffer(l);
drop(m); drop(m);
@@ -153,18 +143,17 @@ fn test_data_provider() {
assert!(dropped.load(SeqCst)) assert!(dropped.load(SeqCst))
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
fn CGDataProviderCopyData(provider: crate::sys::CGDataProviderRef) -> CFDataRef; fn CGDataProviderCopyData(provider: ::sys::CGDataProviderRef) -> CFDataRef;
//fn CGDataProviderCreateDirect //fn CGDataProviderCreateDirect
//fn CGDataProviderCreateSequential //fn CGDataProviderCreateSequential
//fn CGDataProviderCreateWithCFData //fn CGDataProviderCreateWithCFData
fn CGDataProviderCreateWithData( fn CGDataProviderCreateWithData(info: *mut c_void,
info: *mut c_void, data: *const c_void,
data: *const c_void, size: size_t,
size: size_t, releaseData: CGDataProviderReleaseDataCallback
releaseData: CGDataProviderReleaseDataCallback, ) -> ::sys::CGDataProviderRef;
) -> crate::sys::CGDataProviderRef;
//fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef; //fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef;
//fn CGDataProviderCreateWithURL //fn CGDataProviderCreateWithURL
fn CGDataProviderGetTypeID() -> CFTypeID; fn CGDataProviderGetTypeID() -> CFTypeID;

View File

@@ -9,21 +9,20 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use bitflags::bitflags;
use libc; use libc;
use std::ops::Deref;
use std::ptr; use std::ptr;
use std::ops::Deref;
pub use crate::base::{boolean_t, CGError}; pub use base::{CGError, boolean_t};
pub use crate::geometry::{CGPoint, CGRect, CGSize}; pub use geometry::{CGRect, CGPoint, CGSize};
use crate::image::CGImage;
use core_foundation::base::{CFRetain, TCFType};
use core_foundation::string::{CFString, CFStringRef}; use core_foundation::string::{CFString, CFStringRef};
use foreign_types::{foreign_type, ForeignType}; use core_foundation::base::{CFRetain, TCFType};
use image::CGImage;
use foreign_types::ForeignType;
pub type CGDirectDisplayID = u32; pub type CGDirectDisplayID = u32;
pub type CGWindowID = u32; pub type CGWindowID = u32;
pub type CGWindowLevel = i32; pub type CGWindowLevel = i32;
pub const kCGNullWindowID: CGWindowID = 0 as CGWindowID; pub const kCGNullWindowID: CGWindowID = 0 as CGWindowID;
@@ -31,12 +30,12 @@ pub const kCGNullDirectDisplayID: CGDirectDisplayID = 0 as CGDirectDisplayID;
pub type CGWindowListOption = u32; pub type CGWindowListOption = u32;
pub const kCGWindowListOptionAll: CGWindowListOption = 0; pub const kCGWindowListOptionAll: CGWindowListOption = 0;
pub const kCGWindowListOptionOnScreenOnly: CGWindowListOption = 1 << 0; pub const kCGWindowListOptionOnScreenOnly: CGWindowListOption = 1 << 0;
pub const kCGWindowListOptionOnScreenAboveWindow: CGWindowListOption = 1 << 1; pub const kCGWindowListOptionOnScreenAboveWindow: CGWindowListOption = 1 << 1;
pub const kCGWindowListOptionOnScreenBelowWindow: CGWindowListOption = 1 << 2; pub const kCGWindowListOptionOnScreenBelowWindow: CGWindowListOption = 1 << 2;
pub const kCGWindowListOptionIncludingWindow: CGWindowListOption = 1 << 3; pub const kCGWindowListOptionIncludingWindow: CGWindowListOption = 1 << 3;
pub const kCGWindowListExcludeDesktopElements: CGWindowListOption = 1 << 4; pub const kCGWindowListExcludeDesktopElements: CGWindowListOption = 1 << 4;
pub type CGWindowImageOption = u32; pub type CGWindowImageOption = u32;
@@ -47,28 +46,28 @@ pub const kCGWindowImageOnlyShadows: CGWindowImageOption = 1 << 2;
pub const kCGWindowImageBestResolution: CGWindowImageOption = 1 << 3; pub const kCGWindowImageBestResolution: CGWindowImageOption = 1 << 3;
pub const kCGWindowImageNominalResolution: CGWindowImageOption = 1 << 4; pub const kCGWindowImageNominalResolution: CGWindowImageOption = 1 << 4;
pub const kDisplayModeValidFlag: u32 = 0x00000001; pub const kDisplayModeValidFlag: u32 = 0x00000001;
pub const kDisplayModeSafeFlag: u32 = 0x00000002; pub const kDisplayModeSafeFlag: u32 = 0x00000002;
pub const kDisplayModeDefaultFlag: u32 = 0x00000004; pub const kDisplayModeDefaultFlag: u32 = 0x00000004;
pub const kDisplayModeAlwaysShowFlag: u32 = 0x00000008; pub const kDisplayModeAlwaysShowFlag: u32 = 0x00000008;
pub const kDisplayModeNeverShowFlag: u32 = 0x00000080; pub const kDisplayModeNeverShowFlag: u32 = 0x00000080;
pub const kDisplayModeNotResizeFlag: u32 = 0x00000010; pub const kDisplayModeNotResizeFlag: u32 = 0x00000010;
pub const kDisplayModeRequiresPanFlag: u32 = 0x00000020; pub const kDisplayModeRequiresPanFlag: u32 = 0x00000020;
pub const kDisplayModeInterlacedFlag: u32 = 0x00000040; pub const kDisplayModeInterlacedFlag: u32 = 0x00000040;
pub const kDisplayModeSimulscanFlag: u32 = 0x00000100; pub const kDisplayModeSimulscanFlag: u32 = 0x00000100;
pub const kDisplayModeBuiltInFlag: u32 = 0x00000400; pub const kDisplayModeBuiltInFlag: u32 = 0x00000400;
pub const kDisplayModeNotPresetFlag: u32 = 0x00000200; pub const kDisplayModeNotPresetFlag: u32 = 0x00000200;
pub const kDisplayModeStretchedFlag: u32 = 0x00000800; pub const kDisplayModeStretchedFlag: u32 = 0x00000800;
pub const kDisplayModeNotGraphicsQualityFlag: u32 = 0x00001000; pub const kDisplayModeNotGraphicsQualityFlag: u32 = 0x00001000;
pub const kDisplayModeValidateAgainstDisplay: u32 = 0x00002000; pub const kDisplayModeValidateAgainstDisplay: u32 = 0x00002000;
pub const kDisplayModeTelevisionFlag: u32 = 0x00100000; pub const kDisplayModeTelevisionFlag: u32 = 0x00100000;
pub const kDisplayModeValidForMirroringFlag: u32 = 0x00200000; pub const kDisplayModeValidForMirroringFlag: u32 = 0x00200000;
pub const kDisplayModeAcceleratorBackedFlag: u32 = 0x00400000; pub const kDisplayModeAcceleratorBackedFlag: u32 = 0x00400000;
pub const kDisplayModeValidForHiResFlag: u32 = 0x00800000; pub const kDisplayModeValidForHiResFlag: u32 = 0x00800000;
pub const kDisplayModeValidForAirPlayFlag: u32 = 0x01000000; pub const kDisplayModeValidForAirPlayFlag: u32 = 0x01000000;
pub const kDisplayModeNativeFlag: u32 = 0x02000000; pub const kDisplayModeNativeFlag: u32 = 0x02000000;
pub const kDisplayModeSafetyFlags: u32 = 0x00000007; pub const kDisplayModeSafetyFlags: u32 = 0x00000007;
pub type CGDisplayBlendFraction = f32; pub type CGDisplayBlendFraction = f32;
pub const kCGDisplayBlendNormal: CGDisplayBlendFraction = 0.0; pub const kCGDisplayBlendNormal: CGDisplayBlendFraction = 0.0;
@@ -81,25 +80,24 @@ pub type CGDisplayFadeInterval = f32;
pub type CGDisplayReservationInterval = f32; pub type CGDisplayReservationInterval = f32;
pub const kCGMaxDisplayReservationInterval: CGDisplayReservationInterval = 15.0; pub const kCGMaxDisplayReservationInterval: CGDisplayReservationInterval = 15.0;
pub const IO1BitIndexedPixels: &str = "P"; pub const IO1BitIndexedPixels: &str = "P";
pub const IO2BitIndexedPixels: &str = "PP"; pub const IO2BitIndexedPixels: &str = "PP";
pub const IO4BitIndexedPixels: &str = "PPPP"; pub const IO4BitIndexedPixels: &str = "PPPP";
pub const IO8BitIndexedPixels: &str = "PPPPPPPP"; pub const IO8BitIndexedPixels: &str = "PPPPPPPP";
pub const IO16BitDirectPixels: &str = "-RRRRRGGGGGBBBBB"; pub const IO16BitDirectPixels: &str = "-RRRRRGGGGGBBBBB";
pub const IO32BitDirectPixels: &str = "--------RRRRRRRRGGGGGGGGBBBBBBBB"; pub const IO32BitDirectPixels: &str = "--------RRRRRRRRGGGGGGGGBBBBBBBB";
pub const kIO30BitDirectPixels: &str = "--RRRRRRRRRRGGGGGGGGGGBBBBBBBBBB"; pub const kIO30BitDirectPixels: &str = "--RRRRRRRRRRGGGGGGGGGGBBBBBBBBBB";
pub const kIO64BitDirectPixels: &str = "-16R16G16B16"; pub const kIO64BitDirectPixels: &str = "-16R16G16B16";
pub const kIO16BitFloatPixels: &str = "-16FR16FG16FB16"; pub const kIO16BitFloatPixels: &str = "-16FR16FG16FB16";
pub const kIO32BitFloatPixels: &str = "-32FR32FG32FB32"; pub const kIO32BitFloatPixels: &str = "-32FR32FG32FB32";
pub const IOYUV422Pixels: &str = "Y4U2V2"; pub const IOYUV422Pixels: &str = "Y4U2V2";
pub const IO8BitOverlayPixels: &str = "O8"; pub const IO8BitOverlayPixels: &str = "O8";
pub use core_foundation::array::{CFArray, CFArrayRef};
pub use core_foundation::array::{CFArrayGetCount, CFArrayGetValueAtIndex}; pub use core_foundation::dictionary::{ CFDictionary, CFDictionaryRef, CFDictionaryGetValueIfPresent };
pub use core_foundation::base::{CFIndex, CFRelease, CFTypeRef}; pub use core_foundation::array::{ CFArray, CFArrayRef };
pub use core_foundation::dictionary::{ pub use core_foundation::array::{ CFArrayGetCount, CFArrayGetValueAtIndex };
CFDictionary, CFDictionaryGetValueIfPresent, CFDictionaryRef, pub use core_foundation::base::{ CFIndex, CFRelease, CFTypeRef };
};
pub type CGDisplayConfigRef = *mut libc::c_void; pub type CGDisplayConfigRef = *mut libc::c_void;
@@ -111,41 +109,6 @@ pub enum CGConfigureOption {
ConfigurePermanently = 2, ConfigurePermanently = 2,
} }
/// A client-supplied callback function thats invoked whenever the configuration of a local display is changed.
pub type CGDisplayReconfigurationCallBack =
unsafe extern "C" fn(display: CGDirectDisplayID, flags: u32, user_info: *const libc::c_void);
bitflags! {
/// The configuration parameters that are passed to a display reconfiguration callback function.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CGDisplayChangeSummaryFlags: u32 {
/// The display configuration is about to change.
const kCGDisplayBeginConfigurationFlag = 1;
/// The location of the upper-left corner of the display in the global display coordinate space has changed.
const kCGDisplayMovedFlag = 1 << 1;
/// The display is now the main display.
const kCGDisplaySetMainFlag = 1 << 2;
/// The display mode has changed.
const kCGDisplaySetModeFlag = 1 << 3;
/// The display has been added to the active display list.
const kCGDisplayAddFlag = 1 << 4;
/// The display has been removed from the active display list.
const kCGDisplayRemoveFlag = 1 << 5;
/// The display has been enabled.
const kCGDisplayEnabledFlag = 1 << 8;
/// The display has been disabled.
const kCGDisplayDisabledFlag = 1 << 9;
/// The display is now mirroring another display.
const kCGDisplayMirrorFlag = 1 << 10;
/// The display is no longer mirroring another display.
const kCGDisplayUnMirrorFlag = 1 << 11;
/// The shape of the desktop (the union of display areas) has changed.
const kCGDisplayDesktopShapeChangedFlag = 1 << 12;
const _ = !0;
}
}
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct CGDisplay { pub struct CGDisplay {
pub id: CGDirectDisplayID, pub id: CGDirectDisplayID,
@@ -154,7 +117,7 @@ pub struct CGDisplay {
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGDisplayMode { pub unsafe type CGDisplayMode {
type CType = crate::sys::CGDisplayMode; type CType = ::sys::CGDisplayMode;
fn drop = CGDisplayModeRelease; fn drop = CGDisplayModeRelease;
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
@@ -163,7 +126,7 @@ foreign_type! {
impl CGDisplay { impl CGDisplay {
#[inline] #[inline]
pub fn new(id: CGDirectDisplayID) -> CGDisplay { pub fn new(id: CGDirectDisplayID) -> CGDisplay {
CGDisplay { id } CGDisplay { id: id }
} }
/// Returns the the main display. /// Returns the the main display.
@@ -496,15 +459,11 @@ impl CGDisplay {
/// Provides a list of displays that are active (or drawable). /// Provides a list of displays that are active (or drawable).
#[inline] #[inline]
pub fn active_displays() -> Result<Vec<CGDirectDisplayID>, CGError> { pub fn active_displays() -> Result<Vec<CGDirectDisplayID>, CGError> {
let expected_count = CGDisplay::active_display_count()?; let count = CGDisplay::active_display_count()?;
let mut buf: Vec<CGDirectDisplayID> = vec![0; expected_count as usize]; let mut buf: Vec<CGDirectDisplayID> = vec![0; count as usize];
let mut actual_count: u32 = 0;
let result = let result =
unsafe { CGGetActiveDisplayList(expected_count, buf.as_mut_ptr(), &mut actual_count) }; unsafe { CGGetActiveDisplayList(count as u32, buf.as_mut_ptr(), ptr::null_mut()) };
if result == 0 { if result == 0 {
buf.truncate(actual_count as usize);
Ok(buf) Ok(buf)
} else { } else {
Err(result) Err(result)
@@ -517,7 +476,7 @@ impl CGDisplay {
let mut count: u32 = 0; let mut count: u32 = 0;
let result = unsafe { CGGetActiveDisplayList(0, ptr::null_mut(), &mut count) }; let result = unsafe { CGGetActiveDisplayList(0, ptr::null_mut(), &mut count) };
if result == 0 { if result == 0 {
Ok(count) Ok(count as u32)
} else { } else {
Err(result) Err(result)
} }
@@ -601,10 +560,9 @@ impl CGDisplayMode {
let vec: Vec<CGDisplayMode> = modes let vec: Vec<CGDisplayMode> = modes
.into_iter() .into_iter()
.map(|value0| { .map(|value0| {
let x = *value0.deref() as *mut crate::sys::CGDisplayMode; let x = *value0.deref() as *mut ::sys::CGDisplayMode;
unsafe { CGDisplayMode::from_ptr(x) } unsafe { CGDisplayMode::from_ptr(x) }
}) }).collect();
.collect();
Some(vec) Some(vec)
} }
None => None, None => None,
@@ -643,7 +601,7 @@ impl CGDisplayMode {
/// Returns the I/O Kit flags of the specified display mode. /// Returns the I/O Kit flags of the specified display mode.
#[inline] #[inline]
pub fn io_flags(&self) -> u32 { pub fn io_flags(&self) -> u32 {
unsafe { CGDisplayModeGetIOFlags(self.as_ptr()) } unsafe { CGDisplayModeGetIOFlags(self.as_ptr()) as u32 }
} }
/// Returns the pixel encoding of the specified display mode. /// Returns the pixel encoding of the specified display mode.
@@ -681,15 +639,15 @@ impl CGDisplayMode {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern "C" {
pub static CGRectNull: CGRect; pub static CGRectNull: CGRect;
pub static CGRectInfinite: CGRect; pub static CGRectInfinite: CGRect;
pub static kCGDisplayShowDuplicateLowResolutionModes: CFStringRef; pub static kCGDisplayShowDuplicateLowResolutionModes: CFStringRef;
pub fn CGDisplayModeRetain(mode: crate::sys::CGDisplayModeRef); pub fn CGDisplayModeRetain(mode: ::sys::CGDisplayModeRef);
pub fn CGDisplayModeRelease(mode: crate::sys::CGDisplayModeRef); pub fn CGDisplayModeRelease(mode: ::sys::CGDisplayModeRef);
pub fn CGMainDisplayID() -> CGDirectDisplayID; pub fn CGMainDisplayID() -> CGDirectDisplayID;
pub fn CGDisplayIsActive(display: CGDirectDisplayID) -> boolean_t; pub fn CGDisplayIsActive(display: CGDirectDisplayID) -> boolean_t;
@@ -724,11 +682,11 @@ extern "C" {
pub fn CGDisplayPixelsHigh(display: CGDirectDisplayID) -> libc::size_t; pub fn CGDisplayPixelsHigh(display: CGDirectDisplayID) -> libc::size_t;
pub fn CGDisplayPixelsWide(display: CGDirectDisplayID) -> libc::size_t; pub fn CGDisplayPixelsWide(display: CGDirectDisplayID) -> libc::size_t;
pub fn CGDisplayBounds(display: CGDirectDisplayID) -> CGRect; pub fn CGDisplayBounds(display: CGDirectDisplayID) -> CGRect;
pub fn CGDisplayCreateImage(display: CGDirectDisplayID) -> crate::sys::CGImageRef; pub fn CGDisplayCreateImage(display: CGDirectDisplayID) -> ::sys::CGImageRef;
pub fn CGDisplayCreateImageForRect( pub fn CGDisplayCreateImageForRect(
display: CGDirectDisplayID, display: CGDirectDisplayID,
rect: CGRect, rect: CGRect,
) -> crate::sys::CGImageRef; ) -> ::sys::CGImageRef;
// Capturing and Releasing Displays // Capturing and Releasing Displays
pub fn CGDisplayCapture(display: CGDirectDisplayID) -> CGError; pub fn CGDisplayCapture(display: CGDirectDisplayID) -> CGError;
@@ -745,7 +703,7 @@ extern "C" {
pub fn CGConfigureDisplayWithDisplayMode( pub fn CGConfigureDisplayWithDisplayMode(
config: CGDisplayConfigRef, config: CGDisplayConfigRef,
display: CGDirectDisplayID, display: CGDirectDisplayID,
mode: crate::sys::CGDisplayModeRef, mode: ::sys::CGDisplayModeRef,
options: CFDictionaryRef, options: CFDictionaryRef,
) -> CGError; ) -> CGError;
pub fn CGConfigureDisplayMirrorOfDisplay( pub fn CGConfigureDisplayMirrorOfDisplay(
@@ -760,24 +718,16 @@ extern "C" {
y: i32, y: i32,
) -> CGError; ) -> CGError;
pub fn CGRestorePermanentDisplayConfiguration(); pub fn CGRestorePermanentDisplayConfiguration();
pub fn CGDisplayRegisterReconfigurationCallback(
callback: CGDisplayReconfigurationCallBack,
user_info: *const libc::c_void,
) -> CGError;
pub fn CGDisplayRemoveReconfigurationCallback(
callback: CGDisplayReconfigurationCallBack,
user_info: *const libc::c_void,
) -> CGError;
pub fn CGDisplayCopyDisplayMode(display: CGDirectDisplayID) -> crate::sys::CGDisplayModeRef; pub fn CGDisplayCopyDisplayMode(display: CGDirectDisplayID) -> ::sys::CGDisplayModeRef;
pub fn CGDisplayModeGetHeight(mode: crate::sys::CGDisplayModeRef) -> libc::size_t; pub fn CGDisplayModeGetHeight(mode: ::sys::CGDisplayModeRef) -> libc::size_t;
pub fn CGDisplayModeGetWidth(mode: crate::sys::CGDisplayModeRef) -> libc::size_t; pub fn CGDisplayModeGetWidth(mode: ::sys::CGDisplayModeRef) -> libc::size_t;
pub fn CGDisplayModeGetPixelHeight(mode: crate::sys::CGDisplayModeRef) -> libc::size_t; pub fn CGDisplayModeGetPixelHeight(mode: ::sys::CGDisplayModeRef) -> libc::size_t;
pub fn CGDisplayModeGetPixelWidth(mode: crate::sys::CGDisplayModeRef) -> libc::size_t; pub fn CGDisplayModeGetPixelWidth(mode: ::sys::CGDisplayModeRef) -> libc::size_t;
pub fn CGDisplayModeGetRefreshRate(mode: crate::sys::CGDisplayModeRef) -> libc::c_double; pub fn CGDisplayModeGetRefreshRate(mode: ::sys::CGDisplayModeRef) -> libc::c_double;
pub fn CGDisplayModeGetIOFlags(mode: crate::sys::CGDisplayModeRef) -> u32; pub fn CGDisplayModeGetIOFlags(mode: ::sys::CGDisplayModeRef) -> u32;
pub fn CGDisplayModeCopyPixelEncoding(mode: crate::sys::CGDisplayModeRef) -> CFStringRef; pub fn CGDisplayModeCopyPixelEncoding(mode: ::sys::CGDisplayModeRef) -> CFStringRef;
pub fn CGDisplayModeGetIODisplayModeID(mode: crate::sys::CGDisplayModeRef) -> i32; pub fn CGDisplayModeGetIODisplayModeID(mode: ::sys::CGDisplayModeRef) -> i32;
pub fn CGDisplayCopyAllDisplayModes( pub fn CGDisplayCopyAllDisplayModes(
display: CGDirectDisplayID, display: CGDirectDisplayID,
@@ -785,7 +735,7 @@ extern "C" {
) -> CFArrayRef; ) -> CFArrayRef;
pub fn CGDisplaySetDisplayMode( pub fn CGDisplaySetDisplayMode(
display: CGDirectDisplayID, display: CGDirectDisplayID,
mode: crate::sys::CGDisplayModeRef, mode: ::sys::CGDisplayModeRef,
options: CFDictionaryRef, options: CFDictionaryRef,
) -> CGError; ) -> CGError;
@@ -832,10 +782,10 @@ extern "C" {
listOptions: CGWindowListOption, listOptions: CGWindowListOption,
windowId: CGWindowID, windowId: CGWindowID,
imageOptions: CGWindowImageOption, imageOptions: CGWindowImageOption,
) -> crate::sys::CGImageRef; ) -> ::sys::CGImageRef;
pub fn CGWindowListCreateImageFromArray( pub fn CGWindowListCreateImageFromArray(
screenBounds: CGRect, screenBounds: CGRect,
windowArray: CFArrayRef, windowArray: CFArrayRef,
imageOptions: CGWindowImageOption, imageOptions: CGWindowImageOption,
) -> crate::sys::CGImageRef; ) -> ::sys::CGImageRef;
} }

View File

@@ -1,13 +1,11 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use crate::event_source::CGEventSource;
use crate::geometry::CGPoint;
use bitflags::bitflags;
use core_foundation::{ use core_foundation::{
base::{CFRelease, CFRetain, CFTypeID, TCFType}, base::{CFRelease, CFRetain, CFTypeID, TCFType},
mach_port::{CFMachPort, CFMachPortRef}, mach_port::{CFMachPort, CFMachPortRef},
}; };
use foreign_types::{foreign_type, ForeignType}; use event_source::CGEventSource;
use foreign_types::ForeignType;
use geometry::CGPoint;
use libc::c_void; use libc::c_void;
use std::mem::ManuallyDrop; use std::mem::ManuallyDrop;
@@ -20,7 +18,6 @@ bitflags! {
/// ///
/// [Ref](http://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-700/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h) /// [Ref](http://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-700/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h)
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct CGEventFlags: u64 { pub struct CGEventFlags: u64 {
const CGEventFlagNull = 0; const CGEventFlagNull = 0;
@@ -180,7 +177,7 @@ impl EventField {
pub const MOUSE_EVENT_INSTANT_MOUSER: CGEventField = 6; pub const MOUSE_EVENT_INSTANT_MOUSER: CGEventField = 6;
/// Key to access an integer field that encodes the mouse event subtype as /// Key to access an integer field that encodes the mouse event subtype as
/// a `kCFNumberIntType`. /// a `kCFNumberIntType'.
pub const MOUSE_EVENT_SUB_TYPE: CGEventField = 7; pub const MOUSE_EVENT_SUB_TYPE: CGEventField = 7;
/// Key to access an integer field, non-zero when this is an autorepeat of /// Key to access an integer field, non-zero when this is an autorepeat of
@@ -211,7 +208,7 @@ impl EventField {
/// since the last scrolling event from a Mighty Mouse scroller or a /// since the last scrolling event from a Mighty Mouse scroller or a
/// single-wheel mouse scroller. The scrolling data uses a fixed-point /// single-wheel mouse scroller. The scrolling data uses a fixed-point
/// 16.16 signed integer format. If this key is passed to /// 16.16 signed integer format. If this key is passed to
/// `CGEventGetDoubleValueField`, the fixed-point value is converted to a /// `CGEventGetDoubleValueField', the fixed-point value is converted to a
/// double value. /// double value.
pub const SCROLL_WHEEL_EVENT_FIXED_POINT_DELTA_AXIS_1: CGEventField = 93; pub const SCROLL_WHEEL_EVENT_FIXED_POINT_DELTA_AXIS_1: CGEventField = 93;
@@ -219,7 +216,7 @@ impl EventField {
/// represents a line-based or pixel-based change in horizontal position /// represents a line-based or pixel-based change in horizontal position
/// since the last scrolling event from a Mighty Mouse scroller. The /// since the last scrolling event from a Mighty Mouse scroller. The
/// scrolling data uses a fixed-point 16.16 signed integer format. If this /// scrolling data uses a fixed-point 16.16 signed integer format. If this
/// key is passed to `CGEventGetDoubleValueField`, the fixed-point value is /// key is passed to `CGEventGetDoubleValueField', the fixed-point value is
/// converted to a double value. /// converted to a double value.
pub const SCROLL_WHEEL_EVENT_FIXED_POINT_DELTA_AXIS_2: CGEventField = 94; pub const SCROLL_WHEEL_EVENT_FIXED_POINT_DELTA_AXIS_2: CGEventField = 94;
@@ -422,16 +419,16 @@ pub type CGEventTapCallBackFn<'tap_life> =
type CGEventTapCallBackInternal = unsafe extern "C" fn( type CGEventTapCallBackInternal = unsafe extern "C" fn(
proxy: CGEventTapProxy, proxy: CGEventTapProxy,
etype: CGEventType, etype: CGEventType,
event: crate::sys::CGEventRef, event: ::sys::CGEventRef,
user_info: *const c_void, user_info: *const c_void,
) -> crate::sys::CGEventRef; ) -> ::sys::CGEventRef;
unsafe extern "C" fn cg_event_tap_callback_internal( unsafe extern "C" fn cg_event_tap_callback_internal(
_proxy: CGEventTapProxy, _proxy: CGEventTapProxy,
_etype: CGEventType, _etype: CGEventType,
_event: crate::sys::CGEventRef, _event: ::sys::CGEventRef,
_user_info: *const c_void, _user_info: *const c_void,
) -> crate::sys::CGEventRef { ) -> ::sys::CGEventRef {
let callback = _user_info as *mut CGEventTapCallBackFn; let callback = _user_info as *mut CGEventTapCallBackFn;
let event = CGEvent::from_ptr(_event); let event = CGEvent::from_ptr(_event);
let new_event = (*callback)(_proxy, _etype, &event); let new_event = (*callback)(_proxy, _etype, &event);
@@ -442,7 +439,9 @@ unsafe extern "C" fn cg_event_tap_callback_internal(
ManuallyDrop::new(event).as_ptr() ManuallyDrop::new(event).as_ptr()
} }
/// ```no_run /// ```no_run
///extern crate core_foundation;
///use core_foundation::runloop::{kCFRunLoopCommonModes, CFRunLoop}; ///use core_foundation::runloop::{kCFRunLoopCommonModes, CFRunLoop};
///use core_graphics::event::{CGEventTap, CGEventTapLocation, CGEventTapPlacement, CGEventTapOptions, CGEventType}; ///use core_graphics::event::{CGEventTap, CGEventTapLocation, CGEventTapPlacement, CGEventTapOptions, CGEventType};
///let current = CFRunLoop::get_current(); ///let current = CFRunLoop::get_current();
@@ -519,7 +518,7 @@ impl<'tap_life> CGEventTap<'tap_life> {
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGEvent { pub unsafe type CGEvent {
type CType = crate::sys::CGEvent; type CType = ::sys::CGEvent;
fn drop = |p| CFRelease(p as *mut _); fn drop = |p| CFRelease(p as *mut _);
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
@@ -527,7 +526,9 @@ foreign_type! {
impl CGEvent { impl CGEvent {
pub fn type_id() -> CFTypeID { pub fn type_id() -> CFTypeID {
unsafe { CGEventGetTypeID() } unsafe {
CGEventGetTypeID()
}
} }
pub fn new(source: CGEventSource) -> Result<CGEvent, ()> { pub fn new(source: CGEventSource) -> Result<CGEvent, ()> {
@@ -544,7 +545,7 @@ impl CGEvent {
pub fn new_keyboard_event( pub fn new_keyboard_event(
source: CGEventSource, source: CGEventSource,
keycode: CGKeyCode, keycode: CGKeyCode,
keydown: bool, keydown: bool
) -> Result<CGEvent, ()> { ) -> Result<CGEvent, ()> {
unsafe { unsafe {
let event_ref = CGEventCreateKeyboardEvent(source.as_ptr(), keycode, keydown); let event_ref = CGEventCreateKeyboardEvent(source.as_ptr(), keycode, keydown);
@@ -560,15 +561,11 @@ impl CGEvent {
source: CGEventSource, source: CGEventSource,
mouse_type: CGEventType, mouse_type: CGEventType,
mouse_cursor_position: CGPoint, mouse_cursor_position: CGPoint,
mouse_button: CGMouseButton, mouse_button: CGMouseButton
) -> Result<CGEvent, ()> { ) -> Result<CGEvent, ()> {
unsafe { unsafe {
let event_ref = CGEventCreateMouseEvent( let event_ref = CGEventCreateMouseEvent(source.as_ptr(), mouse_type,
source.as_ptr(), mouse_cursor_position, mouse_button);
mouse_type,
mouse_cursor_position,
mouse_button,
);
if !event_ref.is_null() { if !event_ref.is_null() {
Ok(Self::from_ptr(event_ref)) Ok(Self::from_ptr(event_ref))
} else { } else {
@@ -633,7 +630,9 @@ impl CGEvent {
} }
pub fn get_flags(&self) -> CGEventFlags { pub fn get_flags(&self) -> CGEventFlags {
unsafe { CGEventGetFlags(self.as_ptr()) } unsafe {
CGEventGetFlags(self.as_ptr())
}
} }
pub fn set_type(&self, event_type: CGEventType) { pub fn set_type(&self, event_type: CGEventType) {
@@ -643,7 +642,9 @@ impl CGEvent {
} }
pub fn get_type(&self) -> CGEventType { pub fn get_type(&self) -> CGEventType {
unsafe { CGEventGetType(self.as_ptr()) } unsafe {
CGEventGetType(self.as_ptr())
}
} }
pub fn set_string_from_utf16_unchecked(&self, buf: &[u16]) { pub fn set_string_from_utf16_unchecked(&self, buf: &[u16]) {
@@ -675,14 +676,14 @@ impl CGEvent {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
/// Return the type identifier for the opaque type `CGEventRef'. /// Return the type identifier for the opaque type `CGEventRef'.
fn CGEventGetTypeID() -> CFTypeID; fn CGEventGetTypeID() -> CFTypeID;
/// Return a new event using the event source `source'. If `source' is NULL, /// Return a new event using the event source `source'. If `source' is NULL,
/// the default source is used. /// the default source is used.
fn CGEventCreate(source: crate::sys::CGEventSourceRef) -> crate::sys::CGEventRef; fn CGEventCreate(source: ::sys::CGEventSourceRef) -> ::sys::CGEventRef;
/// Return a new keyboard event. /// Return a new keyboard event.
/// ///
@@ -694,11 +695,8 @@ extern "C" {
/// SHIFT, CONTROL, OPTION, and COMMAND keys. For example, to produce a 'Z', /// SHIFT, CONTROL, OPTION, and COMMAND keys. For example, to produce a 'Z',
/// the SHIFT key must be down, the 'z' key must go down, and then the SHIFT /// the SHIFT key must be down, the 'z' key must go down, and then the SHIFT
/// and 'z' key must be released: /// and 'z' key must be released:
fn CGEventCreateKeyboardEvent( fn CGEventCreateKeyboardEvent(source: ::sys::CGEventSourceRef, keycode: CGKeyCode,
source: crate::sys::CGEventSourceRef, keydown: bool) -> ::sys::CGEventRef;
keycode: CGKeyCode,
keydown: bool,
) -> crate::sys::CGEventRef;
/// Return a new mouse event. /// Return a new mouse event.
/// ///
@@ -713,12 +711,8 @@ extern "C" {
/// thirty-two buttons. Mouse button 0 is the primary button on the mouse. /// thirty-two buttons. Mouse button 0 is the primary button on the mouse.
/// Mouse button 1 is the secondary mouse button (right). Mouse button 2 is /// Mouse button 1 is the secondary mouse button (right). Mouse button 2 is
/// the center button, and the remaining buttons are in USB device order. /// the center button, and the remaining buttons are in USB device order.
fn CGEventCreateMouseEvent( fn CGEventCreateMouseEvent(source: ::sys::CGEventSourceRef, mouseType: CGEventType,
source: crate::sys::CGEventSourceRef, mouseCursorPosition: CGPoint, mouseButton: CGMouseButton) -> ::sys::CGEventRef;
mouseType: CGEventType,
mouseCursorPosition: CGPoint,
mouseButton: CGMouseButton,
) -> crate::sys::CGEventRef;
/// A non-variadic variant version of CGEventCreateScrollWheelEvent. /// A non-variadic variant version of CGEventCreateScrollWheelEvent.
/// ///
@@ -728,42 +722,42 @@ extern "C" {
/// event before posting it to the event system. /// event before posting it to the event system.
#[cfg(feature = "highsierra")] #[cfg(feature = "highsierra")]
fn CGEventCreateScrollWheelEvent2( fn CGEventCreateScrollWheelEvent2(
source: crate::sys::CGEventSourceRef, source: ::sys::CGEventSourceRef,
units: CGScrollEventUnit, units: CGScrollEventUnit,
wheelCount: u32, wheelCount: u32,
wheel1: i32, wheel1: i32,
wheel2: i32, wheel2: i32,
wheel3: i32, wheel3: i32,
) -> crate::sys::CGEventRef; ) -> ::sys::CGEventRef;
/// Post an event into the event stream at a specified location. /// Post an event into the event stream at a specified location.
/// ///
/// This function posts the specified event immediately before any event taps /// This function posts the specified event immediately before any event taps
/// instantiated for that location, and the event passes through any such /// instantiated for that location, and the event passes through any such
/// taps. /// taps.
fn CGEventPost(tapLocation: CGEventTapLocation, event: crate::sys::CGEventRef); fn CGEventPost(tapLocation: CGEventTapLocation, event: ::sys::CGEventRef);
fn CGEventTapPostEvent(tapProxy: CGEventTapProxy, event: crate::sys::CGEventRef); fn CGEventTapPostEvent(tapProxy: CGEventTapProxy, event: ::sys::CGEventRef);
#[cfg(feature = "elcapitan")] #[cfg(feature = "elcapitan")]
/// Post an event to a specified process ID /// Post an event to a specified process ID
fn CGEventPostToPid(pid: libc::pid_t, event: crate::sys::CGEventRef); fn CGEventPostToPid(pid: libc::pid_t, event: ::sys::CGEventRef);
/// Set the event flags of an event. /// Set the event flags of an event.
fn CGEventSetFlags(event: crate::sys::CGEventRef, flags: CGEventFlags); fn CGEventSetFlags(event: ::sys::CGEventRef, flags: CGEventFlags);
/// Return the event flags of an event. /// Return the event flags of an event.
fn CGEventGetFlags(event: crate::sys::CGEventRef) -> CGEventFlags; fn CGEventGetFlags(event: ::sys::CGEventRef) -> CGEventFlags;
/// Return the location of an event in global display coordinates. /// Return the location of an event in global display coordinates.
/// CGPointZero is returned if event is not a valid crate::sys::CGEventRef. /// CGPointZero is returned if event is not a valid ::sys::CGEventRef.
fn CGEventGetLocation(event: crate::sys::CGEventRef) -> CGPoint; fn CGEventGetLocation(event: ::sys::CGEventRef) -> CGPoint;
/// Set the event type of an event. /// Set the event type of an event.
fn CGEventSetType(event: crate::sys::CGEventRef, eventType: CGEventType); fn CGEventSetType(event: ::sys::CGEventRef, eventType: CGEventType);
/// Return the event type of an event (left mouse down, for example). /// Return the event type of an event (left mouse down, for example).
fn CGEventGetType(event: crate::sys::CGEventRef) -> CGEventType; fn CGEventGetType(event: ::sys::CGEventRef) -> CGEventType;
/// Set the Unicode string associated with a keyboard event. /// Set the Unicode string associated with a keyboard event.
/// ///
@@ -773,14 +767,12 @@ extern "C" {
/// Note that application frameworks may ignore the Unicode string in a /// Note that application frameworks may ignore the Unicode string in a
/// keyboard event and do their own translation based on the virtual /// keyboard event and do their own translation based on the virtual
/// keycode and perceived event state. /// keycode and perceived event state.
fn CGEventKeyboardSetUnicodeString( fn CGEventKeyboardSetUnicodeString(event: ::sys::CGEventRef,
event: crate::sys::CGEventRef, length: libc::c_ulong,
length: libc::c_ulong, string: *const u16);
string: *const u16,
);
/// Return the integer value of a field in an event. /// Return the integer value of a field in an event.
fn CGEventGetIntegerValueField(event: crate::sys::CGEventRef, field: CGEventField) -> i64; fn CGEventGetIntegerValueField(event: ::sys::CGEventRef, field: CGEventField) -> i64;
/// Set the integer value of a field in an event. /// Set the integer value of a field in an event.
/// ///
@@ -792,14 +784,14 @@ extern "C" {
/// function and specify the field `kCGMouseEventSubtype' with a value of /// function and specify the field `kCGMouseEventSubtype' with a value of
/// `kCGEventMouseSubtypeTabletPoint' or /// `kCGEventMouseSubtypeTabletPoint' or
/// `kCGEventMouseSubtypeTabletProximity' before setting other parameters. /// `kCGEventMouseSubtypeTabletProximity' before setting other parameters.
fn CGEventSetIntegerValueField(event: crate::sys::CGEventRef, field: CGEventField, value: i64); fn CGEventSetIntegerValueField(event: ::sys::CGEventRef, field: CGEventField, value: i64);
/// Return the floating-point value of a field in an event. /// Return the floating-point value of a field in an event.
/// ///
/// In cases where the field value is represented within the event by a fixed /// In cases where the field value is represented within the event by a fixed
/// point number or an integer, the result is scaled to the appropriate range /// point number or an integer, the result is scaled to the appropriate range
/// as part of creating the floating-point representation. /// as part of creating the floating-point representation.
fn CGEventGetDoubleValueField(event: crate::sys::CGEventRef, field: CGEventField) -> f64; fn CGEventGetDoubleValueField(event: ::sys::CGEventRef, field: CGEventField) -> f64;
/// Set the floating-point value of a field in an event. /// Set the floating-point value of a field in an event.
/// ///
@@ -810,7 +802,7 @@ extern "C" {
/// In cases where the fields value is represented within the event by a /// In cases where the fields value is represented within the event by a
/// fixed point number or integer, the value parameter is scaled as needed /// fixed point number or integer, the value parameter is scaled as needed
/// and converted to the appropriate type. /// and converted to the appropriate type.
fn CGEventSetDoubleValueField(event: crate::sys::CGEventRef, field: CGEventField, value: f64); fn CGEventSetDoubleValueField(event: ::sys::CGEventRef, field: CGEventField, value: f64);
// ::sys::CGEventTapRef is actually an CFMachPortRef // ::sys::CGEventTapRef is actually an CFMachPortRef
fn CGEventTapCreate( fn CGEventTapCreate(

View File

@@ -1,5 +1,5 @@
use core_foundation::base::{CFRelease, CFRetain, CFTypeID}; use core_foundation::base::{CFRelease, CFRetain, CFTypeID};
use foreign_types::{foreign_type, ForeignType}; use foreign_types::ForeignType;
/// Possible source states of an event source. /// Possible source states of an event source.
#[repr(C)] #[repr(C)]
@@ -13,7 +13,7 @@ pub enum CGEventSourceStateID {
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGEventSource { pub unsafe type CGEventSource {
type CType = crate::sys::CGEventSource; type CType = ::sys::CGEventSource;
fn drop = |p| CFRelease(p as *mut _); fn drop = |p| CFRelease(p as *mut _);
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
@@ -21,7 +21,9 @@ foreign_type! {
impl CGEventSource { impl CGEventSource {
pub fn type_id() -> CFTypeID { pub fn type_id() -> CFTypeID {
unsafe { CGEventSourceGetTypeID() } unsafe {
CGEventSourceGetTypeID()
}
} }
pub fn new(state_id: CGEventSourceStateID) -> Result<Self, ()> { pub fn new(state_id: CGEventSourceStateID) -> Result<Self, ()> {
@@ -36,11 +38,11 @@ impl CGEventSource {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
/// Return the type identifier for the opaque type `CGEventSourceRef'. /// Return the type identifier for the opaque type `CGEventSourceRef'.
fn CGEventSourceGetTypeID() -> CFTypeID; fn CGEventSourceGetTypeID() -> CFTypeID;
/// Return a Quartz event source created with a specified source state. /// Return a Quartz event source created with a specified source state.
fn CGEventSourceCreate(stateID: CGEventSourceStateID) -> crate::sys::CGEventSourceRef; fn CGEventSourceCreate(stateID: CGEventSourceStateID) -> ::sys::CGEventSourceRef;
} }

View File

@@ -7,17 +7,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::data_provider::CGDataProvider;
use crate::geometry::CGRect;
use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::base::{CFRelease, CFRetain, CFType, CFTypeID, TCFType}; use core_foundation::base::{CFRelease, CFRetain, CFType, CFTypeID, TCFType};
use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::data::{CFData, CFDataRef}; use core_foundation::data::{CFData, CFDataRef};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use core_foundation::number::CFNumber; use core_foundation::number::CFNumber;
use core_foundation::string::{CFString, CFStringRef}; use core_foundation::string::{CFString, CFStringRef};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use data_provider::CGDataProvider;
use geometry::CGRect;
use std::ptr::NonNull; use std::ptr::NonNull;
use foreign_types::{foreign_type, ForeignType}; use foreign_types::ForeignType;
use libc::{c_int, size_t}; use libc::{c_int, size_t};
@@ -26,7 +26,7 @@ pub use core_graphics_types::base::CGGlyph;
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGFont: Send + Sync { pub unsafe type CGFont: Send + Sync {
type CType = crate::sys::CGFont; type CType = ::sys::CGFont;
fn drop = |p| CFRelease(p as *mut _); fn drop = |p| CFRelease(p as *mut _);
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
@@ -34,7 +34,9 @@ foreign_type! {
impl CGFont { impl CGFont {
pub fn type_id() -> CFTypeID { pub fn type_id() -> CFTypeID {
unsafe { CGFontGetTypeID() } unsafe {
CGFontGetTypeID()
}
} }
pub fn from_data_provider(provider: CGDataProvider) -> Result<CGFont, ()> { pub fn from_data_provider(provider: CGDataProvider) -> Result<CGFont, ()> {
@@ -57,13 +59,10 @@ impl CGFont {
} }
} }
pub fn create_copy_from_variations( pub fn create_copy_from_variations(&self, vars: &CFDictionary<CFString, CFNumber>) -> Result<CGFont, ()> {
&self,
vars: &CFDictionary<CFString, CFNumber>,
) -> Result<CGFont, ()> {
unsafe { unsafe {
let font_ref = let font_ref = CGFontCreateCopyWithVariations(self.as_ptr(),
CGFontCreateCopyWithVariations(self.as_ptr(), vars.as_concrete_TypeRef()); vars.as_concrete_TypeRef());
match NonNull::new(font_ref) { match NonNull::new(font_ref) {
Some(font_ref) => Ok(CGFont(font_ref)), Some(font_ref) => Ok(CGFont(font_ref)),
None => Err(()), None => Err(()),
@@ -81,53 +80,33 @@ impl CGFont {
pub fn get_glyph_b_boxes(&self, glyphs: &[CGGlyph], bboxes: &mut [CGRect]) -> bool { pub fn get_glyph_b_boxes(&self, glyphs: &[CGGlyph], bboxes: &mut [CGRect]) -> bool {
unsafe { unsafe {
assert!(bboxes.len() >= glyphs.len()); assert!(bboxes.len() >= glyphs.len());
CGFontGetGlyphBBoxes( CGFontGetGlyphBBoxes(self.as_ptr(),
self.as_ptr(), glyphs.as_ptr(),
glyphs.as_ptr(), glyphs.len(),
glyphs.len(), bboxes.as_mut_ptr())
bboxes.as_mut_ptr(),
)
} }
} }
pub fn get_glyph_advances(&self, glyphs: &[CGGlyph], advances: &mut [c_int]) -> bool { pub fn get_glyph_advances(&self, glyphs: &[CGGlyph], advances: &mut [c_int]) -> bool {
unsafe { unsafe {
assert!(advances.len() >= glyphs.len()); assert!(advances.len() >= glyphs.len());
CGFontGetGlyphAdvances( CGFontGetGlyphAdvances(self.as_ptr(),
self.as_ptr(), glyphs.as_ptr(),
glyphs.as_ptr(), glyphs.len(),
glyphs.len(), advances.as_mut_ptr())
advances.as_mut_ptr(),
)
} }
} }
pub fn ascent(&self) -> c_int {
unsafe { CGFontGetAscent(self.as_ptr()) }
}
pub fn descent(&self) -> c_int {
unsafe { CGFontGetDescent(self.as_ptr()) }
}
pub fn leading(&self) -> c_int {
unsafe { CGFontGetLeading(self.as_ptr()) }
}
pub fn cap_height(&self) -> c_int {
unsafe { CGFontGetCapHeight(self.as_ptr()) }
}
pub fn x_height(&self) -> c_int {
unsafe { CGFontGetXHeight(self.as_ptr()) }
}
pub fn get_units_per_em(&self) -> c_int { pub fn get_units_per_em(&self) -> c_int {
unsafe { CGFontGetUnitsPerEm(self.as_ptr()) } unsafe {
CGFontGetUnitsPerEm(self.as_ptr())
}
} }
pub fn copy_table_tags(&self) -> CFArray<u32> { pub fn copy_table_tags(&self) -> CFArray<u32> {
unsafe { TCFType::wrap_under_create_rule(CGFontCopyTableTags(self.as_ptr())) } unsafe {
TCFType::wrap_under_create_rule(CGFontCopyTableTags(self.as_ptr()))
}
} }
pub fn copy_table_for_tag(&self, tag: u32) -> Option<CFData> { pub fn copy_table_for_tag(&self, tag: u32) -> Option<CFData> {
@@ -158,48 +137,35 @@ impl CGFont {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
// TODO: basically nothing has bindings (even commented-out) besides what we use. // TODO: basically nothing has bindings (even commented-out) besides what we use.
fn CGFontCreateWithDataProvider( fn CGFontCreateWithDataProvider(provider: ::sys::CGDataProviderRef) -> ::sys::CGFontRef;
provider: crate::sys::CGDataProviderRef, fn CGFontCreateWithFontName(name: CFStringRef) -> ::sys::CGFontRef;
) -> crate::sys::CGFontRef; fn CGFontCreateCopyWithVariations(font: ::sys::CGFontRef, vars: CFDictionaryRef) -> ::sys::CGFontRef;
fn CGFontCreateWithFontName(name: CFStringRef) -> crate::sys::CGFontRef;
fn CGFontCreateCopyWithVariations(
font: crate::sys::CGFontRef,
vars: CFDictionaryRef,
) -> crate::sys::CGFontRef;
fn CGFontGetTypeID() -> CFTypeID; fn CGFontGetTypeID() -> CFTypeID;
fn CGFontCopyPostScriptName(font: crate::sys::CGFontRef) -> CFStringRef; fn CGFontCopyPostScriptName(font: ::sys::CGFontRef) -> CFStringRef;
// These do the same thing as CFRetain/CFRelease, except // These do the same thing as CFRetain/CFRelease, except
// gracefully handle a NULL argument. We don't use them. // gracefully handle a NULL argument. We don't use them.
//fn CGFontRetain(font: ::sys::CGFontRef); //fn CGFontRetain(font: ::sys::CGFontRef);
//fn CGFontRelease(font: ::sys::CGFontRef); //fn CGFontRelease(font: ::sys::CGFontRef);
fn CGFontGetGlyphBBoxes( fn CGFontGetGlyphBBoxes(font: ::sys::CGFontRef,
font: crate::sys::CGFontRef, glyphs: *const CGGlyph,
glyphs: *const CGGlyph, count: size_t,
count: size_t, bboxes: *mut CGRect)
bboxes: *mut CGRect, -> bool;
) -> bool; fn CGFontGetGlyphAdvances(font: ::sys::CGFontRef,
fn CGFontGetGlyphAdvances( glyphs: *const CGGlyph,
font: crate::sys::CGFontRef, count: size_t,
glyphs: *const CGGlyph, advances: *mut c_int)
count: size_t, -> bool;
advances: *mut c_int, fn CGFontGetUnitsPerEm(font: ::sys::CGFontRef) -> c_int;
) -> bool;
fn CGFontGetAscent(font: crate::sys::CGFontRef) -> c_int; fn CGFontCopyTableTags(font: ::sys::CGFontRef) -> CFArrayRef;
fn CGFontGetDescent(font: crate::sys::CGFontRef) -> c_int; fn CGFontCopyTableForTag(font: ::sys::CGFontRef, tag: u32) -> CFDataRef;
fn CGFontGetLeading(font: crate::sys::CGFontRef) -> c_int; fn CGFontCopyVariations(font: ::sys::CGFontRef) -> CFDictionaryRef;
fn CGFontGetCapHeight(font: crate::sys::CGFontRef) -> c_int; fn CGFontCopyVariationAxes(font: ::sys::CGFontRef) -> CFArrayRef;
fn CGFontGetXHeight(font: crate::sys::CGFontRef) -> c_int;
fn CGFontGetUnitsPerEm(font: crate::sys::CGFontRef) -> c_int;
fn CGFontCopyTableTags(font: crate::sys::CGFontRef) -> CFArrayRef;
fn CGFontCopyTableForTag(font: crate::sys::CGFontRef, tag: u32) -> CFDataRef;
fn CGFontCopyVariations(font: crate::sys::CGFontRef) -> CFDictionaryRef;
fn CGFontCopyVariationAxes(font: crate::sys::CGFontRef) -> CFArrayRef;
} }

View File

@@ -7,4 +7,4 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
pub use core_graphics_types::geometry::*; pub use core_graphics_types::geometry::*;

View File

@@ -9,20 +9,18 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use crate::base::CGFloat; use base::CGFloat;
use crate::color::CGColor; use color::CGColor;
use crate::color_space::CGColorSpace; use color_space::CGColorSpace;
use bitflags::bitflags; use core_foundation::array::{ CFArray, CFArrayRef };
use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::base::{CFRelease, CFRetain, TCFType}; use core_foundation::base::{CFRelease, CFRetain, TCFType};
use foreign_types::{foreign_type, ForeignType}; use foreign_types::ForeignType;
use libc::size_t; use libc::size_t;
bitflags! { bitflags! {
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct CGGradientDrawingOptions: u32 { pub struct CGGradientDrawingOptions: u32 {
const CGGradientDrawsBeforeStartLocation = (1 << 0); const CGGradientDrawsBeforeStartLocation = (1 << 0);
const CGGradientDrawsAfterEndLocation = (1 << 1); const CGGradientDrawsAfterEndLocation = (1 << 1);
@@ -32,59 +30,33 @@ bitflags! {
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGGradient { pub unsafe type CGGradient {
type CType = crate::sys::CGGradient; type CType = ::sys::CGGradient;
fn drop = |p| CFRelease(p as *mut _); fn drop = |p| CFRelease(p as *mut _);
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
} }
impl CGGradient { impl CGGradient {
pub fn create_with_color_components( pub fn create_with_color_components(color_space: &CGColorSpace, components: &[CGFloat], locations: &[CGFloat], count: usize) -> CGGradient {
color_space: &CGColorSpace,
components: &[CGFloat],
locations: &[CGFloat],
count: usize,
) -> CGGradient {
unsafe { unsafe {
let result = CGGradientCreateWithColorComponents( let result = CGGradientCreateWithColorComponents(color_space.as_ptr(), components.as_ptr(), locations.as_ptr(), count);
color_space.as_ptr(),
components.as_ptr(),
locations.as_ptr(),
count,
);
assert!(!result.is_null()); assert!(!result.is_null());
Self::from_ptr(result) Self::from_ptr(result)
} }
} }
pub fn create_with_colors( pub fn create_with_colors(color_space: &CGColorSpace, colors: &CFArray<CGColor>, locations: &[CGFloat]) -> CGGradient {
color_space: &CGColorSpace,
colors: &CFArray<CGColor>,
locations: &[CGFloat],
) -> CGGradient {
unsafe { unsafe {
let result = CGGradientCreateWithColors( let result = CGGradientCreateWithColors(color_space.as_ptr(), colors.as_concrete_TypeRef(), locations.as_ptr());
color_space.as_ptr(),
colors.as_concrete_TypeRef(),
locations.as_ptr(),
);
assert!(!result.is_null()); assert!(!result.is_null());
Self::from_ptr(result) Self::from_ptr(result)
} }
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
fn CGGradientCreateWithColorComponents( fn CGGradientCreateWithColorComponents(color_space: ::sys::CGColorSpaceRef, components: *const CGFloat, locations: *const CGFloat, count: size_t) -> ::sys::CGGradientRef;
color_space: crate::sys::CGColorSpaceRef, fn CGGradientCreateWithColors(color_space: ::sys::CGColorSpaceRef, colors: CFArrayRef, locations: *const CGFloat) -> ::sys::CGGradientRef;
components: *const CGFloat,
locations: *const CGFloat,
count: size_t,
) -> crate::sys::CGGradientRef;
fn CGGradientCreateWithColors(
color_space: crate::sys::CGColorSpaceRef,
colors: CFArrayRef,
locations: *const CGFloat,
) -> crate::sys::CGGradientRef;
} }

View File

@@ -1,24 +1,24 @@
use std::ptr; use std::ptr;
use crate::base::CGFloat; use base::CGFloat;
use crate::color_space::CGColorSpace;
use crate::data_provider::{CGDataProvider, CGDataProviderRef};
use crate::geometry::CGRect;
use core_foundation::base::{CFRetain, CFTypeID}; use core_foundation::base::{CFRetain, CFTypeID};
use core_foundation::data::CFData; use core_foundation::data::CFData;
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef}; use color_space::CGColorSpace;
use data_provider::{CGDataProviderRef, CGDataProvider};
use geometry::CGRect;
use libc::size_t; use libc::size_t;
use foreign_types::{ForeignType, ForeignTypeRef};
#[repr(C)] #[repr(C)]
pub enum CGImageAlphaInfo { pub enum CGImageAlphaInfo {
CGImageAlphaNone, /* For example, RGB. */ CGImageAlphaNone, /* For example, RGB. */
CGImageAlphaPremultipliedLast, /* For example, premultiplied RGBA */ CGImageAlphaPremultipliedLast, /* For example, premultiplied RGBA */
CGImageAlphaPremultipliedFirst, /* For example, premultiplied ARGB */ CGImageAlphaPremultipliedFirst, /* For example, premultiplied ARGB */
CGImageAlphaLast, /* For example, non-premultiplied RGBA */ CGImageAlphaLast, /* For example, non-premultiplied RGBA */
CGImageAlphaFirst, /* For example, non-premultiplied ARGB */ CGImageAlphaFirst, /* For example, non-premultiplied ARGB */
CGImageAlphaNoneSkipLast, /* For example, RBGX. */ CGImageAlphaNoneSkipLast, /* For example, RBGX. */
CGImageAlphaNoneSkipFirst, /* For example, XRBG. */ CGImageAlphaNoneSkipFirst, /* For example, XRBG. */
CGImageAlphaOnly, /* No color data, alpha data only */ CGImageAlphaOnly /* No color data, alpha data only */
} }
#[repr(C)] #[repr(C)]
@@ -27,74 +27,83 @@ pub enum CGImageByteOrderInfo {
CGImageByteOrder16Little = 1 << 12, CGImageByteOrder16Little = 1 << 12,
CGImageByteOrder32Little = 2 << 12, CGImageByteOrder32Little = 2 << 12,
CGImageByteOrder16Big = 3 << 12, CGImageByteOrder16Big = 3 << 12,
CGImageByteOrder32Big = 4 << 12, CGImageByteOrder32Big = 4 << 12
} }
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGImage { pub unsafe type CGImage {
type CType = crate::sys::CGImage; type CType = ::sys::CGImage;
fn drop = CGImageRelease; fn drop = CGImageRelease;
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
} }
impl CGImage { impl CGImage {
pub fn new( pub fn new(width: size_t,
width: size_t, height: size_t,
height: size_t, bits_per_component: size_t,
bits_per_component: size_t, bits_per_pixel: size_t,
bits_per_pixel: size_t, bytes_per_row: size_t,
bytes_per_row: size_t, colorspace: &CGColorSpace,
colorspace: &CGColorSpace, bitmap_info: u32,
bitmap_info: u32, provider: &CGDataProvider,
provider: &CGDataProvider, should_interpolate: bool,
should_interpolate: bool, rendering_intent: u32)
rendering_intent: u32, -> Self {
) -> Self {
unsafe { unsafe {
let result = CGImageCreate( let result = CGImageCreate(width,
width, height,
height, bits_per_component,
bits_per_component, bits_per_pixel,
bits_per_pixel, bytes_per_row,
bytes_per_row, colorspace.as_ptr(),
colorspace.as_ptr(), bitmap_info,
bitmap_info, provider.as_ptr(),
provider.as_ptr(), ptr::null_mut(),
ptr::null_mut(), should_interpolate,
should_interpolate, rendering_intent);
rendering_intent,
);
assert!(!result.is_null()); assert!(!result.is_null());
Self::from_ptr(result) Self::from_ptr(result)
} }
} }
pub fn type_id() -> CFTypeID { pub fn type_id() -> CFTypeID {
unsafe { CGImageGetTypeID() } unsafe {
CGImageGetTypeID()
}
} }
} }
impl CGImageRef { impl CGImageRef {
pub fn width(&self) -> size_t { pub fn width(&self) -> size_t {
unsafe { CGImageGetWidth(self.as_ptr()) } unsafe {
CGImageGetWidth(self.as_ptr())
}
} }
pub fn height(&self) -> size_t { pub fn height(&self) -> size_t {
unsafe { CGImageGetHeight(self.as_ptr()) } unsafe {
CGImageGetHeight(self.as_ptr())
}
} }
pub fn bits_per_component(&self) -> size_t { pub fn bits_per_component(&self) -> size_t {
unsafe { CGImageGetBitsPerComponent(self.as_ptr()) } unsafe {
CGImageGetBitsPerComponent(self.as_ptr())
}
} }
pub fn bits_per_pixel(&self) -> size_t { pub fn bits_per_pixel(&self) -> size_t {
unsafe { CGImageGetBitsPerPixel(self.as_ptr()) } unsafe {
CGImageGetBitsPerPixel(self.as_ptr())
}
} }
pub fn bytes_per_row(&self) -> size_t { pub fn bytes_per_row(&self) -> size_t {
unsafe { CGImageGetBytesPerRow(self.as_ptr()) } unsafe {
CGImageGetBytesPerRow(self.as_ptr())
}
} }
pub fn color_space(&self) -> CGColorSpace { pub fn color_space(&self) -> CGColorSpace {
@@ -108,8 +117,9 @@ impl CGImageRef {
/// Returns the raw image bytes wrapped in `CFData`. Note, the returned `CFData` owns the /// Returns the raw image bytes wrapped in `CFData`. Note, the returned `CFData` owns the
/// underlying buffer. /// underlying buffer.
pub fn data(&self) -> CFData { pub fn data(&self) -> CFData {
let data_provider = let data_provider = unsafe {
unsafe { CGDataProviderRef::from_ptr(CGImageGetDataProvider(self.as_ptr())) }; CGDataProviderRef::from_ptr(CGImageGetDataProvider(self.as_ptr()))
};
data_provider.copy_data() data_provider.copy_data()
} }
@@ -125,34 +135,30 @@ impl CGImageRef {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
fn CGImageGetTypeID() -> CFTypeID; fn CGImageGetTypeID() -> CFTypeID;
fn CGImageGetWidth(image: crate::sys::CGImageRef) -> size_t; fn CGImageGetWidth(image: ::sys::CGImageRef) -> size_t;
fn CGImageGetHeight(image: crate::sys::CGImageRef) -> size_t; fn CGImageGetHeight(image: ::sys::CGImageRef) -> size_t;
fn CGImageGetBitsPerComponent(image: crate::sys::CGImageRef) -> size_t; fn CGImageGetBitsPerComponent(image: ::sys::CGImageRef) -> size_t;
fn CGImageGetBitsPerPixel(image: crate::sys::CGImageRef) -> size_t; fn CGImageGetBitsPerPixel(image: ::sys::CGImageRef) -> size_t;
fn CGImageGetBytesPerRow(image: crate::sys::CGImageRef) -> size_t; fn CGImageGetBytesPerRow(image: ::sys::CGImageRef) -> size_t;
fn CGImageGetColorSpace(image: crate::sys::CGImageRef) -> crate::sys::CGColorSpaceRef; fn CGImageGetColorSpace(image: ::sys::CGImageRef) -> ::sys::CGColorSpaceRef;
fn CGImageGetDataProvider(image: crate::sys::CGImageRef) -> crate::sys::CGDataProviderRef; fn CGImageGetDataProvider(image: ::sys::CGImageRef) -> ::sys::CGDataProviderRef;
fn CGImageRelease(image: crate::sys::CGImageRef); fn CGImageRelease(image: ::sys::CGImageRef);
fn CGImageCreate( fn CGImageCreate(width: size_t,
width: size_t, height: size_t,
height: size_t, bitsPerComponent: size_t,
bitsPerComponent: size_t, bitsPerPixel: size_t,
bitsPerPixel: size_t, bytesPerRow: size_t,
bytesPerRow: size_t, space: ::sys::CGColorSpaceRef,
space: crate::sys::CGColorSpaceRef, bitmapInfo: u32,
bitmapInfo: u32, provider: ::sys::CGDataProviderRef,
provider: crate::sys::CGDataProviderRef, decode: *const CGFloat,
decode: *const CGFloat, shouldInterpolate: bool,
shouldInterpolate: bool, intent: u32)
intent: u32, -> ::sys::CGImageRef;
) -> crate::sys::CGImageRef; fn CGImageCreateWithImageInRect(image: ::sys::CGImageRef, rect: CGRect) -> ::sys::CGImageRef;
fn CGImageCreateWithImageInRect(
image: crate::sys::CGImageRef,
rect: CGRect,
) -> crate::sys::CGImageRef;
//fn CGImageGetAlphaInfo(image: ::sys::CGImageRef) -> CGImageAlphaInfo; //fn CGImageGetAlphaInfo(image: ::sys::CGImageRef) -> CGImageAlphaInfo;
//fn CGImageCreateCopyWithColorSpace(image: ::sys::CGImageRef, space: ::sys::CGColorSpaceRef) -> ::sys::CGImageRef //fn CGImageCreateCopyWithColorSpace(image: ::sys::CGImageRef, space: ::sys::CGColorSpaceRef) -> ::sys::CGImageRef

View File

@@ -7,8 +7,19 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#[cfg(target_os = "macos")] extern crate libc;
pub mod access;
#[macro_use]
extern crate core_foundation;
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate foreign_types;
extern crate core_graphics_types;
pub mod base; pub mod base;
pub mod color; pub mod color;
pub mod color_space; pub mod color_space;
@@ -23,10 +34,12 @@ pub mod event_source;
pub mod font; pub mod font;
pub mod geometry; pub mod geometry;
pub mod gradient; pub mod gradient;
pub mod image;
pub mod path;
#[cfg(target_os = "macos")]
pub mod private;
pub mod sys;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub mod window; pub mod window;
#[cfg(target_os = "macos")]
pub mod private;
pub mod image;
pub mod path;
pub mod sys;
#[cfg(target_os = "macos")]
pub mod access;

View File

@@ -7,11 +7,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
pub use crate::sys::CGPathRef as SysCGPathRef; pub use sys::CGPathRef as SysCGPathRef;
use crate::geometry::{CGAffineTransform, CGPoint, CGRect};
use core_foundation::base::{CFRelease, CFRetain, CFTypeID}; use core_foundation::base::{CFRelease, CFRetain, CFTypeID};
use foreign_types::{foreign_type, ForeignType}; use foreign_types::ForeignType;
use geometry::{CGAffineTransform, CGPoint, CGRect};
use libc::c_void; use libc::c_void;
use std::fmt::{self, Debug, Formatter}; use std::fmt::{self, Debug, Formatter};
use std::marker::PhantomData; use std::marker::PhantomData;
@@ -22,7 +22,7 @@ use std::slice;
foreign_type! { foreign_type! {
#[doc(hidden)] #[doc(hidden)]
pub unsafe type CGPath { pub unsafe type CGPath {
type CType = crate::sys::CGPath; type CType = ::sys::CGPath;
fn drop = |p| CFRelease(p as *mut _); fn drop = |p| CFRelease(p as *mut _);
fn clone = |p| CFRetain(p as *const _) as *mut _; fn clone = |p| CFRetain(p as *const _) as *mut _;
} }
@@ -40,25 +40,18 @@ impl CGPath {
} }
pub fn type_id() -> CFTypeID { pub fn type_id() -> CFTypeID {
unsafe { CGPathGetTypeID() } unsafe {
CGPathGetTypeID()
}
} }
pub fn apply<'a, F>(&'a self, mut closure: &'a F) pub fn apply<'a, F>(&'a self, mut closure: &'a F) where F: FnMut(CGPathElementRef<'a>) {
where
F: FnMut(CGPathElementRef<'a>),
{
unsafe { unsafe {
CGPathApply( CGPathApply(self.as_ptr(), &mut closure as *mut _ as *mut c_void, do_apply::<F>);
self.as_ptr(),
&mut closure as *mut _ as *mut c_void,
do_apply::<F>,
);
} }
unsafe extern "C" fn do_apply<'a, F>(info: *mut c_void, element: *const CGPathElement) unsafe extern "C" fn do_apply<'a, F>(info: *mut c_void, element: *const CGPathElement)
where where F: FnMut(CGPathElementRef<'a>) {
F: FnMut(CGPathElementRef<'a>),
{
let closure = info as *mut *mut F; let closure = info as *mut *mut F;
(**closure)(CGPathElementRef::new(element)) (**closure)(CGPathElementRef::new(element))
} }
@@ -83,7 +76,7 @@ pub struct CGPathElementRef<'a> {
impl<'a> CGPathElementRef<'a> { impl<'a> CGPathElementRef<'a> {
fn new<'b>(element: *const CGPathElement) -> CGPathElementRef<'b> { fn new<'b>(element: *const CGPathElement) -> CGPathElementRef<'b> {
CGPathElementRef { CGPathElementRef {
element, element: element,
phantom: PhantomData, phantom: PhantomData,
} }
} }
@@ -92,7 +85,9 @@ impl<'a> CGPathElementRef<'a> {
impl<'a> Deref for CGPathElementRef<'a> { impl<'a> Deref for CGPathElementRef<'a> {
type Target = CGPathElement; type Target = CGPathElement;
fn deref(&self) -> &CGPathElement { fn deref(&self) -> &CGPathElement {
unsafe { &*self.element } unsafe {
&*self.element
}
} }
} }
@@ -123,14 +118,12 @@ impl CGPathElement {
} }
} }
type CGPathApplierFunction = unsafe extern "C" fn(info: *mut c_void, element: *const CGPathElement); type CGPathApplierFunction = unsafe extern "C" fn(info: *mut c_void,
element: *const CGPathElement);
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
fn CGPathCreateWithRect( fn CGPathCreateWithRect(rect: CGRect, transform: *const CGAffineTransform) -> ::sys::CGPathRef;
rect: CGRect, fn CGPathApply(path: ::sys::CGPathRef, info: *mut c_void, function: CGPathApplierFunction);
transform: *const CGAffineTransform,
) -> crate::sys::CGPathRef;
fn CGPathApply(path: crate::sys::CGPathRef, info: *mut c_void, function: CGPathApplierFunction);
fn CGPathGetTypeID() -> CFTypeID; fn CGPathGetTypeID() -> CFTypeID;
} }

View File

@@ -11,7 +11,7 @@
//! //!
//! These are liable to change at any time. Use with caution! //! These are liable to change at any time. Use with caution!
use crate::geometry::CGRect; use geometry::CGRect;
use libc::{c_int, c_uint}; use libc::{c_int, c_uint};
use std::ptr; use std::ptr;
@@ -21,7 +21,9 @@ pub struct CGSRegion {
impl Drop for CGSRegion { impl Drop for CGSRegion {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ffi::CGSRegionRelease(self.region) } unsafe {
ffi::CGSRegionRelease(self.region)
}
} }
} }
@@ -31,7 +33,9 @@ impl CGSRegion {
unsafe { unsafe {
let mut region = ptr::null_mut(); let mut region = ptr::null_mut();
assert!(ffi::CGSNewRegionWithRect(rect, &mut region) == 0); assert!(ffi::CGSNewRegionWithRect(rect, &mut region) == 0);
CGSRegion { region } CGSRegion {
region: region,
}
} }
} }
@@ -39,11 +43,12 @@ impl CGSRegion {
pub fn from_rects(rects: &[CGRect]) -> CGSRegion { pub fn from_rects(rects: &[CGRect]) -> CGSRegion {
unsafe { unsafe {
let mut region = ptr::null_mut(); let mut region = ptr::null_mut();
assert!( assert!(ffi::CGSNewRegionWithRectList(rects.as_ptr(),
ffi::CGSNewRegionWithRectList(rects.as_ptr(), rects.len() as c_uint, &mut region) rects.len() as c_uint,
== 0 &mut region) == 0);
); CGSRegion {
CGSRegion { region } region: region,
}
} }
} }
} }
@@ -59,9 +64,9 @@ impl CGSSurface {
#[inline] #[inline]
pub fn from_ids(context_id: c_uint, window_number: c_int, surface_id: c_uint) -> CGSSurface { pub fn from_ids(context_id: c_uint, window_number: c_int, surface_id: c_uint) -> CGSSurface {
CGSSurface { CGSSurface {
context_id, context_id: context_id,
window_number, window_number: window_number,
surface_id, surface_id: surface_id,
} }
} }
@@ -73,20 +78,16 @@ impl CGSSurface {
#[inline] #[inline]
pub fn set_shape(&self, region: &CGSRegion) { pub fn set_shape(&self, region: &CGSRegion) {
unsafe { unsafe {
assert!( assert!(ffi::CGSSetSurfaceShape(self.context_id,
ffi::CGSSetSurfaceShape( self.window_number,
self.context_id, self.surface_id,
self.window_number, region.region) == 0)
self.surface_id,
region.region
) == 0
)
} }
} }
} }
mod ffi { mod ffi {
use crate::geometry::CGRect; use geometry::CGRect;
use libc::{c_int, c_uint}; use libc::{c_int, c_uint};
// This is an enum so that we can't easily make instances of this opaque type. // This is an enum so that we can't easily make instances of this opaque type.
@@ -96,21 +97,20 @@ mod ffi {
pub type CGSRegionRef = *mut CGSRegionObject; pub type CGSRegionRef = *mut CGSRegionObject;
pub type OSStatus = i32; pub type OSStatus = i32;
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
pub fn CGSRegionRelease(region: CGSRegionRef); pub fn CGSRegionRelease(region: CGSRegionRef);
pub fn CGSNewRegionWithRect(rect: *const CGRect, outRegion: *mut CGSRegionRef) -> CGError; pub fn CGSNewRegionWithRect(rect: *const CGRect, outRegion: *mut CGSRegionRef) -> CGError;
pub fn CGSNewRegionWithRectList( pub fn CGSNewRegionWithRectList(rects: *const CGRect,
rects: *const CGRect, rectCount: c_uint,
rectCount: c_uint, outRegion: *mut CGSRegionRef)
outRegion: *mut CGSRegionRef, -> CGError;
) -> CGError;
pub fn CGSSetSurfaceShape( pub fn CGSSetSurfaceShape(contextID: c_uint,
contextID: c_uint, windowNumber: c_int,
windowNumber: c_int, surfaceID: c_uint,
surfaceID: c_uint, region: CGSRegionRef)
region: CGSRegionRef, -> CGError;
) -> CGError;
} }
} }

View File

@@ -28,16 +28,16 @@ pub type CGGradientRef = *mut CGGradient;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
mod macos { mod macos {
pub enum CGEventTap {} pub enum CGEventTap {}
pub type CGEventTapRef = core_foundation::mach_port::CFMachPortRef; pub type CGEventTapRef = core_foundation::mach_port::CFMachPortRef;
pub enum CGEvent {} pub enum CGEvent {}
pub type CGEventRef = *mut CGEvent; pub type CGEventRef = *mut CGEvent;
pub enum CGEventSource {} pub enum CGEventSource {}
pub type CGEventSourceRef = *mut CGEventSource; pub type CGEventSourceRef = *mut CGEventSource;
pub enum CGDisplayMode {} pub enum CGDisplayMode {}
pub type CGDisplayModeRef = *mut CGDisplayMode; pub type CGDisplayModeRef = *mut CGDisplayMode;
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]

View File

@@ -15,30 +15,29 @@ use core_foundation::dictionary::CFDictionary;
use core_foundation::string::{CFString, CFStringRef}; use core_foundation::string::{CFString, CFStringRef};
use foreign_types::ForeignType; use foreign_types::ForeignType;
use crate::geometry::CGRect; use geometry::CGRect;
use crate::image::CGImage; use image::CGImage;
use crate::sys; use sys;
pub type CGWindowID = u32; pub type CGWindowID = u32;
pub type CGWindowSharingType = u32; pub type CGWindowSharingType = u32;
pub const kCGWindowSharingNone: CGWindowSharingType = 0; pub const kCGWindowSharingNone: CGWindowSharingType = 0;
pub const kCGWindowSharingReadOnly: CGWindowSharingType = 1; pub const kCGWindowSharingReadOnly: CGWindowSharingType = 1;
pub const kCGWindowSharingReadWrite: CGWindowSharingType = 2; pub const kCGWindowSharingReadWrite: CGWindowSharingType = 1;
pub type CGWindowBackingType = u32; pub type CGWindowBackingType = u32;
pub const kCGWindowBackingStoreRetained: CGWindowBackingType = 0; pub const kCGWindowBackingStoreRetained: CGWindowBackingType = 0;
pub const kCGWindowBackingStoreNonretained: CGWindowBackingType = 1; pub const kCGWindowBackingStoreNonretained: CGWindowBackingType = 1;
pub const kCGWindowBackingStoreBuffered: CGWindowBackingType = 2; pub const kCGWindowBackingStoreBuffered: CGWindowBackingType = 2;
// https://developer.apple.com/documentation/coregraphics/quartz_window_services/window_list_option_constants?language=objc
pub type CGWindowListOption = u32; pub type CGWindowListOption = u32;
pub const kCGWindowListOptionAll: CGWindowListOption = 0; pub const kCGWindowListOptionAll: CGWindowListOption = 1 << 0;
pub const kCGWindowListOptionOnScreenOnly: CGWindowListOption = 1 << 0; pub const kCGWindowListOptionOnScreenOnly: CGWindowListOption = 1 << 1;
pub const kCGWindowListOptionOnScreenAboveWindow: CGWindowListOption = 1 << 1; pub const kCGWindowListOptionOnScreenAboveWindow: CGWindowListOption = 1 << 2;
pub const kCGWindowListOptionOnScreenBelowWindow: CGWindowListOption = 1 << 2; pub const kCGWindowListOptionOnScreenBelowWindow: CGWindowListOption = 1 << 3;
pub const kCGWindowListOptionIncludingWindow: CGWindowListOption = 1 << 3; pub const kCGWindowListOptionIncludingWindow: CGWindowListOption = 1 << 4;
pub const kCGWindowListExcludeDesktopElements: CGWindowListOption = 1 << 4; pub const kCGWindowListOptionExcludeDesktopElements: CGWindowListOption = 1 << 5;
pub type CGWindowImageOption = u32; pub type CGWindowImageOption = u32;
pub const kCGWindowImageDefault: CGWindowImageOption = 0; pub const kCGWindowImageDefault: CGWindowImageOption = 0;
@@ -50,10 +49,8 @@ pub const kCGWindowImageNominalResolution: CGWindowImageOption = 1 << 4;
pub const kCGNullWindowID: CGWindowID = 0; pub const kCGNullWindowID: CGWindowID = 0;
pub fn copy_window_info( pub fn copy_window_info(option: CGWindowListOption, relative_to_window: CGWindowID)
option: CGWindowListOption, -> Option<CFArray> {
relative_to_window: CGWindowID,
) -> Option<CFArray> {
unsafe { unsafe {
let array = CGWindowListCopyWindowInfo(option, relative_to_window); let array = CGWindowListCopyWindowInfo(option, relative_to_window);
if array.is_null() { if array.is_null() {
@@ -64,10 +61,8 @@ pub fn copy_window_info(
} }
} }
pub fn create_window_list( pub fn create_window_list(option: CGWindowListOption, relative_to_window: CGWindowID)
option: CGWindowListOption, -> Option<CFArray<CGWindowID>> {
relative_to_window: CGWindowID,
) -> Option<CFArray<CGWindowID>> {
unsafe { unsafe {
let array = CGWindowListCreate(option, relative_to_window); let array = CGWindowListCreate(option, relative_to_window);
if array.is_null() { if array.is_null() {
@@ -78,9 +73,8 @@ pub fn create_window_list(
} }
} }
pub fn create_description_from_array( pub fn create_description_from_array(window_array: CFArray<CGWindowID>) ->
window_array: CFArray<CGWindowID>, Option<CFArray<CFDictionary<CFString, CFType>>> {
) -> Option<CFArray<CFDictionary<CFString, CFType>>> {
unsafe { unsafe {
let array = CGWindowListCreateDescriptionFromArray(window_array.as_concrete_TypeRef()); let array = CGWindowListCreateDescriptionFromArray(window_array.as_concrete_TypeRef());
if array.is_null() { if array.is_null() {
@@ -91,12 +85,11 @@ pub fn create_description_from_array(
} }
} }
pub fn create_image( pub fn create_image(screen_bounds: CGRect,
screen_bounds: CGRect, list_option: CGWindowListOption,
list_option: CGWindowListOption, window_id: CGWindowID,
window_id: CGWindowID, image_option: CGWindowImageOption)
image_option: CGWindowImageOption, -> Option<CGImage> {
) -> Option<CGImage> {
unsafe { unsafe {
let image = CGWindowListCreateImage(screen_bounds, list_option, window_id, image_option); let image = CGWindowListCreateImage(screen_bounds, list_option, window_id, image_option);
if image.is_null() { if image.is_null() {
@@ -107,17 +100,14 @@ pub fn create_image(
} }
} }
pub fn create_image_from_array( pub fn create_image_from_array(screen_bounds: CGRect,
screen_bounds: CGRect, window_array: CFArray,
window_array: CFArray, image_option: CGWindowImageOption)
image_option: CGWindowImageOption, -> Option<CGImage> {
) -> Option<CGImage> {
unsafe { unsafe {
let image = CGWindowListCreateImageFromArray( let image = CGWindowListCreateImageFromArray(screen_bounds,
screen_bounds, window_array.as_concrete_TypeRef(),
window_array.as_concrete_TypeRef(), image_option);
image_option,
);
if image.is_null() { if image.is_null() {
None None
} else { } else {
@@ -126,8 +116,8 @@ pub fn create_image_from_array(
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] #[link(name = "CoreGraphics", kind = "framework")]
extern "C" { extern {
pub static kCGWindowNumber: CFStringRef; pub static kCGWindowNumber: CFStringRef;
pub static kCGWindowStoreType: CFStringRef; pub static kCGWindowStoreType: CFStringRef;
pub static kCGWindowLayer: CFStringRef; pub static kCGWindowLayer: CFStringRef;
@@ -142,24 +132,18 @@ extern "C" {
pub static kCGWindowIsOnscreen: CFStringRef; pub static kCGWindowIsOnscreen: CFStringRef;
pub static kCGWindowBackingLocationVideoMemory: CFStringRef; pub static kCGWindowBackingLocationVideoMemory: CFStringRef;
pub fn CGWindowListCopyWindowInfo( pub fn CGWindowListCopyWindowInfo(option: CGWindowListOption, relativeToWindow: CGWindowID)
option: CGWindowListOption, -> CFArrayRef;
relativeToWindow: CGWindowID, pub fn CGWindowListCreate(option: CGWindowListOption, relativeToWindow: CGWindowID)
) -> CFArrayRef; -> CFArrayRef;
pub fn CGWindowListCreate(
option: CGWindowListOption,
relativeToWindow: CGWindowID,
) -> CFArrayRef;
pub fn CGWindowListCreateDescriptionFromArray(windowArray: CFArrayRef) -> CFArrayRef; pub fn CGWindowListCreateDescriptionFromArray(windowArray: CFArrayRef) -> CFArrayRef;
pub fn CGWindowListCreateImage( pub fn CGWindowListCreateImage(screenBounds: CGRect,
screenBounds: CGRect, listOption: CGWindowListOption,
listOption: CGWindowListOption, windowID: CGWindowID,
windowID: CGWindowID, imageOption: CGWindowImageOption)
imageOption: CGWindowImageOption, -> *mut sys::CGImage;
) -> *mut sys::CGImage; pub fn CGWindowListCreateImageFromArray(screenBounds: CGRect,
pub fn CGWindowListCreateImageFromArray( windowArray: CFArrayRef,
screenBounds: CGRect, imageOption: CGWindowImageOption)
windowArray: CFArrayRef, -> *mut sys::CGImage;
imageOption: CGWindowImageOption,
) -> *mut sys::CGImage;
} }

View File

@@ -1 +1 @@
{"files":{"COPYRIGHT":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"fa829578940a22ac0df6aeb8b4efad23f826404b4ebe05da76cf196d9ad56611","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","README.md":"3fc3f13cfbe371c6e167aefc25a3d4b9fdc5fff933225b7a47a208e6a70ebe8b","src/font.rs":"ef2db0955e8b39875239bb12138547ff8871fe8dc3c8342edbc518e84aa51f86","src/font_collection.rs":"63eff5e987f05d844b79073b0f38d55e2501015b6db23407616d34ac6738fe76","src/font_descriptor.rs":"55e64b36a79899df07864e7db10b90a115c23d3edf0f71e0eb7eddd89cebf405","src/font_manager.rs":"f936404cfa76fb4e467b3233e328a50a2068ae2370407245b62528cb4b948bb1","src/frame.rs":"e3550b1cd897d71122e475e351060f64a46432b4789eb9c1dab9cd5b2661e399","src/framesetter.rs":"27e78ef764dd91a803f80c153d76e119a2ed76420511ab54d10a6e8577689dbf","src/lib.rs":"6ce6b1126fafe46f2317939804ba0a5d564d124914d34c4bf32dfdd5c354b61d","src/line.rs":"9f1921d39a1100d43f1fcc421749cabc69135a1205e5005307595ea35a81f3d8","src/run.rs":"7060fc8105fe0a862ad2788f5f352292b9f5e18c9bbf02f03843974e8bf22d1e","src/string_attributes.rs":"398ccc9fcf6238bc9a88f33bb52237a458f0d7149b9688cfee8957775768a6ff"},"package":"a593227b66cbd4007b2a050dfdd9e1d1318311409c8d600dc82ba1b15ca9c130"} {"files":{"COPYRIGHT":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"4d4220f78f2823ddc045b0664ac88627bbe3d3bd3dac79539b96c193aa5bfbbc","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","README.md":"98d25015857a430aac32f34bdc979a1a66e672a0ea42c5f92dd9cfe23c1fccfd","src/font.rs":"67acc8a7a9329e7b59d7addccf8d32cb705587573ac4d736df10714b590a7d82","src/font_collection.rs":"2bd992032aa1dda4042c8e28974a5708a7ddcd60f3fbd1d58499c1e7b54ae615","src/font_descriptor.rs":"df229425f3f425af441cb51c4fcd4b8eb7f758bbe34bd2437f0bf56dff7d42c9","src/font_manager.rs":"f936404cfa76fb4e467b3233e328a50a2068ae2370407245b62528cb4b948bb1","src/frame.rs":"1fb9434eab2460abc5d882e8ff228a6376b2557fc6c2483a41e0a3495724ca02","src/framesetter.rs":"13e34b4111cee5f023aa05e2220d2a6f102e96fd18c51a356992bffd6c9fc7c1","src/lib.rs":"eeb19facf14bb50870c2481bc370d7e008d5755e7d5cbc10de7891ceab28db2e","src/line.rs":"592a5eb6b5d14f3e4cceb449ee935a4385ce364988f23c483a8c36dd02be4e34","src/run.rs":"fd3838ea31da8fd71a33b256aa397192d96094b457489dc6c91ac190130727c8","src/string_attributes.rs":"398ccc9fcf6238bc9a88f33bb52237a458f0d7149b9688cfee8957775768a6ff"},"package":"c9d2790b5c08465d49f8dc05c8bcae9fea467855947db39b0f8145c091aaced5"}

View File

@@ -10,15 +10,9 @@
# See Cargo.toml.orig for the original contents. # See Cargo.toml.orig for the original contents.
[package] [package]
edition = "2018"
name = "core-text" name = "core-text"
version = "21.0.0" version = "20.1.0"
authors = ["The Servo Project Developers"] authors = ["The Servo Project Developers"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Bindings to the Core Text framework." description = "Bindings to the Core Text framework."
readme = "README.md" readme = "README.md"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
@@ -28,17 +22,11 @@ repository = "https://github.com/servo/core-foundation-rs"
all-features = true all-features = true
default-target = "x86_64-apple-darwin" default-target = "x86_64-apple-darwin"
[lib]
name = "core_text"
path = "src/lib.rs"
[dependencies.core-foundation] [dependencies.core-foundation]
version = "0.10" version = "0.9"
default-features = false
[dependencies.core-graphics] [dependencies.core-graphics]
version = "0.24" version = "0.23.0"
default-features = false
[dependencies.foreign-types] [dependencies.foreign-types]
version = "0.5" version = "0.5"
@@ -47,12 +35,5 @@ version = "0.5"
version = "0.2" version = "0.2"
[features] [features]
default = [ default = ["mountainlion"]
"mountainlion",
"link",
]
link = [
"core-foundation/link",
"core-graphics/link",
]
mountainlion = [] mountainlion = []

View File

@@ -1 +1,3 @@
# core-text-rs # core-text-rs
[![Build Status](https://travis-ci.com/servo/core-text-rs.svg?branch=master)](https://travis-ci.com/servo/core-text-rs)

View File

@@ -9,12 +9,10 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use crate::font_descriptor; use font_descriptor;
use crate::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation};
use crate::font_descriptor::{ use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors};
CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors, use font_manager::create_font_descriptor;
};
use crate::font_manager::create_font_descriptor;
use core_foundation::array::{CFArray, CFArrayRef}; use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::base::{CFIndex, CFOptionFlags, CFType, CFTypeID, CFTypeRef, TCFType}; use core_foundation::base::{CFIndex, CFOptionFlags, CFType, CFTypeID, CFTypeRef, TCFType};
@@ -23,7 +21,6 @@ use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use core_foundation::number::CFNumber; use core_foundation::number::CFNumber;
use core_foundation::string::{CFString, CFStringRef, UniChar}; use core_foundation::string::{CFString, CFStringRef, UniChar};
use core_foundation::url::{CFURLRef, CFURL}; use core_foundation::url::{CFURLRef, CFURL};
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use core_graphics::base::CGFloat; use core_graphics::base::CGFloat;
use core_graphics::context::CGContext; use core_graphics::context::CGContext;
use core_graphics::font::{CGFont, CGGlyph}; use core_graphics::font::{CGFont, CGGlyph};
@@ -495,10 +492,6 @@ impl CTFont {
} }
} }
pub fn get_matrix(&self) -> CGAffineTransform {
unsafe { CTFontGetMatrix(self.as_concrete_TypeRef()) }
}
pub fn url(&self) -> Option<CFURL> { pub fn url(&self) -> Option<CFURL> {
unsafe { unsafe {
let result = CTFontCopyAttribute(self.0, kCTFontURLAttribute); let result = CTFontCopyAttribute(self.0, kCTFontURLAttribute);
@@ -601,7 +594,7 @@ pub fn cascade_list_for_languages(
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] #[link(name = "CoreText", kind = "framework")]
extern "C" { extern "C" {
/* /*
* CTFont.h * CTFont.h
@@ -697,7 +690,7 @@ extern "C" {
fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef; fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef;
fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef; fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef;
fn CTFontGetSize(font: CTFontRef) -> CGFloat; fn CTFontGetSize(font: CTFontRef) -> CGFloat;
fn CTFontGetMatrix(font: CTFontRef) -> CGAffineTransform; //fn CTFontGetMatrix
fn CTFontGetSymbolicTraits(font: CTFontRef) -> CTFontSymbolicTraits; fn CTFontGetSymbolicTraits(font: CTFontRef) -> CTFontSymbolicTraits;
fn CTFontCopyTraits(font: CTFontRef) -> CFDictionaryRef; fn CTFontCopyTraits(font: CTFontRef) -> CFDictionaryRef;
@@ -884,7 +877,7 @@ fn copy_system_font() {
let ps = small.postscript_name(); let ps = small.postscript_name();
let desc = small.copy_descriptor(); let desc = small.copy_descriptor();
// check that we can construct a new version by descriptor // check that we can construct a new vesion by descriptor
let ctfont = new_from_descriptor(&desc, 20.); let ctfont = new_from_descriptor(&desc, 20.);
assert_eq!(big.postscript_name(), ctfont.postscript_name()); assert_eq!(big.postscript_name(), ctfont.postscript_name());
@@ -945,13 +938,11 @@ fn copy_system_font() {
#[test] #[test]
fn out_of_range_variations() { fn out_of_range_variations() {
use crate::*; use crate::*;
use core_foundation::base::ItemRef;
let small = new_ui_font_for_language(kCTFontSystemDetailFontType, 19., None); let small = new_ui_font_for_language(kCTFontSystemDetailFontType, 19., None);
let axes = small.get_variation_axes(); let axes = small.get_variation_axes();
let version = dbg!(macos_version()); if macos_version() < (10, 12, 0) {
if version < (10, 12, 0) {
assert!(axes.is_none()); assert!(axes.is_none());
return; return;
} }
@@ -987,25 +978,10 @@ fn out_of_range_variations() {
let var_desc = variation_font.copy_descriptor(); let var_desc = variation_font.copy_descriptor();
let var_attrs = var_desc.attributes(); let var_attrs = var_desc.attributes();
dbg!(&var_attrs); dbg!(&var_attrs);
// attributes greater than max are dropped on macOS <= 11
// Handling of attributes greater than max changed between versions // on macOS 12 they seem to be preserved as is.
let var_attrs = var_attrs.find(variation_attribute); let var_attrs = var_attrs.find(variation_attribute);
if version >= (14, 0, 0) { if macos_version() >= (12, 0, 0) && macos_version() < (13, 0, 0) {
check_attrs(0., var_attrs, axes);
} else if version >= (12, 0, 0) && version < (13, 0, 0) {
check_attrs(1., var_attrs, axes);
} else if version >= (10, 15, 0) {
assert!(var_attrs.is_none());
} else {
let var_attrs = var_attrs.unwrap().downcast::<CFDictionary>().unwrap();
assert!(var_attrs.is_empty());
}
fn check_attrs(
clamp_diff: f64,
var_attrs: Option<ItemRef<'_, CFType>>,
axes: CFArray<CFDictionary<CFString, CFType>>,
) {
let var_attrs = var_attrs.unwrap().downcast::<CFDictionary>().unwrap(); let var_attrs = var_attrs.unwrap().downcast::<CFDictionary>().unwrap();
assert!(!var_attrs.is_empty()); assert!(!var_attrs.is_empty());
let var_attrs: CFDictionary<CFType, CFType> = unsafe { std::mem::transmute(var_attrs) }; let var_attrs: CFDictionary<CFType, CFType> = unsafe { std::mem::transmute(var_attrs) };
@@ -1028,14 +1004,13 @@ fn out_of_range_variations() {
.unwrap() .unwrap()
.to_f64() .to_f64()
.unwrap(); .unwrap();
assert_eq!(val, max + 1.);
let expected = max + clamp_diff;
assert_eq!(
val, expected,
"axis {:?} = {:?} (expected {:?})",
tag, val, expected
);
} }
} else if macos_version() >= (10, 15, 0) {
assert!(var_attrs.is_none());
} else {
let var_attrs = var_attrs.unwrap().downcast::<CFDictionary>().unwrap();
assert!(var_attrs.is_empty());
} }
} }

View File

@@ -7,9 +7,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::font_descriptor; use font_descriptor;
use crate::font_descriptor::{CTFontDescriptor, CTFontDescriptorCreateMatchingFontDescriptors}; use font_descriptor::{CTFontDescriptor, CTFontDescriptorCreateMatchingFontDescriptors};
use crate::font_manager::{ use font_manager::{
CTFontManagerCopyAvailableFontFamilyNames, CTFontManagerCopyAvailablePostScriptNames, CTFontManagerCopyAvailableFontFamilyNames, CTFontManagerCopyAvailablePostScriptNames,
}; };
@@ -19,7 +19,6 @@ use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use core_foundation::number::CFNumber; use core_foundation::number::CFNumber;
use core_foundation::set::CFSet; use core_foundation::set::CFSet;
use core_foundation::string::{CFString, CFStringRef}; use core_foundation::string::{CFString, CFStringRef};
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use std::os::raw::c_void; use std::os::raw::c_void;
@@ -79,7 +78,7 @@ pub fn create_for_all_families() -> CTFontCollection {
} }
pub fn create_for_family(family: &str) -> Option<CTFontCollection> { pub fn create_for_family(family: &str) -> Option<CTFontCollection> {
use crate::font_descriptor::kCTFontFamilyNameAttribute; use font_descriptor::kCTFontFamilyNameAttribute;
unsafe { unsafe {
let family_attr = CFString::wrap_under_get_rule(kCTFontFamilyNameAttribute); let family_attr = CFString::wrap_under_get_rule(kCTFontFamilyNameAttribute);

View File

@@ -16,7 +16,6 @@ use core_foundation::number::{CFNumber, CFNumberRef};
use core_foundation::set::CFSetRef; use core_foundation::set::CFSetRef;
use core_foundation::string::{CFString, CFStringRef}; use core_foundation::string::{CFString, CFStringRef};
use core_foundation::url::{CFURLRef, CFURL}; use core_foundation::url::{CFURLRef, CFURL};
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use core_graphics::base::CGFloat; use core_graphics::base::CGFloat;
use std::os::raw::c_void; use std::os::raw::c_void;

View File

@@ -10,7 +10,6 @@
use crate::line::CTLine; use crate::line::CTLine;
use core_foundation::array::{CFArray, CFArrayRef}; use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::base::{CFRange, CFTypeID, TCFType}; use core_foundation::base::{CFRange, CFTypeID, TCFType};
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use core_graphics::context::{CGContext, CGContextRef}; use core_graphics::context::{CGContext, CGContextRef};
use core_graphics::geometry::CGPoint; use core_graphics::geometry::CGPoint;
use core_graphics::path::{CGPath, SysCGPathRef}; use core_graphics::path::{CGPath, SysCGPathRef};
@@ -85,7 +84,7 @@ impl CTFrame {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] #[link(name = "CoreText", kind = "framework")]
extern "C" { extern "C" {
fn CTFrameGetTypeID() -> CFTypeID; fn CTFrameGetTypeID() -> CFTypeID;
fn CTFrameGetLines(frame: CTFrameRef) -> CFArrayRef; fn CTFrameGetLines(frame: CTFrameRef) -> CFArrayRef;

View File

@@ -11,7 +11,6 @@ use super::frame::{CTFrame, CTFrameRef};
use core_foundation::attributed_string::CFAttributedStringRef; use core_foundation::attributed_string::CFAttributedStringRef;
use core_foundation::base::{CFRange, CFTypeID, TCFType}; use core_foundation::base::{CFRange, CFTypeID, TCFType};
use core_foundation::dictionary::CFDictionaryRef; use core_foundation::dictionary::CFDictionaryRef;
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use core_graphics::geometry::CGSize; use core_graphics::geometry::CGSize;
use core_graphics::path::{CGPath, CGPathRef}; use core_graphics::path::{CGPath, CGPathRef};
use foreign_types::{ForeignType, ForeignTypeRef}; use foreign_types::{ForeignType, ForeignTypeRef};
@@ -75,7 +74,7 @@ impl CTFramesetter {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] #[link(name = "CoreText", kind = "framework")]
extern "C" { extern "C" {
fn CTFramesetterGetTypeID() -> CFTypeID; fn CTFramesetterGetTypeID() -> CFTypeID;
fn CTFramesetterCreateWithAttributedString(string: CFAttributedStringRef) -> CTFramesetterRef; fn CTFramesetterCreateWithAttributedString(string: CFAttributedStringRef) -> CTFramesetterRef;

View File

@@ -16,6 +16,13 @@ Many of these functions will add objects to the autorelease pool.
If you don't have one this will cause leaks. If you don't have one this will cause leaks.
*/ */
extern crate foreign_types;
extern crate libc;
#[macro_use]
extern crate core_foundation;
extern crate core_graphics;
pub mod font; pub mod font;
pub mod font_collection; pub mod font_collection;
pub mod font_descriptor; pub mod font_descriptor;

View File

@@ -7,15 +7,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::run::CTRun;
use core_foundation::array::{CFArray, CFArrayRef}; use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::attributed_string::CFAttributedStringRef; use core_foundation::attributed_string::CFAttributedStringRef;
use core_foundation::base::{CFIndex, CFRange, CFTypeID, TCFType}; use core_foundation::base::{CFIndex, CFRange, CFTypeID, TCFType};
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use core_graphics::base::CGFloat; use core_graphics::base::CGFloat;
use core_graphics::context::CGContext; use core_graphics::context::CGContext;
use core_graphics::geometry::{CGPoint, CGRect}; use core_graphics::geometry::{CGPoint, CGRect};
use foreign_types::ForeignType; use foreign_types::ForeignType;
use run::CTRun;
use std::os::raw::c_void; use std::os::raw::c_void;
#[repr(C)] #[repr(C)]
@@ -92,7 +91,7 @@ impl CTLine {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] #[link(name = "CoreText", kind = "framework")]
extern "C" { extern "C" {
fn CTLineGetTypeID() -> CFTypeID; fn CTLineGetTypeID() -> CFTypeID;
fn CTLineGetGlyphRuns(line: CTLineRef) -> CFArrayRef; fn CTLineGetGlyphRuns(line: CTLineRef) -> CFArrayRef;

View File

@@ -10,16 +10,12 @@
use core_foundation::base::{CFIndex, CFRange, CFType, CFTypeID, TCFType}; use core_foundation::base::{CFIndex, CFRange, CFType, CFTypeID, TCFType};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use core_foundation::string::CFString; use core_foundation::string::CFString;
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use core_graphics::base::CGFloat;
use core_graphics::font::CGGlyph; use core_graphics::font::CGGlyph;
use core_graphics::geometry::CGPoint; use core_graphics::geometry::CGPoint;
use std::borrow::Cow; use std::borrow::Cow;
use std::os::raw::c_void; use std::os::raw::c_void;
use std::slice; use std::slice;
use crate::line::TypographicBounds;
#[repr(C)] #[repr(C)]
pub struct __CTRun(c_void); pub struct __CTRun(c_void);
@@ -85,34 +81,6 @@ impl CTRun {
} }
} }
pub fn get_typographic_bounds(&self) -> TypographicBounds {
let mut ascent = 0.0;
let mut descent = 0.0;
let mut leading = 0.0;
unsafe {
// The portion of the run to calculate the typographic bounds for. By setting this to 0,
// CoreText will measure the bounds from start to end, see https://developer.apple.com/documentation/coretext/1510569-ctrungettypographicbounds?language=objc.
let range = CFRange {
location: 0,
length: 0,
};
let width = CTRunGetTypographicBounds(
self.as_concrete_TypeRef(),
range,
&mut ascent,
&mut descent,
&mut leading,
);
TypographicBounds {
width,
ascent,
descent,
leading,
}
}
}
pub fn string_indices(&self) -> Cow<[CFIndex]> { pub fn string_indices(&self) -> Cow<[CFIndex]> {
unsafe { unsafe {
// CTRunGetStringIndicesPtr can return null under some not understood circumstances. // CTRunGetStringIndicesPtr can return null under some not understood circumstances.
@@ -136,10 +104,10 @@ impl CTRun {
#[test] #[test]
fn create_runs() { fn create_runs() {
use crate::font;
use crate::line::*;
use crate::string_attributes::*;
use core_foundation::attributed_string::CFMutableAttributedString; use core_foundation::attributed_string::CFMutableAttributedString;
use font;
use line::*;
use string_attributes::*;
let mut string = CFMutableAttributedString::new(); let mut string = CFMutableAttributedString::new();
string.replace_str(&CFString::new("Food"), CFRange::init(0, 0)); string.replace_str(&CFString::new("Food"), CFRange::init(0, 0));
let len = string.char_len(); let len = string.char_len();
@@ -177,7 +145,7 @@ fn create_runs() {
} }
} }
#[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] #[link(name = "CoreText", kind = "framework")]
extern "C" { extern "C" {
fn CTRunGetTypeID() -> CFTypeID; fn CTRunGetTypeID() -> CFTypeID;
fn CTRunGetAttributes(run: CTRunRef) -> CFDictionaryRef; fn CTRunGetAttributes(run: CTRunRef) -> CFDictionaryRef;
@@ -188,11 +156,4 @@ extern "C" {
fn CTRunGetStringIndices(run: CTRunRef, range: CFRange, buffer: *const CFIndex); fn CTRunGetStringIndices(run: CTRunRef, range: CFRange, buffer: *const CFIndex);
fn CTRunGetGlyphsPtr(run: CTRunRef) -> *const CGGlyph; fn CTRunGetGlyphsPtr(run: CTRunRef) -> *const CGGlyph;
fn CTRunGetGlyphs(run: CTRunRef, range: CFRange, buffer: *const CGGlyph); fn CTRunGetGlyphs(run: CTRunRef, range: CFRange, buffer: *const CGGlyph);
fn CTRunGetTypographicBounds(
line: CTRunRef,
range: CFRange,
ascent: *mut CGFloat,
descent: *mut CGFloat,
leading: *mut CGFloat,
) -> CGFloat;
} }