示例#1
0
        public static media_query create_from_string(string str, document doc)
        {
            var tokens = new List <string>();

            html.split_string(str, tokens, " \t\r\n", "", "(");

            var query = new media_query();

            for (var i = 0; i < tokens.Count; i++)
            {
                var tok = tokens[i];
                if (tok == "not")
                {
                    query._not = true;
                }
                else if (tok[0] == '(')
                {
                    tok = tok.Substring(1);
                    if (tok[tok.Length - 1] == ')')
                    {
                        tok = tok.Remove(tok.Length - 1, 1);
                    }
                    var expr        = new media_query_expression();
                    var expr_tokens = new List <string>();
                    html.split_string(tok, expr_tokens, ":");
                    if (expr_tokens.Count != 0)
                    {
                        expr_tokens[0] = expr_tokens[0].Trim();
                        expr.feature   = (media_feature)html.value_index(expr_tokens[0], types.media_feature_strings, (int)media_feature.none);
                        if (expr.feature != media_feature.none)
                        {
                            if (expr_tokens.Count == 1)
                            {
                                expr.check_as_bool = true;
                            }
                            else
                            {
                                expr_tokens[1]     = expr_tokens[1].Trim();
                                expr.check_as_bool = false;
                                if (expr.feature == media_feature.orientation)
                                {
                                    expr.val = html.value_index(expr_tokens[1], types.media_orientation_strings, (int)media_orientation.landscape);
                                }
                                else
                                {
                                    var slash_pos = expr_tokens[1].IndexOf('/');
                                    if (slash_pos != -1)
                                    {
                                        var val1 = expr_tokens[1].Substring(0, slash_pos).Trim();
                                        var val2 = expr_tokens[1].Substring(slash_pos + 1).Trim();
                                        expr.val  = int.TryParse(val1, out var v) ? v : 0;
                                        expr.val2 = int.TryParse(val2, out v) ? v : 0;
                                    }
                                    else
                                    {
                                        var length = new css_length();
                                        length.fromString(expr_tokens[1]);
                                        if (length.units == css_units.dpcm)
                                        {
                                            expr.val = (int)(length.val * 2.54);
                                        }
                                        else if (length.units == css_units.dpi)
                                        {
                                            expr.val = (int)(length.val * 2.54);
                                        }
                                        else
                                        {
                                            if (doc != null)
                                            {
                                                doc.cvt_units(length, doc.container.get_default_font_size());
                                            }
                                            expr.val = (int)length.val;
                                        }
                                    }
                                }
                            }
                            query._expressions.Add(expr);
                        }
                    }
                }
                else
                {
                    query._media_type = (media_type)html.value_index(tok, types.media_type_strings, (int)media_type.all);
                }
            }
            return(query);
        }
示例#2
0
 public void link(document doc, element el)
 {
 }
示例#3
0
 public element create_element(string tag_name, Dictionary <string, string> attributes, document doc) => null;
示例#4
0
 public el_after(document doc) : base(doc, false)
 {
 }
示例#5
0
 public el_before(document doc) : base(doc, true)
 {
 }
示例#6
0
 public el_space(string text, document doc) : base(text, doc)
 {
 }
示例#7
0
 public element(document doc) : base()
 {
     _doc  = doc;
     _box  = null;
     _skip = false;
 }
示例#8
0
 public el_tr(document doc) : base(doc)
 {
 }