mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Move font-variant-east-asian outside of mako
This commit is contained in:
parent
c18417db5e
commit
c110c8a131
7 changed files with 270 additions and 148 deletions
|
@ -690,152 +690,14 @@ macro_rules! exclusive_value {
|
|||
}
|
||||
}
|
||||
|
||||
<%helpers:longhand name="font-variant-east-asian" products="gecko" animation_value_type="discrete"
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-east-asian">
|
||||
use properties::longhands::system_font::SystemFont;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
|
||||
bitflags! {
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct VariantEastAsian: u16 {
|
||||
const NORMAL = 0;
|
||||
const JIS78 = 0x01;
|
||||
const JIS83 = 0x02;
|
||||
const JIS90 = 0x04;
|
||||
const JIS04 = 0x08;
|
||||
const SIMPLIFIED = 0x10;
|
||||
const TRADITIONAL = 0x20;
|
||||
const FULL_WIDTH = 0x40;
|
||||
const PROPORTIONAL_WIDTH = 0x80;
|
||||
const RUBY = 0x100;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||
pub enum SpecifiedValue {
|
||||
Value(VariantEastAsian),
|
||||
System(SystemFont)
|
||||
}
|
||||
|
||||
<%self:simple_system_boilerplate name="font_variant_east_asian"></%self:simple_system_boilerplate>
|
||||
|
||||
// servo_bit: gecko_bit
|
||||
<% font_variant_east_asian_map = { "VariantEastAsian::JIS78": "JIS78",
|
||||
"VariantEastAsian::JIS83": "JIS83",
|
||||
"VariantEastAsian::JIS90": "JIS90",
|
||||
"VariantEastAsian::JIS04": "JIS04",
|
||||
"VariantEastAsian::SIMPLIFIED": "SIMPLIFIED",
|
||||
"VariantEastAsian::TRADITIONAL": "TRADITIONAL",
|
||||
"VariantEastAsian::FULL_WIDTH": "FULL_WIDTH",
|
||||
"VariantEastAsian::PROPORTIONAL_WIDTH": "PROP_WIDTH",
|
||||
"VariantEastAsian::RUBY": "RUBY" } %>
|
||||
|
||||
${helpers.gecko_bitflags_conversion(font_variant_east_asian_map, 'NS_FONT_VARIANT_EAST_ASIAN_',
|
||||
'VariantEastAsian', kw_type='u16')}
|
||||
|
||||
|
||||
impl ToCss for VariantEastAsian {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if self.is_empty() {
|
||||
return dest.write_str("normal")
|
||||
}
|
||||
|
||||
let mut has_any = false;
|
||||
|
||||
macro_rules! write_value {
|
||||
($ident:path => $str:expr) => {
|
||||
if self.intersects($ident) {
|
||||
if has_any {
|
||||
dest.write_str(" ")?;
|
||||
}
|
||||
has_any = true;
|
||||
dest.write_str($str)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
write_value!(VariantEastAsian::JIS78 => "jis78");
|
||||
write_value!(VariantEastAsian::JIS83 => "jis83");
|
||||
write_value!(VariantEastAsian::JIS90 => "jis90");
|
||||
write_value!(VariantEastAsian::JIS04 => "jis04");
|
||||
write_value!(VariantEastAsian::SIMPLIFIED => "simplified");
|
||||
write_value!(VariantEastAsian::TRADITIONAL => "traditional");
|
||||
write_value!(VariantEastAsian::FULL_WIDTH => "full-width");
|
||||
write_value!(VariantEastAsian::PROPORTIONAL_WIDTH => "proportional-width");
|
||||
write_value!(VariantEastAsian::RUBY => "ruby");
|
||||
|
||||
debug_assert!(has_any);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = super::VariantEastAsian;
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::empty()
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
SpecifiedValue::Value(VariantEastAsian::empty())
|
||||
}
|
||||
|
||||
/// normal | [ <east-asian-variant-values> || <east-asian-width-values> || ruby ]
|
||||
/// <east-asian-variant-values> = [ jis78 | jis83 | jis90 | jis04 | simplified | traditional ]
|
||||
/// <east-asian-width-values> = [ full-width | proportional-width ]
|
||||
<% east_asian_variant_values = """VariantEastAsian::JIS78 | VariantEastAsian::JIS83 |
|
||||
VariantEastAsian::JIS90 | VariantEastAsian::JIS04 |
|
||||
VariantEastAsian::SIMPLIFIED | VariantEastAsian::TRADITIONAL""" %>
|
||||
<% east_asian_width_values = "VariantEastAsian::FULL_WIDTH | VariantEastAsian::PROPORTIONAL_WIDTH" %>
|
||||
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
let mut result = VariantEastAsian::empty();
|
||||
|
||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||
return Ok(SpecifiedValue::Value(result))
|
||||
}
|
||||
|
||||
while let Ok(flag) = input.try(|input| {
|
||||
Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
|
||||
"jis78" =>
|
||||
exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::JIS78),
|
||||
"jis83" =>
|
||||
exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::JIS83),
|
||||
"jis90" =>
|
||||
exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::JIS90),
|
||||
"jis04" =>
|
||||
exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::JIS04),
|
||||
"simplified" =>
|
||||
exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::SIMPLIFIED),
|
||||
"traditional" =>
|
||||
exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::TRADITIONAL),
|
||||
"full-width" =>
|
||||
exclusive_value!((result, ${east_asian_width_values}) => VariantEastAsian::FULL_WIDTH),
|
||||
"proportional-width" =>
|
||||
exclusive_value!((result, ${east_asian_width_values}) => VariantEastAsian::PROPORTIONAL_WIDTH),
|
||||
"ruby" =>
|
||||
exclusive_value!((result, VariantEastAsian::RUBY) => VariantEastAsian::RUBY),
|
||||
_ => return Err(()),
|
||||
})
|
||||
}) {
|
||||
result.insert(flag);
|
||||
}
|
||||
|
||||
if !result.is_empty() {
|
||||
Ok(SpecifiedValue::Value(result))
|
||||
} else {
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl_gecko_keyword_conversions!(VariantEastAsian, u16);
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type("font-variant-east-asian",
|
||||
"FontVariantEastAsian",
|
||||
products="gecko",
|
||||
initial_value="computed::FontVariantEastAsian::empty()",
|
||||
initial_specified_value="specified::FontVariantEastAsian::empty()",
|
||||
animation_value_type="discrete",
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-east-asian")}
|
||||
|
||||
<%helpers:longhand name="font-variant-ligatures" products="gecko" animation_value_type="discrete"
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue