/// <summary> /// 高斯-勒让德算法 super pi 使用 /// </summary> /// <returns></returns> public static decimal CalculatePi_SuperPi_decimal() { decimal a = 1; decimal b = 1 / MathCommon.Sqrt(2m); decimal t = 1 / (decimal)4; decimal p = 1; int maxN = 10; for (int n = 0; n < maxN; ++n) { decimal nextA = (a + b) / 2; decimal nextB = MathCommon.Sqrt(a * b); decimal nextT = t - p * (a - nextA) * (a - nextA); decimal nextP = 2 * p; a = nextA; b = nextB; t = nextT; p = nextP; } decimal pi = (a + b) * (a + b) / (4 * t); return(pi); }
/// <summary> /// 根据插入点所在的容器来修正图片元素的大小 /// </summary> /// <param name="document">文档对象</param> /// <param name="element">图片元素</param> public static void CheckImageSizeWhenInsertImage(DomDocument document, DomImageElement element) { if (document.Options.EditOptions.FixWidthWhenInsertImage) { DomContainerElement container = null; int elementIndex = 0; document.Content.GetCurrentPositionInfo(out container, out elementIndex); container = container.ContentElement; SizeF size = new SizeF(element.Width, element.Height); size = MathCommon.FixSize( new SizeF(container.ClientWidth - document.PixelToDocumentUnit(2), 100000), size, element.KeepWidthHeightRate); element.Width = size.Width; element.Height = size.Height; } }
/// <summary> /// 使用指定图形绘制对象从指定位置开始绘制页面框架 /// </summary> /// <param name="g">图形绘制对象</param> /// <param name="ClipRectangle">剪切矩形</param> public void DrawPageFrame( System.Drawing.Graphics g, System.Drawing.Rectangle ClipRectangle) { using (RectangleDrawer drawer = new RectangleDrawer()) { drawer.Bounds = this.myBounds; drawer.RoundRadio = 9; if (this.intBorderColor.A != 0 && this.intBorderWidth > 0) { drawer.BorderPen = new System.Drawing.Pen( this.intBorderColor, this.intBorderWidth); } if (this.intBackColor.A != 0) { drawer.FillBrush = new System.Drawing.SolidBrush(this.intBackColor); } if (drawer.Draw(g, ClipRectangle)) { if (myBackgroundImage != null) { // 绘制页面背景图片 Rectangle ir = new Rectangle( myBounds.Left, myBounds.Top, myBounds.Width, myBounds.Height); if (ClipRectangle.IsEmpty == false) { ir = System.Drawing.Rectangle.Intersect(ir, ClipRectangle); } if (ir.IsEmpty == false) { using (TextureBrush brush = new TextureBrush(myBackgroundImage)) { brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; float rate = (float)GraphicsUnitConvert.GetRate( g.PageUnit, System.Drawing.GraphicsUnit.Pixel); brush.TranslateTransform( myBounds.Left, myBounds.Top); brush.ScaleTransform(rate, rate); g.FillRectangle(brush, ir); } //using drawer.DrawBorder(g, ClipRectangle); } //if //Rectangle ir = new Rectangle( // myBounds.Left + this.LeftMargin, // myBounds.Top + this.TopMargin, // myBounds.Width - this.LeftMargin - this.RightMargin, // myBounds.Height - this.TopMargin - this.BottomMargin); //if (ClipRectangle.IsEmpty == false) //{ // ir = System.Drawing.Rectangle.Intersect(ir, ClipRectangle); //} //if (ir.IsEmpty == false) //{ // using (TextureBrush brush = new TextureBrush(myBackgroundImage)) // { // brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; // float rate = (float)GraphicsUnitConvert.GetRate( // g.PageUnit, // System.Drawing.GraphicsUnit.Pixel); // brush.TranslateTransform( // myBounds.Left + this.LeftMargin, // myBounds.Top + this.TopMargin); // brush.ScaleTransform(rate, rate); // g.FillRectangle(brush, ir); // }//using //}//if } if (this.bolDrawMargin && this.intMarginLineColor.A != 0 && this.intMarginLineLength > 0) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle( myBounds.Left + this.intLeftMargin - 1, myBounds.Top + this.intTopMargin, myBounds.Width - this.intLeftMargin - this.intRightMargin + 2, myBounds.Height - this.intTopMargin - this.intBottomMargin); System.Drawing.Point[] ps = new System.Drawing.Point[16]; ps[0] = rect.Location; ps[1].X = rect.Left - intMarginLineLength; ps[1].Y = rect.Top; ps[2] = ps[0]; ps[3].X = rect.Left; ps[3].Y = rect.Top - intMarginLineLength; ps[4].X = rect.Right; ps[4].Y = rect.Top; ps[5].X = rect.Right + intMarginLineLength; ps[5].Y = rect.Top; ps[6] = ps[4]; ps[7].X = rect.Right; ps[7].Y = rect.Top - intMarginLineLength; ps[8].X = rect.Right; ps[8].Y = rect.Bottom; ps[9].X = rect.Right + intMarginLineLength; ps[9].Y = rect.Bottom; ps[10] = ps[8]; ps[11].X = rect.Right; ps[11].Y = rect.Bottom + intMarginLineLength; ps[12].X = rect.Left; ps[12].Y = rect.Bottom; ps[13].X = rect.Left; ps[13].Y = rect.Bottom + intMarginLineLength; ps[14] = ps[12]; ps[15].X = rect.Left - intMarginLineLength; ps[15].Y = rect.Bottom; MathCommon.RectangleClipLines(myBounds, ps); using (System.Drawing.Pen p = new System.Drawing.Pen( this.intMarginLineColor, 1)) { for (int iCount = 0; iCount < ps.Length; iCount += 2) { g.DrawLine(p, ps[iCount], ps[iCount + 1]); } } //using( System.Drawing.Pen p = new System.Drawing.Pen( this.intMarginLineColor , 1 )) } //if( this.bolDrawMargin && this.intMarginLineColor.A != 0 ) } //if( drawer.Draw( g , ClipRectangle )) } //using( RectangleDrawer drawer = new RectangleDrawer() ) } //public void DrawPageFrame()