/// <summary> /// Draws a rectangle specified by a Rectangle structure. /// </summary> /// <param name="g">The Graphics to draw on.</param> /// <param name="pen">A Pen object that determines the color, width, and style of the rectangle.</param> /// <param name="rect">A Rectangle structure that represents the rectangle to draw.</param> public static void DrawRectangle(Graphics g, Pen pen, RectangleD rect) { g.DrawRectangle(pen, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height); }
/// <summary> /// Draws text. /// </summary> /// <param name="g">Graphics to draw on.</param> /// <param name="text">Text to draw on.</param> /// <param name="font">Font to draw on.</param> /// <param name="brush">Brush to draw.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="textOptions">Options to show text.</param> /// <param name="ha">Horizontal alignment.</param> /// <param name="va">Vertical alignment.</param> public static void DrawString(Graphics g, string text, Font font, Brush brush, RectangleD rect, StiTextOptions textOptions, StiTextHorAlignment ha, StiVertAlignment va) { DrawString(g, text, font, brush, rect, textOptions, ha, va, false, 1); }
/// <summary> /// Draws a rectangle specified by a Rectangle structure. /// </summary> /// <param name="g">The Graphics to draw on.</param> /// <param name="color">Color to draw Rectangle.</param> /// <param name="rect">A Rectangle structure that represents the rectangle to draw.</param> public static void DrawRectangle(Graphics g, Color color, RectangleD rect) { using (Pen pen = new Pen(color)) DrawRectangle(g, pen, rect); }
public static void DrawString(Graphics g, string text, Font font, Brush brush, RectangleF rect, StringFormat stringFormat, float angle) { DrawString(g, text, font, brush, RectangleD.CreateFromRectangle(rect), stringFormat, angle); }
/// <summary> /// Draws text at an angle. /// </summary> /// <param name="g">Graphics to draw on.</param> /// <param name="text">Text to draw on.</param> /// <param name="font">Font to draw on.</param> /// <param name="brush">Brush to draw.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="stringFormat">Text format.</param> public static void DrawString(Graphics g, string text, Font font, Brush brush, RectangleD rect, StringFormat stringFormat) { DrawString(g, text, font, brush, rect, stringFormat, 0); }
/// <summary> /// Draws this border on the indicated Graphics. /// </summary> /// <param name="g">Graphics on which a border can be drawn.</param> /// <param name="rect">The rectangle that indicates an area of the border drawing.</param> /// <param name="zoom">The scale of a border to draw.</param> /// <param name="emptyColor">The color of space between double lines (used only when border style equal Double).</param> public void Draw(Graphics g, RectangleD rect, double zoom, Color emptyColor) { Draw(g, rect.ToRectangleF(), (float)zoom, emptyColor); }
/// <summary> /// Returns ranges array. /// </summary> /// <param name="g">Graphics to measure sizes.</param> /// <param name="rect">Describes a rectangle.</param> /// <param name="text">Text for burst into arrays.</param> /// <param name="font">Font of the text.</param> /// <param name="sf">Text format.</param> /// <returns>Ranges.</returns> private static StiRange[] GetRange(Graphics g, RectangleD rect, string text, Font font, StringFormat sf) { var rn = new List <StiRange>(); var txt = StiTxt.GetTexts(text); var ln = new List <Line>(); double heightFont = font.Height; //Form words for (int k = 0; k < txt.Length; k++) { var size = g.MeasureString(txt[k].Text, font); rn.Add(new StiRange(txt[k].Text, new SizeD(size.Width, size.Height), txt[k].IsEnter)); } #region Divide into lines double posX = rect.Left; double posY = rect.Top; int line = 1; int wordCount = 0; int start = 0; bool forceNewLine = false; var ranges = rn.ToArray(); float spaceSize = g.MeasureString(" ", font, 100000, sf).Width / 2; for (int k = 0; k < ranges.Length; k++) { posX += ranges[k].Size.Width - spaceSize; if (forceNewLine || (posX >= rect.Right && wordCount >= 1)) { posX = rect.Left + ranges[k].Size.Width; line++; posY += heightFont; ln.Add(new Line(start, wordCount, forceNewLine)); start = k; wordCount = 0; } wordCount++; ranges[k].Line = line; ranges[k].Pos.Y = posY; forceNewLine = ranges[k].NewLineForm; } ln.Add(new Line(start, wordCount, true)); #endregion var lines = ln.ToArray(); #region Examine lines and sets horizontal coordinates for (int h = 0; h < lines.Length; h++) { int startPos = lines[h].Start; int endPos = lines[h].Start + lines[h].Count - 1; ranges[startPos].IsStart = true; ranges[endPos].IsEnd = true; #region Last line or line finishing Enter if (lines[h].IsEnter) { posX = rect.Left; for (int f = startPos; f <= endPos; f++) { ranges[f].Pos.X = posX; posX += ranges[f].Size.Width; } } #endregion else { #region One word if (lines[h].Count == 1) { ranges[startPos].Pos.X = rect.Left; } #endregion #region Much words else { ranges[startPos].Pos.X = rect.Left; ranges[endPos].Pos.X = rect.Right - ranges[endPos].Size.Width; double space = 0; if (lines[h].Count > 2) { double wx = 0; for (int a = startPos + 1; a < endPos; a++) { wx += ranges[a].Size.Width; } space = ((rect.Width - ranges[startPos].Size.Width - ranges[endPos].Size.Width - wx) / (lines[h].Count - 1)); } posX = ranges[startPos].Size.Width + rect.Left + space; for (int f = startPos + 1; f < endPos; f++) { ranges[f].Pos.X = posX; posX += space + ranges[f].Size.Width; } } #endregion } } #endregion #region Aligning the text if (sf.LineAlignment != StringAlignment.Near) { double allHeight = heightFont * lines.Length; double dist = 0; if (sf.LineAlignment == StringAlignment.Far) { dist = rect.Height - allHeight; } if (sf.LineAlignment == StringAlignment.Center) { dist = (rect.Height - allHeight) / 2; } for (int k = 0; k < ranges.Length; k++) { ranges[k].Pos.Y += dist; } } #endregion #region Correct of the text (LineLimit & Trimming) for (int k = 0; k < ranges.Length; k++) { CorrectSize(ref ranges[k], rect); } #endregion return(ranges); }
//public override int GetHashCode() //{ // return base.GetHashCode(); //} //public override bool Equals(Object obj) //{ // StiBorder border = obj as StiBorder; // if (border == null) return false; // if (border.bits == null && this.bits == null) return true; // if (border.bits != null && this.bits == null) return false; // if (border.bits == null && this.bits != null) return false; // if (this.bits.Color != border.bits.Color) return false; // if (!this.bits.Side.Equals(border.bits.Side)) return false; // if (this.bits.Size != border.bits.Size) return false; // if (!this.bits.Style.Equals(border.bits.Style)) return false; // if (this.bits.ShadowSize != border.bits.ShadowSize) return false; // if (this.bits.DropShadow != border.bits.DropShadow) return false; // if (this.bits.Topmost != border.bits.Topmost) return false; // if (!((this.shadowBrush == null) && (border.shadowBrush == null))) // { // if (!this.shadowBrush.Equals(border.shadowBrush)) return false; // } // return true; //} /// <summary> /// Draws this border on the indicated Graphics. /// </summary> /// <param name="g">Graphics on which a border can be drawn.</param> /// <param name="rect">The rectangle that indicates an area of the border drawing.</param> /// <param name="zoom">The scale of a border to draw.</param> public void Draw(Graphics g, RectangleD rect, double zoom) { Draw(g, rect, zoom, Color.White); }
/// <summary> /// Returns the standard brush from the report brush. /// </summary> /// <param name="brush">Report brush.</param> /// <param name="rect">Rectangle for gradient.</param> /// <returns>Gdi brush.</returns> public static Brush GetBrush(StiBrush brush, RectangleD rect) { if (brush is StiEmptyBrush) { return(new SolidBrush(Color.Transparent)); } else if (brush is StiSolidBrush) { return(new SolidBrush(((StiSolidBrush)brush).Color)); } else if (brush is StiGradientBrush) { RectangleF rectF = rect.ToRectangleF(); if (rectF.Width < 1) { rectF.Width = 1; } if (rectF.Height < 1) { rectF.Height = 1; } StiGradientBrush gradientBrush = brush as StiGradientBrush; return(new LinearGradientBrush(rectF, gradientBrush.StartColor, gradientBrush.EndColor, (float)gradientBrush.Angle)); } else if (brush is StiHatchBrush) { StiHatchBrush hatchBrush = brush as StiHatchBrush; return(new HatchBrush(hatchBrush.Style, hatchBrush.ForeColor, hatchBrush.BackColor)); } else if (brush is StiGlareBrush) { RectangleF rectF = rect.ToRectangleF(); if (rectF.Width < 1) { rectF.Width = 1; } if (rectF.Height < 1) { rectF.Height = 1; } StiGlareBrush glareBrush = brush as StiGlareBrush; LinearGradientBrush br = new LinearGradientBrush(rectF, glareBrush.StartColor, glareBrush.EndColor, (float)glareBrush.Angle); br.SetSigmaBellShape(glareBrush.Focus, glareBrush.Scale); return(br); } else if (brush is StiGlassBrush) { Bitmap bmp = new Bitmap((int)rect.Width + 1, (int)rect.Height + 1); using (Graphics gg = Graphics.FromImage(bmp)) { ((StiGlassBrush)brush).Draw(gg, new RectangleF(0, 0, (float)rect.Width + 1, (float)rect.Height + 1)); } TextureBrush textureBrush = new TextureBrush(bmp); textureBrush.TranslateTransform((float)rect.X, (float)rect.Y); return(textureBrush); } return(null); }
/// <summary> /// Returns the gdi brush from the report brush. /// </summary> /// <param name="brush">Report brush.</param> /// <param name="rect">Rectangle for gradient.</param> /// <returns>Gdi brush.</returns> public static Brush GetBrush(StiBrush brush, RectangleF rect) { return(GetBrush(brush, RectangleD.CreateFromRectangle(rect))); }
/// <summary> /// Checks does the point fit into the position. /// </summary> /// <param name="x">X point.</param> /// <param name="y">Y point.</param> /// <param name="rect"></param> /// <returns>true, if the point fits to the position, and false, if not.</returns> public static bool PointInRect(float x, float y, RectangleF rect) { return(PointInRect(x, y, RectangleD.CreateFromRectangle(rect))); }
/// <summary> /// Returns the action fits to the position of a point in the specified rectangle. /// </summary> /// <param name="size">Tolerable limit size.</param> /// <param name="x">X point.</param> /// <param name="y">Y point.</param> /// <param name="sizeRect">Rectangle of sizes.</param> /// <param name="selectRect">Rectangle of selection.</param> /// <param name="isSelected">Indicates, is this rectangle selected or not?</param> /// <param name="locked">Indicates, is this ectangle locked or not?</param> /// <returns>Action.</returns> public static StiAction PointInRect(double size, double x, double y, RectangleD sizeRect, RectangleD selectRect, bool isSelected, bool locked) { if (isSelected && locked == false) { //SizeLeftTop if (PointInEdge(x, y, new PointD(sizeRect.X, sizeRect.Y), size)) { return(StiAction.SizeLeftTop); } //SizeRightTop else if (PointInEdge(x, y, new PointD(sizeRect.X + sizeRect.Width, sizeRect.Y), size)) { return(StiAction.SizeRightTop); } //SizeLeftBottom else if (PointInEdge(x, y, new PointD(sizeRect.X, sizeRect.Y + sizeRect.Height), size)) { return(StiAction.SizeLeftBottom); } //SizeRightBottom else if (PointInEdge(x, y, new PointD(sizeRect.X + sizeRect.Width, sizeRect.Y + sizeRect.Height), size)) { return(StiAction.SizeRightBottom); } //SizeTop else if (PointInEdge(x, y, new PointD(sizeRect.X + sizeRect.Width / 2, sizeRect.Y), size)) { return(StiAction.SizeTop); } //SizeBottom else if (PointInEdge(x, y, new PointD(sizeRect.X + sizeRect.Width / 2, sizeRect.Y + sizeRect.Height), size)) { return(StiAction.SizeBottom); } //SizeLeft else if (PointInEdge(x, y, new PointD(sizeRect.X, sizeRect.Y + sizeRect.Height / 2), size)) { return(StiAction.SizeLeft); } //SizeRight else if (PointInEdge(x, y, new PointD(sizeRect.X + sizeRect.Width, sizeRect.Y + sizeRect.Height / 2), size)) { return(StiAction.SizeRight); } } decimal selectRectLeft = Math.Round((decimal)selectRect.Left, 2); decimal selectRectTop = Math.Round((decimal)selectRect.Top, 2); decimal selectRectRight = Math.Round((decimal)selectRect.Right, 2); decimal selectRectBottom = Math.Round((decimal)selectRect.Bottom, 2); decimal xx = Math.Round((decimal)x, 2); decimal yy = Math.Round((decimal)y, 2); if ((selectRectLeft <= xx) & (selectRectTop <= yy) & (selectRectBottom >= yy) & (selectRectRight >= xx)) { return(StiAction.Move); } return(StiAction.None); }