/// <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 ); //} }
/// <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); } } } }