Skip to content

Commit 60fe8d5

Browse files
committed
feat: add superscript, subscript, small caps, all caps to TextStyle
Add VerticalTextAlign enum (Superscript/Subscript) and all_caps/small_caps fields to TextStyle IR. Parse superscript/subscript from docx-rs vert_align, all_caps from caps field. SmallCaps uses XML pre-scanning since docx-rs doesn't expose w:smallCaps. Render as #super[], #sub[], #smallcaps[], and uppercase text transformation in Typst output. Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
1 parent 22e4b60 commit 60fe8d5

File tree

4 files changed

+344
-12
lines changed

4 files changed

+344
-12
lines changed

crates/office2pdf/src/ir/style.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ pub enum LineSpacing {
5757
Exact(f64),
5858
}
5959

60+
/// Vertical alignment for superscript/subscript text.
61+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
62+
pub enum VerticalTextAlign {
63+
Superscript,
64+
Subscript,
65+
}
66+
6067
/// Character-level formatting.
6168
#[derive(Debug, Clone, Default)]
6269
pub struct TextStyle {
@@ -67,6 +74,12 @@ pub struct TextStyle {
6774
pub underline: Option<bool>,
6875
pub strikethrough: Option<bool>,
6976
pub color: Option<Color>,
77+
/// Superscript or subscript vertical alignment.
78+
pub vertical_align: Option<VerticalTextAlign>,
79+
/// All caps: render text in uppercase.
80+
pub all_caps: Option<bool>,
81+
/// Small caps: render lowercase letters as smaller uppercase.
82+
pub small_caps: Option<bool>,
7083
}
7184

7285
/// RGB color.
@@ -122,4 +135,41 @@ mod tests {
122135
let ss = StyleSheet::default();
123136
assert!(ss.styles.is_empty());
124137
}
138+
139+
#[test]
140+
fn test_text_style_default_has_none_text_effects() {
141+
let ts = TextStyle::default();
142+
assert!(ts.vertical_align.is_none());
143+
assert!(ts.all_caps.is_none());
144+
assert!(ts.small_caps.is_none());
145+
}
146+
147+
#[test]
148+
fn test_text_style_superscript() {
149+
let ts = TextStyle {
150+
vertical_align: Some(VerticalTextAlign::Superscript),
151+
..TextStyle::default()
152+
};
153+
assert_eq!(ts.vertical_align, Some(VerticalTextAlign::Superscript));
154+
}
155+
156+
#[test]
157+
fn test_text_style_subscript() {
158+
let ts = TextStyle {
159+
vertical_align: Some(VerticalTextAlign::Subscript),
160+
..TextStyle::default()
161+
};
162+
assert_eq!(ts.vertical_align, Some(VerticalTextAlign::Subscript));
163+
}
164+
165+
#[test]
166+
fn test_text_style_caps() {
167+
let ts = TextStyle {
168+
all_caps: Some(true),
169+
small_caps: Some(true),
170+
..TextStyle::default()
171+
};
172+
assert_eq!(ts.all_caps, Some(true));
173+
assert_eq!(ts.small_caps, Some(true));
174+
}
125175
}

0 commit comments

Comments
 (0)