harfbuzz_traits/unicode_funcs_traits.rs
1// Copyright 2023 The Servo Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10/// A general category value. Equivalent to [`hb_unicode_general_category_t`].
11///
12/// [`hb_unicode_general_category_t`]: crate::sys::hb_unicode_general_category_t
13#[repr(u8)]
14#[derive(Debug, Copy, Clone, PartialEq, Eq)]
15#[allow(non_camel_case_types)] // the names are defined by Unicode
16#[allow(missing_docs)] // the categories are defined by Unicode
17pub enum GeneralCategory {
18 Control = 0,
19 Format = 1,
20 Unassigned = 2,
21 PrivateUse = 3,
22 Surrogate = 4,
23 LowercaseLetter = 5,
24 ModifierLetter = 6,
25 OtherLetter = 7,
26 TitlecaseLetter = 8,
27 UppercaseLetter = 9,
28 SpacingMark = 10,
29 EnclosingMark = 11,
30 NonSpacingMark = 12,
31 DecimalNumber = 13,
32 LetterNumber = 14,
33 OtherNumber = 15,
34 ConnectPunctuation = 16,
35 DashPunctuation = 17,
36 ClosePunctuation = 18,
37 FinalPunctuation = 19,
38 InitialPunctuation = 20,
39 OtherPunctuation = 21,
40 OpenPunctuation = 22,
41 CurrencySymbol = 23,
42 ModifierSymbol = 24,
43 MathSymbol = 25,
44 OtherSymbol = 26,
45 LineSeparator = 27,
46 ParagraphSeparator = 28,
47 SpaceSeparator = 29,
48}
49
50/// An object to map from code points to general category properties.
51pub trait GeneralCategoryFunc {
52 /// Given a code point, return the general category as a [`GeneralCategory`].
53 fn general_category(&self, ch: char) -> GeneralCategory;
54}
55
56/// An object to map from code points to combining classes.
57pub trait CombiningClassFunc {
58 /// Given a code point, return the combining class as a `u8` corresponding to a
59 /// [`hb_unicode_combining_class_t`]. Note that the
60 /// [Unicode stability policy](https://www.unicode.org/policies/stability_policy.html)
61 /// guarantees that Canonical Combining Class numeric values fit in a `u8`.
62 ///
63 /// [`hb_unicode_combining_class_t`]: crate::sys::hb_unicode_combining_class_t
64 fn combining_class(&self, ch: char) -> u8;
65}
66
67/// An object to map from code points to mirrored code points.
68pub trait MirroringFunc {
69 /// Given a code point, return the mirrored code point.
70 fn mirroring(&self, ch: char) -> char;
71}
72
73/// An object to map from code points to script names.
74pub trait ScriptFunc {
75 /// Given a code point, return the script as a 4-byte script name.
76 fn script(&self, ch: char) -> [u8; 4];
77}
78
79/// An object to compose two characters.
80pub trait ComposeFunc {
81 /// Given two code points, return the composed code point.
82 fn compose(&self, a: char, b: char) -> Option<char>;
83}
84
85/// An object to decompose a character.
86pub trait DecomposeFunc {
87 /// Given a code point, return the two decomposed code points.
88 fn decompose(&self, ab: char) -> Option<(char, char)>;
89}