AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.

Home Page:https://anglesharp.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AngleSharp.CSS to extract fontfamily does not work

ghisbo opened this issue · comments

I try to extract the font family name of a css source.
When looking in debug mode, the font family name is present.
Also when i modify it by a SetFontFamily, in debug mode i can see the font-family value.

The GetFontFamiliy however does not return anything.

example code:

public void CssStyleSheettractFontFamily()
    {
        var parser = new CssParser();
        var source = "<!-- body { font-family: Verdana } div.hidden { display: none } -->";
        ICssStyleSheet sheet = parser.ParseStyleSheet(source);

        Debug.Print( sheet.Rules.Length.ToString());

        foreach (ICssStyleRule rule in sheet.Rules)
        {
            Debug.Print(rule.CssText);
            rule.Style.SetFontFamily("Verdana Bold");
            Debug.Print("fontfamily", rule.Style.GetFontFamily());
            Debug.Print("fontSize", rule.Style.GetFontSize());
        } 
    }

I tried your code. It all works.

Maybe you just forgot to print it, e.g.:

foreach (ICssStyleRule rule in sheet.Rules)
{
    Debug.Print(rule.CssText);
    rule.Style.SetFontFamily("Verdana Bold");
    Debug.Print("fontfamily {0}", rule.Style.GetFontFamily());
    Debug.Print("fontSize {0}", rule.Style.GetFontSize());
} 

Thank you, i am ashamed to have overlooked this.