public override void Draw(DocumentPaintEventArgs args)
        {
            DomContentLine line = this.OwnerLine;
            RectangleF     rect = this.AbsBounds;

            if (line.ParagraphListStyle == ParagraphListStyle.BulletedList)
            {
                float      size       = Math.Min(rect.Width * 0.6f, rect.Height * 0.6f);
                RectangleF circleRect = new RectangleF(rect.Left + size / 2, rect.Top + size / 2, size, size);
                args.Graphics.FillEllipse(Brushes.Black, circleRect);
            }
            else if (line.ParagraphListStyle == ParagraphListStyle.NumberedList)
            {
                using (System.Drawing.StringFormat f
                           = new System.Drawing.StringFormat())
                {
                    XFontValue font = this.RuntimeStyle.Font;
                    f.Alignment     = System.Drawing.StringAlignment.Near;
                    f.LineAlignment = System.Drawing.StringAlignment.Center;
                    f.FormatFlags   = System.Drawing.StringFormatFlags.NoWrap;
                    args.Graphics.DrawString(
                        line.ParagraphStyleIndex + ".",
                        font.Value,
                        System.Drawing.Brushes.Black,
                        rect,
                        f);
                }
            }
        }
Example #2
0
 public XTextUndoSetDefaultFont(CSWriterControl ctl, XFontValue of, Color oc, XFontValue nf, Color nc)
 {
     _Control  = ctl;
     _OldFont  = of;
     _OldColor = oc;
     _NewFont  = nf;
     _NewColor = nc;
 }
 protected void Font(object sender, WriterCommandEventArgs args)
 {
     if (args.Mode == WriterCommandEventMode.QueryState)
     {
         args.Enabled = args.DocumentControler != null &&
                        args.DocumentControler.Snapshot.CanModifySelection;
     }
     else if (args.Mode == WriterCommandEventMode.Invoke)
     {
         //MessageBox.Show(Convert.ToString(args.Parameter));
         //System.Diagnostics.Debugger.Break();
         DocumentContentStyle cs   = GetCurrentStyle(args.Document);
         XFontValue           font = new XFontValue();
         if (args.Parameter == null)
         {
             font = cs.Font;
             //MessageBox.Show("1:" + font.Size);
         }
         else if (args.Parameter is XFontValue)
         {
             font = ((XFontValue)args.Parameter).Clone();
             //MessageBox.Show("2:" + font.Size);
         }
         else if (args.Parameter is System.Drawing.Font)
         {
             font = new XFontValue((System.Drawing.Font)args.Parameter);
             //MessageBox.Show("3:" + font.Size);
         }
         else
         {
             // 未知参数
             font = cs.Font;
         }
         if (args.ShowUI)
         {
             using (FontDialog dlg = new FontDialog())
             {
                 dlg.Font = font.Value;
                 if (dlg.ShowDialog(args.EditorControl) == DialogResult.OK)
                 {
                     font = new XFontValue(dlg.Font);
                 }
                 else
                 {
                     return;
                 }
             }
         }
         args.Parameter = font;
         SetStyleProperty(sender, args, StandardCommandNames.Font);
     }
 }
 protected void DocumentDefaultFont(object sender, WriterCommandEventArgs args)
 {
     if (args.Mode == WriterCommandEventMode.QueryState)
     {
         args.Enabled = false;
         if (args.Document != null)
         {
             if (args.EditorControl != null &&
                 args.EditorControl.Readonly == false &&
                 args.EditorControl.AutoSetDocumentDefaultFont == false)
             {
                 args.Enabled = true;
             }
         }
     }
     else if (args.Mode == WriterCommandEventMode.Invoke)
     {
         XFontValue font = new XFontValue();
         if (args.Parameter is XFontValue)
         {
             font = (XFontValue)args.Parameter;
         }
         else if (args.Parameter is System.Drawing.Font)
         {
             font = new XFontValue((System.Drawing.Font)args.Parameter);
         }
         else if (args.Parameter is string)
         {
             font.Parse((string)args.Parameter);
         }
         else
         {
             font = args.Document.DefaultStyle.Font;
         }
         System.Drawing.Color c = args.Document.DefaultStyle.Color;
         if (args.ShowUI)
         {
             using (FontDialog dlg = new FontDialog())
             {
                 dlg.ShowColor = true;
                 dlg.Font      = font.Value;
                 dlg.Color     = c;
                 if (dlg.ShowDialog(args.EditorControl) == DialogResult.OK)
                 {
                     font = new XFontValue(dlg.Font);
                     c    = dlg.Color;
                 }
                 else
                 {
                     return;
                 }
             }
         }
         if (args.Document.BeginLogUndo())
         {
             DCSoft.CSharpWriter.Dom.Undo.XTextUndoSetDefaultFont undo =
                 new Dom.Undo.XTextUndoSetDefaultFont(
                     args.EditorControl,
                     args.Document.DefaultStyle.Font,
                     args.Document.DefaultStyle.Color,
                     font,
                     c);
             args.Document.UndoList.Add(undo);
             args.Document.EndLogUndo();
         }
         args.EditorControl.EditorSetDefaultFont(font, c, true);
     }
 }
Example #5
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 );
            //}
        }