Пример #1
0
        public int cvt_units(css_length val, int fontSize, int size = 0)
        {
            if (val.is_predefined)
            {
                return(0);
            }
            var ret = 0;

            switch (val.units)
            {
            case css_units.percentage: ret = val.calc_percent(size); break;

            case css_units.em: ret = (int)Math.Round(val.val * fontSize); val.set_value(ret, css_units.px); break;

            case css_units.pt: ret = _container.pt_to_px((int)val.val); val.set_value(ret, css_units.px); break;

            case css_units.@in: ret = _container.pt_to_px((int)(val.val * 72)); val.set_value(ret, css_units.px); break;

            case css_units.cm: ret = _container.pt_to_px((int)(val.val * 0.3937 * 72)); val.set_value(ret, css_units.px); break;

            case css_units.mm: ret = _container.pt_to_px((int)(val.val * 0.3937 * 72) / 10); val.set_value(ret, css_units.px); break;

            case css_units.vw: ret = (int)(_media.width * (double)val.val / 100.0); break;

            case css_units.vh: ret = (int)(_media.height * (double)val.val / 100.0); break;

            case css_units.vmin: ret = (int)(Math.Min(_media.height, _media.width) * (double)val.val / 100.0); break;

            case css_units.vmax: ret = (int)(Math.Max(_media.height, _media.width) * (double)val.val / 100.0); break;

            default: ret = (int)val.val; break;
            }
            return(ret);
        }
Пример #2
0
 public table_column(table_column val)
 {
     left         = val.left;
     right        = val.right;
     border_left  = val.border_left;
     border_right = val.border_right;
     max_width    = val.max_width;
     min_width    = val.min_width;
     width        = val.width;
     css_width    = val.css_width;
 }
Пример #3
0
 public table_row(table_row val)
 {
     min_height    = val.min_height;
     top           = val.top;
     bottom        = val.bottom;
     border_bottom = val.border_bottom;
     border_top    = val.border_top;
     height        = val.height;
     css_height    = val.css_height;
     el_row        = val.el_row;
 }
Пример #4
0
        public void CssLengthParseTest()
        {
            var length = new css_length();

            length.fromString("calc(todo)"); Assert.AreEqual(length.is_predefined, true); Assert.AreEqual(length.predef, 0); Assert.AreEqual(length.val, 0); Assert.AreEqual(length.units, css_units.none);
            length.fromString("top", "top;bottom", -1); Assert.AreEqual(length.is_predefined, true); Assert.AreEqual(length.predef, 0); Assert.AreEqual(length.val, 0); Assert.AreEqual(length.units, css_units.none);
            length.fromString("bottom", "top;bottom", -1); Assert.AreEqual(length.is_predefined, true); Assert.AreEqual(length.predef, 1); Assert.AreEqual(length.val, 0); Assert.AreEqual(length.units, css_units.none);
            length.fromString("bad", "top;bottom", -1); Assert.AreEqual(length.is_predefined, true); Assert.AreEqual(length.predef, -1); Assert.AreEqual(length.val, 0); Assert.AreEqual(length.units, css_units.none);
            length.fromString("123", "top;bottom", -1); Assert.AreEqual(length.is_predefined, false); Assert.AreEqual(length.predef, 0); Assert.AreEqual(length.val, 123); Assert.AreEqual(length.units, css_units.none);
            length.fromString("123px", "top;bottom", -1); Assert.AreEqual(length.is_predefined, false); Assert.AreEqual(length.predef, 0); Assert.AreEqual(length.val, 123); Assert.AreEqual(length.units, css_units.px);
        }
Пример #5
0
 public css_length(css_length val)
 {
     if (val.is_predefined)
     {
         _value = 0; _predef = val._predef;
     }
     else
     {
         _value = val._value; _predef = 0;
     }
     _units         = val._units;
     _is_predefined = val._is_predefined;
 }
Пример #6
0
 public table_row(int h, element row)
 {
     min_height    = 0;
     height        = h;
     el_row        = row;
     border_bottom = 0;
     border_top    = 0;
     top           = 0;
     bottom        = 0;
     if (row != null)
     {
         css_height = row.get_css_height();
     }
 }
Пример #7
0
        public int cvt_units(string str, int fontSize, out bool is_percent)
        {
            is_percent = false;
            if (str == null)
            {
                return(0);
            }
            var val = new css_length();

            val.fromString(str);
            if (is_percent && val.units == css_units.percentage && !val.is_predefined)
            {
                is_percent = true;
            }
            return(cvt_units(val, fontSize));
        }
Пример #8
0
        public void CvtUnitsTest()
        {
            var doc = new document(new container_test(), null);

            doc.cvt_units("", 10, out var is_percent);
            var c = new css_length();

            c.fromString("10%"); doc.cvt_units(c, 10, 100);
            c.fromString("10em"); doc.cvt_units(c, 10, 100);
            c.fromString("10pt"); doc.cvt_units(c, 10, 100);
            c.fromString("10in"); doc.cvt_units(c, 10, 100);
            c.fromString("10cm"); doc.cvt_units(c, 10, 100);
            c.fromString("10mm"); doc.cvt_units(c, 10, 100);
            c.fromString("10vm"); doc.cvt_units(c, 10, 100);
            c.fromString("10vh"); doc.cvt_units(c, 10, 100);
            c.fromString("10vmin"); doc.cvt_units(c, 10, 100);
            c.fromString("10vmax"); doc.cvt_units(c, 10, 100);
            c.fromString("10"); doc.cvt_units(c, 10, 100);
        }
Пример #9
0
        public int calc_table_width(int block_width, bool is_auto, int min_table_width, int max_table_width)
        {
            min_table_width = 0; // MIN
            max_table_width = 0; // MAX

            var cur_width = 0;
            var max_w     = 0;
            var min_w     = 0;

            for (var col = 0; col < _cols_count; col++)
            {
                min_table_width += _columns[col].min_width;
                max_table_width += _columns[col].max_width;

                if (!_columns[col].css_width.is_predefined)
                {
                    _columns[col].width = _columns[col].css_width.calc_percent(block_width);
                    _columns[col].width = Math.Max(_columns[col].width, _columns[col].min_width);
                }
                else
                {
                    _columns[col].width = _columns[col].min_width;
                    max_w += _columns[col].max_width;
                    min_w += _columns[col].min_width;
                }

                cur_width += _columns[col].width;
            }

            if (cur_width == block_width)
            {
                return(cur_width);
            }

            if (cur_width < block_width)
            {
                if (cur_width - min_w + max_w <= block_width)
                {
                    cur_width = 0;
                    for (var col = 0; col < _cols_count; col++)
                    {
                        if (_columns[col].css_width.is_predefined)
                        {
                            _columns[col].width = _columns[col].max_width;
                        }
                        cur_width += _columns[col].width;
                    }
                    if (cur_width == block_width || is_auto)
                    {
                        return(cur_width);
                    }
                }
                distribute_width(block_width - cur_width, 0, _cols_count - 1);
                cur_width = 0;
                for (var col = 0; col < _cols_count; col++)
                {
                    cur_width += _columns[col].width;
                }
            }
            else
            {
                var fixed_width = 0;
                var percent     = 0F;
                for (int col = 0; col < _cols_count; col++)
                {
                    if (!_columns[col].css_width.is_predefined && _columns[col].css_width.units == css_units.percentage)
                    {
                        percent += _columns[col].css_width.val;
                    }
                    else
                    {
                        fixed_width += _columns[col].width;
                    }
                }
                var scale = (float)(100.0 / percent);
                cur_width = 0;
                for (var col = 0; col < _cols_count; col++)
                {
                    if (!_columns[col].css_width.is_predefined && _columns[col].css_width.units == css_units.percentage)
                    {
                        var w = new css_length();
                        w.set_value(_columns[col].css_width.val * scale, css_units.percentage);
                        _columns[col].width = w.calc_percent(block_width - fixed_width);
                        if (_columns[col].width < _columns[col].min_width)
                        {
                            _columns[col].width = _columns[col].min_width;
                        }
                    }
                    cur_width += _columns[col].width;
                }
            }
            return(cur_width);
        }
Пример #10
0
        public static media_query create_from_string(string str, document doc)
        {
            var query  = new media_query();
            var tokens = new List <string>();

            html.split_string(str, tokens, " \t\r\n", "", "(");
            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);
        }