Skip to main content

ttf_view/
lib.rs

1//! A TrueType/OpenType font parsing/viewing library and a CLI tool.
2//!
3//! # Features
4//!
5//! Not much is implemented yet, but here's a few features that [`ttf-parser`] and [`read-fonts`]
6//! don't have:
7//!
8//! - Two-byte codepoint mappings (other crates only support Unicode).
9//! - Supports more character encodings (such as Shift JIS, GB 18030, Big5, EUC-KR).
10//! - Faster and easier access to metrics in the 'hmtx' table.
11//! - Actually implements 'cmap' format 2 subtable.
12//!
13//! Also, while not implemented yet, validation of the table data will only happen once - when you
14//! load the font, instead doing bounds-checks on every single field access like `ttf-parser` and
15//! `read-fonts` do, for some reason.
16//!
17//! The documentation will also be better, more descriptive and with examples and stuff. I want the
18//! entire crate to be comprehensible through documentation alone, without the need to look through
19//! what the language server shows you a type can do.
20//!
21//! # Reading a font file
22//!
23//! Loading fonts in a safe manner is not implemented yet, so you'll need to use `unsafe`.
24//! It will not perform any validation or bounds checks, and may cause memory access violation.
25//! But, as long as the font file is well-formed, there shouldn't be any issues.
26//!
27//! ```no_run
28//! use ttf_view::tables::TableDirectoryRepr;
29//!
30//! let data = std::fs::read("MyFont.ttf").unwrap();
31//! let dir = unsafe { TableDirectoryRepr::new_unchecked(&data) };
32//!
33//! if let Some(cmap) = dir.cmap() {
34//!     // ...
35//! }
36//! ```
37//!
38//! [`TableDirectoryRepr`] is the entry point and the main hub for OpenType tables.
39//!
40//! See the [`tables`] module for more information about tables that you can access.
41//!
42//! [`TableDirectoryRepr`]: tables::TableDirectoryRepr
43//! [`ttf-parser`]: https://docs.rs/ttf-parser/latest/ttf_parser/
44//! [`read-fonts`]: https://docs.rs/read-fonts/latest/read_fonts/
45
46#![feature(const_trait_impl)]
47#![feature(const_result_trait_fn)]
48#![feature(const_slice_from_ptr_range)]
49#![feature(const_slice_make_iter)]
50#![feature(const_option_ops)]
51#![feature(const_convert)]
52#![feature(const_default)]
53#![feature(const_clone)]
54#![feature(const_index)]
55#![feature(const_iter)]
56#![feature(const_cmp)]
57#![feature(const_try)]
58#![feature(derive_const)]
59#![feature(bstr)]
60#![feature(debug_closure_helpers)]
61#![feature(formatting_options)]
62#![feature(slice_from_ptr_range)]
63#![feature(try_trait_v2)]
64#![allow(clippy::missing_safety_doc)] // TODO: remove when adding docs
65
66pub mod platform;
67pub mod tables;
68pub mod types;
69
70mod util;