/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ //! Specified values for font properties use crate::context::QuirksMode; use crate::parser::{Parse, ParserContext}; use crate::values::computed::font::{FamilyName, FontFamilyList, SingleFontFamily}; use crate::values::computed::Percentage as ComputedPercentage; use crate::values::computed::{font as computed, Length, NonNegativeLength}; use crate::values::computed::{CSSPixelLength, Context, ToComputedValue}; use crate::values::generics::font::VariationValue; use crate::values::generics::font::{ self as generics, FeatureTagValue, FontSettings, FontTag, GenericFontSizeAdjust, }; use crate::values::generics::NonNegative; use crate::values::specified::length::{FontBaseSize, PX_PER_PT}; use crate::values::specified::{AllowQuirks, Angle, Integer, LengthPercentage}; use crate::values::specified::{NoCalcLength, NonNegativeNumber, NonNegativePercentage, Number}; use crate::values::{CustomIdent, SelectorParseErrorKind, serialize_atom_identifier}; use crate::Atom; use cssparser::{Parser, Token}; #[cfg(feature = "gecko")] use malloc_size_of::{MallocSizeOf, MallocSizeOfOps, MallocUnconditionalSizeOf}; use std::fmt::{self, Write}; use style_traits::values::SequenceWriter; use style_traits::{CssWriter, KeywordsCollectFn, ParseError}; use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss}; // FIXME(emilio): The system font code is copy-pasta, and should be cleaned up. macro_rules! system_font_methods { ($ty:ident, $field:ident) => { system_font_methods!($ty); fn compute_system(&self, _context: &Context) -> <$ty as ToComputedValue>::ComputedValue { debug_assert!(matches!(*self, $ty::System(..))); #[cfg(feature = "gecko")] { _context.cached_system_font.as_ref().unwrap().$field.clone() } #[cfg(feature = "servo")] { unreachable!() } } }; ($ty:ident) => { /// Get a specified value that represents a system font. pub fn system_font(f: SystemFont) -> Self { $ty::System(f) } /// Retreive a SystemFont from the specified value. pub fn get_system(&self) -> Option { if let $ty::System(s) = *self { Some(s) } else { None } } }; } /// System fonts. #[repr(u8)] #[derive( Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, )] #[allow(missing_docs)] pub enum SystemFont { /// https://drafts.csswg.org/css-fonts/#valdef-font-caption Caption, /// https://drafts.csswg.org/css-fonts/#valdef-font-icon Icon, /// https://drafts.csswg.org/css-fonts/#valdef-font-menu Menu, /// https://drafts.csswg.org/css-fonts/#valdef-font-message-box MessageBox, /// https://drafts.csswg.org/css-fonts/#valdef-font-small-caption SmallCaption, /// https://drafts.csswg.org/css-fonts/#valdef-font-status-bar StatusBar, /// Internal system font, used by the ``s on macOS. #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] MozPullDownMenu, /// Internal system font, used for `