示例#1
0
        /// <summary>
        /// 设置文档内容的样式
        /// </summary>
        /// <param name="newStyle">新样式</param>
        /// <param name="logUndo">是否记录撤销操作信息</param>
        public virtual void EditorSetContentStyle(DocumentContentStyle newStyle, bool logUndo)
        {
            if (newStyle == null)
            {
                throw new ArgumentNullException("newStyle");
            }
            DomElementList list = new DomElementList();

            list.Add(this);
            this.AppendContent(list, true);
            if (logUndo)
            {
                this.OwnerDocument.BeginLogUndo();
            }
            bool result = DomSelection.SetElementStyle(newStyle, this.OwnerDocument, list);

            if (logUndo)
            {
                this.OwnerDocument.EndLogUndo();
            }
            if (result)
            {
                this.OwnerDocument.EditorCurrentStyle = null;
                this.OwnerDocument.OnSelectionChanged();
                this.OwnerDocument.OnDocumentContentChanged();
            }
        }
示例#2
0
        /// <summary>
        /// 刷新元素大小
        /// </summary>
        /// <param name="g">参数</param>
        protected virtual void RefreshSize(DomParagraphFlagElement eof, System.Drawing.Graphics g)
        {
            int h = (int)Math.Ceiling((double)this.Document.DefaultStyle.DefaultLineHeight);
            DocumentContentStyle rs = eof.RuntimeStyle;
            SizeF size = g.MeasureString("#", rs.Font.Value);

            eof.Height      = rs.Font.GetHeight(g);// size.Height;
            eof.Width       = this.Document.PixelToDocumentUnit(10);
            eof.SizeInvalid = false;
        }
示例#3
0
        ///// <summary>
        ///// 对象在文档对象模型中的序号
        ///// </summary>
        //[Browsable(false)]
        //public int DomIndex
        //{
        //    get
        //    {
        //        int result = 0;
        //        XTextElement element = this ;
        //        XTextElement parent = this.Parent;
        //        while (parent != null)
        //        {
        //            result = result + parent.Elements.IndexOf(element);
        //            element = parent;
        //            parent = element.Parent;
        //        }
        //        return result;

        //        return _DomIndex;
        //    }
        //}

        /// <summary>
        /// 返回子元素背景样式
        /// </summary>
        public virtual DocumentContentStyle GetContentBackgroundStyle(DomElement childElement)
        {
            DocumentContentStyle rs = (DocumentContentStyle)this.RuntimeStyle;

            if (rs != null && rs.HasVisibleBackground)
            {
                return(rs);
            }
            else
            {
                return(null);
            }
            //return null;
        }
示例#4
0
        public virtual void RenderBorder(
            DomElement element,
            DocumentPaintEventArgs args,
            RectangleF bounds)
        {
            DocumentContentStyle style = element.RuntimeStyle;

            if (style.HasVisibleBorder)
            {
                using (Pen p = style.CreateBorderPen())
                {
                    style.DrawBorder(args.Graphics, p, bounds);
                }
            }
        }
        //public override void AfterLoad(DocumentFormatStyle format)
        //{
        //    base.AfterLoad(format);
        //    if (format == DocumentFormatStyle.XML)
        //    {
        //        WriterUtils.SplitElements(this.Elements);
        //    }
        //}
//
//		/// <summary>
//		/// 删除子元素操作
//		/// </summary>
//		/// <param name="element">要删除的子元素</param>
//		/// <returns>是否删除元素</returns>
//		public override bool RemoveChild(XTextElement element)
//		{
//			if( element == this.myEOFElement )
//			{
//				if( this.NextElement is XTextParagraph )
//				{
//					XTextParagraph p = ( XTextParagraph ) this.NextElement ;
//					int pindex = myParent.Elements.IndexOf( p );
//					XTextElementList list = new XTextElementList();
//					list.AddRange( p.Elements );
//					list.RemoveAt( list.Count - 1 );
//					int index = myElements.Count - 1 ;
//					myElements.AddRange( list );
//					myParent.RemoveChild( p );
//					if( myOwnerDocument.CanLogUndo )
//					{
//						myOwnerDocument.UndoList.AddRemoveElement( myParent , pindex , p );
//						myOwnerDocument.UndoList.AddInsertElements( this , index , list );
//					}
//					myOwnerDocument.bolModifyParagraph = true ;
//					return true ;
//				}
//				return false;
//			}
//			myElements.Remove( element );
//			return true ;
//		}

        public override void WriteHTML(DCSoft.CSharpWriter.Html.WriterHtmlDocumentWriter writer)
        {
            DocumentContentStyle rs = this.RuntimeStyle;

            if (rs.NumberedList == false && rs.BulletedList == false)
            {
                writer.WriteStartElement("p");
            }
            else
            {
                writer.WriteStartElement("li");
            }
            writer.WriteDocumentContentStyle(this.RuntimeStyle, this);
            writer.WriteStyleItem("text-justify", "inter-ideograph");
            writer.WriteStyleItem(
                "margin-bottom",
                this.OwnerDocument.ToPixel(( int )rs.SpacingBeforeParagraph) + " px");
            //if( intListStyle == ParagraphListStyle.None && this.bolHeadIndent )

            if (rs.NumberedList == false &&
                rs.BulletedList == false &&
                rs.FirstLineIndent != 0)
            {
                writer.WriteStyleItem(
                    "margin-left",
                    this.OwnerDocument.ToPixel(( int )rs.FirstLineIndent) + " px");
            }
            writer.WriteEndStyle();
            if (this.Elements.Count > 1)
            {
                DomParagraphElement p = this.CreateMergedParagrahp(
                    writer.IncludeSelectionOndly);

                foreach (DomElement element in p.Elements)
                {
                    element.WriteHTML(writer);
                }
                //base.WriteContentHTML( writer );
            }
            else
            {
                writer.WriteText(" ");
            }
            writer.WriteEndElement();
        }
示例#6
0
        /// <summary>
        /// 设置段落样式
        /// </summary>
        /// <param name="newStyle"></param>
        /// <returns></returns>
        public DomElementList SetParagraphStyle(DocumentContentStyle newStyle)
        {
            DomDocument document = this._DocumentContent.OwnerDocument;
            Dictionary <DomElement, int> styleIndexs
                = new Dictionary <DomElement, int>();

            if (this.Document.Options.SecurityOptions.EnablePermission)
            {
                newStyle.DisableDefaultValue = true;
                newStyle.CreatorIndex        = this.Document.UserHistories.CurrentIndex;
                newStyle.DeleterIndex        = -1;
            }
            else
            {
                newStyle.DisableDefaultValue = true;
                newStyle.CreatorIndex        = -1;
                newStyle.DeleterIndex        = -1;
            }
            foreach (DomParagraphFlagElement p in this.ParagraphsEOFs)
            {
                if (document.DocumentControler.CanModify(p))
                {
                    DocumentContentStyle rs = (DocumentContentStyle)p.RuntimeStyle.Clone();
                    if (XDependencyObject.MergeValues(newStyle, rs, true) > 0)
                    {
                        rs.DefaultValuePropertyNames = newStyle.GetDefaultValuePropertyNames();
                        int newStyleIndex = document.ContentStyles.GetStyleIndex(rs);
                        if (newStyleIndex != p.StyleIndex)
                        {
                            styleIndexs[p] = newStyleIndex;
                        }
                    }
                }
            }//foreach
            if (styleIndexs.Count > 0)
            {
                DomElementList result = document.EditorSetParagraphStyle(styleIndexs, true);
                return(result);
            }
            else
            {
                return(null);
            }
        }
 public override void FixElements()
 {
     if (this.Elements.Count == 0 ||
         (this.Elements.LastElement is DomParagraphFlagElement) == false)
     {
         DomParagraphFlagElement flag = new DomParagraphFlagElement();
         flag.AutoCreate = true;
         DocumentContentStyle style = new DocumentContentStyle();
         style.Align = DocumentContentAlignment.Center;
         //style.BorderWidth = 1;
         //style.BorderColor = Color.Black;
         //style.BorderStyle = System.Drawing.Drawing2D.DashStyle.Solid;
         //style.BorderLeft = false;
         //style.BorderTop = false;
         //style.BorderRight = false;
         //style.BorderBottom = true;
         //style.BorderSpacing = 8;
         flag.StyleIndex = this.OwnerDocument.ContentStyles.GetStyleIndex(style);
         this.AppendChildElement(flag);
     }
 }
示例#8
0
        /// <summary>
        /// 删除与默认样式相同的项目,只保留不同的项目
        /// </summary>
        /// <param name="defaultStyle">默认样式对象</param>
        /// <returns>经过操作后本对象剩余的项目</returns>
        public int RemoveSameStyle(DocumentContentStyle defaultStyle)
        {
            if (defaultStyle == null)
            {
                throw new ArgumentNullException("defaultStyle");
            }

            foreach (XDependencyProperty p in defaultStyle.InnerValues.Keys)
            {
                if (this.InnerValues.ContainsKey(p))
                {
                    object v1 = defaultStyle.InnerValues[p];
                    object v2 = this.InnerValues[p];
                    if (v1 == v2)
                    {
                        this.InnerValues.Remove(p);
                    }
                }
            }
            return(this.InnerValues.Count);
        }
示例#9
0
        internal void ClearContent()
        {
            this.Elements.Clear();
            DomDocumentContentElement ce = this.Body;

            ce.AppendChildElement(this.OwnerDocument.CreateParagraphEOF());
            ce.UpdateContentElements(true);
            ce.SetSelection(0, 0);

            ce = this.Header;
            ce.FixElements();
            DocumentContentStyle style = new DocumentContentStyle();

            ce.UpdateContentElements(true);
            ce.SetSelection(0, 0);

            ce = this.Footer;
            ce.FixElements();
            ce.UpdateContentElements(true);
            ce.SetSelection(0, 0);
        }
示例#10
0
        /// <summary>
        /// 设置文档元素的样式
        /// </summary>
        /// <param name="newStyle">新样式</param>
        /// <returns>是否修改了文档内容</returns>
        public bool SetElementStyle(DocumentContentStyle newStyle)
        {
            Dictionary <DomElement, int> newStyleIndexs
                = new Dictionary <DomElement, int>();

            foreach (DomElement element in this)
            {
                DocumentContentStyle rs = (DocumentContentStyle)element.RuntimeStyle.Clone();
                if (XDependencyObject.MergeValues(newStyle, rs, true) > 0)
                {
                    int styleIndex = this.Document.ContentStyles.GetStyleIndex(rs);
                    if (styleIndex != element.StyleIndex)
                    {
                        newStyleIndexs[element] = styleIndex;
                    }
                }
            }//foreach
            if (newStyleIndexs.Count > 0)
            {
                this.Document.EditorSetElementStyle(newStyleIndexs, true);
                return(true);
            }
            return(false);
        }
示例#11
0
        /// <summary>
        /// 设置段落样式
        /// </summary>
        /// <param name="newStyle"></param>
        /// <returns></returns>
        public DomElementList SetParagraphStyle(DocumentContentStyle newStyle)
        {
            CheckState();
            Dictionary <DomElement, int> styleIndexs
                = new Dictionary <DomElement, int>();

            foreach (DomParagraphFlagElement p in this.ParagraphsEOFs)
            {
                DocumentContentStyle rs = (DocumentContentStyle)p.RuntimeStyle.Clone();
                if (XDependencyObject.MergeValues(newStyle, rs, true) > 0)
                {
                    int newStyleIndex = this.Document.ContentStyles.GetStyleIndex(rs);
                    if (newStyleIndex != p.StyleIndex)
                    {
                        styleIndexs[p] = newStyleIndex;
                    }
                }
            }//foreach
            if (styleIndexs.Count > 0)
            {
                this.Document.EditorSetParagraphStyle(styleIndexs, true);
            }
            return(this.ParagraphsEOFs);
        }
示例#12
0
        /// <summary>
        /// 输出对象数据到HTML文档
        /// </summary>
        /// <param name="writer">HTML文档书写器</param>
        public override void WriteHTML(DCSoft.CSharpWriter.Html.WriterHtmlDocumentWriter writer)
        {
            DocumentContentStyle rs = this.RuntimeStyle;

            if (rs.Superscript)
            {
                writer.WriteStartElement("sup");
            }
            else if (rs.Subscript)
            {
                writer.WriteStartElement("sub");
            }
            string link = rs.Link;

            if (link != null && link.Trim().Length > 0)
            {
                writer.WriteStartElement("a");
                writer.WriteAttributeString("href", link);
            }
            else
            {
                writer.WriteStartElement("span");
            }
            writer.WriteStartStyle();
            writer.WriteDocumentContentStyle(this.RuntimeStyle, this);
            writer.WriteEndStyle();

            writer.WriteText(
                this.GetOutputText(writer.IncludeSelectionOndly));

            writer.WriteEndElement();
            if (rs.Superscript || rs.Subscript)
            {
                writer.WriteEndElement();
            }
        }
示例#13
0
 /// <summary>
 /// 设置文档元素的样式
 /// </summary>
 /// <param name="newStyle">新样式</param>
 /// <returns>是否修改了文档内容</returns>
 public bool SetElementStyle(DocumentContentStyle newStyle)
 {
     return(SetElementStyle(newStyle, this._DocumentContent.OwnerDocument, this));
 }
示例#14
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);
                    }
                }
            }
        }
示例#15
0
        /// <summary>
        /// 重新计算对象大小
        /// </summary>
        /// <param name="g">图形绘制对象</param>
        protected virtual void RefreshSize(DomCharElement chr, System.Drawing.Graphics g)
        {
            DocumentViewOptions opt = this.Document.Options.ViewOptions;

            if (myMeasureFormat == null)
            {
                myMeasureFormat = new System.Drawing.StringFormat(
                    System.Drawing.StringFormat.GenericTypographic);
                myMeasureFormat.FormatFlags = System.Drawing.StringFormatFlags.FitBlackBox
                                              | System.Drawing.StringFormatFlags.MeasureTrailingSpaces
                                              | StringFormatFlags.NoClip;
            }
            DomDocument document = chr.OwnerDocument;

            if (_EnableCharSizeBuffer)
            {
                if (chr.CharValue != '\t')
                {
                    if (charSizes != null)
                    {
                        if (charSizes.ContainsKey(chr.StyleIndex))
                        {
                            Dictionary <char, SizeF> sizes = charSizes[chr.StyleIndex];
                            if (sizes.ContainsKey(chr.CharValue))
                            {
                                // 从缓存区中获得字母大小
                                SizeF bsize = sizes[chr.CharValue];
                                chr.Width       = bsize.Width;
                                chr.Height      = bsize.Height;
                                chr._FontHeight = chr.RuntimeStyle.Font.GetHeight(g);
                                return;
                            }
                        }
                    }
                } //if
            }     //if

            DocumentContentStyle rs = chr.RuntimeStyle;

            System.Drawing.SizeF size = System.Drawing.SizeF.Empty;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
            //this.UseGDIFontSize = true;
            if (opt.RichTextBoxCompatibility)
            {
                // 使用GDI模式计算字符大小
                string  key  = rs.FontName + "|" + rs.FontSize + "|" + rs.FontStyle;
                GDIFont font = null;
                if (gdiFonts.ContainsKey(key))
                {
                    font = gdiFonts[key];
                }
                else
                {
                    font = new GDIFont(
                        rs.FontName,
                        //(int)( rs.FontSize *  1.3837 * 3 ),
                        (int)(GraphicsUnitConvert.Convert(
                                  rs.FontSize,
                                  GraphicsUnit.Point,
                                  GraphicsUnit.Document)),
                        rs.Bold,
                        rs.Italic,
                        rs.Underline,
                        rs.Strikeout);
                    gdiFonts[key] = font;
                }

                Size[] sizes = font.MeasureCharactersSize(g, chr.CharValue.ToString());
                size.Width  = sizes[0].Width;
                size.Height = sizes[0].Height;
                if (chr.CharValue == ' ')
                {
                    if (rs.FontName == "Times New Roman")
                    {
                        size.Width = size.Width * 1.28f;
                    }
                }
            }
            else
            {
                if (chr.CharValue == ' ')
                {
                    size = g.MeasureString(
                        " ",
                        rs.Font.Value,
                        10000,
                        System.Drawing.StringFormat.GenericDefault);
                    size.Width = size.Width * 0.57f;
                }
                else if (chr.CharValue == '\t')
                {
                }
                else
                {
                    size = g.MeasureString(
                        chr.CharValue.ToString(),
                        rs.Font.Value,
                        10000,
                        myMeasureFormat);
                    size.Width = size.Width;
                }
            }
            chr.Width       = size.Width;
            chr.Height      = size.Height + 1;
            chr._FontHeight = rs.Font.GetHeight(g);
            chr.Height      = chr._FontHeight;// size.Height;
            if (rs.Superscript)
            {
                chr.Height = chr.Height * 1.2f;
            }
            if (rs.Superscript || rs.Subscript)
            {
                chr.Width = chr.Width * 0.6f;
            }
            if (_EnableCharSizeBuffer)
            {
                if (charSizes != null)
                {
                    Dictionary <char, SizeF> sizes2 = null;
                    if (charSizes.ContainsKey(chr.StyleIndex))
                    {
                        sizes2 = charSizes[chr.StyleIndex];
                    }
                    else
                    {
                        sizes2 = new Dictionary <char, SizeF>();
                        charSizes[chr.StyleIndex] = sizes2;
                    }
                    sizes2[chr.CharValue] = new SizeF(chr.Width, chr.Height);
                }
            }
        }
示例#16
0
        //private ParagraphListStyle _L

        //private float _LeftCount = 0 ;
        internal bool AddElement(DomElement element)
        {
            if (this.Count == 0)
            {
                //intLeftCount = 0 ;
                this.List.Add(element);

                {
                    DomParagraphFlagElement p = element.OwnerParagraphEOF;
                    if (p != null)
                    {
                        DocumentContentStyle rs = p.RuntimeStyle;
                        if (element == p.ParagraphFirstContentElement)
                        {
                            if (rs.NumberedList || rs.BulletedList)
                            {
                                this.PaddingLeft = rs.LeftIndent;
                                if (rs.NumberedList)
                                {
                                    this.ParagraphListStyle = ParagraphListStyle.NumberedList;
                                }
                                else if (rs.BulletedList)
                                {
                                    this.ParagraphListStyle = ParagraphListStyle.BulletedList;
                                }
                                this.ParagraphStyleIndex = p.ListIndex;
                            }
                            this.PaddingLeft = rs.LeftIndent + rs.FirstLineIndent;
                        }
                        else
                        {
                            this.PaddingLeft = rs.LeftIndent;
                        }
                    }
                    else
                    {
                        this.PaddingLeft = 0;
                    }
                }
                element.Left = this.PaddingLeft;
                if (this.ParagraphListStyle == Dom.ParagraphListStyle.BulletedList ||
                    this.ParagraphListStyle == Dom.ParagraphListStyle.NumberedList)
                {
                    DomParagraphListItemElement item = new DomParagraphListItemElement();
                    DocumentContentStyle        rs   = element.RuntimeStyle;
                    float size = rs.Font.GetHeight(element.OwnerDocument.DocumentGraphicsUnit);
                    item.Width  = size;
                    item.Height = size;
                    if (this.ParagraphListStyle == Dom.ParagraphListStyle.NumberedList)
                    {
                        item.Width = item.Width * 2;
                    }
                    item.OwnerDocument = element.OwnerDocument;
                    item.StyleIndex    = element.StyleIndex;
                    this.Insert(0, item);
                    // float size = rs.Font.GetHeight(
                }
                //intLeftCount = intLeftCount + element.Width + this.intSpacing ;
                //element.OwnerLine = this ;
                return(true);
            }
            float WidthCount = this.ContentWidth;

            if ((element is DomParagraphFlagElement) == false)
            {
                // 在排版中段落元素不计宽度,可以无条件的添加到文档行中。
                if (WidthCount + element.Width + this._Spacing > this.Width - this.PaddingLeft)
                {
                    return(false);
                }
            }
            DomElement PreElement = ( DomElement )this.List[this.Count - 1];

            element.Left = PreElement.Left + PreElement.Width + this._Spacing;
            this.List.Add(element);
            //intLeftCount = intLeftCount + element.Width + this.intSpacing ;
            //element.OwnerLine = this ;
            return(true);
        }
示例#17
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 );
            //}
        }
示例#18
0
        /// <summary>
        /// 设置多个元素的样式
        /// </summary>
        /// <param name="newStyle">新样式</param>
        /// <param name="document">文档对象</param>
        /// <param name="elements">要设置的元素列表</param>
        /// <returns>操作是否成功</returns>
        internal static bool SetElementStyle(
            DocumentContentStyle newStyle,
            DomDocument document,
            System.Collections.IEnumerable elements)
        {
            if (newStyle == null)
            {
                throw new ArgumentNullException("newStyle");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }
            if (document.Options.SecurityOptions.EnablePermission)
            {
                // 运行授权控制,向样式信息添加用户信息
                newStyle.DisableDefaultValue = false;
                newStyle.CreatorIndex        = document.UserHistories.CurrentIndex;
                newStyle.DeleterIndex        = -1;
            }
            else
            {
                // 去除授权控制相关信息
                newStyle.DisableDefaultValue = false;
                newStyle.CreatorIndex        = -1;
                newStyle.DeleterIndex        = -1;
            }
            Dictionary <DomElement, int> newStyleIndexs
                = new Dictionary <DomElement, int>();
            DomElementList parents    = new DomElementList();
            DomElement     lastParent = null;

            foreach (DomElement element in elements)
            {
                DomElement parent = element.Parent;
                //if (parent != lastParent)
                {
                    // 记录所有涉及到的父元素
                    lastParent = parent;
                    bool addParent = false;
                    //if (element is XTextFieldBorderElement)
                    //{
                    //    addParent = true;
                    //}
                    //else

                    if (addParent)
                    {
                        if (parents.Contains(element.Parent) == false)
                        {
                            parents.Add(element.Parent);
                        }
                    }
                }//if
                DocumentContentStyle rs = (DocumentContentStyle)element.RuntimeStyle.Clone();
                if (XDependencyObject.MergeValues(newStyle, rs, true) > 0)
                {
                    rs.DefaultValuePropertyNames = newStyle.GetDefaultValuePropertyNames();
                    int styleIndex = document.ContentStyles.GetStyleIndex(rs);
                    if (styleIndex != element.StyleIndex)
                    {
                        newStyleIndexs[element] = styleIndex;
                    }
                    if (element.ShadowElement != null && styleIndex != element.ShadowElement.StyleIndex)
                    {
                        newStyleIndexs[element.ShadowElement] = styleIndex;
                    }
                }
            }//foreach
            if (parents.Count > 0)
            {
                // 对涉及到的父元素设置样式
                foreach (DomElement element in parents)
                {
                    DocumentContentStyle rs = (DocumentContentStyle)element.RuntimeStyle.Clone();
                    if (XDependencyObject.MergeValues(newStyle, rs, true) > 0)
                    {
                        rs.DefaultValuePropertyNames = newStyle.GetDefaultValuePropertyNames();
                        int styleIndex = document.ContentStyles.GetStyleIndex(rs);
                        if (styleIndex != element.StyleIndex)
                        {
                            newStyleIndexs[element] = styleIndex;
                        }
                    }
                }
            }
            if (newStyleIndexs.Count > 0)
            {
                DomElementList result = document.EditorSetElementStyle(newStyleIndexs, true);
                if (result != null && result.Count > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#19
0
        /// <summary>
        /// 绘制授权状态标记
        /// </summary>
        /// <param name="element">文档元素对象</param>
        /// <param name="args">参数</param>
        public virtual void DrawPermissionMark(DomElement element, DocumentPaintEventArgs args)
        {
            DocumentContentStyle style = element.Style;

            if (style.DeleterIndex >= 0)
            {
                DomContentLine line   = element.OwnerLine;
                RectangleF     bounds = new RectangleF(
                    element.AbsLeft,
                    line.AbsTop,
                    element.Width + element.WidthFix,
                    line.Height);
                int level = element.DeleterPermissionLevel;
                if (level >= 0)
                {
                    if (level == 0)
                    {
                        args.Graphics.DrawLine(
                            Pens.Blue,
                            bounds.Left,
                            bounds.Top + bounds.Height / 2,
                            bounds.Right,
                            bounds.Top + bounds.Height / 2);
                    }
                    else
                    {
                        float step = bounds.Height / (level + 1);
                        for (int iCount = 1; iCount <= level; iCount++)
                        {
                            args.Graphics.DrawLine(
                                Pens.Red,
                                bounds.Left,
                                bounds.Top + step * iCount,
                                bounds.Right,
                                bounds.Top + step * iCount);
                        }//for
                    }
                }
            }
            else if (style.CreatorIndex >= 0)
            {
                DomContentLine line   = element.OwnerLine;
                RectangleF     bounds = new RectangleF(
                    element.AbsLeft,
                    line.AbsTop,
                    element.Width + element.WidthFix,
                    line.Height);
                int level = element.CreatorPermessionLevel;
                if (level > 0)
                {
                    if (level == 1)
                    {
                        args.Graphics.DrawLine(Pens.Blue, bounds.Left, bounds.Bottom, bounds.Right, bounds.Bottom);
                    }
                    else
                    {
                        args.Graphics.DrawLine(Pens.Blue, bounds.Left, bounds.Bottom, bounds.Right, bounds.Bottom);
                        args.Graphics.DrawLine(Pens.Blue, bounds.Left, bounds.Bottom - 6, bounds.Right, bounds.Bottom - 6);
                    }
                }
            }
        }