diff --git a/Cargo.lock b/Cargo.lock index 7052dec4f..97c1bcbd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,11 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "anyhow" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "app_dirs2" version = "2.0.4" @@ -30,46 +35,56 @@ dependencies = [ "xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayref" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "arrayvec" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "atty" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.37" +version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "backtrace-sys" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -85,6 +100,16 @@ name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "blake2b_simd" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "block" version = "0.1.6" @@ -95,7 +120,7 @@ name = "block-buffer" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -103,7 +128,7 @@ dependencies = [ [[package]] name = "block-padding" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -126,26 +151,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "c2-chacha" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cc" -version = "1.0.45" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -153,9 +177,9 @@ name = "chrono" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -181,6 +205,19 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cmake" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cookie" version = "0.12.0" @@ -196,12 +233,12 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "publicsuffix 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "publicsuffix 1.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -213,7 +250,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -222,7 +259,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -243,7 +280,7 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -254,18 +291,18 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "core-text" -version = "13.3.0" +version = "13.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -276,7 +313,7 @@ dependencies = [ "core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -284,28 +321,28 @@ name = "crc32fast" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-deque" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-epoch" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -322,7 +359,17 @@ name = "crossbeam-utils" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -334,6 +381,16 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dtoa" version = "0.4.4" @@ -344,6 +401,16 @@ name = "dunce" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "dwrote" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "either" version = "1.5.3" @@ -354,7 +421,18 @@ name = "encoding_rs" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "enum_dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -362,28 +440,45 @@ name = "error-chain" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "euclid" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "expat-sys" +version = "2.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "failure" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "failure_derive" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -393,20 +488,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "flate2" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz_oxide 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "float-ord" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fnv" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "font-kit" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", + "core-text 13.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "dwrote 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.20.4 (registry+https://github.com/rust-lang/crates.io-index)", + "float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lyon_path 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "servo-fontconfig 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "foreign-types" version = "0.3.2" @@ -425,27 +550,8 @@ name = "freetype" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "freetype-rs" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "freetype-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "freetype-sys" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "servo-freetype-sys 4.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -453,7 +559,7 @@ name = "fs2" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -487,7 +593,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -500,11 +606,11 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -517,8 +623,8 @@ dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", - "indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -531,7 +637,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-text 13.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core-text 13.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -545,7 +651,7 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "headers-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", @@ -557,7 +663,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -565,12 +671,20 @@ name = "heck" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hermit-abi" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "http" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -585,7 +699,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -603,10 +717,10 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -616,9 +730,9 @@ dependencies = [ "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -642,7 +756,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -652,21 +766,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "indexmap" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "iovec" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -690,7 +806,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.62" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -698,11 +814,11 @@ name = "libpng-sys" version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", "dunce 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -710,19 +826,18 @@ name = "libz-sys" version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "lock_api" -version = "0.1.5" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -730,7 +845,25 @@ name = "log" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lyon_geom" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.20.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lyon_path" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lyon_geom 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -738,7 +871,7 @@ name = "malloc_buf" version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -746,6 +879,11 @@ name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "md-5" version = "0.8.0" @@ -761,9 +899,18 @@ name = "memchr" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memoffset" -version = "0.5.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -780,12 +927,12 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "miniz_oxide" -version = "0.3.2" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -798,9 +945,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -813,8 +960,8 @@ name = "mio-uds" version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -835,14 +982,14 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.24 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.10.25 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.49 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.52 (registry+https://github.com/rust-lang/crates.io-index)", "schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -851,14 +998,14 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "nodrop" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -866,24 +1013,25 @@ name = "num-integer" version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num_cpus" -version = "1.10.1" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -912,6 +1060,11 @@ dependencies = [ "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "once_cell" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "opaque-debug" version = "0.2.3" @@ -919,15 +1072,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "openssl" -version = "0.10.24" +version = "0.10.25" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.49 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.52 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -937,42 +1090,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "openssl-sys" -version = "0.9.49" +version = "0.9.52" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "owning_ref" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parking_lot" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parking_lot_core" -version = "0.4.0" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -988,7 +1136,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pkg-config" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -998,7 +1146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "ppv-lite86" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1006,22 +1154,14 @@ name = "proc-macro-error" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro2" -version = "1.0.3" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1029,7 +1169,7 @@ dependencies = [ [[package]] name = "publicsuffix" -version = "1.5.3" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1039,20 +1179,12 @@ dependencies = [ "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "quote" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "quote" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1060,8 +1192,8 @@ name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1078,8 +1210,8 @@ name = "rand" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1090,7 +1222,7 @@ name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1099,7 +1231,7 @@ name = "rand_chacha" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1121,7 +1253,7 @@ name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1153,7 +1285,7 @@ name = "rand_jitter" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1165,7 +1297,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1176,7 +1308,7 @@ name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1201,6 +1333,17 @@ name = "redox_syscall" version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "redox_users" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "regex" version = "1.3.1" @@ -1227,7 +1370,7 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.9.20" +version = "0.9.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1235,29 +1378,39 @@ dependencies = [ "cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rust-argon2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2b_simd 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-demangle" version = "0.1.16" @@ -1273,9 +1426,17 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "same-file" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "schannel" version = "0.1.16" @@ -1285,11 +1446,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "scopeguard" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "scopeguard" version = "1.0.0" @@ -1297,18 +1453,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "security-framework" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "security-framework-sys" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1329,30 +1485,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_json" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1362,10 +1518,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "servo-fontconfig" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "servo-fontconfig-sys 4.0.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "servo-fontconfig-sys" +version = "4.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "servo-freetype-sys 4.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "servo-freetype-sys" +version = "4.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sha-1" version = "0.8.1" @@ -1395,13 +1579,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.10" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "stable_deref_trait" -version = "1.1.1" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "string" @@ -1418,54 +1600,44 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "structopt" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt-derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt-derive 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "structopt-derive" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syn" -version = "0.15.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "syn" -version = "1.0.5" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "synstructure" -version = "0.10.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1474,24 +1646,24 @@ version = "0.1.12-dev" dependencies = [ "app_dirs2 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "headers 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "md-5 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "tectonic_engine 0.0.1-dev", "tectonic_xdv 0.1.9-dev", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "zip 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1499,17 +1671,18 @@ dependencies = [ name = "tectonic_bridge" version = "0.0.1-dev" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "anyhow 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tectonic_dvipdfmx" version = "0.0.1-dev" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libpng-sys 1.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "md-5 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1523,18 +1696,23 @@ name = "tectonic_engine" version = "0.0.1-dev" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-text 15.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "freetype-rs 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "enum_dispatch 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.20.4 (registry+https://github.com/rust-lang/crates.io-index)", + "font-kit 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "harfbuzz-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tectonic_bridge 0.0.1-dev", @@ -1555,8 +1733,8 @@ name = "tempfile" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1592,7 +1770,7 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1605,16 +1783,16 @@ dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1665,7 +1843,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1680,7 +1858,7 @@ dependencies = [ [[package]] name = "tokio-reactor" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1688,17 +1866,17 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-sync" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1712,24 +1890,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-threadpool" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1756,7 +1934,7 @@ dependencies = [ "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1766,22 +1944,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "toml" -version = "0.5.3" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1794,7 +1972,7 @@ name = "try_from" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1804,10 +1982,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicase" -version = "2.5.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1820,15 +1998,15 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "unicode-segmentation" -version = "1.3.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1836,11 +2014,6 @@ name = "unicode-width" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "unicode-xid" version = "0.2.0" @@ -1889,6 +2062,21 @@ name = "version_check" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "version_check" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "walkdir" +version = "2.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "want" version = "0.2.0" @@ -1978,7 +2166,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1986,26 +2174,32 @@ dependencies = [ "checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum anyhow 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "57114fc2a6cc374bce195d3482057c846e706d252ff3604363449695684d7a0d" "checksum app_dirs2 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "61b1fa4b1eeb18470c454bbed5406f02463aad37fd20f3a16c65bed88d4e115a" -"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" +"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" +"checksum arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" +"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" -"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" -"checksum backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)" = "5180c5a20655b14a819b652fd2378fa5f1697b6c9ddad3e695c2f9cedf6df4e2" -"checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b" +"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" +"checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" +"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum blake2b_simd 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b83b7baab1e671718d78204225800d6b170e648188ac7dc992e9d6bddf87d0c0" "checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -"checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" +"checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" -"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" -"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" -"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" +"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" +"checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" +"checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" "checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" "checksum cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" "checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" @@ -2014,29 +2208,35 @@ dependencies = [ "checksum core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" "checksum core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "56790968ab1c8a1202a102e6de05fc6e1ec87da99e4e93e9a7d13efbfc1e95a9" "checksum core-graphics 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "59e78b2e0aaf43f08e7ae0d6bc96895ef72ff0921c7d4ff4762201b2dba376dd" -"checksum core-text 13.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12684243b314c95600a2b49628fb775f91d97bbe18424522f665b77014f2a640" +"checksum core-text 13.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "db84654ad95211c082cf9795f6f83dc17d0ae6c985ac1b906369dc7384ed346d" "checksum core-text 15.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "131b3fd1f8bd5db9f2b398fa4fdb6008c64afc04d447c306ac2c7e98fba2a61d" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" -"checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71" -"checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" +"checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" +"checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" +"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum dunce 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0ad6bf6a88548d1126045c413548df1453d9be094a8ab9fd59bf1fdd338da4f" +"checksum dwrote 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0bd1369e02db5e9b842a9b67bce8a2fcc043beafb2ae8a799dd482d46ea1ff0d" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9" +"checksum enum_dispatch 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d187ded8d68dfce7d5fe26be489494e1d43edf15896d1df094790d77caf07b27" "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" -"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" -"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" +"checksum euclid 0.20.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4eeaa189ab5e5b393b765ff1ca754d88f3180d16260f1a5b39156c7b16159cce" +"checksum expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "658f19728920138342f68408b7cf7644d90d4784353d8ebc32e7e8663dbe45fa" +"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" +"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" -"checksum flate2 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "2adaffba6388640136149e18ed080b77a78611c1e1d6de75aedcdf78df5d4682" +"checksum flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f" +"checksum float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +"checksum font-kit 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b7ff8d2a0a660875d01689807925a45c5843bf90a1ef97ec52ef86ab0cafba" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "11926b2b410b469d0e9399eca4cbbe237a9ef02176c485803b29216307e8e028" -"checksum freetype-rs 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4e4ba31012a428040fde05907b42ee7d62b093457f4b2280a0294e0835d61b" -"checksum freetype-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7dc687b58f0c77150b0aca7d9a1dc93522303570458e1aa36b4fb367584f60c4" "checksum fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" @@ -2044,66 +2244,69 @@ dependencies = [ "checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" -"checksum getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "473a1265acc8ff1e808cd0a1af8cee3c2ee5200916058a2ca113c29f2d903571" +"checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" "checksum harfbuzz-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e1042ab0b3e7bc1ff64f7f5935778b644ff2194a1cae5ec52167127d3fd23961" "checksum headers 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "882ca7d8722f33ce2c2db44f95425d6267ed59ca96ce02acbe58320054ceb642" "checksum headers-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "967131279aaa9f7c20c7205b45a391638a83ab118e6509b2d0ccbe08de044237" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" -"checksum http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "372bcb56f939e449117fb0869c2e8fd8753a8223d92a172c6e808cf123a5b6e4" +"checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" +"checksum http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e06e336150b178206af098a055e3621e8336027e2b4d126bda0bc64824baaf" "checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)" = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" "checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" -"checksum indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a61202fbe46c4a951e9404a720a0180bcf3212c750d735cb5c4ba4dc551299f3" -"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" +"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" +"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" +"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum libpng-sys 1.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "939658d8a33e52645ecfdc42500285c8b0fdeb26df10677c32abd13a1fc1d70c" "checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" -"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +"checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +"checksum lyon_geom 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca04310c9807612a311506106000b6eccb2e27bca9bfb594ce80fb8a31231f9d" +"checksum lyon_path 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0bcb57ac24a5428539e2c7c0592766d5933c937d703f430990c669c00de96862" "checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" "checksum md-5 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a18af3dcaf2b0219366cdb4e2af65a6101457b415c3d1a5c71dd9c2b7c77b9c8" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" -"checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f" +"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +"checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" "checksum mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "dd1d63acd1b78403cc0c325605908475dd9b9a3acbf65ed8bcab97e27014afcf" "checksum mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599" -"checksum miniz_oxide 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7108aff85b876d06f22503dcce091e29f76733b2bfdd91eebce81f5e68203a10" +"checksum miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625" "checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" -"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" "checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" -"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" -"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" +"checksum num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "443c53b3c3531dfcbfa499d8893944db78474ad7a1d87fa2d94d1a2231693ac6" +"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" "checksum objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" "checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" "checksum objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" -"checksum openssl 0.10.24 (registry+https://github.com/rust-lang/crates.io-index)" = "8152bb5a9b5b721538462336e3bef9a539f892715e5037fda0f984577311af15" +"checksum openssl 0.10.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2f372b2b53ce10fb823a337aaa674e3a7d072b957c6264d0f4ff0bd86e657449" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" -"checksum openssl-sys 0.9.49 (registry+https://github.com/rust-lang/crates.io-index)" = "f4fad9e54bd23bd4cbbe48fdc08a1b8091707ac869ef8508edea2fec77dcc884" -"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" -"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" -"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +"checksum openssl-sys 0.9.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c977d08e1312e2f7e4b86f9ebaa0ed3b19d1daff75fae88bbb88108afbd801fc" +"checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" +"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -"checksum pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "72d5370d90f49f70bd033c3d75e87fc529fbfff9d6f7cccef07d6170079d91ea" +"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" "checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" -"checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" +"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" "checksum proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097" -"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e98a83a9f9b331f54b924e68a66acb1bb35cb01fb0a23645139967abefb697e8" -"checksum publicsuffix 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9bf259a81de2b2eb9850ec990ec78e6a25319715584fd7652b9b26f96fcb1510" -"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" +"checksum publicsuffix 1.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3bbaa49075179162b49acac1c6aa45fb4dafb5f13cf6794276d77bc7fd95757b" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412" @@ -2121,36 +2324,39 @@ dependencies = [ "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +"checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d" "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -"checksum reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)" = "0f6d896143a583047512e59ac54a215cb203c29cc941917343edea3be8df9c78" +"checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650" +"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" +"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" +"checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" "checksum schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "87f550b06b6cba9c8b8be3ee73f391990116bf527450d2556e9b9ce263b9a021" -"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" -"checksum security-framework 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eee63d0f4a9ec776eeb30e220f0bc1e092c3ad744b2a379e3993070364d3adc2" -"checksum security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9636f8989cbf61385ae4824b98c1aaa54c994d7d8b41f11c601ed799f0549a56" +"checksum security-framework 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "301c862a6d0ee78f124c5e1710205965fc5c553100dcda6d98f13ef87a763f04" +"checksum security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "9796c9b7ba2ffe7a9ce53c2287dfc48080f4b2b362fcc245a259b3a7201119dd" -"checksum serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "4b133a43a1ecd55d4086bd5b4dc6c1751c68b1bfbeba7a5040442022c7e7c02e" -"checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704" +"checksum serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0" +"checksum serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "ca13fc1a832f793322228923fbb3aba9f3f44444898f835d31ad1b74fa0a2bf8" +"checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2" "checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a" +"checksum servo-fontconfig 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a088f8d775a5c5314aae09bd77340bc9c67d72b9a45258be34c83548b4814cd9" +"checksum servo-fontconfig-sys 4.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b46d201addcfbd25c1798ad1281d98c40743824e0b0f1e611bd3d5d0d31a7b8d" +"checksum servo-freetype-sys 4.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4ccb6d0d32d277d3ef7dea86203d8210945eb7a45fba89dd445b3595dd0dfc" "checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" -"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum structopt 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe8d3289b63ef2f196d89e7701f986583c0895e764b78f052a55b9b5d34d84a" -"checksum structopt-derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f3add731f5b4fb85931d362a3c92deb1ad7113649a8d51701fb257673705f122" -"checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" -"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" +"checksum structopt 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c167b61c7d4c126927f5346a4327ce20abf8a186b8041bbeb1ce49e5db49587b" +"checksum structopt-derive 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "519621841414165d2ad0d4c92be8f41844203f2b67e245f9345a5a12d40c69d7" +"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" +"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" @@ -2163,23 +2369,22 @@ dependencies = [ "checksum tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f27ee0e6db01c5f0b2973824547ce7e637b2ed79b891a9677b0de9bd532b6ac" "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" -"checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce" -"checksum tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2162248ff317e2bc713b261f242b69dbb838b85248ed20bb21df56d60ea4cae7" +"checksum tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "c56391be9805bc80163151c0b9e5164ee64f4b0200962c346fea12773158f22d" +"checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" -"checksum tokio-threadpool 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "90ca01319dea1e376a001e8dc192d42ebde6dd532532a5bad988ac37db365b19" +"checksum tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd2c6a3885302581f4401c82af70d792bb9df1700e7437b0aeb4ada94d5388c" "checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" "checksum tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f02298505547f73e60f568359ef0d016d5acd6e830ab9bc7c4a5b3403440121b" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" -"checksum toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7aabe75941d914b72bf3e5d3932ed92ce0664d49d8432305a8b547c37227724" +"checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" -"checksum unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150" +"checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" -"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" +"checksum unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "09c8070a9942f5e7cfccd93f490fdebd230ee3c3c9f107cb25bad5351ef671cf" +"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" "checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" -"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" @@ -2187,6 +2392,8 @@ dependencies = [ "checksum vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" +"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" +"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e" "checksum want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" diff --git a/bridge/Cargo.toml b/bridge/Cargo.toml index 1b0d6381c..845379798 100644 --- a/bridge/Cargo.toml +++ b/bridge/Cargo.toml @@ -9,3 +9,4 @@ cc = "^1.0" [dependencies] libc = "0.2" +anyhow = "1.0.19" diff --git a/bridge/src/lib.rs b/bridge/src/lib.rs index 23f67022a..cc13d15ce 100644 --- a/bridge/src/lib.rs +++ b/bridge/src/lib.rs @@ -9,7 +9,7 @@ unused_mut )] -use std::io::{prelude::*, Result}; +use std::io::{self, prelude::*, Result, ErrorKind}; use std::io::SeekFrom; use std::ptr::NonNull; @@ -52,12 +52,29 @@ impl Write for OutputHandleWrapper { } #[derive(Clone, PartialEq)] +#[repr(transparent)] pub struct InputHandleWrapper(pub NonNull); impl Read for InputHandleWrapper { fn read(&mut self, buf: &mut [u8]) -> Result { unsafe { - Ok(ttstub_input_read(self.0.as_ptr(), buf.as_mut_ptr() as *mut i8, buf.len() as u64) as usize) + let read_isize = ttstub_input_read(self.0.as_ptr(), buf.as_mut_ptr() as *mut i8, buf.len() as u64); + if read_isize < 0 { + Err(io::Error::new(ErrorKind::Other, anyhow::anyhow!("Unknown -1 error code from across the bridge while reading input handle"))) + } else { + Ok(read_isize as usize) + } + } + } + + fn read_exact(&mut self, buf: &mut [u8]) -> Result<()> { + unsafe { + let read_isize = ttstub_input_read_exact(self.0.as_ptr(), buf.as_mut_ptr() as *mut i8, buf.len() as u64); + if read_isize < 0 { + Err(io::Error::new(ErrorKind::Other, anyhow::anyhow!("Unknown -1 error code from across the bridge while reading input handle (with read_exact)"))) + } else { + Ok(()) + } } } } @@ -71,7 +88,8 @@ impl Seek for InputHandleWrapper { SeekFrom::End(o) => (o as ssize_t, SEEK_END), }; unsafe { - Ok(ttstub_input_seek(self.0.as_ptr(), offset, whence) as u64) + let sought = ttstub_input_seek(self.0.as_ptr(), offset, whence); + Ok(sought as u64) } } } @@ -86,22 +104,22 @@ impl InputHandleWrapper { #[repr(C)] pub struct tt_bridge_api_t { pub context: *mut libc::c_void, - pub issue_warning: Option ()>, - pub issue_error: Option ()>, + pub issue_warning: Option ()>, + pub issue_error: Option ()>, pub get_file_md5: - Option i32>, + Option i32>, pub get_data_md5: Option< - unsafe extern "C" fn(_: *mut libc::c_void, _: *const i8, _: size_t, _: *mut i8) -> i32, + unsafe fn(_: *mut libc::c_void, _: *const i8, _: size_t, _: *mut i8) -> i32, >, pub output_open: Option< - unsafe extern "C" fn(_: *mut libc::c_void, _: *const i8, _: i32) -> rust_output_handle_t, + unsafe fn(_: *mut libc::c_void, _: *const i8, _: i32) -> rust_output_handle_t, >, pub output_open_stdout: - Option rust_output_handle_t>, + Option rust_output_handle_t>, pub output_putc: - Option i32>, + Option i32>, pub output_write: Option< - unsafe extern "C" fn( + unsafe fn( _: *mut libc::c_void, _: rust_output_handle_t, _: *const i8, @@ -109,11 +127,11 @@ pub struct tt_bridge_api_t { ) -> size_t, >, pub output_flush: - Option i32>, + Option i32>, pub output_close: - Option i32>, + Option i32>, pub input_open: Option< - unsafe extern "C" fn( + unsafe fn( _: *mut libc::c_void, _: *const i8, _: TTInputFormat, @@ -121,11 +139,11 @@ pub struct tt_bridge_api_t { ) -> rust_input_handle_t, >, pub input_open_primary: - Option rust_input_handle_t>, + Option rust_input_handle_t>, pub input_get_size: - Option size_t>, + Option size_t>, pub input_seek: Option< - unsafe extern "C" fn( + unsafe fn( _: *mut libc::c_void, _: rust_input_handle_t, _: ssize_t, @@ -134,7 +152,15 @@ pub struct tt_bridge_api_t { ) -> size_t, >, pub input_read: Option< - unsafe extern "C" fn( + unsafe fn( + _: *mut libc::c_void, + _: rust_input_handle_t, + _: *mut i8, + _: size_t, + ) -> ssize_t, + >, + pub input_read_exact: Option< + unsafe fn( _: *mut libc::c_void, _: rust_input_handle_t, _: *mut i8, @@ -142,11 +168,11 @@ pub struct tt_bridge_api_t { ) -> ssize_t, >, pub input_getc: - Option i32>, + Option i32>, pub input_ungetc: - Option i32>, + Option i32>, pub input_close: - Option i32>, + Option i32>, } #[repr(C)] @@ -161,8 +187,11 @@ pub enum TTHistory { #[repr(C)] #[derive(Clone, Copy, PartialEq)] pub enum TTInputFormat { + /// TeX Font Metric TFM = 3, + /// Adobe Font Metric AFM = 4, + /// BibTeX BIB = 6, BST = 7, CNF = 8, @@ -371,6 +400,7 @@ pub unsafe extern "C" fn ttstub_input_seek( } rv } + #[no_mangle] pub unsafe extern "C" fn ttstub_input_read( mut handle: rust_input_handle_t, @@ -383,18 +413,34 @@ pub unsafe extern "C" fn ttstub_input_read( (*tectonic_global_bridge).context, handle, data, len ) } + +#[no_mangle] +pub unsafe extern "C" fn ttstub_input_read_exact( + mut handle: rust_input_handle_t, + mut data: *mut i8, + mut len: size_t, +) -> ssize_t { + (*tectonic_global_bridge) + .input_read_exact + .expect("non-null function pointer")( + (*tectonic_global_bridge).context, handle, data, len + ) +} + #[no_mangle] pub unsafe extern "C" fn ttstub_input_getc(handle: &mut InputHandleWrapper) -> i32 { (*tectonic_global_bridge) .input_getc .expect("non-null function pointer")((*tectonic_global_bridge).context, handle.0.as_ptr()) } + #[no_mangle] pub unsafe extern "C" fn ttstub_input_ungetc(handle: &mut InputHandleWrapper, mut ch: i32) -> i32 { (*tectonic_global_bridge) .input_ungetc .expect("non-null function pointer")((*tectonic_global_bridge).context, handle.0.as_ptr(), ch) } + #[no_mangle] pub unsafe extern "C" fn ttstub_input_close(mut handle: InputHandleWrapper) -> i32 { if (*tectonic_global_bridge) diff --git a/dpx/src/dpx_bmpimage.rs b/dpx/src/dpx_bmpimage.rs index b78894e99..47b2d4a5c 100644 --- a/dpx/src/dpx_bmpimage.rs +++ b/dpx/src/dpx_bmpimage.rs @@ -36,7 +36,7 @@ use crate::dpx_pdfobj::{ pdf_stream_set_predictor, STREAM_COMPRESS, }; use crate::warn; -use crate::{ttstub_input_read}; +use crate::{ttstub_input_read_exact}; use libc::{free, memset}; use std::io::{Seek, SeekFrom}; @@ -63,7 +63,7 @@ pub struct hdr_info { pub unsafe extern "C" fn check_for_bmp(handle: &mut InputHandleWrapper) -> i32 { let mut sigbytes: [u8; 2] = [0; 2]; handle.seek(SeekFrom::Start(0)).unwrap(); - if ttstub_input_read( + if ttstub_input_read_exact( handle.0.as_ptr(), sigbytes.as_mut_ptr() as *mut i8, ::std::mem::size_of::<[u8; 2]>() as u64, @@ -192,7 +192,7 @@ pub unsafe extern "C" fn bmp_include_image( let palette = new(((num_palette * 3i32 + 1i32) as u32 as u64) .wrapping_mul(::std::mem::size_of::() as u64) as u32) as *mut u8; for i in 0..num_palette { - if ttstub_input_read(handle.0.as_ptr(), bgrq.as_mut_ptr() as *mut i8, hdr.psize as size_t) + if ttstub_input_read_exact(handle.0.as_ptr(), bgrq.as_mut_ptr() as *mut i8, hdr.psize as size_t) != hdr.psize as i64 { warn!("Reading file failed..."); @@ -235,7 +235,7 @@ pub unsafe extern "C" fn bmp_include_image( let mut n = 0i32; while n < info.height { let p = stream_data_ptr.offset((n * rowbytes) as isize); - if ttstub_input_read(handle.0.as_ptr(), p as *mut i8, dib_rowbytes as size_t) + if ttstub_input_read_exact(handle.0.as_ptr(), p as *mut i8, dib_rowbytes as size_t) != dib_rowbytes as i64 { warn!("Reading BMP raster data failed..."); @@ -316,7 +316,7 @@ use crate::FromLEByteSlice; unsafe fn read_header(handle: &mut InputHandleWrapper, hdr: &mut hdr_info) -> i32 { let mut buf: [u8; 142] = [0; 142]; let p = &mut buf; - if ttstub_input_read(handle.0.as_ptr(), p.as_mut_ptr() as *mut i8, (14i32 + 4i32) as size_t) + if ttstub_input_read_exact(handle.0.as_ptr(), p.as_mut_ptr() as *mut i8, (14i32 + 4i32) as size_t) != (14i32 + 4i32) as i64 { warn!("Could not read BMP file header..."); @@ -339,7 +339,7 @@ unsafe fn read_header(handle: &mut InputHandleWrapper, hdr: &mut hdr_info) -> i3 /* info header */ hdr.hsize = u32::from_le_byte_slice(&p[..4]); /* undefined. FIXME */ let p = &mut p[4..]; /* undefined. FIXME */ - if ttstub_input_read( + if ttstub_input_read_exact( handle.0.as_ptr(), p.as_mut_ptr() as *mut i8, hdr.hsize.wrapping_sub(4_u32) as size_t, @@ -439,7 +439,7 @@ unsafe fn read_raster_rle8( warn!("RLE decode failed..."); return -1i32; } - if ttstub_input_read(handle.0.as_ptr(), p as *mut i8, b1 as size_t) != b1 as i64 { + if ttstub_input_read_exact(handle.0.as_ptr(), p as *mut i8, b1 as size_t) != b1 as i64 { return -1i32; } count += b1 as i32; @@ -534,7 +534,7 @@ unsafe fn read_raster_rle4( *fresh0 = (*fresh0 as i32 | b as i32 >> 4i32 & 0xfi32) as u8; *p = ((b as i32) << 4i32 & 0xf0i32) as u8; } - } else if ttstub_input_read(handle.0.as_ptr(), p as *mut i8, nbytes as size_t) + } else if ttstub_input_read_exact(handle.0.as_ptr(), p as *mut i8, nbytes as size_t) != nbytes as i64 { return -1i32; diff --git a/dpx/src/dpx_cff.rs b/dpx/src/dpx_cff.rs index 88733b854..3f9ece66d 100644 --- a/dpx/src/dpx_cff.rs +++ b/dpx/src/dpx_cff.rs @@ -33,7 +33,7 @@ use crate::warn; use super::dpx_cff_dict::{cff_dict_get, cff_dict_known, cff_dict_unpack, cff_release_dict}; use super::dpx_mem::{new, renew}; use super::dpx_numbers::{tt_get_unsigned_byte, tt_get_unsigned_pair}; -use crate::{ttstub_input_read}; +use crate::{ttstub_input_read_exact}; use libc::{free, memcmp, memcpy, memmove, memset, strlen}; use std::io::{Seek, SeekFrom}; @@ -1041,7 +1041,7 @@ pub unsafe extern "C" fn cff_get_index(cff: &mut cff_font) -> *mut cff_index { as *mut u8; let mut offset = 0; while length > 0i32 { - let nb_read = ttstub_input_read( + let nb_read = ttstub_input_read_exact( handle.0.as_ptr(), ((*idx).data as *mut i8).offset(offset as isize), length as size_t, @@ -2277,7 +2277,7 @@ pub unsafe extern "C" fn cff_read_private(cff: &mut cff_font) -> i32 { let data = new( (size as u32 as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32, ) as *mut u8; - if ttstub_input_read(handle.0.as_ptr(), data as *mut i8, size as size_t) != size as i64 { + if ttstub_input_read_exact(handle.0.as_ptr(), data as *mut i8, size as size_t) != size as i64 { panic!("reading file failed"); } let ref mut fresh53 = *cff.private.offset(i as isize); @@ -2305,7 +2305,7 @@ pub unsafe extern "C" fn cff_read_private(cff: &mut cff_font) -> i32 { let data = new((size as u32 as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32) as *mut u8; - if ttstub_input_read(handle.0.as_ptr(), data as *mut i8, size as size_t) != size as i64 { + if ttstub_input_read_exact(handle.0.as_ptr(), data as *mut i8, size as size_t) != size as i64 { panic!("reading file failed"); } let ref mut fresh55 = *cff.private.offset(0); diff --git a/dpx/src/dpx_cidtype0.rs b/dpx/src/dpx_cidtype0.rs index c7ce23f9e..a4c0c072a 100644 --- a/dpx/src/dpx_cidtype0.rs +++ b/dpx/src/dpx_cidtype0.rs @@ -85,7 +85,7 @@ use crate::dpx_pdfobj::{ }; use crate::dpx_truetype::sfnt_table_info; use crate::shims::sprintf; -use crate::{ttstub_input_read}; +use crate::{ttstub_input_read_exact}; use libc::{free, memmove, memset, strcat, strcmp, strcpy, strlen, strstr}; use std::io::{Seek, SeekFrom}; @@ -849,7 +849,7 @@ pub unsafe extern "C" fn CIDFont_type0_dofont(mut font: *mut CIDFont) { *(*charstrings).offset.offset(gid as isize) = (charstring_len + 1i32) as l_offset; let handle = cffont.handle.as_mut().unwrap(); handle.seek(SeekFrom::Start(offset as u64 + *(*idx).offset.offset(gid_org as isize) as u64 - 1)).unwrap(); - ttstub_input_read(handle.0.as_ptr(), data as *mut i8, size as size_t); + ttstub_input_read_exact(handle.0.as_ptr(), data as *mut i8, size as size_t); let fd = cff_fdselect_lookup(cffont, gid_org) as i32; charstring_len += cs_copy_charstring( (*charstrings).data.offset(charstring_len as isize), @@ -1395,7 +1395,7 @@ pub unsafe extern "C" fn CIDFont_type0_t1cdofont(mut font: *mut CIDFont) { *(*charstrings).offset.offset(gid as isize) = (charstring_len + 1i32) as l_offset; let handle = cffont.handle.as_mut().unwrap(); handle.seek(SeekFrom::Start(offset as u64 + *(*idx).offset.offset(cid as isize) as u64 - 1 )).unwrap(); - ttstub_input_read(handle.0.as_ptr(), data as *mut i8, size as size_t); + ttstub_input_read_exact(handle.0.as_ptr(), data as *mut i8, size as size_t); charstring_len += cs_copy_charstring( (*charstrings).data.offset(charstring_len as isize), max_len - charstring_len, diff --git a/dpx/src/dpx_cmap_read.rs b/dpx/src/dpx_cmap_read.rs index ece402ef1..1fa39c532 100644 --- a/dpx/src/dpx_cmap_read.rs +++ b/dpx/src/dpx_cmap_read.rs @@ -45,7 +45,7 @@ use super::dpx_pst_obj::pst_obj; use super::dpx_pst_obj::{ pst_data_ptr, pst_getIV, pst_getSV, pst_length_of, pst_release_obj, pst_type_of, }; -use crate::{ttstub_input_get_size, ttstub_input_read}; +use crate::{ttstub_input_get_size, ttstub_input_read_exact}; use libc::{free, memcmp, memcpy, memmove, strcmp, strlen, strstr}; pub type __ssize_t = i64; @@ -122,7 +122,7 @@ unsafe fn ifreader_read(mut reader: *mut ifreader, mut size: size_t) -> size_t { ); (*reader).cursor = (*reader).buf; (*reader).endptr = (*reader).buf.offset(bytesrem as isize); - if ttstub_input_read((*reader).handle.0.as_ptr(), (*reader).endptr as *mut i8, bytesread) as u64 + if ttstub_input_read_exact((*reader).handle.0.as_ptr(), (*reader).endptr as *mut i8, bytesread) as u64 != bytesread { panic!("Reading file failed."); @@ -680,7 +680,7 @@ pub unsafe extern "C" fn CMap_parse_check_sig(handle: Option<&mut InputHandleWra } let mut handle = handle.unwrap(); handle.seek(SeekFrom::Start(0)).unwrap(); - if ttstub_input_read(handle.0.as_ptr(), sig.as_mut_ptr(), 64i32 as size_t) != 64i32 as i64 { + if ttstub_input_read_exact(handle.0.as_ptr(), sig.as_mut_ptr(), 64i32 as size_t) != 64i32 as i64 { result = -1i32 } else { sig[64] = 0_i8; diff --git a/dpx/src/dpx_dvi.rs b/dpx/src/dpx_dvi.rs index 7a39c2c37..fb3084208 100644 --- a/dpx/src/dpx_dvi.rs +++ b/dpx/src/dpx_dvi.rs @@ -86,7 +86,7 @@ use crate::specials::{ }; use crate::{ ttstub_input_close, ttstub_input_get_size, ttstub_input_getc, ttstub_input_open, - ttstub_input_read, ttstub_input_ungetc, + ttstub_input_read_exact, ttstub_input_ungetc, }; use crate::dpx_dvicodes::*; @@ -537,14 +537,14 @@ unsafe fn read_font_record(mut tex_id: u32) { let directory = new( ((dir_length + 1i32) as u32 as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32 ) as *mut i8; - if ttstub_input_read(handle.0.as_ptr(), directory, dir_length as size_t) != dir_length as i64 { + if ttstub_input_read_exact(handle.0.as_ptr(), directory, dir_length as size_t) != dir_length as i64 { panic!(invalid_signature); } *directory.offset(dir_length as isize) = '\u{0}' as i32 as i8; free(directory as *mut libc::c_void); let font_name = new(((name_length + 1i32) as u32 as u64) .wrapping_mul(::std::mem::size_of::() as u64) as u32) as *mut i8; - if ttstub_input_read(handle.0.as_ptr(), font_name, name_length as size_t) != name_length as i64 { + if ttstub_input_read_exact(handle.0.as_ptr(), font_name, name_length as size_t) != name_length as i64 { panic!(invalid_signature); } *font_name.offset(name_length as isize) = '\u{0}' as i32 as i8; @@ -582,7 +582,7 @@ unsafe fn read_native_font_record(mut tex_id: u32) { let font_name = new(((len + 1i32) as u32 as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32) as *mut i8; - if ttstub_input_read(handle.0.as_ptr(), font_name, len as size_t) != len as i64 { + if ttstub_input_read_exact(handle.0.as_ptr(), font_name, len as size_t) != len as i64 { panic!(invalid_signature); } *font_name.offset(len as isize) = '\u{0}' as i32 as i8; diff --git a/dpx/src/dpx_jpegimage.rs b/dpx/src/dpx_jpegimage.rs index 15ee9294c..3fce50560 100644 --- a/dpx/src/dpx_jpegimage.rs +++ b/dpx/src/dpx_jpegimage.rs @@ -43,7 +43,7 @@ use crate::dpx_pdfobj::{ pdf_new_number, pdf_new_stream, pdf_obj, pdf_ref_obj, pdf_release_obj, pdf_stream_dataptr, pdf_stream_length, STREAM_COMPRESS, }; -use crate::{ttstub_input_get_size, ttstub_input_getc, ttstub_input_read}; +use crate::{ttstub_input_get_size, ttstub_input_getc, ttstub_input_read_exact}; use libc::{free, memcmp, memset}; use std::io::{Seek, SeekFrom}; @@ -161,7 +161,7 @@ pub struct JPEG_APPn_JFIF { pub unsafe extern "C" fn check_for_jpeg(handle: &mut InputHandleWrapper) -> i32 { let mut jpeg_sig: [u8; 2] = [0; 2]; handle.seek(SeekFrom::Start(0)).unwrap(); - if ttstub_input_read(handle.0.as_ptr(), jpeg_sig.as_mut_ptr() as *mut i8, 2i32 as size_t) != 2i32 as i64 { + if ttstub_input_read_exact(handle.0.as_ptr(), jpeg_sig.as_mut_ptr() as *mut i8, 2i32 as size_t) != 2i32 as i64 { return 0i32; } else { if jpeg_sig[0] as i32 != 0xffi32 || jpeg_sig[1] as i32 != JM_SOI as i32 { @@ -528,7 +528,7 @@ unsafe fn read_APP1_Exif( let mut res_unit_ms: f64 = 0.0f64; let mut buffer_box: Box<[u8]> = vec![0u8; length as usize].into_boxed_slice(); // auto destruct let buffer = buffer_box.as_mut_ptr(); - let r = ttstub_input_read(handle.0.as_ptr(), buffer as *mut i8, length); + let r = ttstub_input_read_exact(handle.0.as_ptr(), buffer as *mut i8, length); if r < 0 || r as size_t != length { return length; } @@ -720,7 +720,7 @@ unsafe fn read_APP0_JFIF(j_info: *mut JPEG_info, handle: &mut InputHandleWrapper (*app_data).thumbnail = new((thumb_data_len as u32 as u64) .wrapping_mul(::std::mem::size_of::() as u64) as u32) as *mut u8; - ttstub_input_read(handle.0.as_ptr(), (*app_data).thumbnail as *mut i8, thumb_data_len); + ttstub_input_read_exact(handle.0.as_ptr(), (*app_data).thumbnail as *mut i8, thumb_data_len); } else { (*app_data).thumbnail = 0 as *mut u8 } @@ -771,7 +771,7 @@ unsafe fn read_APP1_XMP( (*app_data).packet = new( ((*app_data).length as u32 as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32 ) as *mut u8; - ttstub_input_read(handle.0.as_ptr(), (*app_data).packet as *mut i8, (*app_data).length); + ttstub_input_read_exact(handle.0.as_ptr(), (*app_data).packet as *mut i8, (*app_data).length); add_APPn_marker( j_info, JM_APP1, @@ -793,7 +793,7 @@ unsafe fn read_APP2_ICC( (*app_data).chunk = new( ((*app_data).length as u32 as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32 ) as *mut u8; - ttstub_input_read(handle.0.as_ptr(), (*app_data).chunk as *mut i8, (*app_data).length); + ttstub_input_read_exact(handle.0.as_ptr(), (*app_data).chunk as *mut i8, (*app_data).length); add_APPn_marker( j_info, JM_APP2, @@ -839,7 +839,7 @@ unsafe fn JPEG_copy_stream( 4i32, ); while length > 0i32 { - let mut nb_read: i32 = ttstub_input_read( + let mut nb_read: i32 = ttstub_input_read_exact( handle.0.as_ptr(), work_buffer.as_mut_ptr(), (if length < 1024i32 { length } else { 1024i32 }) as size_t, @@ -873,7 +873,7 @@ unsafe fn JPEG_copy_stream( 4i32, ); while length > 0i32 { - let mut nb_read_0: i32 = ttstub_input_read( + let mut nb_read_0: i32 = ttstub_input_read_exact( handle.0.as_ptr(), work_buffer.as_mut_ptr(), (if length < 1024i32 { length } else { 1024i32 }) as size_t, @@ -896,7 +896,7 @@ unsafe fn JPEG_copy_stream( let mut total_size: size_t = ttstub_input_get_size(handle); let mut pos = handle.seek(SeekFrom::Current(0)).unwrap(); loop { - let length = ttstub_input_read( + let length = ttstub_input_read_exact( handle.0.as_ptr(), work_buffer.as_mut_ptr(), if (1024i32 as u64) < total_size.wrapping_sub(pos) { @@ -945,7 +945,7 @@ unsafe fn JPEG_scan_file(mut j_info: *mut JPEG_info, handle: &mut InputHandleWra } 224 => { if length > 5i32 { - if ttstub_input_read(handle.0.as_ptr(), app_sig.as_mut_ptr(), 5i32 as size_t) + if ttstub_input_read_exact(handle.0.as_ptr(), app_sig.as_mut_ptr(), 5i32 as size_t) != 5i32 as i64 { return -1i32; @@ -975,7 +975,7 @@ unsafe fn JPEG_scan_file(mut j_info: *mut JPEG_info, handle: &mut InputHandleWra } 225 => { if length > 5i32 { - if ttstub_input_read(handle.0.as_ptr(), app_sig.as_mut_ptr(), 5i32 as size_t) + if ttstub_input_read_exact(handle.0.as_ptr(), app_sig.as_mut_ptr(), 5i32 as size_t) != 5i32 as i64 { return -1i32; @@ -1000,7 +1000,7 @@ unsafe fn JPEG_scan_file(mut j_info: *mut JPEG_info, handle: &mut InputHandleWra ) == 0 && length > 24i32 { - if ttstub_input_read(handle.0.as_ptr(), app_sig.as_mut_ptr(), 24i32 as size_t) + if ttstub_input_read_exact(handle.0.as_ptr(), app_sig.as_mut_ptr(), 24i32 as size_t) != 24i32 as i64 { return -1i32; @@ -1032,7 +1032,7 @@ unsafe fn JPEG_scan_file(mut j_info: *mut JPEG_info, handle: &mut InputHandleWra } 226 => { if length >= 14i32 { - if ttstub_input_read(handle.0.as_ptr(), app_sig.as_mut_ptr(), 12i32 as size_t) + if ttstub_input_read_exact(handle.0.as_ptr(), app_sig.as_mut_ptr(), 12i32 as size_t) != 12i32 as i64 { return -1i32; @@ -1062,7 +1062,7 @@ unsafe fn JPEG_scan_file(mut j_info: *mut JPEG_info, handle: &mut InputHandleWra } 238 => { if length > 5i32 { - if ttstub_input_read(handle.0.as_ptr(), app_sig.as_mut_ptr(), 5i32 as size_t) + if ttstub_input_read_exact(handle.0.as_ptr(), app_sig.as_mut_ptr(), 5i32 as size_t) != 5i32 as i64 { return -1i32; diff --git a/dpx/src/dpx_pdfobj.rs b/dpx/src/dpx_pdfobj.rs index 8b30d6a23..525dcb64d 100644 --- a/dpx/src/dpx_pdfobj.rs +++ b/dpx/src/dpx_pdfobj.rs @@ -46,7 +46,7 @@ use super::dpx_pdfencrypt::{pdf_enc_set_generation, pdf_enc_set_label, pdf_encry use super::dpx_pdfparse::skip_white; use crate::shims::{sprintf, sscanf}; use crate::{ - ttstub_input_get_size, ttstub_input_getc, ttstub_input_read, + ttstub_input_get_size, ttstub_input_getc, ttstub_input_read_exact, ttstub_input_ungetc, ttstub_output_close, ttstub_output_open, ttstub_output_open_stdout, ttstub_output_putc, }; @@ -2851,7 +2851,7 @@ unsafe fn find_xref(handle: &mut InputHandleWrapper, mut file_size: i32) -> i32 } else { let currentpos = handle.seek(SeekFrom::Current(0)).unwrap() as i32; let n = core::cmp::min(strlen(b"startxref\x00" as *const u8 as *const i8) as i32, file_size - currentpos); - ttstub_input_read(handle.0.as_ptr(), work_buffer.as_mut_ptr(), n as size_t); + ttstub_input_read_exact(handle.0.as_ptr(), work_buffer.as_mut_ptr(), n as size_t); handle.seek(SeekFrom::Start(currentpos as u64)).unwrap(); tries -= 1; if !(tries > 0i32 @@ -2968,7 +2968,7 @@ unsafe fn pdf_read_object( ((length + 1i32) as u32 as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32, ) as *mut i8; (*pf).handle.seek(SeekFrom::Start(offset as u64)).unwrap(); - ttstub_input_read((*pf).handle.0.as_ptr(), buffer, length as size_t); + ttstub_input_read_exact((*pf).handle.0.as_ptr(), buffer, length as size_t); let mut p = buffer as *const i8; let mut endptr = p.offset(length as isize); /* Check for obj_num and obj_gen */ @@ -3865,7 +3865,7 @@ unsafe fn parse_pdf_version(handle: &mut InputHandleWrapper, mut ret_version: *m ); let mut minor: u32 = 0; handle.seek(SeekFrom::Start(0)).unwrap(); - if ttstub_input_read( + if ttstub_input_read_exact( handle.0.as_ptr(), buffer.as_mut_ptr(), (::std::mem::size_of::<[i8; 10]>() as u64).wrapping_sub(1i32 as u64), diff --git a/dpx/src/dpx_pngimage.rs b/dpx/src/dpx_pngimage.rs index 69b39a256..bf6b0fd3d 100644 --- a/dpx/src/dpx_pngimage.rs +++ b/dpx/src/dpx_pngimage.rs @@ -40,7 +40,7 @@ use crate::dpx_pdfobj::{ pdf_new_name, pdf_new_number, pdf_new_stream, pdf_new_string, pdf_obj, pdf_ref_obj, pdf_release_obj, pdf_stream_set_predictor, STREAM_COMPRESS, }; -use crate::{ttstub_input_read}; +use crate::{ttstub_input_read_exact}; use libc::free; use std::io::{Seek, SeekFrom}; @@ -62,7 +62,7 @@ pub type png_uint_32 = libc::c_uint; pub unsafe extern "C" fn check_for_png(handle: &mut InputHandleWrapper) -> i32 { let mut sigbytes: [u8; 8] = [0; 8]; handle.seek(SeekFrom::Start(0)).unwrap(); - if ttstub_input_read( + if ttstub_input_read_exact( handle.0.as_ptr(), sigbytes.as_mut_ptr() as *mut i8, ::std::mem::size_of::<[u8; 8]>() as u64, @@ -88,7 +88,7 @@ unsafe extern "C" fn _png_warning_callback( unsafe extern "C" fn _png_read(mut png_ptr: *mut png_struct, mut outbytes: *mut u8, mut n: usize) { let mut png = png_ptr.as_ref().unwrap(); let mut handle = png_get_io_ptr(png) as tectonic_bridge::rust_input_handle_t; - let r = ttstub_input_read(handle, outbytes as *mut i8, n.try_into().unwrap()); + let r = ttstub_input_read_exact(handle, outbytes as *mut i8, n.try_into().unwrap()); if r < 0i32 as ssize_t || r as size_t != n.try_into().unwrap() { panic!("error reading PNG"); }; diff --git a/dpx/src/dpx_sfnt.rs b/dpx/src/dpx_sfnt.rs index 55f1d9773..f412f25a9 100644 --- a/dpx/src/dpx_sfnt.rs +++ b/dpx/src/dpx_sfnt.rs @@ -37,7 +37,7 @@ use crate::dpx_pdfobj::{ }; use crate::dpx_truetype::SfntTableInfo; use crate::mfree; -use crate::{ttstub_input_read}; +use crate::{ttstub_input_read_exact}; use libc::{free, memcpy}; use std::io::{Seek, SeekFrom}; @@ -439,7 +439,7 @@ pub unsafe extern "C" fn sfnt_create_FontFile_stream(mut sfont: *mut sfnt) -> *m length = (*(*td).tables.offset(i as isize)).length as i32; (*sfont).handle.seek(SeekFrom::Start((*(*td).tables.offset(i as isize)).offset as u64)).unwrap(); while length > 0i32 { - let nb_read = ttstub_input_read( + let nb_read = ttstub_input_read_exact( (*sfont).handle.0.as_ptr(), wbuf.as_mut_ptr() as *mut i8, (if length < 1024i32 { length } else { 1024i32 }) as size_t, diff --git a/dpx/src/dpx_t1_load.rs b/dpx/src/dpx_t1_load.rs index 81f942eae..ac49a18a1 100644 --- a/dpx/src/dpx_t1_load.rs +++ b/dpx/src/dpx_t1_load.rs @@ -42,7 +42,7 @@ use super::dpx_pst_obj::pst_obj; use super::dpx_pst_obj::{ pst_data_ptr, pst_getIV, pst_getRV, pst_getSV, pst_release_obj, pst_type_of, }; -use crate::{ttstub_input_getc, ttstub_input_read}; +use crate::{ttstub_input_getc, ttstub_input_read_exact}; use libc::{free, memcpy, memmove, memset, strcmp, strcpy, strlen}; use std::io::{Seek, SeekFrom}; @@ -2121,7 +2121,7 @@ unsafe fn get_pfb_segment( as u32, ) as *mut u8; while slen > 0i32 { - let rlen = ttstub_input_read( + let rlen = ttstub_input_read_exact( handle.0.as_ptr(), (buffer as *mut i8).offset(bytesread as isize), slen as size_t, diff --git a/dpx/src/dpx_tt_glyf.rs b/dpx/src/dpx_tt_glyf.rs index ac582ba8c..ad614b093 100644 --- a/dpx/src/dpx_tt_glyf.rs +++ b/dpx/src/dpx_tt_glyf.rs @@ -38,7 +38,7 @@ use super::dpx_tt_table::{ tt_read_vhea_table, }; use crate::dpx_truetype::sfnt_table_info; -use crate::{ttstub_input_read}; +use crate::{ttstub_input_read_exact}; use libc::{free, memcpy, memset}; use std::io::{Seek, SeekFrom}; @@ -369,7 +369,7 @@ pub unsafe extern "C" fn tt_build_tables(mut sfont: *mut sfnt, mut g: *mut tt_gl 2i32, ) as isize); /* Read evrything else. */ - ttstub_input_read( + ttstub_input_read_exact( (*sfont).handle.0.as_ptr(), p as *mut i8, len.wrapping_sub(10_u32) as size_t, diff --git a/dpx/src/dpx_tt_post.rs b/dpx/src/dpx_tt_post.rs index 5dbf13592..c0a4cdb4b 100644 --- a/dpx/src/dpx_tt_post.rs +++ b/dpx/src/dpx_tt_post.rs @@ -35,7 +35,7 @@ use crate::streq_ptr; use crate::warn; use super::dpx_mem::{new, xstrdup}; -use crate::ttstub_input_read; +use crate::ttstub_input_read_exact; use libc::free; pub type __ssize_t = i64; @@ -116,7 +116,7 @@ unsafe fn read_v2_post_names(mut post: *mut tt_post_table, mut sfont: *mut sfnt) *fresh0 = new(((len + 1i32) as u32 as u64) .wrapping_mul(::std::mem::size_of::() as u64) as u32) as *mut i8; - ttstub_input_read( + ttstub_input_read_exact( handle.0.as_ptr(), *(*post).names.offset(i as isize), len as size_t, diff --git a/dpx/src/dpx_tt_table.rs b/dpx/src/dpx_tt_table.rs index 168e41e20..fd34bcab7 100644 --- a/dpx/src/dpx_tt_table.rs +++ b/dpx/src/dpx_tt_table.rs @@ -35,7 +35,7 @@ use crate::warn; use super::dpx_mem::new; use super::dpx_sfnt::{sfnt_find_table_len, sfnt_find_table_pos, sfnt_locate_table}; use crate::dpx_truetype::sfnt_table_info; -use crate::{ttstub_input_read}; +use crate::{ttstub_input_read_exact}; use std::io::{Seek, SeekFrom}; @@ -654,7 +654,7 @@ unsafe fn tt_get_name( length = (destlen as i32 - 1i32) as u16 } handle.seek(SeekFrom::Start(name_offset as u64 + string_offset as u64 + offset as u64)).unwrap(); - ttstub_input_read( + ttstub_input_read_exact( handle.0.as_ptr(), dest as *mut u8 as *mut i8, length as size_t, diff --git a/dpx/src/dpx_type1c.rs b/dpx/src/dpx_type1c.rs index c6f18aeb1..91f8106c6 100644 --- a/dpx/src/dpx_type1c.rs +++ b/dpx/src/dpx_type1c.rs @@ -64,7 +64,7 @@ use crate::dpx_pdfobj::{ pdf_release_obj, pdf_stream_dataptr, pdf_stream_length, STREAM_COMPRESS, }; use crate::shims::sprintf; -use crate::{ttstub_input_read}; +use crate::{ttstub_input_read_exact}; use libc::{free, strcmp, strlen}; use std::io::{Seek, SeekFrom}; @@ -514,7 +514,7 @@ pub unsafe extern "C" fn pdf_font_load_type1c(mut font: *mut pdf_font) -> i32 { *(*charstrings).offset.offset(0) = (charstring_len + 1i32) as l_offset; let handle = cffont.handle.as_mut().unwrap(); handle.seek(SeekFrom::Start(offset as u64 + *(*cs_idx).offset.offset(0) as u64 - 1)).unwrap(); - ttstub_input_read(handle.0.as_ptr(), data as *mut i8, size as size_t); + ttstub_input_read_exact(handle.0.as_ptr(), data as *mut i8, size as size_t); charstring_len += cs_copy_charstring( (*charstrings).data.offset(charstring_len as isize), max_len - charstring_len, @@ -620,7 +620,7 @@ pub unsafe extern "C" fn pdf_font_load_type1c(mut font: *mut pdf_font) -> i32 { (charstring_len + 1i32) as l_offset; let handle = cffont.handle.as_mut().unwrap(); handle.seek(SeekFrom::Start(offset as u64 + *(*cs_idx).offset.offset(gid_0 as isize) as u64 - 1)).unwrap(); - ttstub_input_read(handle.0.as_ptr(), data as *mut i8, size as size_t); + ttstub_input_read_exact(handle.0.as_ptr(), data as *mut i8, size as size_t); charstring_len += cs_copy_charstring( (*charstrings).data.offset(charstring_len as isize), max_len - charstring_len, diff --git a/dpx/src/dpx_vf.rs b/dpx/src/dpx_vf.rs index b5c012e6d..41f9ff352 100644 --- a/dpx/src/dpx_vf.rs +++ b/dpx/src/dpx_vf.rs @@ -44,7 +44,7 @@ use super::dpx_mem::{new, renew}; use super::dpx_numbers::{sqxfw, tt_skip_bytes}; use super::dpx_tfm::tfm_open; use super::dpx_dvicodes::*; -use crate::{ttstub_input_close, ttstub_input_open, ttstub_input_read}; +use crate::{ttstub_input_close, ttstub_input_open, ttstub_input_read_exact}; use libc::{free, strcpy, strlen}; pub type __off_t = i64; @@ -176,7 +176,7 @@ unsafe fn read_a_char_def( if pkt_len > 0_u32 { let pkt = new((pkt_len as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32) as *mut u8; - if ttstub_input_read(vf_handle.0.as_ptr(), pkt as *mut i8, pkt_len as size_t) != pkt_len as i64 { + if ttstub_input_read_exact(vf_handle.0.as_ptr(), pkt as *mut i8, pkt_len as size_t) != pkt_len as i64 { panic!("VF file ended prematurely."); } let ref mut fresh2 = *(*vf_fonts.offset(thisfont as isize)) @@ -221,14 +221,14 @@ unsafe fn read_a_font_def(vf_handle: &mut InputHandleWrapper, mut font_id: i32, (*dev_font).directory = new( ((dir_length + 1i32) as u32 as u64).wrapping_mul(::std::mem::size_of::() as u64) as u32 ) as *mut i8; - if ttstub_input_read(vf_handle.0.as_ptr(), (*dev_font).directory, dir_length as size_t) + if ttstub_input_read_exact(vf_handle.0.as_ptr(), (*dev_font).directory, dir_length as size_t) != dir_length as i64 { panic!("directory read failed"); } (*dev_font).name = new(((name_length + 1i32) as u32 as u64) .wrapping_mul(::std::mem::size_of::() as u64) as u32) as *mut i8; - if ttstub_input_read(vf_handle.0.as_ptr(), (*dev_font).name, name_length as size_t) != name_length as i64 { + if ttstub_input_read_exact(vf_handle.0.as_ptr(), (*dev_font).name, name_length as size_t) != name_length as i64 { panic!("directory read failed"); } *(*dev_font).directory.offset(dir_length as isize) = 0_i8; diff --git a/engine/Cargo.toml b/engine/Cargo.toml index d8903e321..6d486492c 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -15,7 +15,6 @@ repository = "https://github.com/tectonic-typesetting/tectonic/" readme = "README.md" license = "MIT" edition = "2018" - [build-dependencies] cc = "^1.0" pkg-config = "^0.3" # note: sync dist/docker/*/pkg-config-rs.sh with the version in Cargo.lock @@ -31,7 +30,17 @@ libc = "0.2" chrono = "0.4.9" #log = { version = "0.4", features = ["std"] } harfbuzz-sys = {version = "^0.3", default-features = false} -freetype-rs = "0.23.0" +euclid = "0.20.3" +freetype = "0.4.1" +cfg-if = "0.1.10" +enum_dispatch = "0.2.0" +once_cell = "1.2.0" + +[dependencies.font-kit] +version = "0.4.0" +# to minimize code change, we're using harfbuzz with freetype only +# but as font-kit takes over, this can go, and macOS gets to use Core Text, and Windows gets to use DirectWrite +features = ["loader-freetype", "loader-freetype-default"] [target.'cfg(target_os = "macos")'.dependencies] core-foundation = "0.7.0" diff --git a/engine/build.rs b/engine/build.rs index 2859fe275..c584fcfb1 100644 --- a/engine/build.rs +++ b/engine/build.rs @@ -20,8 +20,7 @@ const PKGCONFIG_LIBS: &'static str = // No fontconfig on MacOS: #[cfg(target_os = "macos")] -const PKGCONFIG_LIBS: &'static str = - "harfbuzz >= 1.4 harfbuzz-icu icu-uc freetype2 graphite2"; +const PKGCONFIG_LIBS: &'static str = "harfbuzz >= 1.4 harfbuzz-icu icu-uc freetype2 graphite2"; /// Build-script state when using pkg-config as the backend. #[derive(Debug)] diff --git a/engine/src/bibtex.rs b/engine/src/bibtex.rs index 9cfeec103..ab68e5921 100644 --- a/engine/src/bibtex.rs +++ b/engine/src/bibtex.rs @@ -76,19 +76,17 @@ const MAX_GLOB_STRS: i32 = 10; const MAX_FIELDS: i32 = 17250; const LIT_STK_SIZE: i32 = 100; -unsafe extern "C" fn peekable_open( +unsafe fn peekable_open( mut path: *const i8, mut format: TTInputFormat, ) -> Option { - ttstub_input_open(path, format, 0i32).map(|handle| { - peekable_input_t { - handle, - peek_char: -1, - saw_eof: false, - } + ttstub_input_open(path, format, 0i32).map(|handle| peekable_input_t { + handle, + peek_char: -1, + saw_eof: false, }) } -unsafe extern "C" fn peekable_close(peekable: Option) -> i32 { +unsafe fn peekable_close(peekable: Option) -> i32 { let mut rv: i32 = 0; if let Some(peekable_input_t { handle, .. }) = peekable { ttstub_input_close(handle) @@ -96,7 +94,7 @@ unsafe extern "C" fn peekable_close(peekable: Option) -> i32 { return 0; } } -unsafe extern "C" fn peekable_getc(peekable: &mut peekable_input_t) -> i32 { +unsafe fn peekable_getc(peekable: &mut peekable_input_t) -> i32 { let mut rv: i32 = 0; if peekable.peek_char != -1i32 { rv = peekable.peek_char; @@ -109,12 +107,12 @@ unsafe extern "C" fn peekable_getc(peekable: &mut peekable_input_t) -> i32 { } rv } -unsafe extern "C" fn peekable_ungetc(peekable: &mut peekable_input_t, mut c: i32) { +unsafe fn peekable_ungetc(peekable: &mut peekable_input_t, mut c: i32) { /* TODO: assert c != EOF */ peekable.peek_char = c; } /* eofeoln.c, adapted for Rusty I/O */ -unsafe extern "C" fn tectonic_eof(peekable: Option<&mut peekable_input_t>) -> bool { +unsafe fn tectonic_eof(peekable: Option<&mut peekable_input_t>) -> bool { /* Check for EOF following Pascal semantics. */ let mut c: i32 = 0; if peekable.is_none() { @@ -131,7 +129,7 @@ unsafe extern "C" fn tectonic_eof(peekable: Option<&mut peekable_input_t>) -> bo peekable_ungetc(peekable, c); false } -unsafe extern "C" fn eoln(peekable: &mut peekable_input_t) -> bool { +unsafe fn eoln(peekable: &mut peekable_input_t) -> bool { let mut c: i32 = 0; if peekable.saw_eof { return true; @@ -206,8 +204,8 @@ static mut scan_result: u8 = 0; static mut token_value: i32 = 0; static mut aux_name_length: i32 = 0; static mut aux_file: [Option; 21] = [ - None, None, None, None, None, None, None, None, None, None, None, - None, None, None, None, None, None, None, None, None, None + None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, ]; static mut aux_list: [str_number; 21] = [0; 21]; static mut aux_ptr: aux_number = 0; @@ -398,7 +396,7 @@ static mut min_crossrefs: i32 = 0; /*:473*/ /*12: *//*3: */ -unsafe extern "C" fn putc_log(c: i32) { +unsafe fn putc_log(c: i32) { ttstub_output_putc(log_file.as_mut().unwrap(), c); /* note: global! */ ttstub_output_putc(standard_output.as_mut().unwrap(), c); } @@ -411,7 +409,7 @@ macro_rules! log { }} } -unsafe extern "C" fn mark_warning() { +unsafe fn mark_warning() { if history == TTHistory::WARNING_ISSUED { err_count += 1 } else if history == TTHistory::SPOTLESS { @@ -419,7 +417,7 @@ unsafe extern "C" fn mark_warning() { err_count = 1i32 }; } -unsafe extern "C" fn mark_error() { +unsafe fn mark_error() { if (history as i32) < (TTHistory::ERROR_ISSUED as i32) { history = TTHistory::ERROR_ISSUED; err_count = 1i32 @@ -427,19 +425,19 @@ unsafe extern "C" fn mark_error() { err_count += 1 }; } -unsafe extern "C" fn mark_fatal() { +unsafe fn mark_fatal() { history = TTHistory::FATAL_ERROR; } -unsafe extern "C" fn print_overflow() { +unsafe fn print_overflow() { log!("Sorry---you\'ve exceeded BibTeX\'s "); mark_fatal(); } -unsafe extern "C" fn print_confusion() { +unsafe fn print_confusion() { log!("---this can\'t happen\n"); log!("*Please notify the BibTeX maintainer*\n"); mark_fatal(); } -unsafe extern "C" fn buffer_overflow() { +unsafe fn buffer_overflow() { buffer = xrealloc( buffer as *mut libc::c_void, ((buf_size + 20000i32 + 1i32) as u64).wrapping_mul(::std::mem::size_of::() as u64), @@ -467,7 +465,7 @@ unsafe extern "C" fn buffer_overflow() { ) as *mut u8; buf_size = buf_size + 20000i32; } -unsafe extern "C" fn input_ln(peekable: &mut Option) -> bool { +unsafe fn input_ln(peekable: &mut Option) -> bool { last = 0i32; if tectonic_eof(peekable.as_mut()) { return false; @@ -490,7 +488,7 @@ unsafe extern "C" fn input_ln(peekable: &mut Option) -> bool { } true } -unsafe extern "C" fn out_pool_str(handle: &mut OutputHandleWrapper, mut s: str_number) { +unsafe fn out_pool_str(handle: &mut OutputHandleWrapper, mut s: str_number) { let mut i: pool_pointer = 0; if s < 0i32 || s >= str_ptr + 3i32 || s >= max_strings { log!("Illegal string number:{}", s); @@ -503,11 +501,11 @@ unsafe extern "C" fn out_pool_str(handle: &mut OutputHandleWrapper, mut s: str_n i += 1 } } -unsafe extern "C" fn print_a_pool_str(mut s: str_number) { +unsafe fn print_a_pool_str(mut s: str_number) { out_pool_str(standard_output.as_mut().unwrap(), s); out_pool_str(log_file.as_mut().unwrap(), s); } -unsafe extern "C" fn pool_overflow() { +unsafe fn pool_overflow() { str_pool = xrealloc( str_pool as *mut libc::c_void, ((pool_size as i64 + 65000 + 1i32 as i64) as u64) @@ -515,16 +513,16 @@ unsafe extern "C" fn pool_overflow() { ) as *mut u8; pool_size = (pool_size as i64 + 65000) as i32; } -unsafe extern "C" fn out_token(handle: &mut OutputHandleWrapper) { +unsafe fn out_token(handle: &mut OutputHandleWrapper) { for i in buf_ptr1..buf_ptr2 { ttstub_output_putc(handle, *buffer.offset(i as isize) as i32); } } -unsafe extern "C" fn print_a_token() { +unsafe fn print_a_token() { out_token(standard_output.as_mut().unwrap()); out_token(log_file.as_mut().unwrap()); } -unsafe extern "C" fn print_bad_input_line() { +unsafe fn print_bad_input_line() { let mut bf_ptr: buf_pointer = 0; log!(" : "); bf_ptr = 0i32; @@ -570,10 +568,10 @@ unsafe extern "C" fn print_bad_input_line() { } mark_error(); } -unsafe extern "C" fn print_skipping_whatever_remains() { +unsafe fn print_skipping_whatever_remains() { log!("I\'m skipping whatever remains of this "); } -unsafe extern "C" fn sam_wrong_file_name_print() { +unsafe fn sam_wrong_file_name_print() { let mut output = standard_output.as_mut().unwrap(); write!(output, "I couldn\'t open file name `").unwrap(); name_ptr = 0i32; @@ -585,23 +583,23 @@ unsafe extern "C" fn sam_wrong_file_name_print() { ttstub_output_putc(output, '\'' as i32); ttstub_output_putc(output, '\n' as i32); } -unsafe extern "C" fn print_aux_name() { +unsafe fn print_aux_name() { print_a_pool_str(aux_list[aux_ptr as usize]); putc_log('\n' as i32); } -unsafe extern "C" fn log_pr_aux_name() { +unsafe fn log_pr_aux_name() { let lg = log_file.as_mut().unwrap(); out_pool_str(lg, aux_list[aux_ptr as usize]); ttstub_output_putc(lg, '\n' as i32); } -unsafe extern "C" fn aux_err_print() { +unsafe fn aux_err_print() { log!("---line {} of file ", aux_ln_stack[aux_ptr as usize]); print_aux_name(); print_bad_input_line(); print_skipping_whatever_remains(); log!("command\n"); } -unsafe extern "C" fn aux_err_illegal_another_print(cmd_num: i32) { +unsafe fn aux_err_illegal_another_print(cmd_num: i32) { log!("Illegal, another \\bib"); match cmd_num { 0 => { @@ -618,43 +616,43 @@ unsafe extern "C" fn aux_err_illegal_another_print(cmd_num: i32) { } log!(" command"); } -unsafe extern "C" fn aux_err_no_right_brace_print() { +unsafe fn aux_err_no_right_brace_print() { log!("No \"}}\""); } -unsafe extern "C" fn aux_err_stuff_after_right_brace_print() { +unsafe fn aux_err_stuff_after_right_brace_print() { log!("Stuff after \"}}\""); } -unsafe extern "C" fn aux_err_white_space_in_argument_print() { +unsafe fn aux_err_white_space_in_argument_print() { log!("White space in argument"); } -unsafe extern "C" fn print_bib_name() { +unsafe fn print_bib_name() { print_a_pool_str(*bib_list.offset(bib_ptr as isize)); print_a_pool_str(s_bib_extension); putc_log('\n' as i32); } -unsafe extern "C" fn log_pr_bib_name() { +unsafe fn log_pr_bib_name() { let lg = log_file.as_mut().unwrap(); out_pool_str(lg, *bib_list.offset(bib_ptr as isize)); out_pool_str(lg, s_bib_extension); ttstub_output_putc(lg, '\n' as i32); } -unsafe extern "C" fn print_bst_name() { +unsafe fn print_bst_name() { print_a_pool_str(bst_str); print_a_pool_str(s_bst_extension); putc_log('\n' as i32); } -unsafe extern "C" fn log_pr_bst_name() { +unsafe fn log_pr_bst_name() { let lg = log_file.as_mut().unwrap(); out_pool_str(lg, bst_str); out_pool_str(lg, s_bst_extension); ttstub_output_putc(lg, '\n' as i32); } -unsafe extern "C" fn hash_cite_confusion() { +unsafe fn hash_cite_confusion() { log!("Cite hash error"); print_confusion(); panic!(); } -unsafe extern "C" fn check_cite_overflow(mut last_cite: cite_number) { +unsafe fn check_cite_overflow(mut last_cite: cite_number) { if last_cite == max_cites { cite_list = xrealloc( cite_list as *mut libc::c_void, @@ -683,19 +681,19 @@ unsafe extern "C" fn check_cite_overflow(mut last_cite: cite_number) { } }; } -unsafe extern "C" fn aux_end1_err_print() { +unsafe fn aux_end1_err_print() { log!("I found no "); } -unsafe extern "C" fn aux_end2_err_print() { +unsafe fn aux_end2_err_print() { log!("---while reading file "); print_aux_name(); mark_error(); } -unsafe extern "C" fn bst_ln_num_print() { +unsafe fn bst_ln_num_print() { log!("--line {} of file ", bst_line_num); print_bst_name(); } -unsafe extern "C" fn bst_err_print_and_look_for_blank_line() { +unsafe fn bst_err_print_and_look_for_blank_line() { putc_log('-' as i32); bst_ln_num_print(); print_bad_input_line(); @@ -708,19 +706,19 @@ unsafe extern "C" fn bst_err_print_and_look_for_blank_line() { } buf_ptr2 = last; } -unsafe extern "C" fn bst_warn_print() { +unsafe fn bst_warn_print() { bst_ln_num_print(); mark_warning(); } -unsafe extern "C" fn eat_bst_print() { +unsafe fn eat_bst_print() { log!("Illegal end of style file in command: "); } -unsafe extern "C" fn unknwn_function_class_confusion() { +unsafe fn unknwn_function_class_confusion() { log!("Unknown function class"); print_confusion(); panic!(); } -unsafe extern "C" fn print_fn_class(fn_loc_0: hash_loc) { +unsafe fn print_fn_class(fn_loc_0: hash_loc) { match *fn_type.offset(fn_loc_0 as isize) as i32 { 0 => { log!("built-in"); @@ -756,12 +754,12 @@ unsafe extern "C" fn print_fn_class(fn_loc_0: hash_loc) { } /*:159*/ /*160: */ -unsafe extern "C" fn id_scanning_confusion() { +unsafe fn id_scanning_confusion() { log!("Identifier scanning error"); print_confusion(); panic!(); } -unsafe extern "C" fn bst_id_print() { +unsafe fn bst_id_print() { if scan_result as i32 == 0i32 { /*id_null */ log!( @@ -778,24 +776,24 @@ unsafe extern "C" fn bst_id_print() { id_scanning_confusion(); }; } -unsafe extern "C" fn bst_left_brace_print() { +unsafe fn bst_left_brace_print() { log!("\"{{\" is missing in command: "); } -unsafe extern "C" fn bst_right_brace_print() { +unsafe fn bst_right_brace_print() { log!("\"}}\" is missing in command: "); } -unsafe extern "C" fn already_seen_function_print(mut seen_fn_loc: hash_loc) { +unsafe fn already_seen_function_print(mut seen_fn_loc: hash_loc) { print_a_pool_str(*hash_text.offset(seen_fn_loc as isize)); log!(" is already a type \""); print_fn_class(seen_fn_loc); log!("\" function name\n"); bst_err_print_and_look_for_blank_line(); } -unsafe extern "C" fn bib_ln_num_print() { +unsafe fn bib_ln_num_print() { log!("--line {} of file", bib_line_num); print_bib_name(); } -unsafe extern "C" fn bib_err_print() { +unsafe fn bib_err_print() { putc_log('-' as i32); bib_ln_num_print(); print_bad_input_line(); @@ -806,11 +804,11 @@ unsafe extern "C" fn bib_err_print() { log!("entry\n"); }; } -unsafe extern "C" fn bib_warn_print() { +unsafe fn bib_warn_print() { bib_ln_num_print(); mark_warning(); } -unsafe extern "C" fn check_field_overflow(mut total_fields: i32) { +unsafe fn check_field_overflow(mut total_fields: i32) { let mut f_ptr: field_loc = 0; let mut start_fields: field_loc = 0; if total_fields > max_fields { @@ -837,11 +835,11 @@ unsafe extern "C" fn check_field_overflow(mut total_fields: i32) { } }; } -unsafe extern "C" fn eat_bib_print() { +unsafe fn eat_bib_print() { log!("Illegal end of database file"); bib_err_print(); } -unsafe extern "C" fn bib_one_of_two_print(mut char1: u8, mut char2: u8) { +unsafe fn bib_one_of_two_print(mut char1: u8, mut char2: u8) { log!( "I was expecting a `{}' or a `{}'", char1 as char, @@ -849,24 +847,24 @@ unsafe extern "C" fn bib_one_of_two_print(mut char1: u8, mut char2: u8) { ); bib_err_print(); } -unsafe extern "C" fn bib_equals_sign_print() { +unsafe fn bib_equals_sign_print() { log!("I was expecting an \"=\""); bib_err_print(); } -unsafe extern "C" fn bib_unbalanced_braces_print() { +unsafe fn bib_unbalanced_braces_print() { log!("Unbalanced braces"); bib_err_print(); } -unsafe extern "C" fn bib_field_too_long_print() { +unsafe fn bib_field_too_long_print() { log!("Your field is more than {} characters", buf_size); bib_err_print(); } -unsafe extern "C" fn macro_warn_print() { +unsafe fn macro_warn_print() { log!("Warning--string name \""); print_a_token(); log!("\" is "); } -unsafe extern "C" fn bib_id_print() { +unsafe fn bib_id_print() { if scan_result as i32 == 0i32 { /*id_null */ log!("You\'re missing "); @@ -880,17 +878,17 @@ unsafe extern "C" fn bib_id_print() { id_scanning_confusion(); }; } -unsafe extern "C" fn bib_cmd_confusion() { +unsafe fn bib_cmd_confusion() { log!("Unknown database-file command"); print_confusion(); panic!(); } -unsafe extern "C" fn cite_key_disappeared_confusion() { +unsafe fn cite_key_disappeared_confusion() { log!("A cite key disappeared"); print_confusion(); panic!(); } -unsafe extern "C" fn bad_cross_reference_print(mut s: str_number) { +unsafe fn bad_cross_reference_print(mut s: str_number) { log!("--entry \""); print_a_pool_str(*cite_list.offset(cite_ptr as isize)); putc_log('\"' as i32); @@ -898,20 +896,20 @@ unsafe extern "C" fn bad_cross_reference_print(mut s: str_number) { log!("refers to entry \""); print_a_pool_str(s); } -unsafe extern "C" fn nonexistent_cross_reference_error() { +unsafe fn nonexistent_cross_reference_error() { log!("A bad cross reference-"); bad_cross_reference_print(*field_info.offset(field_ptr as isize)); log!("\", which doesn\'t exist\n"); mark_error(); } -unsafe extern "C" fn print_missing_entry(mut s: str_number) { +unsafe fn print_missing_entry(mut s: str_number) { log!("Warning--I didn\'t find a database entry for \""); print_a_pool_str(s); putc_log('\"' as i32); putc_log('\n' as i32); mark_warning(); } -unsafe extern "C" fn bst_ex_warn_print() { +unsafe fn bst_ex_warn_print() { if mess_with_entries { log!(" for entry "); print_a_pool_str(*cite_list.offset(cite_ptr as isize)); @@ -921,7 +919,7 @@ unsafe extern "C" fn bst_ex_warn_print() { bst_ln_num_print(); mark_error(); } -unsafe extern "C" fn bst_mild_ex_warn_print() { +unsafe fn bst_mild_ex_warn_print() { if mess_with_entries { log!(" for entry "); print_a_pool_str(*cite_list.offset(cite_ptr as isize)); @@ -930,21 +928,21 @@ unsafe extern "C" fn bst_mild_ex_warn_print() { log!("while executing"); bst_warn_print(); } -unsafe extern "C" fn bst_cant_mess_with_entries_print() { +unsafe fn bst_cant_mess_with_entries_print() { log!("You can\'t mess with entries here"); bst_ex_warn_print(); } -unsafe extern "C" fn illegl_literal_confusion() { +unsafe fn illegl_literal_confusion() { log!("Illegal literal type"); print_confusion(); panic!(); } -unsafe extern "C" fn unknwn_literal_confusion() { +unsafe fn unknwn_literal_confusion() { log!("Unknown literal type"); print_confusion(); panic!(); } -unsafe extern "C" fn print_stk_lit(mut stk_lt: i32, mut stk_tp: stk_type) { +unsafe fn print_stk_lit(mut stk_lt: i32, mut stk_tp: stk_type) { match stk_tp as i32 { 0 => { log!("{} is an integer literal", stk_lt); @@ -972,7 +970,7 @@ unsafe extern "C" fn print_stk_lit(mut stk_lt: i32, mut stk_tp: stk_type) { } }; } -unsafe extern "C" fn print_lit(mut stk_lt: i32, mut stk_tp: stk_type) { +unsafe fn print_lit(mut stk_lt: i32, mut stk_tp: stk_type) { match stk_tp as i32 { 0 => { log!("{}\n", stk_lt); @@ -997,7 +995,7 @@ unsafe extern "C" fn print_lit(mut stk_lt: i32, mut stk_tp: stk_type) { } }; } -unsafe extern "C" fn output_bbl_line() { +unsafe fn output_bbl_line() { let bbl = bbl_file.as_mut().unwrap(); if out_buf_length != 0i32 { while out_buf_length > 0i32 { @@ -1022,26 +1020,26 @@ unsafe extern "C" fn output_bbl_line() { bbl_line_num += 1; out_buf_length = 0i32; } -unsafe extern "C" fn bst_1print_string_size_exceeded() { +unsafe fn bst_1print_string_size_exceeded() { log!("Warning--you\'ve exceeded "); } -unsafe extern "C" fn bst_2print_string_size_exceeded() { +unsafe fn bst_2print_string_size_exceeded() { log!("-string-size,"); bst_mild_ex_warn_print(); log!("*Please notify the bibstyle designer*\n"); } -unsafe extern "C" fn braces_unbalanced_complaint(mut pop_lit_var: str_number) { +unsafe fn braces_unbalanced_complaint(mut pop_lit_var: str_number) { log!("Warning--\""); print_a_pool_str(pop_lit_var); log!("\" isn\'t a brace-balanced string"); bst_mild_ex_warn_print(); } -unsafe extern "C" fn case_conversion_confusion() { +unsafe fn case_conversion_confusion() { log!("Unknown type of case conversion"); print_confusion(); panic!(); } -unsafe extern "C" fn start_name(mut file_name: str_number) { +unsafe fn start_name(mut file_name: str_number) { let mut p_ptr: pool_pointer = 0; free(name_of_file as *mut libc::c_void); name_of_file = xmalloc( @@ -1061,7 +1059,7 @@ unsafe extern "C" fn start_name(mut file_name: str_number) { *str_start.offset((file_name + 1i32) as isize) - *str_start.offset(file_name as isize); *name_of_file.offset(name_length as isize) = 0i32 as u8; } -unsafe extern "C" fn add_extension(mut ext: str_number) { +unsafe fn add_extension(mut ext: str_number) { let mut p_ptr: pool_pointer = 0; name_ptr = name_length; p_ptr = *str_start.offset(ext as isize); @@ -1073,7 +1071,7 @@ unsafe extern "C" fn add_extension(mut ext: str_number) { name_length += *str_start.offset((ext + 1i32) as isize) - *str_start.offset(ext as isize); *name_of_file.offset(name_length as isize) = 0i32 as u8; } -unsafe extern "C" fn make_string() -> str_number { +unsafe fn make_string() -> str_number { if str_ptr == max_strings { print_overflow(); log!("number of strings {}\n", max_strings); @@ -1083,7 +1081,7 @@ unsafe extern "C" fn make_string() -> str_number { *str_start.offset(str_ptr as isize) = pool_ptr; str_ptr - 1i32 } -unsafe extern "C" fn str_eq_buf( +unsafe fn str_eq_buf( mut s: str_number, mut buf: buf_type, mut bf_ptr: buf_pointer, @@ -1105,7 +1103,7 @@ unsafe extern "C" fn str_eq_buf( } true } -unsafe extern "C" fn str_eq_str(mut s1: str_number, mut s2: str_number) -> bool { +unsafe fn str_eq_str(mut s1: str_number, mut s2: str_number) -> bool { if *str_start.offset((s1 + 1i32) as isize) - *str_start.offset(s1 as isize) != *str_start.offset((s2 + 1i32) as isize) - *str_start.offset(s2 as isize) { @@ -1122,7 +1120,7 @@ unsafe extern "C" fn str_eq_str(mut s1: str_number, mut s2: str_number) -> bool } true } -unsafe extern "C" fn lower_case(mut buf: buf_type, mut bf_ptr: buf_pointer, mut len: buf_pointer) { +unsafe fn lower_case(mut buf: buf_type, mut bf_ptr: buf_pointer, mut len: buf_pointer) { let mut i: buf_pointer = 0; if len > 0i32 { let mut for_end: i32 = 0; @@ -1144,7 +1142,7 @@ unsafe extern "C" fn lower_case(mut buf: buf_type, mut bf_ptr: buf_pointer, mut } }; } -unsafe extern "C" fn upper_case(mut buf: buf_type, mut bf_ptr: buf_pointer, mut len: buf_pointer) { +unsafe fn upper_case(mut buf: buf_type, mut bf_ptr: buf_pointer, mut len: buf_pointer) { let mut i: buf_pointer = 0; if len > 0i32 { let mut for_end: i32 = 0; @@ -1166,7 +1164,7 @@ unsafe extern "C" fn upper_case(mut buf: buf_type, mut bf_ptr: buf_pointer, mut } }; } -unsafe extern "C" fn str_lookup( +unsafe fn str_lookup( mut buf: buf_type, mut j: buf_pointer, mut l: buf_pointer, @@ -1241,7 +1239,7 @@ unsafe extern "C" fn str_lookup( p = *hash_next.offset(p as isize) } } -unsafe extern "C" fn pre_define(pds: pds_type, len: pds_len, ilk: str_ilk) { +unsafe fn pre_define(pds: pds_type, len: pds_len, ilk: str_ilk) { let mut i: pds_len = 1; let for_end = len as i32; if i as i32 <= for_end { @@ -1256,7 +1254,7 @@ unsafe extern "C" fn pre_define(pds: pds_type, len: pds_len, ilk: str_ilk) { } pre_def_loc = str_lookup(buffer, 1i32, len as buf_pointer, ilk, true); } -unsafe extern "C" fn int_to_ASCII( +unsafe fn int_to_ASCII( mut the_int: i32, mut int_buf: buf_type, mut int_begin: buf_pointer, @@ -1297,7 +1295,7 @@ unsafe extern "C" fn int_to_ASCII( int_xptr = int_xptr + 1i32 } } -unsafe extern "C" fn add_database_cite(mut new_cite: *mut cite_number) { +unsafe fn add_database_cite(mut new_cite: *mut cite_number) { check_cite_overflow(*new_cite); check_field_overflow(num_fields * (*new_cite + 1i32)); *cite_list.offset(*new_cite as isize) = *hash_text.offset(cite_loc as isize); @@ -1305,7 +1303,7 @@ unsafe extern "C" fn add_database_cite(mut new_cite: *mut cite_number) { *ilk_info.offset(lc_cite_loc as isize) = cite_loc; *new_cite = *new_cite + 1i32; } -unsafe extern "C" fn find_cite_locs_for_this_cite_key(mut cite_str: str_number) -> bool { +unsafe fn find_cite_locs_for_this_cite_key(mut cite_str: str_number) -> bool { ex_buf_ptr = 0i32; tmp_ptr = *str_start.offset(cite_str as isize); tmp_end_ptr = *str_start.offset((cite_str + 1i32) as isize); @@ -1336,13 +1334,13 @@ unsafe extern "C" fn find_cite_locs_for_this_cite_key(mut cite_str: str_number) ); hash_found } -unsafe extern "C" fn swap(mut swap1: cite_number, mut swap2: cite_number) { +unsafe fn swap(mut swap1: cite_number, mut swap2: cite_number) { let mut innocent_bystander: cite_number = 0; innocent_bystander = *cite_info.offset(swap2 as isize); *cite_info.offset(swap2 as isize) = *cite_info.offset(swap1 as isize); *cite_info.offset(swap1 as isize) = innocent_bystander; } -unsafe extern "C" fn less_than(mut arg1: cite_number, mut arg2: cite_number) -> bool { +unsafe fn less_than(mut arg1: cite_number, mut arg2: cite_number) -> bool { let mut char_ptr: i32 = 0; let mut ptr1: str_ent_loc = 0; let mut ptr2: str_ent_loc = 0; @@ -1387,7 +1385,7 @@ unsafe extern "C" fn less_than(mut arg1: cite_number, mut arg2: cite_number) -> char_ptr = char_ptr + 1i32 } } -unsafe extern "C" fn quick_sort(mut left_end: cite_number, mut right_end: cite_number) { +unsafe fn quick_sort(mut left_end: cite_number, mut right_end: cite_number) { let mut left: cite_number = 0; let mut right: cite_number = 0; let mut insert_ptr: cite_number = 0; @@ -1482,7 +1480,7 @@ unsafe extern "C" fn quick_sort(mut left_end: cite_number, mut right_end: cite_n quick_sort(left, right_end); /*int_global_var */ }; } -unsafe extern "C" fn build_in( +unsafe fn build_in( pds: pds_type, len: pds_len, fn_hash_loc: &mut hash_loc, @@ -1493,7 +1491,7 @@ unsafe extern "C" fn build_in( *fn_type.offset(*fn_hash_loc as isize) = 0i32 as fn_class; *ilk_info.offset(*fn_hash_loc as isize) = blt_in_num; } -unsafe extern "C" fn pre_def_certain_strings() { +unsafe fn pre_def_certain_strings() { pre_define(b".aux \x00" as *const u8 as *const i8, 4, 7); s_aux_extension = *hash_text.offset(pre_def_loc as isize); pre_define(b".bbl \x00" as *const u8 as *const i8, 4, 7); @@ -1892,14 +1890,14 @@ unsafe extern "C" fn pre_def_certain_strings() { *fn_type.offset(pre_def_loc as isize) = 7i32 as fn_class; *ilk_info.offset(pre_def_loc as isize) = glob_str_size; } -unsafe extern "C" fn scan1(mut char1: u8) -> bool { +unsafe fn scan1(mut char1: u8) -> bool { buf_ptr1 = buf_ptr2; while buf_ptr2 < last && *buffer.offset(buf_ptr2 as isize) as i32 != char1 as i32 { buf_ptr2 = buf_ptr2 + 1i32 } buf_ptr2 < last } -unsafe extern "C" fn scan1_white(mut char1: u8) -> bool { +unsafe fn scan1_white(mut char1: u8) -> bool { buf_ptr1 = buf_ptr2; while buf_ptr2 < last && lex_class[*buffer.offset(buf_ptr2 as isize) as usize] as i32 != 1i32 @@ -1909,7 +1907,7 @@ unsafe extern "C" fn scan1_white(mut char1: u8) -> bool { } buf_ptr2 < last } -unsafe extern "C" fn scan2(mut char1: u8, mut char2: u8) -> bool { +unsafe fn scan2(mut char1: u8, mut char2: u8) -> bool { buf_ptr1 = buf_ptr2; while buf_ptr2 < last && *buffer.offset(buf_ptr2 as isize) as i32 != char1 as i32 @@ -1919,7 +1917,7 @@ unsafe extern "C" fn scan2(mut char1: u8, mut char2: u8) -> bool { } buf_ptr2 < last } -unsafe extern "C" fn scan2_white(mut char1: u8, mut char2: u8) -> bool { +unsafe fn scan2_white(mut char1: u8, mut char2: u8) -> bool { buf_ptr1 = buf_ptr2; while buf_ptr2 < last && *buffer.offset(buf_ptr2 as isize) as i32 != char1 as i32 @@ -1930,7 +1928,7 @@ unsafe extern "C" fn scan2_white(mut char1: u8, mut char2: u8) -> bool { } buf_ptr2 < last } -unsafe extern "C" fn scan3(mut char1: u8, mut char2: u8, mut char3: u8) -> bool { +unsafe fn scan3(mut char1: u8, mut char2: u8, mut char3: u8) -> bool { buf_ptr1 = buf_ptr2; while buf_ptr2 < last && *buffer.offset(buf_ptr2 as isize) as i32 != char1 as i32 @@ -1941,14 +1939,14 @@ unsafe extern "C" fn scan3(mut char1: u8, mut char2: u8, mut char3: u8) -> bool } buf_ptr2 < last } -unsafe extern "C" fn scan_alpha() -> bool { +unsafe fn scan_alpha() -> bool { buf_ptr1 = buf_ptr2; while buf_ptr2 < last && lex_class[*buffer.offset(buf_ptr2 as isize) as usize] as i32 == 2i32 { buf_ptr2 = buf_ptr2 + 1i32 } buf_ptr2 - buf_ptr1 != 0i32 } -unsafe extern "C" fn scan_identifier(mut char1: u8, mut char2: u8, mut char3: u8) { +unsafe fn scan_identifier(mut char1: u8, mut char2: u8, mut char3: u8) { buf_ptr1 = buf_ptr2; if lex_class[*buffer.offset(buf_ptr2 as isize) as usize] as i32 != 3i32 { /*numeric */ @@ -1974,7 +1972,7 @@ unsafe extern "C" fn scan_identifier(mut char1: u8, mut char2: u8, mut char3: u8 }; /*specified_char_adjacent */ /*other_char_adjacent */ } -unsafe extern "C" fn scan_nonneg_integer() -> bool { +unsafe fn scan_nonneg_integer() -> bool { buf_ptr1 = buf_ptr2; token_value = 0i32; while buf_ptr2 < last && lex_class[*buffer.offset(buf_ptr2 as isize) as usize] as i32 == 3i32 { @@ -1983,7 +1981,7 @@ unsafe extern "C" fn scan_nonneg_integer() -> bool { } buf_ptr2 - buf_ptr1 != 0i32 } -unsafe extern "C" fn scan_integer() -> bool { +unsafe fn scan_integer() -> bool { let mut sign_length: u8 = 0; buf_ptr1 = buf_ptr2; if *buffer.offset(buf_ptr2 as isize) as i32 == 45i32 { @@ -2003,13 +2001,13 @@ unsafe extern "C" fn scan_integer() -> bool { } buf_ptr2 - buf_ptr1 != sign_length as i32 } -unsafe extern "C" fn scan_white_space() -> bool { +unsafe fn scan_white_space() -> bool { while buf_ptr2 < last && lex_class[*buffer.offset(buf_ptr2 as isize) as usize] as i32 == 1i32 { buf_ptr2 = buf_ptr2 + 1i32 } buf_ptr2 < last } -unsafe extern "C" fn eat_bst_white_space() -> bool { +unsafe fn eat_bst_white_space() -> bool { loop { if scan_white_space() { if *buffer.offset(buf_ptr2 as isize) as i32 != 37i32 { @@ -2024,32 +2022,32 @@ unsafe extern "C" fn eat_bst_white_space() -> bool { buf_ptr2 = 0i32 } } -unsafe extern "C" fn skip_token_print() { +unsafe fn skip_token_print() { putc_log('-' as i32); bst_ln_num_print(); mark_error(); scan2_white(125i32 as u8, 37i32 as u8); } -unsafe extern "C" fn print_recursion_illegal() { +unsafe fn print_recursion_illegal() { log!("Curse you, wizard, before you recurse me:\n"); log!("function "); print_a_token(); log!(" is illegal in its own definition\n"); skip_token_print(); } -unsafe extern "C" fn skp_token_unknown_function_print() { +unsafe fn skp_token_unknown_function_print() { print_a_token(); log!(" is an unknown function"); skip_token_print(); } -unsafe extern "C" fn skip_illegal_stuff_after_token_print() { +unsafe fn skip_illegal_stuff_after_token_print() { log!( "\"{}\" can't follow a literal", *buffer.offset(buf_ptr2 as isize) as char ); skip_token_print(); } -unsafe extern "C" fn scan_fn_def(mut fn_hash_loc: hash_loc) { +unsafe fn scan_fn_def(mut fn_hash_loc: hash_loc) { let mut singl_function: *mut hash_ptr2 = 0 as *mut hash_ptr2; let mut single_fn_space: i32 = 0; let mut single_ptr: fn_def_loc = 0; @@ -2296,7 +2294,7 @@ unsafe extern "C" fn scan_fn_def(mut fn_hash_loc: hash_loc) { } exit(singl_function); } -unsafe extern "C" fn eat_bib_white_space() -> bool { +unsafe fn eat_bib_white_space() -> bool { while !scan_white_space() { if !input_ln(&mut bib_file[bib_ptr]) { return false; @@ -2306,7 +2304,7 @@ unsafe extern "C" fn eat_bib_white_space() -> bool { } true } -unsafe extern "C" fn compress_bib_white() -> bool { +unsafe fn compress_bib_white() -> bool { if ex_buf_ptr == buf_size { bib_field_too_long_print(); return false; @@ -2324,7 +2322,7 @@ unsafe extern "C" fn compress_bib_white() -> bool { } true } -unsafe extern "C" fn scan_balanced_braces() -> bool { +unsafe fn scan_balanced_braces() -> bool { buf_ptr2 = buf_ptr2 + 1i32; if lex_class[*buffer.offset(buf_ptr2 as isize) as usize] as i32 == 1i32 || buf_ptr2 == last { if !compress_bib_white() { @@ -2506,7 +2504,7 @@ unsafe extern "C" fn scan_balanced_braces() -> bool { buf_ptr2 = buf_ptr2 + 1i32; true } -unsafe extern "C" fn scan_a_field_token_and_eat_white() -> bool { +unsafe fn scan_a_field_token_and_eat_white() -> bool { match *buffer.offset(buf_ptr2 as isize) as i32 { 123 => { right_str_delim = 125i32 as u8; @@ -2634,7 +2632,7 @@ unsafe extern "C" fn scan_a_field_token_and_eat_white() -> bool { } true } -unsafe extern "C" fn scan_and_store_the_field_value_and_eat_white() -> bool { +unsafe fn scan_and_store_the_field_value_and_eat_white() -> bool { ex_buf_ptr = 0i32; if !scan_a_field_token_and_eat_white() { return false; @@ -2748,19 +2746,19 @@ unsafe extern "C" fn scan_and_store_the_field_value_and_eat_white() -> bool { } true } -unsafe extern "C" fn decr_brace_level(mut pop_lit_var: str_number) { +unsafe fn decr_brace_level(mut pop_lit_var: str_number) { if brace_level == 0i32 { braces_unbalanced_complaint(pop_lit_var); } else { brace_level = brace_level - 1i32 }; } -unsafe extern "C" fn check_brace_level(mut pop_lit_var: str_number) { +unsafe fn check_brace_level(mut pop_lit_var: str_number) { if brace_level > 0i32 { braces_unbalanced_complaint(pop_lit_var); }; } -unsafe extern "C" fn name_scan_for_and(mut pop_lit_var: str_number) { +unsafe fn name_scan_for_and(mut pop_lit_var: str_number) { brace_level = 0i32; preceding_white = false; and_found = false; @@ -2825,7 +2823,7 @@ unsafe extern "C" fn name_scan_for_and(mut pop_lit_var: str_number) { } check_brace_level(pop_lit_var); } -unsafe extern "C" fn von_token_found() -> bool { +unsafe fn von_token_found() -> bool { nm_brace_level = 0i32; while name_bf_ptr < name_bf_xptr { if *sv_buffer.offset(name_bf_ptr as isize) as i32 >= 'A' as i32 @@ -2918,7 +2916,7 @@ unsafe extern "C" fn von_token_found() -> bool { } false } -unsafe extern "C" fn von_name_ends_and_last_name_starts_stuff() { +unsafe fn von_name_ends_and_last_name_starts_stuff() { von_end = last_end - 1i32; while von_end > von_start { name_bf_ptr = *name_tok.offset((von_end - 1i32) as isize); @@ -2929,7 +2927,7 @@ unsafe extern "C" fn von_name_ends_and_last_name_starts_stuff() { von_end = von_end - 1i32 } } -unsafe extern "C" fn skip_stuff_at_sp_brace_level_greater_than_one() { +unsafe fn skip_stuff_at_sp_brace_level_greater_than_one() { while sp_brace_level > 1i32 && sp_ptr < sp_end { if *str_pool.offset(sp_ptr as isize) as i32 == 125i32 { /*right_brace */ @@ -2941,13 +2939,13 @@ unsafe extern "C" fn skip_stuff_at_sp_brace_level_greater_than_one() { sp_ptr = sp_ptr + 1i32 } } -unsafe extern "C" fn brace_lvl_one_letters_complaint() { +unsafe fn brace_lvl_one_letters_complaint() { log!("The format string \""); print_a_pool_str(pop_lit1); log!("\" has an illegal brace-level-1 letter"); bst_ex_warn_print(); } -unsafe extern "C" fn enough_text_chars(mut enough_chars: buf_pointer) -> bool { +unsafe fn enough_text_chars(mut enough_chars: buf_pointer) -> bool { num_text_chars = 0i32; ex_buf_yptr = ex_buf_xptr; while ex_buf_yptr < ex_buf_ptr && num_text_chars < enough_chars { @@ -2979,7 +2977,7 @@ unsafe extern "C" fn enough_text_chars(mut enough_chars: buf_pointer) -> bool { } num_text_chars >= enough_chars } -unsafe extern "C" fn figure_out_the_formatted_name() { +unsafe fn figure_out_the_formatted_name() { ex_buf_ptr = 0i32; sp_brace_level = 0i32; sp_ptr = *str_start.offset(pop_lit1 as isize); @@ -3294,7 +3292,7 @@ unsafe extern "C" fn figure_out_the_formatted_name() { } ex_buf_length = ex_buf_ptr; } -unsafe extern "C" fn push_lit_stk(mut push_lt: i32, mut push_type: stk_type) { +unsafe fn push_lit_stk(mut push_lt: i32, mut push_type: stk_type) { *lit_stack.offset(lit_stk_ptr as isize) = push_lt; *lit_stk_type.offset(lit_stk_ptr as isize) = push_type; if lit_stk_ptr == lit_stk_size { @@ -3312,7 +3310,7 @@ unsafe extern "C" fn push_lit_stk(mut push_lt: i32, mut push_type: stk_type) { } lit_stk_ptr = lit_stk_ptr + 1i32; } -unsafe extern "C" fn pop_lit_stk(mut pop_lit: *mut i32, mut pop_type: *mut stk_type) { +unsafe fn pop_lit_stk(mut pop_lit: *mut i32, mut pop_type: *mut stk_type) { if lit_stk_ptr == 0i32 { log!("You can\'t pop an empty literal stack"); bst_ex_warn_print(); @@ -3336,11 +3334,7 @@ unsafe extern "C" fn pop_lit_stk(mut pop_lit: *mut i32, mut pop_type: *mut stk_t } }; } -unsafe extern "C" fn print_wrong_stk_lit( - mut stk_lt: i32, - mut stk_tp1: stk_type, - mut stk_tp2: stk_type, -) { +unsafe fn print_wrong_stk_lit(mut stk_lt: i32, mut stk_tp1: stk_type, mut stk_tp2: stk_type) { if stk_tp1 as i32 != 4i32 { /*stk_empty */ print_stk_lit(stk_lt, stk_tp1); @@ -3364,7 +3358,7 @@ unsafe extern "C" fn print_wrong_stk_lit( bst_ex_warn_print(); }; } -unsafe extern "C" fn pop_top_and_print() { +unsafe fn pop_top_and_print() { let mut stk_lt: i32 = 0; let mut stk_tp: stk_type = 0; pop_lit_stk(&mut stk_lt, &mut stk_tp); @@ -3375,16 +3369,16 @@ unsafe extern "C" fn pop_top_and_print() { print_lit(stk_lt, stk_tp); }; } -unsafe extern "C" fn pop_whole_stack() { +unsafe fn pop_whole_stack() { while lit_stk_ptr > 0i32 { pop_top_and_print(); } } -unsafe extern "C" fn init_command_execution() { +unsafe fn init_command_execution() { lit_stk_ptr = 0i32; cmd_str_ptr = str_ptr; } -unsafe extern "C" fn check_command_execution() { +unsafe fn check_command_execution() { if lit_stk_ptr != 0i32 { log!("ptr={}, stack=\n", lit_stk_ptr); pop_whole_stack(); @@ -3397,7 +3391,7 @@ unsafe extern "C" fn check_command_execution() { panic!(); }; } -unsafe extern "C" fn add_pool_buf_and_push() { +unsafe fn add_pool_buf_and_push() { while pool_ptr + ex_buf_length > pool_size { pool_overflow(); } @@ -3409,7 +3403,7 @@ unsafe extern "C" fn add_pool_buf_and_push() { } push_lit_stk(make_string(), 1i32 as stk_type); } -unsafe extern "C" fn add_buf_pool(mut p_str: str_number) { +unsafe fn add_buf_pool(mut p_str: str_number) { p_ptr1 = *str_start.offset(p_str as isize); p_ptr2 = *str_start.offset((p_str + 1i32) as isize); if ex_buf_length + (p_ptr2 - p_ptr1) > buf_size { @@ -3423,7 +3417,7 @@ unsafe extern "C" fn add_buf_pool(mut p_str: str_number) { } ex_buf_length = ex_buf_ptr; } -unsafe extern "C" fn add_out_pool(mut p_str: str_number) { +unsafe fn add_out_pool(mut p_str: str_number) { let mut break_ptr: buf_pointer = 0; let mut end_ptr: buf_pointer = 0; let mut break_pt_found: bool = false; @@ -3496,7 +3490,7 @@ unsafe extern "C" fn add_out_pool(mut p_str: str_number) { } } } -unsafe extern "C" fn x_equals() { +unsafe fn x_equals() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != pop_typ2 as i32 { @@ -3530,7 +3524,7 @@ unsafe extern "C" fn x_equals() { push_lit_stk(0i32, 0i32 as stk_type); }; } -unsafe extern "C" fn x_greater_than() { +unsafe fn x_greater_than() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != 0i32 { @@ -3547,7 +3541,7 @@ unsafe extern "C" fn x_greater_than() { push_lit_stk(0i32, 0i32 as stk_type); }; } -unsafe extern "C" fn x_less_than() { +unsafe fn x_less_than() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != 0i32 { @@ -3564,7 +3558,7 @@ unsafe extern "C" fn x_less_than() { push_lit_stk(0i32, 0i32 as stk_type); }; } -unsafe extern "C" fn x_plus() { +unsafe fn x_plus() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != 0i32 { @@ -3579,7 +3573,7 @@ unsafe extern "C" fn x_plus() { push_lit_stk(pop_lit2 + pop_lit1, 0i32 as stk_type); }; } -unsafe extern "C" fn x_minus() { +unsafe fn x_minus() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != 0i32 { @@ -3594,7 +3588,7 @@ unsafe extern "C" fn x_minus() { push_lit_stk(pop_lit2 - pop_lit1, 0i32 as stk_type); }; } -unsafe extern "C" fn x_concatenate() { +unsafe fn x_concatenate() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != 1i32 { @@ -3706,7 +3700,7 @@ unsafe extern "C" fn x_concatenate() { push_lit_stk(make_string(), 1i32 as stk_type); }; } -unsafe extern "C" fn x_gets() { +unsafe fn x_gets() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != 2i32 { @@ -3806,7 +3800,7 @@ unsafe extern "C" fn x_gets() { } }; } -unsafe extern "C" fn x_add_period() { +unsafe fn x_add_period() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -3865,7 +3859,7 @@ unsafe extern "C" fn x_add_period() { } }; } -unsafe extern "C" fn x_change_case() { +unsafe fn x_change_case() { let mut current_block: u64; pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); @@ -4111,7 +4105,7 @@ unsafe extern "C" fn x_change_case() { add_pool_buf_and_push(); }; } -unsafe extern "C" fn x_chr_to_int() { +unsafe fn x_chr_to_int() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -4132,14 +4126,14 @@ unsafe extern "C" fn x_chr_to_int() { ); }; } -unsafe extern "C" fn x_cite() { +unsafe fn x_cite() { if !mess_with_entries { bst_cant_mess_with_entries_print(); } else { push_lit_stk(*cite_list.offset(cite_ptr as isize), 1i32 as stk_type); }; } -unsafe extern "C" fn x_duplicate() { +unsafe fn x_duplicate() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -4172,7 +4166,7 @@ unsafe extern "C" fn x_duplicate() { } }; } -unsafe extern "C" fn x_empty() { +unsafe fn x_empty() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); match pop_typ1 as i32 { 1 => { @@ -4202,7 +4196,7 @@ unsafe extern "C" fn x_empty() { } }; } -unsafe extern "C" fn x_format_name() { +unsafe fn x_format_name() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); pop_lit_stk(&mut pop_lit3, &mut pop_typ3); @@ -4420,7 +4414,7 @@ unsafe extern "C" fn x_format_name() { add_pool_buf_and_push(); }; } -unsafe extern "C" fn x_int_to_chr() { +unsafe fn x_int_to_chr() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 0i32 { /*stk_int */ @@ -4439,7 +4433,7 @@ unsafe extern "C" fn x_int_to_chr() { push_lit_stk(make_string(), 1i32 as stk_type); }; } -unsafe extern "C" fn x_int_to_str() { +unsafe fn x_int_to_str() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 0i32 { /*stk_int */ @@ -4450,7 +4444,7 @@ unsafe extern "C" fn x_int_to_str() { add_pool_buf_and_push(); }; } -unsafe extern "C" fn x_missing() { +unsafe fn x_missing() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if !mess_with_entries { bst_cant_mess_with_entries_print(); @@ -4469,7 +4463,7 @@ unsafe extern "C" fn x_missing() { push_lit_stk(0i32, 0i32 as stk_type); }; } -unsafe extern "C" fn x_num_names() { +unsafe fn x_num_names() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -4487,7 +4481,7 @@ unsafe extern "C" fn x_num_names() { push_lit_stk(num_names, 0i32 as stk_type); }; } -unsafe extern "C" fn x_preamble() { +unsafe fn x_preamble() { ex_buf_length = 0i32; preamble_ptr = 0; while preamble_ptr < num_preamble_strings { @@ -4496,7 +4490,7 @@ unsafe extern "C" fn x_preamble() { } add_pool_buf_and_push(); } -unsafe extern "C" fn x_purify() { +unsafe fn x_purify() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -4605,7 +4599,7 @@ unsafe extern "C" fn x_purify() { add_pool_buf_and_push(); }; } -unsafe extern "C" fn x_quote() { +unsafe fn x_quote() { while pool_ptr + 1i32 > pool_size { pool_overflow(); } @@ -4613,7 +4607,7 @@ unsafe extern "C" fn x_quote() { pool_ptr = pool_ptr + 1i32; push_lit_stk(make_string(), 1i32 as stk_type); } -unsafe extern "C" fn x_substring() { +unsafe fn x_substring() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); pop_lit_stk(&mut pop_lit3, &mut pop_typ3); @@ -4681,7 +4675,7 @@ unsafe extern "C" fn x_substring() { } }; } -unsafe extern "C" fn x_swap() { +unsafe fn x_swap() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != 1i32 || pop_lit1 < cmd_str_ptr { @@ -4710,7 +4704,7 @@ unsafe extern "C" fn x_swap() { add_pool_buf_and_push(); }; } -unsafe extern "C" fn x_text_length() { +unsafe fn x_text_length() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -4755,7 +4749,7 @@ unsafe extern "C" fn x_text_length() { push_lit_stk(num_text_chars, 0i32 as stk_type); }; } -unsafe extern "C" fn x_text_prefix() { +unsafe fn x_text_prefix() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); pop_lit_stk(&mut pop_lit2, &mut pop_typ2); if pop_typ1 as i32 != 0i32 { @@ -4827,7 +4821,7 @@ unsafe extern "C" fn x_text_prefix() { push_lit_stk(make_string(), 1i32 as stk_type); }; } -unsafe extern "C" fn x_type() { +unsafe fn x_type() { if !mess_with_entries { bst_cant_mess_with_entries_print(); } else if *type_list.offset(cite_ptr as isize) == undefined @@ -4841,7 +4835,7 @@ unsafe extern "C" fn x_type() { ); }; } -unsafe extern "C" fn x_warning() { +unsafe fn x_warning() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -4852,7 +4846,7 @@ unsafe extern "C" fn x_warning() { mark_warning(); }; } -unsafe extern "C" fn x_width() { +unsafe fn x_width() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -4952,7 +4946,7 @@ unsafe extern "C" fn x_width() { push_lit_stk(string_width, 0i32 as stk_type); }; } -unsafe extern "C" fn x_write() { +unsafe fn x_write() { pop_lit_stk(&mut pop_lit1, &mut pop_typ1); if pop_typ1 as i32 != 1i32 { /*stk_str */ @@ -4961,7 +4955,7 @@ unsafe extern "C" fn x_write() { add_out_pool(pop_lit1); }; } -unsafe extern "C" fn execute_fn(mut ex_fn_loc: hash_loc) { +unsafe fn execute_fn(mut ex_fn_loc: hash_loc) { let mut r_pop_lt1: i32 = 0; let mut r_pop_lt2: i32 = 0; let mut r_pop_tp1: stk_type = 0; @@ -5217,7 +5211,7 @@ unsafe extern "C" fn execute_fn(mut ex_fn_loc: hash_loc) { } }; } -unsafe extern "C" fn get_the_top_level_aux_file_name(mut aux_file_name: *const i8) -> i32 { +unsafe fn get_the_top_level_aux_file_name(mut aux_file_name: *const i8) -> i32 { name_of_file = xmalloc( strlen(aux_file_name) .wrapping_add(1) @@ -5267,7 +5261,7 @@ unsafe extern "C" fn get_the_top_level_aux_file_name(mut aux_file_name: *const i aux_ln_stack[aux_ptr as usize] = 0i32; 0i32 } -unsafe extern "C" fn aux_bib_data_command() { +unsafe fn aux_bib_data_command() { if bib_seen { aux_err_illegal_another_print(0i32); aux_err_print(); @@ -5336,7 +5330,7 @@ unsafe extern "C" fn aux_bib_data_command() { assert!(bib_file.len() == bib_ptr); } } -unsafe extern "C" fn aux_bib_style_command() { +unsafe fn aux_bib_style_command() { if bst_seen { aux_err_illegal_another_print(1i32); aux_err_print(); @@ -5386,7 +5380,7 @@ unsafe extern "C" fn aux_bib_style_command() { log_pr_bst_name(); }; } -unsafe extern "C" fn aux_citation_command() { +unsafe fn aux_citation_command() { citation_seen = true; 'lab23: while *buffer.offset(buf_ptr2 as isize) as i32 != 125 /*right_brace */ @@ -5470,7 +5464,7 @@ unsafe extern "C" fn aux_citation_command() { continue 'lab23; /*next_cite */ } } -unsafe extern "C" fn aux_input_command() { +unsafe fn aux_input_command() { let mut aux_extension_ok: bool = false; buf_ptr2 = buf_ptr2 + 1i32; if !scan1_white(125i32 as u8) { @@ -5547,7 +5541,7 @@ unsafe extern "C" fn aux_input_command() { print_aux_name(); aux_ln_stack[aux_ptr as usize] = 0i32; } -unsafe extern "C" fn pop_the_aux_stack() -> i32 { +unsafe fn pop_the_aux_stack() -> i32 { peekable_close(aux_file[aux_ptr as usize].take()); if aux_ptr == 0i32 { return 1i32; @@ -5555,7 +5549,7 @@ unsafe extern "C" fn pop_the_aux_stack() -> i32 { aux_ptr -= 1; 0i32 } -unsafe extern "C" fn get_aux_command_and_process() { +unsafe fn get_aux_command_and_process() { buf_ptr2 = 0i32; if !scan1(123i32 as u8) { return; @@ -5589,7 +5583,7 @@ unsafe extern "C" fn get_aux_command_and_process() { } }; } -unsafe extern "C" fn last_check_for_aux_errors() { +unsafe fn last_check_for_aux_errors() { num_cites = cite_ptr; num_bib_files = bib_ptr; if !citation_seen { @@ -5620,7 +5614,7 @@ unsafe extern "C" fn last_check_for_aux_errors() { aux_end2_err_print(); }; } -unsafe extern "C" fn bst_entry_command() { +unsafe fn bst_entry_command() { if entry_seen { log!("Illegal, another entry command"); bst_err_print_and_look_for_blank_line(); @@ -5791,7 +5785,7 @@ unsafe extern "C" fn bst_entry_command() { } buf_ptr2 = buf_ptr2 + 1i32; } -unsafe extern "C" fn bad_argument_token() -> bool { +unsafe fn bad_argument_token() -> bool { lower_case(buffer, buf_ptr1, buf_ptr2 - buf_ptr1); fn_loc = str_lookup( buffer, @@ -5818,7 +5812,7 @@ unsafe extern "C" fn bad_argument_token() -> bool { } false } -unsafe extern "C" fn bst_execute_command() { +unsafe fn bst_execute_command() { if !read_seen { log!("Illegal, execute command before read command"); bst_err_print_and_look_for_blank_line(); @@ -5874,7 +5868,7 @@ unsafe extern "C" fn bst_execute_command() { execute_fn(fn_loc); check_command_execution(); } -unsafe extern "C" fn bst_function_command() { +unsafe fn bst_function_command() { if !eat_bst_white_space() { eat_bst_print(); log!("function"); @@ -5949,7 +5943,7 @@ unsafe extern "C" fn bst_function_command() { buf_ptr2 = buf_ptr2 + 1i32; scan_fn_def(wiz_loc); } -unsafe extern "C" fn bst_integers_command() { +unsafe fn bst_integers_command() { if !eat_bst_white_space() { eat_bst_print(); log!("integers"); @@ -6003,7 +5997,7 @@ unsafe extern "C" fn bst_integers_command() { } buf_ptr2 = buf_ptr2 + 1i32; } -unsafe extern "C" fn bst_iterate_command() { +unsafe fn bst_iterate_command() { if !read_seen { log!("Illegal, iterate command before read command"); bst_err_print_and_look_for_blank_line(); @@ -6064,7 +6058,7 @@ unsafe extern "C" fn bst_iterate_command() { sort_cite_ptr = sort_cite_ptr + 1i32 } } -unsafe extern "C" fn bst_macro_command() { +unsafe fn bst_macro_command() { if read_seen { log!("Illegal, macro command after read command"); bst_err_print_and_look_for_blank_line(); @@ -6178,7 +6172,7 @@ unsafe extern "C" fn bst_macro_command() { } buf_ptr2 = buf_ptr2 + 1i32; } -unsafe extern "C" fn get_bib_command_or_entry_and_process() { +unsafe fn get_bib_command_or_entry_and_process() { let mut current_block: u64; at_bib_command = false; while !scan1(64i32 as u8) { @@ -6584,7 +6578,7 @@ unsafe extern "C" fn get_bib_command_or_entry_and_process() { } buf_ptr2 = buf_ptr2 + 1i32; } -unsafe extern "C" fn bst_read_command() { +unsafe fn bst_read_command() { if read_seen { log!("Illegal, another read command"); bst_err_print_and_look_for_blank_line(); @@ -6815,7 +6809,7 @@ unsafe extern "C" fn bst_read_command() { tmp_ptr = tmp_ptr + 1i32 } } -unsafe extern "C" fn bst_reverse_command() { +unsafe fn bst_reverse_command() { if !read_seen { log!("Illegal, reverse command before read command"); bst_err_print_and_look_for_blank_line(); @@ -6881,7 +6875,7 @@ unsafe extern "C" fn bst_reverse_command() { } }; } -unsafe extern "C" fn bst_sort_command() { +unsafe fn bst_sort_command() { if !read_seen { log!("Illegal, sort command before read command"); bst_err_print_and_look_for_blank_line(); @@ -6891,7 +6885,7 @@ unsafe extern "C" fn bst_sort_command() { quick_sort(0i32, num_cites - 1i32); }; } -unsafe extern "C" fn bst_strings_command() { +unsafe fn bst_strings_command() { if !eat_bst_white_space() { eat_bst_print(); log!("strings"); @@ -6970,7 +6964,7 @@ unsafe extern "C" fn bst_strings_command() { } buf_ptr2 += 1; } -unsafe extern "C" fn get_bst_command_and_process() { +unsafe fn get_bst_command_and_process() { if !scan_alpha() { log!( "\"{}\" can't start a style-file command", @@ -7031,7 +7025,7 @@ unsafe extern "C" fn get_bst_command_and_process() { } }; } -unsafe extern "C" fn setup_params() { +unsafe fn setup_params() { ent_str_size = 250i32; glob_str_size = 20000i32; max_strings = 35307i32; @@ -7044,7 +7038,7 @@ unsafe extern "C" fn setup_params() { end_of_def = hash_max + 1i32; /*illegal */ undefined = hash_max + 1i32; /*illegal */ } -unsafe extern "C" fn compute_hash_prime() { +unsafe fn compute_hash_prime() { let mut hash_want: i32 = 0; /*white_space */ let mut k: i32 = 0; /*white_space */ let mut j: i32 = 0; /*white_space */ @@ -7089,7 +7083,7 @@ unsafe extern "C" fn compute_hash_prime() { *hash_next.offset(k as isize) = hash_prime } } -unsafe extern "C" fn initialize(mut aux_file_name: *const i8) -> i32 { +unsafe fn initialize(mut aux_file_name: *const i8) -> i32 { let mut i: i32 = 0; let mut k: hash_loc = 0; bad = 0i32; @@ -7325,7 +7319,7 @@ unsafe extern "C" fn initialize(mut aux_file_name: *const i8) -> i32 { Licensed under the MIT License. */ #[no_mangle] -pub unsafe extern "C" fn bibtex_main(mut aux_file_name: *const i8) -> TTHistory { +pub unsafe fn bibtex_main(mut aux_file_name: *const i8) -> TTHistory { pool_size = POOL_SIZE; buf_size = BUF_SIZE; MAX_BIB_FILES = MAX_BIBFILES; diff --git a/engine/src/lib.rs b/engine/src/lib.rs index 3a15900f2..a8fae5b40 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -150,6 +150,7 @@ mod core_memory { } mod bibtex; +mod text_layout_engine; mod xetex_aatfont; mod xetex_consts; mod xetex_engine_interface; @@ -196,85 +197,4 @@ pub(crate) unsafe extern "C" fn streq_ptr(s1: *const i8, s2: *const i8) -> bool mod xetex_font_info; mod xetex_font_manager; mod xetex_layout_engine; -mod xetex_layout_interface; mod xetex_opentype_math; - -pub(crate) mod freetype_sys_patch { - use freetype::freetype_sys::{FT_Face, FT_Byte, FT_Short, FT_UShort, FT_Long, FT_ULong, FT_UInt, FT_Int32, FT_Fixed, FT_Error, FT_Sfnt_Tag}; - - extern "C" { - #[no_mangle] - pub fn FT_Face_GetCharVariantIndex( - face: FT_Face, - charcode: FT_ULong, - variantSelector: FT_ULong, - ) -> FT_UInt; - - #[no_mangle] - pub fn FT_Get_Advance( - face: FT_Face, - gindex: FT_UInt, - load_flags: FT_Int32, - padvance: *mut FT_Fixed, - ) -> FT_Error; - - #[no_mangle] - pub fn FT_Load_Sfnt_Table( - face: FT_Face, - tag: FT_ULong, - offset: FT_Long, - buffer: *mut FT_Byte, - length: *mut FT_ULong, - ) -> FT_Error; - - #[no_mangle] - pub fn FT_Get_Sfnt_Name_Count(face: FT_Face) -> FT_UInt; - - #[no_mangle] - pub fn FT_Get_Sfnt_Name(face: FT_Face, idx: FT_UInt, aname: *mut FT_SfntName) -> FT_Error; - } - - pub const FT_SFNT_MAX: FT_Sfnt_Tag = 7; - pub const FT_SFNT_PCLT: FT_Sfnt_Tag = 6; - pub const FT_SFNT_POST: FT_Sfnt_Tag = 5; - pub const FT_SFNT_VHEA: FT_Sfnt_Tag = 4; - pub const FT_SFNT_HHEA: FT_Sfnt_Tag = 3; - pub const FT_SFNT_OS2: FT_Sfnt_Tag = 2; - pub const FT_SFNT_MAXP: FT_Sfnt_Tag = 1; - pub const FT_SFNT_HEAD: FT_Sfnt_Tag = 0; - - #[derive(Copy, Clone)] - #[repr(C)] - pub struct TT_Header_ { - pub Table_Version: FT_Fixed, - pub Font_Revision: FT_Fixed, - pub CheckSum_Adjust: FT_Long, - pub Magic_Number: FT_Long, - pub Flags: FT_UShort, - pub Units_Per_EM: FT_UShort, - pub Created: [FT_ULong; 2], - pub Modified: [FT_ULong; 2], - pub xMin: FT_Short, - pub yMin: FT_Short, - pub xMax: FT_Short, - pub yMax: FT_Short, - pub Mac_Style: FT_UShort, - pub Lowest_Rec_PPEM: FT_UShort, - pub Font_Direction: FT_Short, - pub Index_To_Loc_Format: FT_Short, - pub Glyph_Data_Format: FT_Short, - } - pub type TT_Header = TT_Header_; - - #[derive(Copy, Clone)] - #[repr(C)] - pub struct FT_SfntName_ { - pub platform_id: FT_UShort, - pub encoding_id: FT_UShort, - pub language_id: FT_UShort, - pub name_id: FT_UShort, - pub string: *mut FT_Byte, - pub string_len: FT_UInt, - } - pub type FT_SfntName = FT_SfntName_; -} diff --git a/engine/src/text_layout_engine.rs b/engine/src/text_layout_engine.rs new file mode 100644 index 000000000..c62269914 --- /dev/null +++ b/engine/src/text_layout_engine.rs @@ -0,0 +1,369 @@ +#![allow(dead_code)] + +// XXX: should be no harfbuzz in the interface +use crate::xetex_ext::UniChar; +use crate::xetex_font_info::{GlyphBBox, XeTeXFontInst}; +use crate::xetex_font_manager::PlatformFontRef; +use crate::xetex_ini::memory_word; +use harfbuzz_sys::hb_tag_t; + +pub type Fixed = i32; + +#[derive(Copy, Clone)] +#[cfg_attr(not(target_os = "macos"), repr(C))] +#[cfg_attr(target_os = "macos", repr(C, packed(2)))] +pub struct FixedPoint { + pub x: Fixed, + pub y: Fixed, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct FloatPoint { + pub x: f32, + pub y: f32, +} + +pub type Fract = i32; + +pub type scaled_t = i32; + +// Annoying XeTeXFontMgr singleton accessors +// pub unsafe fn getFullName(fontRef: PlatformFontRef) -> *const libc::c_char; +// pub unsafe fn getDesignSize(font: *mut XeTeXFontInst) -> f64; +// pub unsafe fn findFontByName(name: &CStr, var: Option<&mut String>, size: f64) -> PlatformFontRef; +// pub unsafe fn terminate_font_manager(); +// pub unsafe fn destroy_font_manager(); + +// Internal to XeTeXLayoutEngine but could use improvement + +// pub unsafe fn getGlyphs(engine: XeTeXLayoutEngine, glyphs: *mut u32); +// pub unsafe fn getGlyphAdvances(engine: XeTeXLayoutEngine, advances: *mut f32); +// pub unsafe fn getGlyphPositions(engine: XeTeXLayoutEngine, positions: *mut FloatPoint); + +// engine : *font_layout_engine.offset((*node.offset(4)).b16.s2 as isize) as CFDictionaryRef; +pub struct LayoutRequest<'a> { + // ```text + // let txtLen = (*node.offset(4)).b16.s1 as libc::c_long; + // let txtPtr = node.offset(6) as *mut UniChar; + // slice::from_raw_parts(txtPtr, txtLen) + // ``` + pub text: &'a [u16], + // node.offset(1).b32.s1 + pub line_width: Fixed, + // let f = let mut f: libc::c_uint = (*node.offset(4)).b16.s2 as libc::c_uint; + // *font_letter_space.offset(f as usize) + pub letter_space_unit: Fixed, + + /// Only used by AAT + pub justify: bool, +} + +impl LayoutRequest<'_> { + /// Unsafety: obviously, dereferences raw node pointer. The lifetime is also pulled out of + /// thin air, so just keep it in scope, ok? + pub unsafe fn from_node<'a>(node: *mut memory_word, justify: bool) -> LayoutRequest<'a> { + use crate::xetex_ini::font_letter_space; + + let txtLen = (*node.offset(4)).b16.s1 as usize; + let txtPtr = node.offset(6) as *mut UniChar; + let text = std::slice::from_raw_parts(txtPtr, txtLen); + let line_width = (*node.offset(1)).b32.s1; + let mut f = (*node.offset(4)).b16.s2 as u32; + let letter_space_unit = *font_letter_space.offset(f as isize); + LayoutRequest { + text, + line_width, + letter_space_unit, + justify, + } + } +} + +pub struct NodeLayout { + // if lsDelta != 0i32 { + // lsDelta -= lsUnit; + // let ref mut fresh2 = (*node.offset(1)).b32.s1; + // *fresh2 += lsDelta + // } + pub lsDelta: Option, + // (*node.offset(1)).b32.s1 = width as int32_t; + pub width: Fixed, + // (*node.offset(4)).b16.s0 = totalGlyphCount as uint16_t; + pub total_glyph_count: u16, + // let ref mut fresh0 = (*node.offset(5)).ptr; + // *fresh0 = glyph_info; + pub glyph_info: *mut FixedPoint, +} + +impl NodeLayout { + pub unsafe fn write_node(&self, node: *mut memory_word) { + let NodeLayout { + lsDelta, + width, + total_glyph_count, + glyph_info, + } = *self; + + (*node.offset(1)).b32.s1 = width + lsDelta.unwrap_or(0); + (*node.offset(4)).b16.s0 = total_glyph_count; + let ref mut fresh0 = (*node.offset(5)).ptr; + *fresh0 = glyph_info as *mut libc::c_void; + } +} + +/// Stuff that should be added as XeTeXFontInst methods +trait FontInstance { + unsafe fn countGlyphs(font: *mut XeTeXFontInst) -> u32; + unsafe fn getGlyphWidth(font: *mut XeTeXFontInst, gid: u32) -> f32; + unsafe fn setFontLayoutDir(font: *mut XeTeXFontInst, vertical: libc::c_int); + + unsafe fn getIndLanguage(font: *mut XeTeXFontInst, script: hb_tag_t, index: u32) -> hb_tag_t; + unsafe fn countFeatures(font: *mut XeTeXFontInst, script: hb_tag_t, language: hb_tag_t) -> u32; + unsafe fn getIndFeature( + font: *mut XeTeXFontInst, + script: hb_tag_t, + language: hb_tag_t, + index: u32, + ) -> hb_tag_t; + unsafe fn countScripts(font: *mut XeTeXFontInst) -> u32; + unsafe fn getIndScript(font: *mut XeTeXFontInst, index: u32) -> hb_tag_t; + unsafe fn countLanguages(font: *mut XeTeXFontInst, script: hb_tag_t) -> u32; + unsafe fn getSlant(font: *mut XeTeXFontInst) -> Fixed; + unsafe fn getFontTablePtr(font: *mut XeTeXFontInst, tableTag: u32) -> *mut libc::c_void; + // unsafe fn deleteFont(mut font: *mut XeTeXFontInst); +} + +// Not quite layout engine things + +// pub unsafe fn createFont(fontRef: PlatformFontRef, pointSize: Fixed) -> *mut XeTeXFontInst; +// pub unsafe fn createFontFromFile( +// filename: &CStr, +// index: libc::c_int, +// pointSize: Fixed, +// ) -> *mut XeTeXFontInst; + +// // Misc static dictionary lookups/setters +// pub unsafe fn set_cp_code(fontNum: libc::c_int, code: libc::c_uint, side: libc::c_int, value: libc::c_int); +// pub unsafe fn get_cp_code( +// fontNum: libc::c_int, +// code: libc::c_uint, +// side: libc::c_int, +// ) -> libc::c_int; + +pub struct GlyphBBoxCache { + // ... +} +impl GlyphBBoxCache { + /// getCachedGlyphBBox + pub unsafe fn get(fontID: u16, glyphID: u16) -> Option { + unimplemented!() + } + pub unsafe fn store(fontID: u16, glyphID: u16, bbox: GlyphBBox) { + unimplemented!() + } +} + +#[repr(u8)] +pub enum GlyphEdge { + Left = 1, + Top = 2, + Right = 3, + Bottom = 4, +} + +impl GlyphEdge { + /// If a glyph is left or right + #[inline] + pub fn is_side(&self) -> bool { + match *self { + GlyphEdge::Left | GlyphEdge::Right => true, + _ => false, + } + } + #[inline] + pub fn pick_from(&self, options: &(f32, f32)) -> f32 { + match *self { + GlyphEdge::Left | GlyphEdge::Top => options.0, + GlyphEdge::Right | GlyphEdge::Bottom => options.1, + } + } + pub fn from_int(i: i32) -> Option { + Some(match i { + 1 => GlyphEdge::Left, + 2 => GlyphEdge::Top, + 3 => GlyphEdge::Right, + 4 => GlyphEdge::Bottom, + _ => return None, + }) + } +} + +use crate::xetex_layout_engine::XeTeXLayoutEngine_rec; + +// Everywhere except macOS, this should compile down to nothing. +cfg_if::cfg_if! { + if #[cfg(target_os = "macos")] { + use crate::xetex_aatfont::AATLayoutEngine; + #[enum_dispatch::enum_dispatch] + pub enum TextLayoutEngine { + AAT(AATLayoutEngine), + XeTeX(XeTeXLayoutEngine_rec), + } + } else { + #[enum_dispatch::enum_dispatch] + pub enum TextLayoutEngine { + XeTeX(XeTeXLayoutEngine_rec), + } + } +} + +#[enum_dispatch::enum_dispatch(TextLayoutEngine)] +pub trait TextLayout { + /// The most important trait method. Lay out some text and return its size. + unsafe fn layout_text(&mut self, request: LayoutRequest) -> NodeLayout; + + /// getFontFilename + /// Only for make_font_def. Should use CStr, probably. + unsafe fn font_filename(&self, index: &mut u32) -> *mut libc::c_char; + + unsafe fn print_font_name(&self, c: i32, arg1: i32, arg2: i32); + + /// getFontInst + // fn font_instance(&self) -> *mut XeTeXFontInst; + + // should implement Drop + // unsafe fn deleteLayoutEngine(mut engine: XeTeXLayoutEngine); + + unsafe fn glyph_width(&self, gid: u32) -> f64; + + // XXX: make a single struct for make_font_def to consume, of all the required values + + unsafe fn get_font_metrics( + &self, + ascent: &mut Fixed, + descent: &mut Fixed, + x_ht: &mut Fixed, + cap_ht: &mut Fixed, + slant: &mut Fixed, + ); + + /// ot_font_get, aat_font_get + unsafe fn poorly_named_getter(&self, what: i32) -> i32; + + /// ot_font_get_1, aat_font_get_1 + unsafe fn poorly_named_getter_1(&self, what: i32, param1: i32) -> i32; + + /// ot_font_get_2, aat_font_get_2 + unsafe fn poorly_named_getter_2(&self, what: i32, param1: i32, param2: i32) -> i32; + + /// ot_font_get_3 + unsafe fn poorly_named_getter_3(&self, what: i32, param1: i32, param2: i32, param3: i32) -> i32; + + unsafe fn get_flags(&self, font_number: u32) -> i32; + + /// getExtendFactor + unsafe fn extend_factor(&self) -> f64; + /// getPointSize + unsafe fn point_size(&self) -> f64; + /// getAscentAndDescent + unsafe fn ascent_and_descent(&self, ascent: &mut f32, descent: &mut f32); + /// getCapAndXHeight + unsafe fn cap_and_x_height(&self, capheight: &mut f32, xheight: &mut f32); + /// getEmboldenFactor + unsafe fn embolden_factor(&self) -> f32; + /// getRgbValue + /// as r,g,b,a bytes, in order (careful of endianness maybe at output phase) + unsafe fn rgb_value(&self) -> u32; + /// getSlantFactor + unsafe fn slant_factor(&self) -> f64; + + /// getGlyphName + /// Only used for debugging. Should be a String/CStr then! + unsafe fn glyph_name(&self, gid: u16, len: &mut libc::c_int) -> *const libc::c_char; + + /// getGlyphBounds (had out param) + unsafe fn glyph_bbox(&self, glyphID: u32) -> Option; + + unsafe fn getGlyphWidthFromEngine(&self, glyphID: u32) -> f64; + + /// getGlyphHeightDepth (had out params height, depth) + unsafe fn glyph_height_depth(&self, glyphID: u32) -> Option<(f32, f32)>; + + /// getGlyphSidebearings (had out params lsb, rsb) + unsafe fn glyph_sidebearings(&self, glyphID: u32) -> Option<(f32, f32)>; + + /// getGlyphItalCorr + unsafe fn glyph_ital_correction(&self, glyphID: u32) -> Option; + + /// mapCharToGlyph + /// Should probably just use engine.font as this just passes on the call + /// This is used for 'fallback in case lacks an OS/2 table', and also for adding accents + /// (get_native_char_sidebearings). + /// Although the shaping engine should probably be doing the latter, not xetex0! + unsafe fn map_char_to_glyph(&self, codepoint: u32) -> u32; + + /// getFontCharRange + /// Another candidate for using XeTeXFontInst directly + unsafe fn font_char_range(&self, reqFirst: libc::c_int) -> libc::c_int; + + /// mapGlyphToIndex + /// Should use engine.font directly + unsafe fn map_glyph_to_index(&self, glyphName: *const libc::c_char) -> i32; + + // Provided methods, override if using stuff + + /// Default impl is { false }. + /// Only used directly with xetex0. + unsafe fn usingGraphite(&self) -> bool { + false + } + + /// Returns true if "user asked for Graphite line breaking and the font supports it" + /// Only relevant if this engine actually uses graphite, hence default impl of { false } + unsafe fn initGraphiteBreaking(&mut self, txtPtr: *const u16, txtLen: i32) -> bool { + false + } + + /// Not sure what AAT should return, since this is only called with random casts to + /// XeTeXLayoutENgine in xetex0. + unsafe fn usingOpenType(&self) -> bool { + false + } + + unsafe fn isOpenTypeMathFont(&self) -> bool { + false + } +} + +trait GraphiteFontSomething { + unsafe fn countGraphiteFeatures(&self) -> u32; + unsafe fn getGraphiteFeatureCode(&self, index: u32) -> u32; + unsafe fn countGraphiteFeatureSettings(&self, featureID: u32) -> u32; + unsafe fn getGraphiteFeatureSettingCode(&self, featureID: u32, index: u32) -> u32; + unsafe fn getGraphiteFeatureDefaultSetting(&self, featureID: u32) -> u32; + unsafe fn getGraphiteFeatureLabel(&self, featureID: u32) -> *mut libc::c_char; + unsafe fn getGraphiteFeatureSettingLabel( + &self, + featureID: u32, + settingID: u32, + ) -> *mut libc::c_char; + unsafe fn findGraphiteFeature( + &self, + s: *const libc::c_char, + e: *const libc::c_char, + f: *mut hb_tag_t, + v: *mut libc::c_int, + ) -> bool; + unsafe fn findGraphiteFeatureNamed( + &self, + name: *const libc::c_char, + namelength: libc::c_int, + ) -> libc::c_long; + unsafe fn findGraphiteFeatureSettingNamed( + &self, + id: u32, + name: *const libc::c_char, + namelength: libc::c_int, + ) -> libc::c_long; +} diff --git a/engine/src/xetex_aatfont.rs b/engine/src/xetex_aatfont.rs index aae2b9fa6..dda0012b8 100644 --- a/engine/src/xetex_aatfont.rs +++ b/engine/src/xetex_aatfont.rs @@ -9,349 +9,382 @@ unused_mut )] -use super::xetex_layout_engine::GlyphBBox; +use super::text_layout_engine::{ + Fixed, FixedPoint, Fract, GlyphEdge, LayoutRequest, NodeLayout, TextLayout, TextLayoutEngine, +}; +use super::xetex_font_info::GlyphBBox; use self::cf_prelude::*; use core_foundation::base::TCFType; use core_foundation::string::CFString; use core_foundation::url::CFURL; -use freetype::Library as FreeTypeLibrary; +use font_kit::handle::Handle; use std::borrow::Cow; use std::cell::RefCell; +use std::ffi::CStr; use std::ptr; -pub mod cf_prelude { - pub use core_foundation::{ - attributed_string::{CFAttributedString, CFAttributedStringCreate, CFAttributedStringRef}, - base::{ - kCFAllocatorDefault, kCFAllocatorNull, CFAllocatorRef, CFComparisonResult, CFEqual, - CFHashCode, CFIndex, CFOptionFlags, CFRange, CFRelease, CFTypeRef, ToVoid, - }, - boolean::{kCFBooleanTrue, CFBooleanRef}, - dictionary::{ - kCFTypeDictionaryKeyCallBacks, kCFTypeDictionaryValueCallBacks, CFDictionary, - CFDictionaryAddValue, CFDictionaryCopyDescriptionCallBack, CFDictionaryCreate, - CFDictionaryCreateMutable, CFDictionaryEqualCallBack, CFDictionaryGetValueIfPresent, - CFDictionaryHashCallBack, CFDictionaryKeyCallBacks, CFDictionaryRef, - CFDictionaryReleaseCallBack, CFDictionaryRetainCallBack, CFDictionaryValueCallBacks, - CFMutableDictionaryRef, - }, - number::{CFNumberCompare, CFNumberCreate, CFNumberGetValue, CFNumberRef, CFNumberType}, - string::{ - kCFStringEncodingUTF8, CFStringCompareFlags, CFStringCreateWithBytes, - CFStringCreateWithCString, CFStringEncoding, CFStringGetCString, CFStringGetLength, - CFStringRef, - }, - url::{CFURLGetFileSystemRepresentation, CFURLRef}, - }; - pub const kCFNumberMaxType: CFNumberType = 16; - pub const kCFNumberCGFloatType: CFNumberType = 16; - pub const kCFNumberNSIntegerType: CFNumberType = 15; - pub const kCFNumberCFIndexType: CFNumberType = 14; - pub const kCFNumberDoubleType: CFNumberType = 13; - pub const kCFNumberFloatType: CFNumberType = 12; - pub const kCFNumberLongLongType: CFNumberType = 11; - pub const kCFNumberLongType: CFNumberType = 10; - pub const kCFNumberIntType: CFNumberType = 9; - pub const kCFNumberShortType: CFNumberType = 8; - pub const kCFNumberCharType: CFNumberType = 7; - pub const kCFNumberFloat64Type: CFNumberType = 6; - pub const kCFNumberFloat32Type: CFNumberType = 5; - pub const kCFNumberSInt64Type: CFNumberType = 4; - pub const kCFNumberSInt32Type: CFNumberType = 3; - pub const kCFNumberSInt16Type: CFNumberType = 2; - pub const kCFNumberSInt8Type: CFNumberType = 1; +#[repr(transparent)] +pub struct AATLayoutEngine { + attributes: CFDictionaryRef, +} - pub const kCFStringEncodingUTF32LE: CFStringEncoding = 469762304; - pub const kCFStringEncodingUTF32BE: CFStringEncoding = 402653440; - pub const kCFStringEncodingUTF32: CFStringEncoding = 201326848; - pub const kCFStringEncodingUTF16LE: CFStringEncoding = 335544576; - pub const kCFStringEncodingUTF16BE: CFStringEncoding = 268435712; - pub const kCFStringEncodingUTF16: CFStringEncoding = 256; - pub const kCFStringEncodingNonLossyASCII: CFStringEncoding = 3071; - pub const kCFStringEncodingUnicode: CFStringEncoding = 256; - pub const kCFStringEncodingASCII: CFStringEncoding = 1536; - pub const kCFStringEncodingNextStepLatin: CFStringEncoding = 2817; - pub const kCFStringEncodingISOLatin1: CFStringEncoding = 513; - pub const kCFStringEncodingWindowsLatin1: CFStringEncoding = 1280; - pub const kCFStringEncodingMacRoman: CFStringEncoding = 0; +impl AATLayoutEngine { + pub fn new(attributes: CFDictionaryRef) -> Self { + AATLayoutEngine { attributes } + } + pub unsafe fn ct_font(&self) -> CTFontRef { + font_from_attributes(self.attributes) + } + pub unsafe fn transform(&self) -> CGAffineTransform { + let font = self.ct_font(); + CTFontGetMatrix(font) + } +} - pub const kCFCompareForcedOrdering: CFStringCompareFlags = 512; - pub const kCFCompareWidthInsensitive: CFStringCompareFlags = 256; - pub const kCFCompareDiacriticInsensitive: CFStringCompareFlags = 128; - pub const kCFCompareNumerically: CFStringCompareFlags = 64; - pub const kCFCompareLocalized: CFStringCompareFlags = 32; - pub const kCFCompareNonliteral: CFStringCompareFlags = 16; - pub const kCFCompareAnchored: CFStringCompareFlags = 8; - pub const kCFCompareBackwards: CFStringCompareFlags = 4; - pub const kCFCompareCaseInsensitive: CFStringCompareFlags = 1; +impl TextLayout for AATLayoutEngine { + /// The most important trait method. Lay out some text and return its size. + unsafe fn layout_text(&mut self, request: LayoutRequest) -> NodeLayout { + let mut glyphRuns: CFArrayRef = ptr::null_mut(); + let mut i: CFIndex = 0; + let mut j: CFIndex = 0; + let mut runCount: CFIndex = 0; + let mut totalGlyphCount: CFIndex = 0; + let mut glyphIDs: *mut UInt16 = ptr::null_mut(); + let mut glyphAdvances: *mut Fixed = ptr::null_mut(); + let mut glyph_info: *mut FixedPoint = ptr::null_mut(); + let mut locations: *mut FixedPoint = ptr::null_mut(); + let mut width: CGFloat = 0.; + let mut string: CFStringRef = ptr::null_mut(); + let mut attrString: CFAttributedStringRef = ptr::null_mut(); + let mut typesetter: CTTypesetterRef = 0 as CTTypesetterRef; + let mut line: CTLineRef = ptr::null_mut(); - // The CFArray wrapper is not mutable, so we use the APIs directly - pub use core_foundation::array::{ - kCFTypeArrayCallBacks, CFArrayCallBacks, CFArrayGetCount, CFArrayRef, __CFArray, - }; - pub type CFMutableArrayRef = *mut __CFArray; - extern "C" { - #[no_mangle] - pub fn CFArrayCreateMutable( - allocator: CFAllocatorRef, - capacity: CFIndex, - callBacks: *const CFArrayCallBacks, - ) -> CFMutableArrayRef; - #[no_mangle] - pub fn CFArrayAppendValue(theArray: CFMutableArrayRef, value: *const libc::c_void); + let mut txtLen = request.text.len() as CFIndex; + let mut txtPtr: *const UniChar = request.text.as_ptr(); + let justify = request.justify; + + let mut layout = NodeLayout { + lsDelta: None, + width: 0, + total_glyph_count: 0, + glyph_info: ptr::null_mut(), + }; + + string = CFStringCreateWithCharactersNoCopy(ptr::null(), txtPtr, txtLen, kCFAllocatorNull); + attrString = CFAttributedStringCreate(ptr::null(), string, self.attributes); + CFRelease(string as CFTypeRef); + typesetter = CTTypesetterCreateWithAttributedString(attrString); + CFRelease(attrString as CFTypeRef); + line = CTTypesetterCreateLine(typesetter, CFRangeMake(0i32 as CFIndex, txtLen)); + if justify { + let mut lineWidth: CGFloat = TeXtoPSPoints(Fix2D(request.line_width)); + let mut justifiedLine: CTLineRef = CTLineCreateJustifiedLine( + line, + TeXtoPSPoints(Fix2D(0x40000000i64 as Fixed)), + lineWidth, + ); + // TODO(jjgod): how to handle the case when justification failed? for + // now we just fallback to use the original line. + if !justifiedLine.is_null() { + CFRelease(line as CFTypeRef); + line = justifiedLine + } + } + glyphRuns = CTLineGetGlyphRuns(line); + runCount = CFArrayGetCount(glyphRuns); + totalGlyphCount = CTLineGetGlyphCount(line); + if totalGlyphCount > 0 { + glyph_info = xmalloc((totalGlyphCount * 10) as _) as *mut FixedPoint; + locations = glyph_info as *mut FixedPoint; + glyphIDs = locations.offset(totalGlyphCount as isize) as *mut UInt16; + glyphAdvances = + xmalloc((totalGlyphCount as i64 * std::mem::size_of::() as i64) as _) + as *mut Fixed; + totalGlyphCount = 0; + width = 0i32 as CGFloat; + i = 0i32 as CFIndex; + while i < runCount { + let mut run: CTRunRef = CFArrayGetValueAtIndex(glyphRuns, i) as CTRunRef; + let mut count: CFIndex = CTRunGetGlyphCount(run); + let mut runAttributes: CFDictionaryRef = CTRunGetAttributes(run); + let mut vertical: CFBooleanRef = CFDictionaryGetValue( + runAttributes, + kCTVerticalFormsAttributeName as *const libc::c_void, + ) as CFBooleanRef; + // TODO(jjgod): Avoid unnecessary allocation with CTRunGetFoosPtr(). + let mut glyphs: *mut CGGlyph = + xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) + as *mut CGGlyph; + let mut positions: *mut CGPoint = + xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) + as *mut CGPoint; + let mut advances: *mut CGSize = + xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) + as *mut CGSize; + let mut runWidth: CGFloat = CTRunGetTypographicBounds( + run, + CFRangeMake(0i32 as CFIndex, 0i32 as CFIndex), + ptr::null_mut(), + ptr::null_mut(), + ptr::null_mut(), + ); + CTRunGetGlyphs(run, CFRangeMake(0i32 as CFIndex, 0i32 as CFIndex), glyphs); + CTRunGetPositions( + run, + CFRangeMake(0i32 as CFIndex, 0i32 as CFIndex), + positions, + ); + CTRunGetAdvances(run, CFRangeMake(0i32 as CFIndex, 0i32 as CFIndex), advances); + j = 0i32 as CFIndex; + while j < count { + // XXX Core Text has that font cascading thing that will do + // font substitution for missing glyphs, which we do not want + // but I can not find a way to disable it yet, so if the font + // of the resulting run is not the same font we asked for, use + // the glyph at index 0 (usually .notdef) instead or we will be + // showing garbage or even invalid glyphs + if CFEqual( + self.ct_font() as CFTypeRef, + font_from_attributes(runAttributes) as CFTypeRef, + ) == 0 + { + *glyphIDs.offset(totalGlyphCount as isize) = 0i32 as UInt16 + } else { + *glyphIDs.offset(totalGlyphCount as isize) = *glyphs.offset(j as isize) + } + // Swap X and Y when doing vertical layout + if vertical == kCFBooleanTrue { + (*locations.offset(totalGlyphCount as isize)).x = + -FixedPStoTeXPoints((*positions.offset(j as isize)).y); + (*locations.offset(totalGlyphCount as isize)).y = + FixedPStoTeXPoints((*positions.offset(j as isize)).x) + } else { + (*locations.offset(totalGlyphCount as isize)).x = + FixedPStoTeXPoints((*positions.offset(j as isize)).x); + (*locations.offset(totalGlyphCount as isize)).y = + -FixedPStoTeXPoints((*positions.offset(j as isize)).y) + } + *glyphAdvances.offset(totalGlyphCount as isize) = + (*advances.offset(j as isize)).width as Fixed; + totalGlyphCount += 1; + j += 1 + } + width += FixedPStoTeXPoints(runWidth) as libc::c_double; + free(glyphs as *mut libc::c_void); + free(positions as *mut libc::c_void); + free(advances as *mut libc::c_void); + i += 1 + } + } + layout.total_glyph_count = totalGlyphCount as u16; + layout.glyph_info = glyph_info; + + if !justify { + layout.width = width as Fixed; + if totalGlyphCount > 0 { + /* this is essentially a copy from similar code in XeTeX_ext.c, easier + * to be done here */ + if request.letter_space_unit != 0i32 { + let mut lsDelta: Fixed = 0i32; + let mut lsUnit: Fixed = request.letter_space_unit; + let mut i_0 = 0; + while i_0 < totalGlyphCount { + if *glyphAdvances.offset(i_0 as isize) == 0i32 && lsDelta != 0i32 { + lsDelta -= lsUnit + } + let ref mut fresh1 = (*locations.offset(i_0 as isize)).x; + *fresh1 += lsDelta; + lsDelta += lsUnit; + i_0 += 1 + } + if lsDelta != 0i32 { + lsDelta -= lsUnit; + layout.lsDelta = Some(lsDelta); + } + } + } + } + free(glyphAdvances as *mut libc::c_void); + CFRelease(line as CFTypeRef); + CFRelease(typesetter as CFTypeRef); + layout } - extern "C" { - // Missing - #[no_mangle] - pub fn CFStringCreateWithCStringNoCopy( - alloc: CFAllocatorRef, - cStr: *const libc::c_char, - encoding: CFStringEncoding, - contentsDeallocator: CFAllocatorRef, - ) -> CFStringRef; - #[no_mangle] - pub fn CFStringCompare( - theString1: CFStringRef, - theString2: CFStringRef, - compareOptions: CFStringCompareFlags, - ) -> CFComparisonResult; + + /// getFontFilename + /// Only for make_font_def. Should use CStr, probably. + unsafe fn font_filename(&self, index: &mut u32) -> *mut libc::c_char { + let filename = getFileNameFromCTFont(self.ct_font(), index); + assert!(!filename.is_null()); + filename } - extern "C" { - #[no_mangle] - pub fn CFDictionaryGetValue( - theDict: CFDictionaryRef, - key: *const libc::c_void, - ) -> *const libc::c_void; + + unsafe fn print_font_name(&self, c: i32, arg1: i32, arg2: i32) { + if self.usingGraphite() { + aat_print_font_name(c, self.attributes, arg1, arg2); + } } - // CFComparisonResult is missing PartialEq - pub fn comparison_was(a: CFComparisonResult, b: CFComparisonResult) -> bool { - match (a, b) { - (CFComparisonResult::LessThan, CFComparisonResult::LessThan) => true, - (CFComparisonResult::EqualTo, CFComparisonResult::EqualTo) => true, - (CFComparisonResult::GreaterThan, CFComparisonResult::GreaterThan) => true, - _ => false, + unsafe fn get_font_metrics( + &self, + ascent: &mut Fixed, + descent: &mut Fixed, + x_ht: &mut Fixed, + cap_ht: &mut Fixed, + slant: &mut Fixed, + ) { + aat_get_font_metrics(self.attributes, ascent, descent, x_ht, cap_ht, slant); + } + + unsafe fn get_flags(&self, _font_number: u32) -> i32 { + if !CFDictionaryGetValue( + self.attributes, + kCTVerticalFormsAttributeName as *const libc::c_void, + ) + .is_null() + { + 0x100 + } else { + 0 } } - pub use core_graphics::{ - base::CGFloat, - color::{CGColor, SysCGColorRef as CGColorRef}, - font::CGGlyph, - geometry::{CGAffineTransform, CGPoint, CGRect, CGSize}, - }; - extern "C" { - #[no_mangle] - pub static CGAffineTransformIdentity: CGAffineTransform; - #[no_mangle] - pub fn CGRectIsNull(rect: CGRect) -> bool; + /// ot_font_get, aat_font_get + unsafe fn poorly_named_getter(&self, mut what: i32) -> i32 { + aat_font_get(what, self.attributes) } - pub use core_text::run::CTRunRef; - extern "C" { - #[no_mangle] - pub fn CTRunGetGlyphCount(run: CTRunRef) -> CFIndex; - #[no_mangle] - pub fn CTRunGetAttributes(run: CTRunRef) -> CFDictionaryRef; - #[no_mangle] - pub fn CTRunGetGlyphs(run: CTRunRef, range: CFRange, buffer: *mut CGGlyph); - #[no_mangle] - pub fn CTRunGetPositions(run: CTRunRef, range: CFRange, buffer: *mut CGPoint); - #[no_mangle] - pub fn CTRunGetAdvances(run: CTRunRef, range: CFRange, buffer: *mut CGSize); - #[no_mangle] - pub fn CTLineGetGlyphCount(line: CTLineRef) -> CFIndex; - #[no_mangle] - pub fn CTLineGetGlyphRuns(line: CTLineRef) -> CFArrayRef; - #[no_mangle] - pub fn CTRunGetTypographicBounds( - run: CTRunRef, - range: CFRange, - ascent: *mut CGFloat, - descent: *mut CGFloat, - leading: *mut CGFloat, - ) -> libc::c_double; + + /// ot_font_get_1, aat_font_get_1 + unsafe fn poorly_named_getter_1(&self, mut what: i32, mut param1: i32) -> i32 { + aat_font_get_1(what, self.attributes, param1) } - pub use core_text::{ - font::CTFontRef, - font_descriptor::{ - kCTFontCascadeListAttribute, kCTFontFeatureSettingsAttribute, - kCTFontOrientationAttribute, kCTFontURLAttribute, CTFontDescriptor, - CTFontDescriptorCreateWithAttributes, CTFontDescriptorCreateWithNameAndSize, - CTFontDescriptorRef, CTFontOrientation, - }, - line::CTLineRef, - string_attributes::{ - kCTFontAttributeName, kCTForegroundColorAttributeName, kCTKernAttributeName, - kCTVerticalFormsAttributeName, - }, - }; + /// ot_font_get_2, aat_font_get_2 + unsafe fn poorly_named_getter_2(&self, mut what: i32, mut param1: i32, mut param2: i32) -> i32 { + aat_font_get_2(what, self.attributes, param1, param2) + } - pub const kCTFontVerticalOrientation: CTFontOrientation = 2; - pub const kCTFontHorizontalOrientation: CTFontOrientation = 1; - pub const kCTFontDefaultOrientation: CTFontOrientation = 0; - pub const kCTFontOrientationVertical: CTFontOrientation = 2; - pub const kCTFontOrientationHorizontal: CTFontOrientation = 1; - pub const kCTFontOrientationDefault: CTFontOrientation = 0; + /// ot_font_get_3 + unsafe fn poorly_named_getter_3(&self, what: i32, param1: i32, param2: i32, param3: i32) -> i32 { + unimplemented!() + } - // The CGFont wrapper is not feature complete. - pub type CGFontRef = *const __CGFont; - extern "C" { - pub type __CGFont; - #[no_mangle] - pub fn CGFontGetNumberOfGlyphs(font: CGFontRef) -> usize; - #[no_mangle] - pub fn CGFontRelease(font: CGFontRef); - #[no_mangle] - pub fn CGFontCopyGlyphNameForGlyph(font: CGFontRef, glyph: CGGlyph) -> CFStringRef; - #[no_mangle] - pub fn CTFontCopyGraphicsFont( - font: CTFontRef, - attributes: *mut CTFontDescriptorRef, - ) -> CGFontRef; - #[no_mangle] - pub static kCTFontPostScriptNameKey: CFStringRef; + /// getExtendFactor + unsafe fn extend_factor(&self) -> f64 { + self.transform().a } - // Typesetters - pub type CTTypesetterRef = *const __CTTypesetter; - extern "C" { - pub type __CTTypesetter; - #[no_mangle] - pub fn CTTypesetterCreateWithAttributedString( - string: CFAttributedStringRef, - ) -> CTTypesetterRef; - #[no_mangle] - pub fn CTTypesetterCreateLine( - typesetter: CTTypesetterRef, - stringRange: CFRange, - ) -> CTLineRef; + + unsafe fn slant_factor(&self) -> f64 { + self.transform().c } - // misc - extern "C" { - #[no_mangle] - pub fn CTFontCreateWithFontDescriptor( - descriptor: CTFontDescriptorRef, - size: CGFloat, - matrix: *const CGAffineTransform, - ) -> CTFontRef; - #[no_mangle] - pub fn CTLineCreateJustifiedLine( - line: CTLineRef, - justificationFactor: CGFloat, - justificationWidth: libc::c_double, - ) -> CTLineRef; - #[no_mangle] - pub fn CFStringCreateWithCharactersNoCopy( - alloc: CFAllocatorRef, - chars: *const UniChar, - numChars: CFIndex, - contentsDeallocator: CFAllocatorRef, - ) -> CFStringRef; - #[no_mangle] - pub fn CTFontCreateCopyWithAttributes( - font: CTFontRef, - size: CGFloat, - matrix: *const CGAffineTransform, - attributes: CTFontDescriptorRef, - ) -> CTFontRef; - #[no_mangle] - pub fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef; - #[no_mangle] - pub fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; - #[no_mangle] - pub fn CTFontGetGlyphsForCharacters( - font: CTFontRef, - characters: *const UniChar, - glyphs: *mut CGGlyph, - count: CFIndex, - ) -> bool; - #[no_mangle] - pub fn CTFontGetGlyphWithName(font: CTFontRef, glyphName: CFStringRef) -> CGGlyph; - #[no_mangle] - pub fn CTFontGetBoundingRectsForGlyphs( - font: CTFontRef, - orientation: CTFontOrientation, - glyphs: *const CGGlyph, - boundingRects: *mut CGRect, - count: CFIndex, - ) -> CGRect; - #[no_mangle] - pub fn CTFontGetAdvancesForGlyphs( - font: CTFontRef, - orientation: CTFontOrientation, - glyphs: *const CGGlyph, - advances: *mut CGSize, - count: CFIndex, - ) -> libc::c_double; - #[no_mangle] - pub static kCTFontFeatureTypeIdentifierKey: CFStringRef; - #[no_mangle] - pub static kCTFontFeatureTypeNameKey: CFStringRef; - #[no_mangle] - pub static kCTFontFeatureTypeSelectorsKey: CFStringRef; - #[no_mangle] - pub static kCTFontFeatureTypeExclusiveKey: CFStringRef; - #[no_mangle] - pub fn CTFontCopyFeatures(font: CTFontRef) -> CFArrayRef; - #[no_mangle] - pub static kCTFontFeatureSelectorNameKey: CFStringRef; - #[no_mangle] - pub static kCTFontFeatureSelectorDefaultKey: CFStringRef; - #[no_mangle] - pub static kCTFontFeatureSelectorIdentifierKey: CFStringRef; - #[no_mangle] - pub fn CTFontGetXHeight(font: CTFontRef) -> CGFloat; - #[no_mangle] - pub fn CTFontGetAscent(font: CTFontRef) -> CGFloat; - #[no_mangle] - pub fn CTFontGetDescent(font: CTFontRef) -> CGFloat; - #[no_mangle] - pub fn CTFontGetGlyphCount(font: CTFontRef) -> CFIndex; - #[no_mangle] - pub fn CTFontGetSlantAngle(font: CTFontRef) -> CGFloat; - #[no_mangle] - pub fn CTFontGetCapHeight(font: CTFontRef) -> CGFloat; - #[no_mangle] - pub fn CFStringGetCharacters(theString: CFStringRef, range: CFRange, buffer: *mut UniChar); - #[no_mangle] - pub fn CFArrayGetValueAtIndex(theArray: CFArrayRef, idx: CFIndex) -> *const libc::c_void; - #[no_mangle] - pub fn CTFontGetSize(font: CTFontRef) -> CGFloat; - #[no_mangle] - pub fn CTFontGetMatrix(font: CTFontRef) -> CGAffineTransform; - #[no_mangle] - pub fn CGColorGetComponents(color: CGColorRef) -> *const CGFloat; - #[no_mangle] - pub fn CFBooleanGetValue(boolean: CFBooleanRef) -> libc::c_uchar; + unsafe fn point_size(&self) -> f64 { + unsafe { CTFontGetSize(self.ct_font()) } } - pub type UniChar = UInt16; - pub type UInt16 = libc::c_ushort; + /// getAscentAndDescent + unsafe fn ascent_and_descent(&self, ascent: &mut f32, descent: &mut f32) { + unimplemented!() + } - #[inline(always)] - pub fn CFRangeMake(mut loc: CFIndex, mut len: CFIndex) -> CFRange { - let mut range: CFRange = CFRange { - location: 0, - length: 0, - }; - range.location = loc; - range.length = len; - range + /// getCapAndXHeight + unsafe fn cap_and_x_height(&self, capheight: &mut f32, xheight: &mut f32) { + unimplemented!() } - pub unsafe fn cgColorToRGBA32(mut color: CGColorRef) -> u32 { - let mut components: *const CGFloat = CGColorGetComponents(color); - let mut rval: u32 = (*components.offset(0) * 255.0f64 + 0.5f64) as u8 as u32; - rval <<= 8i32; - rval = (rval as u32).wrapping_add((*components.offset(1) * 255.0f64 + 0.5f64) as u8 as u32); - rval <<= 8i32; - rval = (rval as u32).wrapping_add((*components.offset(2) * 255.0f64 + 0.5f64) as u8 as u32); - rval <<= 8i32; - rval = (rval as u32).wrapping_add((*components.offset(3) * 255.0f64 + 0.5f64) as u8 as u32); - return rval; + /// getEmboldenFactor + unsafe fn embolden_factor(&self) -> f32 { + let mut embolden: f32 = 0.; + unsafe { + let emboldenNumber = CFDictionaryGetValue( + self.attributes, + getkXeTeXEmboldenAttributeName() as *const libc::c_void, + ) as CFNumberRef; + if !emboldenNumber.is_null() { + CFNumberGetValue( + emboldenNumber, + kCFNumberFloatType as libc::c_int as CFNumberType, + &mut embolden as *mut libc::c_float as *mut libc::c_void, + ); + } + } + embolden + } + + /// getRgbValue + unsafe fn rgb_value(&self) -> u32 { + let color = unsafe { + CFDictionaryGetValue( + self.attributes, + kCTForegroundColorAttributeName as *const libc::c_void, + ) + } as CGColorRef; + if !color.is_null() { + unsafe { cgColorToRGBA32(color) } + } else { + 0 + } + } + + /// getGlyphName + /// Only used for debugging. Should be a String/CStr then! + unsafe fn glyph_name(&self, gid: u16, len: &mut libc::c_int) -> *const libc::c_char { + GetGlyphNameFromCTFont(font_from_attributes(self.attributes), gid, len) + } + + unsafe fn glyph_width(&self, gid: u32) -> f64 { + GetGlyphWidth_AAT(self.attributes, gid as u16) + } + + /// getGlyphBounds (had out param) + unsafe fn glyph_bbox(&self, glyphID: u32) -> Option { + let mut bbox = GlyphBBox::zero(); + GetGlyphBBox_AAT(self.attributes, glyphID as u16, &mut bbox); + Some(bbox) + } + + unsafe fn getGlyphWidthFromEngine(&self, glyphID: u32) -> f64 { + GetGlyphWidth_AAT(self.attributes, glyphID as u16) + } + + /// getGlyphHeightDepth (had out params height, depth) + unsafe fn glyph_height_depth(&self, glyphID: u32) -> Option<(f32, f32)> { + let mut h = 0.; + let mut d = 0.; + GetGlyphHeightDepth_AAT(self.attributes, glyphID as u16, &mut h, &mut d); + Some((h, d)) + } + + /// getGlyphSidebearings (had out params lsb, rsb) + unsafe fn glyph_sidebearings(&self, glyphID: u32) -> Option<(f32, f32)> { + let mut a = 0.; + let mut b = 0.; + GetGlyphSidebearings_AAT(self.attributes, glyphID as u16, &mut a, &mut b); + Some((a, b)) + } + + /// getGlyphItalCorr + unsafe fn glyph_ital_correction(&self, glyphID: u32) -> Option { + Some(GetGlyphItalCorr_AAT(self.attributes, glyphID as u16)) + } + + /// mapCharToGlyph + unsafe fn map_char_to_glyph(&self, codepoint: u32) -> u32 { + // XXX: not sure about this as cast + MapCharToGlyph_AAT(self.attributes, codepoint) as u32 + } + + /// getFontCharRange + /// Another candidate for using XeTeXFontInst directly + unsafe fn font_char_range(&self, reqFirst: libc::c_int) -> libc::c_int { + GetFontCharRange_AAT(self.attributes, reqFirst) + } + + /// mapGlyphToIndex + /// Should use engine.font directly + unsafe fn map_glyph_to_index(&self, glyphName: *const libc::c_char) -> i32 { + MapGlyphToIndex_AAT(self.attributes, glyphName) } } @@ -359,11 +392,13 @@ use crate::core_memory::{xcalloc, xmalloc}; use crate::xetex_ext::{print_chars, readCommonFeatures, read_double, D2Fix, Fix2D}; use crate::xetex_ini::memory_word; use crate::xetex_ini::{ - font_area, font_layout_engine, font_letter_space, loaded_font_flags, loaded_font_letter_space, - name_length, name_of_file, native_font_type_flag, + font_letter_space, loaded_font_flags, loaded_font_letter_space, name_length, name_of_file, + native_font_type_flag, FONT_AREA, }; use crate::xetex_xetex0::font_feature_warning; -use libc::{free, strcmp, strdup, strlen, strncmp}; +#[cfg(not(unix))] +use libc::strdup; +use libc::{free, strdup, strlen}; type int32_t = libc::c_int; type uint16_t = libc::c_ushort; pub type Boolean = libc::c_uchar; @@ -371,15 +406,6 @@ type scaled_t = int32_t; type UInt32 = libc::c_uint; type SInt32 = libc::c_int; -type Fixed = SInt32; -type Fract = SInt32; -#[derive(Copy, Clone)] -#[repr(C, packed(2))] -struct FixedPoint { - x: Fixed, - y: Fixed, -} - pub type str_number = int32_t; /* tectonic/core-strutils.h: miscellaneous C string utilities Copyright 2016-2018 the Tectonic Project @@ -388,7 +414,7 @@ pub type str_number = int32_t; /* Note that we explicitly do *not* change this on Windows. For maximum * portability, we should probably accept *either* forward or backward slashes * as directory separators. */ -use crate::{streq_ptr, strstartswith}; +use crate::strstartswith; /* ***************************************************************************\ Part of the XeTeX typesetting system Copyright (c) 1994-2008 by SIL International @@ -443,178 +469,6 @@ unsafe fn font_from_attributes(mut attributes: CFDictionaryRef) -> CTFontRef { as CTFontRef; } -pub unsafe fn font_from_integer(mut font: int32_t) -> CTFontRef { - let mut attributes: CFDictionaryRef = - *font_layout_engine.offset(font as isize) as CFDictionaryRef; - return font_from_attributes(attributes); -} - -pub unsafe fn do_aat_layout(mut p: *mut libc::c_void, mut justify: libc::c_int) { - let mut glyphRuns: CFArrayRef = ptr::null_mut(); - let mut i: CFIndex = 0; - let mut j: CFIndex = 0; - let mut runCount: CFIndex = 0; - let mut totalGlyphCount: CFIndex = 0; - let mut glyphIDs: *mut UInt16 = ptr::null_mut(); - let mut glyphAdvances: *mut Fixed = ptr::null_mut(); - let mut glyph_info: *mut libc::c_void = ptr::null_mut(); - let mut locations: *mut FixedPoint = ptr::null_mut(); - let mut width: CGFloat = 0.; - let mut txtLen: CFIndex = 0; - let mut txtPtr: *const UniChar = ptr::null_mut(); - let mut attributes: CFDictionaryRef = ptr::null_mut(); - let mut string: CFStringRef = ptr::null_mut(); - let mut attrString: CFAttributedStringRef = ptr::null_mut(); - let mut typesetter: CTTypesetterRef = 0 as CTTypesetterRef; - let mut line: CTLineRef = ptr::null_mut(); - let mut node: *mut memory_word = p as *mut memory_word; - let mut f: libc::c_uint = (*node.offset(4)).b16.s2 as libc::c_uint; - if *font_area.offset(f as isize) as libc::c_uint != 0xffffu32 { - panic!("do_aat_layout called for non-AAT font"); - } - txtLen = (*node.offset(4)).b16.s1 as CFIndex; - txtPtr = node.offset(6) as *mut UniChar; - attributes = *font_layout_engine.offset((*node.offset(4)).b16.s2 as isize) as CFDictionaryRef; - string = CFStringCreateWithCharactersNoCopy(ptr::null(), txtPtr, txtLen, kCFAllocatorNull); - attrString = CFAttributedStringCreate(ptr::null(), string, attributes); - CFRelease(string as CFTypeRef); - typesetter = CTTypesetterCreateWithAttributedString(attrString); - CFRelease(attrString as CFTypeRef); - line = CTTypesetterCreateLine(typesetter, CFRangeMake(0i32 as CFIndex, txtLen)); - if justify != 0 { - let mut lineWidth: CGFloat = TeXtoPSPoints(Fix2D((*node.offset(1)).b32.s1)); - let mut justifiedLine: CTLineRef = CTLineCreateJustifiedLine( - line, - TeXtoPSPoints(Fix2D(0x40000000i64 as Fract)), - lineWidth, - ); - // TODO(jjgod): how to handle the case when justification failed? for - // now we just fallback to use the original line. - if !justifiedLine.is_null() { - CFRelease(line as CFTypeRef); - line = justifiedLine - } - } - glyphRuns = CTLineGetGlyphRuns(line); - runCount = CFArrayGetCount(glyphRuns); - totalGlyphCount = CTLineGetGlyphCount(line); - if totalGlyphCount > 0 { - glyph_info = xmalloc((totalGlyphCount * 10) as _); - locations = glyph_info as *mut FixedPoint; - glyphIDs = locations.offset(totalGlyphCount as isize) as *mut UInt16; - glyphAdvances = - xmalloc((totalGlyphCount as usize).wrapping_mul(::std::mem::size_of::()) as _) - as *mut Fixed; - totalGlyphCount = 0i32 as CFIndex; - width = 0i32 as CGFloat; - i = 0i32 as CFIndex; - while i < runCount { - let mut run: CTRunRef = CFArrayGetValueAtIndex(glyphRuns, i) as CTRunRef; - let mut count: CFIndex = CTRunGetGlyphCount(run); - let mut runAttributes: CFDictionaryRef = CTRunGetAttributes(run); - let mut vertical: CFBooleanRef = CFDictionaryGetValue( - runAttributes, - kCTVerticalFormsAttributeName as *const libc::c_void, - ) as CFBooleanRef; - // TODO(jjgod): Avoid unnecessary allocation with CTRunGetFoosPtr(). - let mut glyphs: *mut CGGlyph = - xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) - as *mut CGGlyph; - let mut positions: *mut CGPoint = - xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) - as *mut CGPoint; - let mut advances: *mut CGSize = - xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) - as *mut CGSize; - let mut runWidth: CGFloat = CTRunGetTypographicBounds( - run, - CFRangeMake(0i32 as CFIndex, 0i32 as CFIndex), - ptr::null_mut(), - ptr::null_mut(), - ptr::null_mut(), - ); - CTRunGetGlyphs(run, CFRangeMake(0i32 as CFIndex, 0i32 as CFIndex), glyphs); - CTRunGetPositions( - run, - CFRangeMake(0i32 as CFIndex, 0i32 as CFIndex), - positions, - ); - CTRunGetAdvances(run, CFRangeMake(0i32 as CFIndex, 0i32 as CFIndex), advances); - j = 0i32 as CFIndex; - while j < count { - // XXX Core Text has that font cascading thing that will do - // font substitution for missing glyphs, which we do not want - // but I can not find a way to disable it yet, so if the font - // of the resulting run is not the same font we asked for, use - // the glyph at index 0 (usually .notdef) instead or we will be - // showing garbage or even invalid glyphs - if CFEqual( - font_from_attributes(attributes) as CFTypeRef, - font_from_attributes(runAttributes) as CFTypeRef, - ) == 0 - { - *glyphIDs.offset(totalGlyphCount as isize) = 0i32 as UInt16 - } else { - *glyphIDs.offset(totalGlyphCount as isize) = *glyphs.offset(j as isize) - } - // Swap X and Y when doing vertical layout - if vertical == kCFBooleanTrue { - (*locations.offset(totalGlyphCount as isize)).x = - -FixedPStoTeXPoints((*positions.offset(j as isize)).y); - (*locations.offset(totalGlyphCount as isize)).y = - FixedPStoTeXPoints((*positions.offset(j as isize)).x) - } else { - (*locations.offset(totalGlyphCount as isize)).x = - FixedPStoTeXPoints((*positions.offset(j as isize)).x); - (*locations.offset(totalGlyphCount as isize)).y = - -FixedPStoTeXPoints((*positions.offset(j as isize)).y) - } - *glyphAdvances.offset(totalGlyphCount as isize) = - (*advances.offset(j as isize)).width as Fixed; - totalGlyphCount += 1; - j += 1 - } - width += FixedPStoTeXPoints(runWidth) as libc::c_double; - free(glyphs as *mut libc::c_void); - free(positions as *mut libc::c_void); - free(advances as *mut libc::c_void); - i += 1 - } - } - (*node.offset(4)).b16.s0 = totalGlyphCount as uint16_t; - let ref mut fresh0 = (*node.offset(5)).ptr; - *fresh0 = glyph_info; - if justify == 0 { - (*node.offset(1)).b32.s1 = width as int32_t; - if totalGlyphCount > 0 { - /* this is essentially a copy from similar code in XeTeX_ext.c, easier - * to be done here */ - if *font_letter_space.offset(f as isize) != 0i32 { - let mut lsDelta: Fixed = 0i32; - let mut lsUnit: Fixed = *font_letter_space.offset(f as isize); - let mut i_0 = 0; - while i_0 < totalGlyphCount { - if *glyphAdvances.offset(i_0 as isize) == 0i32 && lsDelta != 0i32 { - lsDelta -= lsUnit - } - let ref mut fresh1 = (*locations.offset(i_0 as isize)).x; - *fresh1 += lsDelta; - lsDelta += lsUnit; - i_0 += 1 - } - if lsDelta != 0i32 { - lsDelta -= lsUnit; - let ref mut fresh2 = (*node.offset(1)).b32.s1; - *fresh2 += lsDelta - } - } - } - } - free(glyphAdvances as *mut libc::c_void); - CFRelease(line as CFTypeRef); - CFRelease(typesetter as CFTypeRef); -} - unsafe fn getGlyphBBoxFromCTFont(mut font: CTFontRef, mut gid: UInt16, mut bbox: *mut GlyphBBox) { let mut rect: CGRect = CGRect { origin: CGPoint { x: 0., y: 0. }, @@ -867,15 +721,13 @@ unsafe fn ct_font_get_postscript_name(ctFontRef: CTFontRef, nameKey: CFStringRef CFString::wrap_under_create_rule(name) } -thread_local!(static FREETYPE_LIBRARY: RefCell = RefCell::new(FreeTypeLibrary::init().unwrap())); - -// This needs to be linked from C++, hence extern "C" +// This will become unnecessary as font_kit spreads. #[no_mangle] pub unsafe extern "C" fn getFileNameFromCTFont( mut ctFontRef: CTFontRef, mut index: *mut u32, ) -> *mut i8 { - let mut ix: i32 = -1; + let mut ix = None; let mut ret: *mut libc::c_char = 0 as *mut libc::c_char; let urlRef = CTFontCopyAttribute(ctFontRef, kCTFontURLAttribute) as CFURLRef; if !urlRef.is_null() { @@ -884,36 +736,42 @@ pub unsafe extern "C" fn getFileNameFromCTFont( let ps_name1 = ct_font_get_postscript_name(ctFontRef, kCTFontPostScriptNameKey); let ps_name = Cow::from(&ps_name1); - let mut i: isize = 0; - while let Ok(face) = FREETYPE_LIBRARY.with(|l| l.borrow().new_face(&pathbuf, i)) { - if let Some(ps_name2) = face.postscript_name() { + let mut handle = Handle::Path { + path: pathbuf.clone(), + font_index: 0, + }; + // Saves cloning the path + fn set_index(handle: &mut Handle, i: u32) { + match handle { + Handle::Memory { + ref mut font_index, .. + } + | Handle::Path { + ref mut font_index, .. + } => *font_index = i, + } + } + let mut i = 0u32; + while let Ok(font) = handle.load() { + if let Some(ps_name2) = font.postscript_name() { if ps_name2 == ps_name { - ix = i as i32; + ix = Some(i); break; } } i += 1; + set_index(&mut handle, i); } - if ix > -1 { - *index = ix as u32; + + if let Some(ix) = ix { + *index = ix; let osstr = pathbuf.as_os_str(); - #[cfg(unix)] - { - use std::os::unix::ffi::OsStrExt; - let bytes = osstr.as_bytes(); - ret = - xcalloc((bytes.len() + 1) as _, std::mem::size_of::() as _) as *mut i8; - for i in 0..bytes.len() { - *ret.offset(i as isize) = bytes[i] as i8; - } - } - #[cfg(not(unix))] - { - // On Windows, given the limitations of the bridge API, we don't actually - // support full-on OsStrings anyway, so we'll just work with utf8. - let cstring = CString::from(osstr.to_string_lossy()); - let bytes = cstring.as_bytes(); - ret = strdup(bytes.as_ptr()); + // We're on macOS; std::os::unix is available. + use std::os::unix::ffi::OsStrExt; + let bytes = osstr.as_bytes(); + ret = xcalloc((bytes.len() + 1) as _, std::mem::size_of::() as _) as *mut i8; + for i in 0..bytes.len() { + *ret.offset(i as isize) = bytes[i] as i8; } } } @@ -1077,8 +935,8 @@ unsafe fn getLastResort() -> CFStringRef { pub unsafe fn loadAATfont( mut descriptor: CTFontDescriptorRef, mut scaled_size: int32_t, - mut cp1: *const libc::c_char, -) -> *mut libc::c_void { + mut cp1: Option<&CStr>, +) -> Option { let mut current_block: u64; let mut font: CTFontRef = 0 as CTFontRef; let mut actualFont: CTFontRef = 0 as CTFontRef; @@ -1105,7 +963,7 @@ pub unsafe fn loadAATfont( ctSize = TeXtoPSPoints(Fix2D(scaled_size)); font = CTFontCreateWithFontDescriptor(descriptor, ctSize, 0 as *const CGAffineTransform); if font.is_null() { - return 0 as *mut libc::c_void; + return None; } stringAttributes = CFDictionaryCreateMutable( 0 as CFAllocatorRef, @@ -1119,7 +977,7 @@ pub unsafe fn loadAATfont( &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks, ); - if !cp1.is_null() { + if let Some(mut cp1) = cp1.map(|x| x.as_ptr()) { let mut features: CFArrayRef = CTFontCopyFeatures(font); let mut featureSettings: CFMutableArrayRef = CFArrayCreateMutable(0 as CFAllocatorRef, 0i32 as CFIndex, &kCFTypeArrayCallBacks); @@ -1429,7 +1287,7 @@ pub unsafe fn loadAATfont( ); CFRelease(actualFont as CFTypeRef); native_font_type_flag = 0xffffu32 as int32_t; - return stringAttributes as *mut libc::c_void; + return Some(TextLayoutEngine::AAT(AATLayoutEngine { attributes: stringAttributes })); } /* the metrics params here are really TeX 'scaled' (or MacOS 'Fixed') values, but that typedef isn't available every place this is included */ @@ -1616,70 +1474,63 @@ pub unsafe fn aat_font_get_2( return rval; } -#[no_mangle] -pub unsafe fn aat_font_get_named( - mut what: libc::c_int, - mut attributes: CFDictionaryRef, -) -> libc::c_int { - let mut rval: libc::c_int = -1i32; - if what == 10i32 { - let mut font: CTFontRef = font_from_attributes(attributes); - let mut features: CFArrayRef = CTFontCopyFeatures(font); - if !features.is_null() { - let mut feature: CFDictionaryRef = findDictionaryInArray( - features, - kCTFontFeatureTypeNameKey as *const libc::c_void, - name_of_file, - name_length, - ); - if !feature.is_null() { - let mut identifier: CFNumberRef = CFDictionaryGetValue( - feature, - kCTFontFeatureTypeIdentifierKey as *const libc::c_void, - ) as CFNumberRef; - CFNumberGetValue( - identifier, - kCFNumberIntType as libc::c_int as CFNumberType, - &mut rval as *mut libc::c_int as *mut libc::c_void, +impl AATLayoutEngine { + pub unsafe fn aat_font_get_named(&self, mut what: libc::c_int) -> libc::c_int { + let mut rval: libc::c_int = -1i32; + if what == 10i32 { + let mut font: CTFontRef = self.ct_font(); + let mut features: CFArrayRef = CTFontCopyFeatures(font); + if !features.is_null() { + let mut feature: CFDictionaryRef = findDictionaryInArray( + features, + kCTFontFeatureTypeNameKey as *const libc::c_void, + name_of_file, + name_length, ); - } - CFRelease(features as CFTypeRef); - } - } - return rval; -} - -#[no_mangle] -pub unsafe fn aat_font_get_named_1( - mut what: i32, - mut attributes: CFDictionaryRef, - mut param: i32, -) -> i32 { - let mut rval: libc::c_int = -1i32; - let mut font: CTFontRef = font_from_attributes(attributes); - if what == 14i32 { - let mut features: CFArrayRef = CTFontCopyFeatures(font); - if !features.is_null() { - let mut feature: CFDictionaryRef = findDictionaryInArrayWithIdentifier( - features, - kCTFontFeatureTypeIdentifierKey as *const libc::c_void, - param, - ); - if !feature.is_null() { - let mut selector: CFNumberRef = - findSelectorByName(feature, name_of_file, name_length); - if !selector.is_null() { + if !feature.is_null() { + let mut identifier: CFNumberRef = CFDictionaryGetValue( + feature, + kCTFontFeatureTypeIdentifierKey as *const libc::c_void, + ) as CFNumberRef; CFNumberGetValue( - selector, + identifier, kCFNumberIntType as libc::c_int as CFNumberType, &mut rval as *mut libc::c_int as *mut libc::c_void, ); } + CFRelease(features as CFTypeRef); } - CFRelease(features as CFTypeRef); } + return rval; + } + + pub unsafe fn aat_font_get_named_1(&self, mut what: i32, mut param: i32) -> i32 { + let mut rval: libc::c_int = -1i32; + let mut font: CTFontRef = self.ct_font(); + if what == 14i32 { + let mut features: CFArrayRef = CTFontCopyFeatures(font); + if !features.is_null() { + let mut feature: CFDictionaryRef = findDictionaryInArrayWithIdentifier( + features, + kCTFontFeatureTypeIdentifierKey as *const libc::c_void, + param, + ); + if !feature.is_null() { + let mut selector: CFNumberRef = + findSelectorByName(feature, name_of_file, name_length); + if !selector.is_null() { + CFNumberGetValue( + selector, + kCFNumberIntType as libc::c_int as CFNumberType, + &mut rval as *mut libc::c_int as *mut libc::c_void, + ); + } + } + CFRelease(features as CFTypeRef); + } + } + return rval; } - return rval; } #[no_mangle] @@ -1735,3 +1586,383 @@ pub unsafe fn aat_print_font_name( free(buf as *mut libc::c_void); }; } + +pub mod cf_prelude { + pub use core_foundation::{ + attributed_string::{CFAttributedString, CFAttributedStringCreate, CFAttributedStringRef}, + base::{ + kCFAllocatorDefault, kCFAllocatorNull, CFAllocatorRef, CFComparisonResult, CFEqual, + CFHashCode, CFIndex, CFOptionFlags, CFRange, CFRelease, CFRetain, CFTypeRef, ToVoid, + }, + boolean::{kCFBooleanTrue, CFBooleanRef}, + dictionary::{ + kCFTypeDictionaryKeyCallBacks, kCFTypeDictionaryValueCallBacks, CFDictionary, + CFDictionaryAddValue, CFDictionaryCopyDescriptionCallBack, CFDictionaryCreate, + CFDictionaryCreateMutable, CFDictionaryEqualCallBack, CFDictionaryGetValueIfPresent, + CFDictionaryHashCallBack, CFDictionaryKeyCallBacks, CFDictionaryRef, + CFDictionaryReleaseCallBack, CFDictionaryRetainCallBack, CFDictionaryValueCallBacks, + CFMutableDictionaryRef, + }, + number::{CFNumberCompare, CFNumberCreate, CFNumberGetValue, CFNumberRef, CFNumberType}, + set::{kCFTypeSetCallBacks, CFSet, CFSetCreate, CFSetRef}, + string::{ + kCFStringEncodingUTF8, CFStringCompareFlags, CFStringCreateWithBytes, + CFStringCreateWithCString, CFStringEncoding, CFStringGetCString, CFStringGetLength, + CFStringRef, + }, + url::{CFURLGetFileSystemRepresentation, CFURLRef}, + }; + pub const kCFNumberMaxType: CFNumberType = 16; + pub const kCFNumberCGFloatType: CFNumberType = 16; + pub const kCFNumberNSIntegerType: CFNumberType = 15; + pub const kCFNumberCFIndexType: CFNumberType = 14; + pub const kCFNumberDoubleType: CFNumberType = 13; + pub const kCFNumberFloatType: CFNumberType = 12; + pub const kCFNumberLongLongType: CFNumberType = 11; + pub const kCFNumberLongType: CFNumberType = 10; + pub const kCFNumberIntType: CFNumberType = 9; + pub const kCFNumberShortType: CFNumberType = 8; + pub const kCFNumberCharType: CFNumberType = 7; + pub const kCFNumberFloat64Type: CFNumberType = 6; + pub const kCFNumberFloat32Type: CFNumberType = 5; + pub const kCFNumberSInt64Type: CFNumberType = 4; + pub const kCFNumberSInt32Type: CFNumberType = 3; + pub const kCFNumberSInt16Type: CFNumberType = 2; + pub const kCFNumberSInt8Type: CFNumberType = 1; + + pub const kCFStringEncodingUTF32LE: CFStringEncoding = 469762304; + pub const kCFStringEncodingUTF32BE: CFStringEncoding = 402653440; + pub const kCFStringEncodingUTF32: CFStringEncoding = 201326848; + pub const kCFStringEncodingUTF16LE: CFStringEncoding = 335544576; + pub const kCFStringEncodingUTF16BE: CFStringEncoding = 268435712; + pub const kCFStringEncodingUTF16: CFStringEncoding = 256; + pub const kCFStringEncodingNonLossyASCII: CFStringEncoding = 3071; + pub const kCFStringEncodingUnicode: CFStringEncoding = 256; + pub const kCFStringEncodingASCII: CFStringEncoding = 1536; + pub const kCFStringEncodingNextStepLatin: CFStringEncoding = 2817; + pub const kCFStringEncodingISOLatin1: CFStringEncoding = 513; + pub const kCFStringEncodingWindowsLatin1: CFStringEncoding = 1280; + pub const kCFStringEncodingMacRoman: CFStringEncoding = 0; + + pub const kCFCompareForcedOrdering: CFStringCompareFlags = 512; + pub const kCFCompareWidthInsensitive: CFStringCompareFlags = 256; + pub const kCFCompareDiacriticInsensitive: CFStringCompareFlags = 128; + pub const kCFCompareNumerically: CFStringCompareFlags = 64; + pub const kCFCompareLocalized: CFStringCompareFlags = 32; + pub const kCFCompareNonliteral: CFStringCompareFlags = 16; + pub const kCFCompareAnchored: CFStringCompareFlags = 8; + pub const kCFCompareBackwards: CFStringCompareFlags = 4; + pub const kCFCompareCaseInsensitive: CFStringCompareFlags = 1; + + // The CFArray wrapper is not mutable, so we use the APIs directly + pub use core_foundation::array::{ + kCFTypeArrayCallBacks, CFArrayCallBacks, CFArrayCopyDescriptionCallBack, + CFArrayEqualCallBack, CFArrayGetCount, CFArrayRef, CFArrayReleaseCallBack, + CFArrayRetainCallBack, __CFArray, + }; + pub type CFMutableArrayRef = *mut __CFArray; + extern "C" { + #[no_mangle] + pub fn CFArrayCreateMutable( + allocator: CFAllocatorRef, + capacity: CFIndex, + callBacks: *const CFArrayCallBacks, + ) -> CFMutableArrayRef; + #[no_mangle] + pub fn CFArrayCreate( + allocator: CFAllocatorRef, + values: *mut *const libc::c_void, + numValues: CFIndex, + callBacks: *const CFArrayCallBacks, + ) -> CFArrayRef; + #[no_mangle] + pub fn CFArrayAppendValue(theArray: CFMutableArrayRef, value: *const libc::c_void); + } + extern "C" { + // Missing + #[no_mangle] + pub fn CFStringCreateWithCStringNoCopy( + alloc: CFAllocatorRef, + cStr: *const libc::c_char, + encoding: CFStringEncoding, + contentsDeallocator: CFAllocatorRef, + ) -> CFStringRef; + #[no_mangle] + pub fn CFStringCompare( + theString1: CFStringRef, + theString2: CFStringRef, + compareOptions: CFStringCompareFlags, + ) -> CFComparisonResult; + } + extern "C" { + #[no_mangle] + pub fn CFDictionaryGetValue( + theDict: CFDictionaryRef, + key: *const libc::c_void, + ) -> *const libc::c_void; + } + + // CFComparisonResult is missing PartialEq + pub fn comparison_was(a: CFComparisonResult, b: CFComparisonResult) -> bool { + match (a, b) { + (CFComparisonResult::LessThan, CFComparisonResult::LessThan) => true, + (CFComparisonResult::EqualTo, CFComparisonResult::EqualTo) => true, + (CFComparisonResult::GreaterThan, CFComparisonResult::GreaterThan) => true, + _ => false, + } + } + + pub use core_graphics::{ + base::CGFloat, + color::{CGColor, SysCGColorRef as CGColorRef}, + font::CGGlyph, + geometry::{CGAffineTransform, CGPoint, CGRect, CGSize}, + }; + extern "C" { + #[no_mangle] + pub static CGAffineTransformIdentity: CGAffineTransform; + #[no_mangle] + pub fn CGRectIsNull(rect: CGRect) -> bool; + } + pub use core_text::run::CTRunRef; + extern "C" { + #[no_mangle] + pub fn CTRunGetGlyphCount(run: CTRunRef) -> CFIndex; + #[no_mangle] + pub fn CTRunGetAttributes(run: CTRunRef) -> CFDictionaryRef; + #[no_mangle] + pub fn CTRunGetGlyphs(run: CTRunRef, range: CFRange, buffer: *mut CGGlyph); + #[no_mangle] + pub fn CTRunGetPositions(run: CTRunRef, range: CFRange, buffer: *mut CGPoint); + #[no_mangle] + pub fn CTRunGetAdvances(run: CTRunRef, range: CFRange, buffer: *mut CGSize); + #[no_mangle] + pub fn CTLineGetGlyphCount(line: CTLineRef) -> CFIndex; + #[no_mangle] + pub fn CTLineGetGlyphRuns(line: CTLineRef) -> CFArrayRef; + #[no_mangle] + pub fn CTRunGetTypographicBounds( + run: CTRunRef, + range: CFRange, + ascent: *mut CGFloat, + descent: *mut CGFloat, + leading: *mut CGFloat, + ) -> libc::c_double; + } + + pub use core_text::{ + font::CTFontRef, + font_descriptor::{ + kCTFontCascadeListAttribute, kCTFontFeatureSettingsAttribute, + kCTFontOrientationAttribute, kCTFontURLAttribute, CTFontDescriptor, + CTFontDescriptorCreateWithAttributes, CTFontDescriptorCreateWithNameAndSize, + CTFontDescriptorRef, CTFontOrientation, + }, + line::CTLineRef, + string_attributes::{ + kCTFontAttributeName, kCTForegroundColorAttributeName, kCTKernAttributeName, + kCTVerticalFormsAttributeName, + }, + }; + + extern "C" { + #[no_mangle] + pub static kCTFontFamilyNameKey: CFStringRef; + #[no_mangle] + pub static kCTFontNameAttribute: CFStringRef; + #[no_mangle] + pub static kCTFontStyleNameKey: CFStringRef; + #[no_mangle] + pub static kCTFontDisplayNameAttribute: CFStringRef; + #[no_mangle] + pub static kCTFontFamilyNameAttribute: CFStringRef; + #[no_mangle] + pub static kCTFontFullNameKey: CFStringRef; + } + + pub const kCTFontVerticalOrientation: CTFontOrientation = 2; + pub const kCTFontHorizontalOrientation: CTFontOrientation = 1; + pub const kCTFontDefaultOrientation: CTFontOrientation = 0; + pub const kCTFontOrientationVertical: CTFontOrientation = 2; + pub const kCTFontOrientationHorizontal: CTFontOrientation = 1; + pub const kCTFontOrientationDefault: CTFontOrientation = 0; + + // The CGFont wrapper is not feature complete. + pub type CGFontRef = *const __CGFont; + extern "C" { + pub type __CGFont; + #[no_mangle] + pub fn CGFontGetNumberOfGlyphs(font: CGFontRef) -> usize; + #[no_mangle] + pub fn CGFontRelease(font: CGFontRef); + #[no_mangle] + pub fn CGFontCopyGlyphNameForGlyph(font: CGFontRef, glyph: CGGlyph) -> CFStringRef; + #[no_mangle] + pub fn CTFontCopyGraphicsFont( + font: CTFontRef, + attributes: *mut CTFontDescriptorRef, + ) -> CGFontRef; + #[no_mangle] + pub static kCTFontPostScriptNameKey: CFStringRef; + } + // Typesetters + pub type CTTypesetterRef = *const __CTTypesetter; + extern "C" { + pub type __CTTypesetter; + #[no_mangle] + pub fn CTTypesetterCreateWithAttributedString( + string: CFAttributedStringRef, + ) -> CTTypesetterRef; + #[no_mangle] + pub fn CTTypesetterCreateLine( + typesetter: CTTypesetterRef, + stringRange: CFRange, + ) -> CTLineRef; + } + + // misc + extern "C" { + #[no_mangle] + pub fn CTFontCreateWithFontDescriptor( + descriptor: CTFontDescriptorRef, + size: CGFloat, + matrix: *const CGAffineTransform, + ) -> CTFontRef; + #[no_mangle] + pub fn CTLineCreateJustifiedLine( + line: CTLineRef, + justificationFactor: CGFloat, + justificationWidth: libc::c_double, + ) -> CTLineRef; + #[no_mangle] + pub fn CFStringCreateWithCharactersNoCopy( + alloc: CFAllocatorRef, + chars: *const UniChar, + numChars: CFIndex, + contentsDeallocator: CFAllocatorRef, + ) -> CFStringRef; + #[no_mangle] + pub fn CTFontCreateCopyWithAttributes( + font: CTFontRef, + size: CGFloat, + matrix: *const CGAffineTransform, + attributes: CTFontDescriptorRef, + ) -> CTFontRef; + #[no_mangle] + pub fn CTFontDescriptorCreateCopyWithAttributes( + original: CTFontDescriptorRef, + attributes: CFDictionaryRef, + ) -> CTFontDescriptorRef; + #[no_mangle] + pub fn CTFontDescriptorCopyAttribute( + descriptor: CTFontDescriptorRef, + attribute: CFStringRef, + ) -> CFTypeRef; + #[no_mangle] + pub fn CTFontDescriptorCreateMatchingFontDescriptors( + descriptor: CTFontDescriptorRef, + mandatoryAttributes: CFSetRef, + ) -> CFArrayRef; + #[no_mangle] + pub fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef; + #[no_mangle] + pub fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; + #[no_mangle] + pub fn CTFontCopyLocalizedName( + font: CTFontRef, + nameKey: CFStringRef, + actualLanguage: *mut CFStringRef, + ) -> CFStringRef; + #[no_mangle] + pub fn CTFontGetGlyphsForCharacters( + font: CTFontRef, + characters: *const UniChar, + glyphs: *mut CGGlyph, + count: CFIndex, + ) -> bool; + #[no_mangle] + pub fn CTFontGetGlyphWithName(font: CTFontRef, glyphName: CFStringRef) -> CGGlyph; + #[no_mangle] + pub fn CTFontGetBoundingRectsForGlyphs( + font: CTFontRef, + orientation: CTFontOrientation, + glyphs: *const CGGlyph, + boundingRects: *mut CGRect, + count: CFIndex, + ) -> CGRect; + #[no_mangle] + pub fn CTFontGetAdvancesForGlyphs( + font: CTFontRef, + orientation: CTFontOrientation, + glyphs: *const CGGlyph, + advances: *mut CGSize, + count: CFIndex, + ) -> libc::c_double; + #[no_mangle] + pub static kCTFontFeatureTypeIdentifierKey: CFStringRef; + #[no_mangle] + pub static kCTFontFeatureTypeNameKey: CFStringRef; + #[no_mangle] + pub static kCTFontFeatureTypeSelectorsKey: CFStringRef; + #[no_mangle] + pub static kCTFontFeatureTypeExclusiveKey: CFStringRef; + #[no_mangle] + pub fn CTFontCopyFeatures(font: CTFontRef) -> CFArrayRef; + #[no_mangle] + pub static kCTFontFeatureSelectorNameKey: CFStringRef; + #[no_mangle] + pub static kCTFontFeatureSelectorDefaultKey: CFStringRef; + #[no_mangle] + pub static kCTFontFeatureSelectorIdentifierKey: CFStringRef; + #[no_mangle] + pub fn CTFontGetXHeight(font: CTFontRef) -> CGFloat; + #[no_mangle] + pub fn CTFontGetAscent(font: CTFontRef) -> CGFloat; + #[no_mangle] + pub fn CTFontGetDescent(font: CTFontRef) -> CGFloat; + #[no_mangle] + pub fn CTFontGetGlyphCount(font: CTFontRef) -> CFIndex; + #[no_mangle] + pub fn CTFontGetSlantAngle(font: CTFontRef) -> CGFloat; + #[no_mangle] + pub fn CTFontGetCapHeight(font: CTFontRef) -> CGFloat; + #[no_mangle] + pub fn CFStringGetCharacters(theString: CFStringRef, range: CFRange, buffer: *mut UniChar); + #[no_mangle] + pub fn CFArrayGetValueAtIndex(theArray: CFArrayRef, idx: CFIndex) -> *const libc::c_void; + #[no_mangle] + pub fn CTFontGetSize(font: CTFontRef) -> CGFloat; + #[no_mangle] + pub fn CTFontGetMatrix(font: CTFontRef) -> CGAffineTransform; + #[no_mangle] + pub fn CGColorGetComponents(color: CGColorRef) -> *const CGFloat; + #[no_mangle] + pub fn CFBooleanGetValue(boolean: CFBooleanRef) -> libc::c_uchar; + } + + pub type UniChar = UInt16; + pub type UInt16 = libc::c_ushort; + + #[inline(always)] + pub fn CFRangeMake(mut loc: CFIndex, mut len: CFIndex) -> CFRange { + let mut range: CFRange = CFRange { + location: 0, + length: 0, + }; + range.location = loc; + range.length = len; + range + } + + pub unsafe fn cgColorToRGBA32(mut color: CGColorRef) -> u32 { + let mut components: *const CGFloat = CGColorGetComponents(color); + let mut rval: u32 = (*components.offset(0) * 255.0f64 + 0.5f64) as u8 as u32; + rval <<= 8i32; + rval = (rval as u32).wrapping_add((*components.offset(1) * 255.0f64 + 0.5f64) as u8 as u32); + rval <<= 8i32; + rval = (rval as u32).wrapping_add((*components.offset(2) * 255.0f64 + 0.5f64) as u8 as u32); + rval <<= 8i32; + rval = (rval as u32).wrapping_add((*components.offset(3) * 255.0f64 + 0.5f64) as u8 as u32); + return rval; + } +} diff --git a/engine/src/xetex_ext.rs b/engine/src/xetex_ext.rs index e303a0710..cab911d1a 100644 --- a/engine/src/xetex_ext.rs +++ b/engine/src/xetex_ext.rs @@ -10,28 +10,35 @@ use crate::stub_icu as icu; use crate::stub_teckit as teckit; +use crate::text_layout_engine::{ + scaled_t, Fixed, FixedPoint, GlyphEdge, LayoutRequest, NodeLayout, TextLayout, TextLayoutEngine, +}; +use crate::xetex_font_info::XeTeXFontInst; use crate::xetex_xetexd::print_c_string; use crate::{streq_ptr, strstartswith}; -use crate::{ttstub_input_close, ttstub_input_get_size, ttstub_input_open, ttstub_input_read}; -use libc::free; +use crate::{ + ttstub_input_close, ttstub_input_get_size, ttstub_input_open, ttstub_input_read_exact, +}; +use libc::{free, strncat}; +use std::ffi::{CStr, CString}; +use std::ptr; #[cfg(target_os = "macos")] use super::xetex_aatfont as aat; #[cfg(target_os = "macos")] use super::xetex_aatfont::cf_prelude::{ - kCFNumberFloatType, kCTFontAttributeName, kCTForegroundColorAttributeName, - kCTVerticalFormsAttributeName, CFBooleanRef, CFDictionaryGetValue, CFDictionaryRef, - CFNumberGetValue, CFNumberRef, CFNumberType, CFRelease, CFTypeRef, CGAffineTransform, - CGColorGetComponents, CGColorRef, CGFloat, CTFontDescriptorRef, CTFontGetMatrix, CTFontGetSize, - CTFontRef, + cgColorToRGBA32, kCFNumberFloatType, kCTFontAttributeName, kCTForegroundColorAttributeName, + kCTVerticalFormsAttributeName, CFDictionaryGetValue, CFDictionaryRef, CFNumberGetValue, + CFNumberRef, CFNumberType, CFRelease, CFTypeRef, CGAffineTransform, CGColorGetComponents, + CGColorRef, CGFloat, CTFontGetMatrix, CTFontGetSize, CTFontRef, }; use crate::core_memory::{mfree, xcalloc, xmalloc, xrealloc, xstrdup}; +use crate::xetex_font_info::GlyphBBox; use crate::xetex_ini::memory_word; use crate::xetex_ini::{ - depth_base, font_area, font_flags, font_info, font_layout_engine, font_letter_space, - height_base, loaded_font_design_size, loaded_font_flags, loaded_font_letter_space, - loaded_font_mapping, mapped_text, name_length, name_of_file, native_font_type_flag, param_base, - xdv_buffer, + depth_base, font_flags, font_info, font_letter_space, get_text_layout_engine, get_text_layout_engine_mut, height_base, + loaded_font_design_size, loaded_font_flags, loaded_font_letter_space, loaded_font_mapping, + mapped_text, name_length, name_of_file, native_font_type_flag, param_base, xdv_buffer, }; use crate::xetex_output::{print_char, print_int, print_nl, print_raw_char}; use crate::xetex_scaledmath::xn_over_d; @@ -43,9 +50,11 @@ use crate::xetex_xetex0::{ use bridge::_tt_abort; use crate::stub_stdio::strcasecmp; +use crate::xetex_font_manager::{PlatformFontRef, ShaperRequest}; use crate::xetex_layout_engine::*; +use crate::xetex_texmfmp::maketexstring; +use harfbuzz_sys::{hb_feature_t, hb_tag_from_string, hb_tag_t}; use libc::{memcpy, strcat, strcpy, strdup, strlen, strncpy, strstr}; -use harfbuzz_sys::{hb_tag_t, hb_tag_from_string, hb_feature_t}; pub type __ssize_t = i64; pub type size_t = u64; @@ -174,15 +183,15 @@ pub unsafe extern "C" fn linebreak_start( ) { let mut status: icu::UErrorCode = icu::U_ZERO_ERROR; let mut locale: *mut i8 = gettexstring(localeStrNum); - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && streq_ptr(locale, b"G\x00" as *const u8 as *const i8) as i32 != 0 - { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine; - if initGraphiteBreaking(engine, text, textLength) { - /* user asked for Graphite line breaking and the font supports it */ - return; + let mut engine = get_text_layout_engine_mut(f as usize); + match engine.as_mut().map(|x| &mut **x) { + Some(TextLayoutEngine::XeTeX(eng)) if streq_ptr(locale, b"G\x00" as *const u8 as *const i8) as i32 != 0 => { + if eng.initGraphiteBreaking(text, textLength) { + /* user asked for Graphite line breaking and the font supports it */ + return; + } } + _ => {} } if localeStrNum != brkLocaleStrNum && !brkIter.is_null() { icu::ubrk_close(brkIter); @@ -328,7 +337,8 @@ unsafe extern "C" fn load_mapping_file( if let Some(mut map) = ttstub_input_open(buffer, TTInputFormat::MISCFONTS, 0i32) { let mut mappingSize: size_t = ttstub_input_get_size(&mut map); let mut mapping: *mut u8 = xmalloc(mappingSize) as *mut u8; - let mut r: ssize_t = ttstub_input_read(map.0.as_ptr(), mapping as *mut i8, mappingSize); + let mut r: ssize_t = + ttstub_input_read_exact(map.0.as_ptr(), mapping as *mut i8, mappingSize); if r < 0i32 as i64 || r as size_t != mappingSize { _tt_abort( b"could not read mapping file \"%s\"\x00" as *const u8 as *const i8, @@ -667,23 +677,22 @@ unsafe extern "C" fn readFeatureNumber( } unsafe extern "C" fn loadOTfont( mut fontRef: PlatformFontRef, - mut font: XeTeXFont, + mut font: *mut XeTeXFontInst, mut scaled_size: Fixed, - mut cp1: *mut i8, -) -> *mut libc::c_void { + mut cp1: Option<&CStr>, + mut shaperRequest: Option, +) -> Option { let mut current_block: u64; - let mut engine: XeTeXLayoutEngine = 0 as XeTeXLayoutEngine; - let mut script: hb_tag_t = (0_u32 & 0xff_u32) << 24i32 - | (0_u32 & 0xff_u32) << 16i32 - | (0_u32 & 0xff_u32) << 8i32 - | 0_u32 & 0xff_u32; + let mut rval = None; + // ft_make_tag also works for harfbuzz tags. + let mut script: hb_tag_t = ft_make_tag(&[0, 0, 0, 0]); let mut language: *mut i8 = 0 as *mut i8; let mut features: *mut hb_feature_t = 0 as *mut hb_feature_t; - let mut shapers: *mut *mut i8 = 0 as *mut *mut i8; + let mut shaper_list = CStringListBuilder::new(); let mut nFeatures: i32 = 0i32; let mut nShapers: i32 = 0i32; - let mut cp2: *mut i8 = 0 as *mut i8; - let mut cp3: *const i8 = 0 as *const i8; + let mut cp2: *const i8 = ptr::null(); + let mut cp3: *const i8 = ptr::null(); let mut tag: hb_tag_t = 0; let mut rgbValue: u32 = 0xff_u32; let mut extend: f32 = 1.0f64 as f32; @@ -691,46 +700,42 @@ unsafe extern "C" fn loadOTfont( let mut embolden: f32 = 0.0f64 as f32; let mut letterspace: f32 = 0.0f64 as f32; let mut i: i32 = 0; - let mut reqEngine: i8 = getReqEngine(); - if reqEngine as i32 == 'O' as i32 || reqEngine as i32 == 'G' as i32 { - shapers = xrealloc( - shapers as *mut libc::c_void, - ((nShapers + 1i32) as u64).wrapping_mul(::std::mem::size_of::<*mut i8>() as u64), - ) as *mut *mut i8; - if reqEngine as i32 == 'O' as i32 { - static mut ot_const: [i8; 3] = [111, 116, 0]; - let ref mut fresh8 = *shapers.offset(nShapers as isize); - *fresh8 = ot_const.as_mut_ptr() - } else if reqEngine as i32 == 'G' as i32 { - static mut graphite2_const: [i8; 10] = [103, 114, 97, 112, 104, 105, 116, 101, 50, 0]; - let ref mut fresh9 = *shapers.offset(nShapers as isize); - *fresh9 = graphite2_const.as_mut_ptr() + + if shaperRequest == Some(ShaperRequest::OpenType) + || shaperRequest == Some(ShaperRequest::Graphite) + { + match shaperRequest.expect("already know shaperRequest is Some") { + ShaperRequest::OpenType => { + shaper_list.push_non_null_terminated(&b"ot"[..]); + } + ShaperRequest::Graphite => { + shaper_list.push_non_null_terminated(&b"graphite2"[..]); + } + _ => unreachable!(), } nShapers += 1 } - if reqEngine as i32 == 'G' as i32 { - let mut tmpShapers: [*mut i8; 1] = [*shapers.offset(0)]; + if shaperRequest == Some(ShaperRequest::Graphite) { + let tmp_shapers = shaper_list.clone(); /* create a default engine so we can query the font for Graphite features; * because of font caching, it's cheap to discard this and create the real one later */ - engine = createLayoutEngine( + rval = Some(createLayoutEngine( fontRef, font, script, language, features, nFeatures, - tmpShapers.as_mut_ptr(), + tmp_shapers.none_if_empty(), rgbValue, extend, slant, embolden, - ); - if engine.is_null() { - return 0 as *mut libc::c_void; - } + shaperRequest, + )); } /* scan the feature string (if any) */ - if !cp1.is_null() { + if let Some(mut cp1) = cp1.map(|x| x.as_ptr()) { while *cp1 != 0 { if *cp1 as i32 == ':' as i32 || *cp1 as i32 == ';' as i32 || *cp1 as i32 == ',' as i32 { cp1 = cp1.offset(1) @@ -785,18 +790,7 @@ unsafe extern "C" fn loadOTfont( current_block = 10622493848381539643; } else { cp3 = cp3.offset(1); - shapers = xrealloc( - shapers as *mut libc::c_void, - ((nShapers + 1i32) as u64) - .wrapping_mul(::std::mem::size_of::<*mut i8>() as u64), - ) as *mut *mut i8; - /* some dumb systems have no strndup() */ - let ref mut fresh10 = *shapers.offset(nShapers as isize); - *fresh10 = strdup(cp3); - *(*shapers.offset(nShapers as isize)) - .offset(cp2.wrapping_offset_from(cp3) as i64 as isize) = - '\u{0}' as i32 as i8; - nShapers += 1; + shaper_list.push_cstr(CStr::from_ptr(cp3)); current_block = 13857423536159756434; } } else { @@ -814,12 +808,16 @@ unsafe extern "C" fn loadOTfont( } else if i == -1i32 { current_block = 10622493848381539643; } else { - if reqEngine as i32 == 'G' as i32 { + if shaperRequest == Some(ShaperRequest::Graphite) { let mut value: i32 = 0i32; if readFeatureNumber(cp1, cp2, &mut tag, &mut value) as i32 != 0 - || findGraphiteFeature(engine, cp1, cp2, &mut tag, &mut value) - as i32 - != 0 + || rval.as_mut().map(|engine| findGraphiteFeature( + engine, + cp1, + cp2, + &mut tag, + &mut value, + )).unwrap_or(false) { features = xrealloc( features as *mut libc::c_void, @@ -935,15 +933,6 @@ unsafe extern "C" fn loadOTfont( cp1 = cp2 } } - /* break if end of string */ - if !shapers.is_null() { - shapers = xrealloc( - shapers as *mut libc::c_void, - ((nShapers + 1i32) as u64).wrapping_mul(::std::mem::size_of::<*mut i8>() as u64), - ) as *mut *mut i8; - let ref mut fresh11 = *shapers.offset(nShapers as isize); - *fresh11 = 0 as *mut i8 - } if embolden as f64 != 0.0f64 { embolden = (embolden as f64 * Fix2D(scaled_size) / 100.0f64) as f32 } @@ -956,18 +945,22 @@ unsafe extern "C" fn loadOTfont( if loaded_font_flags as i32 & 0x2i32 != 0i32 { setFontLayoutDir(font, 1i32); } - engine = createLayoutEngine( - fontRef, font, script, language, features, nFeatures, shapers, rgbValue, extend, slant, + rval = Some(createLayoutEngine( + fontRef, + font, + script, + language, + features, + nFeatures, + shaper_list.none_if_empty(), + rgbValue, + extend, + slant, embolden, - ); - if engine.is_null() { - // only free these if creation failed, otherwise the engine now owns them - free(features as *mut libc::c_void); - free(shapers as *mut libc::c_void); - } else { - native_font_type_flag = 0xfffeu32 as i32 - } - engine as *mut libc::c_void + shaperRequest, + )); + native_font_type_flag = 0xfffeu32 as i32; + rval.map(TextLayoutEngine::XeTeX) } unsafe extern "C" fn splitFontName( @@ -1024,53 +1017,89 @@ unsafe extern "C" fn splitFontName( *var = *feat }; } + +struct SplitName { + tex_internal: bool, + name: CString, + /// Easier: you get starts_with(). + var: Option, + feat: Option, + index: i32, +} + +impl SplitName { + unsafe fn from_packed_name(name: *mut i8) -> Self { + let mut var: *mut i8 = ptr::null_mut(); + let mut feat: *mut i8 = ptr::null_mut(); + let mut end: *mut i8 = ptr::null_mut(); + let mut index = 0i32; + + splitFontName(name, &mut var, &mut feat, &mut end, &mut index); + + let full_str = CStr::from_ptr(name); + let full_bytes = full_str.to_bytes(); + let start_index = if full_bytes[0] == b'[' { 1 } else { 0 }; + let name_string = + CString::new(&full_bytes[start_index..var.wrapping_offset_from(name) as usize]) + .unwrap(); + + let mut var_out = None; + let mut feat_out = None; + + if feat > var { + let from = var.wrapping_offset_from(name) as usize + 1; + let to = from + feat.wrapping_offset_from(var) as usize - 1; + var_out = Some(CString::new(&full_bytes[from..to]).unwrap()); + } + if end > feat { + let from = feat.wrapping_offset_from(name) as usize + 1; + let to = from + end.wrapping_offset_from(feat) as usize - 1; + feat_out = Some(CString::new(&full_bytes[from..to]).unwrap()); + } + + SplitName { + tex_internal: start_index == 1, + name: name_string, + // XXX: could fail + var: var_out.map(|v| v.into_string().unwrap()), + feat: feat_out, + index, + } + } +} + +/// scaled_size here is in TeX points, or is a negative integer for 'scaled_t' #[no_mangle] pub unsafe extern "C" fn find_native_font( mut uname: *mut i8, mut scaled_size: i32, -) -> *mut libc::c_void -/* scaled_size here is in TeX points, or is a negative integer for 'scaled_t' */ { - let mut rval: *mut libc::c_void = 0 as *mut libc::c_void; - let mut nameString: *mut i8 = 0 as *mut i8; - let mut var: *mut i8 = 0 as *mut i8; - let mut feat: *mut i8 = 0 as *mut i8; - let mut end: *mut i8 = 0 as *mut i8; - let mut name: *mut i8 = uname; - let mut varString: *mut i8 = 0 as *mut i8; - let mut featString: *mut i8 = 0 as *mut i8; +) -> Option { + let mut rval = None; let mut fontRef: PlatformFontRef = 0 as PlatformFontRef; - let mut font: XeTeXFont = 0 as XeTeXFont; - let mut index: i32 = 0i32; + let mut font: *mut XeTeXFontInst = ptr::null_mut(); + + let mut name: *mut i8 = uname; + let SplitName { + tex_internal, + name, + mut var, + feat, + index, + } = SplitName::from_packed_name(name); + let feat_cstr: Option<&CStr> = feat.as_ref().map(|x| x.as_ref()); + loaded_font_mapping = 0 as *mut libc::c_void; loaded_font_flags = 0_i8; loaded_font_letter_space = 0i32; - splitFontName(name, &mut var, &mut feat, &mut end, &mut index); - nameString = - xmalloc((var.wrapping_offset_from(name) as i64 + 1i32 as i64) as size_t) as *mut i8; - strncpy(nameString, name, var.wrapping_offset_from(name) as usize); - *nameString.offset(var.wrapping_offset_from(name) as i64 as isize) = 0_i8; - if feat > var { - varString = xmalloc(feat.wrapping_offset_from(var) as i64 as size_t) as *mut i8; - strncpy( - varString, - var.offset(1), - (feat.wrapping_offset_from(var) as i64 - 1i32 as i64) as usize, - ); - *varString.offset((feat.wrapping_offset_from(var) as i64 - 1i32 as i64) as isize) = 0_i8 - } - if end > feat { - featString = xmalloc(end.wrapping_offset_from(feat) as i64 as size_t) as *mut i8; - strncpy( - featString, - feat.offset(1), - (end.wrapping_offset_from(feat) as i64 - 1i32 as i64) as usize, - ); - *featString.offset((end.wrapping_offset_from(feat) as i64 - 1i32 as i64) as isize) = 0_i8 - } + + // the requested rendering technology for the most recent findFont + // or 0 if no specific technology was requested + let mut shaperRequest = None; + // check for "[filename]" form, don't search maps in this case - if *nameString.offset(0) as i32 == '[' as i32 { + if tex_internal { if scaled_size < 0i32 { - font = createFontFromFile(nameString.offset(1), index, 655360i64 as Fixed); + font = createFontFromFile(&name, index, 655360i64 as Fixed); if !font.is_null() { let mut dsize: Fixed = D2Fix(getDesignSize(font)); if scaled_size == -1000i32 { @@ -1081,48 +1110,48 @@ pub unsafe extern "C" fn find_native_font( deleteFont(font); } } - font = createFontFromFile(nameString.offset(1), index, scaled_size); + font = createFontFromFile(&name, index, scaled_size); if !font.is_null() { loaded_font_design_size = D2Fix(getDesignSize(font)); /* This is duplicated in XeTeXFontMgr::findFont! */ - setReqEngine(0_i8); - if !varString.is_null() { - if !strstartswith(varString, b"/AAT\x00" as *const u8 as *const i8).is_null() { - setReqEngine('A' as i32 as i8); - } else if !strstartswith(varString, b"/OT\x00" as *const u8 as *const i8).is_null() - || !strstartswith(varString, b"/ICU\x00" as *const u8 as *const i8).is_null() - { - setReqEngine('O' as i32 as i8); - } else if !strstartswith(varString, b"/GR\x00" as *const u8 as *const i8).is_null() - { - setReqEngine('G' as i32 as i8); + if let Some(var) = var { + if var.starts_with("/AAT") { + shaperRequest = Some(ShaperRequest::AAT); + } else if var.starts_with("/OT") || var.starts_with("/ICU") { + shaperRequest = Some(ShaperRequest::OpenType); + } else if var.starts_with("/GR") { + shaperRequest = Some(ShaperRequest::Graphite); } } - rval = loadOTfont(0 as PlatformFontRef, font, scaled_size, featString); - if rval.is_null() { + rval = loadOTfont( + 0 as PlatformFontRef, + font, + scaled_size, + feat_cstr, + shaperRequest, + ); + if rval.is_none() { deleteFont(font); } - if !rval.is_null() && get_tracing_fonts_state() > 0i32 { + if rval.is_some() && get_tracing_fonts_state() > 0i32 { begin_diagnostic(); print_nl(' ' as i32); print_c_string(b"-> \x00" as *const u8 as *const i8); - print_c_string(nameString.offset(1)); + print_c_string(name.as_ptr()); end_diagnostic(0i32 != 0); } } } else { - fontRef = findFontByName(nameString, varString, Fix2D(scaled_size)); + fontRef = findFontByName(&name, var.as_mut(), Fix2D(scaled_size), &mut shaperRequest); if !fontRef.is_null() { /* update name_of_file to the full name of the font, for error messages during font loading */ let mut fullName: *const i8 = getFullName(fontRef); name_length = strlen(fullName) as i32; - if !featString.is_null() { - name_length = - (name_length as usize).wrapping_add(strlen(featString).wrapping_add(1)) as _ + if let Some(feat) = &feat { + name_length = ((name_length as usize) + feat.as_bytes().len() + 1) as _; } - if !varString.is_null() { - name_length = - (name_length as usize).wrapping_add(strlen(varString).wrapping_add(1)) as _ + if let Some(var) = &var { + name_length = ((name_length as usize) + var.as_bytes().len() + 1) as _; } free(name_of_file as *mut libc::c_void); name_of_file = xmalloc((name_length + 1i32) as size_t) as *mut i8; @@ -1143,272 +1172,53 @@ pub unsafe extern "C" fn find_native_font( if !font.is_null() { #[cfg(not(target_os = "macos"))] { - rval = loadOTfont(fontRef, font, scaled_size, featString); - if rval.is_null() { - deleteFont(font); - } + rval = loadOTfont(fontRef, font, scaled_size, feat_cstr, shaperRequest); } #[cfg(target_os = "macos")] { /* decide whether to use AAT or OpenType rendering with this font */ - if getReqEngine() as libc::c_int == 'A' as i32 { - rval = aat::loadAATfont(fontRef, scaled_size, featString); - if rval.is_null() { + if shaperRequest == Some(ShaperRequest::AAT) { + rval = aat::loadAATfont(fontRef, scaled_size, feat_cstr); + if rval.is_none() { deleteFont(font); } } else { - if getReqEngine() as libc::c_int == 'O' as i32 - || getReqEngine() as libc::c_int == 'G' as i32 - || !getFontTablePtr( - font, - ('G' as i32 as u32 & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as u32 & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as u32 & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as u32 & 0xffi32 as libc::c_uint, - ) - .is_null() - || !getFontTablePtr( - font, - ('G' as i32 as u32 & 0xffi32 as libc::c_uint) << 24i32 - | ('P' as i32 as u32 & 0xffi32 as libc::c_uint) << 16i32 - | ('O' as i32 as u32 & 0xffi32 as libc::c_uint) << 8i32 - | 'S' as i32 as u32 & 0xffi32 as libc::c_uint, - ) - .is_null() + if shaperRequest == Some(ShaperRequest::OpenType) + || shaperRequest == Some(ShaperRequest::Graphite) + || !getFontTablePtr(font, ft_make_tag(b"GSUB")).is_null() + || !getFontTablePtr(font, ft_make_tag(b"GPOS")).is_null() { - rval = loadOTfont(fontRef, font, scaled_size, featString) + rval = loadOTfont(fontRef, font, scaled_size, feat_cstr, shaperRequest) } /* loadOTfont failed or the above check was false */ - if rval.is_null() { - rval = aat::loadAATfont(fontRef, scaled_size, featString) + if rval.is_none() { + rval = aat::loadAATfont(fontRef, scaled_size, feat_cstr) } - if rval.is_null() { + if rval.is_none() { deleteFont(font); } } } } /* append the style and feature strings, so that \show\fontID will give a full result */ - if !varString.is_null() && *varString as i32 != 0i32 { - strcat(name_of_file, b"/\x00" as *const u8 as *const i8); - strcat(name_of_file, varString); + if let Some(var) = var { + if !var.as_bytes().is_empty() { + strcat(name_of_file, b"/\x00" as *const u8 as *const i8); + strncat(name_of_file, var.as_ptr() as *const i8, var.len()); + } } - if !featString.is_null() && *featString as i32 != 0i32 { - strcat(name_of_file, b":\x00" as *const u8 as *const i8); - strcat(name_of_file, featString); + if let Some(feat) = feat { + if !feat.as_bytes().is_empty() { + strcat(name_of_file, b":\x00" as *const u8 as *const i8); + strcat(name_of_file, feat.as_ptr()); + } } name_length = strlen(name_of_file) as i32 } } - free(varString as *mut libc::c_void); - free(featString as *mut libc::c_void); - free(nameString as *mut libc::c_void); rval } -#[no_mangle] -pub unsafe extern "C" fn release_font_engine(mut engine: *mut libc::c_void, mut type_flag: i32) { - match type_flag as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - CFRelease(engine as CFDictionaryRef as CFTypeRef); - } - 0xfffeu32 => { - deleteLayoutEngine(engine as XeTeXLayoutEngine); - } - _ => {} - } -} -#[no_mangle] -pub unsafe extern "C" fn ot_get_font_metrics( - mut pEngine: *mut libc::c_void, - mut ascent: *mut scaled_t, - mut descent: *mut scaled_t, - mut xheight: *mut scaled_t, - mut capheight: *mut scaled_t, - mut slant: *mut scaled_t, -) { - let mut engine: XeTeXLayoutEngine = pEngine as XeTeXLayoutEngine; - let mut a: f32 = 0.; - let mut d: f32 = 0.; - getAscentAndDescent(engine, &mut a, &mut d); - *ascent = D2Fix(a as f64); - *descent = D2Fix(d as f64); - *slant = D2Fix( - Fix2D(getSlant(getFont(engine))) * getExtendFactor(engine) as f64 - + getSlantFactor(engine) as f64, - ); - /* get cap and x height from OS/2 table */ - getCapAndXHeight(engine, &mut a, &mut d); - *capheight = D2Fix(a as f64); - *xheight = D2Fix(d as f64); - /* fallback in case the font does not have OS/2 table */ - if *xheight == 0i32 { - let mut glyphID: i32 = mapCharToGlyph(engine, 'x' as i32 as u32) as i32; - if glyphID != 0i32 { - getGlyphHeightDepth(engine, glyphID as u32, &mut a, &mut d); - *xheight = D2Fix(a as f64) - } else { - *xheight = *ascent / 2i32 - /* arbitrary figure if there's no 'x' in the font */ - } - } - if *capheight == 0i32 { - let mut glyphID_0: i32 = mapCharToGlyph(engine, 'X' as i32 as u32) as i32; - if glyphID_0 != 0i32 { - getGlyphHeightDepth(engine, glyphID_0 as u32, &mut a, &mut d); - *capheight = D2Fix(a as f64) - } else { - *capheight = *ascent - /* arbitrary figure if there's no 'X' in the font */ - } - }; -} -#[no_mangle] -pub unsafe extern "C" fn ot_font_get(mut what: i32, mut pEngine: *mut libc::c_void) -> i32 { - let mut engine: XeTeXLayoutEngine = pEngine as XeTeXLayoutEngine; - let mut fontInst: XeTeXFont = getFont(engine); - match what { - 1 => return countGlyphs(fontInst) as i32, - 8 => { - /* ie Graphite features */ - return countGraphiteFeatures(engine) as i32; - } - 16 => return countScripts(fontInst) as i32, - _ => {} - } - 0i32 -} -#[no_mangle] -pub unsafe extern "C" fn ot_font_get_1( - mut what: i32, - mut pEngine: *mut libc::c_void, - mut param: i32, -) -> i32 { - let mut engine: XeTeXLayoutEngine = pEngine as XeTeXLayoutEngine; - let mut fontInst: XeTeXFont = getFont(engine); - match what { - 17 => return countLanguages(fontInst, param as hb_tag_t) as i32, - 19 => return getIndScript(fontInst, param as u32) as i32, - 9 => { - /* for graphite fonts...*/ - return getGraphiteFeatureCode(engine, param as u32) as i32; - } - 11 => return 1i32, - 12 => return countGraphiteFeatureSettings(engine, param as u32) as i32, - _ => {} - } - 0i32 -} -#[no_mangle] -pub unsafe extern "C" fn ot_font_get_2( - mut what: i32, - mut pEngine: *mut libc::c_void, - mut param1: i32, - mut param2: i32, -) -> i32 { - let mut engine: XeTeXLayoutEngine = pEngine as XeTeXLayoutEngine; - let mut fontInst: XeTeXFont = getFont(engine); - match what { - 20 => return getIndLanguage(fontInst, param1 as hb_tag_t, param2 as u32) as i32, - 18 => return countFeatures(fontInst, param1 as hb_tag_t, param2 as hb_tag_t) as i32, - 13 => { - /* for graphite fonts */ - return getGraphiteFeatureSettingCode(engine, param1 as u32, param2 as u32) as i32; - } - 15 => { - return (getGraphiteFeatureDefaultSetting(engine, param1 as u32) == param2 as u32) - as i32 - } - _ => {} - } /* to guarantee enough space in the buffer */ - 0i32 -} -#[no_mangle] -pub unsafe extern "C" fn ot_font_get_3( - mut what: i32, - mut pEngine: *mut libc::c_void, - mut param1: i32, - mut param2: i32, - mut param3: i32, -) -> i32 { - let mut engine: XeTeXLayoutEngine = pEngine as XeTeXLayoutEngine; - let mut fontInst: XeTeXFont = getFont(engine); - match what { - 21 => { - return getIndFeature( - fontInst, - param1 as hb_tag_t, - param2 as hb_tag_t, - param3 as u32, - ) as i32 - } - _ => {} - } - 0i32 -} -#[no_mangle] -pub unsafe extern "C" fn gr_print_font_name( - mut what: i32, - mut pEngine: *mut libc::c_void, - mut param1: i32, - mut param2: i32, -) { - let mut name: *mut i8 = 0 as *mut i8; - let mut engine: XeTeXLayoutEngine = pEngine as XeTeXLayoutEngine; - match what { - 8 => name = getGraphiteFeatureLabel(engine, param1 as u32), - 9 => name = getGraphiteFeatureSettingLabel(engine, param1 as u32, param2 as u32), - _ => {} - } - if !name.is_null() { - print_c_string(name); - gr_label_destroy(name as *mut libc::c_void); - }; -} -#[no_mangle] -pub unsafe extern "C" fn gr_font_get_named(mut what: i32, mut pEngine: *mut libc::c_void) -> i32 { - let mut rval: i64 = -1i32 as i64; - let mut engine: XeTeXLayoutEngine = pEngine as XeTeXLayoutEngine; - match what { - 10 => rval = findGraphiteFeatureNamed(engine, name_of_file, name_length), - _ => {} - } - rval as i32 -} -#[no_mangle] -pub unsafe extern "C" fn gr_font_get_named_1( - mut what: i32, - mut pEngine: *mut libc::c_void, - mut param: i32, -) -> i32 { - let mut rval: i64 = -1i32 as i64; - let mut engine: XeTeXLayoutEngine = pEngine as XeTeXLayoutEngine; - match what { - 14 => { - rval = findGraphiteFeatureSettingNamed(engine, param as u32, name_of_file, name_length) - } - _ => {} - } - rval as i32 -} -#[cfg(target_os = "macos")] -unsafe extern "C" fn cgColorToRGBA32(mut color: CGColorRef) -> u32 { - let mut components: *const CGFloat = CGColorGetComponents(color); - let mut rval: u32 = (*components.offset(0) * 255.0f64 + 0.5f64) as u8 as u32; - rval <<= 8i32; - rval = (rval as libc::c_uint) - .wrapping_add((*components.offset(1) * 255.0f64 + 0.5f64) as u8 as libc::c_uint) - as u32 as u32; - rval <<= 8i32; - rval = (rval as libc::c_uint) - .wrapping_add((*components.offset(2) * 255.0f64 + 0.5f64) as u8 as libc::c_uint) - as u32 as u32; - rval <<= 8i32; - rval = (rval as libc::c_uint) - .wrapping_add((*components.offset(3) * 255.0f64 + 0.5f64) as u8 as libc::c_uint) - as u32 as u32; - return rval; -} + static mut xdvBufSize: i32 = 0i32; #[no_mangle] pub unsafe extern "C" fn makeXDVGlyphArrayData(mut pNode: *mut libc::c_void) -> i32 { @@ -1503,83 +1313,21 @@ pub unsafe extern "C" fn make_font_def(mut f: i32) -> i32 { let mut fontDefLength: i32 = 0; let mut cp: *mut i8 = 0 as *mut i8; /* PlatformFontRef fontRef = 0; */ - let mut extend: f32 = 1.0f64 as f32; - let mut slant: f32 = 0.0f64 as f32; - let mut embolden: f32 = 0.0f64 as f32; - match *font_area.offset(f as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - let mut attributes: CFDictionaryRef = 0 as CFDictionaryRef; - let mut font: CTFontRef = 0 as CTFontRef; - let mut color: CGColorRef = 0 as CGColorRef; - let mut t: CGAffineTransform = CGAffineTransform { - a: 0., - b: 0., - c: 0., - d: 0., - tx: 0., - ty: 0., - }; - let mut emboldenNumber: CFNumberRef = 0 as CFNumberRef; - let mut fSize: CGFloat = 0.; - attributes = *font_layout_engine.offset(f as isize) as CFDictionaryRef; - font = CFDictionaryGetValue(attributes, kCTFontAttributeName as *const libc::c_void) - as CTFontRef; - filename = aat::getFileNameFromCTFont(font, &mut index); - assert!(!filename.is_null()); - if !CFDictionaryGetValue( - attributes, - kCTVerticalFormsAttributeName as *const libc::c_void, - ) - .is_null() - { - flags = (flags as libc::c_int | 0x100i32) as u16 - } - color = CFDictionaryGetValue( - attributes, - kCTForegroundColorAttributeName as *const libc::c_void, - ) as CGColorRef; - if !color.is_null() { - rgba = cgColorToRGBA32(color) - } - t = CTFontGetMatrix(font); - extend = t.a as libc::c_float; - slant = t.c as libc::c_float; - emboldenNumber = CFDictionaryGetValue( - attributes, - aat::getkXeTeXEmboldenAttributeName() as *const libc::c_void, - ) as CFNumberRef; - if !emboldenNumber.is_null() { - CFNumberGetValue( - emboldenNumber, - kCFNumberFloatType as libc::c_int as CFNumberType, - &mut embolden as *mut libc::c_float as *mut libc::c_void, - ); - } - fSize = CTFontGetSize(font); - size = D2Fix(fSize); - } - 0xfffeu32 => { - let mut engine: XeTeXLayoutEngine = 0 as *mut XeTeXLayoutEngine_rec; - engine = *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine; - /* fontRef = */ - getFontRef(engine); - filename = getFontFilename(engine, &mut index); - assert!(!filename.is_null()); - rgba = getRgbValue(engine); - if *font_flags.offset(f as isize) as i32 & 0x2i32 != 0i32 { - flags = (flags as i32 | 0x100i32) as u16 - } - extend = getExtendFactor(engine); - slant = getSlantFactor(engine); - embolden = getEmboldenFactor(engine); - size = D2Fix(getPointSize(engine) as f64) - } - _ => { - panic!("bad native font flag in `make_font_def`"); - } - } + let mut extend = 1.0f64; + let mut slant = 0.0f64; + let mut embolden = 0.0f64; + + let eng = get_text_layout_engine(f as usize).expect("bad native font flag in `make_font_def`"); + filename = eng.font_filename(&mut index); + assert!(!filename.is_null()); filenameLen = strlen(filename) as u8; + rgba = eng.rgb_value(); + extend = eng.extend_factor(); + slant = eng.slant_factor(); + embolden = eng.embolden_factor() as f64; + size = D2Fix(eng.point_size()); + flags = (flags as i32 | eng.get_flags(f as u32)) as u16; + /* parameters after internal font ID: // size[4] // flags[2] @@ -1718,29 +1466,16 @@ pub unsafe extern "C" fn get_native_char_height_depth( mut height: *mut scaled_t, mut depth: *mut scaled_t, ) { - let mut ht: f32 = 0.0f64 as f32; - let mut dp: f32 = 0.0f64 as f32; let mut fuzz: Fixed = 0; - match *font_area.offset(font as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - let mut attributes: CFDictionaryRef = - *font_layout_engine.offset(font as isize) as CFDictionaryRef; - let mut gid: libc::c_int = aat::MapCharToGlyph_AAT(attributes, ch as u32); - aat::GetGlyphHeightDepth_AAT(attributes, gid as u16, &mut ht, &mut dp); - } - 0xfffeu32 => { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(font as isize) as XeTeXLayoutEngine; - let mut gid: i32 = mapCharToGlyph(engine, ch as u32) as i32; - getGlyphHeightDepth(engine, gid as u32, &mut ht, &mut dp); - } - _ => { - panic!("bad native font flag in `get_native_char_height_depth`"); - } - } - *height = D2Fix(ht as f64); - *depth = D2Fix(dp as f64); + + let engine = get_text_layout_engine(font as usize).expect("no font found with that id"); + let gid = engine.map_char_to_glyph(ch as u32); + let (h, d) = engine.glyph_height_depth(gid) + .map(|(h, d)| (D2Fix(h as f64), D2Fix(d as f64))) + .unwrap_or((0, 0)); + *height = h; + *depth = d; + /* snap to "known" zones for baseline, x-height, cap-height if within 4% of em-size */ fuzz = (*font_info.offset((6i32 + *param_base.offset(font as isize)) as isize)) .b32 @@ -1784,60 +1519,35 @@ pub unsafe extern "C" fn get_native_char_sidebearings( mut lsb: *mut scaled_t, mut rsb: *mut scaled_t, ) { - let mut l: f32 = 0.; - let mut r: f32 = 0.; - match *font_area.offset(font as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - let mut attributes: CFDictionaryRef = - *font_layout_engine.offset(font as isize) as CFDictionaryRef; - let mut gid: libc::c_int = aat::MapCharToGlyph_AAT(attributes, ch as u32); - aat::GetGlyphSidebearings_AAT(attributes, gid as u16, &mut l, &mut r); - } - 0xfffeu32 => { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(font as isize) as XeTeXLayoutEngine; - let mut gid: i32 = mapCharToGlyph(engine, ch as u32) as i32; - getGlyphSidebearings(engine, gid as u32, &mut l, &mut r); - } - _ => { - panic!("bad native font flag in `get_native_char_side_bearings`"); - } - } + let eng = get_text_layout_engine(font as usize) + .expect("bad native font flag in `get_native_char_side_bearings`"); + let gid = eng.map_char_to_glyph(ch as u32); + let (l, r) = eng.glyph_sidebearings(gid).unwrap_or((0., 0.)); *lsb = D2Fix(l as f64); *rsb = D2Fix(r as f64); } + #[no_mangle] pub unsafe extern "C" fn get_glyph_bounds(mut font: i32, mut edge: i32, mut gid: i32) -> scaled_t { - /* edge codes 1,2,3,4 => L T R B */ - let mut a: f32 = 0.; - let mut b: f32 = 0.; - match *font_area.offset(font as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - let mut attributes: CFDictionaryRef = - *font_layout_engine.offset(font as isize) as CFDictionaryRef; - if edge & 1i32 != 0 { - aat::GetGlyphSidebearings_AAT(attributes, gid as u16, &mut a, &mut b); - } else { - aat::GetGlyphHeightDepth_AAT(attributes, gid as u16, &mut a, &mut b); - } - } - 0xfffeu32 => { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(font as isize) as XeTeXLayoutEngine; - if edge & 1i32 != 0 { - getGlyphSidebearings(engine, gid as u32, &mut a, &mut b); + GlyphEdge::from_int(edge) + .and_then(|edge| { + /* edge codes 1,2,3,4 => L T R B */ + let mut a: f32 = 0.; + let mut b: f32 = 0.; + let eng = get_text_layout_engine(font as usize) + .expect("bad native font flag in `get_glyph_bounds`"); + if edge.is_side() { + eng.glyph_sidebearings(gid as u32) } else { - getGlyphHeightDepth(engine, gid as u32, &mut a, &mut b); + eng.glyph_height_depth(gid as u32) } - } - _ => { - _tt_abort(b"bad native font flag in `get_glyph_bounds`\x00" as *const u8 as *const i8); - } - } - D2Fix((if edge <= 2i32 { a } else { b }) as f64) + .map(|pair| edge.pick_from(&pair)) + }) + .map(|d| D2Fix(d as f64)) + // This means 'None' to xetex + .unwrap_or(D2Fix(0.0)) } + #[no_mangle] pub unsafe extern "C" fn getnativecharic(mut f: i32, mut c: i32) -> scaled_t { let mut lsb: scaled_t = 0; @@ -1849,30 +1559,16 @@ pub unsafe extern "C" fn getnativecharic(mut f: i32, mut c: i32) -> scaled_t { *font_letter_space.offset(f as isize) } } + /* single-purpose metrics accessors */ #[no_mangle] pub unsafe extern "C" fn getnativecharwd(mut f: i32, mut c: i32) -> scaled_t { let mut wd: scaled_t = 0i32; - match *font_area.offset(f as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - let mut attributes: CFDictionaryRef = - *font_layout_engine.offset(f as isize) as CFDictionaryRef; - let mut gid: libc::c_int = aat::MapCharToGlyph_AAT(attributes, c as u32); - wd = D2Fix(aat::GetGlyphWidth_AAT(attributes, gid as u16)) - } - 0xfffeu32 => { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine; - let mut gid: i32 = mapCharToGlyph(engine, c as u32) as i32; - wd = D2Fix(getGlyphWidthFromEngine(engine, gid as u32) as f64) - } - _ => { - panic!("bad native font flag in `get_native_char_wd`"); - } - } - wd + let eng = get_text_layout_engine(f as usize).expect("bad native font flag"); + let gid = eng.map_char_to_glyph(c as u32); + D2Fix(eng.getGlyphWidthFromEngine(gid as u32)) } + #[no_mangle] pub unsafe extern "C" fn real_get_native_glyph( mut pNode: *mut libc::c_void, @@ -1888,22 +1584,24 @@ pub unsafe extern "C" fn real_get_native_glyph( *glyphIDs.offset(index as isize) } } -#[no_mangle] -pub unsafe extern "C" fn store_justified_native_glyphs(mut pNode: *mut libc::c_void) { + +pub unsafe fn store_justified_native_glyphs(mut pNode: *mut libc::c_void) { let mut node: *mut memory_word = pNode as *mut memory_word; let mut f: u32 = (*node.offset(4)).b16.s2 as u32; - match *font_area.offset(f as isize) as u32 { + let mut eng = get_text_layout_engine_mut(f as usize).expect("bad native font flag"); + match &mut *eng { #[cfg(target_os = "macos")] - 0xffffu32 => { - /* separate Mac-only codepath for AAT fonts */ - aat::do_aat_layout(node as *mut libc::c_void, 1i32); + TextLayoutEngine::AAT(eng) => { + /* separate Mac-only codepath for AAT fonts, activated with LayoutRequest.justify */ + let request = LayoutRequest::from_node(node, true); + let layout = eng.layout_text(request); + layout.write_node(node); return; } - _ => { - /* FIXME: 0xfffeu32 case, but the original code wrote it this way */ + TextLayoutEngine::XeTeX(eng) => { /* save desired width */ let mut savedWidth: i32 = (*node.offset(1)).b32.s1; - measure_native_node(node as *mut libc::c_void, 0i32); + measure_native_node_inner(node as *mut libc::c_void, eng, 0i32); if (*node.offset(1)).b32.s1 != savedWidth { /* see how much adjustment is needed overall */ let mut justAmount: f64 = Fix2D(savedWidth - (*node.offset(1)).b32.s1); @@ -1950,206 +1648,24 @@ pub unsafe extern "C" fn store_justified_native_glyphs(mut pNode: *mut libc::c_v } } } -#[no_mangle] -pub unsafe extern "C" fn measure_native_node( - mut pNode: *mut libc::c_void, - mut use_glyph_metrics: i32, -) { + +pub unsafe fn measure_native_node(mut pNode: *mut libc::c_void, mut use_glyph_metrics: i32) { + let mut node: *mut memory_word = pNode as *mut memory_word; + let f = (*node.offset(4)).b16.s2 as usize; + let mut eng = get_text_layout_engine_mut(f).expect("bad native font flag in `measure_native_node`"); + measure_native_node_inner(pNode, &mut *eng, use_glyph_metrics); +} + +pub unsafe fn measure_native_node_inner(mut pNode: *mut libc::c_void, eng: &mut impl TextLayout, use_glyph_metrics: i32) { let mut node: *mut memory_word = pNode as *mut memory_word; let mut txtLen: i32 = (*node.offset(4)).b16.s1 as i32; let mut txtPtr: *mut u16 = node.offset(6) as *mut u16; let mut f: u32 = (*node.offset(4)).b16.s2 as u32; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 { - /* using this font in OT Layout mode, so font_layout_engine[f] is actually a XeTeXLayoutEngine */ - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine; - let mut locations: *mut FixedPoint = 0 as *mut FixedPoint; - let mut glyphIDs: *mut u16 = 0 as *mut u16; - let mut glyphAdvances: *mut Fixed = 0 as *mut Fixed; - let mut totalGlyphCount: i32 = 0i32; - /* need to find direction runs within the text, and call layoutChars separately for each */ - let mut dir: icu::UBiDiDirection = icu::UBIDI_LTR; - let mut glyph_info: *mut libc::c_void = 0 as *mut libc::c_void; - static mut positions: *mut FloatPoint = 0 as *const FloatPoint as *mut FloatPoint; - static mut advances: *mut f32 = 0 as *const f32 as *mut f32; - static mut glyphs: *mut u32 = 0 as *const u32 as *mut u32; - let mut pBiDi: *mut icu::UBiDi = icu::ubidi_open(); - let mut errorCode: icu::UErrorCode = icu::U_ZERO_ERROR; - icu::ubidi_setPara( - pBiDi, - txtPtr as *const icu::UChar, - txtLen, - getDefaultDirection(engine) as icu::UBiDiLevel, - 0 as *mut icu::UBiDiLevel, - &mut errorCode, - ); - dir = icu::ubidi_getDirection(pBiDi); - if dir as u32 == icu::UBIDI_MIXED as i32 as u32 { - /* we actually do the layout twice here, once to count glyphs and then again to get them; - which is inefficient, but i figure that MIXED is a relatively rare occurrence, so i can't be - bothered to deal with the memory reallocation headache of doing it differently - */ - let mut nRuns: i32 = icu::ubidi_countRuns(pBiDi, &mut errorCode); - let mut width: f64 = 0i32 as f64; - let mut i: i32 = 0; - let mut runIndex: i32 = 0; - let mut logicalStart: i32 = 0; - let mut length: i32 = 0; - runIndex = 0i32; - while runIndex < nRuns { - dir = icu::ubidi_getVisualRun(pBiDi, runIndex, &mut logicalStart, &mut length); - totalGlyphCount += layoutChars( - engine, - txtPtr, - logicalStart, - length, - txtLen, - dir as u32 == icu::UBIDI_RTL as i32 as u32, - ); - runIndex += 1 - } - if totalGlyphCount > 0i32 { - let mut x: f64 = 0.; - let mut y: f64 = 0.; - glyph_info = xcalloc(totalGlyphCount as size_t, 10i32 as size_t); - locations = glyph_info as *mut FixedPoint; - glyphIDs = locations.offset(totalGlyphCount as isize) as *mut u16; - glyphAdvances = xcalloc( - totalGlyphCount as size_t, - ::std::mem::size_of::() as u64, - ) as *mut Fixed; - totalGlyphCount = 0i32; - y = 0.0f64; - x = y; - runIndex = 0i32; - while runIndex < nRuns { - let mut nGlyphs: i32 = 0; - dir = icu::ubidi_getVisualRun(pBiDi, runIndex, &mut logicalStart, &mut length); - nGlyphs = layoutChars( - engine, - txtPtr, - logicalStart, - length, - txtLen, - dir as u32 == icu::UBIDI_RTL as i32 as u32, - ); - glyphs = - xcalloc(nGlyphs as size_t, ::std::mem::size_of::() as u64) as *mut u32; - positions = xcalloc( - (nGlyphs + 1i32) as size_t, - ::std::mem::size_of::() as u64, - ) as *mut FloatPoint; - advances = - xcalloc(nGlyphs as size_t, ::std::mem::size_of::() as u64) as *mut f32; - getGlyphs(engine, glyphs); - getGlyphAdvances(engine, advances); - getGlyphPositions(engine, positions); - i = 0i32; - while i < nGlyphs { - *glyphIDs.offset(totalGlyphCount as isize) = - *glyphs.offset(i as isize) as u16; - (*locations.offset(totalGlyphCount as isize)).x = - D2Fix((*positions.offset(i as isize)).x as f64 + x); - (*locations.offset(totalGlyphCount as isize)).y = - D2Fix((*positions.offset(i as isize)).y as f64 + y); - *glyphAdvances.offset(totalGlyphCount as isize) = - D2Fix(*advances.offset(i as isize) as f64); - totalGlyphCount += 1; - i += 1 - } - x += (*positions.offset(nGlyphs as isize)).x as f64; - y += (*positions.offset(nGlyphs as isize)).y as f64; - free(glyphs as *mut libc::c_void); - free(positions as *mut libc::c_void); - free(advances as *mut libc::c_void); - runIndex += 1 - } - width = x - } - (*node.offset(1)).b32.s1 = D2Fix(width); - (*node.offset(4)).b16.s0 = totalGlyphCount as u16; - let ref mut fresh29 = (*node.offset(5)).ptr; - *fresh29 = glyph_info - } else { - let mut width_0: f64 = 0i32 as f64; - totalGlyphCount = layoutChars( - engine, - txtPtr, - 0i32, - txtLen, - txtLen, - dir as u32 == icu::UBIDI_RTL as i32 as u32, - ); - glyphs = xcalloc( - totalGlyphCount as size_t, - ::std::mem::size_of::() as u64, - ) as *mut u32; - positions = xcalloc( - (totalGlyphCount + 1i32) as size_t, - ::std::mem::size_of::() as u64, - ) as *mut FloatPoint; - advances = xcalloc( - totalGlyphCount as size_t, - ::std::mem::size_of::() as u64, - ) as *mut f32; - getGlyphs(engine, glyphs); - getGlyphAdvances(engine, advances); - getGlyphPositions(engine, positions); - if totalGlyphCount > 0i32 { - let mut i_0: i32 = 0; - glyph_info = xcalloc(totalGlyphCount as size_t, 10i32 as size_t); - locations = glyph_info as *mut FixedPoint; - glyphIDs = locations.offset(totalGlyphCount as isize) as *mut u16; - glyphAdvances = xcalloc( - totalGlyphCount as size_t, - ::std::mem::size_of::() as u64, - ) as *mut Fixed; - i_0 = 0i32; - while i_0 < totalGlyphCount { - *glyphIDs.offset(i_0 as isize) = *glyphs.offset(i_0 as isize) as u16; - *glyphAdvances.offset(i_0 as isize) = - D2Fix(*advances.offset(i_0 as isize) as f64); - (*locations.offset(i_0 as isize)).x = - D2Fix((*positions.offset(i_0 as isize)).x as f64); - (*locations.offset(i_0 as isize)).y = - D2Fix((*positions.offset(i_0 as isize)).y as f64); - i_0 += 1 - } - width_0 = (*positions.offset(totalGlyphCount as isize)).x as f64 - } - (*node.offset(1)).b32.s1 = D2Fix(width_0); - (*node.offset(4)).b16.s0 = totalGlyphCount as u16; - let ref mut fresh30 = (*node.offset(5)).ptr; - *fresh30 = glyph_info; - free(glyphs as *mut libc::c_void); - free(positions as *mut libc::c_void); - free(advances as *mut libc::c_void); - } - icu::ubidi_close(pBiDi); - if *font_letter_space.offset(f as isize) != 0i32 { - let mut lsDelta: Fixed = 0i32; - let mut lsUnit: Fixed = *font_letter_space.offset(f as isize); - let mut i_1: i32 = 0; - i_1 = 0i32; - while i_1 < totalGlyphCount { - if *glyphAdvances.offset(i_1 as isize) == 0i32 && lsDelta != 0i32 { - lsDelta -= lsUnit - } - let ref mut fresh31 = (*locations.offset(i_1 as isize)).x; - *fresh31 += lsDelta; - lsDelta += lsUnit; - i_1 += 1 - } - if lsDelta != 0i32 { - lsDelta -= lsUnit; - let ref mut fresh32 = (*node.offset(1)).b32.s1; - *fresh32 += lsDelta - } - } - free(glyphAdvances as *mut libc::c_void); - } else { - panic!("bad native font flag in `measure_native_node`"); - } + + let request = LayoutRequest::from_node(node, false); + let layout = eng.layout_text(request); + layout.write_node(node); + if use_glyph_metrics == 0i32 || (*node.offset(4)).b16.s0 as i32 == 0i32 { /* for efficiency, height and depth are the font's ascent/descent, not true values based on the actual content of the word, @@ -2176,25 +1692,10 @@ pub unsafe extern "C" fn measure_native_node( yMax: 0., }; if getCachedGlyphBBox(f as u16, *glyphIDs_0.offset(i_2 as isize), &mut bbox) == 0i32 { - match *font_area.offset(f as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - aat::GetGlyphBBox_AAT( - *font_layout_engine.offset(f as isize) as CFDictionaryRef, - *glyphIDs_0.offset(i_2 as isize), - &mut bbox, - ); - } - 0xfffeu32 => { - getGlyphBounds( - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine, - *glyphIDs_0.offset(i_2 as isize) as u32, - &mut bbox, - ); - } - _ => {} + if let Some(bb) = eng.glyph_bbox(*glyphIDs_0.offset(i_2 as isize) as u32) { + bbox = bb; + cacheGlyphBBox(f as u16, *glyphIDs_0.offset(i_2 as isize), &mut bbox); } - cacheGlyphBBox(f as u16, *glyphIDs_0.offset(i_2 as isize), &mut bbox); } ht = bbox.yMax; dp = -bbox.yMin; @@ -2210,6 +1711,7 @@ pub unsafe extern "C" fn measure_native_node( (*node.offset(2)).b32.s1 = -D2Fix(yMin as f64) }; } + #[no_mangle] pub unsafe extern "C" fn real_get_native_italic_correction(mut pNode: *mut libc::c_void) -> Fixed { let mut node: *mut memory_word = pNode as *mut memory_word; @@ -2218,27 +1720,20 @@ pub unsafe extern "C" fn real_get_native_italic_correction(mut pNode: *mut libc: if n > 0_u32 { let mut locations: *mut FixedPoint = (*node.offset(5)).ptr as *mut FixedPoint; let mut glyphIDs: *mut u16 = locations.offset(n as isize) as *mut u16; - match *font_area.offset(f as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - return D2Fix(aat::GetGlyphItalCorr_AAT( - *font_layout_engine.offset(f as isize) as CFDictionaryRef, - *glyphIDs.offset(n.wrapping_sub(1i32 as libc::c_uint) as isize), - )) + *font_letter_space.offset(f as isize); - } - 0xfffeu32 => { - return D2Fix(getGlyphItalCorr( - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine, - *glyphIDs.offset(n.wrapping_sub(1_u32) as isize) as u32, - ) as f64) - + *font_letter_space.offset(f as isize); - } - _ => 0i32, - } + get_text_layout_engine(f as usize) + .and_then(|eng| { + let gid = *glyphIDs.offset(n.wrapping_sub(1i32 as libc::c_uint) as isize) as u32; + let lspace = *font_letter_space.offset(f as isize); + eng.glyph_ital_correction(gid.into()) + .map(D2Fix) + .map(|x| x + lspace) + }) + .unwrap_or(0) // XXX: Not many functions return 0 instead of panicking. Why this one? } else { 0i32 } } + #[no_mangle] pub unsafe extern "C" fn real_get_native_glyph_italic_correction( mut pNode: *mut libc::c_void, @@ -2246,60 +1741,22 @@ pub unsafe extern "C" fn real_get_native_glyph_italic_correction( let mut node: *mut memory_word = pNode as *mut memory_word; let mut gid: u16 = (*node.offset(4)).b16.s1; let mut f: u32 = (*node.offset(4)).b16.s2 as u32; - match *font_area.offset(f as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - return D2Fix(aat::GetGlyphItalCorr_AAT( - *font_layout_engine.offset(f as isize) as CFDictionaryRef, - gid, - )); - } - 0xfffeu32 => { - return D2Fix(getGlyphItalCorr( - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine, - gid as u32, - ) as f64); - } - _ => { - 0i32 - /* can't actually happen */ - } - } + get_text_layout_engine(f as usize) + .and_then(|eng| eng.glyph_ital_correction(gid.into())) + .map(D2Fix) + .unwrap_or(0) // XXX: Apparently the matched-none case was "can't happen" } -#[no_mangle] -pub unsafe extern "C" fn measure_native_glyph( - mut pNode: *mut libc::c_void, - mut use_glyph_metrics: i32, -) { + +pub unsafe fn measure_native_glyph(mut pNode: *mut libc::c_void, mut use_glyph_metrics: i32) { let mut node: *mut memory_word = pNode as *mut memory_word; let mut gid: u16 = (*node.offset(4)).b16.s1; let mut f: u32 = (*node.offset(4)).b16.s2 as u32; - let mut ht: f32 = 0.0f64 as f32; - let mut dp: f32 = 0.0f64 as f32; - match *font_area.offset(f as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - let mut attributes: CFDictionaryRef = - *font_layout_engine.offset(f as isize) as CFDictionaryRef; - (*node.offset(1)).b32.s1 = D2Fix(aat::GetGlyphWidth_AAT(attributes, gid)); - if use_glyph_metrics != 0 { - aat::GetGlyphHeightDepth_AAT(attributes, gid, &mut ht, &mut dp); - } - } - 0xfffeu32 => { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine; - let mut fontInst: XeTeXFont = getFont(engine); - (*node.offset(1)).b32.s1 = D2Fix(getGlyphWidth(fontInst, gid as u32) as f64); - if use_glyph_metrics != 0 { - getGlyphHeightDepth(engine, gid as u32, &mut ht, &mut dp); - } - } - _ => { - panic!("bad native font flag in `measure_native_glyph`"); - } - } + let eng = + get_text_layout_engine(f as usize).expect("bad native font flag in `measure_native_glyph`"); + + (*node.offset(1)).b32.s1 = D2Fix(eng.glyph_width(gid as u32)); if use_glyph_metrics != 0 { + let (ht, dp) = eng.glyph_height_depth(gid as u32).unwrap_or((0., 0.)); (*node.offset(3)).b32.s1 = D2Fix(ht as f64); (*node.offset(2)).b32.s1 = D2Fix(dp as f64) } else { @@ -2307,101 +1764,38 @@ pub unsafe extern "C" fn measure_native_glyph( (*node.offset(2)).b32.s1 = *depth_base.offset(f as isize) }; } -#[no_mangle] -pub unsafe extern "C" fn map_char_to_glyph(mut font: i32, mut ch: i32) -> i32 { + +pub unsafe fn map_char_to_glyph(mut font: i32, mut ch: i32) -> i32 { if ch > 0x10ffffi32 || ch >= 0xd800i32 && ch <= 0xdfffi32 { return 0i32; } - match *font_area.offset(font as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - return aat::MapCharToGlyph_AAT( - *font_layout_engine.offset(font as isize) as CFDictionaryRef, - ch as u32, - ); - } - 0xfffeu32 => { - return mapCharToGlyph( - *font_layout_engine.offset(font as isize) as XeTeXLayoutEngine, - ch as u32, - ) as i32; - } - _ => { - panic!("bad native font flag in `map_char_to_glyph`"); - } - } + let eng = + get_text_layout_engine(font as usize).expect("bad native font flag in `map_char_to_glyph`"); + eng.map_char_to_glyph(ch as u32) as i32 } + #[no_mangle] -pub unsafe extern "C" fn map_glyph_to_index(mut font: i32) -> i32 -/* glyph name is at name_of_file */ { - match *font_area.offset(font as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - return aat::MapGlyphToIndex_AAT( - *font_layout_engine.offset(font as isize) as CFDictionaryRef, - name_of_file, - ); - } - 0xfffeu32 => { - return mapGlyphToIndex( - *font_layout_engine.offset(font as isize) as XeTeXLayoutEngine, - name_of_file, - ); - } - _ => { - panic!("bad native font flag in `map_glyph_to_index`"); - } - } +pub unsafe fn map_glyph_to_index(mut font: i32) -> i32 { + let eng = + get_text_layout_engine(font as usize).expect("map_glyph_to_index had invalid font number"); + // glyph name is at name_of_file. I guess it was scanned as a filename? + eng.map_glyph_to_index(name_of_file) } -#[no_mangle] -pub unsafe extern "C" fn get_font_char_range(mut font: i32, mut first: i32) -> i32 { - match *font_area.offset(font as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - return aat::GetFontCharRange_AAT( - *font_layout_engine.offset(font as isize) as CFDictionaryRef, - first, - ); - } - 0xfffeu32 => { - return getFontCharRange( - *font_layout_engine.offset(font as isize) as XeTeXLayoutEngine, - first, - ); - } - _ => { - panic!("bad native font flag in `get_font_char_range\'`"); - } - } -} -#[no_mangle] -pub unsafe extern "C" fn D2Fix(mut d: f64) -> Fixed { + +pub fn D2Fix(mut d: f64) -> Fixed { let rval: Fixed = (d * 65536.0f64 + 0.5f64) as i32; rval } -#[no_mangle] -pub unsafe extern "C" fn Fix2D(mut f: Fixed) -> f64 { + +pub fn Fix2D(mut f: Fixed) -> f64 { f as f64 / 65536. } -#[no_mangle] -pub unsafe extern "C" fn print_glyph_name(mut font: i32, mut gid: i32) { +pub unsafe fn print_glyph_name(mut font: i32, mut gid: i32) { let mut s: *const i8 = 0 as *const i8; let mut len: i32 = 0i32; - match *font_area.offset(font as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - s = aat::GetGlyphNameFromCTFont(aat::font_from_integer(font), gid as u16, &mut len); - } - 0xfffeu32 => { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(font as isize) as XeTeXLayoutEngine; - s = getGlyphName(getFont(engine), gid as u16, &mut len); - } - _ => { - panic!("bad native font flag in `print_glyph_name`"); - } - } + let engine = get_text_layout_engine(font as usize).expect("should have already checked"); + s = engine.glyph_name(gid as u16, &mut len); loop { let fresh33 = len; len = len - 1; diff --git a/engine/src/xetex_font_info.rs b/engine/src/xetex_font_info.rs index 08d6e6b48..f65a20bf3 100644 --- a/engine/src/xetex_font_info.rs +++ b/engine/src/xetex_font_info.rs @@ -1,41 +1,108 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] + +use std::ptr; + +use font_kit::handle::Handle; +use freetype::freetype::{ + FT_Attach_Stream, FT_BBox, FT_Byte, FT_Encoding, FT_Error, FT_Face, + FT_Face_GetCharVariantIndex, FT_Fixed, FT_Generic, FT_Generic_Finalizer, FT_Get_Char_Index, + FT_Get_First_Char, FT_Get_Glyph_Name, FT_Get_Kerning, FT_Get_Name_Index, FT_Get_Next_Char, + FT_Get_Sfnt_Table, FT_GlyphSlot, FT_Glyph_Format, FT_Glyph_Metrics, FT_Int, FT_Int32, + FT_Kerning_Mode, FT_Library, FT_Load_Glyph, FT_Load_Sfnt_Table, FT_Long, FT_Memory, + FT_MemoryRec_, FT_Open_Args, FT_Parameter, FT_Pointer, FT_Pos, FT_Sfnt_Tag, FT_Short, FT_Size, + FT_Stream, FT_String, FT_UInt, FT_ULong, FT_Vector, +}; + +use freetype::tt_os2::TT_OS2; +use std::ffi::{CStr, CString}; + +use freetype_missing::*; + +pub mod freetype_missing { + + use freetype::freetype::{ + FT_Error, FT_Face, FT_Fixed, FT_Int32, FT_Long, FT_Short, FT_UInt, FT_ULong, FT_UShort, + }; + + #[derive(Copy, Clone)] + #[repr(C)] + pub struct TT_Postscript_ { + pub FormatType: FT_Fixed, + pub italicAngle: FT_Fixed, + pub underlinePosition: FT_Short, + pub underlineThickness: FT_Short, + pub isFixedPitch: FT_ULong, + pub minMemType42: FT_ULong, + pub maxMemType42: FT_ULong, + pub minMemType1: FT_ULong, + pub maxMemType1: FT_ULong, + } + pub type TT_Postscript = TT_Postscript_; + + #[derive(Copy, Clone)] + #[repr(C)] + pub struct TT_Header_ { + pub Table_Version: FT_Fixed, + pub Font_Revision: FT_Fixed, + pub CheckSum_Adjust: FT_Long, + pub Magic_Number: FT_Long, + pub Flags: FT_UShort, + pub Units_Per_EM: FT_UShort, + pub Created: [FT_ULong; 2], + pub Modified: [FT_ULong; 2], + pub xMin: FT_Short, + pub yMin: FT_Short, + pub xMax: FT_Short, + pub yMax: FT_Short, + pub Mac_Style: FT_UShort, + pub Lowest_Rec_PPEM: FT_UShort, + pub Font_Direction: FT_Short, + pub Index_To_Loc_Format: FT_Short, + pub Glyph_Data_Format: FT_Short, + } + pub type TT_Header = TT_Header_; + + extern "C" { + + #[no_mangle] + pub fn FT_Get_Advance( + face: FT_Face, + gindex: FT_UInt, + load_flags: FT_Int32, + padvance: *mut FT_Fixed, + ) -> FT_Error; + + } +} use crate::core_memory::xmalloc; -use harfbuzz_sys::{hb_font_funcs_t, hb_destroy_func_t, hb_font_t, hb_codepoint_t, - hb_position_t, hb_bool_t, hb_font_destroy, hb_glyph_extents_t, hb_font_funcs_create, - hb_font_funcs_set_glyph_h_advance_func, hb_font_funcs_set_glyph_v_advance_func, - hb_font_funcs_set_glyph_h_origin_func, hb_font_funcs_set_glyph_v_origin_func, +use harfbuzz_sys::{ + hb_blob_create, hb_blob_t, hb_bool_t, hb_codepoint_t, hb_destroy_func_t, + hb_face_create_for_tables, hb_face_destroy, hb_face_set_index, hb_face_set_upem, hb_face_t, + hb_font_create, hb_font_destroy, hb_font_funcs_create, hb_font_funcs_set_glyph_contour_point_func, hb_font_funcs_set_glyph_extents_func, - hb_blob_create, HB_MEMORY_MODE_WRITABLE, hb_face_t, hb_tag_t, hb_blob_t, - hb_font_funcs_set_glyph_name_func, hb_face_create_for_tables, hb_face_set_index, - hb_face_set_upem, hb_font_create, hb_face_destroy, hb_font_set_funcs, - hb_font_set_scale, hb_font_set_ppem}; - -use freetype::freetype_sys::{FT_Byte, FT_UInt, FT_Long, FT_ULong, FT_Int32, FT_Pointer, FT_Error, FT_Fixed, - FT_Library, FT_Face, FT_Glyph, FT_String, FT_Parameter, FT_Vector, FT_Sfnt_Tag, - FT_BBox}; -use freetype::freetype_sys::{ - FT_Init_FreeType, - FT_New_Memory_Face, FT_Attach_Stream, - FT_Get_Char_Index, FT_Get_First_Char, FT_Get_Next_Char, - FT_Load_Glyph, FT_Get_Glyph, FT_Get_Glyph_Name, FT_Glyph_Get_CBox, FT_Done_Glyph, - FT_Get_Sfnt_Table, - FT_Get_Kerning, - FT_Get_Name_Index, - FT_Done_Face, + hb_font_funcs_set_glyph_h_advance_func, hb_font_funcs_set_glyph_h_origin_func, + hb_font_funcs_set_glyph_name_func, hb_font_funcs_set_glyph_v_advance_func, + hb_font_funcs_set_glyph_v_origin_func, hb_font_funcs_t, hb_font_set_funcs, hb_font_set_ppem, + hb_font_set_scale, hb_font_t, hb_glyph_extents_t, hb_position_t, hb_tag_t, + HB_MEMORY_MODE_WRITABLE, }; -use crate::freetype_sys_patch::{FT_Face_GetCharVariantIndex, FT_Get_Advance, FT_Load_Sfnt_Table}; use crate::{ - ttstub_input_close, ttstub_input_get_size, ttstub_input_read, ttstub_input_getc, ttstub_input_open, + ttstub_input_close, ttstub_input_get_size, ttstub_input_getc, ttstub_input_open, + ttstub_input_read_exact, }; +use crate::xetex_ext::Fix2D; + use bridge::TTInputFormat; #[cfg(not(target_os = "macos"))] @@ -45,8 +112,15 @@ mod imp {} #[path = "xetex_font_info_coretext.rs"] mod imp; +#[cfg(target_os = "macos")] +pub use imp::{XeTeXFontInst_Mac, XeTeXFontInst_Mac_create}; + extern crate libc; extern "C" { + pub type FT_ModuleRec_; + pub type FT_DriverRec_; + pub type FT_Face_InternalRec_; + pub type FT_Size_InternalRec_; #[no_mangle] fn malloc(_: libc::c_ulong) -> *mut libc::c_void; #[no_mangle] @@ -57,9 +131,6 @@ extern "C" { fn strrchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char; #[no_mangle] fn strlen(_: *const libc::c_char) -> libc::c_ulong; - /* The internal, C/C++ interface: */ - #[no_mangle] - fn _tt_abort(format: *const libc::c_char, _: ...) -> !; /* tectonic/core-memory.h: basic dynamic memory helpers Copyright 2016-2018 the Tectonic Project Licensed under the MIT License. @@ -68,6 +139,7 @@ extern "C" { fn xstrdup(s: *const libc::c_char) -> *mut libc::c_char; #[no_mangle] fn tolower(_: libc::c_int) -> libc::c_int; + // TODO: NOTE: this api doesn't included in harfbuzz_sys #[no_mangle] fn hb_font_funcs_set_glyph_h_kerning_func( @@ -76,6 +148,7 @@ extern "C" { user_data: *mut libc::c_void, destroy: hb_destroy_func_t, ); + #[no_mangle] fn hb_font_funcs_set_glyph_func( ffuncs: *mut hb_font_funcs_t, @@ -83,6 +156,7 @@ extern "C" { user_data: *mut libc::c_void, destroy: hb_destroy_func_t, ); + #[no_mangle] fn hb_font_funcs_set_glyph_v_kerning_func( ffuncs: *mut hb_font_funcs_t, @@ -90,9 +164,9 @@ extern "C" { user_data: *mut libc::c_void, destroy: hb_destroy_func_t, ); - #[no_mangle] - fn Fix2D(f: Fixed) -> libc::c_double; + } + pub type size_t = usize; pub type int32_t = i32; pub type uint16_t = u16; @@ -101,9 +175,6 @@ pub type ssize_t = isize; use bridge::InputHandleWrapper; pub type UChar32 = int32_t; -/* quasi-hack to get the primary input */ -/* */ -/* this #if 0 ... #endif clause is for documentation purposes */ pub type hb_font_get_glyph_kerning_func_t = Option< unsafe extern "C" fn( @@ -131,6 +202,7 @@ pub type OTTag = uint32_t; pub type GlyphID = uint16_t; pub type Fixed = i32; + #[derive(Copy, Clone)] #[repr(C)] pub struct GlyphBBox { @@ -139,7 +211,21 @@ pub struct GlyphBBox { pub xMax: libc::c_float, pub yMax: libc::c_float, } -#[derive(Copy, Clone)] + +impl GlyphBBox { + pub const fn zero() -> Self { + GlyphBBox { + xMin: 0.0, + yMin: 0.0, + xMax: 0.0, + yMax: 0.0, + } + } +} + +use font_kit::loaders::default::{Font, NativeFont}; + +#[derive(Clone)] #[repr(C)] pub struct XeTeXFontInst { pub m_unitsPerEM: libc::c_ushort, @@ -150,14 +236,47 @@ pub struct XeTeXFontInst { pub m_xHeight: libc::c_float, pub m_italicAngle: libc::c_float, pub m_vertical: bool, - pub m_filename: *mut libc::c_char, + // So it can be freed properly by the awkward C++ subclasses (by setting to None) + pub m_filename: Option, pub m_index: uint32_t, pub m_ftFace: FT_Face, - pub m_backingData: *mut FT_Byte, - pub m_backingData2: *mut FT_Byte, + pub m_afm_backing_data: Vec, pub m_hbFont: *mut hb_font_t, - pub m_subdtor: Option ()>, + pub m_subdtor: Option ()>, + pub fk_font: Option, } + +/* ***************************************************************************\ + Part of the XeTeX typesetting system + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew + + SIL Author(s): Jonathan Kew + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the copyright holders +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in this Software without prior written +authorization from the copyright holders. +\****************************************************************************/ /* * file name: XeTeXFontInst.cpp * @@ -181,48 +300,82 @@ unsafe extern "C" fn xbasename(mut name: *const libc::c_char) -> *const libc::c_ } return base; } + #[no_mangle] -pub static mut gFreeTypeLibrary: FT_Library = 0 as FT_Library; -static mut hbFontFuncs: *mut hb_font_funcs_t = 0 as *mut hb_font_funcs_t; -#[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_base_ctor( - mut self_0: *mut XeTeXFontInst, - mut pathname: *const libc::c_char, - mut index: libc::c_int, - mut pointSize: libc::c_float, - mut status: *mut libc::c_int, -) { - (*self_0).m_unitsPerEM = 0i32 as libc::c_ushort; - (*self_0).m_pointSize = pointSize; - (*self_0).m_ascent = 0i32 as libc::c_float; - (*self_0).m_descent = 0i32 as libc::c_float; - (*self_0).m_capHeight = 0i32 as libc::c_float; - (*self_0).m_xHeight = 0i32 as libc::c_float; - (*self_0).m_italicAngle = 0i32 as libc::c_float; - (*self_0).m_vertical = 0i32 != 0; - (*self_0).m_filename = 0 as *mut libc::c_char; - (*self_0).m_index = 0i32 as uint32_t; - (*self_0).m_ftFace = 0 as FT_Face; - (*self_0).m_backingData = 0 as *mut FT_Byte; - (*self_0).m_backingData2 = 0 as *mut FT_Byte; - (*self_0).m_hbFont = 0 as *mut hb_font_t; - (*self_0).m_subdtor = None; - if !pathname.is_null() { - XeTeXFontInst_initialize(self_0, pathname, index, status); - }; +pub static mut gFreeTypeLibrary: FT_Library = ptr::null_mut(); +static mut hbFontFuncs: *mut hb_font_funcs_t = ptr::null_mut(); + +impl XeTeXFontInst { + pub unsafe fn new( + mut pathname: Option<&CStr>, + mut index: libc::c_int, + mut pointSize: libc::c_float, + mut status: *mut libc::c_int, + ) -> Self { + let mut neu = XeTeXFontInst { + m_unitsPerEM: 0, + m_pointSize: pointSize, + m_ascent: 0.0, + m_descent: 0.0, + m_capHeight: 0.0, + m_xHeight: 0.0, + m_italicAngle: 0.0, + m_vertical: false, + m_filename: None, + m_index: 0, + m_ftFace: std::ptr::null_mut(), + m_afm_backing_data: Vec::new(), + m_hbFont: std::ptr::null_mut(), + m_subdtor: None, + fk_font: None, + }; + if let Some(path) = pathname { + if let Err(e) = neu.init(path, index) { + *status = e; + } + } + neu + } + pub unsafe fn init(&mut self, pathname: &CStr, mut index: libc::c_int) -> Result<(), i32> { + XeTeXFontInst_initialize(self, pathname, index) + } + + pub fn units_to_points(&self, units: f32) -> f32 { + (units * self.m_pointSize) / (self.m_unitsPerEM as f32) + } + + pub fn get_glyph_bounds(&self, gid: GlyphID) -> Option { + if let Some(font) = &self.fk_font { + if let Ok(rect) = font.typographic_bounds(gid as u32) { + let bbox = GlyphBBox { + xMin: self.units_to_points(rect.origin.x), + xMax: self.units_to_points(rect.origin.x + rect.size.width), + yMin: self.units_to_points(rect.origin.y), + yMax: self.units_to_points(rect.origin.y + rect.size.height), + }; + return Some(bbox); + } + } + None + } } + #[no_mangle] pub unsafe extern "C" fn XeTeXFontInst_create( - mut pathname: *const libc::c_char, + mut pathname: &CStr, mut index: libc::c_int, mut pointSize: libc::c_float, mut status: *mut libc::c_int, ) -> *mut XeTeXFontInst { let mut self_0: *mut XeTeXFontInst = malloc(::std::mem::size_of::() as libc::c_ulong) as *mut XeTeXFontInst; - XeTeXFontInst_base_ctor(self_0, pathname, index, pointSize, status); - return self_0; + std::ptr::write( + self_0, + XeTeXFontInst::new(Some(pathname), index, pointSize, status), + ); + self_0 } + #[no_mangle] pub unsafe extern "C" fn XeTeXFontInst_delete(mut self_0: *mut XeTeXFontInst) { if self_0.is_null() { @@ -232,15 +385,17 @@ pub unsafe extern "C" fn XeTeXFontInst_delete(mut self_0: *mut XeTeXFontInst) { (*self_0).m_subdtor.expect("non-null function pointer")(self_0); } if !(*self_0).m_ftFace.is_null() { - FT_Done_Face((*self_0).m_ftFace); (*self_0).m_ftFace = 0 as FT_Face } hb_font_destroy((*self_0).m_hbFont); - free((*self_0).m_backingData as *mut libc::c_void); - free((*self_0).m_backingData2 as *mut libc::c_void); - free((*self_0).m_filename as *mut libc::c_void); + // Writing to these drops what's in there + (*self_0).m_afm_backing_data = Vec::new(); + // Also drops the underlying FreeType font, so we don't have to FT_Done_Face ourselves + (*self_0).fk_font = None; + (*self_0).m_filename = None; free(self_0 as *mut libc::c_void); } + /* HarfBuzz font functions */ unsafe extern "C" fn _get_glyph( mut _hbf: *mut hb_font_t, @@ -260,6 +415,7 @@ unsafe extern "C" fn _get_glyph( } return (*gid != 0i32 as libc::c_uint) as libc::c_int; } + unsafe extern "C" fn _get_glyph_advance( mut face: FT_Face, mut gid: FT_UInt, @@ -281,6 +437,7 @@ unsafe extern "C" fn _get_glyph_advance( } return advance; } + unsafe extern "C" fn _get_glyph_h_advance( mut _hbf: *mut hb_font_t, mut font_data: *mut libc::c_void, @@ -289,6 +446,7 @@ unsafe extern "C" fn _get_glyph_h_advance( ) -> hb_position_t { return _get_glyph_advance(font_data as FT_Face, gid, 0i32 != 0) as hb_position_t; } + unsafe extern "C" fn _get_glyph_v_advance( mut _hbf: *mut hb_font_t, mut font_data: *mut libc::c_void, @@ -308,6 +466,7 @@ unsafe extern "C" fn _get_glyph_h_origin( // horizontal origin is (0, 0) return 1i32; } + unsafe extern "C" fn _get_glyph_v_origin( mut _hbf: *mut hb_font_t, mut font_data: *mut libc::c_void, @@ -319,6 +478,7 @@ unsafe extern "C" fn _get_glyph_v_origin( // vertical origin is (0, 0) for now return 1i32; } + unsafe extern "C" fn _get_glyph_h_kerning( mut _hbf: *mut hb_font_t, mut font_data: *mut libc::c_void, @@ -326,7 +486,6 @@ unsafe extern "C" fn _get_glyph_h_kerning( mut gid2: hb_codepoint_t, mut _p: *mut libc::c_void, ) -> hb_position_t { - use freetype::freetype_sys::FT_KERNING_UNSCALED; let mut face: FT_Face = font_data as FT_Face; let mut error: FT_Error = 0; let mut kerning: FT_Vector = FT_Vector { x: 0, y: 0 }; @@ -335,7 +494,7 @@ unsafe extern "C" fn _get_glyph_h_kerning( face, gid1, gid2, - FT_KERNING_UNSCALED as libc::c_int as FT_UInt, + FT_Kerning_Mode::FT_KERNING_UNSCALED as u32, &mut kerning, ); if error != 0 { @@ -345,6 +504,7 @@ unsafe extern "C" fn _get_glyph_h_kerning( } return ret; } + unsafe extern "C" fn _get_glyph_v_kerning( mut _hbf: *mut hb_font_t, mut font_data: *mut libc::c_void, @@ -355,6 +515,7 @@ unsafe extern "C" fn _get_glyph_v_kerning( /* FreeType does not support vertical kerning */ return 0i32; } + unsafe extern "C" fn _get_glyph_extents( mut _hbf: *mut hb_font_t, mut font_data: *mut libc::c_void, @@ -373,6 +534,7 @@ unsafe extern "C" fn _get_glyph_extents( } return (error == 0) as libc::c_int; } + unsafe extern "C" fn _get_glyph_contour_point( mut _hbf: *mut hb_font_t, mut font_data: *mut libc::c_void, @@ -382,14 +544,13 @@ unsafe extern "C" fn _get_glyph_contour_point( mut y: *mut hb_position_t, mut _p: *mut libc::c_void, ) -> hb_bool_t { - use freetype::freetype_sys::FT_GLYPH_FORMAT_OUTLINE; let mut face: FT_Face = font_data as FT_Face; let mut error: FT_Error = 0; let mut ret: bool = 0i32 != 0; error = FT_Load_Glyph(face, gid, (1i64 << 0i32) as FT_Int32); if error == 0 { if (*(*face).glyph).format as libc::c_uint - == FT_GLYPH_FORMAT_OUTLINE as libc::c_int as libc::c_uint + == FT_Glyph_Format::FT_GLYPH_FORMAT_OUTLINE as libc::c_int as libc::c_uint { if point_index < (*(*face).glyph).outline.n_points as libc::c_uint { *x = (*(*(*face).glyph).outline.points.offset(point_index as isize)).x @@ -402,6 +563,7 @@ unsafe extern "C" fn _get_glyph_contour_point( } return ret as hb_bool_t; } + unsafe extern "C" fn _get_glyph_name( mut _hbf: *mut hb_font_t, mut font_data: *mut libc::c_void, @@ -418,6 +580,7 @@ unsafe extern "C" fn _get_glyph_name( } return ret as hb_bool_t; } + unsafe extern "C" fn _get_font_funcs() -> *mut hb_font_funcs_t { static mut funcs: *mut hb_font_funcs_t = 0 as *const hb_font_funcs_t as *mut hb_font_funcs_t; if funcs.is_null() { @@ -505,14 +668,10 @@ unsafe extern "C" fn _get_font_funcs() -> *mut hb_font_funcs_t { 0 as *mut libc::c_void, None, ); - hb_font_funcs_set_glyph_name_func( - funcs, - Some(_get_glyph_name), - 0 as *mut libc::c_void, - None, - ); + hb_font_funcs_set_glyph_name_func(funcs, Some(_get_glyph_name), 0 as *mut libc::c_void, None); return funcs; } + unsafe extern "C" fn _get_table( mut _hfc: *mut hb_face_t, mut tag: hb_tag_t, @@ -551,64 +710,66 @@ unsafe extern "C" fn _get_table( } return blob; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_initialize( - mut self_0: *mut XeTeXFontInst, - mut pathname: *const libc::c_char, - mut index: libc::c_int, - mut status: *mut libc::c_int, -) { - use freetype::freetype_sys::{FT_Open_Args}; - use freetype::freetype_sys::{TT_OS2, TT_Postscript}; - use crate::freetype_sys_patch::{FT_SFNT_POST, FT_SFNT_OS2}; +pub unsafe fn XeTeXFontInst_initialize( + self_0: &mut XeTeXFontInst, + pathname: &CStr, + index: libc::c_int, +) -> Result<(), i32> { let mut postTable: *mut TT_Postscript = 0 as *mut TT_Postscript; let mut os2Table: *mut TT_OS2 = 0 as *mut TT_OS2; let mut error: FT_Error = 0; let mut hbFace: *mut hb_face_t = 0 as *mut hb_face_t; - if gFreeTypeLibrary.is_null() { - error = FT_Init_FreeType(&mut gFreeTypeLibrary); - if error != 0 { - _tt_abort( - b"FreeType initialization failed, error %d\x00" as *const u8 as *const libc::c_char, - error, - ); - } - } // Here we emulate some logic that was originally in find_native_font(); - let mut handle = ttstub_input_open(pathname, TTInputFormat::OPENTYPE, 0) - .or_else(|| ttstub_input_open(pathname, TTInputFormat::TRUETYPE, 0)) - .or_else(|| ttstub_input_open(pathname, TTInputFormat::TYPE1, 0)); - if handle.is_none() { - *status = 1i32; - return; - } - let mut handle = handle.unwrap(); - let mut sz = ttstub_input_get_size(&mut handle); - (*self_0).m_backingData = xmalloc(sz as _) as *mut FT_Byte; - let mut r = - ttstub_input_read(handle.0.as_ptr(), (*self_0).m_backingData as *mut libc::c_char, sz); - if r < 0 || r != sz as i64 { - _tt_abort(b"failed to read font file\x00" as *const u8 as *const libc::c_char); + let mut handle = ttstub_input_open(pathname.as_ptr(), TTInputFormat::OPENTYPE, 0) + .or_else(|| ttstub_input_open(pathname.as_ptr(), TTInputFormat::TRUETYPE, 0)) + .or_else(|| ttstub_input_open(pathname.as_ptr(), TTInputFormat::TYPE1, 0)) + .ok_or(1)?; + + use std::io::prelude::*; + let mut bytes = Vec::new(); + handle.read_to_end(&mut bytes).unwrap(); + let len = bytes.len(); + + use std::sync::Arc; + let fk_handle = Handle::Memory { + bytes: Arc::new(bytes), + font_index: index as u32, + }; + let fk_font = match fk_handle.load() { + Ok(loaded) => loaded, + Err(e) => panic!( + "font-kit: Couldn't load Handle for {:?}, got error {:?}", + pathname, e + ), + }; + + self_0.m_filename = Some(pathname.to_owned()); + + let ft_face = fk_font.native_font(); + + // https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_face_flag_xxx + const FT_FACE_FLAG_SCALABLE: FT_Long = 1 << 0; + const FT_FACE_FLAG_SFNT: FT_Long = 1 << 3; + + if (*ft_face).face_flags & FT_FACE_FLAG_SCALABLE == 0 { + // Not an outline font + return Err(1); } + + self_0.fk_font = Some(fk_font); + self_0.m_ftFace = ft_face; + ttstub_input_close(handle); - error = FT_New_Memory_Face( - gFreeTypeLibrary, - (*self_0).m_backingData, - sz as FT_Long, - index as FT_Long, - &mut (*self_0).m_ftFace, - ); - if (*(*self_0).m_ftFace).face_flags & 1 << 0i32 == 0 { - *status = 1i32; - return; - } + /* for non-sfnt-packaged fonts (presumably Type 1), see if there is an AFM file we can attach */ - if index == 0i32 && (*(*self_0).m_ftFace).face_flags & 1 << 3i32 == 0 { + if index == 0i32 && (*self_0.m_ftFace).face_flags & FT_FACE_FLAG_SFNT == 0 { // Tectonic: this code used to use kpse_find_file and FT_Attach_File // to try to find metrics for this font. Thanks to the existence of // FT_Attach_Stream we can emulate this behavior while going through // the Rust I/O layer. - let mut afm: *mut libc::c_char = xstrdup(xbasename(pathname)); + let mut afm: *mut libc::c_char = xstrdup(xbasename(pathname.as_ptr())); let mut p: *mut libc::c_char = strrchr(afm, '.' as i32); if !p.is_null() && strlen(p) == 4i32 as libc::c_ulong @@ -620,40 +781,43 @@ pub unsafe extern "C" fn XeTeXFontInst_initialize( let mut afm_handle = ttstub_input_open(afm, TTInputFormat::AFM, 0i32); free(afm as *mut libc::c_void); if let Some(mut afm_handle) = afm_handle { - sz = ttstub_input_get_size(&mut afm_handle); - (*self_0).m_backingData2 = xmalloc(sz as _) as *mut FT_Byte; - r = ttstub_input_read( - afm_handle.0.as_ptr(), - (*self_0).m_backingData2 as *mut libc::c_char, - sz, - ); - if r < 0 || r != sz as i64 { - _tt_abort(b"failed to read AFM file\x00" as *const u8 as *const libc::c_char); - } + self_0.m_afm_backing_data.clear(); + afm_handle + .read_to_end(&mut self_0.m_afm_backing_data) + .unwrap(); ttstub_input_close(afm_handle); - let mut open_args: FT_Open_Args = std::mem::zeroed(); - open_args.flags = 0x1i32 as FT_UInt; - open_args.memory_base = (*self_0).m_backingData2; - open_args.memory_size = sz as FT_Long; - FT_Attach_Stream((*self_0).m_ftFace, &mut open_args); + let mut open_args: FT_Open_Args = FT_Open_Args { + flags: 0, + memory_base: ptr::null(), + memory_size: 0, + pathname: ptr::null_mut(), + stream: ptr::null_mut(), + driver: ptr::null_mut(), + num_params: 0, + params: ptr::null_mut(), + }; + open_args.flags = 1; + open_args.memory_base = self_0.m_afm_backing_data.as_ptr(); + open_args.memory_size = self_0.m_afm_backing_data.len() as FT_Long; + FT_Attach_Stream(self_0.m_ftFace, &mut open_args); } } - (*self_0).m_filename = xstrdup(pathname); - (*self_0).m_index = index as uint32_t; - (*self_0).m_unitsPerEM = (*(*self_0).m_ftFace).units_per_EM; - (*self_0).m_ascent = - XeTeXFontInst_unitsToPoints(self_0, (*(*self_0).m_ftFace).ascender as libc::c_float); - (*self_0).m_descent = - XeTeXFontInst_unitsToPoints(self_0, (*(*self_0).m_ftFace).descender as libc::c_float); - postTable = XeTeXFontInst_getFontTableFT(self_0, FT_SFNT_POST) as *mut TT_Postscript; + self_0.m_index = index as uint32_t; + self_0.m_unitsPerEM = (*self_0.m_ftFace).units_per_EM; + self_0.m_ascent = + XeTeXFontInst_unitsToPoints(self_0, (*self_0.m_ftFace).ascender as libc::c_float); + self_0.m_descent = + XeTeXFontInst_unitsToPoints(self_0, (*self_0.m_ftFace).descender as libc::c_float); + postTable = + XeTeXFontInst_getFontTableFT(self_0, FT_Sfnt_Tag::FT_SFNT_POST) as *mut TT_Postscript; if !postTable.is_null() { - (*self_0).m_italicAngle = Fix2D((*postTable).italicAngle as Fixed) as libc::c_float + self_0.m_italicAngle = Fix2D((*postTable).italicAngle as Fixed) as libc::c_float } - os2Table = XeTeXFontInst_getFontTableFT(self_0, FT_SFNT_OS2) as *mut TT_OS2; + os2Table = XeTeXFontInst_getFontTableFT(self_0, FT_Sfnt_Tag::FT_SFNT_OS2) as *mut TT_OS2; if !os2Table.is_null() { - (*self_0).m_capHeight = + self_0.m_capHeight = XeTeXFontInst_unitsToPoints(self_0, (*os2Table).sCapHeight as libc::c_float); - (*self_0).m_xHeight = + self_0.m_xHeight = XeTeXFontInst_unitsToPoints(self_0, (*os2Table).sxHeight as libc::c_float) } // Set up HarfBuzz font @@ -666,43 +830,41 @@ pub unsafe extern "C" fn XeTeXFontInst_initialize( _: *mut libc::c_void, ) -> *mut hb_blob_t, ), - (*self_0).m_ftFace as *mut libc::c_void, + self_0.m_ftFace as *mut libc::c_void, None, ); hb_face_set_index(hbFace, index as libc::c_uint); - hb_face_set_upem(hbFace, (*self_0).m_unitsPerEM as libc::c_uint); - (*self_0).m_hbFont = hb_font_create(hbFace); + hb_face_set_upem(hbFace, self_0.m_unitsPerEM as libc::c_uint); + self_0.m_hbFont = hb_font_create(hbFace); hb_face_destroy(hbFace); if hbFontFuncs.is_null() { hbFontFuncs = _get_font_funcs() } hb_font_set_funcs( - (*self_0).m_hbFont, + self_0.m_hbFont, hbFontFuncs, - (*self_0).m_ftFace as *mut libc::c_void, + self_0.m_ftFace as *mut libc::c_void, None, ); hb_font_set_scale( - (*self_0).m_hbFont, - (*self_0).m_unitsPerEM as libc::c_int, - (*self_0).m_unitsPerEM as libc::c_int, + self_0.m_hbFont, + self_0.m_unitsPerEM as libc::c_int, + self_0.m_unitsPerEM as libc::c_int, ); // We don’t want device tables adjustments - hb_font_set_ppem( - (*self_0).m_hbFont, - 0i32 as libc::c_uint, - 0i32 as libc::c_uint, - ); + hb_font_set_ppem(self_0.m_hbFont, 0i32 as libc::c_uint, 0i32 as libc::c_uint); + Ok(()) } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_setLayoutDirVertical( +pub unsafe fn XeTeXFontInst_setLayoutDirVertical( mut self_0: *mut XeTeXFontInst, mut vertical: bool, ) { (*self_0).m_vertical = vertical; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getFontTable( +pub unsafe fn XeTeXFontInst_getFontTable( mut self_0: *const XeTeXFontInst, mut tag: OTTag, ) -> *mut libc::c_void { @@ -736,65 +898,26 @@ pub unsafe extern "C" fn XeTeXFontInst_getFontTable( return table; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getFontTableFT( +pub unsafe fn XeTeXFontInst_getFontTableFT( mut self_0: *const XeTeXFontInst, mut tag: FT_Sfnt_Tag, ) -> *mut libc::c_void { return FT_Get_Sfnt_Table((*self_0).m_ftFace, tag); } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getGlyphBounds( - mut self_0: *mut XeTeXFontInst, - mut gid: GlyphID, - mut bbox: *mut GlyphBBox, -) { - use freetype::freetype_sys::FT_GLYPH_BBOX_UNSCALED; - (*bbox).yMax = 0.0f64 as libc::c_float; - (*bbox).xMax = (*bbox).yMax; - (*bbox).yMin = (*bbox).xMax; - (*bbox).xMin = (*bbox).yMin; - let mut error: FT_Error = FT_Load_Glyph( - (*self_0).m_ftFace, - gid as FT_UInt, - (1i64 << 0i32) as FT_Int32, - ); - if error != 0 { - return; - } - let mut glyph: FT_Glyph = 0 as FT_Glyph; - error = FT_Get_Glyph((*(*self_0).m_ftFace).glyph, &mut glyph); - if error == 0i32 { - let mut ft_bbox: FT_BBox = FT_BBox { - xMin: 0, - yMin: 0, - xMax: 0, - yMax: 0, - }; - FT_Glyph_Get_CBox( - glyph, - FT_GLYPH_BBOX_UNSCALED as libc::c_int as FT_UInt, - &mut ft_bbox, - ); - (*bbox).xMin = XeTeXFontInst_unitsToPoints(self_0, ft_bbox.xMin as libc::c_float); - (*bbox).yMin = XeTeXFontInst_unitsToPoints(self_0, ft_bbox.yMin as libc::c_float); - (*bbox).xMax = XeTeXFontInst_unitsToPoints(self_0, ft_bbox.xMax as libc::c_float); - (*bbox).yMax = XeTeXFontInst_unitsToPoints(self_0, ft_bbox.yMax as libc::c_float); - FT_Done_Glyph(glyph); - }; -} -#[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_mapCharToGlyph( +pub unsafe fn XeTeXFontInst_mapCharToGlyph( mut self_0: *const XeTeXFontInst, mut ch: UChar32, ) -> GlyphID { return FT_Get_Char_Index((*self_0).m_ftFace, ch as FT_ULong) as GlyphID; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getNumGlyphs(mut self_0: *const XeTeXFontInst) -> uint16_t { +pub unsafe fn XeTeXFontInst_getNumGlyphs(mut self_0: *const XeTeXFontInst) -> uint16_t { return (*(*self_0).m_ftFace).num_glyphs as uint16_t; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getGlyphWidth( +pub unsafe fn XeTeXFontInst_getGlyphWidth( mut self_0: *mut XeTeXFontInst, mut gid: GlyphID, ) -> libc::c_float { @@ -804,19 +927,14 @@ pub unsafe extern "C" fn XeTeXFontInst_getGlyphWidth( ); } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getGlyphHeightDepth( +pub unsafe fn XeTeXFontInst_getGlyphHeightDepth( mut self_0: *mut XeTeXFontInst, mut gid: GlyphID, mut ht: *mut libc::c_float, mut dp: *mut libc::c_float, ) { - let mut bbox: GlyphBBox = GlyphBBox { - xMin: 0., - yMin: 0., - xMax: 0., - yMax: 0., - }; - XeTeXFontInst_getGlyphBounds(self_0, gid, &mut bbox); + let self_1 = &*(self_0 as *const XeTeXFontInst); + let bbox = self_1.get_glyph_bounds(gid).unwrap_or(GlyphBBox::zero()); if !ht.is_null() { *ht = bbox.yMax } @@ -854,120 +972,48 @@ Except as contained in this notice, the name of the copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the copyright holders. -\****************************************************************************/ -/* - * file name: XeTeXFontInst.h - * - * created on: 2005-10-22 - * created by: Jonathan Kew - * - * originally based on PortableFontInstance.h from ICU - */ -// create specific subclasses for each supported platform -// false = horizontal, true = vertical -// font filename -// face index -/* -class XeTeXFontInst -{ -protected: - -public: - XeTeXFontInst(float pointSize, int &status); - XeTeXFontInst(const char* filename, int index, float pointSize, int &status); - - virtual ~XeTeXFontInst(); - - void initialize(const char* pathname, int index, int &status); - - void *getFontTable(OTTag tableTag) const; - void *getFontTable(FT_Sfnt_Tag tableTag) const; - - hb_font_t *getHbFont() const { return m_hbFont; } - void setLayoutDirVertical(bool vertical); - bool getLayoutDirVertical() const { return m_vertical; } - - GlyphID mapCharToGlyph(UChar32 ch) const; - GlyphID mapGlyphToIndex(const char* glyphName) const; - - uint16_t getNumGlyphs() const; - - void getGlyphBounds(GlyphID glyph, GlyphBBox* bbox); - - float getGlyphWidth(GlyphID glyph); - void getGlyphHeightDepth(GlyphID glyph, float *ht, float* dp); - void getGlyphSidebearings(GlyphID glyph, float* lsb, float* rsb); - float getGlyphItalCorr(GlyphID glyph); - - const char* getGlyphName(GlyphID gid, int& nameLen); - - UChar32 getFirstCharCode(); - UChar32 getLastCharCode(); - - float unitsToPoints(float units) const - { - return (units * m_pointSize) / (float) m_unitsPerEM; - } - - float pointsToUnits(float points) const - { - return (points * (float) m_unitsPerEM) / m_pointSize; - } -}; */ #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getGlyphSidebearings( +pub unsafe fn XeTeXFontInst_getGlyphSidebearings( mut self_0: *mut XeTeXFontInst, mut gid: GlyphID, - mut lsb: *mut libc::c_float, - mut rsb: *mut libc::c_float, + mut lsb: &mut f32, + mut rsb: &mut f32, ) { let mut width: libc::c_float = XeTeXFontInst_getGlyphWidth(self_0, gid); - let mut bbox: GlyphBBox = GlyphBBox { - xMin: 0., - yMin: 0., - xMax: 0., - yMax: 0., - }; - XeTeXFontInst_getGlyphBounds(self_0, gid, &mut bbox); - if !lsb.is_null() { - *lsb = bbox.xMin - } - if !rsb.is_null() { - *rsb = width - bbox.xMax - }; + + let self_1 = &*(self_0 as *const XeTeXFontInst); + let bbox = self_1.get_glyph_bounds(gid).unwrap_or(GlyphBBox::zero()); + + *lsb = bbox.xMin; + *rsb = width - bbox.xMax; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getGlyphItalCorr( +pub unsafe fn XeTeXFontInst_getGlyphItalCorr( mut self_0: *mut XeTeXFontInst, mut gid: GlyphID, ) -> libc::c_float { let mut rval: libc::c_float = 0.0f64 as libc::c_float; let mut width: libc::c_float = XeTeXFontInst_getGlyphWidth(self_0, gid); - let mut bbox: GlyphBBox = GlyphBBox { - xMin: 0., - yMin: 0., - xMax: 0., - yMax: 0., - }; - XeTeXFontInst_getGlyphBounds(self_0, gid, &mut bbox); + let self_1 = &*(self_0 as *const XeTeXFontInst); + let bbox = self_1.get_glyph_bounds(gid).unwrap_or(GlyphBBox::zero()); if bbox.xMax > width { rval = bbox.xMax - width } return rval; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_mapGlyphToIndex( +pub unsafe fn XeTeXFontInst_mapGlyphToIndex( mut self_0: *const XeTeXFontInst, mut glyphName: *const libc::c_char, ) -> GlyphID { return FT_Get_Name_Index((*self_0).m_ftFace, glyphName as *mut libc::c_char) as GlyphID; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getGlyphName( +pub unsafe fn XeTeXFontInst_getGlyphName( mut self_0: *mut XeTeXFontInst, mut gid: GlyphID, - mut nameLen: *mut libc::c_int, + mut nameLen: &mut libc::c_int, ) -> *const libc::c_char { if (*(*self_0).m_ftFace).face_flags & 1 << 9i32 != 0 { static mut buffer: [libc::c_char; 256] = [0; 256]; @@ -985,12 +1031,12 @@ pub unsafe extern "C" fn XeTeXFontInst_getGlyphName( }; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getFirstCharCode(mut self_0: *mut XeTeXFontInst) -> UChar32 { +pub unsafe fn XeTeXFontInst_getFirstCharCode(mut self_0: *mut XeTeXFontInst) -> UChar32 { let mut gindex: FT_UInt = 0; return FT_Get_First_Char((*self_0).m_ftFace, &mut gindex) as UChar32; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_getLastCharCode(mut self_0: *mut XeTeXFontInst) -> UChar32 { +pub unsafe fn XeTeXFontInst_getLastCharCode(mut self_0: *mut XeTeXFontInst) -> UChar32 { let mut gindex: FT_UInt = 0; let mut ch: UChar32 = FT_Get_First_Char((*self_0).m_ftFace, &mut gindex) as UChar32; let mut prev: UChar32 = ch; @@ -1003,22 +1049,23 @@ pub unsafe extern "C" fn XeTeXFontInst_getLastCharCode(mut self_0: *mut XeTeXFon #[no_mangle] //#[inline] -pub unsafe extern "C" fn XeTeXFontInst_getHbFont(self_0: *const XeTeXFontInst) -> *mut hb_font_t { +pub unsafe fn XeTeXFontInst_getHbFont(self_0: *const XeTeXFontInst) -> *mut hb_font_t { (*self_0).m_hbFont } #[no_mangle] //#[inline] -pub unsafe extern "C" fn XeTeXFontInst_unitsToPoints( +pub unsafe fn XeTeXFontInst_unitsToPoints( self_0: *const XeTeXFontInst, units: libc::c_float, ) -> libc::c_float { - (units * (*self_0).m_pointSize) / ((*self_0).m_unitsPerEM as libc::c_float) + let self_1 = &*self_0; + self_1.units_to_points(units) } #[no_mangle] //#[inline] -pub unsafe extern "C" fn XeTeXFontInst_pointsToUnits( +pub unsafe fn XeTeXFontInst_pointsToUnits( self_0: *const XeTeXFontInst, points: libc::c_float, ) -> libc::c_float { diff --git a/engine/src/xetex_font_info_coretext.rs b/engine/src/xetex_font_info_coretext.rs index 48cd7c81d..45d8686e2 100644 --- a/engine/src/xetex_font_info_coretext.rs +++ b/engine/src/xetex_font_info_coretext.rs @@ -1,171 +1,40 @@ #![cfg(target_os = "macos")] -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] use harfbuzz_sys::hb_font_t; -use freetype::freetype_sys; +use std::ffi::CStr; + +use super::XeTeXFontInst; + +use crate::xetex_aatfont::cf_prelude::{ + kCFTypeArrayCallBacks, kCFTypeDictionaryKeyCallBacks, kCFTypeDictionaryValueCallBacks, + kCTFontCascadeListAttribute, CFAllocatorRef, CFArrayCreate, CFArrayRef, CFDictionaryCreate, + CFDictionaryRef, CFIndex, CFRelease, CFTypeRef, CGAffineTransform, + CTFontCreateWithFontDescriptor, CTFontDescriptorCreateCopyWithAttributes, CTFontDescriptorRef, + CTFontRef, +}; +use crate::xetex_aatfont::getFileNameFromCTFont; +use crate::xetex_font_info::XeTeXFontInst_initialize; extern crate libc; extern "C" { - pub type __CFAllocator; - pub type __CFString; - pub type __CFArray; - pub type __CFDictionary; - pub type __CTFontDescriptor; - pub type __CTFont; #[no_mangle] fn malloc(_: libc::c_ulong) -> *mut libc::c_void; #[no_mangle] fn xpc_debugger_api_misuse_info() -> *const libc::c_char; - #[no_mangle] - fn XeTeXFontInst_initialize( - self_0: *mut XeTeXFontInst, - pathname: *const libc::c_char, - index: libc::c_int, - status: *mut libc::c_int, - ); - #[no_mangle] - fn XeTeXFontInst_base_ctor( - self_0: *mut XeTeXFontInst, - pathname: *const libc::c_char, - index: libc::c_int, - pointSize: libc::c_float, - status: *mut libc::c_int, - ); - #[no_mangle] - fn getFileNameFromCTFont(ctFontRef: CTFontRef, index: *mut uint32_t) -> *mut libc::c_char; - #[no_mangle] - static kCFTypeArrayCallBacks: CFArrayCallBacks; - #[no_mangle] - static kCFTypeDictionaryKeyCallBacks: CFDictionaryKeyCallBacks; - #[no_mangle] - static kCTFontCascadeListAttribute: CFStringRef; - #[no_mangle] - static kCFTypeDictionaryValueCallBacks: CFDictionaryValueCallBacks; - #[no_mangle] - fn CFArrayCreate( - allocator: CFAllocatorRef, - values: *mut *const libc::c_void, - numValues: CFIndex, - callBacks: *const CFArrayCallBacks, - ) -> CFArrayRef; - #[no_mangle] - fn CTFontCreateWithFontDescriptor( - descriptor: CTFontDescriptorRef, - size: CGFloat, - matrix: *const CGAffineTransform, - ) -> CTFontRef; - #[no_mangle] - fn CFDictionaryCreate( - allocator: CFAllocatorRef, - keys: *mut *const libc::c_void, - values: *mut *const libc::c_void, - numValues: CFIndex, - keyCallBacks: *const CFDictionaryKeyCallBacks, - valueCallBacks: *const CFDictionaryValueCallBacks, - ) -> CFDictionaryRef; - #[no_mangle] - fn CTFontDescriptorCreateCopyWithAttributes( - original: CTFontDescriptorRef, - attributes: CFDictionaryRef, - ) -> CTFontDescriptorRef; - #[no_mangle] - fn CFRelease(cf: CFTypeRef); -} -pub type uint32_t = libc::c_uint; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct CGAffineTransform { - pub a: CGFloat, - pub b: CGFloat, - pub c: CGFloat, - pub d: CGFloat, - pub tx: CGFloat, - pub ty: CGFloat, } -pub type CGFloat = libc::c_double; -pub type CFAllocatorRef = *const __CFAllocator; + pub type UniChar = UInt16; pub type UInt16 = libc::c_ushort; pub type Boolean = libc::c_uchar; -pub type CFHashCode = libc::c_ulong; -pub type CFIndex = libc::c_long; -pub type CFTypeRef = *const libc::c_void; -pub type CFStringRef = *const __CFString; -pub type CFArrayRetainCallBack = - Option *const libc::c_void>; -pub type CFArrayReleaseCallBack = - Option ()>; -pub type CFArrayCopyDescriptionCallBack = - Option CFStringRef>; -pub type CFArrayEqualCallBack = - Option Boolean>; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct CFArrayCallBacks { - pub version: CFIndex, - pub retain: CFArrayRetainCallBack, - pub release: CFArrayReleaseCallBack, - pub copyDescription: CFArrayCopyDescriptionCallBack, - pub equal: CFArrayEqualCallBack, -} -pub type CFArrayRef = *const __CFArray; -pub type CFDictionaryRetainCallBack = - Option *const libc::c_void>; -pub type CFDictionaryReleaseCallBack = - Option ()>; -pub type CFDictionaryCopyDescriptionCallBack = - Option CFStringRef>; -pub type CFDictionaryEqualCallBack = - Option Boolean>; -pub type CFDictionaryHashCallBack = - Option CFHashCode>; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct CFDictionaryKeyCallBacks { - pub version: CFIndex, - pub retain: CFDictionaryRetainCallBack, - pub release: CFDictionaryReleaseCallBack, - pub copyDescription: CFDictionaryCopyDescriptionCallBack, - pub equal: CFDictionaryEqualCallBack, - pub hash: CFDictionaryHashCallBack, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct CFDictionaryValueCallBacks { - pub version: CFIndex, - pub retain: CFDictionaryRetainCallBack, - pub release: CFDictionaryReleaseCallBack, - pub copyDescription: CFDictionaryCopyDescriptionCallBack, - pub equal: CFDictionaryEqualCallBack, -} -pub type CFDictionaryRef = *const __CFDictionary; -pub type CTFontDescriptorRef = *const __CTFontDescriptor; -pub type CTFontRef = *const __CTFont; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontInst { - pub m_unitsPerEM: libc::c_ushort, - pub m_pointSize: libc::c_float, - pub m_ascent: libc::c_float, - pub m_descent: libc::c_float, - pub m_capHeight: libc::c_float, - pub m_xHeight: libc::c_float, - pub m_italicAngle: libc::c_float, - pub m_vertical: bool, - pub m_filename: *mut libc::c_char, - pub m_index: uint32_t, - pub m_ftFace: freetype_sys::FT_Face, - pub m_backingData: *mut freetype_sys::FT_Byte, - pub m_backingData2: *mut freetype_sys::FT_Byte, - pub m_hbFont: *mut hb_font_t, - pub m_subdtor: Option ()>, -} /* ***************************************************************************\ Part of the XeTeX typesetting system Copyright (c) 1994-2008 by SIL International @@ -205,7 +74,7 @@ authorization from the copyright holders. * created by: Jonathan Kew */ //#include -#[derive(Copy, Clone)] +#[derive(Clone)] #[repr(C)] pub struct XeTeXFontInst_Mac { pub super_: XeTeXFontInst, @@ -252,7 +121,7 @@ authorization from the copyright holders. * created by: Jonathan Kew */ #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_Mac_dtor(mut self_0: *mut XeTeXFontInst) { +pub unsafe fn XeTeXFontInst_Mac_dtor(mut self_0: *mut XeTeXFontInst) { let mut real_self: *mut XeTeXFontInst_Mac = self_0 as *mut XeTeXFontInst_Mac; if !(*real_self).m_descriptor.is_null() { CFRelease((*real_self).m_descriptor as CFTypeRef); @@ -262,7 +131,7 @@ pub unsafe extern "C" fn XeTeXFontInst_Mac_dtor(mut self_0: *mut XeTeXFontInst) }; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_Mac_initialize( +pub unsafe fn XeTeXFontInst_Mac_initialize( mut self_0: *mut XeTeXFontInst_Mac, mut status: *mut libc::c_int, ) { @@ -297,19 +166,19 @@ pub unsafe extern "C" fn XeTeXFontInst_Mac_initialize( CFRelease(attributes as CFTypeRef); (*self_0).m_fontRef = CTFontCreateWithFontDescriptor( (*self_0).m_descriptor, - (*self_0).super_.m_pointSize as libc::c_double * 72.0f64 / 72.27f64, + (*self_0).super_.m_pointSize as f64 * 72.0f64 / 72.27f64, 0 as *const CGAffineTransform, ); if !(*self_0).m_fontRef.is_null() { let mut pathname: *mut libc::c_char = 0 as *mut libc::c_char; - let mut index: uint32_t = 0; + let mut index: u32 = 0; pathname = getFileNameFromCTFont((*self_0).m_fontRef, &mut index); - XeTeXFontInst_initialize( - &mut (*self_0).super_, - pathname, - index as libc::c_int, - status, - ); + if let Err(e) = (*self_0) + .super_ + .init(CStr::from_ptr(pathname), index as libc::c_int) + { + *status = e; + } } else { *status = 1i32; CFRelease((*self_0).m_descriptor as CFTypeRef); @@ -317,21 +186,15 @@ pub unsafe extern "C" fn XeTeXFontInst_Mac_initialize( }; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_Mac_ctor( +pub unsafe fn XeTeXFontInst_Mac_ctor( mut self_0: *mut XeTeXFontInst_Mac, mut descriptor: CTFontDescriptorRef, mut pointSize: libc::c_float, mut status: *mut libc::c_int, ) { - XeTeXFontInst_base_ctor( - &mut (*self_0).super_, - 0 as *const libc::c_char, - 0i32, - pointSize, - status, - ); + (*self_0).super_ = XeTeXFontInst::new(None, 0, pointSize, status); (*self_0).super_.m_subdtor = - Some(XeTeXFontInst_Mac_dtor as unsafe extern "C" fn(_: *mut XeTeXFontInst) -> ()); + Some(XeTeXFontInst_Mac_dtor as unsafe fn(_: *mut XeTeXFontInst) -> ()); (*self_0).m_descriptor = descriptor; (*self_0).m_fontRef = 0 as CTFontRef; XeTeXFontInst_Mac_initialize(self_0, status); @@ -350,7 +213,7 @@ public: }; */ #[no_mangle] -pub unsafe extern "C" fn XeTeXFontInst_Mac_create( +pub unsafe fn XeTeXFontInst_Mac_create( mut descriptor: CTFontDescriptorRef, mut pointSize: libc::c_float, mut status: *mut libc::c_int, diff --git a/engine/src/xetex_font_manager.rs b/engine/src/xetex_font_manager.rs index f6fbdb7f5..c154a3a48 100644 --- a/engine/src/xetex_font_manager.rs +++ b/engine/src/xetex_font_manager.rs @@ -1,33 +1,70 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] -#[cfg(not(target_os = "macos"))] -#[path = "xetex_font_manager_fontconfig.rs"] -pub mod imp; +cfg_if::cfg_if! { + if #[cfg(target_os = "macos")] { + #[path = "xetex_font_manager_coretext.rs"] + pub mod imp; + use imp::XeTeXFontMgr_Mac_create; + use crate::xetex_aatfont::cf_prelude::CTFontDescriptorRef; + pub type PlatformFontRef = CTFontDescriptorRef; -#[cfg(target_os = "macos")] -#[path = "xetex_font_manager_coretext.rs"] -pub mod imp; + #[derive(Copy, Clone)] + #[repr(C)] + pub struct XeTeXFontMgr_Mac { + pub super_: XeTeXFontMgr, + } + + } else { + #[path = "xetex_font_manager_fontconfig.rs"] + pub mod imp; + use imp::{FcPattern, XeTeXFontMgr_FC, XeTeXFontMgr_FC_create}; + pub type PlatformFontRef = *mut FcPattern; + + #[derive(Copy, Clone)] + #[repr(C)] + pub struct _FcFontSet { + pub nfont: libc::c_int, + pub sfont: libc::c_int, + pub fonts: *mut *mut FcPattern, + } + + pub type FcFontSet = _FcFontSet; + + } +} + +use crate::xetex_font_info::freetype_missing::{TT_Header, TT_Postscript}; +use crate::xetex_font_info::{ + XeTeXFontInst, XeTeXFontInst_getFontTableFT, XeTeXFontInst_getHbFont, +}; +use freetype::freetype::FT_Sfnt_Tag; +use freetype::tt_os2::TT_OS2; use std::ffi::CString; use std::ptr::NonNull; use crate::core_memory::xmalloc; -use crate::xetex_layout_interface::collection_types::*; +use crate::xetex_ext::Fix2D; +use crate::xetex_layout_engine::collection_types::*; -#[cfg(target_os = "macos")] -use crate::xetex_layout_interface::__CTFontDescriptor; +use harfbuzz_sys::{hb_face_t, hb_font_get_face, hb_font_t, hb_ot_layout_get_size_params}; -use harfbuzz_sys::{hb_font_t, hb_face_t, hb_font_get_face, hb_ot_layout_get_size_params}; -use freetype::freetype_sys; +use std::ffi::CStr; + +use crate::xetex_layout_engine::{createFont, deleteFont}; extern "C" { + /// This is never defined, it just serves as C void, really. + /// Needs to be cast to XeTeXFontInst pub type XeTeXFont_rec; #[no_mangle] fn tan(_: libc::c_double) -> libc::c_double; @@ -49,10 +86,6 @@ extern "C" { #[no_mangle] fn _tt_abort(format: *const libc::c_char, _: ...) -> !; #[no_mangle] - fn createFont(fontRef: PlatformFontRef, pointSize: Fixed) -> XeTeXFont; - #[no_mangle] - fn deleteFont(font: XeTeXFont); - #[no_mangle] static mut loaded_font_design_size: Fixed; #[no_mangle] fn get_tracing_fonts_state() -> libc::c_int; @@ -64,21 +97,8 @@ extern "C" { fn print_char(c: libc::c_int); #[no_mangle] fn print_nl(s: libc::c_int); - #[no_mangle] - fn Fix2D(f: Fixed) -> libc::c_double; - #[no_mangle] - #[cfg(not(target_os = "macos"))] - fn XeTeXFontMgr_FC_create() -> *mut XeTeXFontMgr_FC; - #[no_mangle] - #[cfg(target_os = "macos")] - fn XeTeXFontMgr_Mac_create() -> *mut XeTeXFontMgr_Mac; - fn XeTeXFontInst_getHbFont(self_0: *const XeTeXFontInst) -> *mut hb_font_t; - #[no_mangle] - fn XeTeXFontInst_getFontTableFT( - self_0: *const XeTeXFontInst, - tag: freetype_sys::FT_Sfnt_Tag, - ) -> *mut libc::c_void; } + pub type size_t = usize; pub type int16_t = i16; pub type int32_t = i32; @@ -86,31 +106,8 @@ pub type uint16_t = u16; pub type uint32_t = u32; pub type ssize_t = isize; -#[cfg(not(target_os = "macos"))] -use imp::FcPattern; - -#[cfg(not(target_os = "macos"))] -#[derive(Copy, Clone)] -#[repr(C)] -pub struct _FcFontSet { - pub nfont: libc::c_int, - pub sfont: libc::c_int, - pub fonts: *mut *mut FcPattern, -} - -#[cfg(not(target_os = "macos"))] -pub type FcFontSet = _FcFontSet; - pub type Fixed = i32; -#[cfg(not(target_os = "macos"))] -pub type PlatformFontRef = *mut FcPattern; - -#[cfg(target_os = "macos")] -pub type PlatformFontRef = CTFontDescriptorRef; -#[cfg(target_os = "macos")] -pub type CTFontDescriptorRef = *const __CTFontDescriptor; -pub type XeTeXFont = *mut XeTeXFont_rec; /* ***************************************************************************\ Part of the XeTeX typesetting system Copyright (c) 1994-2008 by SIL International @@ -190,24 +187,21 @@ pub struct XeTeXFontMgrNameCollection { pub m_psName: *mut CppStdString, pub m_subFamily: *mut CppStdString, } + #[derive(Copy, Clone)] #[repr(C)] pub struct XeTeXFontMgr { - pub m_subdtor: Option ()>, - pub m_memfnInitialize: Option ()>, - pub m_memfnTerminate: Option ()>, - pub m_memfnGetPlatformFontDesc: Option< - unsafe extern "C" fn(_: *const XeTeXFontMgr, _: PlatformFontRef) -> *mut libc::c_char, - >, + pub m_subdtor: Option ()>, + pub m_memfnInitialize: Option ()>, + pub m_memfnTerminate: Option ()>, + pub m_memfnGetPlatformFontDesc: + Option *mut libc::c_char>, pub m_memfnGetOpSizeRecAndStyleFlags: - Option ()>, + Option ()>, pub m_memfnSearchForHostPlatformFonts: - Option ()>, + Option ()>, pub m_memfnReadNames: Option< - unsafe extern "C" fn( - _: *mut XeTeXFontMgr, - _: PlatformFontRef, - ) -> *mut XeTeXFontMgrNameCollection, + unsafe fn(_: *mut XeTeXFontMgr, _: PlatformFontRef) -> *mut XeTeXFontMgrNameCollection, >, pub m_nameToFont: *mut CppStdMap>, pub m_nameToFamily: *mut CppStdMap>, @@ -216,82 +210,20 @@ pub struct XeTeXFontMgr { // maps PS name (as used in .xdv) to font record } -#[cfg(not(target_os = "macos"))] -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontMgr_FC { - pub super_: XeTeXFontMgr, - pub allFonts: *mut FcFontSet, - pub cachedAll: bool, +/// Used to set harfbuzz's shaper list in loadOTFont, and by extension eventually layoutChars. +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +pub enum ShaperRequest { + None, + /// Don't use harfbuzz at all, use AAT if possible. + AAT, + /// Use harfbuzz ot shaper + OpenType, + /// See layoutChars + Graphite, } -#[cfg(target_os = "macos")] -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontMgr_Mac { - pub super_: XeTeXFontMgr, -} -/* ***************************************************************************\ - Part of the XeTeX typesetting system - Copyright (c) 1994-2008 by SIL International - Copyright (c) 2009, 2011 by Jonathan Kew - - SIL Author(s): Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ -/* - * file name: XeTeXFontInst.h - * - * created on: 2005-10-22 - * created by: Jonathan Kew - * - * originally based on PortableFontInstance.h from ICU - */ -// create specific subclasses for each supported platform -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontInst { - pub m_unitsPerEM: libc::c_ushort, - pub m_pointSize: libc::c_float, - pub m_ascent: libc::c_float, - pub m_descent: libc::c_float, - pub m_capHeight: libc::c_float, - pub m_xHeight: libc::c_float, - pub m_italicAngle: libc::c_float, - pub m_vertical: bool, - pub m_filename: *mut libc::c_char, - pub m_index: uint32_t, - pub m_ftFace: freetype_sys::FT_Face, - pub m_backingData: *mut freetype_sys::FT_Byte, - pub m_backingData2: *mut freetype_sys::FT_Byte, - pub m_hbFont: *mut hb_font_t, - pub m_subdtor: Option ()>, -} #[inline] -unsafe extern "C" fn XeTeXFontMgrFamily_create() -> *mut XeTeXFontMgrFamily { +unsafe fn XeTeXFontMgrFamily_create() -> *mut XeTeXFontMgrFamily { let mut self_0: *mut XeTeXFontMgrFamily = malloc(::std::mem::size_of::() as libc::c_ulong) as *mut XeTeXFontMgrFamily; /* default to 10bp */ @@ -304,8 +236,9 @@ unsafe extern "C" fn XeTeXFontMgrFamily_create() -> *mut XeTeXFontMgrFamily { (*self_0).styles = CppStdMap_create(); return self_0; } + #[inline] -unsafe extern "C" fn XeTeXFontMgrFont_create(mut ref_0: PlatformFontRef) -> *mut XeTeXFontMgrFont { +unsafe fn XeTeXFontMgrFont_create(mut ref_0: PlatformFontRef) -> *mut XeTeXFontMgrFont { let mut self_0: *mut XeTeXFontMgrFont = malloc(::std::mem::size_of::() as libc::c_ulong) as *mut XeTeXFontMgrFont; (*self_0).m_fullName = 0 as *mut CppStdString; @@ -325,28 +258,28 @@ unsafe extern "C" fn XeTeXFontMgrFont_create(mut ref_0: PlatformFontRef) -> *mut return self_0; } #[inline] -unsafe extern "C" fn XeTeXFontMgr_initialize(mut self_0: *mut XeTeXFontMgr) { +unsafe fn XeTeXFontMgr_initialize(mut self_0: *mut XeTeXFontMgr) { (*self_0) .m_memfnInitialize .expect("non-null function pointer")(self_0); } #[inline] -unsafe extern "C" fn XeTeXFontMgr_terminate(mut self_0: *mut XeTeXFontMgr) { +unsafe fn XeTeXFontMgr_terminate(mut self_0: *mut XeTeXFontMgr) { (*self_0) .m_memfnTerminate .expect("non-null function pointer")(self_0); } #[inline] -unsafe extern "C" fn XeTeXFontMgr_getPlatformFontDesc( +unsafe fn XeTeXFontMgr_getPlatformFontDesc( mut self_0: *const XeTeXFontMgr, - mut font: PlatformFontRef, + mut fontRef: PlatformFontRef, ) -> *mut libc::c_char { return (*self_0) .m_memfnGetPlatformFontDesc - .expect("non-null function pointer")(self_0, font); + .expect("non-null function pointer")(self_0, fontRef); } #[inline] -unsafe extern "C" fn XeTeXFontMgr_searchForHostPlatformFonts( +unsafe fn XeTeXFontMgr_searchForHostPlatformFonts( mut self_0: *mut XeTeXFontMgr, mut name: *const libc::c_char, ) { @@ -355,7 +288,7 @@ unsafe extern "C" fn XeTeXFontMgr_searchForHostPlatformFonts( .expect("non-null function pointer")(self_0, name); } #[inline] -unsafe extern "C" fn XeTeXFontMgr_getOpSizeRecAndStyleFlags( +unsafe fn XeTeXFontMgr_getOpSizeRecAndStyleFlags( mut self_0: *mut XeTeXFontMgr, mut theFont: *mut XeTeXFontMgrFont, ) { @@ -398,40 +331,38 @@ authorization from the copyright holders. #[no_mangle] pub static mut XeTeXFontMgr_sFontManager: *mut XeTeXFontMgr = 0 as *const XeTeXFontMgr as *mut XeTeXFontMgr; -#[no_mangle] -pub static mut XeTeXFontMgr_sReqEngine: libc::c_char = 0i32 as libc::c_char; /* use our own fmax function because it seems to be missing on certain platforms (solaris2.9, at least) */ #[inline] -unsafe extern "C" fn my_fmax(mut x: libc::c_double, mut y: libc::c_double) -> libc::c_double { +unsafe fn my_fmax(mut x: libc::c_double, mut y: libc::c_double) -> libc::c_double { return if x > y { x } else { y }; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_GetFontManager() -> *mut XeTeXFontMgr { - #[cfg(not(target_os = "macos"))] - { - if XeTeXFontMgr_sFontManager.is_null() { - XeTeXFontMgr_sFontManager = &mut (*(XeTeXFontMgr_FC_create - as unsafe extern "C" fn() -> *mut XeTeXFontMgr_FC)( - )) - .super_; - XeTeXFontMgr_initialize(XeTeXFontMgr_sFontManager); - } - } - #[cfg(target_os = "macos")] - { - if XeTeXFontMgr_sFontManager.is_null() { - XeTeXFontMgr_sFontManager = &mut (*(XeTeXFontMgr_Mac_create - as unsafe extern "C" fn() -> *mut XeTeXFontMgr_Mac)( - )) - .super_; - XeTeXFontMgr_initialize(XeTeXFontMgr_sFontManager); +pub unsafe fn XeTeXFontMgr_GetFontManager() -> *mut XeTeXFontMgr { + cfg_if::cfg_if! { + if #[cfg(target_os = "macos")] { + if XeTeXFontMgr_sFontManager.is_null() { + XeTeXFontMgr_sFontManager = &mut (*(XeTeXFontMgr_Mac_create + as unsafe fn() -> *mut XeTeXFontMgr_Mac)( + )) + .super_; + XeTeXFontMgr_initialize(XeTeXFontMgr_sFontManager); + } + } else { + if XeTeXFontMgr_sFontManager.is_null() { + XeTeXFontMgr_sFontManager = &mut (*(XeTeXFontMgr_FC_create + as unsafe fn() -> *mut XeTeXFontMgr_FC)( + )) + .super_; + XeTeXFontMgr_initialize(XeTeXFontMgr_sFontManager); + } } } return XeTeXFontMgr_sFontManager; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Terminate() { +pub unsafe fn XeTeXFontMgr_Terminate() { if !XeTeXFontMgr_sFontManager.is_null() { XeTeXFontMgr_terminate(XeTeXFontMgr_sFontManager); // we don't actually deallocate the manager, just ask it to clean up @@ -440,32 +371,19 @@ pub unsafe extern "C" fn XeTeXFontMgr_Terminate() { }; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Destroy() { +pub unsafe fn XeTeXFontMgr_Destroy() { // Here we actually fully destroy the font manager. if !XeTeXFontMgr_sFontManager.is_null() { XeTeXFontMgr_delete(XeTeXFontMgr_sFontManager); XeTeXFontMgr_sFontManager = 0 as *mut XeTeXFontMgr }; } -#[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_getReqEngine( - mut self_0: *const XeTeXFontMgr, -) -> libc::c_char { - // return the requested rendering technology for the most recent findFont - // or 0 if no specific technology was requested - return XeTeXFontMgr_sReqEngine; -} -#[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_setReqEngine( - mut self_0: *const XeTeXFontMgr, - mut reqEngine: libc::c_char, -) { - XeTeXFontMgr_sReqEngine = reqEngine; -} + // above are singleton operation. // ///////////// + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_delete(mut self_0: *mut XeTeXFontMgr) { +pub(self) unsafe fn XeTeXFontMgr_delete(mut self_0: *mut XeTeXFontMgr) { if self_0.is_null() { return; } @@ -478,12 +396,14 @@ pub unsafe extern "C" fn XeTeXFontMgr_delete(mut self_0: *mut XeTeXFontMgr) { CppStdMap_delete((*self_0).m_psNameToFont); free(self_0 as *mut libc::c_void); } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_findFont( +pub unsafe fn XeTeXFontMgr_findFont( mut self_0: *mut XeTeXFontMgr, - mut name: *const libc::c_char, - mut variant: *mut libc::c_char, + mut name: &CStr, + mut variant: Option<&mut String>, mut ptSize: libc::c_double, + shaperRequest: &mut Option, ) -> PlatformFontRef { // 1st arg is name as specified by user (C string, UTF-8) // 2nd is /B/I/AAT/OT/ICU/GR/S=## qualifiers @@ -492,7 +412,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_findFont( // 3. try as PostScript name // 4. try name as family with "Regular/Plain/Normal" style // apply style qualifiers and optical sizing if present - // SIDE EFFECT: sets sReqEngine to 'A' or 'O' or 'G' if appropriate, + // SIDE EFFECT: sets shaperRequest to 'A' or 'O' or 'G' if appropriate, // else clears it to 0 // SIDE EFFECT: updates TeX variables /nameoffile/ and /namelength/, // to match the actual font found @@ -500,7 +420,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_findFont( // ptSize is in TeX points, or negative for 'scaled' factor // "variant" string will be shortened (in-place) by removal of /B and /I if present let mut nameStr = CString::default(); - CppStdString_assign_from_const_char_ptr(&mut nameStr, name); + CppStdString_assign_from_const_char_ptr(&mut nameStr, name.as_ptr()); let mut font: *mut XeTeXFontMgrFont = 0 as *mut XeTeXFontMgrFont; let mut dsize: libc::c_int = 100i32; loaded_font_design_size = 655360i64 as Fixed; @@ -604,140 +524,96 @@ pub unsafe extern "C" fn XeTeXFontMgr_findFont( let mut parent: *mut XeTeXFontMgrFamily = (*font).parent; // if there are variant requests, try to apply them // and delete B, I, and S=... codes from the string, just retain /engine option - XeTeXFontMgr_sReqEngine = 0i32 as libc::c_char; + *shaperRequest = None; let mut reqBold: bool = 0i32 != 0; let mut reqItal: bool = 0i32 != 0; - if !variant.is_null() { - let mut varString: *mut CppStdString = CppStdString_create(); - let mut cp: *mut libc::c_char = variant; - while *cp != 0 { - if strncmp( - cp, - b"AAT\x00" as *const u8 as *const libc::c_char, - 3i32 as libc::c_ulong, - ) == 0i32 - { - XeTeXFontMgr_sReqEngine = 'A' as i32 as libc::c_char; - cp = cp.offset(3); - if CppStdString_length(varString) > 0 - && CppStdString_last(varString) as libc::c_int != '/' as i32 - { - CppStdString_append_const_char_ptr( - varString, - b"/\x00" as *const u8 as *const libc::c_char, - ); + if let Some(variant_string) = variant { + let mut varString = String::new(); + let mut slice = &variant_string[..]; + while !slice.is_empty() { + if slice.starts_with("AAT") { + *shaperRequest = Some(ShaperRequest::AAT); + slice = &slice[3..]; + if !varString.is_empty() && varString.chars().last() != Some('/') { + varString.push('/'); } - CppStdString_append_const_char_ptr( - varString, - b"AAT\x00" as *const u8 as *const libc::c_char, - ); - } else if strncmp( - cp, - b"ICU\x00" as *const u8 as *const libc::c_char, - 3i32 as libc::c_ulong, - ) == 0i32 - { + varString.push_str("AAT"); + } else if slice.starts_with("ICU") { // for backword compatability - XeTeXFontMgr_sReqEngine = 'O' as i32 as libc::c_char; - cp = cp.offset(3); - if CppStdString_length(varString) > 0 - && CppStdString_last(varString) as libc::c_int != '/' as i32 - { - CppStdString_append_const_char_ptr( - varString, - b"/\x00" as *const u8 as *const libc::c_char, - ); + *shaperRequest = Some(ShaperRequest::OpenType); + slice = &slice[3..]; + if !varString.is_empty() && varString.chars().last() != Some('/') { + varString.push('/'); } - CppStdString_append_const_char_ptr( - varString, - b"OT\x00" as *const u8 as *const libc::c_char, - ); - } else if strncmp( - cp, - b"OT\x00" as *const u8 as *const libc::c_char, - 2i32 as libc::c_ulong, - ) == 0i32 - { - XeTeXFontMgr_sReqEngine = 'O' as i32 as libc::c_char; - cp = cp.offset(2); - if CppStdString_length(varString) > 0 - && CppStdString_last(varString) as libc::c_int != '/' as i32 - { - CppStdString_append_const_char_ptr( - varString, - b"/\x00" as *const u8 as *const libc::c_char, - ); + varString.push_str("OT"); + } else if slice.starts_with("OT") { + *shaperRequest = Some(ShaperRequest::OpenType); + slice = &slice[2..]; + if !varString.is_empty() && varString.chars().last() != Some('/') { + varString.push('/'); } - CppStdString_append_const_char_ptr( - varString, - b"OT\x00" as *const u8 as *const libc::c_char, - ); - } else if strncmp( - cp, - b"GR\x00" as *const u8 as *const libc::c_char, - 2i32 as libc::c_ulong, - ) == 0i32 - { - XeTeXFontMgr_sReqEngine = 'G' as i32 as libc::c_char; - cp = cp.offset(2); - if CppStdString_length(varString) > 0 - && CppStdString_last(varString) as libc::c_int != '/' as i32 - { - CppStdString_append_const_char_ptr( - varString, - b"/\x00" as *const u8 as *const libc::c_char, - ); + varString.push_str("OT"); + } else if slice.starts_with("GR") { + *shaperRequest = Some(ShaperRequest::Graphite); + slice = &slice[2..]; + if !varString.is_empty() && varString.chars().last() != Some('/') { + varString.push('/'); } - CppStdString_append_const_char_ptr( - varString, - b"GR\x00" as *const u8 as *const libc::c_char, - ); - } else if *cp as libc::c_int == 'S' as i32 { - cp = cp.offset(1); - if *cp as libc::c_int == '=' as i32 { - cp = cp.offset(1) + varString.push_str("GR"); + } else if slice.starts_with("S") { + slice = &slice[1..]; + if slice.starts_with("=") { + slice = &slice[1..]; } ptSize = 0.0f64; - while *cp as libc::c_int >= '0' as i32 && *cp as libc::c_int <= '9' as i32 { - ptSize = ptSize * 10i32 as libc::c_double - + *cp as libc::c_int as libc::c_double - - '0' as i32 as libc::c_double; - cp = cp.offset(1) - } - if *cp as libc::c_int == '.' as i32 { - let mut dec: libc::c_double = 1.0f64; - cp = cp.offset(1); - while *cp as libc::c_int >= '0' as i32 && *cp as libc::c_int <= '9' as i32 { - dec = dec * 10.0f64; - ptSize = ptSize + (*cp as libc::c_int - '0' as i32) as libc::c_double / dec; - cp = cp.offset(1) - } + let (count, pointSize) = slice + .bytes() + .take_while(|&b| b >= b'0' && b <= b'9') + .fold((0, ptSize), |(count, pointSize), b| { + let new = pointSize + 10. + ((b - b'0') as i32 as f64); + (count + 1, new) + }); + ptSize = pointSize; + slice = &slice[count..]; + + if slice.bytes().nth(0) == Some(b'.') { + slice = &slice[1..]; + let (count, _, pointSize) = slice + .bytes() + .take_while(|&b| b >= b'0' && b <= b'9') + .fold((0, 1.0f64, ptSize), |(count, dec, pointSize), b| { + let dec = dec * 10.; + let new = pointSize + (b - b'0') as libc::c_double / dec; + (count + 1, dec, new) + }); + slice = &slice[count..]; + ptSize = pointSize; } } else { - loop /* if the code is "B" or "I", we skip putting it in varString */ - { - if *cp as libc::c_int == 'B' as i32 { - reqBold = 1i32 != 0; - cp = cp.offset(1) + let mut count = 0; + for byte in slice.bytes() { + if byte == b'B' { + reqBold = false; + slice = &slice[1..]; } else { - if !(*cp as libc::c_int == 'I' as i32) { + if byte != b'I' { break; } - reqItal = 1i32 != 0; - cp = cp.offset(1) + reqItal = false; } + count += 1; } + slice = &slice[count..]; } - while *cp as libc::c_int != 0 && *cp as libc::c_int != '/' as i32 { - cp = cp.offset(1) + while !slice.is_empty() && slice.bytes().nth(0) != Some(b'/') { + slice = &slice[1..]; } - if *cp as libc::c_int == '/' as i32 { - cp = cp.offset(1) + if slice.bytes().nth(0) == Some(b'/') { + slice = &slice[1..]; } } - strcpy(variant, CppStdString_cstr(varString)); - CppStdString_delete(varString); + *variant_string = varString; if reqItal { let mut bestMatch: *mut XeTeXFontMgrFont = font; if ((*font).slant as libc::c_int) < (*parent).maxSlant as libc::c_int { @@ -917,14 +793,15 @@ pub unsafe extern "C" fn XeTeXFontMgr_findFont( } return (*font).fontRef; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_getFullName( +pub unsafe fn XeTeXFontMgr_getFullName( mut self_0: *const XeTeXFontMgr, - mut font: PlatformFontRef, + mut fontRef: PlatformFontRef, ) -> *const libc::c_char { // return the full name of the font, suitable for use in XeTeX source // without requiring style qualifiers - let font_ptr = if let Some(font_ptr) = (*(*self_0).m_platformRefToFont).get(&font).cloned() { + let font_ptr = if let Some(font_ptr) = (*(*self_0).m_platformRefToFont).get(&fontRef).cloned() { font_ptr } else { _tt_abort( @@ -939,8 +816,9 @@ pub unsafe extern "C" fn XeTeXFontMgr_getFullName( } return CppStdString_cstr((*font_ptr).m_psName); } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_weightAndWidthDiff( +pub(self) unsafe fn XeTeXFontMgr_weightAndWidthDiff( mut self_0: *const XeTeXFontMgr, mut a: *const XeTeXFontMgrFont, mut b: *const XeTeXFontMgrFont, @@ -962,8 +840,9 @@ pub unsafe extern "C" fn XeTeXFontMgr_weightAndWidthDiff( return (labs(((*a).weight as libc::c_int - (*b).weight as libc::c_int) as libc::c_long) + widDiff as libc::c_long) as libc::c_int; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_styleDiff( +pub(self) unsafe fn XeTeXFontMgr_styleDiff( mut self_0: *const XeTeXFontMgr, mut a: *const XeTeXFontMgrFont, mut wt: libc::c_int, @@ -980,8 +859,9 @@ pub unsafe extern "C" fn XeTeXFontMgr_styleDiff( + labs(((*a).weight as libc::c_int - wt) as libc::c_long) + widDiff as libc::c_long) as libc::c_int; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_bestMatchFromFamily( +pub(self) unsafe fn XeTeXFontMgr_bestMatchFromFamily( mut self_0: *const XeTeXFontMgr, mut fam: *const XeTeXFontMgrFamily, mut wt: libc::c_int, @@ -999,12 +879,13 @@ pub unsafe extern "C" fn XeTeXFontMgr_bestMatchFromFamily( } return bestMatch; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_getOpSize( +pub(self) unsafe fn XeTeXFontMgr_getOpSize( mut self_0: *mut XeTeXFontMgr, - mut font: XeTeXFont, + mut font: *mut XeTeXFontInst, ) -> *mut XeTeXFontMgrOpSizeRec { - let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font as *mut XeTeXFontInst); + let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font); if hbFont.is_null() { return 0 as *mut XeTeXFontMgrOpSizeRec; } @@ -1025,10 +906,11 @@ pub unsafe extern "C" fn XeTeXFontMgr_getOpSize( free(pSizeRec as *mut libc::c_void); return 0 as *mut XeTeXFontMgrOpSizeRec; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_getDesignSize( +pub unsafe fn XeTeXFontMgr_getDesignSize( mut self_0: *mut XeTeXFontMgr, - mut font: XeTeXFont, + mut font: *mut XeTeXFontInst, ) -> libc::c_double { let mut pSizeRec: *mut XeTeXFontMgrOpSizeRec = XeTeXFontMgr_getOpSize(self_0, font); if pSizeRec.is_null() { @@ -1038,15 +920,14 @@ pub unsafe extern "C" fn XeTeXFontMgr_getDesignSize( free(pSizeRec as *mut libc::c_void); return result; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_base_getOpSizeRecAndStyleFlags( +pub unsafe fn XeTeXFontMgr_base_getOpSizeRecAndStyleFlags( mut self_0: *mut XeTeXFontMgr, mut theFont: *mut XeTeXFontMgrFont, ) { - use crate::freetype_sys_patch::{FT_SFNT_HEAD, FT_SFNT_OS2, FT_SFNT_POST, TT_Header}; - use freetype::freetype_sys::{TT_OS2, TT_Postscript}; - let mut font: XeTeXFont = createFont((*theFont).fontRef, 655360i32); - let mut fontInst: *mut XeTeXFontInst = font as *mut XeTeXFontInst; + let mut font = createFont((*theFont).fontRef, 655360i32); + let mut fontInst = font; if !font.is_null() { let mut pSizeRec: *mut XeTeXFontMgrOpSizeRec = XeTeXFontMgr_getOpSize(self_0, font); if !pSizeRec.is_null() { @@ -1067,7 +948,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_base_getOpSizeRecAndStyleFlags( } } let mut os2Table: *const TT_OS2 = - XeTeXFontInst_getFontTableFT(fontInst, FT_SFNT_OS2) as *mut TT_OS2; + XeTeXFontInst_getFontTableFT(fontInst, FT_Sfnt_Tag::FT_SFNT_OS2) as *mut TT_OS2; if !os2Table.is_null() { (*theFont).weight = (*os2Table).usWeightClass; (*theFont).width = (*os2Table).usWidthClass; @@ -1077,7 +958,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_base_getOpSizeRecAndStyleFlags( (*theFont).isItalic = sel as libc::c_int & 1i32 << 0i32 != 0i32 } let mut headTable: *const TT_Header = - XeTeXFontInst_getFontTableFT(fontInst, FT_SFNT_HEAD) as *mut TT_Header; + XeTeXFontInst_getFontTableFT(fontInst, FT_Sfnt_Tag::FT_SFNT_HEAD) as *mut TT_Header; if !headTable.is_null() { let mut ms: uint16_t = (*headTable).Mac_Style; if ms as libc::c_int & 1i32 << 0i32 != 0i32 { @@ -1088,7 +969,8 @@ pub unsafe extern "C" fn XeTeXFontMgr_base_getOpSizeRecAndStyleFlags( } } let mut postTable: *const TT_Postscript = - XeTeXFontInst_getFontTableFT(fontInst, FT_SFNT_POST) as *const TT_Postscript; + XeTeXFontInst_getFontTableFT(fontInst, FT_Sfnt_Tag::FT_SFNT_POST) + as *const TT_Postscript; if !postTable.is_null() { (*theFont).slant = (1000i32 as libc::c_double * tan(Fix2D(-(*postTable).italicAngle as Fixed) * std::f64::consts::PI / 180.0f64)) @@ -1097,9 +979,10 @@ pub unsafe extern "C" fn XeTeXFontMgr_base_getOpSizeRecAndStyleFlags( deleteFont(font); }; } -// append a name but only if it's not already in the list + +/// append a name but only if it's not already in the list #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_appendToList( +pub(self) unsafe fn XeTeXFontMgr_appendToList( mut self_0: *mut XeTeXFontMgr, mut list: *mut CppStdListOfString, mut str: *const libc::c_char, @@ -1118,9 +1001,10 @@ pub unsafe extern "C" fn XeTeXFontMgr_appendToList( } (*list).push_back(CStr::from_ptr(str).to_owned()); } -// prepend a name, removing it from later in the list if present + +/// prepend a name, removing it from later in the list if present #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_prependToList( +pub(self) unsafe fn XeTeXFontMgr_prependToList( mut self_0: *mut XeTeXFontMgr, mut list: *mut CppStdListOfString, mut str: *const libc::c_char, @@ -1145,8 +1029,9 @@ pub unsafe extern "C" fn XeTeXFontMgr_prependToList( remove_first_occur(&mut *list, CStr::from_ptr(str)); (*list).push_front(CStr::from_ptr(str).to_owned()); } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_addToMaps( +pub(self) unsafe fn XeTeXFontMgr_addToMaps( mut self_0: *mut XeTeXFontMgr, mut platformFont: PlatformFontRef, mut names: *const XeTeXFontMgrNameCollection, @@ -1250,18 +1135,20 @@ pub unsafe extern "C" fn XeTeXFontMgr_addToMaps( */ } } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_base_terminate(mut self_0: *mut XeTeXFontMgr) {} +pub(self) unsafe fn XeTeXFontMgr_base_terminate(mut self_0: *mut XeTeXFontMgr) {} + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_base_ctor(mut self_0: *mut XeTeXFontMgr) { +pub(self) unsafe fn XeTeXFontMgr_base_ctor(mut self_0: *mut XeTeXFontMgr) { (*self_0).m_subdtor = None; /*abstract*/ (*self_0).m_memfnInitialize = None; /*abstract*/ (*self_0).m_memfnTerminate = - Some(XeTeXFontMgr_base_terminate as unsafe extern "C" fn(_: *mut XeTeXFontMgr) -> ()); /*abstract*/ + Some(XeTeXFontMgr_base_terminate as unsafe fn(_: *mut XeTeXFontMgr) -> ()); /*abstract*/ (*self_0).m_memfnGetPlatformFontDesc = None; (*self_0).m_memfnGetOpSizeRecAndStyleFlags = Some( XeTeXFontMgr_base_getOpSizeRecAndStyleFlags - as unsafe extern "C" fn(_: *mut XeTeXFontMgr, _: *mut XeTeXFontMgrFont) -> (), + as unsafe fn(_: *mut XeTeXFontMgr, _: *mut XeTeXFontMgrFont) -> (), ); (*self_0).m_memfnSearchForHostPlatformFonts = None; (*self_0).m_memfnReadNames = None; diff --git a/engine/src/xetex_font_manager_coretext.rs b/engine/src/xetex_font_manager_coretext.rs index 82e0ab52d..a1f41b737 100644 --- a/engine/src/xetex_font_manager_coretext.rs +++ b/engine/src/xetex_font_manager_coretext.rs @@ -9,29 +9,22 @@ unused_mut )] -use crate::xetex_layout_interface::collection_types::*; - -use std::ffi::CString; -use std::ptr::{self, NonNull}; - +use super::*; +use crate::xetex_layout_engine::collection_types::*; use objc::rc::autoreleasepool; use objc::{runtime::Object, Message}; use objc_foundation::{NSArray, NSEnumerator, NSString}; use objc_id::Shared; +use std::ffi::CString; +use std::ptr::{self, NonNull}; objc_foundation::object_struct!(NSAutoreleasePool); objc_foundation::object_struct!(NSFontManager); objc_foundation::object_struct!(NSFont); type id = *mut Object; +use crate::xetex_aatfont::cf_prelude::*; + extern "C" { - pub type __CFAllocator; - pub type __CFURL; - pub type __CTFontDescriptor; - pub type __CFString; - pub type __CFArray; - pub type __CFDictionary; - pub type __CFSet; - pub type __CTFont; #[no_mangle] fn free(_: *mut libc::c_void); #[no_mangle] @@ -44,236 +37,51 @@ extern "C" { fn strdup(_: *const libc::c_char) -> *mut libc::c_char; #[no_mangle] fn xpc_debugger_api_misuse_info() -> *const libc::c_char; - #[no_mangle] - fn XeTeXFontMgr_addToMaps( - self_0: *mut XeTeXFontMgr, - platformFont: PlatformFontRef, - names: *const XeTeXFontMgrNameCollection, - ); - #[no_mangle] - fn XeTeXFontMgr_appendToList( - self_0: *mut XeTeXFontMgr, - list: *mut CppStdListOfString, - str: *const libc::c_char, - ); - #[no_mangle] - fn XeTeXFontMgr_base_ctor(self_0: *mut XeTeXFontMgr); - /* ***************************************************************************\ - Part of the XeTeX typesetting system - Copyright (c) 1994-2008 by SIL International - Copyright (c) 2009 by Jonathan Kew - Copyright (c) 2012, 2013 by Jiang Jiang - - SIL Author(s): Jonathan Kew - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE - FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - Except as contained in this notice, the name of the copyright holders - shall not be used in advertising or otherwise to promote the sale, - use or other dealings in this Software without prior written - authorization from the copyright holders. - \****************************************************************************/ - #[no_mangle] - static kCTFontURLAttribute: CFStringRef; - #[no_mangle] - static kCTFontFamilyNameKey: CFStringRef; - #[no_mangle] - static kCTFontNameAttribute: CFStringRef; - #[no_mangle] - static kCTFontStyleNameKey: CFStringRef; - #[no_mangle] - static kCTFontDisplayNameAttribute: CFStringRef; - #[no_mangle] - static kCTFontFamilyNameAttribute: CFStringRef; - #[no_mangle] - static kCTFontFullNameKey: CFStringRef; - #[no_mangle] - static kCFTypeSetCallBacks: CFSetCallBacks; - #[no_mangle] - fn CFURLGetFileSystemRepresentation( - url: CFURLRef, - resolveAgainstBase: Boolean, - buffer: *mut UInt8, - maxBufLen: CFIndex, - ) -> Boolean; - #[no_mangle] - static kCFTypeDictionaryKeyCallBacks: CFDictionaryKeyCallBacks; - #[no_mangle] - static kCFTypeDictionaryValueCallBacks: CFDictionaryValueCallBacks; - #[no_mangle] - fn CFStringCreateWithCString( - alloc: CFAllocatorRef, - cStr: *const libc::c_char, - encoding: CFStringEncoding, - ) -> CFStringRef; - #[no_mangle] - fn CFSetCreate( - allocator: CFAllocatorRef, - values: *mut *const libc::c_void, - numValues: CFIndex, - callBacks: *const CFSetCallBacks, - ) -> CFSetRef; - #[no_mangle] - fn CTFontCreateWithFontDescriptor( - descriptor: CTFontDescriptorRef, - size: CGFloat, - matrix: *const CGAffineTransform, - ) -> CTFontRef; - #[no_mangle] - fn CFArrayGetCount(theArray: CFArrayRef) -> CFIndex; - #[no_mangle] - fn CFDictionaryCreate( - allocator: CFAllocatorRef, - keys: *mut *const libc::c_void, - values: *mut *const libc::c_void, - numValues: CFIndex, - keyCallBacks: *const CFDictionaryKeyCallBacks, - valueCallBacks: *const CFDictionaryValueCallBacks, - ) -> CFDictionaryRef; - #[no_mangle] - fn CTFontDescriptorCreateWithAttributes(attributes: CFDictionaryRef) -> CTFontDescriptorRef; - #[no_mangle] - fn CFArrayGetValueAtIndex(theArray: CFArrayRef, idx: CFIndex) -> *const libc::c_void; - #[no_mangle] - fn CTFontDescriptorCreateMatchingFontDescriptors( - descriptor: CTFontDescriptorRef, - mandatoryAttributes: CFSetRef, - ) -> CFArrayRef; - #[no_mangle] - static kCFAllocatorDefault: CFAllocatorRef; - #[no_mangle] - fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef; - #[no_mangle] - fn CTFontDescriptorCopyAttribute( - descriptor: CTFontDescriptorRef, - attribute: CFStringRef, - ) -> CFTypeRef; - #[no_mangle] - fn CFRetain(cf: CFTypeRef) -> CFTypeRef; - #[no_mangle] - fn CFRelease(cf: CFTypeRef); - #[no_mangle] - fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; - #[no_mangle] - fn CTFontCopyLocalizedName( - font: CTFontRef, - nameKey: CFStringRef, - actualLanguage: *mut CFStringRef, - ) -> CFStringRef; + +/* ***************************************************************************\ + Part of the XeTeX typesetting system + Copyright (c) 1994-2008 by SIL International + Copyright (c) 2009 by Jonathan Kew + Copyright (c) 2012, 2013 by Jiang Jiang + + SIL Author(s): Jonathan Kew + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the copyright holders +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in this Software without prior written +authorization from the copyright holders. +\****************************************************************************/ + } pub type __darwin_size_t = libc::c_ulong; pub type size_t = __darwin_size_t; pub type int16_t = libc::c_short; pub type uint16_t = libc::c_ushort; -pub type CFAllocatorRef = *const __CFAllocator; -pub type CFURLRef = *const __CFURL; -pub type CTFontDescriptorRef = *const __CTFontDescriptor; pub type UniChar = UInt16; pub type UInt16 = libc::c_ushort; pub type Boolean = libc::c_uchar; pub type UInt8 = libc::c_uchar; pub type UInt32 = libc::c_uint; -pub type CFHashCode = libc::c_ulong; -pub type CFIndex = libc::c_long; -pub type CFTypeRef = *const libc::c_void; -pub type CFStringRef = *const __CFString; -pub type CFArrayRef = *const __CFArray; -pub type CFDictionaryRetainCallBack = - Option *const libc::c_void>; -pub type CFDictionaryReleaseCallBack = - Option ()>; -pub type CFDictionaryCopyDescriptionCallBack = - Option CFStringRef>; -pub type CFDictionaryEqualCallBack = - Option Boolean>; -pub type CFDictionaryHashCallBack = - Option CFHashCode>; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct CFDictionaryKeyCallBacks { - pub version: CFIndex, - pub retain: CFDictionaryRetainCallBack, - pub release: CFDictionaryReleaseCallBack, - pub copyDescription: CFDictionaryCopyDescriptionCallBack, - pub equal: CFDictionaryEqualCallBack, - pub hash: CFDictionaryHashCallBack, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct CFDictionaryValueCallBacks { - pub version: CFIndex, - pub retain: CFDictionaryRetainCallBack, - pub release: CFDictionaryReleaseCallBack, - pub copyDescription: CFDictionaryCopyDescriptionCallBack, - pub equal: CFDictionaryEqualCallBack, -} -pub type CFDictionaryRef = *const __CFDictionary; -pub type CFStringEncoding = UInt32; -pub type C2RustUnnamed = libc::c_uint; -pub const kCFStringEncodingUTF32LE: C2RustUnnamed = 469762304; -pub const kCFStringEncodingUTF32BE: C2RustUnnamed = 402653440; -pub const kCFStringEncodingUTF32: C2RustUnnamed = 201326848; -pub const kCFStringEncodingUTF16LE: C2RustUnnamed = 335544576; -pub const kCFStringEncodingUTF16BE: C2RustUnnamed = 268435712; -pub const kCFStringEncodingUTF16: C2RustUnnamed = 256; -pub const kCFStringEncodingNonLossyASCII: C2RustUnnamed = 3071; -pub const kCFStringEncodingUTF8: C2RustUnnamed = 134217984; -pub const kCFStringEncodingUnicode: C2RustUnnamed = 256; -pub const kCFStringEncodingASCII: C2RustUnnamed = 1536; -pub const kCFStringEncodingNextStepLatin: C2RustUnnamed = 2817; -pub const kCFStringEncodingISOLatin1: C2RustUnnamed = 513; -pub const kCFStringEncodingWindowsLatin1: C2RustUnnamed = 1280; -pub const kCFStringEncodingMacRoman: C2RustUnnamed = 0; -pub type CFSetRetainCallBack = - Option *const libc::c_void>; -pub type CFSetReleaseCallBack = - Option ()>; -pub type CFSetCopyDescriptionCallBack = - Option CFStringRef>; -pub type CFSetEqualCallBack = - Option Boolean>; -pub type CFSetHashCallBack = Option CFHashCode>; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct CFSetCallBacks { - pub version: CFIndex, - pub retain: CFSetRetainCallBack, - pub release: CFSetReleaseCallBack, - pub copyDescription: CFSetCopyDescriptionCallBack, - pub equal: CFSetEqualCallBack, - pub hash: CFSetHashCallBack, -} -pub type CFSetRef = *const __CFSet; -pub type CGFloat = libc::c_double; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct CGAffineTransform { - pub a: CGFloat, - pub b: CGFloat, - pub c: CGFloat, - pub d: CGFloat, - pub tx: CGFloat, - pub ty: CGFloat, -} -pub type CTFontRef = *const __CTFont; -pub type PlatformFontRef = CTFontDescriptorRef; + /* ***************************************************************************\ Part of the XeTeX typesetting system Copyright (c) 1994-2008 by SIL International @@ -306,83 +114,14 @@ shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the copyright holders. \****************************************************************************/ -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontMgrOpSizeRec { - pub designSize: libc::c_uint, - pub subFamilyID: libc::c_uint, - pub nameCode: libc::c_uint, - pub minSize: libc::c_uint, - pub maxSize: libc::c_uint, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontMgrFamily { - pub styles: *mut CppStdMap>, - pub minWeight: uint16_t, - pub maxWeight: uint16_t, - pub minWidth: uint16_t, - pub maxWidth: uint16_t, - pub minSlant: int16_t, - pub maxSlant: int16_t, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontMgrFont { - pub m_fullName: *mut CppStdString, - pub m_psName: *mut CppStdString, - pub m_familyName: *mut CppStdString, - pub m_styleName: *mut CppStdString, - pub parent: *mut XeTeXFontMgrFamily, - pub fontRef: PlatformFontRef, - pub opSizeInfo: XeTeXFontMgrOpSizeRec, - pub weight: uint16_t, - pub width: uint16_t, - pub slant: int16_t, - pub isReg: bool, - pub isBold: bool, - pub isItalic: bool, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontMgrNameCollection { - pub m_familyNames: *mut CppStdListOfString, - pub m_styleNames: *mut CppStdListOfString, - pub m_fullNames: *mut CppStdListOfString, - pub m_psName: *mut CppStdString, - pub m_subFamily: *mut CppStdString, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontMgr { - pub m_subdtor: Option ()>, - pub m_memfnInitialize: Option ()>, - pub m_memfnTerminate: Option ()>, - pub m_memfnGetPlatformFontDesc: Option< - unsafe extern "C" fn(_: *const XeTeXFontMgr, _: PlatformFontRef) -> *mut libc::c_char, - >, - pub m_memfnGetOpSizeRecAndStyleFlags: - Option ()>, - pub m_memfnSearchForHostPlatformFonts: - Option ()>, - pub m_memfnReadNames: Option< - unsafe extern "C" fn( - _: *mut XeTeXFontMgr, - _: PlatformFontRef, - ) -> *mut XeTeXFontMgrNameCollection, - >, - pub m_nameToFont: *mut CppStdMap>, - pub m_nameToFamily: *mut CppStdMap>, - pub m_platformRefToFont: *mut CppStdMap>, - pub m_psNameToFont: *mut CppStdMap>, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontMgr_Mac { - pub super_: XeTeXFontMgr, -} + +use super::{ + XeTeXFontMgr, XeTeXFontMgrFamily, XeTeXFontMgrFont, XeTeXFontMgrNameCollection, + XeTeXFontMgrOpSizeRec, XeTeXFontMgr_Mac, +}; + #[inline] -unsafe extern "C" fn XeTeXFontMgrNameCollection_create() -> *mut XeTeXFontMgrNameCollection { +unsafe fn XeTeXFontMgrNameCollection_create() -> *mut XeTeXFontMgrNameCollection { let mut self_0: *mut XeTeXFontMgrNameCollection = malloc(::std::mem::size_of::() as libc::c_ulong) as *mut XeTeXFontMgrNameCollection; @@ -393,8 +132,9 @@ unsafe extern "C" fn XeTeXFontMgrNameCollection_create() -> *mut XeTeXFontMgrNam (*self_0).m_subFamily = CppStdString_create(); return self_0; } + #[inline] -unsafe extern "C" fn XeTeXFontMgr_readNames( +unsafe fn XeTeXFontMgr_readNames( mut self_0: *mut XeTeXFontMgr, mut fontRef: PlatformFontRef, ) -> *mut XeTeXFontMgrNameCollection { @@ -402,10 +142,9 @@ unsafe extern "C" fn XeTeXFontMgr_readNames( .m_memfnReadNames .expect("non-null function pointer")(self_0, fontRef); } + #[inline] -unsafe extern "C" fn XeTeXFontMgrNameCollection_delete( - mut self_0: *mut XeTeXFontMgrNameCollection, -) { +unsafe fn XeTeXFontMgrNameCollection_delete(mut self_0: *mut XeTeXFontMgrNameCollection) { if self_0.is_null() { return; } @@ -416,8 +155,9 @@ unsafe extern "C" fn XeTeXFontMgrNameCollection_delete( CppStdString_delete((*self_0).m_subFamily); free(self_0 as *mut libc::c_void); } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_findFontWithName( +pub unsafe fn XeTeXFontMgr_findFontWithName( mut name: CFStringRef, mut key: CFStringRef, ) -> CTFontDescriptorRef { @@ -453,8 +193,9 @@ pub unsafe extern "C" fn XeTeXFontMgr_findFontWithName( } return matched; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_appendNameToList( +pub unsafe fn XeTeXFontMgr_Mac_appendNameToList( mut self_0: *mut XeTeXFontMgr, mut font: CTFontRef, mut nameList: *mut CppStdListOfString, @@ -466,7 +207,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_Mac_appendNameToList( XeTeXFontMgr_appendToList(self_0, nameList, msg_send![name, UTF8String]); CFRelease(name as CFTypeRef); } - let mut language: CFStringRef = 0 as *const __CFString; + let mut language: CFStringRef = ptr::null_mut(); let name = CTFontCopyLocalizedName(font, nameKey, &mut language); let name: *const NSString = name.cast(); if !name.is_null() { @@ -476,7 +217,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_Mac_appendNameToList( } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_readNames( +pub unsafe fn XeTeXFontMgr_Mac_readNames( mut self_0: *mut XeTeXFontMgr, mut fontRef: CTFontDescriptorRef, ) -> *mut XeTeXFontMgrNameCollection { @@ -506,10 +247,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_Mac_readNames( } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_addFontsToCaches( - mut self_0: *mut XeTeXFontMgr, - fonts: CFArrayRef, -) { +pub unsafe fn XeTeXFontMgr_Mac_addFontsToCaches(mut self_0: *mut XeTeXFontMgr, fonts: CFArrayRef) { let fonts: *const NSArray = fonts.cast(); let mut enumerator: id = msg_send![fonts, objectEnumerator]; for mut aFont in NSEnumerator::::from_ptr(enumerator) { @@ -522,7 +260,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_Mac_addFontsToCaches( } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_addFamilyToCaches( +unsafe fn XeTeXFontMgr_Mac_addFamilyToCaches( mut self_0: *mut XeTeXFontMgr, mut familyRef: CTFontDescriptorRef, ) { @@ -539,7 +277,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_Mac_addFamilyToCaches( } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_addFontAndSiblingsToCaches( +unsafe fn XeTeXFontMgr_Mac_addFontAndSiblingsToCaches( mut self_0: *mut XeTeXFontMgr, mut fontRef: CTFontDescriptorRef, ) { @@ -560,7 +298,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_Mac_addFontAndSiblingsToCaches( } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_searchForHostPlatformFonts( +unsafe fn XeTeXFontMgr_Mac_searchForHostPlatformFonts( mut self_0: *mut XeTeXFontMgr, mut name: *const libc::c_char, ) { @@ -636,23 +374,21 @@ pub unsafe extern "C" fn XeTeXFontMgr_Mac_searchForHostPlatformFonts( return; }; } -#[no_mangle] -pub static mut pool: *mut NSAutoreleasePool = ptr::null_mut(); -#[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_initialize(mut self_0: *mut XeTeXFontMgr) { +static mut pool: *mut NSAutoreleasePool = ptr::null_mut(); + +unsafe fn XeTeXFontMgr_Mac_initialize(mut self_0: *mut XeTeXFontMgr) { pool = msg_send![class!(NSAutoreleasePool), new]; } -#[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_terminate(mut self_0: *mut XeTeXFontMgr) { +unsafe fn XeTeXFontMgr_Mac_terminate(mut self_0: *mut XeTeXFontMgr) { if !pool.is_null() { let _: () = msg_send![pool, drain]; } } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_getPlatformFontDesc( +unsafe fn XeTeXFontMgr_Mac_getPlatformFontDesc( mut self_0: *const XeTeXFontMgr, mut descriptor: PlatformFontRef, ) -> *mut libc::c_char { @@ -686,34 +422,31 @@ pub unsafe extern "C" fn XeTeXFontMgr_Mac_getPlatformFontDesc( } return strdup(path); } -#[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_ctor(mut self_0: *mut XeTeXFontMgr_Mac) { + +unsafe fn XeTeXFontMgr_Mac_ctor(mut self_0: *mut XeTeXFontMgr_Mac) { XeTeXFontMgr_base_ctor(&mut (*self_0).super_); (*self_0).super_.m_memfnInitialize = - Some(XeTeXFontMgr_Mac_initialize as unsafe extern "C" fn(_: *mut XeTeXFontMgr) -> ()); + Some(XeTeXFontMgr_Mac_initialize as unsafe fn(_: *mut XeTeXFontMgr) -> ()); (*self_0).super_.m_memfnTerminate = - Some(XeTeXFontMgr_Mac_terminate as unsafe extern "C" fn(_: *mut XeTeXFontMgr) -> ()); + Some(XeTeXFontMgr_Mac_terminate as unsafe fn(_: *mut XeTeXFontMgr) -> ()); (*self_0).super_.m_memfnGetPlatformFontDesc = Some( XeTeXFontMgr_Mac_getPlatformFontDesc - as unsafe extern "C" fn( - _: *const XeTeXFontMgr, - _: PlatformFontRef, - ) -> *mut libc::c_char, + as unsafe fn(_: *const XeTeXFontMgr, _: PlatformFontRef) -> *mut libc::c_char, ); (*self_0).super_.m_memfnSearchForHostPlatformFonts = Some( XeTeXFontMgr_Mac_searchForHostPlatformFonts - as unsafe extern "C" fn(_: *mut XeTeXFontMgr, _: *const libc::c_char) -> (), + as unsafe fn(_: *mut XeTeXFontMgr, _: *const libc::c_char) -> (), ); (*self_0).super_.m_memfnReadNames = Some( XeTeXFontMgr_Mac_readNames - as unsafe extern "C" fn( + as unsafe fn( _: *mut XeTeXFontMgr, _: CTFontDescriptorRef, ) -> *mut XeTeXFontMgrNameCollection, ); } -#[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_Mac_create() -> *mut XeTeXFontMgr_Mac { + +pub unsafe fn XeTeXFontMgr_Mac_create() -> *mut XeTeXFontMgr_Mac { let mut self_0: *mut XeTeXFontMgr_Mac = malloc(::std::mem::size_of::() as libc::c_ulong) as *mut XeTeXFontMgr_Mac; XeTeXFontMgr_Mac_ctor(self_0); diff --git a/engine/src/xetex_font_manager_fontconfig.rs b/engine/src/xetex_font_manager_fontconfig.rs index fd73064ed..8f4c0a278 100644 --- a/engine/src/xetex_font_manager_fontconfig.rs +++ b/engine/src/xetex_font_manager_fontconfig.rs @@ -1,22 +1,46 @@ #![cfg(not(target_os = "macos"))] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] - +use super::PlatformFontRef; +use super::XeTeXFontMgr_base_ctor; use crate::stub_icu as icu; -use crate::xetex_layout_interface::collection_types::*; +use crate::xetex_layout_engine::collection_types::*; use std::ffi::CString; -use std::ptr::NonNull; +use std::ptr::{self, NonNull}; +use crate::xetex_font_info::XeTeXFontInst; -use freetype::freetype_sys::{FT_Byte, FT_UInt, FT_Long, FT_ULong, FT_Int32, FT_Pointer, FT_Error, FT_Fixed, - FT_Library, FT_Face, FT_Glyph, FT_String, FT_Parameter}; -use freetype::freetype_sys::{FT_New_Face, FT_Done_Face, FT_Get_Postscript_Name, FT_Init_FreeType}; -use crate::freetype_sys_patch::{FT_Get_Sfnt_Name, FT_Get_Sfnt_Name_Count}; +use freetype::freetype::{ + FT_BBox, FT_Bitmap, FT_Bitmap_Size, FT_Byte, FT_CharMap, FT_Done_Face, FT_Encoding, FT_Error, + FT_Face, FT_Fixed, FT_Generic, FT_Get_Postscript_Name, FT_GlyphSlot, FT_Glyph_Metrics, + FT_Init_FreeType, FT_Int, FT_Library, FT_Long, FT_New_Face, FT_Outline, FT_Pos, FT_Short, + FT_Size, FT_String, FT_SubGlyph, FT_UInt, FT_UShort, FT_Vector, +}; + +use super::{ + XeTeXFontMgr, XeTeXFontMgrFamily, XeTeXFontMgrFont, XeTeXFontMgrNameCollection, + XeTeXFontMgrOpSizeRec, XeTeXFontMgr_addToMaps, XeTeXFontMgr_appendToList, + XeTeXFontMgr_base_getOpSizeRecAndStyleFlags, XeTeXFontMgr_prependToList, +}; + +pub type FT_SfntName = FT_SfntName_; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct FT_SfntName_ { + pub platform_id: FT_UShort, + pub encoding_id: FT_UShort, + pub language_id: FT_UShort, + pub name_id: FT_UShort, + pub string: *mut FT_Byte, + pub string_len: FT_UInt, +} extern "C" { pub type _FcPattern; @@ -63,35 +87,15 @@ extern "C" { n: libc::c_int, s: *mut *mut FcChar8, ) -> FcResult; - /* gFreeTypeLibrary is defined in xetex-XeTeXFontInst_FT2.cpp, - * also used in xetex-XeTeXFontMgr_FC.cpp and xetex-ext.c. */ + #[no_mangle] static mut gFreeTypeLibrary: FT_Library; + #[no_mangle] - fn XeTeXFontMgr_base_ctor(self_0: *mut XeTeXFontMgr); - #[no_mangle] - fn XeTeXFontMgr_appendToList( - self_0: *mut XeTeXFontMgr, - list: *mut CppStdListOfString, - str: *const libc::c_char, - ); - #[no_mangle] - fn XeTeXFontMgr_prependToList( - self_0: *mut XeTeXFontMgr, - list: *mut CppStdListOfString, - str: *const libc::c_char, - ); - #[no_mangle] - fn XeTeXFontMgr_addToMaps( - self_0: *mut XeTeXFontMgr, - platformFont: PlatformFontRef, - names: *const XeTeXFontMgrNameCollection, - ); + fn FT_Get_Sfnt_Name_Count(face: FT_Face) -> FT_UInt; + #[no_mangle] - fn XeTeXFontMgr_base_getOpSizeRecAndStyleFlags( - self_0: *mut XeTeXFontMgr, - theFont: *mut XeTeXFontMgrFont, - ); + fn FT_Get_Sfnt_Name(face: FT_Face, idx: FT_UInt, aname: *mut FT_SfntName) -> FT_Error; } pub type __int16_t = libc::c_short; pub type __uint16_t = libc::c_ushort; @@ -127,14 +131,14 @@ pub struct _FcObjectSet { } pub type FcObjectSet = _FcObjectSet; pub type FcConfig = _FcConfig; -pub type PlatformFontRef = *mut FcPattern; + /* ***************************************************************************\ - Part of the XeTeX typesetting system - Copyright (c) 1994-2008 by SIL International - Copyright (c) 2009 by Jonathan Kew - Copyright (c) 2012, 2013 by Jiang Jiang +Part of the XeTeX typesetting system +Copyright (c) 1994-2008 by SIL International +Copyright (c) 2009 by Jonathan Kew +Copyright (c) 2012, 2013 by Jiang Jiang - SIL Author(s): Jonathan Kew +SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -160,16 +164,12 @@ shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the copyright holders. \****************************************************************************/ -use super::{ - XeTeXFontMgr, XeTeXFontMgrFamily, XeTeXFontMgrFont, XeTeXFontMgrNameCollection, - XeTeXFontMgrOpSizeRec, -}; /* ***************************************************************************\ - Part of the XeTeX typesetting system - Copyright (c) 1994-2008 by SIL International - Copyright (c) 2009 by Jonathan Kew +Part of the XeTeX typesetting system +Copyright (c) 1994-2008 by SIL International +Copyright (c) 2009 by Jonathan Kew - SIL Author(s): Jonathan Kew +SIL Author(s): Jonathan Kew Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -195,6 +195,7 @@ shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the copyright holders. \****************************************************************************/ + #[derive(Copy, Clone)] #[repr(C)] pub struct XeTeXFontMgr_FC { @@ -202,8 +203,9 @@ pub struct XeTeXFontMgr_FC { pub allFonts: *mut FcFontSet, pub cachedAll: bool, } + #[inline] -unsafe extern "C" fn XeTeXFontMgrNameCollection_create() -> *mut XeTeXFontMgrNameCollection { +unsafe fn XeTeXFontMgrNameCollection_create() -> *mut XeTeXFontMgrNameCollection { let mut self_0: *mut XeTeXFontMgrNameCollection = malloc(::std::mem::size_of::() as libc::c_ulong) as *mut XeTeXFontMgrNameCollection; @@ -214,10 +216,9 @@ unsafe extern "C" fn XeTeXFontMgrNameCollection_create() -> *mut XeTeXFontMgrNam (*self_0).m_subFamily = CppStdString_create(); return self_0; } + #[inline] -unsafe extern "C" fn XeTeXFontMgrNameCollection_delete( - mut self_0: *mut XeTeXFontMgrNameCollection, -) { +unsafe fn XeTeXFontMgrNameCollection_delete(mut self_0: *mut XeTeXFontMgrNameCollection) { if self_0.is_null() { return; } @@ -228,8 +229,9 @@ unsafe extern "C" fn XeTeXFontMgrNameCollection_delete( CppStdString_delete((*self_0).m_subFamily); free(self_0 as *mut libc::c_void); } + #[inline] -unsafe extern "C" fn XeTeXFontMgr_readNames( +unsafe fn XeTeXFontMgr_readNames( mut self_0: *mut XeTeXFontMgr, mut fontRef: PlatformFontRef, ) -> *mut XeTeXFontMgrNameCollection { @@ -237,17 +239,19 @@ unsafe extern "C" fn XeTeXFontMgr_readNames( .m_memfnReadNames .expect("non-null function pointer")(self_0, fontRef); } + #[inline] -unsafe extern "C" fn XeTeXFontMgr_cacheFamilyMembers( +unsafe fn XeTeXFontMgr_cacheFamilyMembers( mut self_0: *mut XeTeXFontMgr, mut familyNames: *const CppStdListOfString, ) { XeTeXFontMgr_FC_cacheFamilyMembers(self_0, familyNames); } + static mut macRomanConv: *mut icu::UConverter = 0 as *mut icu::UConverter; static mut utf16beConv: *mut icu::UConverter = 0 as *mut icu::UConverter; static mut utf8Conv: *mut icu::UConverter = 0 as *mut icu::UConverter; -unsafe extern "C" fn convertToUtf8( +unsafe fn convertToUtf8( mut conv: *mut icu::UConverter, mut name: *const libc::c_uchar, mut len: libc::c_int, @@ -291,12 +295,12 @@ unsafe extern "C" fn convertToUtf8( free(buffer1 as *mut libc::c_void); return buffer2; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_readNames( +pub unsafe fn XeTeXFontMgr_FC_readNames( mut self_0: *mut XeTeXFontMgr, mut pat: *mut FcPattern, ) -> *mut XeTeXFontMgrNameCollection { - use crate::freetype_sys_patch::FT_SfntName; let mut names: *mut XeTeXFontMgrNameCollection = XeTeXFontMgrNameCollection_create(); let mut pathname: *mut libc::c_char = 0 as *mut libc::c_char; if FcPatternGetString( @@ -320,7 +324,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_readNames( { return names; } - let mut face: FT_Face = 0 as FT_Face; + let mut face: FT_Face = ptr::null_mut(); if FT_New_Face(gFreeTypeLibrary, pathname, index as FT_Long, &mut face) != 0i32 { return names; } @@ -468,8 +472,9 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_readNames( FT_Done_Face(face); return names; } + #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_getOpSizeRecAndStyleFlags( +pub unsafe fn XeTeXFontMgr_FC_getOpSizeRecAndStyleFlags( mut self_0: *mut XeTeXFontMgr, mut theFont: *mut XeTeXFontMgrFont, ) { @@ -511,7 +516,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_getOpSizeRecAndStyleFlags( }; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_cacheFamilyMembers( +pub unsafe fn XeTeXFontMgr_FC_cacheFamilyMembers( mut self_0: *mut XeTeXFontMgr, mut familyNames: *const CppStdListOfString, ) { @@ -550,7 +555,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_cacheFamilyMembers( } } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_searchForHostPlatformFonts( +pub unsafe fn XeTeXFontMgr_FC_searchForHostPlatformFonts( mut self_0: *mut XeTeXFontMgr, mut name: *const libc::c_char, ) { @@ -688,7 +693,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_searchForHostPlatformFonts( CppStdString_delete(famName); } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_initialize(mut self_0: *mut XeTeXFontMgr) { +pub unsafe fn XeTeXFontMgr_FC_initialize(mut self_0: *mut XeTeXFontMgr) { let mut real_self: *mut XeTeXFontMgr_FC = self_0 as *mut XeTeXFontMgr_FC; if FcInit() == 0i32 { _tt_abort(b"fontconfig initialization failed\x00" as *const u8 as *const libc::c_char); @@ -726,7 +731,7 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_initialize(mut self_0: *mut XeTeXFontMg (*real_self).cachedAll = 0i32 != 0; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_terminate(mut self_0: *mut XeTeXFontMgr) { +pub unsafe fn XeTeXFontMgr_FC_terminate(mut self_0: *mut XeTeXFontMgr) { let mut real_self: *mut XeTeXFontMgr_FC = self_0 as *mut XeTeXFontMgr_FC; FcFontSetDestroy((*real_self).allFonts); (*real_self).allFonts = 0 as *mut FcFontSet; @@ -744,14 +749,14 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_terminate(mut self_0: *mut XeTeXFontMgr }; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_getPlatformFontDesc( +pub unsafe fn XeTeXFontMgr_FC_getPlatformFontDesc( mut self_0: *const XeTeXFontMgr, - mut font: PlatformFontRef, + mut fontRef: PlatformFontRef, ) -> *mut libc::c_char { let mut s: *mut FcChar8 = 0 as *mut FcChar8; let mut path: *mut libc::c_char = 0 as *mut libc::c_char; if FcPatternGetString( - font as *const FcPattern, + fontRef as *const FcPattern, b"file\x00" as *const u8 as *const libc::c_char, 0i32, &mut s as *mut *mut FcChar8, @@ -765,37 +770,34 @@ pub unsafe extern "C" fn XeTeXFontMgr_FC_getPlatformFontDesc( return path; } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_ctor(mut self_0: *mut XeTeXFontMgr_FC) { +pub unsafe fn XeTeXFontMgr_FC_ctor(mut self_0: *mut XeTeXFontMgr_FC) { XeTeXFontMgr_base_ctor(&mut (*self_0).super_); (*self_0).super_.m_memfnInitialize = - Some(XeTeXFontMgr_FC_initialize as unsafe extern "C" fn(_: *mut XeTeXFontMgr) -> ()); + Some(XeTeXFontMgr_FC_initialize as unsafe fn(_: *mut XeTeXFontMgr) -> ()); (*self_0).super_.m_memfnTerminate = - Some(XeTeXFontMgr_FC_terminate as unsafe extern "C" fn(_: *mut XeTeXFontMgr) -> ()); + Some(XeTeXFontMgr_FC_terminate as unsafe fn(_: *mut XeTeXFontMgr) -> ()); (*self_0).super_.m_memfnGetOpSizeRecAndStyleFlags = Some( XeTeXFontMgr_FC_getOpSizeRecAndStyleFlags - as unsafe extern "C" fn(_: *mut XeTeXFontMgr, _: *mut XeTeXFontMgrFont) -> (), + as unsafe fn(_: *mut XeTeXFontMgr, _: *mut XeTeXFontMgrFont) -> (), ); (*self_0).super_.m_memfnGetPlatformFontDesc = Some( XeTeXFontMgr_FC_getPlatformFontDesc - as unsafe extern "C" fn( - _: *const XeTeXFontMgr, - _: PlatformFontRef, - ) -> *mut libc::c_char, + as unsafe fn(_: *const XeTeXFontMgr, _: PlatformFontRef) -> *mut libc::c_char, ); (*self_0).super_.m_memfnSearchForHostPlatformFonts = Some( XeTeXFontMgr_FC_searchForHostPlatformFonts - as unsafe extern "C" fn(_: *mut XeTeXFontMgr, _: *const libc::c_char) -> (), + as unsafe fn(_: *mut XeTeXFontMgr, _: *const libc::c_char) -> (), ); (*self_0).super_.m_memfnReadNames = Some( XeTeXFontMgr_FC_readNames - as unsafe extern "C" fn( + as unsafe fn( _: *mut XeTeXFontMgr, _: *mut FcPattern, ) -> *mut XeTeXFontMgrNameCollection, ); } #[no_mangle] -pub unsafe extern "C" fn XeTeXFontMgr_FC_create() -> *mut XeTeXFontMgr_FC { +pub unsafe fn XeTeXFontMgr_FC_create() -> *mut XeTeXFontMgr_FC { let mut self_0: *mut XeTeXFontMgr_FC = malloc(::std::mem::size_of::() as libc::c_ulong) as *mut XeTeXFontMgr_FC; XeTeXFontMgr_FC_ctor(self_0); diff --git a/engine/src/xetex_ini.rs b/engine/src/xetex_ini.rs index cca93edb5..d93794640 100644 --- a/engine/src/xetex_ini.rs +++ b/engine/src/xetex_ini.rs @@ -13,9 +13,9 @@ use std::io::Write; use super::xetex_texmfmp::get_date_and_time; use crate::core_memory::{mfree, xcalloc, xmalloc}; +use crate::text_layout_engine::{TextLayout, TextLayoutEngine}; use crate::xetex_consts::*; use crate::xetex_errors::{confusion, error, overflow}; -use crate::xetex_ext::release_font_engine; use crate::xetex_layout_engine::{destroy_font_manager, set_cp_code}; use crate::xetex_math::initialize_math_variables; use crate::xetex_output::{ @@ -42,7 +42,7 @@ use crate::xetex_xetex0::{ show_save_groups, start_input, trap_zero_glue, }; use crate::{ - ttstub_input_close, ttstub_input_open, ttstub_input_read, ttstub_output_close, + ttstub_input_close, ttstub_input_open, ttstub_input_read_exact, ttstub_output_close, ttstub_output_open, ttstub_output_open_stdout, }; use bridge::_tt_abort; @@ -409,8 +409,13 @@ pub use super::xetex_io::UFILE; Licensed under the MIT License. */ /* All the following variables are declared in xetex-xetexd.h */ + +/// The XeTeX sources don't contain much in the way of documentation for eqtb. +/// This file does a better job: +/// https://fossies.org/windows/misc/w32tex-src.tar.xz/qtx/texk/web2c/luatexdir/tex/equivalents.c #[no_mangle] pub static mut eqtb: *mut memory_word = 0 as *const memory_word as *mut memory_word; + #[no_mangle] pub static mut bad: i32 = 0; #[no_mangle] @@ -781,8 +786,6 @@ pub static mut font_params: *mut font_index = 0 as *const font_index as *mut fon #[no_mangle] pub static mut font_name: *mut str_number = 0 as *const str_number as *mut str_number; #[no_mangle] -pub static mut font_area: *mut str_number = 0 as *const str_number as *mut str_number; -#[no_mangle] pub static mut font_bc: *mut UTF16_code = 0 as *const UTF16_code as *mut UTF16_code; #[no_mangle] pub static mut font_ec: *mut UTF16_code = 0 as *const UTF16_code as *mut UTF16_code; @@ -800,9 +803,15 @@ pub static mut bchar_label: *mut font_index = 0 as *const font_index as *mut fon pub static mut font_bchar: *mut nine_bits = 0 as *const nine_bits as *mut nine_bits; #[no_mangle] pub static mut font_false_bchar: *mut nine_bits = 0 as *const nine_bits as *mut nine_bits; -#[no_mangle] -pub static mut font_layout_engine: *mut *mut libc::c_void = - 0 as *const *mut libc::c_void as *mut *mut libc::c_void; +pub static mut FONT_AREA: *mut str_number = 0 as *const str_number as *mut str_number; +// XXX: change the usize to u32 / internal font number +use std::{sync::Mutex, collections::HashMap}; +use std::cell::{RefCell, Ref, RefMut}; +use once_cell::unsync::Lazy; +pub static mut TEXT_LAYOUT_ENGINES: Lazy>> = Lazy::new(|| { + let m = HashMap::new(); + RefCell::new(m) +}); #[no_mangle] pub static mut font_mapping: *mut *mut libc::c_void = 0 as *const *mut libc::c_void as *mut *mut libc::c_void; @@ -1164,6 +1173,28 @@ that dumps a glue ratio, i.e., a floating-point number. Fortunately, none of the standard formats do that. */ /* This macro is always invoked as a statement. It assumes a variable `temp'. */ + +pub unsafe fn current_font_num() -> usize { + (*eqtb.offset(CUR_FONT_LOC as isize)).b32.s1 as usize +} +use std::ops::{Deref, DerefMut}; +pub unsafe fn get_text_layout_engine(f: usize) -> Option> { + let engines = TEXT_LAYOUT_ENGINES.borrow(); + if engines.contains_key(&f) { + Some(Ref::map(engines, |es| &es[&f])) + } else { + None + } +} +pub unsafe fn get_text_layout_engine_mut(f: usize) -> Option> { + let engines = TEXT_LAYOUT_ENGINES.borrow_mut(); + if engines.contains_key(&f) { + Some(RefMut::map(engines, |es| es.get_mut(&f).unwrap())) + } else { + None + } +} + /* Make the NITEMS items pointed at by P, each of size SIZE, be the opposite-endianness of whatever they are now. */ unsafe extern "C" fn swap_items(mut p: *mut i8, mut nitems: size_t, mut size: size_t) { @@ -1280,6 +1311,7 @@ unsafe extern "C" fn do_dump( get used again. */ swap_items(p, nitems, item_size); } + /* Here is the dual of the writing routine. */ unsafe extern "C" fn do_undump( mut p: *mut i8, @@ -1287,7 +1319,8 @@ unsafe extern "C" fn do_undump( mut nitems: size_t, in_file: &mut InputHandleWrapper, ) { - let mut r: ssize_t = ttstub_input_read(in_file.0.as_ptr(), p, item_size.wrapping_mul(nitems)); + let mut r: ssize_t = + ttstub_input_read_exact(in_file.0.as_ptr(), p, item_size.wrapping_mul(nitems)); if r < 0i32 as i64 || r as size_t != item_size.wrapping_mul(nitems) { _tt_abort( b"could not undump %zu %zu-byte item(s) from %s\x00" as *const u8 as *const i8, @@ -1298,6 +1331,7 @@ unsafe extern "C" fn do_undump( } swap_items(p, nitems, item_size); } + /*:134*/ /*135: */ unsafe extern "C" fn sort_avail() { @@ -2956,12 +2990,11 @@ pub unsafe extern "C" fn prefixed_command() { *hyphen_char.offset(f as isize) = cur_val } else { *skew_char.offset(f as isize) = cur_val } } else { - if *font_area.offset(f as isize) as u32 == 0xffffu32 - || - *font_area.offset(f as isize) as u32 == - 0xfffeu32 { - scan_glyph_number(f); - } else { scan_char_num(); } + if let Some(eng) = get_text_layout_engine(f as usize) { + scan_glyph_number(&*eng); + } else { + scan_char_num(); + } p = cur_val; scan_optional_equals(); scan_int(); @@ -3516,7 +3549,7 @@ unsafe extern "C" fn store_fmt_file() { fmt_out, ); do_dump( - &mut *font_area.offset(0) as *mut str_number as *mut i8, + &mut *FONT_AREA.offset(0) as *mut str_number as *mut i8, ::std::mem::size_of::() as u64, (font_ptr + 1i32) as size_t, fmt_out, @@ -3616,10 +3649,7 @@ unsafe extern "C" fn store_fmt_file() { print_nl_cstr(b"\\font\x00" as *const u8 as *const i8); print_esc((*hash.offset(FONT_ID_BASE as isize + k as isize)).s1); print_char('=' as i32); - if *font_area.offset(k as isize) as u32 == 0xffffu32 - || *font_area.offset(k as isize) as u32 == 0xfffeu32 - || !(*font_mapping.offset(k as isize)).is_null() - { + if get_text_layout_engine(k as usize).is_some() { print_file_name( *font_name.offset(k as isize), (65536 + 1i32 as i64) as i32, @@ -3644,7 +3674,7 @@ unsafe extern "C" fn store_fmt_file() { } else { print_file_name( *font_name.offset(k as isize), - *font_area.offset(k as isize), + *FONT_AREA.offset(k as isize), (65536 + 1i32 as i64) as i32, ); } @@ -4397,10 +4427,6 @@ unsafe extern "C" fn load_fmt_file() -> bool { font_mapping = xmalloc( ((font_max + 1i32) as u64).wrapping_mul(::std::mem::size_of::<*mut libc::c_void>() as u64), ) as *mut *mut libc::c_void; - font_layout_engine = xcalloc( - (font_max + 1i32) as size_t, - ::std::mem::size_of::<*mut libc::c_void>() as u64, - ) as *mut *mut libc::c_void; font_flags = xmalloc(((font_max + 1i32) as u64).wrapping_mul(::std::mem::size_of::() as u64)) as *mut i8; @@ -4422,7 +4448,7 @@ unsafe extern "C" fn load_fmt_file() -> bool { font_name = xmalloc( ((font_max + 1i32) as u64).wrapping_mul(::std::mem::size_of::() as u64), ) as *mut str_number; - font_area = xmalloc( + FONT_AREA = xmalloc( ((font_max + 1i32) as u64).wrapping_mul(::std::mem::size_of::() as u64), ) as *mut str_number; font_bc = xmalloc( @@ -4558,19 +4584,19 @@ unsafe extern "C" fn load_fmt_file() -> bool { } let mut i_2: i32 = 0; do_undump( - &mut *font_area.offset(0) as *mut str_number as *mut i8, + &mut *FONT_AREA.offset(0) as *mut str_number as *mut i8, ::std::mem::size_of::() as u64, (font_ptr + 1i32) as size_t, fmt_in, ); i_2 = 0i32; while i_2 < font_ptr + 1i32 { - if *(&mut *font_area.offset(0) as *mut str_number).offset(i_2 as isize) > str_ptr { + if *(&mut *FONT_AREA.offset(0) as *mut str_number).offset(i_2 as isize) > str_ptr { panic!( "Item {} (={}) of .fmt array at {:x} >{}", i_2, - *(&mut *font_area.offset(0) as *mut str_number).offset(i_2 as isize) as uintptr_t, - &mut *font_area.offset(0) as *mut str_number as uintptr_t, + *(&mut *FONT_AREA.offset(0) as *mut str_number).offset(i_2 as isize) as uintptr_t, + &mut *FONT_AREA.offset(0) as *mut str_number as uintptr_t, str_ptr as uintptr_t ); } @@ -9857,10 +9883,6 @@ pub unsafe extern "C" fn tt_run_engine( (font_max + 1i32) as size_t, ::std::mem::size_of::<*mut libc::c_void>() as u64, ) as *mut *mut libc::c_void; - font_layout_engine = xcalloc( - (font_max + 1i32) as size_t, - ::std::mem::size_of::<*mut libc::c_void>() as u64, - ) as *mut *mut libc::c_void; font_flags = xcalloc( (font_max + 1i32) as size_t, ::std::mem::size_of::() as u64, @@ -9889,7 +9911,7 @@ pub unsafe extern "C" fn tt_run_engine( (font_max + 1i32) as size_t, ::std::mem::size_of::() as u64, ) as *mut str_number; - font_area = xcalloc( + FONT_AREA = xcalloc( (font_max + 1i32) as size_t, ::std::mem::size_of::() as u64, ) as *mut str_number; @@ -9964,7 +9986,7 @@ pub unsafe extern "C" fn tt_run_engine( font_ptr = 0i32; fmem_ptr = 7i32; *font_name.offset(0) = maketexstring(b"nullfont\x00" as *const u8 as *const i8); - *font_area.offset(0) = (65536 + 1i32 as i64) as str_number; + *FONT_AREA.offset(0) = (65536 + 1i32 as i64) as str_number; *hyphen_char.offset(0) = '-' as i32; *skew_char.offset(0) = -1i32; *bchar_label.offset(0) = 0i32; @@ -10021,18 +10043,6 @@ pub unsafe extern "C" fn tt_run_engine( free(font_used as *mut libc::c_void); deinitialize_shipout_variables(); destroy_font_manager(); - font_k = 0i32; - while font_k < font_max { - if !(*font_layout_engine.offset(font_k as isize)).is_null() { - release_font_engine( - *font_layout_engine.offset(font_k as isize), - *font_area.offset(font_k as isize), - ); - let ref mut fresh22 = *font_layout_engine.offset(font_k as isize); - *fresh22 = 0 as *mut libc::c_void - } - font_k += 1 - } // Free the big allocated arrays free(buffer as *mut libc::c_void); free(nest as *mut libc::c_void); @@ -10059,7 +10069,6 @@ pub unsafe extern "C" fn tt_run_engine( free(str_pool as *mut libc::c_void); free(font_info as *mut libc::c_void); free(font_mapping as *mut libc::c_void); - free(font_layout_engine as *mut libc::c_void); free(font_flags as *mut libc::c_void); free(font_letter_space as *mut libc::c_void); free(font_check as *mut libc::c_void); @@ -10067,7 +10076,7 @@ pub unsafe extern "C" fn tt_run_engine( free(font_dsize as *mut libc::c_void); free(font_params as *mut libc::c_void); free(font_name as *mut libc::c_void); - free(font_area as *mut libc::c_void); + free(FONT_AREA as *mut libc::c_void); free(font_bc as *mut libc::c_void); free(font_ec as *mut libc::c_void); free(font_glue as *mut libc::c_void); diff --git a/engine/src/xetex_io.rs b/engine/src/xetex_io.rs index e918ee90b..4bbcb4989 100644 --- a/engine/src/xetex_io.rs +++ b/engine/src/xetex_io.rs @@ -232,8 +232,14 @@ pub struct UFILE { */ #[no_mangle] pub static mut name_of_input_file: *mut i8 = 0 as *const i8 as *mut i8; + +/// Opens a file called called `name_of_file`, and sets `name_of_input_file`. +/// +/// `name_of_file` is a static set by scan_file_name() and pack_file_name() called in sequence. #[no_mangle] -pub unsafe extern "C" fn tt_xetex_open_input(mut filefmt: TTInputFormat) -> Option { +pub unsafe extern "C" fn tt_xetex_open_input( + mut filefmt: TTInputFormat, +) -> Option { let handle = if filefmt == TTInputFormat::TECTONIC_PRIMARY { ttstub_input_open_primary() } else { @@ -247,6 +253,7 @@ pub unsafe extern "C" fn tt_xetex_open_input(mut filefmt: TTInputFormat) -> Opti name_of_input_file = xstrdup(name_of_file); handle } + /* tables/values used in UTF-8 interpretation - code is based on ConvertUTF.[ch] sample code published by the Unicode consortium */ @@ -329,7 +336,7 @@ pub unsafe extern "C" fn u_open_in( (**f).handle = handle; if mode == 0i32 { /* sniff encoding form */ - let handle = (**f).handle.as_mut().unwrap(); + let handle = (**f).handle.as_mut().unwrap(); B1 = ttstub_input_getc(handle); B2 = ttstub_input_getc(handle); if B1 == 0xfei32 && B2 == 0xffi32 { diff --git a/engine/src/xetex_layout_engine.rs b/engine/src/xetex_layout_engine.rs index 1c97aae12..c3c3b656f 100644 --- a/engine/src/xetex_layout_engine.rs +++ b/engine/src/xetex_layout_engine.rs @@ -1,289 +1,2305 @@ -use harfbuzz_sys::{hb_ot_math_glyph_part_t, hb_tag_t, hb_feature_t}; +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] -pub type XeTeXLayoutEngine = *mut XeTeXLayoutEngine_rec; -/// PlatformFontRef matches C++ -#[cfg(not(target_os = "macos"))] -pub type PlatformFontRef = *mut FcPattern; -#[cfg(target_os = "macos")] -use crate::xetex_aatfont::cf_prelude::CTFontDescriptorRef; +// Fc* functions are from fontconfig. + +use crate::core_memory::{xcalloc, xmalloc}; +use crate::stub_icu as icu; +use harfbuzz_sys::*; + +use crate::text_layout_engine::{ + Fixed, FixedPoint, FloatPoint, LayoutRequest, NodeLayout, TextLayout, +}; +use crate::xetex_font_info::XeTeXFontInst; #[cfg(target_os = "macos")] -pub type PlatformFontRef = CTFontDescriptorRef; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct GlyphAssembly { - pub count: u32, - pub parts: *mut hb_ot_math_glyph_part_t, -} +use crate::xetex_font_info::XeTeXFontInst_Mac_create; +use crate::xetex_font_manager::{ + PlatformFontRef, ShaperRequest, XeTeXFontMgr, XeTeXFontMgrFamily, XeTeXFontMgrFont, +}; +use std::ffi::{CStr, CString}; +use std::ptr; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct GlyphBBox { - pub xMin: f32, - pub yMin: f32, - pub xMax: f32, - pub yMax: f32, +// https://www.freetype.org/freetype2/docs/reference/ft2-basic_types.html#ft_make_tag +pub const fn ft_make_tag(buf: &[u8; 4]) -> u32 { + (buf[0] as u32) << 24 | (buf[1] as u32) << 16 | (buf[2] as u32) << 8 | buf[3] as u32 } + extern "C" { - pub type XeTeXFont_rec; - pub type XeTeXLayoutEngine_rec; - #[no_mangle] - pub fn get_ot_math_constant(f: i32, n: i32) -> i32; - #[no_mangle] - pub fn set_cp_code(fontNum: i32, code: u32, side: i32, value: i32); - #[no_mangle] - pub fn get_cp_code(fontNum: i32, code: u32, side: i32) -> i32; - #[no_mangle] - pub fn isOpenTypeMathFont(engine: XeTeXLayoutEngine) -> bool; - #[no_mangle] - pub fn usingGraphite(engine: XeTeXLayoutEngine) -> bool; - #[no_mangle] - pub fn usingOpenType(engine: XeTeXLayoutEngine) -> bool; - #[no_mangle] - pub fn terminate_font_manager(); - #[no_mangle] - pub fn destroy_font_manager(); - #[no_mangle] - pub fn get_native_mathsy_param(f: i32, n: i32) -> i32; - #[no_mangle] - pub fn get_native_mathex_param(f: i32, n: i32) -> i32; - #[no_mangle] - pub fn get_ot_math_variant(f: i32, g: i32, v: i32, adv: *mut i32, horiz: i32) -> i32; - #[no_mangle] - pub fn get_ot_assembly_ptr(f: i32, g: i32, horiz: i32) -> *mut libc::c_void; - #[no_mangle] - pub fn free_ot_assembly(a: *mut GlyphAssembly); - #[no_mangle] - pub fn get_ot_math_ital_corr(f: i32, g: i32) -> i32; - #[no_mangle] - pub fn get_ot_math_accent_pos(f: i32, g: i32) -> i32; - #[no_mangle] - pub fn get_ot_math_kern(f: i32, g: i32, sf: i32, sg: i32, cmd: i32, shift: i32) -> i32; - #[no_mangle] - pub fn ot_part_count(a: *const GlyphAssembly) -> i32; - #[no_mangle] - pub fn ot_part_glyph(a: *const GlyphAssembly, i: i32) -> i32; - #[no_mangle] - pub fn ot_part_is_extender(a: *const GlyphAssembly, i: i32) -> bool; - #[no_mangle] - pub fn ot_part_start_connector(f: i32, a: *const GlyphAssembly, i: i32) -> i32; - #[no_mangle] - pub fn ot_part_end_connector(f: i32, a: *const GlyphAssembly, i: i32) -> i32; - #[no_mangle] - pub fn ot_part_full_advance(f: i32, a: *const GlyphAssembly, i: i32) -> i32; - #[no_mangle] - pub fn ot_min_connector_overlap(f: i32) -> i32; - #[no_mangle] - pub fn getCachedGlyphBBox(fontID: u16, glyphID: u16, bbox: *mut GlyphBBox) -> i32; - #[no_mangle] - pub fn cacheGlyphBBox(fontID: u16, glyphID: u16, bbox: *const GlyphBBox); + pub type gr_face; + pub type gr_font; + pub type gr_feature_ref; + pub type gr_feature_val; + pub type gr_char_info; + pub type gr_segment; + pub type gr_slot; + /* ******************************************************************/ + /* Glyph bounding box cache to speed up \XeTeXuseglyphmetrics mode */ + /* ******************************************************************/ + // key is combined value representing (font_id << 16) + glyph + // value is glyph bounding box in TeX points #[no_mangle] - pub fn maketexstring(s: *const i8) -> i32; + fn tan(_: f64) -> f64; #[no_mangle] - pub fn getDefaultDirection(engine: XeTeXLayoutEngine) -> i32; + fn malloc(_: libc::c_ulong) -> *mut libc::c_void; #[no_mangle] - pub fn createFont(fontRef: PlatformFontRef, pointSize: Fixed) -> XeTeXFont; + fn free(__ptr: *mut libc::c_void); #[no_mangle] - pub fn getAscentAndDescent(engine: XeTeXLayoutEngine, ascent: *mut f32, descent: *mut f32); + fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int; #[no_mangle] - pub fn setFontLayoutDir(font: XeTeXFont, vertical: i32); + fn strncmp(_: *const libc::c_char, _: *const libc::c_char, _: libc::c_ulong) -> libc::c_int; #[no_mangle] - pub fn layoutChars( - engine: XeTeXLayoutEngine, - chars: *mut u16, - offset: i32, - count: i32, - max: i32, - rightToLeft: bool, - ) -> i32; - #[no_mangle] - pub fn getPointSize(engine: XeTeXLayoutEngine) -> f32; - #[no_mangle] - pub fn getGlyphPositions(engine: XeTeXLayoutEngine, positions: *mut FloatPoint); - #[no_mangle] - pub fn getGlyphAdvances(engine: XeTeXLayoutEngine, advances: *mut f32); - #[no_mangle] - pub fn getGlyphs(engine: XeTeXLayoutEngine, glyphs: *mut u32); - #[no_mangle] - pub fn findFontByName(name: *const i8, var: *mut i8, size: f64) -> PlatformFontRef; - #[no_mangle] - pub fn getReqEngine() -> i8; - #[no_mangle] - pub fn setReqEngine(reqEngine: i8); - #[no_mangle] - pub fn getFullName(fontRef: PlatformFontRef) -> *const i8; - #[no_mangle] - pub fn getFontFilename(engine: XeTeXLayoutEngine, index: *mut u32) -> *mut i8; - #[no_mangle] - pub fn getDesignSize(font: XeTeXFont) -> f64; - #[no_mangle] - pub fn deleteFont(font: XeTeXFont); - #[no_mangle] - pub fn getSlant(font: XeTeXFont) -> Fixed; - #[no_mangle] - pub fn getFontTablePtr(font: XeTeXFont, tableTag: u32) -> *mut libc::c_void; + fn strdup(_: *const libc::c_char) -> *mut libc::c_char; #[no_mangle] - pub fn countScripts(font: XeTeXFont) -> u32; - #[no_mangle] - pub fn countLanguages(font: XeTeXFont, script: hb_tag_t) -> u32; - #[no_mangle] - pub fn countFeatures(font: XeTeXFont, script: hb_tag_t, language: hb_tag_t) -> u32; - #[no_mangle] - pub fn countGlyphs(font: XeTeXFont) -> u32; - #[no_mangle] - pub fn getIndScript(font: XeTeXFont, index: u32) -> hb_tag_t; - #[no_mangle] - pub fn getIndLanguage(font: XeTeXFont, script: hb_tag_t, index: u32) -> hb_tag_t; - #[no_mangle] - pub fn getIndFeature( - font: XeTeXFont, - script: hb_tag_t, - language: hb_tag_t, - index: u32, - ) -> hb_tag_t; - #[no_mangle] - pub fn getGlyphWidth(font: XeTeXFont, gid: u32) -> f32; - #[no_mangle] - pub fn createFontFromFile(filename: *const i8, index: i32, pointSize: Fixed) -> XeTeXFont; - #[no_mangle] - pub fn getCapAndXHeight(engine: XeTeXLayoutEngine, capheight: *mut f32, xheight: *mut f32); - #[no_mangle] - pub fn getEmboldenFactor(engine: XeTeXLayoutEngine) -> f32; - #[no_mangle] - pub fn getSlantFactor(engine: XeTeXLayoutEngine) -> f32; - #[no_mangle] - pub fn getExtendFactor(engine: XeTeXLayoutEngine) -> f32; - #[no_mangle] - pub fn getFontRef(engine: XeTeXLayoutEngine) -> PlatformFontRef; + fn strlen(_: *const libc::c_char) -> libc::c_ulong; + /* The internal, C/C++ interface: */ + /* tectonic/core-memory.h: basic dynamic memory helpers + Copyright 2016-2018 the Tectonic Project + Licensed under the MIT License. + */ #[no_mangle] - pub fn getFont(engine: XeTeXLayoutEngine) -> XeTeXFont; + fn xstrdup(s: *const libc::c_char) -> *mut libc::c_char; + #[no_mangle] + #[cfg(not(target_os = "macos"))] + fn FcPatternGetInteger( + p: *const FcPattern, + object: *const libc::c_char, + n: libc::c_int, + i: *mut libc::c_int, + ) -> FcResult; + #[no_mangle] + #[cfg(not(target_os = "macos"))] + fn FcPatternGetString( + p: *const FcPattern, + object: *const libc::c_char, + n: libc::c_int, + s: *mut *mut FcChar8, + ) -> FcResult; + #[no_mangle] + fn hb_unicode_funcs_set_decompose_compatibility_func( + ufuncs: *mut hb_unicode_funcs_t, + func: hb_unicode_decompose_compatibility_func_t, + user_data: *mut libc::c_void, + destroy: hb_destroy_func_t, + ); #[no_mangle] - pub fn deleteLayoutEngine(engine: XeTeXLayoutEngine); + fn hb_ot_layout_script_find_language( + face: *mut hb_face_t, + table_tag: hb_tag_t, + script_index: libc::c_uint, + language_tag: hb_tag_t, + language_index: *mut libc::c_uint, + ) -> hb_bool_t; + #[no_mangle] - pub fn createLayoutEngine( - fontRef: PlatformFontRef, - font: XeTeXFont, - script: hb_tag_t, - language: *mut i8, - features: *mut hb_feature_t, - nFeatures: i32, - shapers: *mut *mut i8, - rgbValue: u32, - extend: f32, - slant: f32, - embolden: f32, - ) -> XeTeXLayoutEngine; - /* graphite interface functions... */ + fn gr_face_featureval_for_lang( + pFace: *const gr_face, + langname: gr_uint32, + ) -> *mut gr_feature_val; #[no_mangle] - pub fn findGraphiteFeature( - engine: XeTeXLayoutEngine, - s: *const i8, - e: *const i8, - f: *mut hb_tag_t, - v: *mut i32, - ) -> bool; + fn gr_face_find_fref(pFace: *const gr_face, featId: gr_uint32) -> *const gr_feature_ref; #[no_mangle] - pub fn findNextGraphiteBreak() -> i32; + fn gr_face_n_fref(pFace: *const gr_face) -> gr_uint16; #[no_mangle] - pub fn initGraphiteBreaking(engine: XeTeXLayoutEngine, txtPtr: *const u16, txtLen: i32) - -> bool; + fn gr_face_fref(pFace: *const gr_face, i: gr_uint16) -> *const gr_feature_ref; #[no_mangle] - pub fn getFontCharRange(engine: XeTeXLayoutEngine, reqFirst: i32) -> i32; + fn gr_fref_feature_value( + pfeatureref: *const gr_feature_ref, + feats: *const gr_feature_val, + ) -> gr_uint16; #[no_mangle] - pub fn getGlyphName(font: XeTeXFont, gid: u16, len: *mut i32) -> *const i8; + fn gr_fref_set_feature_value( + pfeatureref: *const gr_feature_ref, + val: gr_uint16, + pDest: *mut gr_feature_val, + ) -> libc::c_int; #[no_mangle] - pub fn mapGlyphToIndex(engine: XeTeXLayoutEngine, glyphName: *const i8) -> i32; + fn gr_fref_id(pfeatureref: *const gr_feature_ref) -> gr_uint32; #[no_mangle] - pub fn mapCharToGlyph(engine: XeTeXLayoutEngine, charCode: u32) -> u32; + fn gr_fref_n_values(pfeatureref: *const gr_feature_ref) -> gr_uint16; #[no_mangle] - pub fn getGlyphItalCorr(engine: XeTeXLayoutEngine, glyphID: u32) -> f32; + fn gr_fref_value(pfeatureref: *const gr_feature_ref, settingno: gr_uint16) -> gr_int16; #[no_mangle] - pub fn getGlyphSidebearings( - engine: XeTeXLayoutEngine, - glyphID: u32, - lsb: *mut f32, - rsb: *mut f32, - ); + fn gr_fref_label( + pfeatureref: *const gr_feature_ref, + langId: *mut gr_uint16, + utf: gr_encform, + length: *mut gr_uint32, + ) -> *mut libc::c_void; #[no_mangle] - pub fn getGlyphHeightDepth( - engine: XeTeXLayoutEngine, - glyphID: u32, - height: *mut f32, - depth: *mut f32, - ); + fn gr_fref_value_label( + pfeatureref: *const gr_feature_ref, + settingno: gr_uint16, + langId: *mut gr_uint16, + utf: gr_encform, + length: *mut gr_uint32, + ) -> *mut libc::c_void; #[no_mangle] - pub fn getGlyphWidthFromEngine(engine: XeTeXLayoutEngine, glyphID: u32) -> f32; + pub fn gr_label_destroy(label: *mut libc::c_void); #[no_mangle] - pub fn getGlyphBounds(engine: XeTeXLayoutEngine, glyphID: u32, bbox: *mut GlyphBBox); + fn gr_cinfo_break_weight(p: *const gr_char_info) -> libc::c_int; #[no_mangle] - pub fn getRgbValue(engine: XeTeXLayoutEngine) -> u32; + fn gr_cinfo_base(p: *const gr_char_info) -> size_t; #[no_mangle] - pub fn countGraphiteFeatures(engine: XeTeXLayoutEngine) -> u32; + fn gr_make_seg( + font: *const gr_font, + face: *const gr_face, + script: gr_uint32, + pFeats: *const gr_feature_val, + enc: gr_encform, + pStart: *const libc::c_void, + nChars: size_t, + dir: libc::c_int, + ) -> *mut gr_segment; #[no_mangle] - pub fn getGraphiteFeatureCode(engine: XeTeXLayoutEngine, index: u32) -> u32; + fn gr_seg_destroy(p: *mut gr_segment); #[no_mangle] - pub fn countGraphiteFeatureSettings(engine: XeTeXLayoutEngine, feature: u32) -> u32; + fn gr_seg_cinfo(pSeg: *const gr_segment, index: libc::c_uint) -> *const gr_char_info; #[no_mangle] - pub fn getGraphiteFeatureSettingCode( - engine: XeTeXLayoutEngine, - feature: u32, - index: u32, - ) -> u32; + fn gr_seg_first_slot(pSeg: *mut gr_segment) -> *const gr_slot; #[no_mangle] - pub fn getGraphiteFeatureDefaultSetting(engine: XeTeXLayoutEngine, feature: u32) -> u32; + fn gr_seg_last_slot(pSeg: *mut gr_segment) -> *const gr_slot; #[no_mangle] - pub fn getGraphiteFeatureLabel(engine: XeTeXLayoutEngine, feature: u32) -> *mut i8; + fn gr_slot_next_in_segment(p: *const gr_slot) -> *const gr_slot; #[no_mangle] - pub fn getGraphiteFeatureSettingLabel( - engine: XeTeXLayoutEngine, - feature: u32, - setting: u32, - ) -> *mut i8; + fn gr_slot_index(p: *const gr_slot) -> libc::c_uint; #[no_mangle] - pub fn findGraphiteFeatureNamed( - engine: XeTeXLayoutEngine, - name: *const i8, - namelength: i32, - ) -> i64; + fn hb_graphite2_face_get_gr_face(face: *mut hb_face_t) -> *mut gr_face; #[no_mangle] - pub fn findGraphiteFeatureSettingNamed( - engine: XeTeXLayoutEngine, - feature: u32, - name: *const i8, - namelength: i32, - ) -> i64; - /* not the MS compiler, so try Metrowerks' platform macros */ - /* this seems to be needed for a gcc-mingw32 build to work... */ - /* - Create a converter object from a compiled mapping - */ + fn hb_graphite2_font_get_gr_font(font: *mut hb_font_t) -> *mut gr_font; #[no_mangle] - pub fn gr_label_destroy(label: *mut libc::c_void); + fn hb_icu_get_unicode_funcs() -> *mut hb_unicode_funcs_t; +} + +use crate::xetex_ext::{D2Fix, Fix2D}; + +use crate::xetex_font_manager::{ + XeTeXFontMgr_Destroy, XeTeXFontMgr_GetFontManager, XeTeXFontMgr_Terminate, + XeTeXFontMgr_findFont, XeTeXFontMgr_getDesignSize, XeTeXFontMgr_getFullName, +}; + +// use crate::xetex_font_info::{XeTeXFontInst_unitsToPoints, XeTeXFontInst_mapGlyphToIndex, XeTeXFontInst_getGlyphName, XeTeXFontInst_getLastCharCode, XeTeXFontInst_getFirstCharCode, XeTeXFontInst_delete, XeTeXFontInst_create, XeTeXFontInst_setLayoutDirVertical, XeTeXFontInst_mapCharToGlyph, XeTeXFontInst_getFontTable, XeTeXFontInst_getGlyphSidebearings, XeTeXFontInst_getGlyphHeightDepth}; + +use crate::xetex_font_info::*; + +pub mod collection_types { + use super::size_t; + use core::ptr::NonNull; + use std::collections::{BTreeMap, LinkedList, VecDeque}; + use std::ffi::CStr; + use std::ffi::CString; + + pub type CppStdString = CString; + pub type CppStdListOfString = VecDeque; + pub type CppStdMap = BTreeMap; + + pub fn CppStdString_create() -> *mut CppStdString { + Box::into_raw(Box::new(CString::default())) + } + + pub unsafe fn CppStdString_delete(self_0: *mut CppStdString) { + let _: Box = Box::from_raw(self_0); + } + pub unsafe fn CppStdString_length(self_0: *const CppStdString) -> libc::size_t { + self_0.as_ref().unwrap().to_bytes().len() as _ + } + pub unsafe fn CppStdString_cstr(self_0: *const CppStdString) -> *const libc::c_char { + let v = self_0.as_ref().unwrap(); + v.as_ptr() + } + + pub fn CppStdListOfString_create() -> *mut CppStdListOfString { + Box::into_raw(Box::new(CppStdListOfString::default())) + } + + pub unsafe fn CppStdListOfString_delete(self_0: *mut CppStdListOfString) { + let _: Box = Box::from_raw(self_0); + } + + pub fn CppStdMap_create() -> *mut CppStdMap { + Box::into_raw(Box::new(CppStdMap::default())) + } + + pub unsafe fn CppStdMap_put(self_0: *mut CppStdMap, key: K, val: V) { + (*self_0).insert(key, val); + } + + pub unsafe fn CppStdMap_put_with_string_key( + self_0: *mut CppStdMap, + key: *const libc::c_char, + val: V, + ) { + use std::ffi::CStr; + let key = CStr::from_ptr(key); + match (*self_0).get_mut(key) { + Some(v) => { + *v = val; + } + None => { + (*self_0).insert(key.to_owned(), val); + } + } + } + + pub unsafe fn CppStdMap_delete(self_0: *mut CppStdMap) { + let _: Box> = Box::from_raw(self_0); + } + + pub unsafe fn CppStdString_last(self_0: *const CppStdString) -> libc::c_char { + let val = &*self_0; + *val.to_bytes().last().expect("must not be empty") as libc::c_char + } + pub unsafe fn CppStdString_clone(self_0: *const CppStdString) -> *mut CppStdString { + let v: Box = Box::new((*self_0).clone()); + Box::into_raw(v) + } + + pub unsafe fn CppStdString_append_const_char_ptr( + self_0: *mut CppStdString, + val: *const libc::c_char, + ) { + use std::mem::swap; + let o: &mut CppStdString = &mut *self_0; + let mut v: CppStdString = Default::default(); + swap(o, &mut v); + let mut u = v.into_bytes(); + u.extend(CStr::from_ptr(val).to_bytes()); + v = CString::from_vec_unchecked(u); + swap(o, &mut v); + } + + pub unsafe fn CppStdString_assign_from_const_char_ptr( + self_0: *mut CppStdString, + val: *const libc::c_char, + ) { + let o: &mut CppStdString = &mut *self_0; + *o = CStr::from_ptr(val).to_owned(); + } + + pub unsafe fn CppStdString_assign_n_chars( + self_0: *mut CppStdString, + val: *const libc::c_char, + count: usize, + ) { + let o: &mut CppStdString = &mut *self_0; + let slice = std::slice::from_raw_parts(val as *const u8, count); + *o = CString::from_vec_unchecked(slice.to_owned()); + } } -pub type XeTeXFont = *mut XeTeXFont_rec; + +use self::collection_types::*; + +pub type size_t = usize; +pub type int8_t = i8; +pub type int16_t = i16; +pub type int32_t = i32; +pub type uint8_t = u8; +pub type uint16_t = u16; +pub type uint32_t = u32; + +pub type UChar32 = int32_t; #[cfg(not(target_os = "macos"))] -pub type Fixed = scaled_t; -#[cfg(target_os = "macos")] -pub type Fixed = SInt32; - -#[derive(Copy, Clone)] -#[cfg_attr(not(target_os = "macos"), repr(C))] -#[cfg_attr(target_os = "macos", repr(C, packed(2)))] -pub struct FixedPoint { - pub x: Fixed, - pub y: Fixed, -} -pub type scaled_t = i32; -pub type SInt32 = i32; -#[derive(Copy, Clone)] +pub type FcChar8 = libc::c_uchar; +#[cfg(not(target_os = "macos"))] +use crate::xetex_font_manager::imp::{FcPattern, FcResult}; + +pub type hb_unicode_decompose_compatibility_func_t = Option< + unsafe fn( + _: *mut hb_unicode_funcs_t, + _: hb_codepoint_t, + _: *mut hb_codepoint_t, + _: *mut libc::c_void, + ) -> libc::c_uint, +>; + +pub struct ImmutableCStringList { + // Option to make freeing manually easier + inner: Option, + pointer: *const *const libc::c_char, +} + +impl ImmutableCStringList { + // Warning: You must ensure that you do not drop this HarfBuzzShaperList + // while the resulting pointer here is still in use. Store this struct somewhere, or keep it in + // scope. + #[inline] + pub fn as_ptr(&self) -> *const *const libc::c_char { + self.pointer + } +} + +/// A convenient way to build a null-terminated list of null-terminated C pointer strings. +/// +/// Motivation: HarfBuzz shaper lists are pretty tiny, but storing each shaper id as a CString and +/// also having a *const *const c_char available for HarfBuzz to use is otherwise pretty tricky. +/// The original C code simply never freed these things as it was too hard. +#[derive(Clone)] +pub struct CStringListBuilder { + inner: Vec, + pointers: Option>, + dirty: bool, +} + +impl CStringListBuilder { + pub fn freeze(mut self) -> ImmutableCStringList { + let mut pointers = Vec::with_capacity(self.inner.len() + 1); + for cstring in &self.inner { + pointers.push(cstring.as_ptr()); + } + // HarfBuzz expects a null at the end. + pointers.push(ptr::null()); + let p = pointers.as_ptr(); + self.pointers = Some(pointers); + ImmutableCStringList { + pointer: p, + inner: Some(self), + } + } + pub fn new() -> Self { + CStringListBuilder { + inner: Vec::new(), + pointers: None, + dirty: true, + } + } + // Helps you select the default "ot" shaper if you haven't found any shapers to add. + pub fn none_if_empty(self) -> Option { + if self.inner.is_empty() { + return None; + } + Some(self) + } + pub fn push_non_null_terminated(&mut self, shaper: impl Into>) { + self.dirty = true; + self.inner.push( + CString::new(shaper) + .expect("push_non_null_terminated called with a null terminated C string"), + ); + } + pub fn push_cstr(&mut self, cstr: &CStr) { + self.dirty = true; + self.inner.push(cstr.to_owned()) + } +} + +pub type OTTag = uint32_t; +pub type GlyphID = uint16_t; + #[repr(C)] -pub struct FloatPoint { - pub x: f32, - pub y: f32, +pub struct XeTeXLayoutEngine_rec { + pub font: *mut XeTeXFontInst, + pub fontRef: PlatformFontRef, + pub script: hb_tag_t, + pub language: hb_language_t, + pub features: *mut hb_feature_t, + shaper_list: ImmutableCStringList, + pub shaper: *mut libc::c_char, + pub nFeatures: libc::c_int, + pub rgbValue: uint32_t, + pub extend: f32, + pub slant: f32, + pub embolden: f32, + pub hbBuffer: *mut hb_buffer_t, } -#[cfg(not(target_os = "macos"))] -extern "C" { - pub type _FcPattern; +pub type XeTeXLayoutEngine = *mut XeTeXLayoutEngine_rec; + +impl TextLayout for XeTeXLayoutEngine_rec { + // AAT casualties + + // /// getFontRef + // fn platform_font_ref(&self) -> PlatformFontRef { + // self.fontRef + // } + + // /// getFontInst + // fn font_instance(&self) -> *mut XeTeXFontInst { + // self.font + // } + + unsafe fn get_flags(&self, font_number: u32) -> i32 { + use crate::xetex_ini::font_flags; + if *font_flags.offset(font_number as isize) as i32 & 0x2i32 != 0i32 { + 0x100i32 + } else { + 0 + } + } + + // getGlyphWidth + unsafe fn glyph_width(&self, gid: u32) -> f64 { + XeTeXFontInst_getGlyphWidth(self.font, gid as GlyphID) as f64 + } + + /// getFontFilename + unsafe fn font_filename(&self, index: &mut u32) -> *mut libc::c_char { + unsafe { xstrdup(XeTeXFontInst_getFilename(self.font, index)) } + } + + /// getExtendFactor + unsafe fn extend_factor(&self) -> f64 { + self.extend as f64 + } + + unsafe fn get_font_metrics( + &self, + ascent: &mut Fixed, + descent: &mut Fixed, + xheight: &mut Fixed, + capheight: &mut Fixed, + slant: &mut Fixed, + ) { + let mut a: f32 = 0.; + let mut d: f32 = 0.; + self.ascent_and_descent(&mut a, &mut d); + *ascent = D2Fix(a as f64); + *descent = D2Fix(d as f64); + *slant = D2Fix( + Fix2D(getSlant(self.font)) * self.extend_factor() + self.slant_factor(), + ); + /* get cap and x height from OS/2 table */ + self.cap_and_x_height(&mut a, &mut d); + *capheight = D2Fix(a as f64); + *xheight = D2Fix(d as f64); + /* fallback in case the font does not have OS/2 table */ + if *xheight == 0i32 { + let mut glyphID: i32 = self.map_char_to_glyph('x' as i32 as u32) as i32; + if glyphID != 0i32 { + if let Some((height, desc)) = self.glyph_height_depth(glyphID as u32) { + a = height; + d = desc; + *xheight = D2Fix(a as f64); + } + } else { + *xheight = *ascent / 2i32 + /* arbitrary figure if there's no 'x' in the font */ + } + } + if *capheight == 0i32 { + let mut glyphID_0: i32 = self.map_char_to_glyph('X' as i32 as u32) as i32; + if glyphID_0 != 0i32 { + if let Some((height, desc)) = self.glyph_height_depth(glyphID_0 as u32) { + a = height; + d = desc; + *capheight = D2Fix(a as f64) + } + } else { + *capheight = *ascent + /* arbitrary figure if there's no 'X' in the font */ + } + }; + } + + /// ot_font_get, aat_font_get + unsafe fn poorly_named_getter(&self, what: i32) -> i32 { + let mut fontInst = self.font; + match what { + 1 => return countGlyphs(fontInst) as i32, + 8 => { + /* ie Graphite features */ + return countGraphiteFeatures(self) as i32; + } + 16 => return countScripts(fontInst) as i32, + _ => {} + } + 0i32 + } + + /// ot_font_get_1, aat_font_get_1 + unsafe fn poorly_named_getter_1(&self, what: i32, param: i32) -> i32 { + let mut fontInst = self.font; + match what { + 17 => return countLanguages(fontInst, param as hb_tag_t) as i32, + 19 => return getIndScript(fontInst, param as u32) as i32, + 9 => { + /* for graphite fonts...*/ + return getGraphiteFeatureCode(self, param as u32) as i32; + } + 11 => return 1i32, + 12 => return countGraphiteFeatureSettings(self, param as u32) as i32, + _ => {} + } + 0i32 + } + + /// ot_font_get_2, aat_font_get_2 + unsafe fn poorly_named_getter_2(&self, mut what: i32, mut param1: i32, mut param2: i32) -> i32 { + let mut fontInst = self.font; + match what { + 20 => return getIndLanguage(fontInst, param1 as hb_tag_t, param2 as u32) as i32, + 18 => return countFeatures(fontInst, param1 as hb_tag_t, param2 as hb_tag_t) as i32, + 13 => { + /* for graphite fonts */ + return getGraphiteFeatureSettingCode(self, param1 as u32, param2 as u32) as i32; + } + 15 => { + return (getGraphiteFeatureDefaultSetting(self, param1 as u32) == param2 as u32) + as i32 + } + _ => {} + } /* to guarantee enough space in the buffer */ + 0i32 + } + + unsafe fn poorly_named_getter_3( + &self, + mut what: i32, + mut param1: i32, + mut param2: i32, + mut param3: i32, + ) -> i32 { + let mut fontInst = self.font; + match what { + 21 => { + return getIndFeature( + fontInst, + param1 as hb_tag_t, + param2 as hb_tag_t, + param3 as u32, + ) as i32 + } + _ => {} + } + 0i32 + } + + /// getPointSize + unsafe fn point_size(&self) -> f64 { + unsafe { XeTeXFontInst_getPointSize(self.font) as f64 } + } + /// getAscentAndDescent + unsafe fn ascent_and_descent(&self, ascent: &mut f32, descent: &mut f32) { + unsafe { + *ascent = XeTeXFontInst_getAscent(self.font); + *descent = XeTeXFontInst_getDescent(self.font); + } + } + + /// gr_print_font_name + unsafe fn print_font_name(&self, what: i32, param1: i32, param2: i32) { + if self.usingGraphite() { + let mut name: *mut i8 = 0 as *mut i8; + match what { + 8 => name = getGraphiteFeatureLabel(self, param1 as u32), + 9 => name = getGraphiteFeatureSettingLabel(self, param1 as u32, param2 as u32), + _ => {} + } + if !name.is_null() { + crate::xetex_xetexd::print_c_string(name); + gr_label_destroy(name as *mut libc::c_void); + }; + } + // Not sure why non-graphite font names aren't printed + // Originally in xetex0.c. + } + + /// getGlyphName + /// Only used for debugging. Should be a String/CStr then! + unsafe fn glyph_name(&self, gid: u16, len: &mut libc::c_int) -> *const libc::c_char { + XeTeXFontInst_getGlyphName(self.font, gid, len) + } + + /// getCapAndXHeight + unsafe fn cap_and_x_height(&self, capheight: &mut f32, xheight: &mut f32) { + unsafe { + *capheight = XeTeXFontInst_getCapHeight(self.font); + *xheight = XeTeXFontInst_getXHeight(self.font); + } + } + /// getEmboldenFactor + unsafe fn embolden_factor(&self) -> f32 { + self.embolden + } + + /// getRgbValue + unsafe fn rgb_value(&self) -> u32 { + self.rgbValue + } + + unsafe fn slant_factor(&self) -> f64 { + self.slant as f64 + } + + /// getGlyphBounds (had out param) + unsafe fn glyph_bbox(&self, glyphID: u32) -> Option { + let font_info = &*self.font; + + // TODO: xetex_font_info uses u16 (why??????), but glyph IDs should be u32 + font_info.get_glyph_bounds(glyphID as u16).map(|mut bbox| { + if self.extend != 0.0f32 { + bbox.xMin *= self.extend; + bbox.xMax *= self.extend; + } + bbox + }) + } + + unsafe fn getGlyphWidthFromEngine(&self, glyphID: u32) -> f64 { + (self.extend * XeTeXFontInst_getGlyphWidth(self.font, glyphID as GlyphID)) as f64 + } + + /// getGlyphHeightDepth (had out params height, depth) + unsafe fn glyph_height_depth(&self, glyphID: u32) -> Option<(f32, f32)> { + let mut height: f32 = 0.; + let mut depth: f32 = 0.; + // TODO: None if glyph not found + unsafe { + XeTeXFontInst_getGlyphHeightDepth( + self.font, + glyphID as GlyphID, + &mut height, + &mut depth, + ); + } + Some((height, depth)) + } + + /// getGlyphSidebearings (had out params lsb, rsb) + unsafe fn glyph_sidebearings(&self, mut glyphID: u32) -> Option<(f32, f32)> { + let mut lsb = 0.; + let mut rsb = 0.; + // TODO: None if glyph not found + unsafe { + XeTeXFontInst_getGlyphSidebearings(self.font, glyphID as GlyphID, &mut lsb, &mut rsb); + } + if self.extend as f64 != 0.0f64 { + lsb *= self.extend; + rsb *= self.extend; + }; + Some((lsb, rsb)) + } + + /// getGlyphItalCorr + unsafe fn glyph_ital_correction(&self, glyphID: u32) -> Option { + // XXX: return none if glyph not found + Some( + self.extend as f64 + * XeTeXFontInst_getGlyphItalCorr(self.font, glyphID as GlyphID) as f64, + ) + } + + /// mapCharToGlyph + unsafe fn map_char_to_glyph(&self, codepoint: u32) -> u32 { + XeTeXFontInst_mapCharToGlyph(self.font, codepoint as UChar32) as u32 + } + + /// getFontCharRange + /// Another candidate for using XeTeXFontInst directly + unsafe fn font_char_range(&self, mut reqFirst: libc::c_int) -> libc::c_int { + if reqFirst != 0 { + return XeTeXFontInst_getFirstCharCode(self.font); + } else { + return XeTeXFontInst_getLastCharCode(self.font); + } + } + + /// mapGlyphToIndex + unsafe fn map_glyph_to_index(&self, mut glyphName: *const libc::c_char) -> i32 { + XeTeXFontInst_mapGlyphToIndex(self.font, glyphName) as i32 + } + + unsafe fn usingGraphite(&self) -> bool { + if !self.shaper.is_null() + && strcmp( + b"graphite2\x00" as *const u8 as *const libc::c_char, + self.shaper, + ) == 0i32 + { + true + } else { + false + } + } + + unsafe fn initGraphiteBreaking(&mut self, txtPtr: *const uint16_t, txtLen: i32) -> bool { + initGraphiteBreaking(self, txtPtr, txtLen) + } + + unsafe fn usingOpenType(&self) -> bool { + if self.shaper.is_null() + || strcmp(b"ot\x00" as *const u8 as *const libc::c_char, self.shaper) == 0i32 + { + true + } else { + false + } + } + + unsafe fn isOpenTypeMathFont(&self) -> bool { + hb_ot_math_has_data(hb_font_get_face(XeTeXFontInst_getHbFont(self.font))) != 0 + } + + unsafe fn layout_text(&mut self, request: LayoutRequest) -> NodeLayout { + use crate::bridge::size_t; + + // XXX use slices + let txtPtr = request.text.as_ptr(); + let txtLen = request.text.len() as i32; + + let mut locations: *mut FixedPoint = ptr::null_mut(); + let mut glyphIDs: *mut u16 = ptr::null_mut(); + let mut glyphAdvances: *mut Fixed = ptr::null_mut(); + let mut totalGlyphCount: i32 = 0i32; + /* need to find direction runs within the text, and call layoutChars separately for each */ + let mut dir: icu::UBiDiDirection = icu::UBIDI_LTR; + let mut glyph_info: *mut FixedPoint = ptr::null_mut(); + static mut positions: *mut FloatPoint = ptr::null_mut(); + static mut advances: *mut f32 = ptr::null_mut(); + static mut glyphs: *mut u32 = ptr::null_mut(); + let mut pBiDi: *mut icu::UBiDi = icu::ubidi_open(); + let mut errorCode: icu::UErrorCode = icu::U_ZERO_ERROR; + icu::ubidi_setPara( + pBiDi, + txtPtr, + txtLen, + getDefaultDirection(self) as icu::UBiDiLevel, + 0 as *mut icu::UBiDiLevel, + &mut errorCode, + ); + dir = icu::ubidi_getDirection(pBiDi); + + let mut layout = if dir as u32 == icu::UBIDI_MIXED as i32 as u32 { + /* we actually do the layout twice here, once to count glyphs and then again to get them; + which is inefficient, but i figure that MIXED is a relatively rare occurrence, so i can't be + bothered to deal with the memory reallocation headache of doing it differently + */ + let mut nRuns: i32 = icu::ubidi_countRuns(pBiDi, &mut errorCode); + let mut width: f64 = 0i32 as f64; + let mut i: i32 = 0; + let mut runIndex: i32 = 0; + let mut logicalStart: i32 = 0; + let mut length: i32 = 0; + runIndex = 0i32; + while runIndex < nRuns { + dir = icu::ubidi_getVisualRun(pBiDi, runIndex, &mut logicalStart, &mut length); + totalGlyphCount += self.layoutChars( + txtPtr, + logicalStart, + length, + txtLen, + dir as u32 == icu::UBIDI_RTL as i32 as u32, + ); + runIndex += 1 + } + if totalGlyphCount > 0i32 { + let mut x: f64 = 0.; + let mut y: f64 = 0.; + glyph_info = xcalloc(totalGlyphCount as size_t, 10i32 as size_t) as *mut FixedPoint; + locations = glyph_info; + glyphIDs = locations.offset(totalGlyphCount as isize) as *mut u16; + glyphAdvances = xcalloc( + totalGlyphCount as size_t, + ::std::mem::size_of::() as u64, + ) as *mut Fixed; + totalGlyphCount = 0i32; + y = 0.0f64; + x = y; + runIndex = 0i32; + while runIndex < nRuns { + let mut nGlyphs: i32 = 0; + dir = icu::ubidi_getVisualRun(pBiDi, runIndex, &mut logicalStart, &mut length); + nGlyphs = self.layoutChars( + txtPtr, + logicalStart, + length, + txtLen, + dir as u32 == icu::UBIDI_RTL as i32 as u32, + ); + glyphs = + xcalloc(nGlyphs as size_t, ::std::mem::size_of::() as u64) as *mut u32; + positions = xcalloc( + (nGlyphs + 1i32) as size_t, + ::std::mem::size_of::() as u64, + ) as *mut FloatPoint; + advances = + xcalloc(nGlyphs as size_t, ::std::mem::size_of::() as u64) as *mut f32; + getGlyphs(self, glyphs); + getGlyphAdvances(self, advances); + getGlyphPositions(self, positions); + i = 0i32; + while i < nGlyphs { + *glyphIDs.offset(totalGlyphCount as isize) = + *glyphs.offset(i as isize) as u16; + (*locations.offset(totalGlyphCount as isize)).x = + D2Fix((*positions.offset(i as isize)).x as f64 + x); + (*locations.offset(totalGlyphCount as isize)).y = + D2Fix((*positions.offset(i as isize)).y as f64 + y); + *glyphAdvances.offset(totalGlyphCount as isize) = + D2Fix(*advances.offset(i as isize) as f64); + totalGlyphCount += 1; + i += 1 + } + x += (*positions.offset(nGlyphs as isize)).x as f64; + y += (*positions.offset(nGlyphs as isize)).y as f64; + free(glyphs as *mut libc::c_void); + free(positions as *mut libc::c_void); + free(advances as *mut libc::c_void); + runIndex += 1 + } + width = x + } + NodeLayout { + lsDelta: None, + width: D2Fix(width), + total_glyph_count: totalGlyphCount as u16, + glyph_info, + } + } else { + let mut width_0: f64 = 0i32 as f64; + totalGlyphCount = self.layoutChars( + txtPtr, + 0i32, + txtLen, + txtLen, + dir as u32 == icu::UBIDI_RTL as i32 as u32, + ); + glyphs = xcalloc( + totalGlyphCount as size_t, + ::std::mem::size_of::() as u64, + ) as *mut u32; + positions = xcalloc( + (totalGlyphCount + 1i32) as size_t, + ::std::mem::size_of::() as u64, + ) as *mut FloatPoint; + advances = xcalloc( + totalGlyphCount as size_t, + ::std::mem::size_of::() as u64, + ) as *mut f32; + getGlyphs(self, glyphs); + getGlyphAdvances(self, advances); + getGlyphPositions(self, positions); + if totalGlyphCount > 0i32 { + let mut i_0: i32 = 0; + glyph_info = xcalloc(totalGlyphCount as size_t, 10i32 as size_t) as *mut FixedPoint; + locations = glyph_info; + glyphIDs = locations.offset(totalGlyphCount as isize) as *mut u16; + glyphAdvances = xcalloc( + totalGlyphCount as size_t, + ::std::mem::size_of::() as u64, + ) as *mut Fixed; + i_0 = 0i32; + while i_0 < totalGlyphCount { + *glyphIDs.offset(i_0 as isize) = *glyphs.offset(i_0 as isize) as u16; + *glyphAdvances.offset(i_0 as isize) = + D2Fix(*advances.offset(i_0 as isize) as f64); + (*locations.offset(i_0 as isize)).x = + D2Fix((*positions.offset(i_0 as isize)).x as f64); + (*locations.offset(i_0 as isize)).y = + D2Fix((*positions.offset(i_0 as isize)).y as f64); + i_0 += 1 + } + width_0 = (*positions.offset(totalGlyphCount as isize)).x as f64 + } + free(glyphs as *mut libc::c_void); + free(positions as *mut libc::c_void); + free(advances as *mut libc::c_void); + NodeLayout { + lsDelta: None, + width: D2Fix(width_0), + total_glyph_count: totalGlyphCount as u16, + glyph_info, + } + }; + + icu::ubidi_close(pBiDi); + + if request.letter_space_unit != 0i32 { + let mut lsDelta: Fixed = 0i32; + let mut lsUnit: Fixed = request.letter_space_unit; + let mut i_1: i32 = 0; + i_1 = 0i32; + while i_1 < totalGlyphCount { + if *glyphAdvances.offset(i_1 as isize) == 0i32 && lsDelta != 0i32 { + lsDelta -= lsUnit + } + let ref mut fresh31 = (*locations.offset(i_1 as isize)).x; + *fresh31 += lsDelta; + lsDelta += lsUnit; + i_1 += 1 + } + if lsDelta != 0i32 { + lsDelta -= lsUnit; + layout.lsDelta = Some(lsDelta); + } + } + free(glyphAdvances as *mut libc::c_void); + layout + } +} + +pub type gr_uint16 = libc::c_ushort; +pub type gr_int16 = libc::c_short; +pub type gr_uint32 = libc::c_uint; +pub type gr_encform = libc::c_uint; +pub const gr_utf32: gr_encform = 4; +pub const gr_utf16: gr_encform = 2; +pub const gr_utf8: gr_encform = 1; +pub type gr_break_weight = libc::c_int; +pub const gr_breakBeforeClip: gr_break_weight = -40; +pub const gr_breakBeforeLetter: gr_break_weight = -30; +pub const gr_breakBeforeIntra: gr_break_weight = -20; +pub const gr_breakBeforeWord: gr_break_weight = -15; +pub const gr_breakBeforeWhitespace: gr_break_weight = -10; +pub const gr_breakClip: gr_break_weight = 40; +pub const gr_breakLetter: gr_break_weight = 30; +pub const gr_breakIntra: gr_break_weight = 20; +pub const gr_breakWord: gr_break_weight = 15; +pub const gr_breakWhitespace: gr_break_weight = 10; +pub const gr_breakNone: gr_break_weight = 0; + +pub type ProtrusionFactor = CppStdMap; + +/* ***************************************************************************\ +Part of the XeTeX typesetting system +Copyright (c) 1994-2008 by SIL International +Copyright (c) 2009 by Jonathan Kew +Copyright (c) 2012, 2013 by Jiang Jiang + +SIL Author(s): Jonathan Kew + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the copyright holders +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in this Software without prior written +authorization from the copyright holders. +\****************************************************************************/ + +/* The following code used to be in a file called "hz.cpp" and there's no + * particular reason for it to be here, but it was a tiny file with a weird + * name so I wanted to get rid of it. The functions are invoked from the C + * code. */ +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[repr(C)] +pub struct GlyphId { + pub fontNum: libc::c_int, + pub code: libc::c_uint, +} +#[inline] +unsafe fn XeTeXFontInst_getDescent(mut self_0: *const XeTeXFontInst) -> f32 { + return (*self_0).m_descent; +} +#[inline] +unsafe fn XeTeXFontInst_getLayoutDirVertical(mut self_0: *const XeTeXFontInst) -> bool { + return (*self_0).m_vertical; +} +#[inline] +unsafe fn XeTeXFontInst_getPointSize(mut self_0: *const XeTeXFontInst) -> f32 { + return (*self_0).m_pointSize; +} +#[inline] +unsafe fn XeTeXFontInst_getAscent(mut self_0: *const XeTeXFontInst) -> f32 { + return (*self_0).m_ascent; +} +#[inline] +unsafe fn XeTeXFontInst_getCapHeight(mut self_0: *const XeTeXFontInst) -> f32 { + return (*self_0).m_capHeight; +} +#[inline] +unsafe fn XeTeXFontInst_getXHeight(mut self_0: *const XeTeXFontInst) -> f32 { + return (*self_0).m_xHeight; +} +#[inline] +unsafe fn XeTeXFontInst_getItalicAngle(mut self_0: *const XeTeXFontInst) -> f32 { + return (*self_0).m_italicAngle; +} +#[inline] +unsafe fn XeTeXFontInst_getFilename( + mut self_0: *const XeTeXFontInst, + mut index: *mut uint32_t, +) -> *const libc::c_char { + *index = (*self_0).m_index; + if let Some(f) = (*self_0).m_filename.as_ref() { + f.as_ptr() + } else { + ptr::null() + } +} +#[no_mangle] +pub unsafe fn getGlyphBBoxCache() -> *mut CppStdMap { + static mut cache: *mut CppStdMap = + 0 as *const CppStdMap as *mut CppStdMap; + if cache.is_null() { + cache = CppStdMap_create() + } + return cache; +} +#[no_mangle] +pub unsafe fn getCachedGlyphBBox( + mut fontID: uint16_t, + mut glyphID: uint16_t, + mut bbox: *mut GlyphBBox, +) -> libc::c_int { + let mut sGlyphBoxes: *mut CppStdMap = getGlyphBBoxCache(); + let mut key: uint32_t = ((fontID as uint32_t) << 16i32).wrapping_add(glyphID as libc::c_uint); + if let Some(v) = (*sGlyphBoxes).get(&key) { + *bbox = v.clone(); + 1 + } else { + 0 + } +} +#[no_mangle] +pub unsafe fn cacheGlyphBBox( + mut fontID: uint16_t, + mut glyphID: uint16_t, + mut bbox: *const GlyphBBox, +) { + let mut sGlyphBoxes: *mut CppStdMap = getGlyphBBoxCache(); + let mut key: uint32_t = ((fontID as uint32_t) << 16i32).wrapping_add(glyphID as libc::c_uint); + CppStdMap_put(sGlyphBoxes, key, *bbox); +} +#[inline] +unsafe fn GlyphId_create(mut fontNum: libc::c_int, mut code: libc::c_uint) -> GlyphId { + let mut id: GlyphId = GlyphId { + fontNum: 0, + code: 0, + }; + id.fontNum = fontNum; + id.code = code; + return id; +} +#[no_mangle] +pub unsafe fn getProtrusionFactor(mut side: libc::c_int) -> *mut ProtrusionFactor { + static mut leftProt: *mut ProtrusionFactor = + 0 as *const ProtrusionFactor as *mut ProtrusionFactor; + static mut rightProt: *mut ProtrusionFactor = + 0 as *const ProtrusionFactor as *mut ProtrusionFactor; + let mut container: *mut ProtrusionFactor = 0 as *mut ProtrusionFactor; + match side { + 0 => { + if leftProt.is_null() { + leftProt = CppStdMap_create() + } + container = leftProt + // we should not reach here + } + 1 => { + if rightProt.is_null() { + rightProt = CppStdMap_create() + } + container = rightProt + } + _ => { + unreachable!(); + } + } + return container; +} +#[no_mangle] +pub unsafe fn set_cp_code( + mut fontNum: libc::c_int, + mut code: libc::c_uint, + mut side: libc::c_int, + mut value: libc::c_int, +) { + let mut id: GlyphId = GlyphId_create(fontNum, code); + let mut container: *mut ProtrusionFactor = getProtrusionFactor(side); + CppStdMap_put(container, id, value); +} +#[no_mangle] +pub unsafe fn get_cp_code( + mut fontNum: libc::c_int, + mut code: libc::c_uint, + mut side: libc::c_int, +) -> libc::c_int { + let mut id: GlyphId = GlyphId_create(fontNum, code); + let mut container: *mut ProtrusionFactor = getProtrusionFactor(side); + (*container).get(&id).cloned().unwrap_or(0) +} +/* ******************************************************************/ +#[no_mangle] +pub unsafe fn terminate_font_manager() { + XeTeXFontMgr_Terminate(); +} +#[no_mangle] +pub unsafe fn destroy_font_manager() { + XeTeXFontMgr_Destroy(); +} + +#[no_mangle] +pub unsafe fn createFont(mut fontRef: PlatformFontRef, mut pointSize: Fixed) -> *mut XeTeXFontInst { + let mut status: libc::c_int = 0i32; + let mut font: *mut XeTeXFontInst; + #[cfg(not(target_os = "macos"))] + { + let mut pathname: *mut FcChar8 = 0 as *mut FcChar8; + FcPatternGetString( + fontRef as *const FcPattern, + b"file\x00" as *const u8 as *const libc::c_char, + 0i32, + &mut pathname, + ); + let mut index: libc::c_int = 0; + FcPatternGetInteger( + fontRef as *const FcPattern, + b"index\x00" as *const u8 as *const libc::c_char, + 0i32, + &mut index, + ); + font = XeTeXFontInst_create( + CStr::from_ptr(pathname as *const libc::c_char), + index, + Fix2D(pointSize) as f32, + &mut status, + ); + } + #[cfg(target_os = "macos")] + { + let mac_font = XeTeXFontInst_Mac_create(fontRef, Fix2D(pointSize) as f32, &mut status); + // XXX: this only works because free() uses addresses only, and super_ is the first field. + font = &mut (*mac_font).super_; + } + if status != 0i32 { + XeTeXFontInst_delete(font); + return ptr::null_mut(); + } + font +} + +#[no_mangle] +pub unsafe fn createFontFromFile( + filename: &CStr, + index: libc::c_int, + pointSize: Fixed, +) -> *mut XeTeXFontInst { + let mut status: libc::c_int = 0i32; + let mut font: *mut XeTeXFontInst = + XeTeXFontInst_create(filename, index, Fix2D(pointSize) as f32, &mut status); + if status != 0i32 { + XeTeXFontInst_delete(font); + return ptr::null_mut(); + } + return font; +} + +#[no_mangle] +pub unsafe fn setFontLayoutDir(mut font: *mut XeTeXFontInst, mut vertical: libc::c_int) { + XeTeXFontInst_setLayoutDirVertical(font, vertical != 0i32); +} + +#[no_mangle] +pub unsafe fn findFontByName( + mut name: &CStr, + mut var: Option<&mut String>, + mut size: f64, + shaperRequest: &mut Option, +) -> PlatformFontRef { + return XeTeXFontMgr_findFont( + XeTeXFontMgr_GetFontManager(), + name, + var, + size, + shaperRequest, + ); +} + +#[no_mangle] +pub unsafe fn getFullName(mut fontRef: PlatformFontRef) -> *const libc::c_char { + return XeTeXFontMgr_getFullName(XeTeXFontMgr_GetFontManager(), fontRef); +} +#[no_mangle] +pub unsafe fn getDesignSize(mut font: *mut XeTeXFontInst) -> f64 { + return XeTeXFontMgr_getDesignSize(XeTeXFontMgr_GetFontManager(), font); +} +#[no_mangle] +pub unsafe fn getFontFilename( + mut engine: XeTeXLayoutEngine, + mut index: *mut uint32_t, +) -> *mut libc::c_char { + xstrdup(XeTeXFontInst_getFilename((*engine).font, index)) +} +#[no_mangle] +pub unsafe fn getFontRef(mut engine: XeTeXLayoutEngine) -> PlatformFontRef { + return (*engine).fontRef; +} + +#[no_mangle] +pub unsafe fn deleteFont(mut font: *mut XeTeXFontInst) { + XeTeXFontInst_delete(font); +} + +#[no_mangle] +pub unsafe fn getFontTablePtr( + mut font: *mut XeTeXFontInst, + mut tableTag: uint32_t, +) -> *mut libc::c_void { + return XeTeXFontInst_getFontTable(font, tableTag); +} + +#[no_mangle] +pub unsafe fn getSlant(mut font: *mut XeTeXFontInst) -> Fixed { + let mut italAngle: f32 = XeTeXFontInst_getItalicAngle(font); + let radians = -italAngle as f64 * std::f64::consts::PI / 180.0f64; + return D2Fix(radians.tan()); +} + +unsafe fn getLargerScriptListTable( + mut font: *mut XeTeXFontInst, + mut scriptList: *mut *mut hb_tag_t, +) -> libc::c_uint { + use crate::bridge::size_t; + let mut rval: libc::c_uint = 0i32 as libc::c_uint; + let mut face: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(font)); + let mut scriptListSub: *mut hb_tag_t = 0 as *mut hb_tag_t; + let mut scriptListPos: *mut hb_tag_t = 0 as *mut hb_tag_t; + let mut scriptCountSub: libc::c_uint = hb_ot_layout_table_get_script_tags( + face, + ft_make_tag(b"GSUB"), + 0i32 as libc::c_uint, + 0 as *mut libc::c_uint, + 0 as *mut hb_tag_t, + ); + scriptListSub = xcalloc( + scriptCountSub as size_t, + ::std::mem::size_of::<*mut hb_tag_t>() as _, + ) as *mut hb_tag_t; + hb_ot_layout_table_get_script_tags( + face, + ft_make_tag(b"GSUB"), + 0i32 as libc::c_uint, + &mut scriptCountSub, + scriptListSub, + ); + let mut scriptCountPos: libc::c_uint = hb_ot_layout_table_get_script_tags( + face, + ft_make_tag(b"GPOS"), + 0i32 as libc::c_uint, + 0 as *mut libc::c_uint, + 0 as *mut hb_tag_t, + ); + scriptListPos = xcalloc( + scriptCountPos as size_t, + ::std::mem::size_of::<*mut hb_tag_t>() as _, + ) as *mut hb_tag_t; + hb_ot_layout_table_get_script_tags( + face, + ft_make_tag(b"GSUB"), + 0i32 as libc::c_uint, + &mut scriptCountPos, + scriptListPos, + ); + if scriptCountSub > scriptCountPos { + if !scriptList.is_null() { + *scriptList = scriptListSub + } + rval = scriptCountSub + } else { + if !scriptList.is_null() { + *scriptList = scriptListPos + } + rval = scriptCountPos + } + return rval; +} +#[no_mangle] +pub unsafe fn countScripts(mut font: *mut XeTeXFontInst) -> libc::c_uint { + return getLargerScriptListTable(font, 0 as *mut *mut hb_tag_t); +} +#[no_mangle] +pub unsafe fn getIndScript(mut font: *mut XeTeXFontInst, mut index: libc::c_uint) -> hb_tag_t { + let mut rval: hb_tag_t = 0i32 as hb_tag_t; + let mut scriptList: *mut hb_tag_t = 0 as *mut hb_tag_t; + let mut scriptCount: libc::c_uint = getLargerScriptListTable(font, &mut scriptList); + if !scriptList.is_null() { + if index < scriptCount { + rval = *scriptList.offset(index as isize) + } + } + return rval; +} +#[no_mangle] +pub unsafe fn countLanguages(mut font: *mut XeTeXFontInst, mut script: hb_tag_t) -> libc::c_uint { + let mut rval: libc::c_uint = 0i32 as libc::c_uint; + let mut face: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(font)); + let mut scriptList: *mut hb_tag_t = 0 as *mut hb_tag_t; + let mut scriptCount: libc::c_uint = getLargerScriptListTable(font, &mut scriptList); + if !scriptList.is_null() { + let mut i: libc::c_uint = 0i32 as libc::c_uint; + while i < scriptCount { + if *scriptList.offset(i as isize) == script { + rval = rval.wrapping_add(hb_ot_layout_script_get_language_tags( + face, + ft_make_tag(b"GSUB"), + i, + 0i32 as libc::c_uint, + 0 as *mut libc::c_uint, + 0 as *mut hb_tag_t, + )); + rval = rval.wrapping_add(hb_ot_layout_script_get_language_tags( + face, + ft_make_tag(b"GPOS"), + i, + 0i32 as libc::c_uint, + 0 as *mut libc::c_uint, + 0 as *mut hb_tag_t, + )); + break; + } else { + i = i.wrapping_add(1) + } + } + } + return rval; +} +#[no_mangle] +pub unsafe fn getIndLanguage( + mut font: *mut XeTeXFontInst, + mut script: hb_tag_t, + mut index: libc::c_uint, +) -> hb_tag_t { + use crate::bridge::size_t; + let mut rval: hb_tag_t = 0i32 as hb_tag_t; + let mut face: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(font)); + let mut scriptList: *mut hb_tag_t = 0 as *mut hb_tag_t; + let mut scriptCount: libc::c_uint = getLargerScriptListTable(font, &mut scriptList); + if !scriptList.is_null() { + let mut i: libc::c_uint = 0i32 as libc::c_uint; + while i < scriptCount { + if *scriptList.offset(i as isize) == script { + let mut langCount: libc::c_uint = 0; + let mut langList: *mut hb_tag_t = 0 as *mut hb_tag_t; + langCount = hb_ot_layout_script_get_language_tags( + face, + ft_make_tag(b"GSUB"), + i, + 0i32 as libc::c_uint, + 0 as *mut libc::c_uint, + 0 as *mut hb_tag_t, + ); + langList = xcalloc( + langCount as size_t, + ::std::mem::size_of::<*mut hb_tag_t>() as _, + ) as *mut hb_tag_t; + hb_ot_layout_script_get_language_tags( + face, + ft_make_tag(b"GSUB"), + i, + 0i32 as libc::c_uint, + &mut langCount, + langList, + ); + if index < langCount { + rval = *langList.offset(index as isize); + break; + } else { + free(langList as *mut libc::c_void); + langCount = hb_ot_layout_script_get_language_tags( + face, + ft_make_tag(b"GPOS"), + i, + 0i32 as libc::c_uint, + 0 as *mut libc::c_uint, + 0 as *mut hb_tag_t, + ); + langList = xcalloc( + langCount as size_t, + ::std::mem::size_of::<*mut hb_tag_t>() as _, + ) as *mut hb_tag_t; + hb_ot_layout_script_get_language_tags( + face, + ft_make_tag(b"GPOS"), + i, + 0i32 as libc::c_uint, + &mut langCount, + langList, + ); + if index < langCount { + rval = *langList.offset(index as isize); + break; + } else { + free(langList as *mut libc::c_void); + } + } + } + i = i.wrapping_add(1) + } + } + return rval; +} +#[no_mangle] +pub unsafe fn countFeatures( + mut font: *mut XeTeXFontInst, + mut script: hb_tag_t, + mut language: hb_tag_t, +) -> libc::c_uint { + let mut rval: libc::c_uint = 0i32 as libc::c_uint; + let mut face: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(font)); + let mut i: libc::c_int = 0i32; + while i < 2i32 { + let mut scriptIndex: libc::c_uint = 0; + let mut langIndex: libc::c_uint = 0i32 as libc::c_uint; + let mut tableTag: hb_tag_t = if i == 0i32 { + ft_make_tag(b"GSUB") + } else { + ft_make_tag(b"GPOS") + }; + if hb_ot_layout_table_find_script(face, tableTag, script, &mut scriptIndex) != 0 { + if hb_ot_layout_script_find_language( + face, + tableTag, + scriptIndex, + language, + &mut langIndex, + ) != 0 + || language == 0i32 as libc::c_uint + { + rval = rval.wrapping_add(hb_ot_layout_language_get_feature_tags( + face, + tableTag, + scriptIndex, + langIndex, + 0i32 as libc::c_uint, + 0 as *mut libc::c_uint, + 0 as *mut hb_tag_t, + )) + } + } + i += 1 + } + return rval; +} +#[no_mangle] +pub unsafe fn getIndFeature( + mut font: *mut XeTeXFontInst, + mut script: hb_tag_t, + mut language: hb_tag_t, + mut index: libc::c_uint, +) -> hb_tag_t { + use crate::bridge::size_t; + let mut rval: hb_tag_t = 0i32 as hb_tag_t; + let mut face: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(font)); + let mut i: libc::c_int = 0i32; + while i < 2i32 { + let mut scriptIndex: libc::c_uint = 0; + let mut langIndex: libc::c_uint = 0i32 as libc::c_uint; + let mut tableTag: hb_tag_t = if i == 0i32 { + ft_make_tag(b"GSUB") + } else { + ft_make_tag(b"GPOS") + }; + if hb_ot_layout_table_find_script(face, tableTag, script, &mut scriptIndex) != 0 { + if hb_ot_layout_script_find_language( + face, + tableTag, + scriptIndex, + language, + &mut langIndex, + ) != 0 + || language == 0i32 as libc::c_uint + { + let mut featCount: libc::c_uint = hb_ot_layout_language_get_feature_tags( + face, + tableTag, + scriptIndex, + langIndex, + 0i32 as libc::c_uint, + 0 as *mut libc::c_uint, + 0 as *mut hb_tag_t, + ); + let mut featList: *mut hb_tag_t = xcalloc( + featCount as size_t, + ::std::mem::size_of::<*mut hb_tag_t>() as _, + ) as *mut hb_tag_t; + hb_ot_layout_language_get_feature_tags( + face, + tableTag, + scriptIndex, + langIndex, + 0i32 as libc::c_uint, + &mut featCount, + featList, + ); + if index < featCount { + rval = *featList.offset(index as isize); + break; + } else { + index = index.wrapping_sub(featCount) + } + } + } + i += 1 + } + return rval; +} +#[no_mangle] +pub unsafe fn countGraphiteFeatures(engine: &XeTeXLayoutEngine_rec) -> uint32_t { + let mut rval: uint32_t = 0i32 as uint32_t; + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(engine.font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + rval = gr_face_n_fref(grFace) as uint32_t + } + return rval; +} +#[no_mangle] +pub unsafe fn getGraphiteFeatureCode( + engine: &XeTeXLayoutEngine_rec, + mut index: uint32_t, +) -> uint32_t { + let mut rval: uint32_t = 0i32 as uint32_t; + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + let mut feature: *const gr_feature_ref = gr_face_fref(grFace, index as gr_uint16); + rval = gr_fref_id(feature) + } + return rval; +} + +#[no_mangle] +pub unsafe fn countGraphiteFeatureSettings( + engine: &XeTeXLayoutEngine_rec, + mut featureID: uint32_t, +) -> uint32_t { + let mut rval: uint32_t = 0i32 as uint32_t; + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); + rval = gr_fref_n_values(feature) as uint32_t + } + return rval; +} + +#[no_mangle] +pub unsafe fn getGraphiteFeatureSettingCode( + engine: &XeTeXLayoutEngine_rec, + mut featureID: uint32_t, + mut index: uint32_t, +) -> uint32_t { + let mut rval: uint32_t = 0i32 as uint32_t; + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(engine.font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); + rval = gr_fref_value(feature, index as gr_uint16) as uint32_t + } + return rval; +} + +#[no_mangle] +pub unsafe fn getGraphiteFeatureDefaultSetting( + engine: &XeTeXLayoutEngine_rec, + mut featureID: uint32_t, +) -> uint32_t { + let mut rval: uint32_t = 0i32 as uint32_t; + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(engine.font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); + let mut featureValues: *mut gr_feature_val = gr_face_featureval_for_lang( + grFace, + hb_tag_from_string( + hb_language_to_string(engine.language), + strlen(hb_language_to_string(engine.language)) as libc::c_int, + ), + ); + rval = gr_fref_feature_value(feature, featureValues) as uint32_t + } + return rval; +} +#[no_mangle] +pub unsafe fn getGraphiteFeatureLabel( + engine: &XeTeXLayoutEngine_rec, + mut featureID: uint32_t, +) -> *mut libc::c_char { + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); + let mut len: uint32_t = 0i32 as uint32_t; + let mut langID: uint16_t = 0x409i32 as uint16_t; + return gr_fref_label(feature, &mut langID, gr_utf8, &mut len) as *mut libc::c_char; + } + return 0 as *mut libc::c_char; +} +#[no_mangle] +pub unsafe fn getGraphiteFeatureSettingLabel( + engine: &XeTeXLayoutEngine_rec, + featureID: uint32_t, + settingID: uint32_t, +) -> *mut libc::c_char { + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); + let mut i: libc::c_int = 0i32; + while i < gr_fref_n_values(feature) as libc::c_int { + if settingID as libc::c_int == gr_fref_value(feature, i as gr_uint16) as libc::c_int { + let mut len: uint32_t = 0i32 as uint32_t; + let mut langID: uint16_t = 0x409i32 as uint16_t; + return gr_fref_value_label(feature, i as gr_uint16, &mut langID, gr_utf8, &mut len) + as *mut libc::c_char; + } + i += 1 + } + } + return 0 as *mut libc::c_char; +} +#[no_mangle] +pub unsafe fn findGraphiteFeature( + engine: &XeTeXLayoutEngine_rec, + mut s: *const libc::c_char, + mut e: *const libc::c_char, + mut f: *mut hb_tag_t, + mut v: *mut libc::c_int, +) -> bool +/* s...e is a "feature=setting" string; look for this in the font */ { + let mut tmp: libc::c_long = 0; + *f = 0i32 as hb_tag_t; + *v = 0i32; + while *s as libc::c_int == ' ' as i32 || *s as libc::c_int == '\t' as i32 { + s = s.offset(1) + } + let mut cp: *const libc::c_char = s; + while cp < e && *cp as libc::c_int != '=' as i32 { + cp = cp.offset(1) + } + tmp = findGraphiteFeatureNamed( + engine, + s, + cp.wrapping_offset_from(s) as libc::c_long as libc::c_int, + ); + *f = tmp as hb_tag_t; + if tmp == -1i32 as libc::c_long { + return 0i32 != 0; + } + cp = cp.offset(1); + while cp < e && (*cp as libc::c_int == ' ' as i32 || *cp as libc::c_int == '\t' as i32) { + cp = cp.offset(1) + } + if cp == e { + /* no setting was specified */ + return 0i32 != 0; + } + *v = findGraphiteFeatureSettingNamed( + engine, + *f, + cp, + e.wrapping_offset_from(cp) as libc::c_long as libc::c_int, + ) as libc::c_int; + if *v == -1i32 { + return 0i32 != 0; + } + return 1i32 != 0; +} +#[no_mangle] +pub unsafe fn findGraphiteFeatureNamed( + engine: &XeTeXLayoutEngine_rec, + mut name: *const libc::c_char, + mut namelength: libc::c_int, +) -> libc::c_long { + use crate::bridge::size_t; + let mut rval: libc::c_long = -1i32 as libc::c_long; + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + let mut i: libc::c_int = 0i32; + while i < gr_face_n_fref(grFace) as libc::c_int { + let mut feature: *const gr_feature_ref = gr_face_fref(grFace, i as gr_uint16); + let mut len: uint32_t = 0i32 as uint32_t; + let mut langID: uint16_t = 0x409i32 as uint16_t; + // the first call is to get the length of the string + gr_fref_label(feature, &mut langID, gr_utf8, &mut len); + let mut label: *mut libc::c_char = xmalloc(len as size_t) as *mut libc::c_char; + label = gr_fref_label(feature, &mut langID, gr_utf8, &mut len) as *mut libc::c_char; + if strncmp(label, name, namelength as libc::c_ulong) == 0i32 { + rval = gr_fref_id(feature) as libc::c_long; + gr_label_destroy(label as *mut libc::c_void); + break; + } else { + gr_label_destroy(label as *mut libc::c_void); + i += 1 + } + } + } + return rval; +} +#[no_mangle] +pub unsafe fn findGraphiteFeatureSettingNamed( + engine: &XeTeXLayoutEngine_rec, + mut id: uint32_t, + mut name: *const libc::c_char, + mut namelength: libc::c_int, +) -> libc::c_long { + use crate::bridge::size_t; + let mut rval: libc::c_long = -1i32 as libc::c_long; + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont(engine.font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + if !grFace.is_null() { + let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, id); + let mut i: libc::c_int = 0i32; + while i < gr_fref_n_values(feature) as libc::c_int { + let mut len: uint32_t = 0i32 as uint32_t; + let mut langID: uint16_t = 0x409i32 as uint16_t; + // the first call is to get the length of the string + gr_fref_value_label(feature, i as gr_uint16, &mut langID, gr_utf8, &mut len); + let mut label: *mut libc::c_char = xmalloc(len as size_t) as *mut libc::c_char; + label = gr_fref_value_label(feature, i as gr_uint16, &mut langID, gr_utf8, &mut len) + as *mut libc::c_char; + if strncmp(label, name, namelength as libc::c_ulong) == 0i32 { + rval = gr_fref_value(feature, i as gr_uint16) as libc::c_long; + gr_label_destroy(label as *mut libc::c_void); + break; + } else { + gr_label_destroy(label as *mut libc::c_void); + i += 1 + } + } + } + return rval; +} +#[no_mangle] +pub unsafe fn getGlyphWidth(mut font: *mut XeTeXFontInst, mut gid: uint32_t) -> f32 { + return XeTeXFontInst_getGlyphWidth(font, gid as GlyphID); +} +#[no_mangle] +pub unsafe fn countGlyphs(mut font: *mut XeTeXFontInst) -> libc::c_uint { + return XeTeXFontInst_getNumGlyphs(font) as libc::c_uint; +} +#[no_mangle] +pub unsafe fn getFontInst(mut engine: XeTeXLayoutEngine) -> *mut XeTeXFontInst { + return (*engine).font; +} +#[no_mangle] +pub unsafe fn getExtendFactor(mut engine: XeTeXLayoutEngine) -> f32 { + return (*engine).extend; +} +#[no_mangle] +pub unsafe fn getSlantFactor(mut engine: XeTeXLayoutEngine) -> f32 { + return (*engine).slant; +} +#[no_mangle] +pub unsafe fn getEmboldenFactor(mut engine: XeTeXLayoutEngine) -> f32 { + return (*engine).embolden; +} + +#[no_mangle] +pub unsafe fn createLayoutEngine( + fontRef: PlatformFontRef, + font: *mut XeTeXFontInst, + script: hb_tag_t, + language_s: *mut libc::c_char, + features: *mut hb_feature_t, + nFeatures: libc::c_int, + shapers: Option, + rgbValue: uint32_t, + extend: f32, + slant: f32, + embolden: f32, + shaperRequest: Option, +) -> XeTeXLayoutEngine_rec { + // For Graphite fonts treat the language as BCP 47 tag, for OpenType we + // treat it as a OT language tag for backward compatibility with pre-0.9999 + // XeTeX. + let language = if shaperRequest == Some(ShaperRequest::Graphite) { + hb_language_from_string(language_s, -1i32) + } else { + hb_ot_tag_to_language(hb_tag_from_string(language_s, -1i32)) + }; + free(language_s as *mut libc::c_void); + + // HarfBuzz gives graphite2 shaper a priority, so that for hybrid + // Graphite/OpenType fonts, Graphite will be used. However, pre-0.9999 + // XeTeX preferred OpenType over Graphite, so we are doing the same + // here for sake of backward compatibility. Since "ot" shaper never + // fails, we set the shaper list to just include it. + let shaper_list = shapers + .unwrap_or_else(|| { + let mut default_ot = CStringListBuilder::new(); + default_ot.push_non_null_terminated(&b"ot"[..]); + default_ot + }) + .freeze(); + + XeTeXLayoutEngine_rec { + font, + fontRef, + script, + language, + features, + shaper_list, + shaper: ptr::null_mut(), + nFeatures, + rgbValue, + extend, + slant, + embolden, + hbBuffer: hb_buffer_create(), + } +} + +impl Drop for XeTeXLayoutEngine_rec { + fn drop(&mut self) { + unsafe { + hb_buffer_destroy(self.hbBuffer); + XeTeXFontInst_delete(self.font); + if !self.shaper.is_null() { + free(self.shaper as *mut libc::c_void); + } + } + } +} + +#[no_mangle] +pub unsafe fn deleteLayoutEngine(mut engine: XeTeXLayoutEngine) {} + +unsafe fn _decompose_compat( + mut ufuncs: *mut hb_unicode_funcs_t, + mut u: hb_codepoint_t, + mut decomposed: *mut hb_codepoint_t, + mut user_data: *mut libc::c_void, +) -> libc::c_uint { + return 0i32 as libc::c_uint; +} + +unsafe fn _get_unicode_funcs() -> *mut hb_unicode_funcs_t { + static mut ufuncs: *mut hb_unicode_funcs_t = + 0 as *const hb_unicode_funcs_t as *mut hb_unicode_funcs_t; + if ufuncs.is_null() { + ufuncs = hb_unicode_funcs_create(hb_icu_get_unicode_funcs()) + } + hb_unicode_funcs_set_decompose_compatibility_func( + ufuncs, + Some( + _decompose_compat + as unsafe fn( + _: *mut hb_unicode_funcs_t, + _: hb_codepoint_t, + _: *mut hb_codepoint_t, + _: *mut libc::c_void, + ) -> libc::c_uint, + ), + 0 as *mut libc::c_void, + None, + ); + return ufuncs; +} +static mut hbUnicodeFuncs: *mut hb_unicode_funcs_t = + 0 as *const hb_unicode_funcs_t as *mut hb_unicode_funcs_t; + +impl XeTeXLayoutEngine_rec { + pub unsafe fn gr_font_get_named(&self, what: i32) -> i32 { + use crate::xetex_ini::{name_of_file, name_length}; + let mut rval: i64 = -1i32 as i64; + match what { + 10 => rval = findGraphiteFeatureNamed(self, name_of_file, name_length), + _ => {} + } + rval as i32 + } + + pub unsafe fn gr_font_get_named_1( + &self, + mut what: i32, + mut param: i32, + ) -> i32 { + use crate::xetex_ini::{name_of_file, name_length}; + let mut rval: i64 = -1i32 as i64; + match what { + 14 => { + rval = findGraphiteFeatureSettingNamed(self, param as u32, name_of_file, name_length) + } + _ => {} + } + rval as i32 + } + + pub unsafe fn layoutChars( + &mut self, + chars: *const u16, + offset: i32, + count: i32, + max: i32, + rightToLeft: bool, + ) -> libc::c_int { + use crate::bridge::size_t; + let mut res: bool = false; + let mut script: hb_script_t = HB_SCRIPT_INVALID; + let mut direction: hb_direction_t = HB_DIRECTION_LTR; + let mut segment_props: hb_segment_properties_t = hb_segment_properties_t { + direction: HB_DIRECTION_INVALID, + script: HB_SCRIPT_INVALID, + language: 0 as *const hb_language_impl_t, + reserved1: 0 as *mut libc::c_void, + reserved2: 0 as *mut libc::c_void, + }; + let mut shape_plan: *mut hb_shape_plan_t = 0 as *mut hb_shape_plan_t; + let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(self.font); + let mut hbFace: *mut hb_face_t = hb_font_get_face(hbFont); + if XeTeXFontInst_getLayoutDirVertical(self.font) { + direction = HB_DIRECTION_TTB + } else if rightToLeft { + direction = HB_DIRECTION_RTL + } + script = hb_ot_tag_to_script(self.script); + if hbUnicodeFuncs.is_null() { + hbUnicodeFuncs = _get_unicode_funcs() + } + hb_buffer_reset(self.hbBuffer); + hb_buffer_set_unicode_funcs(self.hbBuffer, hbUnicodeFuncs); + hb_buffer_add_utf16(self.hbBuffer, chars, max, offset as libc::c_uint, count); + hb_buffer_set_direction(self.hbBuffer, direction); + hb_buffer_set_script(self.hbBuffer, script); + hb_buffer_set_language(self.hbBuffer, self.language); + hb_buffer_guess_segment_properties(self.hbBuffer); + hb_buffer_get_segment_properties(self.hbBuffer, &mut segment_props); + shape_plan = hb_shape_plan_create_cached( + hbFace, + &mut segment_props, + self.features, + self.nFeatures as libc::c_uint, + self.shaper_list.as_ptr(), + ); + res = hb_shape_plan_execute( + shape_plan, + hbFont, + self.hbBuffer, + self.features, + self.nFeatures as libc::c_uint, + ) != 0; + if !self.shaper.is_null() { + free(self.shaper as *mut libc::c_void); + self.shaper = 0 as *mut libc::c_char + } + if res { + self.shaper = strdup(hb_shape_plan_get_shaper(shape_plan)); + hb_buffer_set_content_type(self.hbBuffer, HB_BUFFER_CONTENT_TYPE_GLYPHS); + } else { + // all selected shapers failed, retrying with default + // we don't use _cached here as the cached plain will always fail. + hb_shape_plan_destroy(shape_plan); /* negative is forwards */ + shape_plan = hb_shape_plan_create( + hbFace, + &mut segment_props, + self.features, + self.nFeatures as libc::c_uint, + 0 as *const *const libc::c_char, + ); /* negative is upwards */ + res = hb_shape_plan_execute( + shape_plan, + hbFont, + self.hbBuffer, + self.features, + self.nFeatures as libc::c_uint, + ) != 0; + if res { + self.shaper = strdup(hb_shape_plan_get_shaper(shape_plan)); + hb_buffer_set_content_type(self.hbBuffer, HB_BUFFER_CONTENT_TYPE_GLYPHS); + } else { + panic!("all shapers failed"); + } + } + hb_shape_plan_destroy(shape_plan); + let mut glyphCount: libc::c_int = hb_buffer_get_length(self.hbBuffer) as libc::c_int; + return glyphCount; + } +} + +#[no_mangle] +pub unsafe fn getGlyphs(engine: &XeTeXLayoutEngine_rec, mut glyphs: *mut uint32_t) { + let mut glyphCount: libc::c_int = hb_buffer_get_length((*engine).hbBuffer) as libc::c_int; + let mut hbGlyphs: *mut hb_glyph_info_t = + hb_buffer_get_glyph_infos((*engine).hbBuffer, 0 as *mut libc::c_uint); + let mut i: libc::c_int = 0i32; + while i < glyphCount { + *glyphs.offset(i as isize) = (*hbGlyphs.offset(i as isize)).codepoint; + i += 1 + } +} +#[no_mangle] +pub unsafe fn getGlyphAdvances(engine: &XeTeXLayoutEngine_rec, mut advances: *mut f32) { + let mut glyphCount: libc::c_int = hb_buffer_get_length((*engine).hbBuffer) as libc::c_int; + let mut hbPositions: *mut hb_glyph_position_t = + hb_buffer_get_glyph_positions((*engine).hbBuffer, 0 as *mut libc::c_uint); + let mut i: libc::c_int = 0i32; + while i < glyphCount { + if XeTeXFontInst_getLayoutDirVertical((*engine).font) { + *advances.offset(i as isize) = XeTeXFontInst_unitsToPoints( + (*engine).font, + (*hbPositions.offset(i as isize)).y_advance as f32, + ) + } else { + *advances.offset(i as isize) = XeTeXFontInst_unitsToPoints( + (*engine).font, + (*hbPositions.offset(i as isize)).x_advance as f32, + ) + } + i += 1 + } +} + +#[no_mangle] +pub unsafe fn getGlyphPositions(engine: &XeTeXLayoutEngine_rec, mut positions: *mut FloatPoint) { + let mut glyphCount: libc::c_int = hb_buffer_get_length((*engine).hbBuffer) as libc::c_int; + let mut hbPositions: *mut hb_glyph_position_t = + hb_buffer_get_glyph_positions((*engine).hbBuffer, 0 as *mut libc::c_uint); + let mut x: f32 = 0i32 as f32; + let mut y: f32 = 0i32 as f32; + if XeTeXFontInst_getLayoutDirVertical((*engine).font) { + let mut i: libc::c_int = 0i32; + while i < glyphCount { + (*positions.offset(i as isize)).x = -XeTeXFontInst_unitsToPoints( + (*engine).font, + x + (*hbPositions.offset(i as isize)).y_offset as f32, + ); + (*positions.offset(i as isize)).y = XeTeXFontInst_unitsToPoints( + (*engine).font, + y - (*hbPositions.offset(i as isize)).x_offset as f32, + ); + x += (*hbPositions.offset(i as isize)).y_advance as f32; + y += (*hbPositions.offset(i as isize)).x_advance as f32; + i += 1 + } + (*positions.offset(glyphCount as isize)).x = + -XeTeXFontInst_unitsToPoints((*engine).font, x); + (*positions.offset(glyphCount as isize)).y = XeTeXFontInst_unitsToPoints((*engine).font, y) + } else { + let mut i_0: libc::c_int = 0i32; + while i_0 < glyphCount { + (*positions.offset(i_0 as isize)).x = XeTeXFontInst_unitsToPoints( + (*engine).font, + x + (*hbPositions.offset(i_0 as isize)).x_offset as f32, + ); + (*positions.offset(i_0 as isize)).y = -XeTeXFontInst_unitsToPoints( + (*engine).font, + y + (*hbPositions.offset(i_0 as isize)).y_offset as f32, + ); + x += (*hbPositions.offset(i_0 as isize)).x_advance as f32; + y += (*hbPositions.offset(i_0 as isize)).y_advance as f32; + i_0 += 1 + } + (*positions.offset(glyphCount as isize)).x = XeTeXFontInst_unitsToPoints((*engine).font, x); + (*positions.offset(glyphCount as isize)).y = -XeTeXFontInst_unitsToPoints((*engine).font, y) + } + if (*engine).extend as f64 != 1.0f64 || (*engine).slant as f64 != 0.0f64 { + let mut i_1: libc::c_int = 0i32; + while i_1 <= glyphCount { + (*positions.offset(i_1 as isize)).x = (*positions.offset(i_1 as isize)).x + * (*engine).extend + - (*positions.offset(i_1 as isize)).y * (*engine).slant; + i_1 += 1 + } + }; +} + +#[no_mangle] +pub unsafe fn getDefaultDirection(engine: XeTeXLayoutEngine) -> libc::c_int { + let mut script: hb_script_t = hb_buffer_get_script((*engine).hbBuffer); + if hb_script_get_horizontal_direction(script) as libc::c_uint + == HB_DIRECTION_RTL as libc::c_int as libc::c_uint + { + return 0xffi32; + } else { + return 0xfei32; + }; +} +#[no_mangle] +pub unsafe fn getRgbValue(mut engine: XeTeXLayoutEngine) -> uint32_t { + return (*engine).rgbValue; +} +#[no_mangle] +pub unsafe fn getGlyphBounds(engine: XeTeXLayoutEngine, glyphID: uint32_t, bbox: *mut GlyphBBox) { + let font_info = &*((*engine).font); + + // TODO: xetex_font_info uses u16 (why??????), but glyph IDs should be u32 + if let Some(bb) = font_info.get_glyph_bounds(glyphID as u16) { + ptr::write(bbox, bb); + } + + if (*engine).extend as f64 != 0.0f64 { + (*bbox).xMin *= (*engine).extend; + (*bbox).xMax *= (*engine).extend + }; +} +#[no_mangle] +pub unsafe fn getGlyphWidthFromEngine( + engine: *mut XeTeXLayoutEngine_rec, + mut glyphID: uint32_t, +) -> f32 { + return (*engine).extend * XeTeXFontInst_getGlyphWidth((*engine).font, glyphID as GlyphID); +} +#[no_mangle] +pub unsafe fn getGlyphHeightDepth( + engine: &XeTeXLayoutEngine_rec, + mut glyphID: uint32_t, + mut height: *mut f32, + mut depth: *mut f32, +) { + XeTeXFontInst_getGlyphHeightDepth((*engine).font, glyphID as GlyphID, height, depth); +} + +static mut grSegment: *mut gr_segment = 0 as *const gr_segment as *mut gr_segment; +static mut grPrevSlot: *const gr_slot = 0 as *const gr_slot; +static mut grTextLen: libc::c_int = 0; +#[no_mangle] +pub unsafe fn initGraphiteBreaking( + mut engine: XeTeXLayoutEngine, + mut txtPtr: *const uint16_t, + mut txtLen: libc::c_int, +) -> bool { + let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); + let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); + let mut grFont: *mut gr_font = + hb_graphite2_font_get_gr_font(XeTeXFontInst_getHbFont((*engine).font)); + if !grFace.is_null() && !grFont.is_null() { + if !grSegment.is_null() { + gr_seg_destroy(grSegment); + grSegment = 0 as *mut gr_segment; + grPrevSlot = 0 as *const gr_slot + } + let mut grFeatureValues: *mut gr_feature_val = gr_face_featureval_for_lang( + grFace, + hb_tag_from_string( + hb_language_to_string((*engine).language), + strlen(hb_language_to_string((*engine).language)) as libc::c_int, + ), + ); + let mut nFeatures: libc::c_int = (*engine).nFeatures; + let mut features: *mut hb_feature_t = (*engine).features; + loop { + let fresh2 = nFeatures; + nFeatures = nFeatures - 1; + if !(fresh2 != 0) { + break; + } + let mut fref: *const gr_feature_ref = gr_face_find_fref(grFace, (*features).tag); + if !fref.is_null() { + gr_fref_set_feature_value(fref, (*features).value as gr_uint16, grFeatureValues); + } + features = features.offset(1) + } + grSegment = gr_make_seg( + grFont, + grFace, + (*engine).script, + grFeatureValues, + gr_utf16, + txtPtr as *const libc::c_void, + txtLen as size_t, + 0i32, + ); + grPrevSlot = gr_seg_first_slot(grSegment); + grTextLen = txtLen; + return 1i32 != 0; + } + return 0i32 != 0; +} +#[no_mangle] +pub unsafe fn findNextGraphiteBreak() -> libc::c_int { + let mut ret: libc::c_int = -1i32; + if !grSegment.is_null() { + if !grPrevSlot.is_null() && grPrevSlot != gr_seg_last_slot(grSegment) { + let mut s: *const gr_slot = gr_slot_next_in_segment(grPrevSlot); + while !s.is_null() { + let mut ci: *const gr_char_info = 0 as *const gr_char_info; + let mut bw: libc::c_int = 0; + ci = gr_seg_cinfo(grSegment, gr_slot_index(s)); + bw = gr_cinfo_break_weight(ci); + if bw < gr_breakNone as libc::c_int && bw >= gr_breakBeforeWord as libc::c_int { + grPrevSlot = s; + ret = gr_cinfo_base(ci) as libc::c_int + } else if bw > gr_breakNone as libc::c_int && bw <= gr_breakWord as libc::c_int { + grPrevSlot = gr_slot_next_in_segment(s); + ret = gr_cinfo_base(ci).wrapping_add(1) as libc::c_int + } + if ret != -1i32 { + break; + } + s = gr_slot_next_in_segment(s) + } + if ret == -1i32 { + grPrevSlot = gr_seg_last_slot(grSegment); + ret = grTextLen + } + } + } + return ret; +} +/* ***************************************************************************\ +Part of the XeTeX typesetting system +Copyright (c) 1994-2008 by SIL International +Copyright (c) 2009 by Jonathan Kew +Copyright (c) 2012-2015 by Khaled Hosny + +SIL Author(s): Jonathan Kew + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the copyright holders +shall not be used in advertising or otherwise to promote the sale, +use or other dealings in this Software without prior written +authorization from the copyright holders. +\****************************************************************************/ +/* graphite interface functions... */ +#[no_mangle] +pub unsafe fn usingGraphite(mut engine: XeTeXLayoutEngine) -> bool { + if !(*engine).shaper.is_null() + && strcmp( + b"graphite2\x00" as *const u8 as *const libc::c_char, + (*engine).shaper, + ) == 0i32 + { + return 1i32 != 0; + } else { + return 0i32 != 0; + }; +} +#[no_mangle] +pub unsafe fn usingOpenType(mut engine: XeTeXLayoutEngine) -> bool { + if (*engine).shaper.is_null() + || strcmp( + b"ot\x00" as *const u8 as *const libc::c_char, + (*engine).shaper, + ) == 0i32 + { + return 1i32 != 0; + } else { + return 0i32 != 0; + }; +} +#[no_mangle] +pub unsafe fn isOpenTypeMathFont(mut engine: XeTeXLayoutEngine) -> bool { + return hb_ot_math_has_data(hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font))) != 0; } -#[cfg(not(target_os = "macos"))] -pub type FcPattern = _FcPattern; diff --git a/engine/src/xetex_layout_interface.rs b/engine/src/xetex_layout_interface.rs deleted file mode 100644 index 0c71d2d64..000000000 --- a/engine/src/xetex_layout_interface.rs +++ /dev/null @@ -1,1934 +0,0 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] -use crate::core_memory::{xcalloc, xmalloc}; -use harfbuzz_sys::*; - -use freetype::freetype_sys; - -extern "C" { - #[cfg(target_os = "macos")] - pub type __CTFontDescriptor; - #[cfg(target_os = "macos")] - pub type __CTFont; - pub type XeTeXFont_rec; - pub type gr_face; - pub type gr_font; - pub type gr_feature_ref; - pub type gr_feature_val; - pub type gr_char_info; - pub type gr_segment; - pub type gr_slot; - /* ******************************************************************/ - /* Glyph bounding box cache to speed up \XeTeXuseglyphmetrics mode */ - /* ******************************************************************/ - // key is combined value representing (font_id << 16) + glyph - // value is glyph bounding box in TeX points - #[no_mangle] - fn tan(_: libc::c_double) -> libc::c_double; - #[no_mangle] - fn malloc(_: libc::c_ulong) -> *mut libc::c_void; - #[no_mangle] - fn free(__ptr: *mut libc::c_void); - #[no_mangle] - fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int; - #[no_mangle] - fn strncmp(_: *const libc::c_char, _: *const libc::c_char, _: libc::c_ulong) -> libc::c_int; - #[no_mangle] - fn strdup(_: *const libc::c_char) -> *mut libc::c_char; - #[no_mangle] - fn strlen(_: *const libc::c_char) -> libc::c_ulong; - /* The internal, C/C++ interface: */ - #[no_mangle] - fn _tt_abort(format: *const libc::c_char, _: ...) -> !; - /* tectonic/core-memory.h: basic dynamic memory helpers - Copyright 2016-2018 the Tectonic Project - Licensed under the MIT License. - */ - #[no_mangle] - fn xstrdup(s: *const libc::c_char) -> *mut libc::c_char; - #[no_mangle] - #[cfg(not(target_os = "macos"))] - fn FcPatternGetInteger( - p: *const FcPattern, - object: *const libc::c_char, - n: libc::c_int, - i: *mut libc::c_int, - ) -> FcResult; - #[no_mangle] - #[cfg(not(target_os = "macos"))] - fn FcPatternGetString( - p: *const FcPattern, - object: *const libc::c_char, - n: libc::c_int, - s: *mut *mut FcChar8, - ) -> FcResult; - #[no_mangle] - fn hb_unicode_funcs_set_decompose_compatibility_func( - ufuncs: *mut hb_unicode_funcs_t, - func: hb_unicode_decompose_compatibility_func_t, - user_data: *mut libc::c_void, - destroy: hb_destroy_func_t, - ); - #[no_mangle] - fn hb_ot_layout_script_find_language( - face: *mut hb_face_t, - table_tag: hb_tag_t, - script_index: libc::c_uint, - language_tag: hb_tag_t, - language_index: *mut libc::c_uint, - ) -> hb_bool_t; - - #[no_mangle] - fn gr_face_featureval_for_lang( - pFace: *const gr_face, - langname: gr_uint32, - ) -> *mut gr_feature_val; - #[no_mangle] - fn gr_face_find_fref(pFace: *const gr_face, featId: gr_uint32) -> *const gr_feature_ref; - #[no_mangle] - fn gr_face_n_fref(pFace: *const gr_face) -> gr_uint16; - #[no_mangle] - fn gr_face_fref(pFace: *const gr_face, i: gr_uint16) -> *const gr_feature_ref; - #[no_mangle] - fn gr_fref_feature_value( - pfeatureref: *const gr_feature_ref, - feats: *const gr_feature_val, - ) -> gr_uint16; - #[no_mangle] - fn gr_fref_set_feature_value( - pfeatureref: *const gr_feature_ref, - val: gr_uint16, - pDest: *mut gr_feature_val, - ) -> libc::c_int; - #[no_mangle] - fn gr_fref_id(pfeatureref: *const gr_feature_ref) -> gr_uint32; - #[no_mangle] - fn gr_fref_n_values(pfeatureref: *const gr_feature_ref) -> gr_uint16; - #[no_mangle] - fn gr_fref_value(pfeatureref: *const gr_feature_ref, settingno: gr_uint16) -> gr_int16; - #[no_mangle] - fn gr_fref_label( - pfeatureref: *const gr_feature_ref, - langId: *mut gr_uint16, - utf: gr_encform, - length: *mut gr_uint32, - ) -> *mut libc::c_void; - #[no_mangle] - fn gr_fref_value_label( - pfeatureref: *const gr_feature_ref, - settingno: gr_uint16, - langId: *mut gr_uint16, - utf: gr_encform, - length: *mut gr_uint32, - ) -> *mut libc::c_void; - #[no_mangle] - fn gr_label_destroy(label: *mut libc::c_void); - #[no_mangle] - fn gr_cinfo_break_weight(p: *const gr_char_info) -> libc::c_int; - #[no_mangle] - fn gr_cinfo_base(p: *const gr_char_info) -> size_t; - #[no_mangle] - fn gr_make_seg( - font: *const gr_font, - face: *const gr_face, - script: gr_uint32, - pFeats: *const gr_feature_val, - enc: gr_encform, - pStart: *const libc::c_void, - nChars: size_t, - dir: libc::c_int, - ) -> *mut gr_segment; - #[no_mangle] - fn gr_seg_destroy(p: *mut gr_segment); - #[no_mangle] - fn gr_seg_cinfo(pSeg: *const gr_segment, index: libc::c_uint) -> *const gr_char_info; - #[no_mangle] - fn gr_seg_first_slot(pSeg: *mut gr_segment) -> *const gr_slot; - #[no_mangle] - fn gr_seg_last_slot(pSeg: *mut gr_segment) -> *const gr_slot; - #[no_mangle] - fn gr_slot_next_in_segment(p: *const gr_slot) -> *const gr_slot; - #[no_mangle] - fn gr_slot_index(p: *const gr_slot) -> libc::c_uint; - #[no_mangle] - fn hb_graphite2_face_get_gr_face(face: *mut hb_face_t) -> *mut gr_face; - #[no_mangle] - fn hb_graphite2_font_get_gr_font(font: *mut hb_font_t) -> *mut gr_font; - #[no_mangle] - fn hb_icu_get_unicode_funcs() -> *mut hb_unicode_funcs_t; - #[no_mangle] - fn Fix2D(f: Fixed) -> libc::c_double; - #[no_mangle] - fn D2Fix(d: libc::c_double) -> Fixed; - #[no_mangle] - fn XeTeXFontMgr_GetFontManager() -> *mut XeTeXFontMgr; - #[no_mangle] - fn XeTeXFontMgr_Terminate(); - #[no_mangle] - fn XeTeXFontMgr_Destroy(); - #[no_mangle] - fn XeTeXFontInst_getGlyphItalCorr(self_0: *mut XeTeXFontInst, gid: GlyphID) -> libc::c_float; - #[no_mangle] - fn XeTeXFontInst_getNumGlyphs(self_0: *const XeTeXFontInst) -> uint16_t; - #[no_mangle] - fn XeTeXFontInst_getGlyphWidth(self_0: *mut XeTeXFontInst, gid: GlyphID) -> libc::c_float; - #[no_mangle] - fn XeTeXFontInst_getHbFont(self_0: *const XeTeXFontInst) -> *mut hb_font_t; - #[no_mangle] - fn XeTeXFontInst_getGlyphBounds(self_0: *mut XeTeXFontInst, gid: GlyphID, bbox: *mut GlyphBBox); - #[no_mangle] - fn XeTeXFontInst_getGlyphHeightDepth( - self_0: *mut XeTeXFontInst, - gid: GlyphID, - ht: *mut libc::c_float, - dp: *mut libc::c_float, - ); - #[no_mangle] - fn XeTeXFontInst_getGlyphSidebearings( - self_0: *mut XeTeXFontInst, - gid: GlyphID, - lsb: *mut libc::c_float, - rsb: *mut libc::c_float, - ); - #[no_mangle] - fn XeTeXFontMgr_findFont( - self_0: *mut XeTeXFontMgr, - name: *const libc::c_char, - variant: *mut libc::c_char, - ptSize: libc::c_double, - ) -> PlatformFontRef; - #[no_mangle] - fn XeTeXFontInst_getFontTable(self_0: *const XeTeXFontInst, tag: OTTag) -> *mut libc::c_void; - #[no_mangle] - fn XeTeXFontInst_mapCharToGlyph(self_0: *const XeTeXFontInst, ch: UChar32) -> GlyphID; - #[no_mangle] - fn XeTeXFontMgr_getDesignSize(self_0: *mut XeTeXFontMgr, font: XeTeXFont) -> libc::c_double; - #[no_mangle] - fn XeTeXFontMgr_getFullName( - self_0: *const XeTeXFontMgr, - font: PlatformFontRef, - ) -> *const libc::c_char; - #[no_mangle] - fn XeTeXFontMgr_getReqEngine(self_0: *const XeTeXFontMgr) -> libc::c_char; - #[no_mangle] - fn XeTeXFontMgr_setReqEngine(self_0: *const XeTeXFontMgr, reqEngine: libc::c_char); - #[no_mangle] - fn XeTeXFontInst_setLayoutDirVertical(self_0: *mut XeTeXFontInst, vertical: bool); - #[no_mangle] - fn XeTeXFontInst_delete(self_0: *mut XeTeXFontInst); - #[no_mangle] - fn XeTeXFontInst_create( - pathname: *const libc::c_char, - index: libc::c_int, - pointSize: libc::c_float, - status: *mut libc::c_int, - ) -> *mut XeTeXFontInst; - #[no_mangle] - #[cfg(target_os = "macos")] - fn XeTeXFontInst_Mac_create( - descriptor: CTFontDescriptorRef, - pointSize: libc::c_float, - status: *mut libc::c_int, - ) -> *mut XeTeXFontInst_Mac; - #[no_mangle] - fn XeTeXFontInst_unitsToPoints( - self_0: *const XeTeXFontInst, - units: libc::c_float, - ) -> libc::c_float; - #[no_mangle] - fn XeTeXFontInst_mapGlyphToIndex( - self_0: *const XeTeXFontInst, - glyphName: *const libc::c_char, - ) -> GlyphID; - #[no_mangle] - fn XeTeXFontInst_getGlyphName( - self_0: *mut XeTeXFontInst, - gid: GlyphID, - nameLen: *mut libc::c_int, - ) -> *const libc::c_char; - #[no_mangle] - fn XeTeXFontInst_getLastCharCode(self_0: *mut XeTeXFontInst) -> UChar32; - #[no_mangle] - fn XeTeXFontInst_getFirstCharCode(self_0: *mut XeTeXFontInst) -> UChar32; - -} - -pub mod collection_types { - use super::size_t; - use super::{GlyphBBox, GlyphId, PlatformFontRef, XeTeXFontMgrFamily, XeTeXFontMgrFont}; - use core::ptr::NonNull; - use std::collections::{BTreeMap, LinkedList, VecDeque}; - use std::ffi::CStr; - use std::ffi::CString; - - pub type CppStdString = CString; - pub type CppStdListOfString = VecDeque; - pub type CppStdMap = BTreeMap; - - pub fn CppStdString_create() -> *mut CppStdString { - Box::into_raw(Box::new(CString::default())) - } - - pub unsafe fn CppStdString_delete(self_0: *mut CppStdString) { - let _: Box = Box::from_raw(self_0); - } - pub unsafe fn CppStdString_length(self_0: *const CppStdString) -> libc::size_t { - self_0.as_ref().unwrap().to_bytes().len() as _ - } - pub unsafe fn CppStdString_cstr(self_0: *const CppStdString) -> *const libc::c_char { - let v = self_0.as_ref().unwrap(); - v.as_ptr() - } - - pub fn CppStdListOfString_create() -> *mut CppStdListOfString { - Box::into_raw(Box::new(CppStdListOfString::default())) - } - - pub unsafe fn CppStdListOfString_delete(self_0: *mut CppStdListOfString) { - let _: Box = Box::from_raw(self_0); - } - - pub fn CppStdMap_create() -> *mut CppStdMap { - Box::into_raw(Box::new(CppStdMap::default())) - } - - pub unsafe fn CppStdMap_put(self_0: *mut CppStdMap, key: K, val: V) { - (*self_0).insert(key, val); - } - - pub unsafe fn CppStdMap_put_with_string_key( - self_0: *mut CppStdMap, - key: *const libc::c_char, - val: V, - ) { - use std::ffi::CStr; - let key = CStr::from_ptr(key); - match (*self_0).get_mut(key) { - Some(v) => { - *v = val; - } - None => { - (*self_0).insert(key.to_owned(), val); - } - } - } - - pub unsafe fn CppStdMap_delete(self_0: *mut CppStdMap) { - let _: Box> = Box::from_raw(self_0); - } - - pub unsafe fn CppStdString_last(self_0: *const CppStdString) -> libc::c_char { - let val = &*self_0; - *val.to_bytes().last().expect("must not be empty") as libc::c_char - } - pub unsafe fn CppStdString_clone(self_0: *const CppStdString) -> *mut CppStdString { - let v: Box = Box::new((*self_0).clone()); - Box::into_raw(v) - } - - pub unsafe fn CppStdString_append_const_char_ptr( - self_0: *mut CppStdString, - val: *const libc::c_char, - ) { - use std::mem::swap; - let o: &mut CppStdString = &mut *self_0; - let mut v: CppStdString = Default::default(); - swap(o, &mut v); - let mut u = v.into_bytes(); - u.extend(CStr::from_ptr(val).to_bytes()); - v = CString::from_vec_unchecked(u); - swap(o, &mut v); - } - - pub unsafe fn CppStdString_assign_from_const_char_ptr( - self_0: *mut CppStdString, - val: *const libc::c_char, - ) { - let o: &mut CppStdString = &mut *self_0; - *o = CStr::from_ptr(val).to_owned(); - } - - pub unsafe fn CppStdString_assign_n_chars( - self_0: *mut CppStdString, - val: *const libc::c_char, - count: usize, - ) { - let o: &mut CppStdString = &mut *self_0; - let slice = std::slice::from_raw_parts(val as *const u8, count); - *o = CString::from_vec_unchecked(slice.to_owned()); - } -} - -use self::collection_types::*; - -pub type size_t = usize; -pub type int8_t = i8; -pub type int16_t = i16; -pub type int32_t = i32; -pub type uint8_t = u8; -pub type uint16_t = u16; -pub type uint32_t = u32; - -pub type UChar32 = int32_t; -#[cfg(not(target_os = "macos"))] -pub type FcChar8 = libc::c_uchar; -#[cfg(not(target_os = "macos"))] -use crate::xetex_font_manager::imp::{FcPattern, FcResult}; - -pub type hb_unicode_decompose_compatibility_func_t = Option< - unsafe extern "C" fn( - _: *mut hb_unicode_funcs_t, - _: hb_codepoint_t, - _: *mut hb_codepoint_t, - _: *mut libc::c_void, - ) -> libc::c_uint, ->; - -pub type OTTag = uint32_t; -pub type GlyphID = uint16_t; -pub type Fixed = i32; -#[cfg(target_os = "macos")] -pub type CTFontDescriptorRef = *const __CTFontDescriptor; -#[cfg(target_os = "macos")] -pub type CTFontRef = *const __CTFont; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct FloatPoint { - pub x: libc::c_float, - pub y: libc::c_float, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct GlyphBBox { - pub xMin: libc::c_float, - pub yMin: libc::c_float, - pub xMax: libc::c_float, - pub yMax: libc::c_float, -} -#[cfg(not(target_os = "macos"))] -pub type PlatformFontRef = *mut FcPattern; -#[cfg(target_os = "macos")] -pub type PlatformFontRef = CTFontDescriptorRef; -pub type XeTeXFont = *mut XeTeXFont_rec; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXLayoutEngine_rec { - pub font: *mut XeTeXFontInst, - pub fontRef: PlatformFontRef, - pub script: hb_tag_t, - pub language: hb_language_t, - pub features: *mut hb_feature_t, - pub ShaperList: *mut *mut libc::c_char, - pub shaper: *mut libc::c_char, - pub nFeatures: libc::c_int, - pub rgbValue: uint32_t, - pub extend: libc::c_float, - pub slant: libc::c_float, - pub embolden: libc::c_float, - pub hbBuffer: *mut hb_buffer_t, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontInst { - pub m_unitsPerEM: libc::c_ushort, - pub m_pointSize: libc::c_float, - pub m_ascent: libc::c_float, - pub m_descent: libc::c_float, - pub m_capHeight: libc::c_float, - pub m_xHeight: libc::c_float, - pub m_italicAngle: libc::c_float, - pub m_vertical: bool, - pub m_filename: *mut libc::c_char, - pub m_index: uint32_t, - pub m_ftFace: freetype_sys::FT_Face, - pub m_backingData: *mut freetype_sys::FT_Byte, - pub m_backingData2: *mut freetype_sys::FT_Byte, - pub m_hbFont: *mut hb_font_t, - pub m_subdtor: Option ()>, -} -pub type XeTeXLayoutEngine = *mut XeTeXLayoutEngine_rec; -pub type gr_uint16 = libc::c_ushort; -pub type gr_int16 = libc::c_short; -pub type gr_uint32 = libc::c_uint; -pub type gr_encform = libc::c_uint; -pub const gr_utf32: gr_encform = 4; -pub const gr_utf16: gr_encform = 2; -pub const gr_utf8: gr_encform = 1; -pub type gr_break_weight = libc::c_int; -pub const gr_breakBeforeClip: gr_break_weight = -40; -pub const gr_breakBeforeLetter: gr_break_weight = -30; -pub const gr_breakBeforeIntra: gr_break_weight = -20; -pub const gr_breakBeforeWord: gr_break_weight = -15; -pub const gr_breakBeforeWhitespace: gr_break_weight = -10; -pub const gr_breakClip: gr_break_weight = 40; -pub const gr_breakLetter: gr_break_weight = 30; -pub const gr_breakIntra: gr_break_weight = 20; -pub const gr_breakWord: gr_break_weight = 15; -pub const gr_breakWhitespace: gr_break_weight = 10; -pub const gr_breakNone: gr_break_weight = 0; - -pub type ProtrusionFactor = CppStdMap; -#[cfg(target_os = "macos")] -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontInst_Mac { - pub super_: XeTeXFontInst, - pub m_descriptor: CTFontDescriptorRef, - pub m_fontRef: CTFontRef, -} - -use crate::xetex_font_manager::{XeTeXFontMgr, XeTeXFontMgrFamily, XeTeXFontMgrFont}; - -/* ***************************************************************************\ - Part of the XeTeX typesetting system - Copyright (c) 1994-2008 by SIL International - Copyright (c) 2009 by Jonathan Kew - Copyright (c) 2012, 2013 by Jiang Jiang - - SIL Author(s): Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ - -/* The following code used to be in a file called "hz.cpp" and there's no - * particular reason for it to be here, but it was a tiny file with a weird - * name so I wanted to get rid of it. The functions are invoked from the C - * code. */ -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] -#[repr(C)] -pub struct GlyphId { - pub fontNum: libc::c_int, - pub code: libc::c_uint, -} -#[inline] -unsafe extern "C" fn XeTeXFontInst_getDescent(mut self_0: *const XeTeXFontInst) -> libc::c_float { - return (*self_0).m_descent; -} -#[inline] -unsafe extern "C" fn XeTeXFontInst_getLayoutDirVertical(mut self_0: *const XeTeXFontInst) -> bool { - return (*self_0).m_vertical; -} -#[inline] -unsafe extern "C" fn XeTeXFontInst_getPointSize(mut self_0: *const XeTeXFontInst) -> libc::c_float { - return (*self_0).m_pointSize; -} -#[inline] -unsafe extern "C" fn XeTeXFontInst_getAscent(mut self_0: *const XeTeXFontInst) -> libc::c_float { - return (*self_0).m_ascent; -} -#[inline] -unsafe extern "C" fn XeTeXFontInst_getCapHeight(mut self_0: *const XeTeXFontInst) -> libc::c_float { - return (*self_0).m_capHeight; -} -#[inline] -unsafe extern "C" fn XeTeXFontInst_getXHeight(mut self_0: *const XeTeXFontInst) -> libc::c_float { - return (*self_0).m_xHeight; -} -#[inline] -unsafe extern "C" fn XeTeXFontInst_getItalicAngle( - mut self_0: *const XeTeXFontInst, -) -> libc::c_float { - return (*self_0).m_italicAngle; -} -#[inline] -unsafe extern "C" fn XeTeXFontInst_getFilename( - mut self_0: *const XeTeXFontInst, - mut index: *mut uint32_t, -) -> *const libc::c_char { - *index = (*self_0).m_index; - return (*self_0).m_filename; -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphBBoxCache() -> *mut CppStdMap { - static mut cache: *mut CppStdMap = - 0 as *const CppStdMap as *mut CppStdMap; - if cache.is_null() { - cache = CppStdMap_create() - } - return cache; -} -#[no_mangle] -pub unsafe extern "C" fn getCachedGlyphBBox( - mut fontID: uint16_t, - mut glyphID: uint16_t, - mut bbox: *mut GlyphBBox, -) -> libc::c_int { - let mut sGlyphBoxes: *mut CppStdMap = getGlyphBBoxCache(); - let mut key: uint32_t = ((fontID as uint32_t) << 16i32).wrapping_add(glyphID as libc::c_uint); - if let Some(v) = (*sGlyphBoxes).get(&key) { - *bbox = v.clone(); - 1 - } else { - 0 - } -} -#[no_mangle] -pub unsafe extern "C" fn cacheGlyphBBox( - mut fontID: uint16_t, - mut glyphID: uint16_t, - mut bbox: *const GlyphBBox, -) { - let mut sGlyphBoxes: *mut CppStdMap = getGlyphBBoxCache(); - let mut key: uint32_t = ((fontID as uint32_t) << 16i32).wrapping_add(glyphID as libc::c_uint); - CppStdMap_put(sGlyphBoxes, key, *bbox); -} -#[inline] -unsafe extern "C" fn GlyphId_create(mut fontNum: libc::c_int, mut code: libc::c_uint) -> GlyphId { - let mut id: GlyphId = GlyphId { - fontNum: 0, - code: 0, - }; - id.fontNum = fontNum; - id.code = code; - return id; -} -#[no_mangle] -pub unsafe extern "C" fn getProtrusionFactor(mut side: libc::c_int) -> *mut ProtrusionFactor { - static mut leftProt: *mut ProtrusionFactor = - 0 as *const ProtrusionFactor as *mut ProtrusionFactor; - static mut rightProt: *mut ProtrusionFactor = - 0 as *const ProtrusionFactor as *mut ProtrusionFactor; - let mut container: *mut ProtrusionFactor = 0 as *mut ProtrusionFactor; - match side { - 0 => { - if leftProt.is_null() { - leftProt = CppStdMap_create() - } - container = leftProt - // we should not reach here - } - 1 => { - if rightProt.is_null() { - rightProt = CppStdMap_create() - } - container = rightProt - } - _ => { - unreachable!(); - } - } - return container; -} -#[no_mangle] -pub unsafe extern "C" fn set_cp_code( - mut fontNum: libc::c_int, - mut code: libc::c_uint, - mut side: libc::c_int, - mut value: libc::c_int, -) { - let mut id: GlyphId = GlyphId_create(fontNum, code); - let mut container: *mut ProtrusionFactor = getProtrusionFactor(side); - CppStdMap_put(container, id, value); -} -#[no_mangle] -pub unsafe extern "C" fn get_cp_code( - mut fontNum: libc::c_int, - mut code: libc::c_uint, - mut side: libc::c_int, -) -> libc::c_int { - let mut id: GlyphId = GlyphId_create(fontNum, code); - let mut container: *mut ProtrusionFactor = getProtrusionFactor(side); - (*container).get(&id).cloned().unwrap_or(0) -} -/* ******************************************************************/ -#[no_mangle] -pub unsafe extern "C" fn terminate_font_manager() { - XeTeXFontMgr_Terminate(); -} -#[no_mangle] -pub unsafe extern "C" fn destroy_font_manager() { - XeTeXFontMgr_Destroy(); -} -#[no_mangle] -pub unsafe extern "C" fn createFont( - mut fontRef: PlatformFontRef, - mut pointSize: Fixed, -) -> XeTeXFont { - let mut status: libc::c_int = 0i32; - let mut font: *mut XeTeXFontInst; - #[cfg(not(target_os = "macos"))] - { - let mut pathname: *mut FcChar8 = 0 as *mut FcChar8; - FcPatternGetString( - fontRef as *const FcPattern, - b"file\x00" as *const u8 as *const libc::c_char, - 0i32, - &mut pathname, - ); - let mut index: libc::c_int = 0; - FcPatternGetInteger( - fontRef as *const FcPattern, - b"index\x00" as *const u8 as *const libc::c_char, - 0i32, - &mut index, - ); - font = XeTeXFontInst_create( - pathname as *const libc::c_char, - index, - Fix2D(pointSize) as libc::c_float, - &mut status, - ); - } - #[cfg(target_os = "macos")] - { - font = &mut (*(XeTeXFontInst_Mac_create - as unsafe extern "C" fn( - _: CTFontDescriptorRef, - _: libc::c_float, - _: *mut libc::c_int, - ) -> *mut XeTeXFontInst_Mac)( - fontRef, - (Fix2D as unsafe extern "C" fn(_: Fixed) -> libc::c_double)(pointSize) as libc::c_float, - &mut status, - )) - .super_; - } - if status != 0i32 { - XeTeXFontInst_delete(font); - return 0 as XeTeXFont; - } - return font as XeTeXFont; -} -#[no_mangle] -pub unsafe extern "C" fn createFontFromFile( - mut filename: *const libc::c_char, - mut index: libc::c_int, - mut pointSize: Fixed, -) -> XeTeXFont { - let mut status: libc::c_int = 0i32; - let mut font: *mut XeTeXFontInst = XeTeXFontInst_create( - filename, - index, - Fix2D(pointSize) as libc::c_float, - &mut status, - ); - if status != 0i32 { - XeTeXFontInst_delete(font); - return 0 as XeTeXFont; - } - return font as XeTeXFont; -} -#[no_mangle] -pub unsafe extern "C" fn setFontLayoutDir(mut font: XeTeXFont, mut vertical: libc::c_int) { - XeTeXFontInst_setLayoutDirVertical(font as *mut XeTeXFontInst, vertical != 0i32); -} -#[no_mangle] -pub unsafe extern "C" fn findFontByName( - mut name: *const libc::c_char, - mut var: *mut libc::c_char, - mut size: libc::c_double, -) -> PlatformFontRef { - return XeTeXFontMgr_findFont(XeTeXFontMgr_GetFontManager(), name, var, size); -} -#[no_mangle] -pub unsafe extern "C" fn getReqEngine() -> libc::c_char { - return XeTeXFontMgr_getReqEngine(XeTeXFontMgr_GetFontManager()); -} -#[no_mangle] -pub unsafe extern "C" fn setReqEngine(mut reqEngine: libc::c_char) { - XeTeXFontMgr_setReqEngine(XeTeXFontMgr_GetFontManager(), reqEngine); -} -#[no_mangle] -pub unsafe extern "C" fn getFullName(mut fontRef: PlatformFontRef) -> *const libc::c_char { - return XeTeXFontMgr_getFullName(XeTeXFontMgr_GetFontManager(), fontRef); -} -#[no_mangle] -pub unsafe extern "C" fn getDesignSize(mut font: XeTeXFont) -> libc::c_double { - return XeTeXFontMgr_getDesignSize(XeTeXFontMgr_GetFontManager(), font); -} -#[no_mangle] -pub unsafe extern "C" fn getFontFilename( - mut engine: XeTeXLayoutEngine, - mut index: *mut uint32_t, -) -> *mut libc::c_char { - return xstrdup(XeTeXFontInst_getFilename((*engine).font, index)); -} -#[no_mangle] -pub unsafe extern "C" fn getFontRef(mut engine: XeTeXLayoutEngine) -> PlatformFontRef { - return (*engine).fontRef; -} -#[no_mangle] -pub unsafe extern "C" fn deleteFont(mut font: XeTeXFont) { - XeTeXFontInst_delete(font as *mut XeTeXFontInst); -} -#[no_mangle] -pub unsafe extern "C" fn getFontTablePtr( - mut font: XeTeXFont, - mut tableTag: uint32_t, -) -> *mut libc::c_void { - return XeTeXFontInst_getFontTable(font as *mut XeTeXFontInst, tableTag); -} -#[no_mangle] -pub unsafe extern "C" fn getSlant(mut font: XeTeXFont) -> Fixed { - let mut italAngle: libc::c_float = XeTeXFontInst_getItalicAngle(font as *mut XeTeXFontInst); - return D2Fix(tan( - -italAngle as libc::c_double * std::f64::consts::PI / 180.0f64 - )); -} -unsafe extern "C" fn getLargerScriptListTable( - mut font: XeTeXFont, - mut scriptList: *mut *mut hb_tag_t, -) -> libc::c_uint { - use crate::bridge::size_t; - let mut rval: libc::c_uint = 0i32 as libc::c_uint; - let mut face: *mut hb_face_t = - hb_font_get_face(XeTeXFontInst_getHbFont(font as *mut XeTeXFontInst)); - let mut scriptListSub: *mut hb_tag_t = 0 as *mut hb_tag_t; - let mut scriptListPos: *mut hb_tag_t = 0 as *mut hb_tag_t; - let mut scriptCountSub: libc::c_uint = hb_ot_layout_table_get_script_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as uint32_t & 0xffi32 as libc::c_uint, - 0i32 as libc::c_uint, - 0 as *mut libc::c_uint, - 0 as *mut hb_tag_t, - ); - scriptListSub = xcalloc( - scriptCountSub as size_t, - ::std::mem::size_of::<*mut hb_tag_t>() as _, - ) as *mut hb_tag_t; - hb_ot_layout_table_get_script_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as uint32_t & 0xffi32 as libc::c_uint, - 0i32 as libc::c_uint, - &mut scriptCountSub, - scriptListSub, - ); - let mut scriptCountPos: libc::c_uint = hb_ot_layout_table_get_script_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('P' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('O' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'S' as i32 as uint32_t & 0xffi32 as libc::c_uint, - 0i32 as libc::c_uint, - 0 as *mut libc::c_uint, - 0 as *mut hb_tag_t, - ); - scriptListPos = xcalloc( - scriptCountPos as size_t, - ::std::mem::size_of::<*mut hb_tag_t>() as _, - ) as *mut hb_tag_t; - hb_ot_layout_table_get_script_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as uint32_t & 0xffi32 as libc::c_uint, - 0i32 as libc::c_uint, - &mut scriptCountPos, - scriptListPos, - ); - if scriptCountSub > scriptCountPos { - if !scriptList.is_null() { - *scriptList = scriptListSub - } - rval = scriptCountSub - } else { - if !scriptList.is_null() { - *scriptList = scriptListPos - } - rval = scriptCountPos - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn countScripts(mut font: XeTeXFont) -> libc::c_uint { - return getLargerScriptListTable(font, 0 as *mut *mut hb_tag_t); -} -#[no_mangle] -pub unsafe extern "C" fn getIndScript(mut font: XeTeXFont, mut index: libc::c_uint) -> hb_tag_t { - let mut rval: hb_tag_t = 0i32 as hb_tag_t; - let mut scriptList: *mut hb_tag_t = 0 as *mut hb_tag_t; - let mut scriptCount: libc::c_uint = getLargerScriptListTable(font, &mut scriptList); - if !scriptList.is_null() { - if index < scriptCount { - rval = *scriptList.offset(index as isize) - } - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn countLanguages(mut font: XeTeXFont, mut script: hb_tag_t) -> libc::c_uint { - let mut rval: libc::c_uint = 0i32 as libc::c_uint; - let mut face: *mut hb_face_t = - hb_font_get_face(XeTeXFontInst_getHbFont(font as *mut XeTeXFontInst)); - let mut scriptList: *mut hb_tag_t = 0 as *mut hb_tag_t; - let mut scriptCount: libc::c_uint = getLargerScriptListTable(font, &mut scriptList); - if !scriptList.is_null() { - let mut i: libc::c_uint = 0i32 as libc::c_uint; - while i < scriptCount { - if *scriptList.offset(i as isize) == script { - rval = rval.wrapping_add(hb_ot_layout_script_get_language_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as uint32_t & 0xffi32 as libc::c_uint, - i, - 0i32 as libc::c_uint, - 0 as *mut libc::c_uint, - 0 as *mut hb_tag_t, - )); - rval = rval.wrapping_add(hb_ot_layout_script_get_language_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('P' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('O' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'S' as i32 as uint32_t & 0xffi32 as libc::c_uint, - i, - 0i32 as libc::c_uint, - 0 as *mut libc::c_uint, - 0 as *mut hb_tag_t, - )); - break; - } else { - i = i.wrapping_add(1) - } - } - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn getIndLanguage( - mut font: XeTeXFont, - mut script: hb_tag_t, - mut index: libc::c_uint, -) -> hb_tag_t { - use crate::bridge::size_t; - let mut rval: hb_tag_t = 0i32 as hb_tag_t; - let mut face: *mut hb_face_t = - hb_font_get_face(XeTeXFontInst_getHbFont(font as *mut XeTeXFontInst)); - let mut scriptList: *mut hb_tag_t = 0 as *mut hb_tag_t; - let mut scriptCount: libc::c_uint = getLargerScriptListTable(font, &mut scriptList); - if !scriptList.is_null() { - let mut i: libc::c_uint = 0i32 as libc::c_uint; - while i < scriptCount { - if *scriptList.offset(i as isize) == script { - let mut langCount: libc::c_uint = 0; - let mut langList: *mut hb_tag_t = 0 as *mut hb_tag_t; - langCount = hb_ot_layout_script_get_language_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as uint32_t & 0xffi32 as libc::c_uint, - i, - 0i32 as libc::c_uint, - 0 as *mut libc::c_uint, - 0 as *mut hb_tag_t, - ); - langList = xcalloc( - langCount as size_t, - ::std::mem::size_of::<*mut hb_tag_t>() as _, - ) as *mut hb_tag_t; - hb_ot_layout_script_get_language_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as uint32_t & 0xffi32 as libc::c_uint, - i, - 0i32 as libc::c_uint, - &mut langCount, - langList, - ); - if index < langCount { - rval = *langList.offset(index as isize); - break; - } else { - free(langList as *mut libc::c_void); - langCount = hb_ot_layout_script_get_language_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('P' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('O' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'S' as i32 as uint32_t & 0xffi32 as libc::c_uint, - i, - 0i32 as libc::c_uint, - 0 as *mut libc::c_uint, - 0 as *mut hb_tag_t, - ); - langList = xcalloc( - langCount as size_t, - ::std::mem::size_of::<*mut hb_tag_t>() as _, - ) as *mut hb_tag_t; - hb_ot_layout_script_get_language_tags( - face, - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('P' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('O' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'S' as i32 as uint32_t & 0xffi32 as libc::c_uint, - i, - 0i32 as libc::c_uint, - &mut langCount, - langList, - ); - if index < langCount { - rval = *langList.offset(index as isize); - break; - } else { - free(langList as *mut libc::c_void); - } - } - } - i = i.wrapping_add(1) - } - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn countFeatures( - mut font: XeTeXFont, - mut script: hb_tag_t, - mut language: hb_tag_t, -) -> libc::c_uint { - let mut rval: libc::c_uint = 0i32 as libc::c_uint; - let mut face: *mut hb_face_t = - hb_font_get_face(XeTeXFontInst_getHbFont(font as *mut XeTeXFontInst)); - let mut i: libc::c_int = 0i32; - while i < 2i32 { - let mut scriptIndex: libc::c_uint = 0; - let mut langIndex: libc::c_uint = 0i32 as libc::c_uint; - let mut tableTag: hb_tag_t = if i == 0i32 { - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as uint32_t & 0xffi32 as libc::c_uint - } else { - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('P' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('O' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'S' as i32 as uint32_t & 0xffi32 as libc::c_uint - }; - if hb_ot_layout_table_find_script(face, tableTag, script, &mut scriptIndex) != 0 { - if hb_ot_layout_script_find_language( - face, - tableTag, - scriptIndex, - language, - &mut langIndex, - ) != 0 - || language == 0i32 as libc::c_uint - { - rval = rval.wrapping_add(hb_ot_layout_language_get_feature_tags( - face, - tableTag, - scriptIndex, - langIndex, - 0i32 as libc::c_uint, - 0 as *mut libc::c_uint, - 0 as *mut hb_tag_t, - )) - } - } - i += 1 - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn getIndFeature( - mut font: XeTeXFont, - mut script: hb_tag_t, - mut language: hb_tag_t, - mut index: libc::c_uint, -) -> hb_tag_t { - use crate::bridge::size_t; - let mut rval: hb_tag_t = 0i32 as hb_tag_t; - let mut face: *mut hb_face_t = - hb_font_get_face(XeTeXFontInst_getHbFont(font as *mut XeTeXFontInst)); - let mut i: libc::c_int = 0i32; - while i < 2i32 { - let mut scriptIndex: libc::c_uint = 0; - let mut langIndex: libc::c_uint = 0i32 as libc::c_uint; - let mut tableTag: hb_tag_t = if i == 0i32 { - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('S' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('U' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'B' as i32 as uint32_t & 0xffi32 as libc::c_uint - } else { - ('G' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 24i32 - | ('P' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 16i32 - | ('O' as i32 as uint32_t & 0xffi32 as libc::c_uint) << 8i32 - | 'S' as i32 as uint32_t & 0xffi32 as libc::c_uint - }; - if hb_ot_layout_table_find_script(face, tableTag, script, &mut scriptIndex) != 0 { - if hb_ot_layout_script_find_language( - face, - tableTag, - scriptIndex, - language, - &mut langIndex, - ) != 0 - || language == 0i32 as libc::c_uint - { - let mut featCount: libc::c_uint = hb_ot_layout_language_get_feature_tags( - face, - tableTag, - scriptIndex, - langIndex, - 0i32 as libc::c_uint, - 0 as *mut libc::c_uint, - 0 as *mut hb_tag_t, - ); - let mut featList: *mut hb_tag_t = xcalloc( - featCount as size_t, - ::std::mem::size_of::<*mut hb_tag_t>() as _, - ) as *mut hb_tag_t; - hb_ot_layout_language_get_feature_tags( - face, - tableTag, - scriptIndex, - langIndex, - 0i32 as libc::c_uint, - &mut featCount, - featList, - ); - if index < featCount { - rval = *featList.offset(index as isize); - break; - } else { - index = index.wrapping_sub(featCount) - } - } - } - i += 1 - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn countGraphiteFeatures(mut engine: XeTeXLayoutEngine) -> uint32_t { - let mut rval: uint32_t = 0i32 as uint32_t; - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - rval = gr_face_n_fref(grFace) as uint32_t - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn getGraphiteFeatureCode( - mut engine: XeTeXLayoutEngine, - mut index: uint32_t, -) -> uint32_t { - let mut rval: uint32_t = 0i32 as uint32_t; - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - let mut feature: *const gr_feature_ref = gr_face_fref(grFace, index as gr_uint16); - rval = gr_fref_id(feature) - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn countGraphiteFeatureSettings( - mut engine: XeTeXLayoutEngine, - mut featureID: uint32_t, -) -> uint32_t { - let mut rval: uint32_t = 0i32 as uint32_t; - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); - rval = gr_fref_n_values(feature) as uint32_t - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn getGraphiteFeatureSettingCode( - mut engine: XeTeXLayoutEngine, - mut featureID: uint32_t, - mut index: uint32_t, -) -> uint32_t { - let mut rval: uint32_t = 0i32 as uint32_t; - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); - rval = gr_fref_value(feature, index as gr_uint16) as uint32_t - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn getGraphiteFeatureDefaultSetting( - mut engine: XeTeXLayoutEngine, - mut featureID: uint32_t, -) -> uint32_t { - let mut rval: uint32_t = 0i32 as uint32_t; - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); - let mut featureValues: *mut gr_feature_val = gr_face_featureval_for_lang( - grFace, - hb_tag_from_string( - hb_language_to_string((*engine).language), - strlen(hb_language_to_string((*engine).language)) as libc::c_int, - ), - ); - rval = gr_fref_feature_value(feature, featureValues) as uint32_t - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn getGraphiteFeatureLabel( - mut engine: XeTeXLayoutEngine, - mut featureID: uint32_t, -) -> *mut libc::c_char { - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); - let mut len: uint32_t = 0i32 as uint32_t; - let mut langID: uint16_t = 0x409i32 as uint16_t; - return gr_fref_label(feature, &mut langID, gr_utf8, &mut len) as *mut libc::c_char; - } - return 0 as *mut libc::c_char; -} -#[no_mangle] -pub unsafe extern "C" fn getGraphiteFeatureSettingLabel( - mut engine: XeTeXLayoutEngine, - mut featureID: uint32_t, - mut settingID: uint32_t, -) -> *mut libc::c_char { - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, featureID); - let mut i: libc::c_int = 0i32; - while i < gr_fref_n_values(feature) as libc::c_int { - if settingID as libc::c_int == gr_fref_value(feature, i as gr_uint16) as libc::c_int { - let mut len: uint32_t = 0i32 as uint32_t; - let mut langID: uint16_t = 0x409i32 as uint16_t; - return gr_fref_value_label(feature, i as gr_uint16, &mut langID, gr_utf8, &mut len) - as *mut libc::c_char; - } - i += 1 - } - } - return 0 as *mut libc::c_char; -} -#[no_mangle] -pub unsafe extern "C" fn findGraphiteFeature( - mut engine: XeTeXLayoutEngine, - mut s: *const libc::c_char, - mut e: *const libc::c_char, - mut f: *mut hb_tag_t, - mut v: *mut libc::c_int, -) -> bool -/* s...e is a "feature=setting" string; look for this in the font */ { - let mut tmp: libc::c_long = 0; - *f = 0i32 as hb_tag_t; - *v = 0i32; - while *s as libc::c_int == ' ' as i32 || *s as libc::c_int == '\t' as i32 { - s = s.offset(1) - } - let mut cp: *const libc::c_char = s; - while cp < e && *cp as libc::c_int != '=' as i32 { - cp = cp.offset(1) - } - tmp = findGraphiteFeatureNamed( - engine, - s, - cp.wrapping_offset_from(s) as libc::c_long as libc::c_int, - ); - *f = tmp as hb_tag_t; - if tmp == -1i32 as libc::c_long { - return 0i32 != 0; - } - cp = cp.offset(1); - while cp < e && (*cp as libc::c_int == ' ' as i32 || *cp as libc::c_int == '\t' as i32) { - cp = cp.offset(1) - } - if cp == e { - /* no setting was specified */ - return 0i32 != 0; - } - *v = findGraphiteFeatureSettingNamed( - engine, - *f, - cp, - e.wrapping_offset_from(cp) as libc::c_long as libc::c_int, - ) as libc::c_int; - if *v == -1i32 { - return 0i32 != 0; - } - return 1i32 != 0; -} -#[no_mangle] -pub unsafe extern "C" fn findGraphiteFeatureNamed( - mut engine: XeTeXLayoutEngine, - mut name: *const libc::c_char, - mut namelength: libc::c_int, -) -> libc::c_long { - use crate::bridge::size_t; - let mut rval: libc::c_long = -1i32 as libc::c_long; - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - let mut i: libc::c_int = 0i32; - while i < gr_face_n_fref(grFace) as libc::c_int { - let mut feature: *const gr_feature_ref = gr_face_fref(grFace, i as gr_uint16); - let mut len: uint32_t = 0i32 as uint32_t; - let mut langID: uint16_t = 0x409i32 as uint16_t; - // the first call is to get the length of the string - gr_fref_label(feature, &mut langID, gr_utf8, &mut len); - let mut label: *mut libc::c_char = xmalloc(len as size_t) as *mut libc::c_char; - label = gr_fref_label(feature, &mut langID, gr_utf8, &mut len) as *mut libc::c_char; - if strncmp(label, name, namelength as libc::c_ulong) == 0i32 { - rval = gr_fref_id(feature) as libc::c_long; - gr_label_destroy(label as *mut libc::c_void); - break; - } else { - gr_label_destroy(label as *mut libc::c_void); - i += 1 - } - } - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn findGraphiteFeatureSettingNamed( - mut engine: XeTeXLayoutEngine, - mut id: uint32_t, - mut name: *const libc::c_char, - mut namelength: libc::c_int, -) -> libc::c_long { - use crate::bridge::size_t; - let mut rval: libc::c_long = -1i32 as libc::c_long; - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - if !grFace.is_null() { - let mut feature: *const gr_feature_ref = gr_face_find_fref(grFace, id); - let mut i: libc::c_int = 0i32; - while i < gr_fref_n_values(feature) as libc::c_int { - let mut len: uint32_t = 0i32 as uint32_t; - let mut langID: uint16_t = 0x409i32 as uint16_t; - // the first call is to get the length of the string - gr_fref_value_label(feature, i as gr_uint16, &mut langID, gr_utf8, &mut len); - let mut label: *mut libc::c_char = xmalloc(len as size_t) as *mut libc::c_char; - label = gr_fref_value_label(feature, i as gr_uint16, &mut langID, gr_utf8, &mut len) - as *mut libc::c_char; - if strncmp(label, name, namelength as libc::c_ulong) == 0i32 { - rval = gr_fref_value(feature, i as gr_uint16) as libc::c_long; - gr_label_destroy(label as *mut libc::c_void); - break; - } else { - gr_label_destroy(label as *mut libc::c_void); - i += 1 - } - } - } - return rval; -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphWidth(mut font: XeTeXFont, mut gid: uint32_t) -> libc::c_float { - return XeTeXFontInst_getGlyphWidth(font as *mut XeTeXFontInst, gid as GlyphID); -} -#[no_mangle] -pub unsafe extern "C" fn countGlyphs(mut font: XeTeXFont) -> libc::c_uint { - return XeTeXFontInst_getNumGlyphs(font as *mut XeTeXFontInst) as libc::c_uint; -} -#[no_mangle] -pub unsafe extern "C" fn getFont(mut engine: XeTeXLayoutEngine) -> XeTeXFont { - return (*engine).font as XeTeXFont; -} -#[no_mangle] -pub unsafe extern "C" fn getExtendFactor(mut engine: XeTeXLayoutEngine) -> libc::c_float { - return (*engine).extend; -} -#[no_mangle] -pub unsafe extern "C" fn getSlantFactor(mut engine: XeTeXLayoutEngine) -> libc::c_float { - return (*engine).slant; -} -#[no_mangle] -pub unsafe extern "C" fn getEmboldenFactor(mut engine: XeTeXLayoutEngine) -> libc::c_float { - return (*engine).embolden; -} -#[no_mangle] -pub unsafe extern "C" fn XeTeXLayoutEngine_create() -> *mut XeTeXLayoutEngine_rec { - return malloc(::std::mem::size_of::() as libc::c_ulong) - as *mut XeTeXLayoutEngine_rec; -} -#[no_mangle] -pub unsafe extern "C" fn XeTeXLayoutEngine_delete(mut engine: *mut XeTeXLayoutEngine_rec) { - free(engine as *mut libc::c_void); -} -#[no_mangle] -pub unsafe extern "C" fn createLayoutEngine( - mut fontRef: PlatformFontRef, - mut font: XeTeXFont, - mut script: hb_tag_t, - mut language: *mut libc::c_char, - mut features: *mut hb_feature_t, - mut nFeatures: libc::c_int, - mut shapers: *mut *mut libc::c_char, - mut rgbValue: uint32_t, - mut extend: libc::c_float, - mut slant: libc::c_float, - mut embolden: libc::c_float, -) -> XeTeXLayoutEngine { - let mut result: XeTeXLayoutEngine = XeTeXLayoutEngine_create(); - (*result).fontRef = fontRef; - (*result).font = font as *mut XeTeXFontInst; - (*result).script = script; - (*result).features = features; - (*result).ShaperList = shapers; - (*result).shaper = 0 as *mut libc::c_char; - (*result).nFeatures = nFeatures; - (*result).rgbValue = rgbValue; - (*result).extend = extend; - (*result).slant = slant; - (*result).embolden = embolden; - (*result).hbBuffer = hb_buffer_create(); - // For Graphite fonts treat the language as BCP 47 tag, for OpenType we - // treat it as a OT language tag for backward compatibility with pre-0.9999 - // XeTeX. - if getReqEngine() as libc::c_int == 'G' as i32 { - (*result).language = hb_language_from_string(language, -1i32) - } else { - (*result).language = hb_ot_tag_to_language(hb_tag_from_string(language, -1i32)) - } - free(language as *mut libc::c_void); - return result; -} -#[no_mangle] -pub unsafe extern "C" fn deleteLayoutEngine(mut engine: XeTeXLayoutEngine) { - hb_buffer_destroy((*engine).hbBuffer); - XeTeXFontInst_delete((*engine).font); - free((*engine).shaper as *mut libc::c_void); - XeTeXLayoutEngine_delete(engine); -} -unsafe extern "C" fn _decompose_compat( - mut ufuncs: *mut hb_unicode_funcs_t, - mut u: hb_codepoint_t, - mut decomposed: *mut hb_codepoint_t, - mut user_data: *mut libc::c_void, -) -> libc::c_uint { - return 0i32 as libc::c_uint; -} -unsafe extern "C" fn _get_unicode_funcs() -> *mut hb_unicode_funcs_t { - static mut ufuncs: *mut hb_unicode_funcs_t = - 0 as *const hb_unicode_funcs_t as *mut hb_unicode_funcs_t; - if ufuncs.is_null() { - ufuncs = hb_unicode_funcs_create(hb_icu_get_unicode_funcs()) - } - hb_unicode_funcs_set_decompose_compatibility_func( - ufuncs, - Some( - _decompose_compat - as unsafe extern "C" fn( - _: *mut hb_unicode_funcs_t, - _: hb_codepoint_t, - _: *mut hb_codepoint_t, - _: *mut libc::c_void, - ) -> libc::c_uint, - ), - 0 as *mut libc::c_void, - None, - ); - return ufuncs; -} -static mut hbUnicodeFuncs: *mut hb_unicode_funcs_t = - 0 as *const hb_unicode_funcs_t as *mut hb_unicode_funcs_t; -#[no_mangle] -pub unsafe extern "C" fn layoutChars( - mut engine: XeTeXLayoutEngine, - mut chars: *mut uint16_t, - mut offset: int32_t, - mut count: int32_t, - mut max: int32_t, - mut rightToLeft: bool, -) -> libc::c_int { - use crate::bridge::size_t; - let mut res: bool = false; - let mut script: hb_script_t = HB_SCRIPT_INVALID; - let mut direction: hb_direction_t = HB_DIRECTION_LTR; - let mut segment_props: hb_segment_properties_t = hb_segment_properties_t { - direction: HB_DIRECTION_INVALID, - script: HB_SCRIPT_INVALID, - language: 0 as *const hb_language_impl_t, - reserved1: 0 as *mut libc::c_void, - reserved2: 0 as *mut libc::c_void, - }; - let mut shape_plan: *mut hb_shape_plan_t = 0 as *mut hb_shape_plan_t; - let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont((*engine).font); - let mut hbFace: *mut hb_face_t = hb_font_get_face(hbFont); - if XeTeXFontInst_getLayoutDirVertical((*engine).font) { - direction = HB_DIRECTION_TTB - } else if rightToLeft { - direction = HB_DIRECTION_RTL - } - script = hb_ot_tag_to_script((*engine).script); - if hbUnicodeFuncs.is_null() { - hbUnicodeFuncs = _get_unicode_funcs() - } - hb_buffer_reset((*engine).hbBuffer); - hb_buffer_set_unicode_funcs((*engine).hbBuffer, hbUnicodeFuncs); - hb_buffer_add_utf16( - (*engine).hbBuffer, - chars as *const uint16_t, - max, - offset as libc::c_uint, - count, - ); - hb_buffer_set_direction((*engine).hbBuffer, direction); - hb_buffer_set_script((*engine).hbBuffer, script); - hb_buffer_set_language((*engine).hbBuffer, (*engine).language); - hb_buffer_guess_segment_properties((*engine).hbBuffer); - hb_buffer_get_segment_properties((*engine).hbBuffer, &mut segment_props); - if (*engine).ShaperList.is_null() { - // HarfBuzz gives graphite2 shaper a priority, so that for hybrid - // Graphite/OpenType fonts, Graphite will be used. However, pre-0.9999 - // XeTeX preferred OpenType over Graphite, so we are doing the same - // here for sake of backward compatibility. Since "ot" shaper never - // fails, we set the shaper list to just include it. - (*engine).ShaperList = xcalloc( - 2i32 as size_t, - ::std::mem::size_of::<*mut libc::c_char>() as _, - ) as *mut *mut libc::c_char; - let ref mut fresh0 = *(*engine).ShaperList.offset(0); - *fresh0 = b"ot\x00" as *const u8 as *const libc::c_char as *mut libc::c_char; - let ref mut fresh1 = *(*engine).ShaperList.offset(1); - *fresh1 = 0 as *mut libc::c_char - } - shape_plan = hb_shape_plan_create_cached( - hbFace, - &mut segment_props, - (*engine).features, - (*engine).nFeatures as libc::c_uint, - (*engine).ShaperList as *const *const libc::c_char, - ); - res = hb_shape_plan_execute( - shape_plan, - hbFont, - (*engine).hbBuffer, - (*engine).features, - (*engine).nFeatures as libc::c_uint, - ) != 0; - if !(*engine).shaper.is_null() { - free((*engine).shaper as *mut libc::c_void); - (*engine).shaper = 0 as *mut libc::c_char - } - if res { - (*engine).shaper = strdup(hb_shape_plan_get_shaper(shape_plan)); - hb_buffer_set_content_type((*engine).hbBuffer, HB_BUFFER_CONTENT_TYPE_GLYPHS); - } else { - // all selected shapers failed, retrying with default - // we don't use _cached here as the cached plain will always fail. - hb_shape_plan_destroy(shape_plan); /* negative is forwards */ - shape_plan = hb_shape_plan_create( - hbFace, - &mut segment_props, - (*engine).features, - (*engine).nFeatures as libc::c_uint, - 0 as *const *const libc::c_char, - ); /* negative is upwards */ - res = hb_shape_plan_execute( - shape_plan, - hbFont, - (*engine).hbBuffer, - (*engine).features, - (*engine).nFeatures as libc::c_uint, - ) != 0; - if res { - (*engine).shaper = strdup(hb_shape_plan_get_shaper(shape_plan)); - hb_buffer_set_content_type((*engine).hbBuffer, HB_BUFFER_CONTENT_TYPE_GLYPHS); - } else { - _tt_abort(b"all shapers failed\x00" as *const u8 as *const libc::c_char); - } - } - hb_shape_plan_destroy(shape_plan); - let mut glyphCount: libc::c_int = hb_buffer_get_length((*engine).hbBuffer) as libc::c_int; - return glyphCount; -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphs(mut engine: XeTeXLayoutEngine, mut glyphs: *mut uint32_t) { - let mut glyphCount: libc::c_int = hb_buffer_get_length((*engine).hbBuffer) as libc::c_int; - let mut hbGlyphs: *mut hb_glyph_info_t = - hb_buffer_get_glyph_infos((*engine).hbBuffer, 0 as *mut libc::c_uint); - let mut i: libc::c_int = 0i32; - while i < glyphCount { - *glyphs.offset(i as isize) = (*hbGlyphs.offset(i as isize)).codepoint; - i += 1 - } -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphAdvances( - mut engine: XeTeXLayoutEngine, - mut advances: *mut libc::c_float, -) { - let mut glyphCount: libc::c_int = hb_buffer_get_length((*engine).hbBuffer) as libc::c_int; - let mut hbPositions: *mut hb_glyph_position_t = - hb_buffer_get_glyph_positions((*engine).hbBuffer, 0 as *mut libc::c_uint); - let mut i: libc::c_int = 0i32; - while i < glyphCount { - if XeTeXFontInst_getLayoutDirVertical((*engine).font) { - *advances.offset(i as isize) = XeTeXFontInst_unitsToPoints( - (*engine).font, - (*hbPositions.offset(i as isize)).y_advance as libc::c_float, - ) - } else { - *advances.offset(i as isize) = XeTeXFontInst_unitsToPoints( - (*engine).font, - (*hbPositions.offset(i as isize)).x_advance as libc::c_float, - ) - } - i += 1 - } -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphPositions( - mut engine: XeTeXLayoutEngine, - mut positions: *mut FloatPoint, -) { - let mut glyphCount: libc::c_int = hb_buffer_get_length((*engine).hbBuffer) as libc::c_int; - let mut hbPositions: *mut hb_glyph_position_t = - hb_buffer_get_glyph_positions((*engine).hbBuffer, 0 as *mut libc::c_uint); - let mut x: libc::c_float = 0i32 as libc::c_float; - let mut y: libc::c_float = 0i32 as libc::c_float; - if XeTeXFontInst_getLayoutDirVertical((*engine).font) { - let mut i: libc::c_int = 0i32; - while i < glyphCount { - (*positions.offset(i as isize)).x = -XeTeXFontInst_unitsToPoints( - (*engine).font, - x + (*hbPositions.offset(i as isize)).y_offset as libc::c_float, - ); - (*positions.offset(i as isize)).y = XeTeXFontInst_unitsToPoints( - (*engine).font, - y - (*hbPositions.offset(i as isize)).x_offset as libc::c_float, - ); - x += (*hbPositions.offset(i as isize)).y_advance as libc::c_float; - y += (*hbPositions.offset(i as isize)).x_advance as libc::c_float; - i += 1 - } - (*positions.offset(glyphCount as isize)).x = - -XeTeXFontInst_unitsToPoints((*engine).font, x); - (*positions.offset(glyphCount as isize)).y = XeTeXFontInst_unitsToPoints((*engine).font, y) - } else { - let mut i_0: libc::c_int = 0i32; - while i_0 < glyphCount { - (*positions.offset(i_0 as isize)).x = XeTeXFontInst_unitsToPoints( - (*engine).font, - x + (*hbPositions.offset(i_0 as isize)).x_offset as libc::c_float, - ); - (*positions.offset(i_0 as isize)).y = -XeTeXFontInst_unitsToPoints( - (*engine).font, - y + (*hbPositions.offset(i_0 as isize)).y_offset as libc::c_float, - ); - x += (*hbPositions.offset(i_0 as isize)).x_advance as libc::c_float; - y += (*hbPositions.offset(i_0 as isize)).y_advance as libc::c_float; - i_0 += 1 - } - (*positions.offset(glyphCount as isize)).x = XeTeXFontInst_unitsToPoints((*engine).font, x); - (*positions.offset(glyphCount as isize)).y = -XeTeXFontInst_unitsToPoints((*engine).font, y) - } - if (*engine).extend as libc::c_double != 1.0f64 || (*engine).slant as libc::c_double != 0.0f64 { - let mut i_1: libc::c_int = 0i32; - while i_1 <= glyphCount { - (*positions.offset(i_1 as isize)).x = (*positions.offset(i_1 as isize)).x - * (*engine).extend - - (*positions.offset(i_1 as isize)).y * (*engine).slant; - i_1 += 1 - } - }; -} -#[no_mangle] -pub unsafe extern "C" fn getPointSize(mut engine: XeTeXLayoutEngine) -> libc::c_float { - return XeTeXFontInst_getPointSize((*engine).font); -} -#[no_mangle] -pub unsafe extern "C" fn getAscentAndDescent( - mut engine: XeTeXLayoutEngine, - mut ascent: *mut libc::c_float, - mut descent: *mut libc::c_float, -) { - *ascent = XeTeXFontInst_getAscent((*engine).font); - *descent = XeTeXFontInst_getDescent((*engine).font); -} -#[no_mangle] -pub unsafe extern "C" fn getCapAndXHeight( - mut engine: XeTeXLayoutEngine, - mut capheight: *mut libc::c_float, - mut xheight: *mut libc::c_float, -) { - *capheight = XeTeXFontInst_getCapHeight((*engine).font); - *xheight = XeTeXFontInst_getXHeight((*engine).font); -} -#[no_mangle] -pub unsafe extern "C" fn getDefaultDirection(mut engine: XeTeXLayoutEngine) -> libc::c_int { - let mut script: hb_script_t = hb_buffer_get_script((*engine).hbBuffer); - if hb_script_get_horizontal_direction(script) as libc::c_uint - == HB_DIRECTION_RTL as libc::c_int as libc::c_uint - { - return 0xffi32; - } else { - return 0xfei32; - }; -} -#[no_mangle] -pub unsafe extern "C" fn getRgbValue(mut engine: XeTeXLayoutEngine) -> uint32_t { - return (*engine).rgbValue; -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphBounds( - mut engine: XeTeXLayoutEngine, - mut glyphID: uint32_t, - mut bbox: *mut GlyphBBox, -) { - XeTeXFontInst_getGlyphBounds((*engine).font, glyphID as GlyphID, bbox); - if (*engine).extend as libc::c_double != 0.0f64 { - (*bbox).xMin *= (*engine).extend; - (*bbox).xMax *= (*engine).extend - }; -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphWidthFromEngine( - mut engine: XeTeXLayoutEngine, - mut glyphID: uint32_t, -) -> libc::c_float { - return (*engine).extend * XeTeXFontInst_getGlyphWidth((*engine).font, glyphID as GlyphID); -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphHeightDepth( - mut engine: XeTeXLayoutEngine, - mut glyphID: uint32_t, - mut height: *mut libc::c_float, - mut depth: *mut libc::c_float, -) { - XeTeXFontInst_getGlyphHeightDepth((*engine).font, glyphID as GlyphID, height, depth); -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphSidebearings( - mut engine: XeTeXLayoutEngine, - mut glyphID: uint32_t, - mut lsb: *mut libc::c_float, - mut rsb: *mut libc::c_float, -) { - XeTeXFontInst_getGlyphSidebearings((*engine).font, glyphID as GlyphID, lsb, rsb); - if (*engine).extend as libc::c_double != 0.0f64 { - *lsb *= (*engine).extend; - *rsb *= (*engine).extend - }; -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphItalCorr( - mut engine: XeTeXLayoutEngine, - mut glyphID: uint32_t, -) -> libc::c_float { - return (*engine).extend * XeTeXFontInst_getGlyphItalCorr((*engine).font, glyphID as GlyphID); -} -#[no_mangle] -pub unsafe extern "C" fn mapCharToGlyph( - mut engine: XeTeXLayoutEngine, - mut charCode: uint32_t, -) -> uint32_t { - return XeTeXFontInst_mapCharToGlyph((*engine).font, charCode as UChar32) as uint32_t; -} -#[no_mangle] -pub unsafe extern "C" fn getFontCharRange( - mut engine: XeTeXLayoutEngine, - mut reqFirst: libc::c_int, -) -> libc::c_int { - if reqFirst != 0 { - return XeTeXFontInst_getFirstCharCode((*engine).font); - } else { - return XeTeXFontInst_getLastCharCode((*engine).font); - }; -} -#[no_mangle] -pub unsafe extern "C" fn getGlyphName( - mut font: XeTeXFont, - mut gid: uint16_t, - mut len: *mut libc::c_int, -) -> *const libc::c_char { - return XeTeXFontInst_getGlyphName(font as *mut XeTeXFontInst, gid, len); -} -#[no_mangle] -pub unsafe extern "C" fn mapGlyphToIndex( - mut engine: XeTeXLayoutEngine, - mut glyphName: *const libc::c_char, -) -> libc::c_int { - return XeTeXFontInst_mapGlyphToIndex((*engine).font, glyphName) as libc::c_int; -} -static mut grSegment: *mut gr_segment = 0 as *const gr_segment as *mut gr_segment; -static mut grPrevSlot: *const gr_slot = 0 as *const gr_slot; -static mut grTextLen: libc::c_int = 0; -#[no_mangle] -pub unsafe extern "C" fn initGraphiteBreaking( - mut engine: XeTeXLayoutEngine, - mut txtPtr: *const uint16_t, - mut txtLen: libc::c_int, -) -> bool { - let mut hbFace: *mut hb_face_t = hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font)); - let mut grFace: *mut gr_face = hb_graphite2_face_get_gr_face(hbFace); - let mut grFont: *mut gr_font = - hb_graphite2_font_get_gr_font(XeTeXFontInst_getHbFont((*engine).font)); - if !grFace.is_null() && !grFont.is_null() { - if !grSegment.is_null() { - gr_seg_destroy(grSegment); - grSegment = 0 as *mut gr_segment; - grPrevSlot = 0 as *const gr_slot - } - let mut grFeatureValues: *mut gr_feature_val = gr_face_featureval_for_lang( - grFace, - hb_tag_from_string( - hb_language_to_string((*engine).language), - strlen(hb_language_to_string((*engine).language)) as libc::c_int, - ), - ); - let mut nFeatures: libc::c_int = (*engine).nFeatures; - let mut features: *mut hb_feature_t = (*engine).features; - loop { - let fresh2 = nFeatures; - nFeatures = nFeatures - 1; - if !(fresh2 != 0) { - break; - } - let mut fref: *const gr_feature_ref = gr_face_find_fref(grFace, (*features).tag); - if !fref.is_null() { - gr_fref_set_feature_value(fref, (*features).value as gr_uint16, grFeatureValues); - } - features = features.offset(1) - } - grSegment = gr_make_seg( - grFont, - grFace, - (*engine).script, - grFeatureValues, - gr_utf16, - txtPtr as *const libc::c_void, - txtLen as size_t, - 0i32, - ); - grPrevSlot = gr_seg_first_slot(grSegment); - grTextLen = txtLen; - return 1i32 != 0; - } - return 0i32 != 0; -} -#[no_mangle] -pub unsafe extern "C" fn findNextGraphiteBreak() -> libc::c_int { - let mut ret: libc::c_int = -1i32; - if !grSegment.is_null() { - if !grPrevSlot.is_null() && grPrevSlot != gr_seg_last_slot(grSegment) { - let mut s: *const gr_slot = gr_slot_next_in_segment(grPrevSlot); - while !s.is_null() { - let mut ci: *const gr_char_info = 0 as *const gr_char_info; - let mut bw: libc::c_int = 0; - ci = gr_seg_cinfo(grSegment, gr_slot_index(s)); - bw = gr_cinfo_break_weight(ci); - if bw < gr_breakNone as libc::c_int && bw >= gr_breakBeforeWord as libc::c_int { - grPrevSlot = s; - ret = gr_cinfo_base(ci) as libc::c_int - } else if bw > gr_breakNone as libc::c_int && bw <= gr_breakWord as libc::c_int { - grPrevSlot = gr_slot_next_in_segment(s); - ret = gr_cinfo_base(ci).wrapping_add(1) as libc::c_int - } - if ret != -1i32 { - break; - } - s = gr_slot_next_in_segment(s) - } - if ret == -1i32 { - grPrevSlot = gr_seg_last_slot(grSegment); - ret = grTextLen - } - } - } - return ret; -} -/* ***************************************************************************\ - Part of the XeTeX typesetting system - Copyright (c) 1994-2008 by SIL International - Copyright (c) 2009 by Jonathan Kew - Copyright (c) 2012-2015 by Khaled Hosny - - SIL Author(s): Jonathan Kew - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the copyright holders -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in this Software without prior written -authorization from the copyright holders. -\****************************************************************************/ -/* graphite interface functions... */ -#[no_mangle] -pub unsafe extern "C" fn usingGraphite(mut engine: XeTeXLayoutEngine) -> bool { - if !(*engine).shaper.is_null() - && strcmp( - b"graphite2\x00" as *const u8 as *const libc::c_char, - (*engine).shaper, - ) == 0i32 - { - return 1i32 != 0; - } else { - return 0i32 != 0; - }; -} -#[no_mangle] -pub unsafe extern "C" fn usingOpenType(mut engine: XeTeXLayoutEngine) -> bool { - if (*engine).shaper.is_null() - || strcmp( - b"ot\x00" as *const u8 as *const libc::c_char, - (*engine).shaper, - ) == 0i32 - { - return 1i32 != 0; - } else { - return 0i32 != 0; - }; -} -#[no_mangle] -pub unsafe extern "C" fn isOpenTypeMathFont(mut engine: XeTeXLayoutEngine) -> bool { - return hb_ot_math_has_data(hb_font_get_face(XeTeXFontInst_getHbFont((*engine).font))) != 0; -} diff --git a/engine/src/xetex_math.rs b/engine/src/xetex_math.rs index 052426ef9..ace3c263f 100644 --- a/engine/src/xetex_math.rs +++ b/engine/src/xetex_math.rs @@ -13,15 +13,16 @@ use crate::xetex_ext::{map_char_to_glyph, measure_native_glyph, real_get_native_ use crate::xetex_ini::{ adjust_tail, avail, char_base, cur_c, cur_chr, cur_cmd, cur_dir, cur_f, cur_group, cur_i, cur_lang, cur_list, cur_val, cur_val1, depth_base, empty, eqtb, exten_base, - file_line_error_style_p, font_area, font_bc, font_ec, font_info, font_layout_engine, - font_params, height_base, help_line, help_ptr, insert_src_special_every_math, italic_base, - just_box, kern_base, lig_kern_base, mem, nest_ptr, null_character, param_base, pre_adjust_tail, - save_ptr, save_stack, skew_char, temp_ptr, tex_remainder, total_shrink, width_base, - xtx_ligature_present, LR_problems, LR_ptr, + file_line_error_style_p, font_bc, font_ec, font_info, font_params, get_text_layout_engine, + height_base, help_line, help_ptr, insert_src_special_every_math, italic_base, just_box, + kern_base, lig_kern_base, mem, nest_ptr, null_character, param_base, pre_adjust_tail, save_ptr, + save_stack, skew_char, temp_ptr, tex_remainder, total_shrink, width_base, xtx_ligature_present, + LR_problems, LR_ptr, TEXT_LAYOUT_ENGINES, }; use crate::xetex_ini::{b16x4, b16x4_le_t, memory_word}; use crate::xetex_layout_engine::*; use crate::xetex_linebreak::line_break; +use crate::xetex_opentype_math::*; use crate::xetex_output::{ print, print_char, print_cstr, print_esc_cstr, print_file_line, print_int, print_nl_cstr, print_size, @@ -40,6 +41,32 @@ use crate::xetex_xetex0::{ }; use crate::xetex_xetexd::is_char_node; +use crate::xetex_consts::{MATH_FONT_BASE, CUR_FONT_LOC}; +use crate::text_layout_engine::{TextLayoutEngine, TextLayout}; + +#[inline(always)] +unsafe fn math_font(n: isize) -> isize { + (*eqtb.offset(MATH_FONT_BASE as isize + n)).b32.s1 as isize +} + +pub unsafe fn is_opentype_math_font(f: usize) -> bool { + let engine = get_text_layout_engine(cur_f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + eng.isOpenTypeMathFont() + } else { + false + } +} + +pub unsafe fn is_using_opentype(f: u32) -> bool { + let engine = get_text_layout_engine(cur_f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + eng.usingOpenType() + } else { + false + } +} + pub type scaled_t = i32; /* ***************************************************************************\ Part of the XeTeX typesetting system @@ -1951,234 +1978,28 @@ pub unsafe extern "C" fn after_math() { if cur_list.mode as i32 == 207i32 { j = cur_list.eTeX_aux } - if *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + 2i32) as isize, - )) - .b32 - .s1 as isize, - ) < 22i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + 2i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + 2i32) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) - || *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 22i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) - || *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 22i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) + + const NUMBER_MATH_FAMILIES: isize = 256; + const TEXT_SIZE: isize = 0; + const SCRIPT_SIZE: isize = NUMBER_MATH_FAMILIES; + const SCRIPT_SCRIPT_SIZE: isize = 2 * NUMBER_MATH_FAMILIES; + const TOTAL_MATHSY_PARAMS: i32 = 22; + const TOTAL_MATHEX_PARAMS: i32 = 13; + + let font_num = math_font(2); + let script_num = math_font(2 + SCRIPT_SIZE); + let script_script_num = math_font(2 + SCRIPT_SCRIPT_SIZE); + + let three = math_font(3 + TEXT_SIZE); + let script_three = math_font(3 + SCRIPT_SIZE); + let script_script_three = math_font(3 + SCRIPT_SCRIPT_SIZE); + + if *font_params.offset(font_num) < TOTAL_MATHSY_PARAMS + && !is_opentype_math_font(font_num as usize) + || *font_params.offset(script_num) < TOTAL_MATHSY_PARAMS + && !is_opentype_math_font(script_num as usize) + || *font_params.offset(script_script_num) < TOTAL_MATHSY_PARAMS + && !is_opentype_math_font(script_script_num as usize) { if file_line_error_style_p != 0 { print_file_line(); @@ -2198,234 +2019,11 @@ pub unsafe extern "C" fn after_math() { error(); flush_math(); danger = true - } else if *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 0i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 13i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 0i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 0i32)) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) - || *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 13i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) - || *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 13i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) + } else if (*font_params.offset(three) < TOTAL_MATHEX_PARAMS) && !is_opentype_math_font(three as usize) + || (*font_params.offset(script_three) < TOTAL_MATHEX_PARAMS) + && !is_opentype_math_font(script_three as usize) + || (*font_params.offset(script_script_three) < TOTAL_MATHEX_PARAMS) + && !is_opentype_math_font(script_script_three as usize) { if file_line_error_style_p != 0 { print_file_line(); @@ -2482,237 +2080,14 @@ pub unsafe extern "C" fn after_math() { } danger = false; if cur_list.mode as i32 == 207i32 { - j = cur_list.eTeX_aux - } - if *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + 2i32) as isize, - )) - .b32 - .s1 as isize, - ) < 22i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + 2i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + 2i32) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) - || *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 22i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) - || *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 22i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (2i32 + 2i32 * 256i32)) - as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) + j = cur_list.eTeX_aux + } + if *font_params.offset(font_num) < TOTAL_MATHSY_PARAMS + && !is_opentype_math_font(font_num as usize) + || *font_params.offset(script_num) < TOTAL_MATHSY_PARAMS + && !is_opentype_math_font(script_num as usize) + || *font_params.offset(script_script_num) < TOTAL_MATHSY_PARAMS + && !is_opentype_math_font(script_script_num as usize) { if file_line_error_style_p != 0 { print_file_line(); @@ -2732,235 +2107,11 @@ pub unsafe extern "C" fn after_math() { error(); flush_math(); danger = true - } else if *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 0i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 13i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 0i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 0i32)) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) - || *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 13i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) - || *font_params.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) < 13i32 - && !(*font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 2i32 * 256i32)) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + (3i32 + 2i32 * 256i32)) - as isize, - )) - .b32 - .s1 as isize, - ) as XeTeXLayoutEngine, - ) as i32 - != 0) + } else if (*font_params.offset(three) < TOTAL_MATHEX_PARAMS) && !is_opentype_math_font(three as usize) + || (*font_params.offset(script_three) < TOTAL_MATHEX_PARAMS) + && !is_opentype_math_font(script_three as usize) + || (*font_params.offset(script_script_three) < TOTAL_MATHEX_PARAMS) + && !is_opentype_math_font(script_script_three as usize) { if file_line_error_style_p != 0 { print_file_line(); @@ -3594,10 +2745,7 @@ unsafe extern "C" fn math_x_height(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 5i32) } else { rval = (*font_info.offset((5i32 + *param_base.offset(f as isize)) as isize)) @@ -3631,10 +2779,7 @@ unsafe extern "C" fn math_quad(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 6i32) } else { rval = (*font_info.offset((6i32 + *param_base.offset(f as isize)) as isize)) @@ -3668,10 +2813,7 @@ unsafe extern "C" fn num1(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 8i32) } else { rval = (*font_info.offset((8i32 + *param_base.offset(f as isize)) as isize)) @@ -3705,10 +2847,7 @@ unsafe extern "C" fn num2(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 9i32) } else { rval = (*font_info.offset((9i32 + *param_base.offset(f as isize)) as isize)) @@ -3742,10 +2881,7 @@ unsafe extern "C" fn num3(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 10i32) } else { rval = (*font_info.offset((10i32 + *param_base.offset(f as isize)) as isize)) @@ -3779,10 +2915,7 @@ unsafe extern "C" fn denom1(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 11i32) } else { rval = (*font_info.offset((11i32 + *param_base.offset(f as isize)) as isize)) @@ -3816,10 +2949,7 @@ unsafe extern "C" fn denom2(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 12i32) } else { rval = (*font_info.offset((12i32 + *param_base.offset(f as isize)) as isize)) @@ -3853,10 +2983,7 @@ unsafe extern "C" fn sup1(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 13i32) } else { rval = (*font_info.offset((13i32 + *param_base.offset(f as isize)) as isize)) @@ -3890,10 +3017,7 @@ unsafe extern "C" fn sup2(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 14i32) } else { rval = (*font_info.offset((14i32 + *param_base.offset(f as isize)) as isize)) @@ -3927,10 +3051,7 @@ unsafe extern "C" fn sup3(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 15i32) } else { rval = (*font_info.offset((15i32 + *param_base.offset(f as isize)) as isize)) @@ -3964,10 +3085,7 @@ unsafe extern "C" fn sub1(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 16i32) } else { rval = (*font_info.offset((16i32 + *param_base.offset(f as isize)) as isize)) @@ -4001,10 +3119,7 @@ unsafe extern "C" fn sub2(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 17i32) } else { rval = (*font_info.offset((17i32 + *param_base.offset(f as isize)) as isize)) @@ -4038,10 +3153,7 @@ unsafe extern "C" fn sup_drop(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 18i32) } else { rval = (*font_info.offset((18i32 + *param_base.offset(f as isize)) as isize)) @@ -4075,10 +3187,7 @@ unsafe extern "C" fn sub_drop(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 19i32) } else { rval = (*font_info.offset((19i32 + *param_base.offset(f as isize)) as isize)) @@ -4112,10 +3221,7 @@ unsafe extern "C" fn delim1(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 20i32) } else { rval = (*font_info.offset((20i32 + *param_base.offset(f as isize)) as isize)) @@ -4149,10 +3255,7 @@ unsafe extern "C" fn delim2(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 21i32) } else { rval = (*font_info.offset((21i32 + *param_base.offset(f as isize)) as isize)) @@ -4186,10 +3289,7 @@ unsafe extern "C" fn axis_height(mut size_code: i32) -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathsy_param(f, 22i32) } else { rval = (*font_info.offset((22i32 + *param_base.offset(f as isize)) as isize)) @@ -4223,10 +3323,7 @@ unsafe extern "C" fn default_rule_thickness() -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathex_param(f, 8i32) } else { rval = (*font_info.offset((8i32 + *param_base.offset(f as isize)) as isize)) @@ -4260,10 +3357,7 @@ unsafe extern "C" fn big_op_spacing1() -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathex_param(f, 9i32) } else { rval = (*font_info.offset((9i32 + *param_base.offset(f as isize)) as isize)) @@ -4297,10 +3391,7 @@ unsafe extern "C" fn big_op_spacing2() -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathex_param(f, 10i32) } else { rval = (*font_info.offset((10i32 + *param_base.offset(f as isize)) as isize)) @@ -4334,10 +3425,7 @@ unsafe extern "C" fn big_op_spacing3() -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathex_param(f, 11i32) } else { rval = (*font_info.offset((11i32 + *param_base.offset(f as isize)) as isize)) @@ -4371,10 +3459,7 @@ unsafe extern "C" fn big_op_spacing4() -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathex_param(f, 12i32) } else { rval = (*font_info.offset((12i32 + *param_base.offset(f as isize)) as isize)) @@ -4408,10 +3493,7 @@ unsafe extern "C" fn big_op_spacing5() -> scaled_t { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rval = get_native_mathex_param(f, 13i32) } else { rval = (*font_info.offset((13i32 + *param_base.offset(f as isize)) as isize)) @@ -4626,9 +3708,7 @@ unsafe extern "C" fn fetch(mut a: i32) { error(); cur_i = null_character; (*mem.offset(a as isize)).b32.s1 = 0i32 - } else if *font_area.offset(cur_f as isize) as u32 == 0xffffu32 - || *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - { + } else if get_text_layout_engine(cur_f as usize).is_some() { cur_i = null_character } else { if cur_c >= *font_bc.offset(cur_f as isize) as i32 @@ -4714,10 +3794,7 @@ unsafe extern "C" fn make_radical(mut q: i32) { )) .b32 .s1; - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { rule_thickness = get_ot_math_constant(f, 51i32) } else { rule_thickness = default_rule_thickness() @@ -4726,10 +3803,7 @@ unsafe extern "C" fn make_radical(mut q: i32) { q + 1i32, (2i32 * (cur_style as i32 / 2i32) + 1i32) as small_number, ); - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { if (cur_style as i32) < 2i32 { clr = get_ot_math_constant(f, 50i32) } else { @@ -4749,10 +3823,7 @@ unsafe extern "C" fn make_radical(mut q: i32) { + clr + rule_thickness, ); - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0 - { + if is_opentype_math_font(f as usize) { (*mem.offset((y + 2i32) as isize)).b32.s1 = (*mem.offset((y + 3i32) as isize)).b32.s1 + (*mem.offset((y + 2i32) as isize)).b32.s1 - rule_thickness; @@ -4770,6 +3841,7 @@ unsafe extern "C" fn make_radical(mut q: i32) { (*mem.offset((q + 1i32) as isize)).b32.s0 = hpack(y, 0i32, 1i32 as small_number); (*mem.offset((q + 1i32) as isize)).b32.s1 = 2i32; } + unsafe extern "C" fn compute_ot_math_accent_pos(mut p: i32) -> scaled_t { let mut q: i32 = 0; let mut r: i32 = 0; @@ -4819,9 +3891,8 @@ unsafe extern "C" fn make_math_accent(mut q: i32) { fetch(q + 4i32); x = -0xfffffffi32; ot_assembly_ptr = 0 as *mut libc::c_void; - if *font_area.offset(cur_f as isize) as u32 == 0xffffu32 - || *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(cur_f as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { c = cur_c; f = cur_f; if !((*mem.offset(q as isize)).b16.s0 as i32 == 2i32 @@ -4904,11 +3975,7 @@ unsafe extern "C" fn make_math_accent(mut q: i32) { } /*:767*/ if x != -0xfffffffi32 { - if *font_area.offset(f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { if (*mem.offset(q as isize)).b16.s0 as i32 == 2i32 || (*mem.offset(q as isize)).b16.s0 as i32 == 2i32 + 1i32 { @@ -4949,9 +4016,8 @@ unsafe extern "C" fn make_math_accent(mut q: i32) { } } y = char_box(f, c); - if *font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(f as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { p = get_node(5i32); (*mem.offset(p as isize)).b16.s1 = 8_u16; (*mem.offset(p as isize)).b16.s0 = 42_u16; @@ -5112,11 +4178,7 @@ unsafe extern "C" fn make_fraction(mut q: i32) { } if (*mem.offset((q + 1i32) as isize)).b32.s1 == 0i32 { /*772:*/ - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { if (cur_style as i32) < 2i32 { clr = get_ot_math_constant(cur_f, 27i32) } else { @@ -5137,11 +4199,7 @@ unsafe extern "C" fn make_fraction(mut q: i32) { shift_down = shift_down + delta } } else { - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { delta = half((*mem.offset((q + 1i32) as isize)).b32.s1); if (cur_style as i32) < 2i32 { clr = get_ot_math_constant(cur_f, 37i32) @@ -5255,11 +4313,7 @@ unsafe extern "C" fn make_op(mut q: i32) -> scaled_t { ot_assembly_ptr = 0 as *mut libc::c_void; if (*mem.offset((q + 1i32) as isize)).b32.s1 == 1i32 { fetch(q + 1i32); - if !(*font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && usingOpenType(*font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine) - as i32 - != 0) - { + if is_using_opentype(cur_f as u32) { if (cur_style as i32) < 2i32 && cur_i.s1 as i32 % 4i32 == 2i32 { c = cur_i.s0; i = (*font_info.offset((*char_base.offset(cur_f as isize) + c as i32) as isize)) @@ -5276,11 +4330,7 @@ unsafe extern "C" fn make_op(mut q: i32) -> scaled_t { .s1 } x = clean_box(q + 1i32, cur_style); - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { p = (*mem.offset((x + 5i32) as isize)).b32.s1; if p != -0xfffffffi32 && !is_char_node(p) @@ -5641,11 +4691,7 @@ unsafe extern "C" fn make_scripts(mut q: i32, mut delta: scaled_t) { if shift_down < sub1(cur_size) { shift_down = sub1(cur_size) } - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { clr = (*mem.offset((x + 3i32) as isize)).b32.s1 - get_ot_math_constant(cur_f, 9i32) } else { clr = (*mem.offset((x + 3i32) as isize)).b32.s1 @@ -5655,21 +4701,12 @@ unsafe extern "C" fn make_scripts(mut q: i32, mut delta: scaled_t) { shift_down = clr } (*mem.offset((x + 4i32) as isize)).b32.s1 = shift_down; - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { /*787: */ if (*mem.offset((q + 3i32) as isize)).b32.s1 == 1i32 { save_f = cur_f; fetch(q + 3i32); - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { script_c = new_native_character(cur_f, cur_c); script_g = real_get_native_glyph( &mut *mem.offset(script_c as isize) as *mut memory_word @@ -5751,11 +4788,7 @@ unsafe extern "C" fn make_scripts(mut q: i32, mut delta: scaled_t) { if shift_up < clr { shift_up = clr } - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { clr = (*mem.offset((x + 2i32) as isize)).b32.s1 + get_ot_math_constant(cur_f, 13i32) } else { clr = (*mem.offset((x + 2i32) as isize)).b32.s1 + math_x_height(cur_size).abs() / 4i32 @@ -5763,21 +4796,12 @@ unsafe extern "C" fn make_scripts(mut q: i32, mut delta: scaled_t) { if shift_up < clr { shift_up = clr } - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont(*font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { /*788: */ if (*mem.offset((q + 2i32) as isize)).b32.s1 == 1i32 { save_f = cur_f; fetch(q + 2i32); - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { script_c = new_native_character(cur_f, cur_c); script_g = real_get_native_glyph( &mut *mem.offset(script_c as isize) as *mut memory_word @@ -5855,12 +4879,7 @@ unsafe extern "C" fn make_scripts(mut q: i32, mut delta: scaled_t) { if shift_down < sub2(cur_size) { shift_down = sub2(cur_size) } - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { clr = get_ot_math_constant(cur_f, 15i32) - (shift_up - (*mem.offset((x + 2i32) as isize)).b32.s1 @@ -5873,12 +4892,7 @@ unsafe extern "C" fn make_scripts(mut q: i32, mut delta: scaled_t) { } if clr > 0i32 { shift_down = shift_down + clr; - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { clr = get_ot_math_constant(cur_f, 16i32) - (shift_up - (*mem.offset((x + 2i32) as isize)).b32.s1) } else { @@ -5890,21 +4904,11 @@ unsafe extern "C" fn make_scripts(mut q: i32, mut delta: scaled_t) { shift_down = shift_down - clr } } - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { if (*mem.offset((q + 3i32) as isize)).b32.s1 == 1i32 { save_f = cur_f; fetch(q + 3i32); - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { script_c = new_native_character(cur_f, cur_c); script_g = real_get_native_glyph( &mut *mem.offset(script_c as isize) as *mut memory_word @@ -5938,12 +4942,7 @@ unsafe extern "C" fn make_scripts(mut q: i32, mut delta: scaled_t) { if (*mem.offset((q + 2i32) as isize)).b32.s1 == 1i32 { save_f = cur_f; fetch(q + 2i32); - if *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset(cur_f as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { + if is_opentype_math_font(cur_f as usize) { script_c = new_native_character(cur_f, cur_c); script_g = real_get_native_glyph( &mut *mem.offset(script_c as isize) as *mut memory_word @@ -6302,9 +5301,8 @@ unsafe extern "C" fn mlist_to_hlist() { match (*mem.offset((q + 1i32) as isize)).b32.s1 { 1 | 4 => { fetch(q + 1i32); - if *font_area.offset(cur_f as isize) as u32 == 0xffffu32 - || *font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(cur_f as usize); + if engine.as_ref().map(|x| &**x).is_some() { z = new_native_character(cur_f, cur_c); p = get_node(5i32); (*mem.offset(p as isize)).b16.s1 = 8_u16; @@ -6326,13 +5324,7 @@ unsafe extern "C" fn mlist_to_hlist() { (*mem.offset((p + 4i32) as isize)).b16.s1 as i32, ); if (*mem.offset((q + 1i32) as isize)).b32.s1 == 4i32 - && !(*font_area.offset(cur_f as isize) as u32 == 0xfffeu32 - && isOpenTypeMathFont( - *font_layout_engine.offset(cur_f as isize) - as XeTeXLayoutEngine, - ) as i32 - != 0) as i32 - != 0i32 + && !is_opentype_math_font(cur_f as usize) { delta = 0i32 } @@ -6710,11 +5702,11 @@ unsafe extern "C" fn var_delimiter(mut d: i32, mut s: i32, mut v: scaled_t) -> i let mut u: scaled_t = 0; let mut w: scaled_t = 0; let mut q: b16x4 = b16x4_le_t { - s0: 0_u16, - s1: 0_u16, - s2: 0_u16, - s3: 0_u16, - }; + s0: 0_u16, + s1: 0_u16, + s2: 0_u16, + s3: 0_u16, + }; let mut r: b16x4 = b16x4 { s0: 0, s1: 0, @@ -6735,35 +5727,10 @@ unsafe extern "C" fn var_delimiter(mut d: i32, mut s: i32, mut v: scaled_t) -> i z = z + s + 256i32; loop { z = z - 256i32; - g = (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + z) as isize, - )) - .b32 - .s1; + g = math_font(z as isize) as i32; if g != 0i32 { /*734: */ - if *font_area.offset(g as isize) as u32 == 0xfffeu32 - && usingOpenType(*font_layout_engine.offset(g as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { + if is_using_opentype(g as u32) { x = map_char_to_glyph(g, x as i32) as u16; f = g; c = x; @@ -6846,10 +5813,7 @@ unsafe extern "C" fn var_delimiter(mut d: i32, mut s: i32, mut v: scaled_t) -> i + ((*mem.offset(d as isize)).b16.s1 as i32 / 256i32) as i64 * 65536) as u16 } if f != 0i32 { - if !(*font_area.offset(f as isize) as u32 == 0xfffeu32 - && usingOpenType(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) as i32 - != 0) - { + if !is_using_opentype(f as u32) { /*736: */ if q.s1 as i32 % 4i32 == 3i32 { /*739: */ @@ -7025,9 +5989,8 @@ unsafe extern "C" fn char_box(mut f: internal_font_number, mut c: i32) -> i32 { }; let mut b: i32 = 0; let mut p: i32 = 0; - if *font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(f as usize); + if engine.as_ref().map(|x| &**x).is_some() { b = new_null_box(); p = new_native_character(f, c); (*mem.offset((b + 5i32) as isize)).b32.s1 = p; diff --git a/engine/src/xetex_opentype_math.rs b/engine/src/xetex_opentype_math.rs index 6e52e5fa0..023ee8b58 100644 --- a/engine/src/xetex_opentype_math.rs +++ b/engine/src/xetex_opentype_math.rs @@ -1,51 +1,28 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] use crate::core_memory::xmalloc; +use crate::xetex_ext::{D2Fix, Fix2D}; +use crate::xetex_font_info::XeTeXFontInst; +use crate::xetex_font_info::{ + XeTeXFontInst_getHbFont, XeTeXFontInst_pointsToUnits, XeTeXFontInst_unitsToPoints, +}; +use crate::xetex_font_manager::PlatformFontRef; +use crate::xetex_layout_engine::{getFontInst, XeTeXLayoutEngine}; +use crate::xetex_ini::{get_text_layout_engine, font_size}; +use crate::text_layout_engine::{TextLayoutEngine, TextLayout}; use harfbuzz_sys::*; -use freetype::freetype_sys; extern "C" { - pub type XeTeXFont_rec; - pub type XeTeXLayoutEngine_rec; #[no_mangle] fn free(__ptr: *mut libc::c_void); - #[no_mangle] - fn getFont(engine: XeTeXLayoutEngine) -> XeTeXFont; - #[no_mangle] - fn getGlyphHeightDepth( - engine: XeTeXLayoutEngine, - glyphID: uint32_t, - height: *mut libc::c_float, - depth: *mut libc::c_float, - ); - #[no_mangle] - fn Fix2D(f: Fixed) -> libc::c_double; - #[no_mangle] - fn D2Fix(d: libc::c_double) -> Fixed; - #[no_mangle] - static mut font_layout_engine: *mut *mut libc::c_void; - #[no_mangle] - static mut font_area: *mut int32_t; - #[no_mangle] - static mut font_size: *mut int32_t; - #[no_mangle] - fn XeTeXFontInst_getHbFont(self_0: *const XeTeXFontInst) -> *mut hb_font_t; - #[no_mangle] - fn XeTeXFontInst_unitsToPoints( - self_0: *const XeTeXFontInst, - units: libc::c_float, - ) -> libc::c_float; - #[no_mangle] - fn XeTeXFontInst_pointsToUnits( - self_0: *const XeTeXFontInst, - points: libc::c_float, - ) -> libc::c_float; } pub type size_t = usize; pub type int32_t = i32; @@ -65,33 +42,12 @@ pub const HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER: hb_ot_math_glyph_part_flags_t = 1 /* our typedefs */ pub type Fixed = i32; -pub type XeTeXFont = *mut XeTeXFont_rec; -pub type XeTeXLayoutEngine = *mut XeTeXLayoutEngine_rec; #[derive(Copy, Clone)] #[repr(C)] pub struct GlyphAssembly { pub count: libc::c_uint, pub parts: *mut hb_ot_math_glyph_part_t, } -#[derive(Copy, Clone)] -#[repr(C)] -pub struct XeTeXFontInst { - pub m_unitsPerEM: libc::c_ushort, - pub m_pointSize: libc::c_float, - pub m_ascent: libc::c_float, - pub m_descent: libc::c_float, - pub m_capHeight: libc::c_float, - pub m_xHeight: libc::c_float, - pub m_italicAngle: libc::c_float, - pub m_vertical: bool, - pub m_filename: *mut libc::c_char, - pub m_index: uint32_t, - pub m_ftFace: freetype_sys::FT_Face, - pub m_backingData: *mut freetype_sys::FT_Byte, - pub m_backingData2: *mut freetype_sys::FT_Byte, - pub m_hbFont: *mut hb_font_t, - pub m_subdtor: Option ()>, -} /* ***************************************************************************\ Part of the XeTeX typesetting system Copyright (c) 1994-2008 by SIL International @@ -131,10 +87,9 @@ pub unsafe extern "C" fn get_ot_math_constant( ) -> libc::c_int { let mut constant: hb_ot_math_constant_t = n as hb_ot_math_constant_t; let mut rval: hb_position_t = 0i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + let font = eng.font; let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font); rval = hb_ot_math_get_constant(hbFont, constant); /* scale according to font size, except the ones that are percentages */ @@ -263,11 +218,9 @@ pub unsafe extern "C" fn get_ot_math_variant( ) -> libc::c_int { let mut rval: hb_codepoint_t = g as hb_codepoint_t; *adv = -1i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; - let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font); + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(eng.font); let mut variant: [hb_ot_math_glyph_variant_t; 1] = [hb_ot_math_glyph_variant_t { glyph: 0, advance: 0, @@ -288,7 +241,7 @@ pub unsafe extern "C" fn get_ot_math_variant( if count > 0i32 as libc::c_uint { rval = (*variant.as_mut_ptr()).glyph; *adv = D2Fix(XeTeXFontInst_unitsToPoints( - font, + eng.font, (*variant.as_mut_ptr()).advance as libc::c_float, ) as libc::c_double) } @@ -302,11 +255,9 @@ pub unsafe extern "C" fn get_ot_assembly_ptr( mut horiz: libc::c_int, ) -> *mut libc::c_void { let mut rval: *mut libc::c_void = 0 as *mut libc::c_void; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; - let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font); + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(eng.font); let mut count: libc::c_uint = hb_ot_math_get_glyph_assembly( hbFont, g as hb_codepoint_t, @@ -361,13 +312,11 @@ pub unsafe extern "C" fn get_ot_math_ital_corr( mut g: libc::c_int, ) -> libc::c_int { let mut rval: hb_position_t = 0i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; - let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font); + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(eng.font); rval = hb_ot_math_get_glyph_italics_correction(hbFont, g as hb_codepoint_t); - rval = D2Fix(XeTeXFontInst_unitsToPoints(font, rval as libc::c_float) as libc::c_double) + rval = D2Fix(XeTeXFontInst_unitsToPoints(eng.font, rval as libc::c_float) as libc::c_double) } return rval; } @@ -377,29 +326,26 @@ pub unsafe extern "C" fn get_ot_math_accent_pos( mut g: libc::c_int, ) -> libc::c_int { let mut rval: hb_position_t = 0x7fffffffu64 as hb_position_t; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; - let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font); + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(eng.font); rval = hb_ot_math_get_glyph_top_accent_attachment(hbFont, g as hb_codepoint_t); - rval = D2Fix(XeTeXFontInst_unitsToPoints(font, rval as libc::c_float) as libc::c_double) + rval = D2Fix(XeTeXFontInst_unitsToPoints(eng.font, rval as libc::c_float) as libc::c_double) } return rval; } #[no_mangle] pub unsafe extern "C" fn ot_min_connector_overlap(mut f: libc::c_int) -> libc::c_int { let mut rval: hb_position_t = 0i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; - let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font); + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(eng.font); rval = hb_ot_math_get_min_connector_overlap(hbFont, HB_DIRECTION_RTL); - rval = D2Fix(XeTeXFontInst_unitsToPoints(font, rval as libc::c_float) as libc::c_double) + rval = D2Fix(XeTeXFontInst_unitsToPoints(eng.font, rval as libc::c_float) as libc::c_double) } return rval; } + unsafe extern "C" fn getMathKernAt( mut f: libc::c_int, mut g: libc::c_int, @@ -407,34 +353,34 @@ unsafe extern "C" fn getMathKernAt( mut height: libc::c_int, ) -> libc::c_int { let mut rval: hb_position_t = 0i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; - let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(font); + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + let mut hbFont: *mut hb_font_t = XeTeXFontInst_getHbFont(eng.font); rval = hb_ot_math_get_glyph_kerning(hbFont, g as hb_codepoint_t, side, height) } return rval; } + unsafe extern "C" fn glyph_height(mut f: libc::c_int, mut g: libc::c_int) -> libc::c_float { - let mut rval: libc::c_float = 0.0f64 as libc::c_float; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine; - getGlyphHeightDepth(engine, g as uint32_t, &mut rval, 0 as *mut libc::c_float); + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + if let Some((height, _depth)) = eng.glyph_height_depth(g as u32) { + return height; + } } - return rval; + 0. } + unsafe extern "C" fn glyph_depth(mut f: libc::c_int, mut g: libc::c_int) -> libc::c_float { - let mut rval: libc::c_float = 0.0f64 as libc::c_float; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut engine: XeTeXLayoutEngine = - *font_layout_engine.offset(f as isize) as XeTeXLayoutEngine; - getGlyphHeightDepth(engine, g as uint32_t, 0 as *mut libc::c_float, &mut rval); + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { + if let Some((_height, depth)) = eng.glyph_height_depth(g as u32) { + return depth; + } } - return rval; + 0. } -#[no_mangle] + pub unsafe extern "C" fn get_ot_math_kern( mut f: libc::c_int, mut g: libc::c_int, @@ -444,19 +390,17 @@ pub unsafe extern "C" fn get_ot_math_kern( mut shift: libc::c_int, ) -> libc::c_int { let mut rval: libc::c_int = 0i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { let mut kern: libc::c_int = 0i32; let mut skern: libc::c_int = 0i32; let mut corr_height_top: libc::c_float = 0.0f64 as libc::c_float; let mut corr_height_bot: libc::c_float = 0.0f64 as libc::c_float; if cmd == 0i32 { // superscript - corr_height_top = XeTeXFontInst_pointsToUnits(font, glyph_height(f, g)); + corr_height_top = XeTeXFontInst_pointsToUnits(eng.font, glyph_height(f, g)); corr_height_bot = -XeTeXFontInst_pointsToUnits( - font, + eng.font, (glyph_depth(sf, sg) as libc::c_double + Fix2D(shift)) as libc::c_float, ); kern = getMathKernAt( @@ -490,10 +434,10 @@ pub unsafe extern "C" fn get_ot_math_kern( } else if cmd == 1i32 { // subscript corr_height_top = XeTeXFontInst_pointsToUnits( - font, + eng.font, (glyph_height(sf, sg) as libc::c_double - Fix2D(shift)) as libc::c_float, ); - corr_height_bot = -XeTeXFontInst_pointsToUnits(font, glyph_depth(f, g)); + corr_height_bot = -XeTeXFontInst_pointsToUnits(eng.font, glyph_depth(f, g)); kern = getMathKernAt( f, g, @@ -526,7 +470,7 @@ pub unsafe extern "C" fn get_ot_math_kern( unreachable!() // we should not reach here } - return D2Fix(XeTeXFontInst_unitsToPoints(font, rval as libc::c_float) as libc::c_double); + return D2Fix(XeTeXFontInst_unitsToPoints(eng.font, rval as libc::c_float) as libc::c_double); } return 0i32; } @@ -557,12 +501,10 @@ pub unsafe extern "C" fn ot_part_start_connector( mut i: libc::c_int, ) -> libc::c_int { let mut rval: libc::c_int = 0i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { rval = D2Fix(XeTeXFontInst_unitsToPoints( - font, + eng.font, (*(*a).parts.offset(i as isize)).start_connector_length as libc::c_float, ) as libc::c_double) } @@ -575,12 +517,10 @@ pub unsafe extern "C" fn ot_part_end_connector( mut i: libc::c_int, ) -> libc::c_int { let mut rval: libc::c_int = 0i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { rval = D2Fix(XeTeXFontInst_unitsToPoints( - font, + eng.font, (*(*a).parts.offset(i as isize)).end_connector_length as libc::c_float, ) as libc::c_double) } @@ -624,12 +564,10 @@ pub unsafe extern "C" fn ot_part_full_advance( mut i: libc::c_int, ) -> libc::c_int { let mut rval: libc::c_int = 0i32; - if *font_area.offset(f as isize) as libc::c_uint == 0xfffeu32 { - let mut font: *mut XeTeXFontInst = - getFont(*font_layout_engine.offset(f as isize) as XeTeXLayoutEngine) - as *mut XeTeXFontInst; + let engine = get_text_layout_engine(f as usize); + if let Some(TextLayoutEngine::XeTeX(eng)) = engine.as_ref().map(|x| &**x) { rval = D2Fix(XeTeXFontInst_unitsToPoints( - font, + eng.font, (*(*a).parts.offset(i as isize)).full_advance as libc::c_float, ) as libc::c_double) } diff --git a/engine/src/xetex_shipout.rs b/engine/src/xetex_shipout.rs index bb5b14450..a30ae27bc 100644 --- a/engine/src/xetex_shipout.rs +++ b/engine/src/xetex_shipout.rs @@ -18,14 +18,14 @@ use crate::xetex_ext::{ use crate::xetex_ini::{ avail, char_base, cur_area, cur_cs, cur_dir, cur_ext, cur_h, cur_h_offset, cur_list, cur_name, cur_page_height, cur_page_width, cur_tok, cur_v, cur_v_offset, dead_cycles, def_ref, - doing_leaders, doing_special, eqtb, file_line_error_style_p, file_offset, font_area, font_bc, - font_check, font_dsize, font_ec, font_glue, font_info, font_letter_space, font_mapping, - font_name, font_ptr, font_size, font_used, help_line, help_ptr, init_pool_ptr, job_name, - last_bop, log_opened, max_h, max_print_line, max_push, max_v, mem, name_of_file, - output_file_extension, pdf_last_x_pos, pdf_last_y_pos, pool_ptr, pool_size, rule_dp, rule_ht, - rule_wd, rust_stdout, selector, semantic_pagination_enabled, str_pool, str_ptr, str_start, - temp_ptr, term_offset, total_pages, width_base, write_file, write_loc, write_open, xdv_buffer, - xtx_ligature_present, LR_problems, LR_ptr, + doing_leaders, doing_special, eqtb, file_line_error_style_p, file_offset, font_bc, font_check, + font_dsize, font_ec, font_glue, font_info, font_letter_space, font_mapping, font_name, + font_ptr, font_size, font_used, help_line, help_ptr, init_pool_ptr, job_name, last_bop, + log_opened, max_h, max_print_line, max_push, max_v, mem, name_of_file, output_file_extension, + pdf_last_x_pos, pdf_last_y_pos, pool_ptr, pool_size, rule_dp, rule_ht, rule_wd, rust_stdout, + selector, semantic_pagination_enabled, str_pool, str_ptr, str_start, temp_ptr, term_offset, + total_pages, width_base, write_file, write_loc, write_open, xdv_buffer, xtx_ligature_present, + LR_problems, LR_ptr, FONT_AREA, get_text_layout_engine, }; use crate::xetex_ini::{memory_word, Selector}; use crate::xetex_output::{ @@ -2971,9 +2971,8 @@ unsafe extern "C" fn dvi_native_font_def(mut f: internal_font_number) { unsafe extern "C" fn dvi_font_def(mut f: internal_font_number) { let mut k: pool_pointer = 0; let mut l: i32 = 0; - if *font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(f as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { dvi_native_font_def(f); } else { if f <= 256i32 { @@ -2990,7 +2989,7 @@ unsafe extern "C" fn dvi_font_def(mut f: internal_font_number) { dvi_out((*font_check.offset(f as isize)).s0 as u8); dvi_four(*font_size.offset(f as isize)); dvi_four(*font_dsize.offset(f as isize)); - dvi_out(length(*font_area.offset(f as isize)) as u8); + dvi_out(length(*FONT_AREA.offset(f as isize)) as u8); l = 0i32; k = *str_start.offset((*font_name.offset(f as isize) as i64 - 65536) as isize); while l == 0i32 @@ -3007,9 +3006,9 @@ unsafe extern "C" fn dvi_font_def(mut f: internal_font_number) { } dvi_out(l as u8); let mut for_end: i32 = 0; - k = *str_start.offset((*font_area.offset(f as isize) as i64 - 65536) as isize); + k = *str_start.offset((*FONT_AREA.offset(f as isize) as i64 - 65536) as isize); for_end = *str_start - .offset(((*font_area.offset(f as isize) + 1i32) as i64 - 65536) as isize) + .offset(((*FONT_AREA.offset(f as isize) + 1i32) as i64 - 65536) as isize) - 1i32; if k <= for_end { loop { diff --git a/engine/src/xetex_xetex0.rs b/engine/src/xetex_xetex0.rs index 915537b39..3fc03b5f6 100644 --- a/engine/src/xetex_xetex0.rs +++ b/engine/src/xetex_xetex0.rs @@ -8,6 +8,11 @@ unused_mut )] +use crate::xetex_ini::{current_font_num, get_text_layout_engine}; + +use crate::text_layout_engine::{TextLayout, TextLayoutEngine}; + +use std::ffi::CStr; use std::io::Write; use super::xetex_ini::Selector; @@ -23,14 +28,12 @@ use crate::xetex_consts::*; use crate::xetex_errors::{confusion, error, fatal_error, overflow, pdf_error}; use crate::xetex_ext::{ apply_mapping, apply_tfm_font_mapping, check_for_tfm_font_mapping, find_native_font, - get_encoding_mode_and_info, get_font_char_range, get_glyph_bounds, - get_native_char_height_depth, get_native_char_sidebearings, getnativechardp, getnativecharht, - getnativecharic, getnativecharwd, gr_font_get_named, gr_font_get_named_1, gr_print_font_name, - linebreak_next, linebreak_start, load_tfm_font_mapping, map_char_to_glyph, map_glyph_to_index, - measure_native_glyph, measure_native_node, ot_font_get, ot_font_get_1, ot_font_get_2, - ot_font_get_3, ot_get_font_metrics, print_glyph_name, print_utf8_str, - real_get_native_glyph_italic_correction, real_get_native_italic_correction, - real_get_native_word_cp, release_font_engine, + get_encoding_mode_and_info, get_glyph_bounds, get_native_char_height_depth, + get_native_char_sidebearings, getnativechardp, getnativecharht, getnativecharic, + getnativecharwd, linebreak_next, linebreak_start, + load_tfm_font_mapping, map_char_to_glyph, map_glyph_to_index, measure_native_glyph, + measure_native_node, print_glyph_name, print_utf8_str, real_get_native_glyph_italic_correction, + real_get_native_italic_correction, real_get_native_word_cp, }; use crate::xetex_ini::{ _xeq_level_array, active_width, adjust_tail, after_token, align_ptr, align_state, @@ -42,34 +45,34 @@ use crate::xetex_ini::{ cur_val1, cur_val_level, dead_cycles, def_ref, deletions_allowed, depth_base, depth_threshold, dig, disc_ptr, empty, eof_seen, eqtb, eqtb_top, error_count, error_line, expand_depth, expand_depth_count, ext_delimiter, exten_base, false_bchar, file_line_error_style_p, - file_name_quote_char, file_offset, first, first_count, fmem_ptr, font_area, font_bc, - font_bchar, font_check, font_dsize, font_ec, font_false_bchar, font_flags, font_glue, - font_in_short_display, font_info, font_layout_engine, font_letter_space, font_mapping, - font_max, font_mem_size, font_name, font_params, font_ptr, font_size, font_used, force_eof, - full_source_filename_stack, gave_char_warning_help, grp_stack, half_error_line, hash, - hash_extra, hash_high, hash_used, height_base, help_line, help_ptr, hi_mem_min, history, - hyphen_char, if_limit, if_line, if_stack, in_open, init_pool_ptr, init_str_ptr, input_file, - input_ptr, input_stack, ins_disc, insert_penalties, insert_src_special_auto, - insert_src_special_every_par, insert_src_special_every_vbox, interaction, is_hyph, - is_in_csname, italic_base, job_name, kern_base, last, last_badness, last_glue, last_kern, - last_leftmost_char, last_node_type, last_penalty, last_rightmost_char, lft_hit, lig_kern_base, - lig_stack, ligature_present, line, line_stack, lo_mem_max, loaded_font_design_size, - loaded_font_flags, loaded_font_letter_space, loaded_font_mapping, log_file, log_opened, - long_help_seen, long_state, mag_set, main_f, main_h, main_i, main_j, main_k, main_p, main_pp, - main_ppp, main_s, mapped_text, max_buf_stack, max_in_open, max_in_stack, max_nest_stack, - max_param_stack, max_print_line, max_reg_help_line, max_reg_num, max_save_stack, max_strings, - mem, mem_end, name_in_progress, name_length, name_length16, name_of_file, name_of_file16, - native_font_type_flag, native_len, native_text, native_text_size, nest, nest_ptr, nest_size, - no_new_control_sequence, old_setting, open_parens, output_active, pack_begin_line, - page_contents, page_so_far, page_tail, par_loc, par_token, param_base, param_ptr, param_size, - param_stack, pdf_last_x_pos, pdf_last_y_pos, pool_ptr, pool_size, pre_adjust_tail, prev_class, - prim, prim_eqtb, prim_used, pseudo_files, pstack, quoted_filename, radix, read_file, read_open, - rover, rt_hit, rust_stdout, sa_chain, sa_level, sa_null, sa_root, save_native_len, save_ptr, - save_size, save_stack, scanner_status, selector, set_box_allowed, shown_mode, skew_char, - skip_line, source_filename_stack, space_class, stack_size, stop_at_space, str_pool, str_ptr, - str_start, tally, temp_ptr, term_offset, tex_remainder, texmf_log_name, total_shrink, - total_stretch, trick_buf, trick_count, use_err_help, used_tectonic_coda_tokens, warning_index, - width_base, write_file, write_open, xtx_ligature_present, LR_problems, LR_ptr, + file_name_quote_char, file_offset, first, first_count, fmem_ptr, font_bc, font_bchar, + font_check, font_dsize, font_ec, font_false_bchar, font_flags, font_glue, + font_in_short_display, font_info, font_letter_space, font_mapping, font_max, font_mem_size, + font_name, font_params, font_ptr, font_size, font_used, force_eof, full_source_filename_stack, + gave_char_warning_help, grp_stack, half_error_line, hash, hash_extra, hash_high, hash_used, + height_base, help_line, help_ptr, hi_mem_min, history, hyphen_char, if_limit, if_line, + if_stack, in_open, init_pool_ptr, init_str_ptr, input_file, input_ptr, input_stack, ins_disc, + insert_penalties, insert_src_special_auto, insert_src_special_every_par, + insert_src_special_every_vbox, interaction, is_hyph, is_in_csname, italic_base, job_name, + kern_base, last, last_badness, last_glue, last_kern, last_leftmost_char, last_node_type, + last_penalty, last_rightmost_char, lft_hit, lig_kern_base, lig_stack, ligature_present, line, + line_stack, lo_mem_max, loaded_font_design_size, loaded_font_flags, loaded_font_letter_space, + loaded_font_mapping, log_file, log_opened, long_help_seen, long_state, mag_set, main_f, main_h, + main_i, main_j, main_k, main_p, main_pp, main_ppp, main_s, mapped_text, max_buf_stack, + max_in_open, max_in_stack, max_nest_stack, max_param_stack, max_print_line, max_reg_help_line, + max_reg_num, max_save_stack, max_strings, mem, mem_end, name_in_progress, name_length, + name_length16, name_of_file, name_of_file16, native_font_type_flag, native_len, native_text, + native_text_size, nest, nest_ptr, nest_size, no_new_control_sequence, old_setting, open_parens, + output_active, pack_begin_line, page_contents, page_so_far, page_tail, par_loc, par_token, + param_base, param_ptr, param_size, param_stack, pdf_last_x_pos, pdf_last_y_pos, pool_ptr, + pool_size, pre_adjust_tail, prev_class, prim, prim_eqtb, prim_used, pseudo_files, pstack, + quoted_filename, radix, read_file, read_open, rover, rt_hit, rust_stdout, sa_chain, sa_level, + sa_null, sa_root, save_native_len, save_ptr, save_size, save_stack, scanner_status, selector, + set_box_allowed, shown_mode, skew_char, skip_line, source_filename_stack, space_class, + stack_size, stop_at_space, str_pool, str_ptr, str_start, tally, temp_ptr, term_offset, + tex_remainder, texmf_log_name, total_shrink, total_stretch, trick_buf, trick_count, + use_err_help, used_tectonic_coda_tokens, warning_index, width_base, write_file, write_open, + xtx_ligature_present, LR_problems, LR_ptr, FONT_AREA, TEXT_LAYOUT_ENGINES, }; use crate::xetex_ini::{b16x4, b32x2, memory_word, prefixed_command}; use crate::xetex_io::{input_line, open_or_close_in, set_input_file_encoding, u_close}; @@ -80,6 +83,7 @@ use crate::xetex_math::{ math_fraction, math_left_right, math_limit_switch, math_radical, resume_after_display, start_eq_no, sub_sup, }; +use crate::xetex_opentype_math::get_ot_math_constant; use crate::xetex_output::{ print, print_char, print_cs, print_cstr, print_current_string, print_esc, print_esc_cstr, print_file_line, print_file_name, print_hex, print_int, print_ln, print_native_word, print_nl, @@ -4179,9 +4183,8 @@ pub unsafe extern "C" fn print_cmd_chr(mut cmd: u16, mut chr_code: i32) { 89 => { print_cstr(b"select font \x00" as *const u8 as *const i8); font_name_str = *font_name.offset(chr_code as isize); - if *font_area.offset(chr_code as isize) as u32 == 0xffffu32 - || *font_area.offset(chr_code as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(chr_code as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { let mut for_end: i32 = length(font_name_str) - 1i32; quote_char = '\"' as i32 as UTF16_code; n = 0i32; @@ -8705,6 +8708,7 @@ pub unsafe extern "C" fn expand() { (*mem.offset((4999999i32 - 13i32) as isize)).b32.s1 = backup_backup; expand_depth_count -= 1; } + #[no_mangle] pub unsafe extern "C" fn get_x_token() { loop { @@ -8731,6 +8735,7 @@ pub unsafe extern "C" fn get_x_token() { cur_tok = 0x1ffffffi32 + cur_cs }; } + #[no_mangle] pub unsafe extern "C" fn x_token() { while cur_cmd as i32 > 102i32 { @@ -8855,14 +8860,14 @@ pub unsafe extern "C" fn mu_error() { error(); } #[no_mangle] -pub unsafe extern "C" fn scan_glyph_number(mut f: internal_font_number) { +pub unsafe extern "C" fn scan_glyph_number(eng: &TextLayoutEngine) { if scan_keyword(b"/\x00" as *const u8 as *const i8) { scan_and_pack_name(); - cur_val = map_glyph_to_index(f); + cur_val = eng.map_glyph_to_index(name_of_file); cur_val_level = 0_u8 } else if scan_keyword(b"u\x00" as *const u8 as *const i8) { scan_char_num(); - cur_val = map_char_to_glyph(f, cur_val); + cur_val = eng.map_char_to_glyph(cur_val as u32) as i32; cur_val_level = 0_u8 } else { scan_int(); @@ -10366,10 +10371,9 @@ pub unsafe extern "C" fn scan_something_internal(mut level: small_number, mut ne cur_val_level = 0_u8 } else { n = cur_val; - if *font_area.offset(n as isize) as u32 == 0xffffu32 - || *font_area.offset(n as isize) as u32 == 0xfffeu32 - { - scan_glyph_number(n); + let engine = get_text_layout_engine(n as usize); + if let Some(eng) = engine.as_ref().map(|x| &**x) { + scan_glyph_number(eng); } else { scan_char_num(); } @@ -10573,55 +10577,10 @@ pub unsafe extern "C" fn scan_something_internal(mut level: small_number, mut ne if m >= 47i32 { match m { 47 => { + let font_num = current_font_num(); /*1435:*/ - if *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xffffu32 - || *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - { + let engine = get_text_layout_engine(font_num as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { scan_int(); /* shellenabledp */ n = cur_val; if n < 1i32 || n > 4i32 { @@ -10642,58 +10601,10 @@ pub unsafe extern "C" fn scan_something_internal(mut level: small_number, mut ne cur_val = 0i32 } else { scan_int(); - cur_val = get_glyph_bounds( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1, - n, - cur_val, - ) + cur_val = get_glyph_bounds(current_font_num() as i32, n, cur_val) } } else { - not_native_font_error( - 71i32, - m, - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1, - ); + not_native_font_error(71i32, m, current_font_num() as i32); cur_val = 0i32 } } @@ -10701,9 +10612,8 @@ pub unsafe extern "C" fn scan_something_internal(mut level: small_number, mut ne scan_font_ident(); q = cur_val; scan_usv_num(); - if *font_area.offset(q as isize) as u32 == 0xffffu32 - || *font_area.offset(q as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(q as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { match m { 48 => cur_val = getnativecharwd(q, cur_val), 49 => cur_val = getnativecharht(q, cur_val), @@ -10882,56 +10792,24 @@ pub unsafe extern "C" fn scan_something_internal(mut level: small_number, mut ne 15 => { scan_font_ident(); n = cur_val; - match *font_area.offset(n as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - cur_val = aat::aat_font_get( - m - 14i32, - (*font_layout_engine.offset(n as isize)) as _, - ) - } - 0xfffeu32 => { - cur_val = ot_font_get( - m - 14i32, - *font_layout_engine.offset(n as isize), - ) - } - _ => cur_val = 0i32, - } + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { + Some(eng) => eng.poorly_named_getter(m - 14), + None => 0, + }; } 22 => { scan_font_ident(); n = cur_val; - match *font_area.offset(n as isize) as u32 { + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { #[cfg(target_os = "macos")] - 0xffffu32 => { - cur_val = aat::aat_font_get( - m - 14i32, - (*font_layout_engine.offset(n as isize)) as _, - ) - } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { - cur_val = -1; + Some(TextLayoutEngine::AAT(eng)) => eng.poorly_named_getter(m - 14), + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingGraphite() => { + eng.poorly_named_getter(m - 14) } - 0xfffeu32 => { - if usingGraphite( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - cur_val = ot_font_get( - m - 14i32, - *font_layout_engine.offset(n as isize), - ); - } else { - cur_val = 0; - } - } - _ => { - cur_val = 0; - } - } + _ => 0, + }; } 17 | 19 | 20 | 21 | 16 => { scan_font_ident(); @@ -10941,530 +10819,228 @@ pub unsafe extern "C" fn scan_something_internal(mut level: small_number, mut ne 23 | 25 | 26 => { scan_font_ident(); n = cur_val; - match *font_area.offset(n as isize) as u32 { + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { #[cfg(target_os = "macos")] - 0xffffu32 => { + Some(TextLayoutEngine::AAT(eng)) => { scan_int(); k = cur_val; - cur_val = aat::aat_font_get_1( - m - 14i32, - (*font_layout_engine.offset(n as isize)) as _, - k, - ) + eng.poorly_named_getter_1(m - 14, k) } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingGraphite() => { scan_int(); k = cur_val; - cur_val = -1; - } - 0xfffeu32 => { - if usingGraphite( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - scan_int(); - k = cur_val; - cur_val = ot_font_get_1( - m - 14i32, - *font_layout_engine.offset(n as isize), - k, - ) - } else { - not_aat_gr_font_error(71i32, m, n); - cur_val = -1i32 - } + eng.poorly_named_getter_1(m - 14, k) } _ => { not_aat_gr_font_error(71i32, m, n); - cur_val = -1i32 + -1i32 } - } + }; } 27 | 29 => { scan_font_ident(); n = cur_val; - match *font_area.offset(n as isize) as u32 { + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { #[cfg(target_os = "macos")] - 0xffffu32 => { + Some(TextLayoutEngine::AAT(eng)) => { scan_int(); k = cur_val; scan_int(); - cur_val = aat::aat_font_get_2( - m - 14i32, - (*font_layout_engine.offset(n as isize)) as _, - k, - cur_val, - ) + eng.poorly_named_getter_2(m - 14, k, cur_val) } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingGraphite() => { scan_int(); k = cur_val; scan_int(); - cur_val = -1; - } - 0xfffeu32 => { - if usingGraphite( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - scan_int(); - k = cur_val; - scan_int(); - cur_val = ot_font_get_2( - m - 14i32, - *font_layout_engine.offset(n as isize), - k, - cur_val, - ) - } else { - not_aat_gr_font_error(71i32, m, n); - cur_val = -1i32 - } + eng.poorly_named_getter_2(m - 14, k, cur_val) } _ => { not_aat_gr_font_error(71i32, m, n); - cur_val = -1i32 + -1 } - } + }; } 18 => { scan_font_ident(); n = cur_val; - match *font_area.offset(n as isize) as u32 { + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { #[cfg(target_os = "macos")] - 0xffffu32 => { + Some(TextLayoutEngine::AAT(aat_eng)) => { scan_and_pack_name(); - cur_val = aat::aat_font_get_named( - m - 14i32, - (*font_layout_engine.offset(n as isize)) as _, - ); - } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { - scan_and_pack_name(); - cur_val = -1; + aat_eng.aat_font_get_named(m - 14) } _ => { not_aat_font_error(71i32, m, n); - cur_val = -1i32 + -1 } - } + }; } 24 => { scan_font_ident(); n = cur_val; - match *font_area.offset(n as isize) as u32 { + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { #[cfg(target_os = "macos")] - 0xffffu32 => { + Some(TextLayoutEngine::AAT(aat_eng)) => { scan_and_pack_name(); - cur_val = aat::aat_font_get_named( - m - 14i32, - (*font_layout_engine.offset(n as isize)) as _, - ); + aat_eng.aat_font_get_named(m - 14) } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { + Some(TextLayoutEngine::XeTeX(xetex_eng)) + if xetex_eng.usingGraphite() => + { scan_and_pack_name(); - cur_val = -1; - } - 0xfffeu32 => { - if usingGraphite( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - scan_and_pack_name(); - cur_val = gr_font_get_named( - m - 14i32, - *font_layout_engine.offset(n as isize), - ) - } else { - not_aat_gr_font_error(71i32, m, n); - cur_val = -1i32 - } + xetex_eng.gr_font_get_named(m - 14i32) } _ => { not_aat_gr_font_error(71i32, m, n); - cur_val = -1i32 + -1i32 } - } + }; } 28 => { scan_font_ident(); n = cur_val; - match *font_area.offset(n as isize) as u32 { + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { #[cfg(target_os = "macos")] - 0xffffu32 => { + Some(TextLayoutEngine::AAT(eng)) => { scan_int(); k = cur_val; - scan_and_pack_name(); - cur_val = aat::aat_font_get_named_1( - m - 14i32, - (*font_layout_engine.offset(n as isize)) as _, - k, - ); + eng.poorly_named_getter_1(m - 14, k) } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingGraphite() => { scan_int(); k = cur_val; scan_and_pack_name(); - cur_val = -1; - } - 0xfffeu32 => { - if usingGraphite( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - scan_int(); - k = cur_val; - scan_and_pack_name(); - cur_val = gr_font_get_named_1( - m - 14i32, - *font_layout_engine.offset(n as isize), - k, - ) - } else { - not_aat_gr_font_error(71i32, m, n); - cur_val = -1i32 - } + eng.poorly_named_getter_1(m - 14, k) } _ => { - not_aat_gr_font_error(71i32, m, n); - cur_val = -1i32 + not_aat_gr_font_error(71, m, n); + -1 } - } + }; } 30 => { scan_font_ident(); n = cur_val; - if *font_area.offset(n as isize) as u32 == 0xfffeu32 - && usingOpenType( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - cur_val = - ot_font_get(m - 14i32, *font_layout_engine.offset(n as isize)) - } else { - cur_val = 0i32 - } + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingOpenType() => { + eng.poorly_named_getter(m - 14) + } + _ =>{ + not_ot_font_error(71i32, m, n); + -1 + } + }; } 31 | 33 => { scan_font_ident(); n = cur_val; - if *font_area.offset(n as isize) as u32 == 0xfffeu32 - && usingOpenType( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - scan_int(); - cur_val = ot_font_get_1( - m - 14i32, - *font_layout_engine.offset(n as isize), - cur_val, - ) - } else { - not_ot_font_error(71i32, m, n); - cur_val = -1i32 - } + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingOpenType() => { + scan_int(); + k = cur_val; + eng.poorly_named_getter_1(m - 14, k) + } + _ =>{ + not_ot_font_error(71i32, m, n); + -1 + } + }; } 32 | 34 => { scan_font_ident(); n = cur_val; - if *font_area.offset(n as isize) as u32 == 0xfffeu32 - && usingOpenType( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - scan_int(); - k = cur_val; - scan_int(); - cur_val = ot_font_get_2( - m - 14i32, - *font_layout_engine.offset(n as isize), - k, - cur_val, - ) - } else { - not_ot_font_error(71i32, m, n); - cur_val = -1i32 - } + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingOpenType() => { + scan_int(); + k = cur_val; + scan_int(); + eng.poorly_named_getter_2(m - 14, k, cur_val) + } + _ =>{ + not_ot_font_error(71i32, m, n); + -1 + } + }; } 35 => { scan_font_ident(); n = cur_val; - if *font_area.offset(n as isize) as u32 == 0xfffeu32 - && usingOpenType( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - scan_int(); - k = cur_val; - scan_int(); - kk = cur_val; - scan_int(); - cur_val = ot_font_get_3( - m - 14i32, - *font_layout_engine.offset(n as isize), - k, - kk, - cur_val, - ) - } else { - not_ot_font_error(71i32, m, n); - cur_val = -1i32 - } + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingOpenType() => { + scan_int(); + k = cur_val; + scan_int(); + kk = cur_val; + scan_int(); + eng.poorly_named_getter_3( + m - 14i32, + k, + kk, + cur_val, + ) + } + _ => { + not_ot_font_error(71i32, m, n); + -1 + } + }; } 36 => { - if *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xffffu32 - || *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - { + let font_num = current_font_num(); + let engine = get_text_layout_engine(font_num); + cur_val = if let Some(eng) = engine.as_ref().map(|x| &**x) { scan_int(); n = cur_val; - cur_val = map_char_to_glyph( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1, - n, - ) + eng.map_char_to_glyph(n as u32) as i32 } else { - not_native_font_error( - 71i32, - m, - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1, - ); - cur_val = 0i32 + not_native_font_error(71i32, m, font_num as i32); + 0 } } 37 => { - if *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xffffu32 - || *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - { + let font_num = current_font_num(); + let engine = get_text_layout_engine(font_num); + cur_val = if let Some(eng) = engine.as_ref().map(|x| &**x) { scan_and_pack_name(); - cur_val = map_glyph_to_index( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1, - ) + // WHAT? WHY? + eng.map_glyph_to_index(name_of_file) } else { - not_native_font_error( - 71i32, - m, - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) - as isize, - )) - .b32 - .s1, - ); - cur_val = 0i32 + not_native_font_error(71i32, m, font_num as i32); + 0 } } 38 => { scan_font_ident(); n = cur_val; - if *font_area.offset(n as isize) as u32 == 0xffffu32 { - cur_val = 1i32 - } else if *font_area.offset(n as isize) as u32 == 0xfffeu32 - && usingOpenType( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - cur_val = 2i32 - } else if *font_area.offset(n as isize) as u32 == 0xfffeu32 - && usingGraphite( - *font_layout_engine.offset(n as isize) as XeTeXLayoutEngine - ) as i32 - != 0 - { - cur_val = 3i32 - } else { - cur_val = 0i32 - } + let engine = get_text_layout_engine(n as usize); + cur_val = match engine.as_ref().map(|x| &**x) { + #[cfg(target_os = "macos")] + Some(TextLayoutEngine::AAT(_)) => 1, + Some(TextLayoutEngine::XeTeX(e)) if e.usingOpenType() => 2, + Some(TextLayoutEngine::XeTeX(e)) if e.usingGraphite() => 3, + _ => 0, + }; } 39 | 40 => { scan_font_ident(); n = cur_val; - if *font_area.offset(n as isize) as u32 == 0xffffu32 - || *font_area.offset(n as isize) as u32 == 0xfffeu32 - { - cur_val = get_font_char_range(n, (m == 39i32) as i32) + let engine = get_text_layout_engine(n as usize); + cur_val = if let Some(eng) = engine.as_ref().map(|x| &**x) { + eng.font_char_range((m == 39) as i32) } else if m == 39i32 { - cur_val = *font_bc.offset(n as isize) as i32 + *font_bc.offset(n as isize) as i32 } else { - cur_val = *font_ec.offset(n as isize) as i32 - } + *font_ec.offset(n as isize) as i32 + }; } 41 => cur_val = pdf_last_x_pos, 42 => cur_val = pdf_last_y_pos, @@ -13447,57 +13023,68 @@ pub unsafe extern "C" fn conv_toks() { 7 => { scan_font_ident(); fnt = cur_val; - if *font_area.offset(fnt as isize) as u32 == 0xffffu32 { - scan_int(); - arg1 = cur_val; - arg2 = 0i32 - } else { - not_aat_font_error(110i32, c as i32, fnt); + let engine = get_text_layout_engine(fnt as usize); + match engine.as_ref().map(|x| &**x) { + #[cfg(target_os = "macos")] + Some(TextLayoutEngine::AAT(_)) => { + scan_int(); + arg1 = cur_val; + arg2 = 0; + } + _ => not_aat_font_error(110, c as i32, fnt), } } 8 => { - scan_font_ident(); - fnt = cur_val; - if *font_area.offset(fnt as isize) as u32 == 0xffffu32 - || *font_area.offset(fnt as isize) as u32 == 0xfffeu32 - && usingGraphite(*font_layout_engine.offset(fnt as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { - scan_int(); - arg1 = cur_val; - arg2 = 0i32 - } else { - not_aat_gr_font_error(110i32, c as i32, fnt); + scan_font_ident(); + fnt = cur_val; + let engine = get_text_layout_engine(fnt as usize); + match engine.as_ref().map(|x| &**x) { + #[cfg(target_os = "macos")] + Some(TextLayoutEngine::AAT(eng)) => { + scan_int(); + arg1 = cur_val; + arg2 = 0i32; + } + Some(TextLayoutEngine::XeTeX(eng)) if eng.usingGraphite() => { + scan_int(); + arg1 = cur_val; + arg2 = 0i32; + } + _ => not_aat_gr_font_error(110i32, c as i32, fnt), } } 9 => { scan_font_ident(); fnt = cur_val; - if *font_area.offset(fnt as isize) as u32 == 0xffffu32 - || *font_area.offset(fnt as isize) as u32 == 0xfffeu32 - && usingGraphite(*font_layout_engine.offset(fnt as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { - scan_int(); - arg1 = cur_val; - scan_int(); - arg2 = cur_val - } else { - not_aat_gr_font_error(110i32, c as i32, fnt); + let engine = get_text_layout_engine(fnt as usize); + match engine.as_ref().map(|x| &**x) { + #[cfg(target_os = "macos")] + Some(TextLayoutEngine::AAT(e)) => { + scan_int(); + arg1 = cur_val; + scan_int(); + arg2 = cur_val; + } + Some(TextLayoutEngine::XeTeX(e)) if e.usingGraphite() => { + scan_int(); + arg1 = cur_val; + scan_int(); + arg2 = cur_val; + } + _ => { + not_aat_gr_font_error(110i32, c as i32, fnt); + } } } 10 => { scan_font_ident(); fnt = cur_val; - if *font_area.offset(fnt as isize) as u32 == 0xffffu32 - || *font_area.offset(fnt as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(fnt as usize); + if let Some(_) = engine.as_ref().map(|x| &**x) { scan_int(); - arg1 = cur_val + arg1 = cur_val; } else { - not_native_font_error(110i32, c as i32, fnt); + not_aat_gr_font_error(110i32, c as i32, fnt); } } 11 | 12 => { @@ -13567,8 +13154,9 @@ pub unsafe extern "C" fn conv_toks() { } 4 => { font_name_str = *font_name.offset(cur_val as isize); - match *font_area.offset(cur_val as isize) as u32 { - 0xffffu32 | 0xfffeu32 => { + let engine = get_text_layout_engine(cur_val as usize); + match engine.as_ref().map(|x| &**x) { + Some(_eng) => { quote_char = '\"' as i32 as UTF16_code; i = 0i32 as small_number; while i as i32 <= length(font_name_str) - 1i32 { @@ -13608,63 +13196,26 @@ pub unsafe extern "C" fn conv_toks() { 6 => { print_cstr(b".99998\x00" as *const u8 as *const i8); } - 7 => { - match *font_area.offset(fnt as isize) as u32 { + 7 => { + let engine = get_text_layout_engine(fnt as usize); + match engine.as_ref().map(|x| &**x) { #[cfg(target_os = "macos")] - 0xffffu32 => { - aat::aat_print_font_name( - c as i32, - (*font_layout_engine.offset(fnt as isize)) as _, - arg1, - arg2, - ); - } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { - // do nothing - } - _ => { - // do nothing - } + Some(TextLayoutEngine::AAT(eng)) => eng.print_font_name(c as i32, arg1, arg2), + _ => {} } - } + }, 8 | 9 => { - match *font_area.offset(fnt as isize) as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - aat::aat_print_font_name( - c as i32, - (*font_layout_engine.offset(fnt as isize)) as _, - arg1, - arg2, - ); - } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { - // do nothing - } - 0xfffeu32 => { - if usingGraphite(*font_layout_engine.offset(fnt as isize) as XeTeXLayoutEngine) - as i32 - != 0 - { - gr_print_font_name( - c as i32, - *font_layout_engine.offset(fnt as isize), - arg1, - arg2, - ); - } - } - _ => {} + let engine = get_text_layout_engine(fnt as usize); + if let Some(eng) = engine.as_ref().map(|x| &**x) { + eng.print_font_name(c as i32, arg1, arg2); } } - 10 => match *font_area.offset(fnt as isize) as u32 { - 0xffffu32 | 0xfffeu32 => { + 10 => { + let engine = get_text_layout_engine(fnt as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { print_glyph_name(fnt, arg1); } - _ => {} - }, + } 11 => { p = (*mem.offset((p + 5i32) as isize)).b32.s1; while p != TEX_NULL @@ -14613,9 +14164,8 @@ pub unsafe extern "C" fn conditional() { scan_font_ident(); n = cur_val; scan_usv_num(); - if *font_area.offset(n as isize) as u32 == 0xffffu32 - || *font_area.offset(n as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(n as usize); + if let Some(engine) = engine.as_ref().map(|x| &**x) { b = map_char_to_glyph(n, cur_val) > 0i32 } else if *font_bc.offset(n as isize) as i32 <= cur_val && *font_ec.offset(n as isize) as i32 >= cur_val @@ -14927,6 +14477,7 @@ pub unsafe extern "C" fn end_name() { cur_ext = slow_make_string() }; } + #[no_mangle] pub unsafe extern "C" fn pack_file_name(mut n: str_number, mut a: str_number, mut e: str_number) { // Note that we populate the buffer in an order different than how the @@ -14953,6 +14504,7 @@ pub unsafe extern "C" fn pack_file_name(mut n: str_number, mut a: str_number, mu strcpy(name_of_file, work_buffer); free(work_buffer as *mut libc::c_void); } + #[no_mangle] pub unsafe extern "C" fn make_name_string() -> str_number { let mut k: i32 = 0; @@ -15014,6 +14566,7 @@ pub unsafe extern "C" fn scan_file_name() { end_name(); name_in_progress = false; } + #[no_mangle] pub unsafe extern "C" fn pack_job_name(mut s: *const i8) { cur_area = (65536 + 1i32 as i64) as str_number; @@ -15021,6 +14574,7 @@ pub unsafe extern "C" fn pack_job_name(mut s: *const i8) { cur_name = job_name; pack_file_name(cur_name, cur_area, cur_ext); } + #[no_mangle] pub unsafe extern "C" fn open_log_file() { let mut k: i32 = 0; @@ -15928,16 +15482,16 @@ pub unsafe extern "C" fn graphite_warning() { ); end_diagnostic(false); } + #[no_mangle] pub unsafe extern "C" fn load_native_font( mut u: i32, - mut nom: str_number, - mut aire: str_number, + mut name: str_number, + mut area: str_number, mut s: scaled_t, ) -> internal_font_number { let mut k: i32 = 0; let mut num_font_dimens: i32 = 0; - let mut font_engine: *mut libc::c_void = 0 as *mut libc::c_void; let mut actual_size: scaled_t = 0; let mut p: i32 = 0; let mut ascent: scaled_t = 0; @@ -15947,10 +15501,11 @@ pub unsafe extern "C" fn load_native_font( let mut cap_ht: scaled_t = 0; let mut f: internal_font_number = 0; let mut full_name: str_number = 0; - font_engine = find_native_font(name_of_file, s); - if font_engine.is_null() { - return 0i32; - } + let font_engine = if let Some(eng) = find_native_font(name_of_file, s) { + eng + } else { + return 0; + }; if s >= 0i32 { actual_size = s } else if s != -1000i32 { @@ -15974,20 +15529,17 @@ pub unsafe extern "C" fn load_native_font( full_name = make_string(); f = 0i32 + 1i32; while f <= font_ptr { - if *font_area.offset(f as isize) == native_font_type_flag + if *FONT_AREA.offset(f as isize) == native_font_type_flag && str_eq_str(*font_name.offset(f as isize), full_name) as i32 != 0 && *font_size.offset(f as isize) == actual_size { - release_font_engine(font_engine, native_font_type_flag); str_ptr -= 1; pool_ptr = *str_start.offset((str_ptr - 65536i32) as isize); return f; } f += 1 } - if native_font_type_flag as u32 == 0xfffeu32 - && isOpenTypeMathFont(font_engine as XeTeXLayoutEngine) as i32 != 0 - { + if font_engine.isOpenTypeMathFont() { num_font_dimens = 65i32 } else { num_font_dimens = 8i32 @@ -16004,7 +15556,7 @@ pub unsafe extern "C" fn load_native_font( if file_name_quote_char as i32 != 0i32 { print_char(file_name_quote_char as i32); } - print_file_name(nom, aire, cur_ext); + print_file_name(name, area, cur_ext); if file_name_quote_char as i32 != 0i32 { print_char(file_name_quote_char as i32); } @@ -16030,7 +15582,7 @@ pub unsafe extern "C" fn load_native_font( return 0i32; } font_ptr += 1; - *font_area.offset(font_ptr as isize) = native_font_type_flag; + *FONT_AREA.offset(font_ptr as isize) = native_font_type_flag; *font_name.offset(font_ptr as isize) = full_name; (*font_check.offset(font_ptr as isize)).s3 = 0_u16; (*font_check.offset(font_ptr as isize)).s2 = 0_u16; @@ -16039,33 +15591,15 @@ pub unsafe extern "C" fn load_native_font( *font_glue.offset(font_ptr as isize) = TEX_NULL; *font_dsize.offset(font_ptr as isize) = loaded_font_design_size; *font_size.offset(font_ptr as isize) = actual_size; - match native_font_type_flag as u32 { - #[cfg(target_os = "macos")] - 0xffffu32 => { - aat::aat_get_font_metrics( - font_engine as _, - &mut ascent, - &mut descent, - &mut x_ht, - &mut cap_ht, - &mut font_slant, - ); - } - #[cfg(not(target_os = "macos"))] - 0xffffu32 => { - // do nothing - } - _ => { - ot_get_font_metrics( - font_engine, - &mut ascent, - &mut descent, - &mut x_ht, - &mut cap_ht, - &mut font_slant, - ); - } - } + + font_engine.get_font_metrics( + &mut ascent, + &mut descent, + &mut x_ht, + &mut cap_ht, + &mut font_slant, + ); + *height_base.offset(font_ptr as isize) = ascent; *depth_base.offset(font_ptr as isize) = -descent; *font_params.offset(font_ptr as isize) = num_font_dimens; @@ -16131,8 +15665,9 @@ pub unsafe extern "C" fn load_native_font( .b32 .s1; *param_base.offset(font_ptr as isize) = fmem_ptr - 1i32; - let ref mut fresh51 = *font_layout_engine.offset(font_ptr as isize); - *fresh51 = font_engine; + + TEXT_LAYOUT_ENGINES.borrow_mut().insert(font_ptr as usize, font_engine); + let ref mut fresh52 = *font_mapping.offset(font_ptr as isize); *fresh52 = 0 as *mut libc::c_void; *font_letter_space.offset(font_ptr as isize) = loaded_font_letter_space; @@ -16182,6 +15717,7 @@ pub unsafe extern "C" fn load_native_font( *font_flags.offset(font_ptr as isize) = loaded_font_flags; font_ptr } + #[no_mangle] pub unsafe extern "C" fn do_locale_linebreaks(mut s: i32, mut len: i32) { let mut offs: i32 = 0; @@ -16534,11 +16070,12 @@ pub unsafe extern "C" fn get_tracing_fonts_state() -> i32 { .b32 .s1 } + #[no_mangle] pub unsafe extern "C" fn read_font_info( mut u: i32, - mut nom: str_number, - mut aire: str_number, + mut name: str_number, + mut area: str_number, mut s: scaled_t, ) -> internal_font_number { let mut k: font_index = 0; @@ -16576,7 +16113,7 @@ pub unsafe extern "C" fn read_font_info( g = FONT_BASE; - pack_file_name(nom, aire, cur_ext); + pack_file_name(name, area, cur_ext); if INTPAR(INT_PAR__xetex_tracing_fonts) > 0 { begin_diagnostic(); @@ -16595,28 +16132,28 @@ pub unsafe extern "C" fn read_font_info( } if quoted_filename { - g = load_native_font(u, nom, aire, s); + g = load_native_font(u, name, area, s); if g != FONT_BASE { return done(None, g); } } - name_too_long = length(nom) > 255i32 || length(aire) > 255i32; + name_too_long = length(name) > 255i32 || length(area) > 255i32; if name_too_long { - return bad_tfm(None, g, u, nom, aire, s, name_too_long); + return bad_tfm(None, g, u, name, area, s, name_too_long); } - pack_file_name(nom, aire, (65536 + 1i32 as i64) as str_number); + pack_file_name(name, area, (65536 + 1i32 as i64) as str_number); check_for_tfm_font_mapping(); let mut tfm_file_owner = tt_xetex_open_input(TTInputFormat::TFM); if tfm_file_owner.is_none() { if !quoted_filename { - g = load_native_font(u, nom, aire, s); + g = load_native_font(u, name, area, s); if g != FONT_BASE { return done(None, g); } } - return bad_tfm(None, g, u, nom, aire, s, name_too_long); + return bad_tfm(None, g, u, name, area, s, name_too_long); } let tfm_file = tfm_file_owner.as_mut().unwrap(); @@ -16629,7 +16166,7 @@ pub unsafe extern "C" fn read_font_info( ($x:expr) => { $x = ttstub_input_getc(tfm_file); if $x > 127 || $x == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } $x *= 256; $x += ttstub_input_getc(tfm_file); @@ -16643,7 +16180,7 @@ pub unsafe extern "C" fn read_font_info( READFIFTEEN!(ec); if bc > ec + 1 || ec > 255 { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } if bc > 255 { bc = 1; @@ -16660,9 +16197,9 @@ pub unsafe extern "C" fn read_font_info( READFIFTEEN!(np); if lf != 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } else if nw == 0 || nh == 0 || nd == 0 || ni == 0 { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } lf = lf - 6 - lh; @@ -16685,7 +16222,7 @@ pub unsafe extern "C" fn read_font_info( *exten_base.offset(f as isize) = *kern_base.offset(f as isize) + 256 * 128 + nk; *param_base.offset(f as isize) = *exten_base.offset(f as isize) + ne; if lh < 2 { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } a = ttstub_input_getc(tfm_file); qw.s3 = a as u16; @@ -16696,7 +16233,7 @@ pub unsafe extern "C" fn read_font_info( d = ttstub_input_getc(tfm_file); qw.s0 = d as u16; if a == libc::EOF || b == libc::EOF || c == libc::EOF || d == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } *font_check.offset(f as isize) = qw; @@ -16704,7 +16241,7 @@ pub unsafe extern "C" fn read_font_info( z = z * 256 + ttstub_input_getc(tfm_file); z = z * 16 + ttstub_input_getc(tfm_file) / 16; if z < 65536 { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } while lh > 2 { ttstub_input_getc(tfm_file); @@ -16737,28 +16274,28 @@ pub unsafe extern "C" fn read_font_info( d = ttstub_input_getc(tfm_file); qw.s0 = d as u16; if a == libc::EOF || b == libc::EOF || c == libc::EOF || d == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } (*font_info.offset(k as isize)).b16 = qw; if a >= nw || b / 16 >= nh || b % 16 >= nd || c / 4 >= ni { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } match c % 4 { 1 => { if d >= nl { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } 3 => { if d >= ne { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } 2 => { if d < bc || d > ec { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } loop { if !(d < k + bc - fmem_ptr) { @@ -16771,7 +16308,7 @@ pub unsafe extern "C" fn read_font_info( d = qw.s0 as i32 } if d == k + bc - fmem_ptr { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } _ => {} @@ -16793,7 +16330,7 @@ pub unsafe extern "C" fn read_font_info( c = ttstub_input_getc(tfm_file); d = ttstub_input_getc(tfm_file); if a == libc::EOF || b == libc::EOF || c == libc::EOF || d == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } sw = ((d * z / 256 + c * z) / 256 + b * z) / beta as i32; @@ -16802,7 +16339,7 @@ pub unsafe extern "C" fn read_font_info( } else if a == 255 { (*font_info.offset(k as isize)).b32.s1 = sw - alpha } else { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } @@ -16811,28 +16348,28 @@ pub unsafe extern "C" fn read_font_info( .s1 != 0 { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } if (*font_info.offset(*height_base.offset(f as isize) as isize)) .b32 .s1 != 0 { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } if (*font_info.offset(*depth_base.offset(f as isize) as isize)) .b32 .s1 != 0 { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } if (*font_info.offset(*italic_base.offset(f as isize) as isize)) .b32 .s1 != 0 { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } bch_label = 32767; @@ -16848,13 +16385,13 @@ pub unsafe extern "C" fn read_font_info( d = ttstub_input_getc(tfm_file); qw.s0 = d as u16; if a == libc::EOF || b == libc::EOF || c == libc::EOF || d == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } (*font_info.offset(k as isize)).b16 = qw; if a > 128 { if 256 * c + d >= nl { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } if a == 255 && k == *lig_kern_base.offset(f as isize) { bchar_0 = b as i16 @@ -16862,28 +16399,28 @@ pub unsafe extern "C" fn read_font_info( } else { if b != bchar_0 as i32 { if b < bc || b > ec { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } qw = (*font_info.offset((*char_base.offset(f as isize) + b) as isize)).b16; if !(qw.s3 > 0) { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } if c < 128 { if d < bc || d > ec { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } qw = (*font_info.offset((*char_base.offset(f as isize) + d) as isize)).b16; if !(qw.s3 > 0) { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } else if 256 * (c - 128) + d >= nk { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } if a < 128 && k - *lig_kern_base.offset(f as isize) + a + 1i32 >= nl { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } } @@ -16898,7 +16435,7 @@ pub unsafe extern "C" fn read_font_info( c = ttstub_input_getc(tfm_file); d = ttstub_input_getc(tfm_file); if a == libc::EOF || b == libc::EOF || c == libc::EOF || d == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } sw = ((d * z / 256i32 + c * z) / 256i32 + b * z) / beta as i32; if a == 0 { @@ -16906,7 +16443,7 @@ pub unsafe extern "C" fn read_font_info( } else if a == 255 { (*font_info.offset(k as isize)).b32.s1 = sw - alpha } else { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } @@ -16920,46 +16457,46 @@ pub unsafe extern "C" fn read_font_info( d = ttstub_input_getc(tfm_file); qw.s0 = d as u16; if a == libc::EOF || b == libc::EOF || c == libc::EOF || d == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } (*font_info.offset(k as isize)).b16 = qw; if a != 0 { if a < bc || a > ec { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } qw = (*font_info.offset((*char_base.offset(f as isize) + a) as isize)).b16; if !(qw.s3 as i32 > 0i32) { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } if b != 0 { if b < bc || b > ec { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } qw = (*font_info.offset((*char_base.offset(f as isize) + b) as isize)).b16; if !(qw.s3 > 0) { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } if c != 0 { if c < bc || c > ec { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } qw = (*font_info.offset((*char_base.offset(f as isize) + c) as isize)).b16; if !(qw.s3 > 0) { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } if d < bc || d > ec { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } qw = (*font_info.offset((*char_base.offset(f as isize) + d) as isize)).b16; if !(qw.s3 > 0) { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } @@ -16967,7 +16504,7 @@ pub unsafe extern "C" fn read_font_info( if k == 1 { sw = ttstub_input_getc(tfm_file); if sw == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } if sw > 127 { sw = sw - 256 @@ -16984,7 +16521,7 @@ pub unsafe extern "C" fn read_font_info( c = ttstub_input_getc(tfm_file); d = ttstub_input_getc(tfm_file); if a == libc::EOF || b == libc::EOF || c == libc::EOF || d == libc::EOF { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } sw = ((d * z / 256i32 + c * z) / 256i32 + b * z) / beta as i32; if a == 0 { @@ -16996,7 +16533,7 @@ pub unsafe extern "C" fn read_font_info( .b32 .s1 = sw - alpha } else { - return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); } } } @@ -17032,8 +16569,8 @@ pub unsafe extern "C" fn read_font_info( } } - *font_name.offset(f as isize) = nom; - *font_area.offset(f as isize) = aire; + *font_name.offset(f as isize) = name; + *FONT_AREA.offset(f as isize) = area; *font_bc.offset(f as isize) = bc as UTF16_code; *font_ec.offset(f as isize) = ec as UTF16_code; *font_glue.offset(f as isize) = TEX_NULL; @@ -17052,8 +16589,8 @@ pub unsafe extern "C" fn read_font_info( tfm_file: Option, g: i32, u: i32, - nom: i32, - aire: i32, + name: i32, + area: i32, s: i32, name_too_long: bool, ) -> i32 { @@ -17070,7 +16607,7 @@ pub unsafe extern "C" fn read_font_info( if file_name_quote_char as i32 != 0i32 { print_char(file_name_quote_char as i32); } - print_file_name(nom, aire, cur_ext); + print_file_name(name, area, cur_ext); if file_name_quote_char as i32 != 0i32 { print_char(file_name_quote_char as i32); } @@ -17110,7 +16647,7 @@ pub unsafe extern "C" fn read_font_info( return done(tfm_file, g); } // unreachable - // return bad_tfm(tfm_file_owner, g, u, nom, aire, s, name_too_long); + // return bad_tfm(tfm_file_owner, g, u, name, area, s, name_too_long); unsafe fn done(tfm_file: Option, g: i32) -> i32 { let file_opened = tfm_file.is_some(); @@ -17137,13 +16674,13 @@ pub unsafe extern "C" fn read_font_info( // unreachable // return done(tfm_file_owner, g); } + #[no_mangle] pub unsafe extern "C" fn new_character(mut f: internal_font_number, mut c: UTF16_code) -> i32 { let mut p: i32 = 0; let mut ec: u16 = 0; - if *font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(f as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { return new_native_character(f, c as UnicodeScalar); } ec = effective_char(false, f, c) as u16; @@ -23112,9 +22649,8 @@ pub unsafe extern "C" fn make_accent() { .b32 .s1 as f64 / 65536.0f64; - if *font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(f as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { a = (*mem.offset((p + 1i32) as isize)).b32.s1; if a == 0i32 { get_native_char_sidebearings(f, cur_val, &mut lsb, &mut rsb); @@ -23170,9 +22706,8 @@ pub unsafe extern "C" fn make_accent() { .b32 .s1 as f64 / 65536.0f64; - if *font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32 - { + let engine = get_text_layout_engine(f as usize); + if let Some(_eng) = engine.as_ref().map(|x| &**x) { w = (*mem.offset((q + 1i32) as isize)).b32.s1; get_native_char_height_depth(f, cur_val, &mut h, &mut delta); } else { @@ -23194,10 +22729,8 @@ pub unsafe extern "C" fn make_accent() { p = hpack(p, 0i32, 1i32 as small_number); (*mem.offset((p + 4i32) as isize)).b32.s1 = x - h } - if (*font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32) - && a == 0i32 - { + let engine = get_text_layout_engine(f as usize); + if engine.is_some() && a == 0i32 { delta = tex_round((w - lsb + rsb) as f64 / 2.0f64 + h as f64 * t - x as f64 * s) } else { delta = tex_round((w - a) as f64 / 2.0f64 + h as f64 * t - x as f64 * s) @@ -24119,6 +23652,7 @@ pub unsafe extern "C" fn alter_box_dimen() { (*mem.offset((b + c as i32) as isize)).b32.s1 = cur_val }; } + #[no_mangle] pub unsafe extern "C" fn new_font(mut a: small_number) { let mut current_block: u64; @@ -24220,10 +23754,8 @@ pub unsafe extern "C" fn new_font(mut a: small_number) { } _ => { if str_eq_str(*font_name.offset(f as isize), cur_name) as i32 != 0 - && (length(cur_area) == 0i32 - && (*font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32) - || str_eq_str(*font_area.offset(f as isize), cur_area) as i32 != 0) + && (length(cur_area) == 0i32 && get_text_layout_engine(f as usize).is_some() + || str_eq_str(*FONT_AREA.offset(f as isize), cur_area) as i32 != 0) { if s > 0i32 { if s == *font_size.offset(f as isize) { @@ -24241,9 +23773,7 @@ pub unsafe extern "C" fn new_font(mut a: small_number) { if str_eq_str(*font_name.offset(f as isize), make_string()) { str_ptr -= 1; pool_ptr = *str_start.offset((str_ptr - 65536i32) as isize); - if *font_area.offset(f as isize) as u32 == 0xffffu32 - || *font_area.offset(f as isize) as u32 == 0xfffeu32 - { + if get_text_layout_engine(f as usize).is_some() { if s > 0i32 { if s == *font_size.offset(f as isize) { break; @@ -24281,6 +23811,7 @@ pub unsafe extern "C" fn new_font(mut a: small_number) { )) .s1 = t; } + #[no_mangle] pub unsafe extern "C" fn new_interaction() { print_ln(); @@ -24779,58 +24310,32 @@ pub unsafe extern "C" fn do_extension() { } } 43 => { + let font_num = (*eqtb.offset( + (1i32 + + (0x10ffffi32 + 1i32) + + (0x10ffffi32 + 1i32) + + 1i32 + + 15000i32 + + 12i32 + + 9000i32 + + 1i32 + + 1i32 + + 19i32 + + 256i32 + + 256i32 + + 13i32 + + 256i32 + + 4i32 + + 256i32) as isize, + )) + .b32 + .s1; if (cur_list.mode as i32).abs() == 1i32 { back_input(); new_graf(1i32 != 0); } else if (cur_list.mode as i32).abs() == 207i32 { report_illegal_case(); - } else if *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xffffu32 - || *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - { + } else if get_text_layout_engine(font_num as usize).is_some() { new_whatsit(42i32 as small_number, 5i32 as small_number); scan_int(); if cur_val < 0i32 || cur_val as i64 > 65535 { @@ -24847,7 +24352,9 @@ pub unsafe extern "C" fn do_extension() { int_error(cur_val); cur_val = 0i32 } - (*mem.offset((cur_list.tail + 4i32) as isize)).b16.s2 = (*eqtb.offset( + (*mem.offset((cur_list.tail + 4i32) as isize)).b16.s2 = current_font_num() as u16; + (*mem.offset((cur_list.tail + 4i32) as isize)).b16.s1 = cur_val as u16; + let use_glyph_metrics = ((*eqtb.offset( (1i32 + (0x10ffffi32 + 1i32) + (0x10ffffi32 + 1i32) @@ -24863,69 +24370,26 @@ pub unsafe extern "C" fn do_extension() { + 13i32 + 256i32 + 4i32 - + 256i32) as isize, + + 256i32 + + 1i32 + + 3i32 * 256i32 + + (0x10ffffi32 + 1i32) + + (0x10ffffi32 + 1i32) + + (0x10ffffi32 + 1i32) + + (0x10ffffi32 + 1i32) + + (0x10ffffi32 + 1i32) + + (0x10ffffi32 + 1i32) + + 74i32) as isize, )) .b32 - .s1 as u16; - (*mem.offset((cur_list.tail + 4i32) as isize)).b16.s1 = cur_val as u16; + .s1 > 0i32) as i32; measure_native_glyph( &mut *mem.offset(cur_list.tail as isize) as *mut memory_word as *mut libc::c_void, - ((*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32 - + 1i32 - + 3i32 * 256i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 74i32) as isize, - )) - .b32 - .s1 > 0i32) as i32, + use_glyph_metrics, ); } else { - not_native_font_error( - 59i32, - 43i32, - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) as isize, - )) - .b32 - .s1, - ); + not_native_font_error(59i32, 43i32, font_num); } } 44 => { @@ -26371,53 +25835,29 @@ pub unsafe extern "C" fn main_control() { } } prev_class = 4096i32 - 1i32; - if *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xffffu32 - || *font_area.offset( - (*eqtb.offset( - (1i32 - + (0x10ffffi32 + 1i32) - + (0x10ffffi32 + 1i32) - + 1i32 - + 15000i32 - + 12i32 - + 9000i32 - + 1i32 - + 1i32 - + 19i32 - + 256i32 - + 256i32 - + 13i32 - + 256i32 - + 4i32 - + 256i32) as isize, - )) - .b32 - .s1 as isize, - ) as u32 - == 0xfffeu32 - { + let font_num = (*eqtb.offset( + (1i32 + + (0x10ffffi32 + 1i32) + + (0x10ffffi32 + 1i32) + + 1i32 + + 15000i32 + + 12i32 + + 9000i32 + + 1i32 + + 1i32 + + 19i32 + + 256i32 + + 256i32 + + 13i32 + + 256i32 + + 4i32 + + 256i32) as isize, + )) + .b32 + .s1; + let engine = get_text_layout_engine(font_num as usize); + if let Some(_) = engine { + drop(engine); if cur_list.mode as i32 > 0i32 { if (*eqtb.offset( (1i32 diff --git a/src/engines/mod.rs b/src/engines/mod.rs index d9ea97c20..89496a71a 100644 --- a/src/engines/mod.rs +++ b/src/engines/mod.rs @@ -421,7 +421,12 @@ impl<'a, I: 'a + IoProvider> ExecutionState<'a, I> { rhandle.try_seek(pos) } - fn input_read(&mut self, handle: *mut InputHandle, buf: &mut [u8]) -> Result<()> { + fn input_read(&mut self, handle: *mut InputHandle, buf: &mut [u8]) -> Result { + let rhandle: &mut InputHandle = unsafe { &mut *handle }; + rhandle.read(buf).map_err(Error::from) + } + + fn input_read_exact(&mut self, handle: *mut InputHandle, buf: &mut [u8]) -> Result<()> { let rhandle: &mut InputHandle = unsafe { &mut *handle }; rhandle.read_exact(buf).map_err(Error::from) } @@ -506,7 +511,7 @@ use tectonic_engine::{ // Entry points for the C/C++ API functions. -extern "C" fn issue_warning<'a, I: 'a + IoProvider>( +fn issue_warning<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, text: *const libc::c_char, ) { @@ -516,7 +521,7 @@ extern "C" fn issue_warning<'a, I: 'a + IoProvider>( tt_warning!(es.status, "{}", rtext.to_string_lossy()); } -extern "C" fn issue_error<'a, I: 'a + IoProvider>( +fn issue_error<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, text: *const libc::c_char, ) { @@ -526,7 +531,7 @@ extern "C" fn issue_error<'a, I: 'a + IoProvider>( tt_error!(es.status, "{}", rtext.to_string_lossy()); } -extern "C" fn get_file_md5<'a, I: 'a + IoProvider>( +fn get_file_md5<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, path: *const libc::c_char, digest: *mut u8, @@ -542,7 +547,7 @@ extern "C" fn get_file_md5<'a, I: 'a + IoProvider>( } } -extern "C" fn get_data_md5<'a, I: 'a + IoProvider>( +fn get_data_md5<'a, I: 'a + IoProvider>( _es: *mut ExecutionState<'a, I>, data: *const u8, len: libc::size_t, @@ -560,7 +565,7 @@ extern "C" fn get_data_md5<'a, I: 'a + IoProvider>( 0 } -extern "C" fn output_open<'a, I: 'a + IoProvider>( +fn output_open<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, name: *const libc::c_char, is_gz: libc::c_int, @@ -572,7 +577,7 @@ extern "C" fn output_open<'a, I: 'a + IoProvider>( es.output_open(&rname, ris_gz) as *const _ } -extern "C" fn output_open_stdout<'a, I: 'a + IoProvider>( +fn output_open_stdout<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, ) -> *const libc::c_void { let es = unsafe { &mut *es }; @@ -580,7 +585,7 @@ extern "C" fn output_open_stdout<'a, I: 'a + IoProvider>( es.output_open_stdout() as *const _ } -extern "C" fn output_putc<'a, I: 'a + IoProvider>( +fn output_putc<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, c: libc::c_int, @@ -596,7 +601,7 @@ extern "C" fn output_putc<'a, I: 'a + IoProvider>( } } -extern "C" fn output_write<'a, I: 'a + IoProvider>( +fn output_write<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, data: *const u8, @@ -615,7 +620,7 @@ extern "C" fn output_write<'a, I: 'a + IoProvider>( } } -extern "C" fn output_flush<'a, I: 'a + IoProvider>( +fn output_flush<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, ) -> libc::c_int { @@ -629,7 +634,7 @@ extern "C" fn output_flush<'a, I: 'a + IoProvider>( } } -extern "C" fn output_close<'a, I: 'a + IoProvider>( +fn output_close<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, ) -> libc::c_int { @@ -648,7 +653,7 @@ extern "C" fn output_close<'a, I: 'a + IoProvider>( } } -extern "C" fn input_open<'a, I: 'a + IoProvider>( +fn input_open<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, name: *const libc::c_char, format: libc::c_int, @@ -665,7 +670,7 @@ extern "C" fn input_open<'a, I: 'a + IoProvider>( } } -extern "C" fn input_open_primary<'a, I: 'a + IoProvider>( +fn input_open_primary<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, ) -> *const libc::c_void { let es = unsafe { &mut *es }; @@ -673,7 +678,7 @@ extern "C" fn input_open_primary<'a, I: 'a + IoProvider>( es.input_open_primary() as *const _ } -extern "C" fn input_get_size<'a, I: 'a + IoProvider>( +fn input_get_size<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, ) -> libc::size_t { @@ -683,7 +688,7 @@ extern "C" fn input_get_size<'a, I: 'a + IoProvider>( es.input_get_size(rhandle) } -extern "C" fn input_seek<'a, I: 'a + IoProvider>( +fn input_seek<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, offset: libc::ssize_t, @@ -720,7 +725,7 @@ extern "C" fn input_seek<'a, I: 'a + IoProvider>( } } -extern "C" fn input_getc<'a, I: 'a + IoProvider>( +fn input_getc<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, ) -> libc::c_int { @@ -742,7 +747,7 @@ extern "C" fn input_getc<'a, I: 'a + IoProvider>( } } -extern "C" fn input_ungetc<'a, I: 'a + IoProvider>( +fn input_ungetc<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, ch: libc::c_int, @@ -759,7 +764,7 @@ extern "C" fn input_ungetc<'a, I: 'a + IoProvider>( } } -extern "C" fn input_read<'a, I: 'a + IoProvider>( +fn input_read<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, data: *mut u8, @@ -770,6 +775,25 @@ extern "C" fn input_read<'a, I: 'a + IoProvider>( let rdata = unsafe { slice::from_raw_parts_mut(data, len) }; match es.input_read(rhandle, rdata) { + Ok(len_read) => len_read as isize, + Err(e) => { + tt_warning!(es.status, "read failed"; e); + -1 + } + } +} + +fn input_read_exact<'a, I: 'a + IoProvider>( + es: *mut ExecutionState<'a, I>, + handle: *mut libc::c_void, + data: *mut u8, + len: libc::size_t, +) -> libc::ssize_t { + let es = unsafe { &mut *es }; + let rhandle = handle as *mut InputHandle; + let rdata = unsafe { slice::from_raw_parts_mut(data, len) }; + + match es.input_read_exact(rhandle, rdata) { Ok(_) => len as isize, Err(e) => { tt_warning!(es.status, "{}-byte read failed", len; e); @@ -778,7 +802,7 @@ extern "C" fn input_read<'a, I: 'a + IoProvider>( } } -extern "C" fn input_close<'a, I: 'a + IoProvider>( +fn input_close<'a, I: 'a + IoProvider>( es: *mut ExecutionState<'a, I>, handle: *mut libc::c_void, ) -> libc::c_int { @@ -823,6 +847,7 @@ impl TectonicBridgeApi { input_get_size: transmute(input_get_size::<'a, I> as *const libc::c_void), input_seek: transmute(input_seek::<'a, I> as *const libc::c_void), input_read: transmute(input_read::<'a, I> as *const libc::c_void), + input_read_exact: transmute(input_read_exact::<'a, I> as *const libc::c_void), input_getc: transmute(input_getc::<'a, I> as *const libc::c_void), input_ungetc: transmute(input_ungetc::<'a, I> as *const libc::c_void), input_close: transmute(input_close::<'a, I> as *const libc::c_void),