/// <summary> /// 绘制元素 /// </summary> /// <param name="g">图形绘制对象</param> /// <param name="ClipRectangle">剪切矩形</param> protected virtual void DrawContent(DomLineBreakElement element, DocumentPaintEventArgs args) { if (_LineBreakIcon == null) { _LineBreakIcon = ( Bitmap )WriterResources.linebreak.Clone(); _LineBreakIcon.MakeTransparent(System.Drawing.Color.White); } System.Drawing.RectangleF rect = element.AbsBounds; if (args.RenderStyle == DocumentRenderStyle.Paint) { System.Drawing.Size size = _LineBreakIcon.Size; size = this.Document.PixelToDocumentUnit(size); args.Graphics.DrawImage(_LineBreakIcon, rect.Left, rect.Bottom - size.Height); //WriterUtils.DrawParagraphFlag( g , rect ); } }
/// <summary> /// 刷新元素大小 /// </summary> /// <param name="g">参数</param> protected virtual void RefreshSize(DomLineBreakElement element, System.Drawing.Graphics g) { float h = this.Document.DefaultStyle.DefaultLineHeight; // XTextElement e = myOwnerDocument.Content.GetPreElement( this ); // if( e != null && e.Height > 0 && e.OwnerLine == this.OwnerLine ) // { // h = e.Height ; // } // h = Math.Max( h , myOwnerDocument.PixelToDocumentUnit( 10 )); element.Height = h; element.Width = this.Document.PixelToDocumentUnit(10); element.SizeInvalid = false; // this.intHeight = ( int ) Math.Ceiling( myOwnerDocument.BodyFont.GetHeight( g ));// size.Height ); // this.intWidth = ( int ) ( intHeight * 0.8 ); //// System.Drawing.SizeF size = g.MeasureString( "H" , myOwnerDocument.BodyFont , 1000 , System.Drawing.StringFormat.GenericTypographic ); //// this.Width = ( int ) Math.Ceiling( size.Height ); //// this.Height = ( int ) Math.Ceiling( size.Height ); // this.bolSizeInvalid = false ; }
/// <summary> /// 刷新状态 /// </summary> /// <returns>操作是否成功</returns> public bool RefreshState() { if (this.Count == 0) { return(false); } DocumentControler controler = null; foreach (DomElement element in this) { if (element.OwnerDocument != null) { controler = element.OwnerDocument.DocumentControler; break; } } //XTextParagraphFlagElement pe = this.LastElement as XTextParagraphFlagElement ; //if( pe != null ) //{ // pe.RefreshSize2( this.SafeGet( this.Count - 2 )); //} DomLineBreakElement lb = this.LastElement as DomLineBreakElement; if (lb != null) { lb.RefreshSize2(this.SafeGet(this.Count - 2)); } // if( this.Count == 1 ) // { // XTextElement element = this[ 0 ]; // this.intHeight = element.Height + LineHeighFix + this.LineSpacing ; // element.Left = this.intMargin ; // element.Top = 0 ; // return true ; // } this._ContentHeight = -1; float contentWidth = 0; float lineHeight = 10; foreach (DomElement element in this) { contentWidth = contentWidth + this.Spacing + element.Width; element.WidthFix = 0; float eh = element.Height; //if (element is XTextCharElement) //{ // XTextCharElement chr = (XTextCharElement)element; // eh = Math.Max(eh, chr._FontHeight); //} if (eh > lineHeight) { lineHeight = eh; } element.OwnerLine = this; }//foreach contentWidth -= this.Spacing; this.Height = ( float )Math.Ceiling(lineHeight + LineHeighFix); // if( EOF != null ) // EOF.Height = this.intHeight ; bool CanFix = true; if (this.Count == 1) { CanFix = false; } else { if (this.HasLineEndElement)// this.OwnerDocument.IsNewLine( this.LastElement ) || this.LastElement is XTextEOF ) { CanFix = false; } else if (this.OwnerContentElement.PrivateLines.LastLine == this) { CanFix = false; } } DocumentContentAlignment align = this.Align; // 元素空白平均修正量 float fix = 0; // 总空白量 float Blank = this.Width - this.PaddingLeft - contentWidth; if (Blank < 0) { return(false); } if (CanFix) { // 计算由于元素分组而损失的空白区域个数 // 文档中连续的英文和数字字符之间没有修正空白,制表符和书签也拒绝修正空白 // 由于存在拒绝修正空白,导致空白分摊的元素减少,此处就修正这种空白分摊元素 // 减少而带来的影响 int GroupFix = 0; for (int iCount = 0; iCount < this.Count; iCount++) { DomCharElement c = this[iCount] as DomCharElement; if (c != null) { if (c.CharValue == '\t') { GroupFix++; } else if (iCount < this.Count - 1) { if (controler.IsEnglishLetterOrDigit(c.CharValue)) { DomCharElement c2 = this[iCount + 1] as DomCharElement; if (c2 != null && controler.IsEnglishLetterOrDigit(c2.CharValue)) { GroupFix++; } } } } } if (GroupFix > this.Count - 2) { GroupFix = 0; } if (this.Count > 1) { fix = (int)Math.Ceiling(Blank / (this.Count - 1.0 - GroupFix)); } if (fix < 0) { fix = 0; } align = DocumentContentAlignment.Justify; } else { fix = 0; } float leftCount = 0; if (align == DocumentContentAlignment.Left) { leftCount = this.PaddingLeft; } else if (align == DocumentContentAlignment.Center) { leftCount = this.PaddingLeft + (this.Width - this.PaddingLeft - contentWidth) / 2; } else if (align == DocumentContentAlignment.Right) { leftCount = this.PaddingLeft + (this.Width - this.PaddingLeft - contentWidth); } else { leftCount = this.PaddingLeft; } //foreach( XTextElement element in this ) for (int iCount = 0; iCount < this.Count; iCount++) { DomElement element = this[iCount]; element.Left = leftCount; float ctf = ContentTopFix; //if (this.AdditionHeight < 0) //{ // ctf = ctf + this.AdditionHeight; //} switch (this.VerticalAlign) { case VerticalAlignStyle.Top: element.Top = ContentTopFix; break; case VerticalAlignStyle.Middle: element.Top = ContentTopFix + (lineHeight - element.Height) / 2.0f; break; case VerticalAlignStyle.Bottom: element.Top = ctf + lineHeight - element.Height; break; case VerticalAlignStyle.Justify: element.Top = ContentTopFix + (lineHeight - element.Height) / 2.0f; break; default: element.Top = ctf + lineHeight - element.Height; break; }//switch //bool IsTab = false ; bool FixFlag = true; // TAB制表符不接收修正空隙 if (element is DomCharElement) { DomCharElement c = ( DomCharElement )element; if (c.CharValue == '\t') { FixFlag = false; } else if (iCount < this.Count - 1) { if (controler.IsEnglishLetterOrDigit(c.CharValue)) { DomCharElement c2 = this[iCount + 1] as DomCharElement; if (c2 != null && controler.IsEnglishLetterOrDigit(c2.CharValue)) { FixFlag = false; } } } } // // 出现拒绝修正情况,重新计算平均修正空隙 // if( CanFix && FixFlag == false ) // { // if( iCount < this.Count - 2 ) // { // Blank = ( this.intWidth - LeftCount - element.Width ) ; // for( int iCount2 = iCount + 1 ; iCount2 < this.Count ; iCount2 ++ ) // { // Blank -= this[ iCount ].Width ; // } // if( Blank > 0 ) // { // fix = Blank / ( this.Count - iCount - 1.0 ); // } // else // fix = 0 ; // } // } // else if( element is XTextNull ) // { // // 若元素是没有实际意义的占位符合则不接收修正空隙 // FixFlag = false; // } if (CanFix && FixFlag) { if (Blank < fix) { fix = Blank; } element.WidthFix = fix + _Spacing; Blank -= fix; if (Blank <= 0) { fix = 0; Blank = 0; } } else { element.WidthFix = _Spacing; } leftCount = leftCount + element.Width + element.WidthFix; } //this.Height += this.LineSpacing ; return(true); }