public static SizeD MeasureString(Graphics g, string text, Font font, StiTextHorAlignment ha, StiVertAlignment va, bool antialiasing, float angle) { StiTextOptions options = new StiTextOptions(); options.Angle = angle; return(MeasureString(g, text, font, 0, options, ha, va, antialiasing)); }
public static StringFormat GetStringFormat( StiTextOptions textOptions, StiTextHorAlignment ha, StiVertAlignment va, bool antialiasing, float zoom) { var stringFormat = textOptions.GetStringFormat(antialiasing, zoom); stringFormat.Alignment = GetAlignment(ha); stringFormat.LineAlignment = GetAlignment(va); if (MeasureTrailingSpaces) { stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; } return(stringFormat); }
public static StringAlignment GetAlignment(StiTextHorAlignment alignment) { switch (alignment) { case StiTextHorAlignment.Center: case StiTextHorAlignment.Width: return(StringAlignment.Center); case StiTextHorAlignment.Right: return(StringAlignment.Far); default: return(StringAlignment.Near); } }
/// <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, bool antialiasing, float zoom) { using (StringFormat stringFormat = GetStringFormat(textOptions, ha, va, antialiasing, zoom)) { if (ha == StiTextHorAlignment.Width) { DrawStringWidth(g, text, font, brush, rect, stringFormat, textOptions.Angle); } else { DrawString(g, text, font, brush, rect, stringFormat, textOptions.Angle); } } }
public static StringFormat GetStringFormat( StiTextOptions textOptions, StiTextHorAlignment ha, StiVertAlignment va, float zoom) { return(GetStringFormat(textOptions, ha, va, false, zoom)); }
public static SizeD MeasureString(Graphics g, string text, Font font, double width, StiTextOptions textOptions, StiTextHorAlignment ha, StiVertAlignment va, bool antialiasing) { #region Cache for stringFormat - about 4% speed optimization int hashCode; unchecked { hashCode = textOptions.GetHashCode(); hashCode = (hashCode * 397) ^ (int)ha; hashCode = (hashCode * 397) ^ (int)va; hashCode = (hashCode * 397) ^ (antialiasing ? 1231 : 1237); } var stringFormat = (StringFormat)hashStringFormats[hashCode]; if (stringFormat == null) { stringFormat = GetStringFormat(textOptions, ha, va, antialiasing, 1); lock (hashStringFormats) { hashStringFormats[hashCode] = stringFormat; } } #endregion //using (StringFormat stringFormat = GetStringFormat(textOptions, ha, va, antialiasing, 1)) //{ if (!textOptions.WordWrap) { width = 0; } SizeF size = new SizeF((float)width, 0); try { //size = g.MeasureString(text, font, (int)width, stringFormat); size = g.MeasureString(text, font, new SizeF((float)width, 999999f), stringFormat); } catch { size = new SizeF((float)width, 0); } if (textOptions.Angle == 90 || textOptions.Angle == 270) { float rw = size.Width; size.Width = size.Height; size.Height = rw; } else if (textOptions.Angle != 0f) { float sx = (float)size.Width / 2; float sy = (float)size.Height / 2; var points = new PointF[] { new PointF(-sx, -sy), new PointF(sx, -sy), new PointF(sx, sy), new PointF(-sx, sy) }; var m = new Matrix(); m.Rotate(-(float)textOptions.Angle); m.TransformPoints(points); int index = 0; foreach (PointF point in points) { double px = point.X; double py = point.Y; points[index++] = new PointF((float)(px + size.Width / 2), (float)(py + size.Height / 2)); } using (var path = new GraphicsPath()) { path.AddPolygon(points); var rect2 = path.GetBounds(); return(new SizeD(rect2.Width, rect2.Height)); } } return(new SizeD(size.Width, size.Height)); //} }
public static SizeD MeasureString(Graphics g, string text, Font font, StiTextHorAlignment ha, StiVertAlignment va, float angle) { return(MeasureString(g, text, font, ha, va, false, angle)); }
/// <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); }
public ITextProperties <T> WithAlign(StiTextHorAlignment alignment = StiTextHorAlignment.Left) { CurrentText.HorAlignment = alignment; return((ITextProperties <T>) this); }