mirror of
https://github.com/servo/servo.git
synced 2025-07-03 21:43:41 +01:00
style: Use unified lists to impl several bitflag font-variant properties.
This also changes their ToCss impl to use SequenceWriter instead of checking has_value manually. SpecifiedValueInfo for those types are also implemented in this patch. Bug: 1434130 Reviewed-by: emilio MozReview-Commit-ID: 23h2VWS417H
This commit is contained in:
parent
eb554044db
commit
54d8863e60
1 changed files with 227 additions and 278 deletions
|
@ -1275,33 +1275,84 @@ impl Parse for FontVariantAlternates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
macro_rules! impl_variant_east_asian {
|
||||||
#[derive(MallocSizeOf)]
|
{
|
||||||
/// Vairants for east asian variant
|
$(
|
||||||
pub struct VariantEastAsian: u16 {
|
$(#[$($meta:tt)+])*
|
||||||
/// None of the features
|
$ident:ident / $css:expr => $gecko:ident = $value:expr,
|
||||||
const NORMAL = 0;
|
)+
|
||||||
/// Enables rendering of JIS78 forms (OpenType feature: jp78)
|
} => {
|
||||||
const JIS78 = 0x01;
|
bitflags! {
|
||||||
/// Enables rendering of JIS83 forms (OpenType feature: jp83).
|
#[derive(MallocSizeOf)]
|
||||||
const JIS83 = 0x02;
|
/// Vairants for east asian variant
|
||||||
/// Enables rendering of JIS90 forms (OpenType feature: jp90).
|
pub struct VariantEastAsian: u16 {
|
||||||
const JIS90 = 0x04;
|
/// None of the features
|
||||||
/// Enables rendering of JIS2004 forms (OpenType feature: jp04).
|
const NORMAL = 0;
|
||||||
const JIS04 = 0x08;
|
$(
|
||||||
/// Enables rendering of simplified forms (OpenType feature: smpl).
|
$(#[$($meta)+])*
|
||||||
const SIMPLIFIED = 0x10;
|
const $ident = $value;
|
||||||
/// Enables rendering of traditional forms (OpenType feature: trad).
|
)+
|
||||||
const TRADITIONAL = 0x20;
|
}
|
||||||
/// Enables rendering of full-width variants (OpenType feature: fwid).
|
}
|
||||||
const FULL_WIDTH = 0x40;
|
|
||||||
/// Enables rendering of proportionally-spaced variants (OpenType feature: pwid).
|
impl ToCss for VariantEastAsian {
|
||||||
const PROPORTIONAL_WIDTH = 0x80;
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
/// Enables display of ruby variant glyphs (OpenType feature: ruby).
|
where
|
||||||
const RUBY = 0x100;
|
W: Write,
|
||||||
|
{
|
||||||
|
if self.is_empty() {
|
||||||
|
return dest.write_str("normal");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut writer = SequenceWriter::new(dest, " ");
|
||||||
|
$(
|
||||||
|
if self.intersects(VariantEastAsian::$ident) {
|
||||||
|
writer.raw_item($css)?;
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Asserts that all variant-east-asian matches its NS_FONT_VARIANT_EAST_ASIAN_* value.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
#[inline]
|
||||||
|
pub fn assert_variant_east_asian_matches() {
|
||||||
|
use gecko_bindings::structs;
|
||||||
|
$(
|
||||||
|
debug_assert_eq!(structs::$gecko as u16, VariantEastAsian::$ident.bits());
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for VariantEastAsian {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&["normal", $($css,)+]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_variant_east_asian! {
|
||||||
|
/// Enables rendering of JIS78 forms (OpenType feature: jp78)
|
||||||
|
JIS78 / "jis78" => NS_FONT_VARIANT_EAST_ASIAN_JIS78 = 0x01,
|
||||||
|
/// Enables rendering of JIS83 forms (OpenType feature: jp83).
|
||||||
|
JIS83 / "jis83" => NS_FONT_VARIANT_EAST_ASIAN_JIS83 = 0x02,
|
||||||
|
/// Enables rendering of JIS90 forms (OpenType feature: jp90).
|
||||||
|
JIS90 / "jis90" => NS_FONT_VARIANT_EAST_ASIAN_JIS90 = 0x04,
|
||||||
|
/// Enables rendering of JIS2004 forms (OpenType feature: jp04).
|
||||||
|
JIS04 / "jis04" => NS_FONT_VARIANT_EAST_ASIAN_JIS04 = 0x08,
|
||||||
|
/// Enables rendering of simplified forms (OpenType feature: smpl).
|
||||||
|
SIMPLIFIED / "simplified" => NS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED = 0x10,
|
||||||
|
/// Enables rendering of traditional forms (OpenType feature: trad).
|
||||||
|
TRADITIONAL / "traditional" => NS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL = 0x20,
|
||||||
|
/// Enables rendering of full-width variants (OpenType feature: fwid).
|
||||||
|
FULL_WIDTH / "full-width" => NS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH = 0x40,
|
||||||
|
/// Enables rendering of proportionally-spaced variants (OpenType feature: pwid).
|
||||||
|
PROPORTIONAL_WIDTH / "proportional-width" => NS_FONT_VARIANT_EAST_ASIAN_PROP_WIDTH = 0x80,
|
||||||
|
/// Enables display of ruby variant glyphs (OpenType feature: ruby).
|
||||||
|
RUBY / "ruby" => NS_FONT_VARIANT_EAST_ASIAN_RUBY = 0x100,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl VariantEastAsian {
|
impl VariantEastAsian {
|
||||||
/// Obtain a specified value from a Gecko keyword value
|
/// Obtain a specified value from a Gecko keyword value
|
||||||
|
@ -1317,78 +1368,9 @@ impl VariantEastAsian {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for VariantEastAsian {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: 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(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl_gecko_keyword_conversions!(VariantEastAsian, u16);
|
impl_gecko_keyword_conversions!(VariantEastAsian, u16);
|
||||||
|
|
||||||
impl SpecifiedValueInfo for VariantEastAsian {}
|
|
||||||
|
|
||||||
/// Asserts that all variant-east-asian matches its NS_FONT_VARIANT_EAST_ASIAN_* value.
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
#[inline]
|
|
||||||
pub fn assert_variant_east_asian_matches() {
|
|
||||||
use gecko_bindings::structs;
|
|
||||||
|
|
||||||
macro_rules! check_variant_east_asian {
|
|
||||||
( $( $a:ident => $b:path),*, ) => {
|
|
||||||
if cfg!(debug_assertions) {
|
|
||||||
$(
|
|
||||||
assert_eq!(structs::$a as u16, $b.bits());
|
|
||||||
)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
check_variant_east_asian! {
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH => VariantEastAsian::FULL_WIDTH,
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_JIS04 => VariantEastAsian::JIS04,
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_JIS78 => VariantEastAsian::JIS78,
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_JIS83 => VariantEastAsian::JIS83,
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_JIS90 => VariantEastAsian::JIS90,
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_PROP_WIDTH => VariantEastAsian::PROPORTIONAL_WIDTH,
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_RUBY => VariantEastAsian::RUBY,
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED => VariantEastAsian::SIMPLIFIED,
|
|
||||||
NS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL => VariantEastAsian::TRADITIONAL,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[derive(Clone, Debug, PartialEq, SpecifiedValueInfo, ToCss)]
|
#[derive(Clone, Debug, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||||
/// Allows control of glyph substitution and sizing in East Asian text.
|
/// Allows control of glyph substitution and sizing in East Asian text.
|
||||||
|
@ -1500,34 +1482,88 @@ impl Parse for FontVariantEastAsian {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
macro_rules! impl_variant_ligatures {
|
||||||
#[derive(MallocSizeOf)]
|
{
|
||||||
/// Variants of ligatures
|
$(
|
||||||
pub struct VariantLigatures: u16 {
|
$(#[$($meta:tt)+])*
|
||||||
/// Specifies that common default features are enabled
|
$ident:ident / $css:expr => $gecko:ident = $value:expr,
|
||||||
const NORMAL = 0;
|
)+
|
||||||
/// Specifies that all types of ligatures and contextual forms
|
} => {
|
||||||
/// covered by this property are explicitly disabled
|
bitflags! {
|
||||||
const NONE = 0x01;
|
#[derive(MallocSizeOf)]
|
||||||
/// Enables display of common ligatures
|
/// Variants of ligatures
|
||||||
const COMMON_LIGATURES = 0x02;
|
pub struct VariantLigatures: u16 {
|
||||||
/// Disables display of common ligatures
|
/// Specifies that common default features are enabled
|
||||||
const NO_COMMON_LIGATURES = 0x04;
|
const NORMAL = 0;
|
||||||
/// Enables display of discretionary ligatures
|
$(
|
||||||
const DISCRETIONARY_LIGATURES = 0x08;
|
$(#[$($meta)+])*
|
||||||
/// Disables display of discretionary ligatures
|
const $ident = $value;
|
||||||
const NO_DISCRETIONARY_LIGATURES = 0x10;
|
)+
|
||||||
/// Enables display of historical ligatures
|
}
|
||||||
const HISTORICAL_LIGATURES = 0x20;
|
}
|
||||||
/// Disables display of historical ligatures
|
|
||||||
const NO_HISTORICAL_LIGATURES = 0x40;
|
impl ToCss for VariantLigatures {
|
||||||
/// Enables display of contextual alternates
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
const CONTEXTUAL = 0x80;
|
where
|
||||||
/// Disables display of contextual alternates
|
W: Write,
|
||||||
const NO_CONTEXTUAL = 0x100;
|
{
|
||||||
|
if self.is_empty() {
|
||||||
|
return dest.write_str("normal");
|
||||||
|
}
|
||||||
|
if self.contains(VariantLigatures::NONE) {
|
||||||
|
return dest.write_str("none");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut writer = SequenceWriter::new(dest, " ");
|
||||||
|
$(
|
||||||
|
if self.intersects(VariantLigatures::$ident) {
|
||||||
|
writer.raw_item($css)?;
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Asserts that all variant-east-asian matches its NS_FONT_VARIANT_EAST_ASIAN_* value.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
#[inline]
|
||||||
|
pub fn assert_variant_ligatures_matches() {
|
||||||
|
use gecko_bindings::structs;
|
||||||
|
$(
|
||||||
|
debug_assert_eq!(structs::$gecko as u16, VariantLigatures::$ident.bits());
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for VariantLigatures {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&["normal", $($css,)+]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_variant_ligatures! {
|
||||||
|
/// Specifies that all types of ligatures and contextual forms
|
||||||
|
/// covered by this property are explicitly disabled
|
||||||
|
NONE / "none" => NS_FONT_VARIANT_LIGATURES_NONE = 0x01,
|
||||||
|
/// Enables display of common ligatures
|
||||||
|
COMMON_LIGATURES / "common-ligatures" => NS_FONT_VARIANT_LIGATURES_COMMON = 0x02,
|
||||||
|
/// Disables display of common ligatures
|
||||||
|
NO_COMMON_LIGATURES / "no-common-ligatures" => NS_FONT_VARIANT_LIGATURES_NO_COMMON = 0x04,
|
||||||
|
/// Enables display of discretionary ligatures
|
||||||
|
DISCRETIONARY_LIGATURES / "discretionary-ligatures" => NS_FONT_VARIANT_LIGATURES_DISCRETIONARY = 0x08,
|
||||||
|
/// Disables display of discretionary ligatures
|
||||||
|
NO_DISCRETIONARY_LIGATURES / "no-discretionary-ligatures" => NS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY = 0x10,
|
||||||
|
/// Enables display of historical ligatures
|
||||||
|
HISTORICAL_LIGATURES / "historical-ligatures" => NS_FONT_VARIANT_LIGATURES_HISTORICAL = 0x20,
|
||||||
|
/// Disables display of historical ligatures
|
||||||
|
NO_HISTORICAL_LIGATURES / "no-historical-ligatures" => NS_FONT_VARIANT_LIGATURES_NO_HISTORICAL = 0x40,
|
||||||
|
/// Enables display of contextual alternates
|
||||||
|
CONTEXTUAL / "contextual" => NS_FONT_VARIANT_LIGATURES_CONTEXTUAL = 0x80,
|
||||||
|
/// Disables display of contextual alternates
|
||||||
|
NO_CONTEXTUAL / "no-contextual" => NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL = 0x100,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl VariantLigatures {
|
impl VariantLigatures {
|
||||||
/// Obtain a specified value from a Gecko keyword value
|
/// Obtain a specified value from a Gecko keyword value
|
||||||
|
@ -1543,80 +1579,9 @@ impl VariantLigatures {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for VariantLigatures {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
if self.is_empty() {
|
|
||||||
return dest.write_str("normal");
|
|
||||||
}
|
|
||||||
if self.contains(VariantLigatures::NONE) {
|
|
||||||
return dest.write_str("none");
|
|
||||||
}
|
|
||||||
|
|
||||||
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!(VariantLigatures::COMMON_LIGATURES => "common-ligatures");
|
|
||||||
write_value!(VariantLigatures::NO_COMMON_LIGATURES => "no-common-ligatures");
|
|
||||||
write_value!(VariantLigatures::DISCRETIONARY_LIGATURES => "discretionary-ligatures");
|
|
||||||
write_value!(VariantLigatures::NO_DISCRETIONARY_LIGATURES => "no-discretionary-ligatures");
|
|
||||||
write_value!(VariantLigatures::HISTORICAL_LIGATURES => "historical-ligatures");
|
|
||||||
write_value!(VariantLigatures::NO_HISTORICAL_LIGATURES => "no-historical-ligatures");
|
|
||||||
write_value!(VariantLigatures::CONTEXTUAL => "contextual");
|
|
||||||
write_value!(VariantLigatures::NO_CONTEXTUAL => "no-contextual");
|
|
||||||
|
|
||||||
debug_assert!(has_any);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SpecifiedValueInfo for VariantLigatures {}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl_gecko_keyword_conversions!(VariantLigatures, u16);
|
impl_gecko_keyword_conversions!(VariantLigatures, u16);
|
||||||
|
|
||||||
/// Asserts that all variant-east-asian matches its NS_FONT_VARIANT_EAST_ASIAN_* value.
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
#[inline]
|
|
||||||
pub fn assert_variant_ligatures_matches() {
|
|
||||||
use gecko_bindings::structs;
|
|
||||||
|
|
||||||
macro_rules! check_variant_ligatures {
|
|
||||||
( $( $a:ident => $b:path),*, ) => {
|
|
||||||
if cfg!(debug_assertions) {
|
|
||||||
$(
|
|
||||||
assert_eq!(structs::$a as u16, $b.bits());
|
|
||||||
)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
check_variant_ligatures! {
|
|
||||||
NS_FONT_VARIANT_LIGATURES_NONE => VariantLigatures::NONE,
|
|
||||||
NS_FONT_VARIANT_LIGATURES_COMMON => VariantLigatures::COMMON_LIGATURES,
|
|
||||||
NS_FONT_VARIANT_LIGATURES_NO_COMMON => VariantLigatures::NO_COMMON_LIGATURES,
|
|
||||||
NS_FONT_VARIANT_LIGATURES_DISCRETIONARY => VariantLigatures::DISCRETIONARY_LIGATURES,
|
|
||||||
NS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY => VariantLigatures::NO_DISCRETIONARY_LIGATURES,
|
|
||||||
NS_FONT_VARIANT_LIGATURES_HISTORICAL => VariantLigatures::HISTORICAL_LIGATURES,
|
|
||||||
NS_FONT_VARIANT_LIGATURES_NO_HISTORICAL => VariantLigatures::NO_HISTORICAL_LIGATURES,
|
|
||||||
NS_FONT_VARIANT_LIGATURES_CONTEXTUAL => VariantLigatures::CONTEXTUAL,
|
|
||||||
NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL => VariantLigatures::NO_CONTEXTUAL,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[derive(Clone, Debug, PartialEq, SpecifiedValueInfo, ToCss)]
|
#[derive(Clone, Debug, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||||
/// Ligatures and contextual forms are ways of combining glyphs
|
/// Ligatures and contextual forms are ways of combining glyphs
|
||||||
|
@ -1739,31 +1704,82 @@ impl Parse for FontVariantLigatures {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
macro_rules! impl_variant_numeric {
|
||||||
#[derive(MallocSizeOf)]
|
{
|
||||||
/// Vairants of numeric values
|
$(
|
||||||
pub struct VariantNumeric: u8 {
|
$(#[$($meta:tt)+])*
|
||||||
/// None of other variants are enabled.
|
$ident:ident / $css:expr => $gecko:ident = $value:expr,
|
||||||
const NORMAL = 0;
|
)+
|
||||||
/// Enables display of lining numerals.
|
} => {
|
||||||
const LINING_NUMS = 0x01;
|
bitflags! {
|
||||||
/// Enables display of old-style numerals.
|
#[derive(MallocSizeOf)]
|
||||||
const OLDSTYLE_NUMS = 0x02;
|
/// Vairants of numeric values
|
||||||
/// Enables display of proportional numerals.
|
pub struct VariantNumeric: u8 {
|
||||||
const PROPORTIONAL_NUMS = 0x04;
|
/// None of other variants are enabled.
|
||||||
/// Enables display of tabular numerals.
|
const NORMAL = 0;
|
||||||
const TABULAR_NUMS = 0x08;
|
$(
|
||||||
/// Enables display of lining diagonal fractions.
|
$(#[$($meta)+])*
|
||||||
const DIAGONAL_FRACTIONS = 0x10;
|
const $ident = $value;
|
||||||
/// Enables display of lining stacked fractions.
|
)+
|
||||||
const STACKED_FRACTIONS = 0x20;
|
}
|
||||||
/// Enables display of letter forms used with ordinal numbers.
|
}
|
||||||
const ORDINAL = 0x80;
|
|
||||||
/// Enables display of slashed zeros.
|
impl ToCss for VariantNumeric {
|
||||||
const SLASHED_ZERO = 0x40;
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: Write,
|
||||||
|
{
|
||||||
|
if self.is_empty() {
|
||||||
|
return dest.write_str("normal");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut writer = SequenceWriter::new(dest, " ");
|
||||||
|
$(
|
||||||
|
if self.intersects(VariantNumeric::$ident) {
|
||||||
|
writer.raw_item($css)?;
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Asserts that all variant-east-asian matches its NS_FONT_VARIANT_EAST_ASIAN_* value.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
#[inline]
|
||||||
|
pub fn assert_variant_numeric_matches() {
|
||||||
|
use gecko_bindings::structs;
|
||||||
|
$(
|
||||||
|
debug_assert_eq!(structs::$gecko as u8, VariantNumeric::$ident.bits());
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for VariantNumeric {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&["normal", $($css,)+]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_variant_numeric! {
|
||||||
|
/// Enables display of lining numerals.
|
||||||
|
LINING_NUMS / "lining-nums" => NS_FONT_VARIANT_NUMERIC_LINING = 0x01,
|
||||||
|
/// Enables display of old-style numerals.
|
||||||
|
OLDSTYLE_NUMS / "oldstyle-nums" => NS_FONT_VARIANT_NUMERIC_OLDSTYLE = 0x02,
|
||||||
|
/// Enables display of proportional numerals.
|
||||||
|
PROPORTIONAL_NUMS / "proportional-nums" => NS_FONT_VARIANT_NUMERIC_PROPORTIONAL = 0x04,
|
||||||
|
/// Enables display of tabular numerals.
|
||||||
|
TABULAR_NUMS / "tabular-nums" => NS_FONT_VARIANT_NUMERIC_TABULAR = 0x08,
|
||||||
|
/// Enables display of lining diagonal fractions.
|
||||||
|
DIAGONAL_FRACTIONS / "diagonal-fractions" => NS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS = 0x10,
|
||||||
|
/// Enables display of lining stacked fractions.
|
||||||
|
STACKED_FRACTIONS / "stacked-fractions" => NS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS = 0x20,
|
||||||
|
/// Enables display of letter forms used with ordinal numbers.
|
||||||
|
ORDINAL / "ordinal" => NS_FONT_VARIANT_NUMERIC_ORDINAL = 0x80,
|
||||||
|
/// Enables display of slashed zeros.
|
||||||
|
SLASHED_ZERO / "slashed-zero" => NS_FONT_VARIANT_NUMERIC_SLASHZERO = 0x40,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl VariantNumeric {
|
impl VariantNumeric {
|
||||||
/// Obtain a specified value from a Gecko keyword value
|
/// Obtain a specified value from a Gecko keyword value
|
||||||
|
@ -1779,76 +1795,9 @@ impl VariantNumeric {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for VariantNumeric {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: 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!(VariantNumeric::LINING_NUMS => "lining-nums");
|
|
||||||
write_value!(VariantNumeric::OLDSTYLE_NUMS => "oldstyle-nums");
|
|
||||||
write_value!(VariantNumeric::PROPORTIONAL_NUMS => "proportional-nums");
|
|
||||||
write_value!(VariantNumeric::TABULAR_NUMS => "tabular-nums");
|
|
||||||
write_value!(VariantNumeric::DIAGONAL_FRACTIONS => "diagonal-fractions");
|
|
||||||
write_value!(VariantNumeric::STACKED_FRACTIONS => "stacked-fractions");
|
|
||||||
write_value!(VariantNumeric::SLASHED_ZERO => "slashed-zero");
|
|
||||||
write_value!(VariantNumeric::ORDINAL => "ordinal");
|
|
||||||
|
|
||||||
debug_assert!(has_any);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SpecifiedValueInfo for VariantNumeric {}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl_gecko_keyword_conversions!(VariantNumeric, u8);
|
impl_gecko_keyword_conversions!(VariantNumeric, u8);
|
||||||
|
|
||||||
/// Asserts that all variant-east-asian matches its NS_FONT_VARIANT_EAST_ASIAN_* value.
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
#[inline]
|
|
||||||
pub fn assert_variant_numeric_matches() {
|
|
||||||
use gecko_bindings::structs;
|
|
||||||
|
|
||||||
macro_rules! check_variant_numeric {
|
|
||||||
( $( $a:ident => $b:path),*, ) => {
|
|
||||||
if cfg!(debug_assertions) {
|
|
||||||
$(
|
|
||||||
assert_eq!(structs::$a as u8, $b.bits());
|
|
||||||
)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
check_variant_numeric! {
|
|
||||||
NS_FONT_VARIANT_NUMERIC_LINING => VariantNumeric::LINING_NUMS,
|
|
||||||
NS_FONT_VARIANT_NUMERIC_OLDSTYLE => VariantNumeric::OLDSTYLE_NUMS,
|
|
||||||
NS_FONT_VARIANT_NUMERIC_PROPORTIONAL => VariantNumeric::PROPORTIONAL_NUMS,
|
|
||||||
NS_FONT_VARIANT_NUMERIC_TABULAR => VariantNumeric::TABULAR_NUMS,
|
|
||||||
NS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS => VariantNumeric::DIAGONAL_FRACTIONS,
|
|
||||||
NS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS => VariantNumeric::STACKED_FRACTIONS,
|
|
||||||
NS_FONT_VARIANT_NUMERIC_SLASHZERO => VariantNumeric::SLASHED_ZERO,
|
|
||||||
NS_FONT_VARIANT_NUMERIC_ORDINAL => VariantNumeric::ORDINAL,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[derive(Clone, Debug, PartialEq, SpecifiedValueInfo, ToCss)]
|
#[derive(Clone, Debug, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||||
/// Specifies control over numerical forms.
|
/// Specifies control over numerical forms.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue