style/values/computed/
text.rs1use crate::derives::*;
8use crate::values::computed::length::{Length, LengthPercentage};
9use crate::values::generics::text::{
10 GenericHyphenateLimitChars, GenericInitialLetter, GenericTextDecorationInset,
11 GenericTextDecorationLength, GenericTextIndent,
12};
13use crate::values::generics::NumberOrAuto;
14use crate::values::specified::text as specified;
15use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword};
16use crate::values::{CSSFloat, CSSInteger};
17use crate::Zero;
18use std::fmt::{self, Write};
19use style_traits::{CssString, CssWriter, KeywordValue, ToCss, ToTyped, TypedValue};
20use thin_vec::ThinVec;
21
22pub use crate::values::specified::text::{
23 HyphenateCharacter, LineBreak, MozControlCharacterVisibility, OverflowWrap, RubyPosition,
24 TextAlignLast, TextAutospace, TextBoxEdge, TextBoxTrim, TextDecorationLine,
25 TextDecorationSkipInk, TextEmphasisPosition, TextJustify, TextOverflow, TextTransform,
26 TextUnderlinePosition, WordBreak,
27};
28
29pub type InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
31
32pub type TextDecorationLength = GenericTextDecorationLength<LengthPercentage>;
34
35pub type TextDecorationInset = GenericTextDecorationInset<Length>;
37
38pub type TextAlign = specified::TextAlignKeyword;
40
41pub type TextIndent = GenericTextIndent<LengthPercentage>;
43
44pub type HyphenateLimitChars = GenericHyphenateLimitChars<CSSInteger>;
46
47impl HyphenateLimitChars {
48 #[inline]
50 pub fn auto() -> Self {
51 Self {
52 total_word_length: NumberOrAuto::Auto,
53 pre_hyphen_length: NumberOrAuto::Auto,
54 post_hyphen_length: NumberOrAuto::Auto,
55 }
56 }
57}
58
59#[repr(transparent)]
61#[derive(
62 Animate,
63 Clone,
64 ComputeSquaredDistance,
65 Copy,
66 Debug,
67 MallocSizeOf,
68 PartialEq,
69 ToAnimatedValue,
70 ToAnimatedZero,
71 ToResolvedValue,
72)]
73pub struct GenericLetterSpacing<L>(pub L);
74pub type LetterSpacing = GenericLetterSpacing<LengthPercentage>;
76
77impl LetterSpacing {
78 #[inline]
80 pub fn normal() -> Self {
81 Self(LengthPercentage::zero())
82 }
83}
84
85impl ToCss for LetterSpacing {
86 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
87 where
88 W: Write,
89 {
90 if self.0.is_zero() {
95 return dest.write_str("normal");
96 }
97 self.0.to_css(dest)
98 }
99}
100
101impl ToTyped for LetterSpacing {
102 fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
108 if !self.0.has_percentage() && self.0.is_zero() {
109 dest.push(TypedValue::Keyword(KeywordValue(CssString::from("normal"))));
110 return Ok(());
111 }
112 self.0.to_typed(dest)
113 }
114}
115
116pub type WordSpacing = LengthPercentage;
118
119impl WordSpacing {
120 #[inline]
122 pub fn normal() -> Self {
123 LengthPercentage::zero()
124 }
125}
126
127#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToTyped)]
129#[allow(missing_docs)]
130#[repr(C, u8)]
131pub enum TextEmphasisStyle {
132 Keyword {
134 #[css(skip_if = "TextEmphasisFillMode::is_filled")]
135 fill: TextEmphasisFillMode,
136 shape: TextEmphasisShapeKeyword,
137 },
138 None,
140 String(crate::OwnedStr),
142}