Skip to content
Snippets Groups Projects
Commit 6b37be51 authored by StarArawn's avatar StarArawn
Browse files

Split more stuff into kayak_font crate.

parent 0aac503c
No related branches found
No related tags found
No related merge requests found
Showing
with 1667 additions and 829 deletions
...@@ -120,15 +120,6 @@ dependencies = [ ...@@ -120,15 +120,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "arrayvec"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9"
dependencies = [
"nodrop",
]
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.7.2" version = "0.7.2"
...@@ -302,8 +293,8 @@ source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec0367359 ...@@ -302,8 +293,8 @@ source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec0367359
dependencies = [ dependencies = [
"Inflector", "Inflector",
"bevy_macro_utils", "bevy_macro_utils",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -341,9 +332,9 @@ version = "0.5.0" ...@@ -341,9 +332,9 @@ version = "0.5.0"
source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c#38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c" source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c#38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c"
dependencies = [ dependencies = [
"bevy_macro_utils", "bevy_macro_utils",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -440,6 +431,7 @@ dependencies = [ ...@@ -440,6 +431,7 @@ dependencies = [
"crevice", "crevice",
"kayak_components", "kayak_components",
"kayak_core", "kayak_core",
"kayak_font",
"kayak_render_macros", "kayak_render_macros",
"serde", "serde",
"serde_json", "serde_json",
...@@ -466,8 +458,8 @@ version = "0.5.0" ...@@ -466,8 +458,8 @@ version = "0.5.0"
source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c#38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c" source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c#38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c"
dependencies = [ dependencies = [
"cargo-manifest", "cargo-manifest",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -538,9 +530,9 @@ version = "0.5.0" ...@@ -538,9 +530,9 @@ version = "0.5.0"
source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c#38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c" source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c#38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c"
dependencies = [ dependencies = [
"bevy_macro_utils", "bevy_macro_utils",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
"uuid", "uuid",
] ]
...@@ -820,8 +812,8 @@ dependencies = [ ...@@ -820,8 +812,8 @@ dependencies = [
"lazy_static", "lazy_static",
"lazycell", "lazycell",
"peeking_take_while", "peeking_take_while",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"regex", "regex",
"rustc-hash", "rustc-hash",
"shlex", "shlex",
...@@ -875,9 +867,9 @@ version = "1.0.1" ...@@ -875,9 +867,9 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54" checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -1221,9 +1213,9 @@ name = "crevice-derive" ...@@ -1221,9 +1213,9 @@ name = "crevice-derive"
version = "0.8.0" version = "0.8.0"
source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c#38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c" source = "git+https://github.com/bevyengine/bevy?rev=38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c#38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -1323,10 +1315,10 @@ checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" ...@@ -1323,10 +1315,10 @@ checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b"
dependencies = [ dependencies = [
"fnv", "fnv",
"ident_case", "ident_case",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"strsim", "strsim",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -1336,8 +1328,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -1336,8 +1328,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -1356,9 +1348,9 @@ version = "2.2.0" ...@@ -1356,9 +1348,9 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -1377,9 +1369,9 @@ version = "0.1.2" ...@@ -1377,9 +1369,9 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f9c37d395456d9c1785499421c6288931b6e3dbc2500acb95b8adaa0e69db3" checksum = "56f9c37d395456d9c1785499421c6288931b6e3dbc2500acb95b8adaa0e69db3"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -1425,16 +1417,6 @@ dependencies = [ ...@@ -1425,16 +1417,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "euclid"
version = "0.19.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "596b99621b9477e7a5f94d2d8dd13a9c5c302ac358b822c67a42b6f1054450e1"
dependencies = [
"euclid_macros",
"num-traits",
]
[[package]] [[package]]
name = "euclid" name = "euclid"
version = "0.22.6" version = "0.22.6"
...@@ -1444,17 +1426,6 @@ dependencies = [ ...@@ -1444,17 +1426,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "euclid_macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdcb84c18ea5037a1c5a23039b4ff29403abce2e0d6b1daa11cf0bde2b30be15"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"syn 0.15.44",
]
[[package]] [[package]]
name = "event-listener" name = "event-listener"
version = "2.5.1" version = "2.5.1"
...@@ -1656,9 +1627,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -1656,9 +1627,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f2a9333e0f9c7bca94dfc20bcf44fa12a61eeec662d6e007563ff748aa59c70" checksum = "1f2a9333e0f9c7bca94dfc20bcf44fa12a61eeec662d6e007563ff748aa59c70"
dependencies = [ dependencies = [
"inflections", "inflections",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -1729,7 +1700,7 @@ version = "0.6.2" ...@@ -1729,7 +1700,7 @@ version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62d5865c036cb1393e23c50693df631d3f5d7bcca4c04fe4cc0fd592e74a782" checksum = "b62d5865c036cb1393e23c50693df631d3f5d7bcca4c04fe4cc0fd592e74a782"
dependencies = [ dependencies = [
"euclid 0.22.6", "euclid",
"svg_fmt", "svg_fmt",
] ]
...@@ -1927,13 +1898,10 @@ dependencies = [ ...@@ -1927,13 +1898,10 @@ dependencies = [
name = "kayak_font" name = "kayak_font"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "bevy",
"bitflags", "serde",
"fontdue", "serde_json",
"lyon_geom", "serde_path_to_error",
"lyon_path",
"png",
"ttf-parser 0.13.3",
] ]
[[package]] [[package]]
...@@ -1943,9 +1911,9 @@ dependencies = [ ...@@ -1943,9 +1911,9 @@ dependencies = [
"kayak_core", "kayak_core",
"pretty_assertions", "pretty_assertions",
"proc-macro-error", "proc-macro-error",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -2050,26 +2018,6 @@ dependencies = [ ...@@ -2050,26 +2018,6 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
[[package]]
name = "lyon_geom"
version = "0.12.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdb9bf1f1d43be9a9cc2343a7a096dc113cc25337a13e8f99721b01d1d548b60"
dependencies = [
"arrayvec 0.4.12",
"euclid 0.19.9",
"num-traits",
]
[[package]]
name = "lyon_path"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9dc8e0746b7cca11960b602f7fe037bb067746a01eab4aa502fed1494544843"
dependencies = [
"lyon_geom",
]
[[package]] [[package]]
name = "mach" name = "mach"
version = "0.2.3" version = "0.2.3"
...@@ -2295,9 +2243,9 @@ checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d" ...@@ -2295,9 +2243,9 @@ checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro-crate 0.1.5", "proc-macro-crate 0.1.5",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -2318,12 +2266,6 @@ dependencies = [ ...@@ -2318,12 +2266,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "nodrop"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]] [[package]]
name = "nom" name = "nom"
version = "5.1.2" version = "5.1.2"
...@@ -2367,9 +2309,9 @@ version = "0.3.3" ...@@ -2367,9 +2309,9 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -2440,9 +2382,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -2440,9 +2382,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9" checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9"
dependencies = [ dependencies = [
"proc-macro-crate 1.1.0", "proc-macro-crate 1.1.0",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -2585,7 +2527,7 @@ version = "0.2.1" ...@@ -2585,7 +2527,7 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb458bb7f6e250e6eb79d5026badc10a3ebb8f9a15d1fff0f13d17c71f4d6dee" checksum = "bb458bb7f6e250e6eb79d5026badc10a3ebb8f9a15d1fff0f13d17c71f4d6dee"
dependencies = [ dependencies = [
"unicode-xid 0.2.2", "unicode-xid",
] ]
[[package]] [[package]]
...@@ -2630,9 +2572,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -2630,9 +2572,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [ dependencies = [
"proc-macro-error-attr", "proc-macro-error-attr",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
"version_check", "version_check",
] ]
...@@ -2642,27 +2584,18 @@ version = "1.0.4" ...@@ -2642,27 +2584,18 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"version_check", "version_check",
] ]
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.32" version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
dependencies = [ dependencies = [
"unicode-xid 0.2.2", "unicode-xid",
] ]
[[package]] [[package]]
...@@ -2671,22 +2604,13 @@ version = "1.0.4" ...@@ -2671,22 +2604,13 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9926767b8b8244d7b6b64546585121d193c3d0b4856ccd656b7bfa9deb91ab6a" checksum = "9926767b8b8244d7b6b64546585121d193c3d0b4856ccd656b7bfa9deb91ab6a"
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.10" version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
] ]
[[package]] [[package]]
...@@ -2906,9 +2830,9 @@ version = "1.0.130" ...@@ -2906,9 +2830,9 @@ version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -3069,11 +2993,11 @@ version = "0.5.3" ...@@ -3069,11 +2993,11 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"serde", "serde",
"serde_derive", "serde_derive",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -3083,13 +3007,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -3083,13 +3007,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [ dependencies = [
"base-x", "base-x",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"sha1", "sha1",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -3120,26 +3044,15 @@ version = "0.4.1" ...@@ -3120,26 +3044,15 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2" checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2"
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid 0.1.0",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.81" version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"unicode-xid 0.2.2", "unicode-xid",
] ]
[[package]] [[package]]
...@@ -3166,9 +3079,9 @@ version = "1.0.30" ...@@ -3166,9 +3079,9 @@ version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -3208,9 +3121,9 @@ version = "0.1.18" ...@@ -3208,9 +3121,9 @@ version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
] ]
[[package]] [[package]]
...@@ -3280,12 +3193,6 @@ version = "0.1.9" ...@@ -3280,12 +3193,6 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.2" version = "0.2.2"
...@@ -3356,9 +3263,9 @@ dependencies = [ ...@@ -3356,9 +3263,9 @@ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
"log", "log",
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
...@@ -3380,7 +3287,7 @@ version = "0.2.78" ...@@ -3380,7 +3287,7 @@ version = "0.2.78"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9"
dependencies = [ dependencies = [
"quote 1.0.10", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
] ]
...@@ -3390,9 +3297,9 @@ version = "0.2.78" ...@@ -3390,9 +3297,9 @@ version = "0.2.78"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab"
dependencies = [ dependencies = [
"proc-macro2 1.0.32", "proc-macro2",
"quote 1.0.10", "quote",
"syn 1.0.81", "syn",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
...@@ -3419,7 +3326,7 @@ version = "0.11.0" ...@@ -3419,7 +3326,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1577ecc4f6992b9e965878ac594efb24eed2bdf089c11f45b3d1c5f216e2e30" checksum = "d1577ecc4f6992b9e965878ac594efb24eed2bdf089c11f45b3d1c5f216e2e30"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "arrayvec",
"js-sys", "js-sys",
"log", "log",
"naga", "naga",
...@@ -3440,7 +3347,7 @@ version = "0.11.2" ...@@ -3440,7 +3347,7 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bdcbfa4885b32c2b1feb2faeb8b6a76065b752b8f08751b82f994e937687f46" checksum = "3bdcbfa4885b32c2b1feb2faeb8b6a76065b752b8f08751b82f994e937687f46"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "arrayvec",
"bitflags", "bitflags",
"cfg_aliases", "cfg_aliases",
"copyless", "copyless",
...@@ -3462,7 +3369,7 @@ version = "0.11.4" ...@@ -3462,7 +3369,7 @@ version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e493835d9edb153d5c8a9d8d016e1811dbe32ddb707a110be1453c7b051d3ec" checksum = "0e493835d9edb153d5c8a9d8d016e1811dbe32ddb707a110be1453c7b051d3ec"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "arrayvec",
"ash", "ash",
"bit-set", "bit-set",
"bitflags", "bitflags",
......
...@@ -9,6 +9,7 @@ bevy = { git = "https://github.com/bevyengine/bevy", rev = "38c7d5eb9e81ab8e1aec ...@@ -9,6 +9,7 @@ bevy = { git = "https://github.com/bevyengine/bevy", rev = "38c7d5eb9e81ab8e1aec
kayak_core = { path = "../kayak_core" } kayak_core = { path = "../kayak_core" }
kayak_components = { path = "../kayak_components" } kayak_components = { path = "../kayak_components" }
kayak_render_macros = { path = "../kayak_render_macros" } kayak_render_macros = { path = "../kayak_render_macros" }
kayak_font = { path = "../kayak_font" }
#kayak_font = { path = "../kayak_font" } #kayak_font = { path = "../kayak_font" }
crevice = { git = "https://github.com/bevyengine/bevy", rev = "38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c" } crevice = { git = "https://github.com/bevyengine/bevy", rev = "38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c" }
serde = "1.0" serde = "1.0"
......
...@@ -4,13 +4,14 @@ use bevy::{ ...@@ -4,13 +4,14 @@ use bevy::{
sprite2::Rect, sprite2::Rect,
}; };
use kayak_core::render_primitive::RenderPrimitive; use kayak_core::render_primitive::RenderPrimitive;
use kayak_font::KayakFont;
use crate::{ use crate::{
render::unified::pipeline::{ExtractQuadBundle, ExtractedQuad, UIQuadType}, render::unified::pipeline::{ExtractQuadBundle, ExtractedQuad, UIQuadType},
to_bevy_color, BevyContext, to_bevy_color, BevyContext,
}; };
use super::{font::KayakFont, font_mapping::FontMapping}; use super::font_mapping::FontMapping;
pub fn extract_texts( pub fn extract_texts(
mut commands: Commands, mut commands: Commands,
......
use std::collections::HashMap;
use super::sdf::Sdf;
use bevy::{prelude::Handle, reflect::TypeUuid, render2::texture::Image};
#[derive(Debug, Clone, TypeUuid)]
#[uuid = "4fe4732c-6731-49bb-bafc-4690d636b848"]
pub struct KayakFont {
pub sdf: Sdf,
pub atlas_image: Handle<Image>,
char_ids: HashMap<char, u32>,
}
impl KayakFont {
pub fn new(sdf: Sdf, atlas_image: Handle<Image>) -> Self {
Self {
sdf,
atlas_image,
char_ids: HashMap::default(),
}
}
pub fn generate_char_ids(&mut self) {
let mut count = 0;
for glyph in self.sdf.glyphs.iter() {
self.char_ids.insert(glyph.unicode, count);
count += 1;
}
}
pub fn get_char_id(&self, c: char) -> Option<u32> {
self.char_ids.get(&c).and_then(|id| Some(*id))
}
}
use bevy::{prelude::Handle, utils::HashMap}; use bevy::{prelude::Handle, utils::HashMap};
use kayak_font::KayakFont;
use super::font::KayakFont;
pub struct FontMapping { pub struct FontMapping {
count: u16, count: u16,
......
...@@ -12,20 +12,14 @@ use bevy::{ ...@@ -12,20 +12,14 @@ use bevy::{
}, },
utils::HashSet, utils::HashSet,
}; };
use kayak_font::{KayakFont, Sdf, FontTextureCache};
use self::{extract::extract_texts, sdf::Sdf};
use super::pipeline::UnifiedPipeline;
mod extract; mod extract;
mod font;
mod font_mapping; mod font_mapping;
mod font_texture_cache;
mod sdf;
pub use font::*; use self::extract::extract_texts;
use super::pipeline::UnifiedPipeline;
pub use font_mapping::*; pub use font_mapping::*;
pub(crate) use font_texture_cache::FontTextureCache;
#[derive(Default)] #[derive(Default)]
pub struct TextRendererPlugin; pub struct TextRendererPlugin;
...@@ -169,5 +163,5 @@ fn create_and_update_font_cache_texture( ...@@ -169,5 +163,5 @@ fn create_and_update_font_cache_texture(
mut font_texture_cache: ResMut<FontTextureCache>, mut font_texture_cache: ResMut<FontTextureCache>,
images: Res<RenderAssets<Image>>, images: Res<RenderAssets<Image>>,
) { ) {
font_texture_cache.process_new(&device, &queue, &pipeline, &images); font_texture_cache.process_new(&device, &queue, pipeline.into_inner(), &images);
} }
use self::{atlas::Atlas, glyph::Glyph, metrics::Metrics};
use bevy::math::Vec2;
use serde::Deserialize;
mod atlas;
mod glyph;
mod metrics;
#[derive(Deserialize, Debug, Clone)]
pub struct Sdf {
pub atlas: Atlas,
metrics: Metrics,
pub glyphs: Vec<Glyph>,
kerning: Vec<KerningData>,
}
#[derive(serde::Deserialize, Debug, Clone, Copy)]
pub struct KerningData {
pub unicode1: u32,
pub unicode2: u32,
pub advance: f32,
}
impl Sdf {
pub fn from_string(data: String) -> Sdf {
let value: Sdf = match serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_str(&data),
) {
Ok(v) => v,
Err(err) => {
let path = err.path().to_string();
dbg!(err);
panic!("failed to deserialize json! path: {}", path);
}
};
value
}
pub fn max_glyph_size(&self) -> Vec2 {
let mut size = Vec2::new(0.0, 0.0);
self.glyphs.iter().for_each(|glyph| {
if let Some(atlas_bounds) = glyph.atlas_bounds {
let atlas_size = atlas_bounds.size();
if atlas_size.x > size.x {
size.x = atlas_size.x;
}
if atlas_size.y > size.y {
size.y = atlas_size.y;
}
}
});
size
}
}
#[test]
fn test_sdf_loader() {
let sdf = Sdf::from_string(include_str!("../../../../../../msdfgen/test.json").to_string());
dbg!(sdf.max_glyph_size());
}
...@@ -31,8 +31,8 @@ use bevy::{ ...@@ -31,8 +31,8 @@ use bevy::{
}; };
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use crevice::std140::AsStd140; use crevice::std140::AsStd140;
use kayak_font::{FontRenderingPipeline, FontTextureCache, KayakFont};
use super::font::{FontTextureCache, KayakFont};
use super::UNIFIED_SHADER_HANDLE; use super::UNIFIED_SHADER_HANDLE;
use crate::render::ui_pass::TransparentUI; use crate::render::ui_pass::TransparentUI;
...@@ -55,6 +55,12 @@ const QUAD_VERTEX_POSITIONS: &[Vec3] = &[ ...@@ -55,6 +55,12 @@ const QUAD_VERTEX_POSITIONS: &[Vec3] = &[
const_vec3!([1.0, 1.0, 0.0]), const_vec3!([1.0, 1.0, 0.0]),
]; ];
impl FontRenderingPipeline for UnifiedPipeline {
fn get_font_image_layout(&self) -> &BindGroupLayout {
&self.font_image_layout
}
}
impl FromWorld for UnifiedPipeline { impl FromWorld for UnifiedPipeline {
fn from_world(world: &mut World) -> Self { fn from_world(world: &mut World) -> Self {
let world = world.cell(); let world = world.cell();
...@@ -586,7 +592,7 @@ impl Draw<TransparentUI> for DrawUI { ...@@ -586,7 +592,7 @@ impl Draw<TransparentUI> for DrawUI {
let unified_pipeline = unified_pipeline.into_inner(); let unified_pipeline = unified_pipeline.into_inner();
if let Some(font_handle) = extracted_quad.font_handle.as_ref() { if let Some(font_handle) = extracted_quad.font_handle.as_ref() {
if let Some(image_bindings) = if let Some(image_bindings) =
font_texture_cache.into_inner().bind_groups.get(font_handle) font_texture_cache.into_inner().get_binding(font_handle)
{ {
pass.set_bind_group(1, image_bindings, &[]); pass.set_bind_group(1, image_bindings, &[]);
} else { } else {
......
...@@ -6,12 +6,7 @@ edition = "2021" ...@@ -6,12 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
arrayvec = "0.7" bevy = { git = "https://github.com/bevyengine/bevy", rev = "38c7d5eb9e81ab8e1aec03673599b25a9aa0c69c" }
bitflags = "1.0" serde = "1.0"
lyon_path = "0.12" serde_json = "1.0"
lyon_geom = "0.12" serde_path_to_error = "0.1"
fontdue = "0.6"
ttf-parser = "0.13"
[dev-dependencies]
png = "0.16.3"
This diff is collapsed.
use std::{fs::File, io::BufWriter};
use kayak_font::{
compute_msdf, recolor_contours, rescale_contours, Angle, FlatPathBuilder, PathCollector, Point,
Rect,
};
pub fn main() {
let font_data = include_bytes!("../resources/Roboto-Regular.ttf");
let face = ttf_parser::Face::from_slice(font_data, 0).unwrap();
let char_dim: u32 = 64;
let c = 'A';
if let Some(glyph) = face.glyph_index(c) {
let mut path_collector = PathCollector::new();
path_collector.scale = 1.0; //0.0001; //1024 as f32 / face.units_per_em() as f32;
let rect = face.outline_glyph(glyph, &mut path_collector).unwrap();
let contours = path_collector.build();
let uv_rect = Rect::new(Point::new(0.0, 0.0), lyon_geom::math::Size::new(1.0, 1.0));
let font_rect = Rect::new(
Point::new(rect.x_min as f32, rect.y_min as f32),
lyon_geom::math::Size::new(rect.width() as f32, rect.height() as f32),
);
let (contours, _) = rescale_contours(contours, font_rect, uv_rect, 0);
let contours = recolor_contours(contours, Angle::degrees(3.0), 1);
let msdf = compute_msdf(&contours, char_dim as usize);
let file = File::create(format!("./test-{}.png", c)).unwrap();
let ref mut w = BufWriter::new(file);
let pixels: Vec<u8> = msdf
.iter()
.flat_map(|y| {
y.iter().flat_map(|pixel| {
vec![
(pixel.0 * 255.0) as u8,
(pixel.1 * 255.0) as u8,
(pixel.2 * 255.0) as u8,
255u8,
]
})
})
.collect();
let mut encoder = png::Encoder::new(w, char_dim, char_dim);
encoder.set_color(png::ColorType::RGBA);
let mut writer = encoder.write_header().unwrap();
writer.write_image_data(&pixels).unwrap();
}
}
use std::{fs::File, io::BufWriter};
use kayak_font::Font;
fn main() {
let font_bytes = include_bytes!("../resources/Roboto-Regular.ttf");
let mut font = Font::new(font_bytes, (64, 64));
font.add_character('A');
font.add_character('B');
font.add_character('C');
font.add_character('!');
font.add_character('&');
// Characters that have already been calculated wont be calculated again!
for _ in 0..1000000 {
font.add_character('A');
}
let dimensions = font.cache.dimensions;
for (c, _, pixels) in font.get_data_to_process() {
let file = File::create(format!("./test-{}.png", c)).unwrap();
let ref mut w = BufWriter::new(file);
let mut encoder = png::Encoder::new(w, dimensions.0, dimensions.1);
encoder.set_color(png::ColorType::RGBA);
let mut writer = encoder.write_header().unwrap();
writer.write_image_data(&pixels).unwrap();
}
}
File deleted
bitflags::bitflags! {
pub struct ColorFlags: u32 {
const BLACK = 0b000;
const RED = 0b001;
const GREEN = 0b010;
const BLUE = 0b100;
const YELLOW = 0b011;
const MAGENTA = 0b101;
const CYAN = 0b110;
const WHITE = 0b111;
}
}
impl ColorFlags {
pub(crate) fn switch(self, seed: &mut u64) -> Self {
match self {
ColorFlags::WHITE | ColorFlags::BLACK => {
const START: [ColorFlags; 3] =
[ColorFlags::CYAN, ColorFlags::MAGENTA, ColorFlags::YELLOW];
let tr = START[(*seed % 3) as usize];
*seed /= 3;
tr
}
ColorFlags::RED | ColorFlags::GREEN | ColorFlags::BLUE => self ^ ColorFlags::WHITE,
_ => {
let v = self.bits();
let v = (v << (1 + (*seed & 1))) & 0b111;
let v = match v.count_ones() {
0 => 0b11, /* Somehow we lost all the bits. Default to yellow */
1 => v | 0b001, /* We just shifted a bit off the left side, add one on the right */
2 => v, /* We already have 2 bits, nothing to do */
_ => unreachable!(), /* There should never be 3+ bits set */
};
*seed >>= 1;
Self::from_bits_truncate(v)
}
}
}
pub(crate) fn switch_banned(self, seed: &mut u64, banned: ColorFlags) -> Self {
let combined = self & banned;
match combined {
ColorFlags::RED | ColorFlags::GREEN | ColorFlags::BLUE => combined ^ ColorFlags::WHITE,
_ => self.switch(seed),
}
}
pub fn float_color(self) -> [f32; 3] {
match self {
ColorFlags::BLACK => [0.0f32, 0.0f32, 0.0f32],
ColorFlags::RED => [1.0f32, 0.0f32, 0.0f32],
ColorFlags::GREEN => [0.0f32, 1.0f32, 0.0f32],
ColorFlags::BLUE => [0.0f32, 0.0f32, 1.0f32],
ColorFlags::CYAN => [0.0f32, 1.0f32, 1.0f32],
ColorFlags::MAGENTA => [1.0f32, 0.0f32, 1.0f32],
ColorFlags::YELLOW => [1.0f32, 1.0f32, 0.0f32],
ColorFlags::WHITE => [1.0f32, 1.0f32, 1.0f32],
_ => [0.5, 0.7, 0.5],
}
}
}
use lyon_geom::math::{Point, Rect};
use lyon_path::Segment;
use crate::path_element::PathElement;
/// A list of path elements forming a closed loop
#[derive(Clone, Debug)]
pub struct Contour {
pub elements: Vec<PathElement>,
}
impl Contour {
pub fn winding(&self) -> f32 {
let shoelace = |a: Point, b: Point| (b.x - a.x) * (a.y + b.y);
let n = self.elements.len();
match n {
0 => 0.0,
1 => {
let a = self.elements[0].sample(0.0);
let b = self.elements[0].sample(1.0 / 3.0);
let c = self.elements[0].sample(2.0 / 3.0);
shoelace(a, b) + shoelace(b, c) + shoelace(c, a)
}
2 => {
let a = self.elements[0].sample(0.0);
let b = self.elements[0].sample(0.5);
let c = self.elements[1].sample(0.0);
let d = self.elements[1].sample(0.5);
shoelace(a, b) + shoelace(b, c) + shoelace(c, d) + shoelace(d, a)
}
_ => {
let mut total = 0.0;
let mut prev = self.elements[n - 1].sample(0.0);
for e in &self.elements {
let curr = e.sample(0.0);
total += shoelace(prev, curr);
prev = curr;
}
total
}
}
.signum()
}
}
/// Rescale contours so they fit in the provided rectangle.
/// Returns the scaled contours along with the transformation used to rescale the contours
pub fn rescale_contours(
mut contours: Vec<Contour>,
initial_bounds: Rect,
bounds: Rect,
_units_per_em: u16,
) -> (Vec<Contour>, lyon_geom::math::Transform2D) {
// let (new_width, new_height) = if initial_bounds.size.width > initial_bounds.size.height {
// let new_width = 1.0;
// let new_height = aspect_ratio_height(
// initial_bounds.size.height,
// initial_bounds.size.width,
// new_width,
// );
// (new_width, new_height)
// } else {
// let new_height = 1.0;
// let new_width = aspect_ratio_width(
// initial_bounds.size.height,
// initial_bounds.size.width,
// new_height,
// );
// (new_width, new_height)
// };
// let x_scale = new_width / initial_bounds.size.width;
// let y_scale = new_height / initial_bounds.size.height;
let initial_scale = initial_bounds.size.height.max(initial_bounds.size.width);
let bounds_scale = bounds.size.width.max(bounds.size.height);
// let size = 128.0 / units_per_em as f32;
let transformation = lyon_geom::math::Transform2D::create_translation(
-initial_bounds.origin.x as f32,
-initial_bounds.origin.y as f32,
)
.post_scale(bounds_scale / initial_scale, bounds_scale / initial_scale)
.post_translate(bounds.origin.to_vector());
for contour in &mut contours {
for mut elem in &mut contour.elements {
elem.segment = match elem.segment {
Segment::Line(s) => Segment::Line(s.transform(&transformation)),
Segment::Quadratic(s) => Segment::Quadratic(s.transform(&transformation)),
Segment::Cubic(s) => Segment::Cubic(s.transform(&transformation)),
Segment::Arc(s) => Segment::Arc(lyon_geom::Arc {
center: transformation.transform_point(&s.center),
..s
}),
}
}
}
(contours, transformation)
}
use std::collections::{HashMap, HashSet}; use std::collections::HashMap;
use lyon_geom::math::{Angle, Point, Rect, Size};
use lyon_path::builder::FlatPathBuilder;
use crate::{compute_msdf, recolor_contours, rescale_contours, PathCollector}; use bevy::{prelude::Handle, reflect::TypeUuid, render2::texture::Image};
#[derive(Debug, Clone)] use crate::Sdf;
pub struct FontCache {
count: usize,
pub dimensions: (u32, u32),
chars: HashMap<char, (usize, Vec<u8>)>,
needs_processing: HashSet<usize>,
id_to_char_mappings: HashMap<usize, char>,
}
impl FontCache {
pub fn new(texture_size: (u32, u32)) -> Self {
Self {
count: 0,
dimensions: texture_size,
chars: HashMap::default(),
needs_processing: HashSet::default(),
id_to_char_mappings: HashMap::default(),
}
}
pub fn add_character(&mut self, c: char) {
self.chars.insert(c, (self.count, vec![]));
self.id_to_char_mappings.insert(self.count, c);
self.count += 1;
}
fn set_texture(&mut self, c: char, texture_data: Vec<Vec<(f32, f32, f32)>>) {
// let pixels: Vec<u8> = texture_data
// .iter()
// .flat_map(|y| {
// y.iter().flat_map(|pixel| {
// vec![
// (pixel.0 * 255.0) as u8,
// (pixel.1 * 255.0) as u8,
// (pixel.2 * 255.0) as u8,
// 255u8,
// ]
// })
// })
// .collect();
let pixels = texture_data
.iter()
.flat_map(|x| {
x.iter()
.flat_map(|p| {
vec![
p.0.to_le_bytes(),
p.1.to_le_bytes(),
p.2.to_le_bytes(),
1.0f32.to_le_bytes(),
]
.into_iter()
.flatten()
.collect::<Vec<u8>>()
})
.collect::<Vec<u8>>()
})
.collect();
self.chars.insert(c, (self.count, pixels));
self.needs_processing.insert(self.count);
self.id_to_char_mappings.insert(self.count, c);
self.count += 1;
}
pub fn has_character(&self, c: char) -> bool { #[derive(Debug, Clone, TypeUuid)]
self.chars.contains_key(&c) #[uuid = "4fe4732c-6731-49bb-bafc-4690d636b848"]
} pub struct KayakFont {
pub sdf: Sdf,
fn get_dimensions(&self) -> (u32, u32) { pub atlas_image: Handle<Image>,
self.dimensions char_ids: HashMap<char, u32>,
}
} }
#[derive(Debug, Clone)] impl KayakFont {
pub struct Font { pub fn new(sdf: Sdf, atlas_image: Handle<Image>) -> Self {
internal_face: ttf_parser::Face<'static>, Self {
font: fontdue::Font, sdf,
pub cache: FontCache, atlas_image,
} char_ids: HashMap::default(),
impl Font {
pub fn new(font_data: &'static [u8], texture_size: (u32, u32)) -> Font {
Font {
internal_face: ttf_parser::Face::from_slice(&font_data, 0).unwrap(),
font: fontdue::Font::from_bytes(font_data.clone(), fontdue::FontSettings::default())
.unwrap(),
cache: FontCache::new(texture_size),
}
}
/// Adds all of the common known characters.
pub fn add_all_common(&mut self) {
let chars = vec![
'`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '~', '!', '@', '#',
'$', '%', '^', '&', '*', '(', ')', '_', '+', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', '\\', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',
'|', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', 'A', 'S', 'D', 'F', 'G',
'H', 'J', 'K', 'L', ':', '"', 'z', 'x', 'c', 'v', 'b', 'n', 'n', 'm', ',', '.', '/',
'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
];
for char in chars {
self.add_character(char);
}
}
pub fn get_layout(
&self,
content: &String,
font_size: f32,
original_font_size: f32,
max_glyph_size: (f32, f32),
) -> Vec<(char, (f32, f32), (f32, f32))> {
let mut layout =
fontdue::layout::Layout::new(fontdue::layout::CoordinateSystem::PositiveYDown);
layout.append(
&[&self.font],
&fontdue::layout::TextStyle::new(content, font_size, 0),
);
let font_ratio = font_size / original_font_size;
let resized_max_glyph_size = (
(max_glyph_size.0 * font_ratio).round(),
(max_glyph_size.1 * font_ratio).round(),
);
let glyphs = layout.glyphs();
let glyphs: Vec<_> = glyphs
.iter()
.filter_map(|glyph_position| {
if glyph_position.parent == ' ' {
return None;
}
// let metrics = self.font.metrics(glyph_position.parent, font_size);
let shift_y = resized_max_glyph_size.1 - glyph_position.height as f32;
Some((
glyph_position.parent,
(glyph_position.x, glyph_position.y - shift_y),
resized_max_glyph_size,
))
})
.collect();
glyphs
}
// pub fn get_size(&self, c: char, font_size: f32) -> (f32, f32) {
// if let Some(glyph) = self.internal_face.glyph_index(c) {
// // Collect our path's from the glyph's outline shape.
// let mut path_collector = PathCollector::new();
// let rect = self
// .internal_face
// .outline_glyph(glyph, &mut path_collector)
// .unwrap();
// let metrics = font_size / self.font.units_per_em();
// (width as f32 * metrics, height as f32 * metrics)
// } else {
// panic!("")
// }
// }
pub fn get_char_id(&self, c: char) -> usize {
if self.cache.has_character(c) {
if let Some((id, _)) = self.cache.chars.get(&c) {
return *id;
}
} }
panic!("No char found!");
} }
pub fn add_character(&mut self, c: char) { pub fn generate_char_ids(&mut self) {
if !self.cache.has_character(c) { let mut count = 0;
if let Some(glyph) = self.internal_face.glyph_index(c) { for glyph in self.sdf.glyphs.iter() {
// Collect our path's from the glyph's outline shape. self.char_ids.insert(glyph.unicode, count);
let mut path_collector = PathCollector::new(); count += 1;
let rect = self
.internal_face
.outline_glyph(glyph, &mut path_collector)
.unwrap();
let contours = path_collector.build();
// Bounds of our texture in UV's
// TODO: Allow this to change because some people may want texture atlases instead.
let uv_rect = Rect::new(Point::new(0.0, 0.0), Size::new(1.0, 1.0));
// Bounds of our rect in font space coords.
let font_rect = Rect::new(
Point::new(rect.x_min as f32, rect.y_min as f32),
Size::new(rect.width() as f32, rect.height() as f32),
);
let (contours, _transform) = rescale_contours(
contours,
font_rect,
uv_rect,
self.internal_face.units_per_em(),
);
let contours = recolor_contours(contours, Angle::degrees(3.0), 1);
let msdf = compute_msdf(&contours, self.cache.get_dimensions().0 as usize);
self.cache.set_texture(c, msdf);
}
} }
} }
pub fn get_data_to_process<'b>(&'b mut self) -> Vec<(char, usize, &'b Vec<u8>)> { pub fn get_char_id(&self, c: char) -> Option<u32> {
let data = self self.char_ids.get(&c).and_then(|id| Some(*id))
.cache
.needs_processing
.iter()
.filter_map(|unprocessed_id| {
if let Some(c) = self.cache.id_to_char_mappings.get(unprocessed_id) {
if let Some((_, data)) = self.cache.chars.get(c) {
return Some((*c, *unprocessed_id, data));
}
}
None
})
.collect();
self.cache.needs_processing.clear();
data
} }
// Checks the given chars and returns ones that haven't been seen before.
pub fn check_chars(&self, chars: std::str::Chars<'_>) -> Vec<char> {
chars
.into_iter()
.filter(|c| !self.cache.chars.contains_key(&c))
.collect()
}
pub fn units_per_em(&self) -> f32 {
self.font.units_per_em()
}
}
fn get_new_size(org_width: f32, new_width: f32, org_height: f32, new_height: f32) -> (f32, f32) {
let ratio = calculate_ratio(org_width, new_width, org_height, new_height);
// let ratio = new_width / new_height;
(org_width * ratio, org_height * ratio)
}
pub fn calculate_ratio(org_width: f32, new_width: f32, org_height: f32, new_height: f32) -> f32 {
let area_size;
let image_size;
if new_height * org_width > new_width * org_height {
area_size = new_height;
image_size = org_height;
} else {
area_size = new_width;
image_size = org_width;
}
let ratio = area_size / image_size;
ratio
} }
#![allow(dead_code)] mod atlas;
mod color_flags;
mod contour;
mod font; mod font;
mod msdf; mod glyph;
mod path_collector; mod metrics;
mod path_element; mod renderer;
mod recolor;
mod sdf; mod sdf;
mod ttf_parser;
mod utils;
pub use color_flags::ColorFlags; pub use atlas::*;
pub use contour::{rescale_contours, Contour}; pub use font::*;
pub use font::{Font, FontCache}; pub use glyph::*;
pub use lyon_geom::math::{Angle, Point, Rect, Vector}; pub use metrics::*;
pub use lyon_path::builder::FlatPathBuilder; pub use sdf::*;
pub use msdf::compute_msdf;
pub use path_collector::PathCollector;
pub use path_element::PathElement;
pub use recolor::recolor_contours;
pub use sdf::compute_sdf;
pub(crate) fn median(a: f32, b: f32, c: f32) -> f32 { pub use renderer::*;
let min = |a: f32, b: f32| a.min(b);
let max = |a: f32, b: f32| a.max(b);
max(min(a, b), min(max(a, b), c))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment