示例#1
0
 public line_box(int top, int left, int front, int right, int line_height, font_metrics fm, text_align align) : base(top, left, front, right) //:h3ml
 {
     _height       = 0;
     _width        = 0;
     _depth        = 0; //:h3ml
     _font_metrics = fm;
     _line_height  = line_height;
     _baseline     = 0;
     _text_align   = align;
 }
示例#2
0
文件: el_text.cs 项目: smorey2/h3ml
        public override void parse_styles(bool is_reparse)
        {
            _text_transform = (text_transform)html.value_index(get_style_property("text-transform", true, "none"), types.text_transform_strings, (int)text_transform.none);
            if (_text_transform != text_transform.none)
            {
                _transformed_text = _text;
                _use_transformed  = true;
                get_document().container.transform_text(_transformed_text, _text_transform);
            }

            if (is_white_space())
            {
                _transformed_text = " "; _use_transformed = true;
            }
            else
            {
                if (_text == "\t")
                {
                    _transformed_text = "    "; _use_transformed = true;
                }
                if (_text == "\n" || _text == "\r")
                {
                    _transformed_text = ""; _use_transformed = true;
                }
            }

            object font = null; font_metrics fm;
            var    el_parent = parent();

            if (el_parent != null)
            {
                font = el_parent.get_font(out fm);
            }
            else
            {
                fm = new font_metrics();
            }
            if (is_break())
            {
                _size.height = 0;
                _size.width  = 0;
                _size.depth  = 0; //:h3ml
            }
            else
            {
                _size.height = fm.height;
                _size.width  = get_document().container.text_width(_use_transformed ? _transformed_text : _text, font);
                _size.depth  = 0; //:h3ml
            }
            _draw_spaces = fm.draw_spaces;
        }
示例#3
0
文件: el_text.cs 项目: smorey2/h3ml
        public override object get_font(out font_metrics fm)
        {
            var el_parent = parent();

            if (el_parent != null)
            {
                return(el_parent.get_font(out fm));
            }
            else
            {
                fm = default(font_metrics);
            }
            return(null);
        }
示例#4
0
        public object get_font(string name, int size, string weight, string style, string decoration, out font_metrics fm)
        {
            if (name == null || string.Equals(name, "inherit", StringComparison.OrdinalIgnoreCase))
            {
                name = _container.get_default_font_name();
            }
            if (size == 0)
            {
                size = container.get_default_font_size();
            }
            var key = $"{name}:{size}:{weight}:{style}:{decoration}";

            if (_fonts.TryGetValue(key, out var el))
            {
                fm = el.metrics;
                return(el.font);
            }
            return(add_font(name, size, weight, style, decoration, out fm));
        }
示例#5
0
        object add_font(string name, int size, string weight, string style, string decoration, out font_metrics fm)
        {
            fm = default(font_metrics);
            object ret = null;

            if (name == null || string.Equals(name, "inherit", StringComparison.OrdinalIgnoreCase))
            {
                name = _container.get_default_font_name();
            }
            if (size == 0)
            {
                size = container.get_default_font_size();
            }
            var key = $"{name}:{size}:{weight}:{style}:{decoration}";

            if (!_fonts.ContainsKey(key))
            {
                var fs = (font_style)html.value_index(style, types.font_style_strings, (int)font_style.normal);
                var fw = html.value_index(weight, types.font_weight_strings, -1);
                if (fw >= 0)
                {
                    switch ((font_weight)fw)
                    {
                    case font_weight.bold: fw = (int)font_weight.w700; break;

                    case font_weight.bolder: fw = (int)font_weight.w600; break;

                    case font_weight.lighter: fw = (int)font_weight.w300; break;

                    default: fw = (int)font_weight.w400; break;
                    }
                }
                else
                {
                    fw = int.Parse(weight);
                    if (fw < 100)
                    {
                        fw = (int)font_weight.w400;
                    }
                }
                var decor = 0U;
                if (decoration != null)
                {
                    var tokens = new List <string>();
                    html.split_string(decoration, tokens, " ");
                    foreach (var i in tokens)
                    {
                        if (string.Equals(i, "underline", StringComparison.OrdinalIgnoreCase))
                        {
                            decor |= types.font_decoration_underline;
                        }
                        else if (string.Equals(i, "line-through", StringComparison.OrdinalIgnoreCase))
                        {
                            decor |= types.font_decoration_linethrough;
                        }
                        else if (string.Equals(i, "overline", StringComparison.OrdinalIgnoreCase))
                        {
                            decor |= types.font_decoration_overline;
                        }
                    }
                }
                var fi = new font_item();
                fi.font     = _container.create_font(name, size, fw, fs, decor, out fi.metrics);
                _fonts[key] = fi;
                ret         = fi.font;
                fm          = fi.metrics;
            }
            return(ret);
        }
示例#6
0
 public object create_font(string faceName, int size, int weight, font_style italic, uint decoration, out font_metrics fm)
 {
     fm = default(font_metrics); return(IntPtr.Zero);
 }