Ejemplo n.º 1
0
 private void Remove(HighlightInfoList list, DomElement element)
 {
     for (int iCount = list.Count - 1; iCount >= 0; iCount--)
     {
         HighlightInfo info   = list[iCount];
         bool          delete = false;
         if (info.OwnerElement == element)
         {
             delete = true;
         }
         else if (info.OwnerElement != null &&
                  info.OwnerElement.IsParentOrSupParent(element))
         {
             delete = true;
         }
         if (delete)
         {
             if (info.Range != null)
             {
                 this.Document.InvalidateView(info.Range);
             }
             list.RemoveAt(iCount);
         }
     }//for
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 比较两个对象设置是否一致
        /// </summary>
        /// <param name="info1">信息1</param>
        /// <param name="info2">信息2</param>
        /// <returns>设置是否一致</returns>
        public static bool Compare(HighlightInfo info1, HighlightInfo info2)
        {
            if (info1 == info2)
            {
                return(true);
            }
            else
            {
                if (info1 == null || info2 == null)
                {
                    // 此时两个对象必然一个为空另外一个不为空,因此不可能相等
                    return(false);
                }

                if (DomRange.Compare(info1.Range, info2.Range) == false ||
                    info1._ActiveStyle != info2._ActiveStyle ||
                    info1._BackColor != info2._BackColor ||
                    info1._Color != info2._Color)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 声明指定的元素相关的高亮度显示区域无效,需要重新设置
 /// </summary>
 /// <param name="element">文档元素对象</param>
 /// <param name="deleteElement">由于删除元素操作而执行本方法,
 /// 此时不需要将元素添加到高亮度区域状态未知的元素列表</param>
 public void InvalidateHighlightInfo(DomElement element)
 {
     if (element is DomCharElement)
     {
         // 字符元素不能设置为高亮度区域,因此不处理,提高效率
         return;
     }
     if (_InnerHighlightInfos != null)
     {
         if (_InvalidateHighlightInfoElements == null)
         {
             _InvalidateHighlightInfoElements = new DomElementList();
         }
         if (_InvalidateHighlightInfoElements.Contains(element) == false)
         {
             _InvalidateHighlightInfoElements.Add(element);
             if (_InnerHighlightInfos != null)
             {
                 for (int iCount = _InnerHighlightInfos.Count - 1; iCount >= 0; iCount--)
                 {
                     HighlightInfo info   = _InnerHighlightInfos[iCount];
                     bool          delete = false;
                     if (info.OwnerElement == element)
                     {
                         delete = true;
                     }
                     else if (info.OwnerElement != null &&
                              info.OwnerElement.IsParentOrSupParent(element))
                     {
                         delete = true;
                     }
                     if (delete)
                     {
                         if (info.Range != null)
                         {
                             this.Document.InvalidateView(info.Range);
                             if (info.OwnerElement != null &&
                                 _InvalidateHighlightInfoElements.Contains(info.OwnerElement) == false)
                             {
                                 _InvalidateHighlightInfoElements.Add(info.OwnerElement);
                             }
                         }
                         _InnerHighlightInfos.RemoveAt(iCount);
                     }
                 } //for
             }     //if
         }         //if
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 更新高亮度显示区域信息
 /// </summary>
 internal void UpdateHighlightInfos()
 {
     _InnerHighlightInfos = null;
     if (this.HighlightRanges != null)
     {
         // 让用户指定的高亮度区域状态无效
         foreach (HighlightInfo info in this.HighlightRanges)
         {
             if (info.Range != null)
             {
                 info.Range.Invalidate();
             }
         }
     }
     _HoverHighlightInfo = null;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 获得指定元素所在的高亮度显示区域
        /// </summary>
        /// <param name="element">指定的文档元素对象</param>
        /// <returns>获得的高亮度显示区域</returns>
        public virtual HighlightInfo this[DomElement element]
        {
            get
            {
                if (element == null)
                {
                    return(null);
                }
                // 首先搜索鼠标悬浮高亮度显示区域,该区域优先级最高而且最容易被命中
                if (_HoverHighlightInfo != null)
                {
                    if (_HoverHighlightInfo.Contains(element))
                    {
                        return(_HoverHighlightInfo);
                    }
                }

                // 搜索用户设置的高亮度显示区域,用户设置的优先处理
                if (this.HighlightRanges != null && this.HighlightRanges.Count > 0)
                {
                    HighlightInfo info = this.HighlightRanges[element];
                    if (info != null)
                    {
                        return(info);
                    }
                }

                // 搜索内部自动生成的区域
                if (this.InnerHighlightInfos.Count > 0)
                {
                    HighlightInfo info = this.InnerHighlightInfos[element];
                    if (info != null)
                    {
                        return(info);
                    }
                }
                return(null);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 绘制对象
        /// </summary>
        /// <param name="g">图形绘制对象</param>
        /// <param name="ClipRectangle">剪切矩形</param>
        protected virtual void DrawContent(DomCharElement chr, DocumentPaintEventArgs args)
        {
            DocumentContentStyle rs = chr.RuntimeStyle;

            System.Drawing.RectangleF rect = chr.AbsBounds;
            rect.Height = rect.Height * 1.5f;
            rect.Width  = rect.Width * 1.5f;
            //if (chr.OwnerLine.AdditionHeight < 0)
            {
                rect.Height = Math.Max(
                    rect.Height,
                    chr.OwnerLine.Height + chr.OwnerLine.AdditionHeight);
            }
            //rect.Height = Math.Min(rect.Height, chr.OwnerLine.Height);
            Color cc = rs.Color;

            if (args.RenderStyle == DocumentRenderStyle.Paint)
            {
                HighlightInfo info = this.Document.HighlightManager[chr];
                if (info != null && info.Color.A != 0)
                {
                    // 设置高亮度文本值
                    cc = info.Color;
                }
            }
            SolidBrush b    = GraphicsObjectBuffer.GetSolidBrush(cc);
            XFontValue font = rs.Font.Clone();

            if (rs.Subscript || rs.Superscript)
            {
                font.Size = font.Size * 0.6f;
                if (rs.Superscript)
                {
                    args.Graphics.DrawString(chr.CharValue.ToString(),
                                             font.Value,
                                             b,
                                             rect.Left,
                                             rect.Top,
                                             myMeasureFormat);
                }
                else
                {
                    args.Graphics.DrawString(chr.CharValue.ToString(),
                                             font.Value,
                                             b,
                                             rect.Left,
                                             (int)Math.Floor(rect.Top + (rect.Height * 0.4)),
                                             myMeasureFormat);
                }
            }
            else
            {
                if ((rs.Underline || rs.Strikeout) && chr.CharValue == ' ')
                {
                    // .NET框架存在一个BUG,不能为空格绘制下划线和删除线,因此在此进行替换绘制成不带下划线的下划线字母。
                    XFontValue font2 = rs.Font.Clone();
                    if (font2.Underline)
                    {
                        font2.Underline = false;
                        args.Graphics.DrawString(
                            "_",
                            font2.Value,
                            b,
                            rect.Left,
                            rect.Top,
                            myMeasureFormat);
                    }
                    else
                    {
                        font2.Strikeout = false;
                        args.Graphics.DrawString(
                            "-",
                            font2.Value,
                            b,
                            rect.Left,
                            rect.Top,
                            myMeasureFormat);
                    }
                }
                else
                {
                    //InnerFormat.FormatFlags = InnerFormat.FormatFlags | StringFormatFlags.MeasureTrailingSpaces;
                    //InnerFormat.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.MeasureTrailingSpaces ;
                    args.Graphics.DrawString(
                        chr.CharValue.ToString(),
                        rs.Font.Value,
                        b,
                        rect,
                        myMeasureFormat);
                }
            }
            //if ( font.Underline )
            //{
            //    float fh = font.GetHeight(args.Graphics);
            //    Pen p = SolidBrushBuffer.GetPen(cc);
            //    args.Graphics.DrawLine(
            //        p,
            //        rect.Left ,
            //        rect.Top + fh ,
            //        rect.Right + chr.WidthFix,
            //        rect.Top + fh );
            //}
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 绘制文档元素背景
        /// </summary>
        /// <param name="element">文档元素对象</param>
        /// <param name="args">参数</param>
        /// <param name="bounds">要绘制背景的区域</param>
        public virtual void DrawBackground(
            DomElement element,
            DocumentPaintEventArgs args,
            RectangleF bounds)
        {
            if (bounds.IsEmpty)
            {
                // 不绘制图形
                return;
            }

            DocumentContentStyle rs = null;

            if (element.Parent != null)
            {
                rs = element.Parent.GetContentBackgroundStyle(element);
            }
            if (rs == null)
            {
                rs = element.RuntimeStyle;
            }
            System.Drawing.Color c = rs.BackgroundColor;
            if (c.A != 0)
            {
                System.Drawing.SolidBrush b = GraphicsObjectBuffer.GetSolidBrush(c);
                bounds = System.Drawing.RectangleF.Intersect(bounds, args.ClipRectangleF);
                if (!bounds.IsEmpty)
                {
                    args.Graphics.FillRectangle(b, bounds);
                    return;
                }
            }

            HighlightInfo highlight = null;

            if (args.ActiveMode && args.RenderStyle == DocumentRenderStyle.Paint)
            {
                highlight = this.Document.HighlightManager[element];
            }
            if (highlight != null)
            {
                if (args.RenderStyle == DocumentRenderStyle.Print &&
                    highlight.ActiveStyle != HighlightActiveStyle.AllTime)
                {
                    // 当进行打印时不显示不能打印的高亮度色
                    return;
                }
                // 如果需要高亮度显示
                // 则绘制高亮度背景
                bounds = RectangleF.Intersect(bounds, args.ClipRectangleF);
                if (highlight.BackColor.A != 0)
                {
                    if (!bounds.IsEmpty)
                    {
                        args.Graphics.FillRectangle(
                            GraphicsObjectBuffer.GetSolidBrush(highlight.BackColor),
                            bounds);
                    }
                }
            }
        }