├── .clippy.toml ├── .github ├── FUNDING.yml └── workflows │ └── ci.yml ├── .gitignore ├── .typos.toml ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md └── src ├── attributes.rs ├── cache.rs ├── charmap.rs ├── feature ├── aat.rs ├── at.rs ├── mod.rs └── util.rs ├── font.rs ├── internal ├── aat.rs ├── at.rs ├── cmap.rs ├── fixed.rs ├── glyf.rs ├── head.rs ├── mod.rs ├── parse.rs ├── var.rs ├── vorg.rs └── xmtx.rs ├── lib.rs ├── macros.rs ├── metrics.rs ├── palette.rs ├── scale ├── bitmap │ ├── mod.rs │ └── png.rs ├── color.rs ├── hinting_cache.rs ├── image.rs ├── mod.rs ├── outline.rs └── proxy.rs ├── setting.rs ├── shape ├── aat.rs ├── at.rs ├── buffer.rs ├── cache.rs ├── cluster.rs ├── engine.rs ├── feature.rs ├── mod.rs └── partition.rs ├── strike.rs ├── string.rs ├── tag.rs ├── text ├── analyze.rs ├── cluster │ ├── char.rs │ ├── cluster.rs │ ├── complex.rs │ ├── info.rs │ ├── mod.rs │ ├── myanmar.rs │ ├── parse.rs │ ├── simple.rs │ └── token.rs ├── compose.rs ├── lang.rs ├── lang_data.rs ├── mod.rs ├── unicode.rs └── unicode_data.rs └── variation.rs /.clippy.toml: -------------------------------------------------------------------------------- 1 | # Don't warn about these identifiers when using clippy::doc_markdown. 2 | doc-valid-idents = ["ClearType", "HarfBuzz", "OpenType", "PostScript", ".."] 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: dfrg 4 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | 8 | jobs: 9 | test: 10 | name: Test (${{ matrix.toolchain }}, ${{ matrix.os }}) 11 | runs-on: ${{ matrix.os }} 12 | timeout-minutes: 60 13 | 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | toolchain: [stable, nightly] 18 | os: [windows-latest, ubuntu-latest, macos-latest] 19 | 20 | steps: 21 | - uses: actions/checkout@v4 22 | - uses: dtolnay/rust-toolchain@master 23 | with: 24 | toolchain: ${{ matrix.toolchain }} 25 | - uses: Swatinem/rust-cache@v2 26 | - run: cargo test 27 | 28 | build-no-std: 29 | runs-on: ubuntu-latest 30 | steps: 31 | - uses: actions/checkout@v4 32 | - uses: dtolnay/rust-toolchain@stable 33 | with: 34 | # Use a target without `std` to make sure we don't link to `std` 35 | targets: "x86_64-unknown-none,thumbv7m-none-eabi" 36 | - run: cargo build --target x86_64-unknown-none --no-default-features --features libm 37 | - run: cargo build --target x86_64-unknown-none --no-default-features --features libm,scale 38 | - run: cargo build --target x86_64-unknown-none --no-default-features --features libm,render 39 | - run: cargo build --target thumbv7m-none-eabi --no-default-features --features libm 40 | - run: cargo build --target thumbv7m-none-eabi --no-default-features --features libm,scale 41 | - run: cargo build --target thumbv7m-none-eabi --no-default-features --features libm,render 42 | 43 | miri: 44 | name: Miri 45 | runs-on: ubuntu-latest 46 | steps: 47 | - uses: actions/checkout@v4 48 | - uses: dtolnay/rust-toolchain@nightly 49 | with: 50 | components: miri 51 | - run: cargo miri test 52 | 53 | doc: 54 | name: cargo doc 55 | # NOTE: We don't have any platform specific docs in this workspace, so we only run on Ubuntu. 56 | # If we get per-platform docs (win/macos/linux/wasm32/..) then doc jobs should match that. 57 | runs-on: ubuntu-latest 58 | steps: 59 | - uses: actions/checkout@v4 60 | 61 | - name: install nightly toolchain 62 | uses: dtolnay/rust-toolchain@nightly 63 | 64 | # We test documentation using nightly to match docs.rs. 65 | - name: cargo doc 66 | run: cargo doc --workspace --all-features --no-deps --document-private-items 67 | env: 68 | RUSTDOCFLAGS: '--cfg docsrs -D warnings' 69 | 70 | # If this fails, consider changing your text or adding something to .typos.toml. 71 | typos: 72 | runs-on: ubuntu-latest 73 | steps: 74 | - uses: actions/checkout@v4 75 | 76 | - name: check typos 77 | uses: crate-ci/typos@v1.30.2 78 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | /target 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /.typos.toml: -------------------------------------------------------------------------------- 1 | # See the configuration reference at 2 | # https://github.com/crate-ci/typos/blob/master/docs/reference.md 3 | 4 | # Corrections take the form of a key/value pair. The key is the incorrect word 5 | # and the value is the correct word. If the key and value are the same, the 6 | # word is treated as always correct. If the value is an empty string, the word 7 | # is treated as always incorrect. 8 | 9 | # Match Identifier - Case Sensitive 10 | [default.extend-identifiers] 11 | xBA = "xBA" 12 | CDxBA = "CDxBA" 13 | DxBA = "DxBA" 14 | DCxBA = "DCxBA" 15 | falt = "falt" 16 | fo = "fo" 17 | FO = "FO" 18 | loca = "loca" 19 | loca_fmt = "loca_fmt" 20 | LOCA = "LOCA" 21 | paeth = "paeth" 22 | use_ot = "use_ot" 23 | wdth = "wdth" 24 | WDTH = "WDTH" 25 | 26 | # Match Inside a Word - Case Insensitive 27 | [default.extend-words] 28 | 29 | [files] 30 | # Include .github, .cargo, etc. 31 | ignore-hidden = false 32 | extend-exclude = [ 33 | "/src/text/lang_data.rs", 34 | "/src/text/unicode_data.rs", 35 | # /.git isn't in .gitignore, because git never tracks it. 36 | # Typos doesn't know that, though. 37 | "/.git" 38 | ] 39 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "swash" 3 | version = "0.2.5" 4 | authors = ["Chad Brokaw "] 5 | edition = "2021" 6 | description = "Font introspection, complex text shaping and glyph rendering." 7 | license = "Apache-2.0 OR MIT" 8 | keywords = ["font", "shape", "glyph", "text"] 9 | categories = ["graphics", "text-processing"] 10 | repository = "https://github.com/dfrg/swash" 11 | homepage = "https://github.com/dfrg/swash" 12 | readme = "README.md" 13 | 14 | [package.metadata.docs.rs] 15 | all-features = true 16 | # There are no platform specific docs. 17 | default-target = "x86_64-unknown-linux-gnu" 18 | targets = [] 19 | 20 | [features] 21 | default = ["std", "scale", "render"] 22 | 23 | libm = ["dep:core_maths", "skrifa/libm", "zeno?/libm"] 24 | std = ["skrifa/std", "zeno?/std", "yazi?/std"] 25 | 26 | scale = ["dep:yazi", "dep:zeno"] 27 | render = ["scale", "zeno/eval"] 28 | 29 | [lints] 30 | clippy.doc_markdown = "warn" 31 | clippy.semicolon_if_nothing_returned = "warn" 32 | 33 | [dependencies] 34 | core_maths = { version = "0.1.1", optional = true } 35 | yazi = { version = "0.2.1", optional = true, default-features = false } 36 | zeno = { version = "0.3.3", optional = true, default-features = false } 37 | skrifa = { version = "0.31.1", default-features = false } 38 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020 Chad Brokaw 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swash 2 | 3 | Swash is a pure Rust, cross-platform crate that provides font introspection, 4 | complex text shaping and glyph rendering. 5 | 6 | [![Crates.io][crates-badge]][crates-url] 7 | [![Docs.rs][docs-badge]][docs-url] 8 | [![Apache 2.0 or MIT license.][license-badge]][license-url] 9 | 10 | [crates-badge]: https://img.shields.io/crates/v/swash.svg 11 | [crates-url]: https://crates.io/crates/swash 12 | [docs-badge]: https://docs.rs/swash/badge.svg 13 | [docs-url]: https://docs.rs/swash 14 | [license-badge]: https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg 15 | [license-url]: #license 16 | 17 | ### Goals 18 | 19 | This crate aims to lay the foundation for a cross-platform, high performance set 20 | of components for beautiful typography. In particular, this library focuses on 21 | fonts and operations that are directly applicable to them. For the most part, the 22 | desire is to be unopinionated with respect to resource management, higher level 23 | layout and lower level rendering. 24 | 25 | ### Non goals 26 | 27 | Due to the intention of being generally useful and easy to integrate, the following 28 | areas of related interest are specifically avoided: 29 | 30 | - Text layout. This is highly application specific and the requirements for both 31 | features and performance differ greatly among web browsers, word processors, 32 | text editors, game engines, etc. There is a sibling crate in development that 33 | does provide general purpose text layout based on this library. 34 | 35 | - Composition. Like layout, this is also application specific in addition to being 36 | hardware dependent. Glyph caching, geometry batching and rendering all belong 37 | here and should integrate well with the application and the hardware environment. 38 | 39 | ### General features 40 | 41 | - Simple borrowed font representation that imposes no requirements on resource 42 | management leading to... 43 | - Thread friendly architecture. Acceleration structures are completely separate from 44 | font data and can be retained per thread, thrown away and rematerialized at any 45 | time 46 | - Zero transient heap allocations. All scratch buffers and caches are maintained by 47 | contexts. Resources belonging to evicted cache entries are immediately reused 48 | 49 | ### Introspection 50 | 51 | - Enumerating font collections (ttc/otc) 52 | - Localized strings including names and other metadata 53 | - Font variation axes and named instances 54 | - Comprehensive font and per-glyph metrics (with synthesized vertical metrics if not provided) 55 | - Primary attributes (stretch, weight, style) with support for synthesis suggestions 56 | based on available variations and scaler transforms (faux bold and oblique) 57 | - Color palettes 58 | - Embedded color and alpha bitmap strikes 59 | - Character to nominal glyph identifier mapping with support for enumerating all pairs 60 | - Writing systems: provides a list of all supported script/language pairs 61 | and their associated typographic features 62 | - All introspection is zero allocation and zero copy 63 | 64 | ### Complex text shaping 65 | 66 | - Full support for OpenType advanced typography (GSUB/GPOS) 67 | - Partial support for Apple advanced typography: glyph metamorphosis (morx) is fully 68 | supported while the current extended kerning support (kerx) covers most common 69 | cases (kerning and mark positioning) 70 | - Full support for variable fonts including positioning and feature substitutions 71 | - Implementation of the Universal Shaping Engine for complex scripts such as Devanagari, Malayalam, etc. 72 | - Arabic joining including Urdu style climbing runs 73 | - Basic shaping support: ligatures, marks, kerning, etc. 74 | - Enable/disable individual features with argument support for activating alternates 75 | such as _swashes_... 76 | - Pre-shaping cluster parsing with an iterative mapping technique (including normalization) allowing for 77 | sophisticated font fallback mechanisms without the expense of heuristically shaping runs 78 | - Shaper output is structured by cluster including original source ranges and provides simple 79 | identification of ligatures and complex multi-glyph clusters 80 | - Pass-through per character user data (a single u32) for accurate association of style 81 | properties with glyphs 82 | - Pass-through per cluster information for retaining text analysis results such as word 83 | and line boundaries, whitespace identification and emoji presentation modes 84 | 85 | ### Scaling 86 | 87 | - Scalable outlines with full variation support (TrueType and Postscript) 88 | - Asymmetric vertical hinting (TrueType and Postscript) 89 | - Horizontal subpixel rendering and fractional positioning 90 | - Full emoji support for Apple (sbix), Google (CBLC/CBDT) and Microsoft (COLR/CPAL) 91 | formats 92 | - Path effects (stroking and dashing) 93 | - Transforms including synthetic emboldening and affine transformations 94 | - Customizable glyph source prioritization (best fit color bitmap -> exact size alpha bitmap -> outline) 95 | 96 | ### Text analysis 97 | 98 | - Unicode character properties related to layout and shaping 99 | - Character composition and decomposition (canonical and compatible) 100 | - Complex, script aware cluster segmentation 101 | - Single pass, iterator based analysis determines word and line boundaries 102 | and detects whether bidi resolution is necessary 103 | 104 | ### Performance 105 | 106 | Performance is a primary goal for this crate and preliminary microbenchmarks show a general 107 | improvement over FreeType and Harfbuzz by about 10-20% on average and some cases show 108 | substantial wins, particularly when scaling Postscript outlines or shaping text with complex 109 | features. Specifically, shaping runs with fonts like Calibri and Noto Sans Myanmar is almost 110 | twice as fast. Simple fonts and pure ASCII runs tend to show the smallest gains as those 111 | simply measure shaper initialization and glyph iteration. A comprehensive set of benchmarks 112 | (and test cases!) are needed here to gain more insight and track regressions. 113 | 114 | ### License 115 | 116 | Licensed under either of 117 | 118 | - Apache License, Version 2.0 119 | ([LICENSE-APACHE](LICENSE-APACHE) or ) 120 | - MIT license 121 | ([LICENSE-MIT](LICENSE-MIT) or ) 122 | 123 | at your option. 124 | 125 | ### Contribution 126 | 127 | Contributions are welcome by pull request. The [Rust code of conduct] applies. 128 | 129 | Unless you explicitly state otherwise, any contribution intentionally submitted 130 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 131 | licensed as above, without any additional terms or conditions. 132 | 133 | [Rust Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct 134 | -------------------------------------------------------------------------------- /src/cache.rs: -------------------------------------------------------------------------------- 1 | use super::FontRef; 2 | use alloc::vec::Vec; 3 | 4 | /// Uniquely generated value for identifying and caching fonts. 5 | #[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)] 6 | pub struct CacheKey(pub(crate) u64); 7 | 8 | impl CacheKey { 9 | /// Generates a new cache key. 10 | pub fn new() -> Self { 11 | use core::sync::atomic::{AtomicUsize, Ordering}; 12 | static KEY: AtomicUsize = AtomicUsize::new(1); 13 | Self(KEY.fetch_add(1, Ordering::Relaxed).try_into().unwrap()) 14 | } 15 | 16 | /// Returns the underlying value of the key. 17 | pub fn value(self) -> u64 { 18 | self.0 19 | } 20 | } 21 | 22 | impl Default for CacheKey { 23 | fn default() -> Self { 24 | Self::new() 25 | } 26 | } 27 | 28 | pub struct FontCache { 29 | entries: Vec>, 30 | max_entries: usize, 31 | epoch: u64, 32 | } 33 | 34 | impl FontCache { 35 | pub fn new(max_entries: usize) -> Self { 36 | Self { 37 | entries: Vec::new(), 38 | epoch: 0, 39 | max_entries, 40 | } 41 | } 42 | 43 | pub fn get<'a>( 44 | &'a mut self, 45 | font: &FontRef, 46 | id_override: Option<[u64; 2]>, 47 | mut f: impl FnMut(&FontRef) -> T, 48 | ) -> ([u64; 2], &'a T) { 49 | let id = id_override.unwrap_or([font.key.value(), u64::MAX]); 50 | let (found, index) = self.find(id); 51 | if found { 52 | let entry = &mut self.entries[index]; 53 | entry.epoch = self.epoch; 54 | (entry.id, &entry.data) 55 | } else { 56 | self.epoch += 1; 57 | let data = f(font); 58 | if index == self.entries.len() { 59 | self.entries.push(Entry { 60 | epoch: self.epoch, 61 | id, 62 | data, 63 | }); 64 | let entry = self.entries.last().unwrap(); 65 | (id, &entry.data) 66 | } else { 67 | let entry = &mut self.entries[index]; 68 | entry.epoch = self.epoch; 69 | entry.id = id; 70 | entry.data = data; 71 | (id, &entry.data) 72 | } 73 | } 74 | } 75 | 76 | fn find(&self, id: [u64; 2]) -> (bool, usize) { 77 | let mut lowest = 0; 78 | let mut lowest_epoch = self.epoch; 79 | for (i, entry) in self.entries.iter().enumerate() { 80 | if entry.id == id { 81 | return (true, i); 82 | } 83 | if entry.epoch < lowest_epoch { 84 | lowest_epoch = entry.epoch; 85 | lowest = i; 86 | } 87 | } 88 | if self.entries.len() < self.max_entries { 89 | (false, self.entries.len()) 90 | } else { 91 | (false, lowest) 92 | } 93 | } 94 | } 95 | 96 | struct Entry { 97 | epoch: u64, 98 | id: [u64; 2], 99 | data: T, 100 | } 101 | -------------------------------------------------------------------------------- /src/charmap.rs: -------------------------------------------------------------------------------- 1 | /*! 2 | Mapping characters to nominal glyph identifiers. 3 | */ 4 | 5 | use super::internal::cmap; 6 | use super::{FontRef, GlyphId}; 7 | 8 | /// Proxy for rematerializing a character map. 9 | #[derive(Copy, Clone, Default, Debug)] 10 | pub struct CharmapProxy(u32, u8, bool); 11 | 12 | impl CharmapProxy { 13 | /// Creates character map proxy from the specified font. 14 | pub fn from_font(font: &FontRef) -> Self { 15 | if let Some((offset, format, symbol)) = cmap::subtable(font) { 16 | Self(offset, format, symbol) 17 | } else { 18 | Self(0, 0, false) 19 | } 20 | } 21 | 22 | /// Materializes a character map from the specified font. This proxy must 23 | /// have been created from the same font. 24 | pub fn materialize<'a>(&self, font: &FontRef<'a>) -> Charmap<'a> { 25 | Charmap { 26 | data: font.data, 27 | proxy: *self, 28 | } 29 | } 30 | } 31 | 32 | /// Maps characters to nominal glyph identifiers. 33 | #[derive(Copy, Clone)] 34 | pub struct Charmap<'a> { 35 | data: &'a [u8], 36 | proxy: CharmapProxy, 37 | } 38 | 39 | impl<'a> Charmap<'a> { 40 | /// Creates a character map from the specified font. 41 | pub fn from_font(font: &FontRef<'a>) -> Self { 42 | let proxy = CharmapProxy::from_font(font); 43 | Self { 44 | data: font.data, 45 | proxy, 46 | } 47 | } 48 | 49 | /// Returns the associated proxy. 50 | pub fn proxy(&self) -> CharmapProxy { 51 | self.proxy 52 | } 53 | 54 | /// Returns a nominal glyph identifier for the specified codepoint. 55 | pub fn map(&self, codepoint: impl Into) -> GlyphId { 56 | let codepoint = codepoint.into(); 57 | let mut glyph_id = cmap::map(self.data, self.proxy.0, self.proxy.1, codepoint).unwrap_or(0); 58 | // Remap U+0000..=U+00FF to U+F000..=U+F0FF for symbol encodings 59 | if glyph_id == 0 && self.proxy.2 && codepoint <= 0x00FF { 60 | glyph_id = 61 | cmap::map(self.data, self.proxy.0, self.proxy.1, codepoint + 0xF000).unwrap_or(0); 62 | } 63 | glyph_id 64 | } 65 | 66 | /// Invokes the specified closure with all codepoint/glyph identifier 67 | /// pairs in the character map. 68 | pub fn enumerate(&self, f: impl FnMut(u32, GlyphId)) { 69 | cmap::enumerate(self.data, self.proxy.0, f); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/feature/aat.rs: -------------------------------------------------------------------------------- 1 | use super::internal::{aat::morx, raw_tag}; 2 | use super::util::*; 3 | 4 | pub use morx::chains; 5 | use morx::Chains; 6 | 7 | #[derive(Copy, Clone)] 8 | pub struct Features<'a> { 9 | chains: Chains<'a>, 10 | features: Option>, 11 | kern: bool, 12 | seen: SeenFeatures, 13 | } 14 | 15 | impl<'a> Features<'a> { 16 | pub fn new(chains: Chains<'a>, kern: bool) -> Self { 17 | Self { 18 | chains, 19 | features: None, 20 | kern, 21 | seen: SeenFeatures::new(), 22 | } 23 | } 24 | } 25 | 26 | impl<'a> Iterator for Features<'a> { 27 | type Item = (u32, &'static str); 28 | 29 | fn next(&mut self) -> Option { 30 | loop { 31 | if self.features.is_none() { 32 | if let Some(chain) = self.chains.next() { 33 | self.features = Some(chain.features()); 34 | } else if self.kern { 35 | let tag = raw_tag(b"kern"); 36 | let (_, desc) = desc_from_at(tag).unwrap_or((0, "Kerning")); 37 | self.kern = false; 38 | return Some((tag, desc)); 39 | } else { 40 | return None; 41 | } 42 | } 43 | if let Some(features) = &mut self.features { 44 | if let Some(feature) = features.next() { 45 | if let Some((index, tag, desc)) = 46 | desc_from_aat(feature.selector, feature.setting_selector) 47 | { 48 | if self.seen.mark(index) { 49 | return Some((tag, desc)); 50 | } 51 | } 52 | } else { 53 | self.features = None; 54 | continue; 55 | } 56 | } 57 | } 58 | } 59 | } 60 | 61 | pub type OnceItem<'a> = Option>; 62 | // #[derive(Copy, Clone)] 63 | // pub struct OnceItem<'a> { 64 | // pub item: Item<'a>, 65 | // pub given: bool, 66 | // } 67 | 68 | // impl<'a> OnceItem<'a> { 69 | // pub fn new(item: Item<'a>) -> Self { 70 | // Self { item, given: false } 71 | // } 72 | // } 73 | 74 | // impl<'a> Iterator for OnceItem<'a> { 75 | // type Item = Item<'a>; 76 | 77 | // fn next(&mut self) -> Option { 78 | // if self.given { 79 | // None 80 | // } else { 81 | // self.given = true; 82 | // Some(self.item) 83 | // } 84 | // } 85 | // } 86 | 87 | #[derive(Copy, Clone)] 88 | pub struct Item<'a> { 89 | pub chains: Chains<'a>, 90 | pub kern: bool, 91 | } 92 | -------------------------------------------------------------------------------- /src/feature/at.rs: -------------------------------------------------------------------------------- 1 | use super::super::Tag; 2 | use super::internal::{at::*, *}; 3 | use super::util::*; 4 | 5 | #[derive(Copy, Clone)] 6 | pub struct Script<'a> { 7 | data: Bytes<'a>, 8 | gsub: u32, 9 | gpos: u32, 10 | gsub_offset: u32, 11 | gpos_offset: u32, 12 | tag: Tag, 13 | } 14 | 15 | impl<'a> Script<'a> { 16 | pub fn languages(&self) -> Languages<'a> { 17 | Languages::new( 18 | self.data, 19 | self.gsub, 20 | self.gpos, 21 | self.gsub_offset, 22 | self.gpos_offset, 23 | ) 24 | } 25 | } 26 | 27 | #[derive(Copy, Clone)] 28 | pub struct Scripts<'a> { 29 | data: Bytes<'a>, 30 | gsub: u32, 31 | gpos: u32, 32 | in_gsub: bool, 33 | len: u16, 34 | cur: u16, 35 | done: bool, 36 | } 37 | 38 | impl<'a> Scripts<'a> { 39 | pub fn new(data: Bytes<'a>, gsub: u32, gpos: u32) -> Self { 40 | Self { 41 | data, 42 | gsub, 43 | gpos, 44 | in_gsub: true, 45 | len: script_count(&data, gsub), 46 | cur: 0, 47 | done: false, 48 | } 49 | } 50 | 51 | fn get_next(&mut self) -> Option> { 52 | if self.in_gsub { 53 | if self.cur < self.len { 54 | let index = self.cur; 55 | self.cur += 1; 56 | let (tag, offset) = script_at(&self.data, self.gsub, index)?; 57 | let gpos_offset = script_by_tag(&self.data, self.gpos, tag).unwrap_or(0); 58 | return Some(Script { 59 | data: self.data, 60 | gsub: self.gsub, 61 | gpos: self.gpos, 62 | gsub_offset: offset, 63 | gpos_offset, 64 | tag, 65 | }); 66 | } else { 67 | self.in_gsub = false; 68 | self.cur = 0; 69 | self.len = script_count(&self.data, self.gpos); 70 | } 71 | } else if self.cur < self.len { 72 | let index = self.cur; 73 | self.cur += 1; 74 | let (tag, offset) = script_at(&self.data, self.gpos, index)?; 75 | if script_by_tag(&self.data, self.gsub, tag).is_some() { 76 | return None; 77 | } 78 | return Some(Script { 79 | data: self.data, 80 | gsub: self.gsub, 81 | gpos: self.gpos, 82 | gsub_offset: 0, 83 | gpos_offset: offset, 84 | tag, 85 | }); 86 | } else { 87 | self.done = true; 88 | } 89 | None 90 | } 91 | } 92 | 93 | impl<'a> Iterator for Scripts<'a> { 94 | type Item = Script<'a>; 95 | 96 | fn next(&mut self) -> Option { 97 | while !self.done { 98 | let item = self.get_next(); 99 | if item.is_some() { 100 | return item; 101 | } 102 | } 103 | None 104 | } 105 | } 106 | 107 | /// Specifies language system specific features used for shaping glyphs in 108 | /// a particular script. 109 | #[derive(Copy, Clone)] 110 | pub struct Language<'a> { 111 | data: Bytes<'a>, 112 | gsub: u32, 113 | gpos: u32, 114 | gsub_offset: u32, 115 | gpos_offset: u32, 116 | tag: Tag, 117 | } 118 | 119 | /// An iterator over languages supported by a script. 120 | #[derive(Copy, Clone)] 121 | pub struct Languages<'a> { 122 | data: Bytes<'a>, 123 | gsub: u32, 124 | gpos: u32, 125 | gsub_script: u32, 126 | gpos_script: u32, 127 | in_gsub: bool, 128 | len: u16, 129 | cur: u16, 130 | done: bool, 131 | } 132 | 133 | impl<'a> Languages<'a> { 134 | fn new(data: Bytes<'a>, gsub: u32, gpos: u32, gsub_script: u32, gpos_script: u32) -> Self { 135 | Self { 136 | data, 137 | gsub, 138 | gpos, 139 | gsub_script, 140 | gpos_script, 141 | in_gsub: true, 142 | len: script_language_count(&data, gsub_script), 143 | cur: 0, 144 | done: false, 145 | } 146 | } 147 | 148 | fn get_next(&mut self) -> Option> { 149 | if self.in_gsub { 150 | if self.cur < self.len { 151 | let index = self.cur; 152 | self.cur += 1; 153 | let (tag, offset) = script_language_at(&self.data, self.gsub_script, index)?; 154 | let gsub_default = tag == DFLT; 155 | let (gpos_offset, _) = if gsub_default { 156 | ( 157 | script_default_language(&self.data, self.gpos_script).unwrap_or(0), 158 | true, 159 | ) 160 | } else { 161 | script_language_by_tag(&self.data, self.gpos_script, Some(tag)) 162 | .unwrap_or((0, false)) 163 | }; 164 | return Some(Language { 165 | data: self.data, 166 | gsub: self.gsub, 167 | gpos: self.gpos, 168 | gsub_offset: offset, 169 | gpos_offset, 170 | tag, 171 | }); 172 | } else { 173 | self.in_gsub = false; 174 | self.cur = 0; 175 | self.len = script_language_count(&self.data, self.gpos_script); 176 | } 177 | } else if self.cur < self.len { 178 | let index = self.cur; 179 | self.cur += 1; 180 | let (tag, offset) = script_language_at(&self.data, self.gpos_script, index)?; 181 | if script_language_by_tag(&self.data, self.gsub_script, Some(tag)).is_some() { 182 | return None; 183 | } 184 | return Some(Language { 185 | data: self.data, 186 | gsub: self.gsub, 187 | gpos: self.gpos, 188 | gsub_offset: 0, 189 | gpos_offset: offset, 190 | tag, 191 | }); 192 | } else { 193 | self.done = true; 194 | } 195 | None 196 | } 197 | } 198 | 199 | impl<'a> Iterator for Languages<'a> { 200 | type Item = Language<'a>; 201 | 202 | fn next(&mut self) -> Option { 203 | while !self.done { 204 | let item = self.get_next(); 205 | if item.is_some() { 206 | return item; 207 | } 208 | } 209 | None 210 | } 211 | } 212 | 213 | #[derive(Copy, Clone)] 214 | pub struct WritingSystem<'a> { 215 | lang: Language<'a>, 216 | script_tag: Tag, 217 | } 218 | 219 | impl<'a> WritingSystem<'a> { 220 | pub fn script_tag(&self) -> Tag { 221 | self.script_tag 222 | } 223 | 224 | pub fn language_tag(&self) -> Tag { 225 | self.lang.tag 226 | } 227 | 228 | pub fn features(&self) -> Features<'a> { 229 | Features::new(&self.lang) 230 | } 231 | } 232 | 233 | #[derive(Copy, Clone)] 234 | pub struct WritingSystems<'a> { 235 | scripts: Scripts<'a>, 236 | langs: Option>, 237 | script_tag: Tag, 238 | } 239 | 240 | impl<'a> WritingSystems<'a> { 241 | pub fn new(scripts: Scripts<'a>) -> Self { 242 | Self { 243 | scripts, 244 | langs: None, 245 | script_tag: 0, 246 | } 247 | } 248 | } 249 | 250 | impl<'a> Iterator for WritingSystems<'a> { 251 | type Item = WritingSystem<'a>; 252 | 253 | fn next(&mut self) -> Option { 254 | loop { 255 | if self.langs.is_none() { 256 | let script = self.scripts.next()?; 257 | self.script_tag = script.tag; 258 | self.langs = Some(script.languages()); 259 | } 260 | if let Some(lang) = self.langs.as_mut().unwrap().next() { 261 | return Some(WritingSystem { 262 | lang, 263 | script_tag: self.script_tag, 264 | }); 265 | } else { 266 | self.langs = None; 267 | } 268 | } 269 | } 270 | } 271 | 272 | /// Represents a single typographic feature-- a substitution or positioning 273 | /// action that is a component of text shaping. 274 | #[derive(Copy, Clone)] 275 | pub struct Feature { 276 | pub stage: u8, 277 | pub tag: Tag, 278 | } 279 | 280 | #[derive(Copy, Clone)] 281 | pub struct Features<'a> { 282 | data: Bytes<'a>, 283 | gsub: u32, 284 | gpos: u32, 285 | gsub_language: u32, 286 | gpos_language: u32, 287 | stage: u8, 288 | len: u16, 289 | cur: u16, 290 | done: bool, 291 | } 292 | 293 | impl<'a> Features<'a> { 294 | fn new(language: &Language<'a>) -> Self { 295 | Self { 296 | data: language.data, 297 | gsub: language.gsub, 298 | gpos: language.gpos, 299 | gsub_language: language.gsub_offset, 300 | gpos_language: language.gpos_offset, 301 | stage: 0, 302 | len: language_feature_count(&language.data, language.gsub_offset), 303 | cur: 0, 304 | done: false, 305 | } 306 | } 307 | 308 | fn get_next(&mut self) -> Option { 309 | let (gsubgpos, language) = match self.stage { 310 | 0 => (self.gsub, self.gsub_language), 311 | _ => (self.gpos, self.gpos_language), 312 | }; 313 | if self.cur < self.len { 314 | let index = self.cur; 315 | self.cur += 1; 316 | let feature = language_feature_at(&self.data, language, index)?; 317 | let (tag, _offset) = feature_at(&self.data, gsubgpos, feature)?; 318 | return Some(Feature { 319 | stage: self.stage, 320 | tag, 321 | }); 322 | } else if self.stage == 0 { 323 | self.stage = 1; 324 | self.len = language_feature_count(&self.data, self.gpos_language); 325 | self.cur = 0; 326 | } else { 327 | self.done = true; 328 | } 329 | None 330 | } 331 | } 332 | 333 | impl<'a> Iterator for Features<'a> { 334 | type Item = Feature; 335 | 336 | fn next(&mut self) -> Option { 337 | while !self.done { 338 | let item = self.get_next(); 339 | if item.is_some() { 340 | return item; 341 | } 342 | } 343 | None 344 | } 345 | } 346 | 347 | #[derive(Copy, Clone)] 348 | pub struct AllFeatures<'a> { 349 | data: Bytes<'a>, 350 | seen: SeenFeatures, 351 | table: u32, 352 | next_table: u32, 353 | stage: u8, 354 | len: u16, 355 | cur: u16, 356 | } 357 | 358 | impl<'a> AllFeatures<'a> { 359 | pub fn new(data: Bytes<'a>, gsub: u32, gpos: u32) -> Self { 360 | let len = feature_count(&data, gsub); 361 | Self { 362 | data, 363 | seen: SeenFeatures::new(), 364 | table: gsub, 365 | next_table: gpos, 366 | stage: 0, 367 | len, 368 | cur: 0, 369 | } 370 | } 371 | } 372 | 373 | impl<'a> Iterator for AllFeatures<'a> { 374 | type Item = (u8, Tag); 375 | 376 | fn next(&mut self) -> Option { 377 | loop { 378 | if self.cur >= self.len { 379 | if self.next_table == 0 { 380 | return None; 381 | } 382 | self.table = self.next_table; 383 | self.next_table = 0; 384 | self.stage = 1; 385 | self.cur = 0; 386 | self.len = feature_count(&self.data, self.table); 387 | if self.len == 0 { 388 | return None; 389 | } 390 | } 391 | let index = self.cur; 392 | self.cur += 1; 393 | if let Some((tag, _)) = feature_at(&self.data, self.table, index) { 394 | match FEATURES.binary_search_by(|pair| pair.0.cmp(&tag)) { 395 | Ok(index) => { 396 | if self.seen.mark(index) { 397 | return Some((self.stage, tag)); 398 | } 399 | } 400 | _ => continue, 401 | } 402 | } 403 | } 404 | } 405 | } 406 | -------------------------------------------------------------------------------- /src/feature/mod.rs: -------------------------------------------------------------------------------- 1 | mod aat; 2 | mod at; 3 | mod util; 4 | 5 | use super::internal::{self, raw_tag, Bytes, RawFont}; 6 | use super::{FontRef, Tag}; 7 | use crate::text::{Language, Script}; 8 | 9 | const DFLT: u32 = raw_tag(b"DFLT"); 10 | 11 | #[derive(Copy, Clone)] 12 | enum Kind { 13 | None, 14 | /// GSUB, GPOS offsets 15 | At(u32, u32), 16 | /// Morx offset, kerning available 17 | Aat(u32, bool), 18 | } 19 | 20 | impl Kind { 21 | fn from_font(font: &FontRef) -> Self { 22 | let gsub = font.table_offset(raw_tag(b"GSUB")); 23 | let gpos = font.table_offset(raw_tag(b"GPOS")); 24 | if gsub != 0 || gpos != 0 { 25 | return Self::At(gsub, gpos); 26 | } 27 | let morx = font.table_offset(raw_tag(b"morx")); 28 | if morx != 0 { 29 | let kern = font.table_offset(raw_tag(b"kern")) != 0 30 | || font.table_offset(raw_tag(b"kerx")) != 0; 31 | return Self::Aat(morx, kern); 32 | } 33 | Self::None 34 | } 35 | } 36 | 37 | #[derive(Copy, Clone)] 38 | enum WritingSystemsKind<'a> { 39 | None, 40 | At(at::WritingSystems<'a>), 41 | Aat(aat::OnceItem<'a>), 42 | } 43 | 44 | /// Iterator over a collection of writing systems. 45 | #[derive(Copy, Clone)] 46 | pub struct WritingSystems<'a> { 47 | kind: WritingSystemsKind<'a>, 48 | } 49 | 50 | impl<'a> WritingSystems<'a> { 51 | pub(crate) fn from_font(font: &FontRef<'a>) -> Self { 52 | let kind = Kind::from_font(font); 53 | WritingSystems { 54 | kind: match kind { 55 | Kind::At(gsub, gpos) => WritingSystemsKind::At(at::WritingSystems::new( 56 | at::Scripts::new(Bytes::new(font.data), gsub, gpos), 57 | )), 58 | Kind::Aat(morx, kern) => WritingSystemsKind::Aat(Some(aat::Item { 59 | chains: aat::chains(font.data, morx), 60 | kern, 61 | })), 62 | _ => WritingSystemsKind::None, 63 | }, 64 | } 65 | } 66 | } 67 | 68 | #[derive(Copy, Clone)] 69 | enum WritingSystemKind<'a> { 70 | At(at::WritingSystem<'a>), 71 | Aat(aat::Item<'a>), 72 | } 73 | 74 | impl<'a> Iterator for WritingSystems<'a> { 75 | type Item = WritingSystem<'a>; 76 | 77 | fn next(&mut self) -> Option { 78 | match &mut self.kind { 79 | WritingSystemsKind::At(iter) => { 80 | let item = iter.next()?; 81 | Some(WritingSystem { 82 | kind: WritingSystemKind::At(item), 83 | script_tag: item.script_tag(), 84 | lang_tag: item.language_tag(), 85 | lang: Language::from_opentype(item.language_tag()), 86 | }) 87 | } 88 | WritingSystemsKind::Aat(iter) => { 89 | let item = iter.take()?; 90 | Some(WritingSystem { 91 | kind: WritingSystemKind::Aat(item), 92 | script_tag: DFLT, 93 | lang_tag: DFLT, 94 | lang: None, 95 | }) 96 | } 97 | _ => None, 98 | } 99 | } 100 | } 101 | 102 | /// Script, language and associated typographic features available in a font. 103 | #[derive(Copy, Clone)] 104 | pub struct WritingSystem<'a> { 105 | kind: WritingSystemKind<'a>, 106 | script_tag: Tag, 107 | lang_tag: Tag, 108 | lang: Option, 109 | } 110 | 111 | impl<'a> WritingSystem<'a> { 112 | /// Returns the OpenType script tag for the writing system. 113 | pub fn script_tag(&self) -> Tag { 114 | self.script_tag 115 | } 116 | 117 | /// Returns the OpenType language tag for the writing system. 118 | pub fn language_tag(&self) -> Tag { 119 | self.lang_tag 120 | } 121 | 122 | /// Returns the script for the writing system. 123 | pub fn script(&self) -> Option