kas_text/env.rs
1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License in the LICENSE-APACHE file or at:
4// https://www.apache.org/licenses/LICENSE-2.0
5
6//! KAS Rich-Text library — text-display environment
7
8/// Alignment of contents
9///
10/// Note that alignment information is often passed as a `(horiz, vert)` pair.
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Ord, PartialOrd, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub enum Align {
14 /// Default alignment
15 ///
16 /// This is context dependent. For example, for Left-To-Right text it means
17 /// `TL`; for things which want to stretch it may mean `Stretch`.
18 #[default]
19 Default,
20 /// Align to top or left
21 TL,
22 /// Align to center
23 Center,
24 /// Align to bottom or right
25 BR,
26 /// Stretch to fill space
27 ///
28 /// For text, this is known as "justified alignment".
29 Stretch,
30}
31
32/// Directionality of text
33///
34/// Texts may be bi-directional as specified by Unicode Technical Report #9.
35#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Ord, PartialOrd, Hash)]
36#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
37#[repr(u8)]
38pub enum Direction {
39 /// Auto-detect direction
40 ///
41 /// The text direction is inferred from the first strongly-directional
42 /// character. In case no such character is found, the text will be
43 /// left-to-right.
44 #[default]
45 Auto = 2,
46 /// Auto-detect, default right-to-left
47 ///
48 /// The text direction is inferred from the first strongly-directional
49 /// character. In case no such character is found, the text will be
50 /// right-to-left.
51 AutoRtl = 3,
52 /// The base text direction is left-to-right
53 ///
54 /// If the text contains right-to-left content, this will be considered an
55 /// embedded right-to-left run. Non-directional leading and trailing
56 /// characters (e.g. a full stop) will normally not be included within this
57 /// right-to-left section.
58 ///
59 /// This uses Unicode TR9 HL1 to set an explicit paragraph embedding level of 0.
60 Ltr = 0,
61 /// The base text direction is right-to-left
62 ///
63 /// If the text contains left-to-right content, this will be considered an
64 /// embedded left-to-right run. Non-directional leading and trailing
65 /// characters (e.g. a full stop) will normally not be included within this
66 /// left-to-right section.
67 ///
68 /// This uses Unicode TR9 HL1 to set an explicit paragraph embedding level of 1.
69 Rtl = 1,
70}