Skip to content
Permalink
Browse files

style: Make font-variant-alternates use cbindgen.

  • Loading branch information...
emilio committed Aug 21, 2019
1 parent b8108ea commit 7c4dc9e79728e5ae212d3d1effa8f7df4330d51f
@@ -1247,6 +1247,8 @@ fn static_assert() {

${impl_simple_type_with_conversion("font_synthesis", "mFont.synthesis")}

${impl_simple("font_variant_alternates", "mFont.variantAlternates")}

pub fn set_font_size_adjust(&mut self, v: longhands::font_size_adjust::computed_value::T) {
use crate::properties::longhands::font_size_adjust::computed_value::T;
match v {
@@ -1319,122 +1321,6 @@ fn static_assert() {
${impl_simple("_moz_script_level", "mScriptLevel")}
<% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %>

pub fn set_font_variant_alternates(
&mut self,
v: values::computed::font::FontVariantAlternates,
) {
use crate::gecko_bindings::bindings::{Gecko_ClearAlternateValues, Gecko_AppendAlternateValues};
% for value in "normal swash stylistic ornaments annotation styleset character_variant historical".split():
use crate::gecko_bindings::structs::NS_FONT_VARIANT_ALTERNATES_${value.upper()};
% endfor
use crate::values::specified::font::VariantAlternates;

unsafe {
Gecko_ClearAlternateValues(&mut self.gecko.mFont, v.len());
}

if v.0.is_empty() {
self.gecko.mFont.variantAlternates = NS_FONT_VARIANT_ALTERNATES_NORMAL as u16;
return;
}

for val in v.0.iter() {
match *val {
% for value in "Swash Stylistic Ornaments Annotation".split():
VariantAlternates::${value}(ref ident) => {
self.gecko.mFont.variantAlternates |= NS_FONT_VARIANT_ALTERNATES_${value.upper()} as u16;
unsafe {
Gecko_AppendAlternateValues(&mut self.gecko.mFont,
NS_FONT_VARIANT_ALTERNATES_${value.upper()},
ident.0.as_ptr());
}
},
% endfor
% for value in "styleset character_variant".split():
VariantAlternates::${to_camel_case(value)}(ref slice) => {
self.gecko.mFont.variantAlternates |= NS_FONT_VARIANT_ALTERNATES_${value.upper()} as u16;
for ident in slice.iter() {
unsafe {
Gecko_AppendAlternateValues(&mut self.gecko.mFont,
NS_FONT_VARIANT_ALTERNATES_${value.upper()},
ident.0.as_ptr());
}
}
},
% endfor
VariantAlternates::HistoricalForms => {
self.gecko.mFont.variantAlternates |= NS_FONT_VARIANT_ALTERNATES_HISTORICAL as u16;
}
}
}
}

#[allow(non_snake_case)]
pub fn copy_font_variant_alternates_from(&mut self, other: &Self) {
use crate::gecko_bindings::bindings::Gecko_CopyAlternateValuesFrom;

self.gecko.mFont.variantAlternates = other.gecko.mFont.variantAlternates;
unsafe {
Gecko_CopyAlternateValuesFrom(&mut self.gecko.mFont, &other.gecko.mFont);
}
}

pub fn reset_font_variant_alternates(&mut self, other: &Self) {
self.copy_font_variant_alternates_from(other)
}

pub fn clone_font_variant_alternates(&self) -> values::computed::font::FontVariantAlternates {
% for value in "normal swash stylistic ornaments annotation styleset character_variant historical".split():
use crate::gecko_bindings::structs::NS_FONT_VARIANT_ALTERNATES_${value.upper()};
% endfor
use crate::values::specified::font::VariantAlternates;
use crate::values::specified::font::VariantAlternatesList;
use crate::values::CustomIdent;

if self.gecko.mFont.variantAlternates == NS_FONT_VARIANT_ALTERNATES_NORMAL as u16 {
return VariantAlternatesList(vec![].into_boxed_slice());
}

let mut alternates = Vec::with_capacity(self.gecko.mFont.alternateValues.len());
if self.gecko.mFont.variantAlternates & (NS_FONT_VARIANT_ALTERNATES_HISTORICAL as u16) != 0 {
alternates.push(VariantAlternates::HistoricalForms);
}

<%
property_need_ident_list = "styleset character_variant".split()
%>
% for value in property_need_ident_list:
let mut ${value}_list = Vec::new();
% endfor

for gecko_alternate_value in self.gecko.mFont.alternateValues.iter() {
let ident = Atom::from(gecko_alternate_value.value.to_string());
match gecko_alternate_value.alternate {
% for value in "Swash Stylistic Ornaments Annotation".split():
NS_FONT_VARIANT_ALTERNATES_${value.upper()} => {
alternates.push(VariantAlternates::${value}(CustomIdent(ident)));
},
% endfor
% for value in property_need_ident_list:
NS_FONT_VARIANT_ALTERNATES_${value.upper()} => {
${value}_list.push(CustomIdent(ident));
},
% endfor
_ => {
panic!("Found unexpected value for font-variant-alternates");
}
}
}

% for value in property_need_ident_list:
if !${value}_list.is_empty() {
alternates.push(VariantAlternates::${to_camel_case(value)}(${value}_list.into_boxed_slice()));
}
% endfor

VariantAlternatesList(alternates.into_boxed_slice())
}

${impl_simple_type_with_conversion("font_variant_ligatures", "mFont.variantLigatures")}
${impl_simple_type_with_conversion("font_variant_east_asian", "mFont.variantEastAsian")}
${impl_simple_type_with_conversion("font_variant_numeric", "mFont.variantNumeric")}
@@ -644,10 +644,10 @@ impl ToAnimatedValue for FontSizeAdjust {
pub type FontVariantAlternates = specified::VariantAlternatesList;

impl FontVariantAlternates {
#[inline]
/// Get initial value with VariantAlternatesList
#[inline]
pub fn get_initial_value() -> Self {
specified::VariantAlternatesList(vec![].into_boxed_slice())
Self::default()
}
}

@@ -1089,17 +1089,20 @@ bitflags! {
#[derive(
Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToResolvedValue, ToShmem,
)]
#[repr(C, u8)]
/// Set of variant alternates
///
/// cbindgen:derive-tagged-enum-copy-constructor=true
pub enum VariantAlternates {
/// Enables display of stylistic alternates
#[css(function)]
Stylistic(CustomIdent),
/// Enables display with stylistic sets
#[css(comma, function)]
Styleset(#[css(iterable)] Box<[CustomIdent]>),
Styleset(#[css(iterable)] crate::OwnedSlice<CustomIdent>),
/// Enables display of specific character variants
#[css(comma, function)]
CharacterVariant(#[css(iterable)] Box<[CustomIdent]>),
CharacterVariant(#[css(iterable)] crate::OwnedSlice<CustomIdent>),
/// Enables display of swash glyphs
#[css(function)]
Swash(CustomIdent),
@@ -1114,11 +1117,12 @@ pub enum VariantAlternates {
}

#[derive(
Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToResolvedValue, ToShmem,
Clone, Debug, Default, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToResolvedValue, ToShmem,
)]
#[repr(transparent)]
/// List of Variant Alternates
pub struct VariantAlternatesList(
#[css(if_empty = "normal", iterable)] pub Box<[VariantAlternates]>,
#[css(if_empty = "normal", iterable)] crate::OwnedSlice<VariantAlternates>,
);

impl VariantAlternatesList {
@@ -1150,7 +1154,7 @@ impl FontVariantAlternates {
#[inline]
/// Get initial specified value with VariantAlternatesList
pub fn get_initial_specified_value() -> Self {
FontVariantAlternates::Value(VariantAlternatesList(vec![].into_boxed_slice()))
FontVariantAlternates::Value(Default::default())
}

system_font_methods!(FontVariantAlternates, font_variant_alternates);
@@ -1184,16 +1188,14 @@ impl Parse for FontVariantAlternates {
_: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<FontVariantAlternates, ParseError<'i>> {
let mut alternates = Vec::new();
if input
.try(|input| input.expect_ident_matching("normal"))
.is_ok()
{
return Ok(FontVariantAlternates::Value(VariantAlternatesList(
alternates.into_boxed_slice(),
)));
return Ok(FontVariantAlternates::Value(Default::default()))
}

let mut alternates = Vec::new();
let mut parsed_alternates = VariantAlternatesParsingFlags::empty();
macro_rules! check_if_parsed(
($input:expr, $flag:path) => (
@@ -1247,7 +1249,7 @@ impl Parse for FontVariantAlternates {
let location = i.current_source_location();
CustomIdent::from_ident(location, i.expect_ident()?, &[])
})?;
alternates.push(VariantAlternates::Styleset(idents.into_boxed_slice()));
alternates.push(VariantAlternates::Styleset(idents.into()));
Ok(())
},
"character-variant" => {
@@ -1256,7 +1258,7 @@ impl Parse for FontVariantAlternates {
let location = i.current_source_location();
CustomIdent::from_ident(location, i.expect_ident()?, &[])
})?;
alternates.push(VariantAlternates::CharacterVariant(idents.into_boxed_slice()));
alternates.push(VariantAlternates::CharacterVariant(idents.into()));
Ok(())
},
_ => return Err(i.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
@@ -1270,7 +1272,7 @@ impl Parse for FontVariantAlternates {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(FontVariantAlternates::Value(VariantAlternatesList(
alternates.into_boxed_slice(),
alternates.into(),
)))
}
}

0 comments on commit 7c4dc9e

Please sign in to comment.
You can’t perform that action at this time.