AngleSharp by Florian Rappl

<PackageReference Include="AngleSharp" Version="0.8.5" />

.NET API 1,113,600 bytes

 CssFontFaceRule

Represents the @font-face rule.
using AngleSharp.Css; using AngleSharp.Extensions; using AngleSharp.Parser.Css; namespace AngleSharp.Dom.Css { internal sealed class CssFontFaceRule : CssRule, ICssFontFaceRule, ICssRule { private readonly CssProperty[] _declarations; string ICssFontFaceRule.Family { get { return GetValue(PropertyNames.FontFamily); } set { SetValue(PropertyNames.FontFamily, value); } } string ICssFontFaceRule.Source { get { return GetValue(PropertyNames.Src); } set { SetValue(PropertyNames.Src, value); } } string ICssFontFaceRule.Style { get { return GetValue(PropertyNames.FontStyle); } set { SetValue(PropertyNames.FontStyle, value); } } string ICssFontFaceRule.Weight { get { return GetValue(PropertyNames.FontWeight); } set { SetValue(PropertyNames.FontWeight, value); } } string ICssFontFaceRule.Stretch { get { return GetValue(PropertyNames.FontStretch); } set { SetValue(PropertyNames.FontStretch, value); } } string ICssFontFaceRule.Range { get { return GetValue(PropertyNames.UnicodeRange); } set { SetValue(PropertyNames.UnicodeRange, value); } } string ICssFontFaceRule.Variant { get { return GetValue(PropertyNames.FontVariant); } set { SetValue(PropertyNames.FontVariant, value); } } string ICssFontFaceRule.Features { get { return string.Empty; } set { } } internal CssFontFaceRule() : base(CssRuleType.FontFace) { _declarations = new CssProperty[7] { new CssFontFamilyProperty(), new CssSrcProperty(), new CssFontStyleProperty(), new CssFontWeightProperty(), new CssFontStretchProperty(), new CssUnicodeRangeProperty(), new CssFontVariantProperty() }; } internal void SetProperty(CssProperty property) { int num = 0; while (true) { if (num >= _declarations.Length) return; if (_declarations[num].Name == property.Name) break; num++; } _declarations[num] = property; } protected override void ReplaceWith(ICssRule rule) { CssFontFaceRule cssFontFaceRule = (CssFontFaceRule)rule; for (int i = 0; i < _declarations.Length; i++) { _declarations[i] = cssFontFaceRule._declarations[i]; } } protected override string ToCss() { return "@font-face " + _declarations.ToCssBlock(); } private string GetValue(string propertyName) { CssProperty[] declarations = _declarations; foreach (CssProperty cssProperty in declarations) { if (cssProperty.HasValue && cssProperty.Name == propertyName) return cssProperty.Value; } return string.Empty; } private void SetValue(string propertyName, string valueText) { CssProperty[] declarations = _declarations; int num = 0; CssProperty cssProperty; while (true) { if (num >= declarations.Length) return; cssProperty = declarations[num]; if (cssProperty.Name == propertyName) break; num++; } CssValue newValue = CssParser.ParseValue(valueText, null); cssProperty.TrySetValue(newValue); } } }