/// <summary> /// Draws the text. /// </summary> /// <param name="p">The p.</param> /// <param name="text">The text.</param> /// <param name="c">The c.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="fontWeight">The font weight.</param> /// <param name="rotate">The rotate.</param> /// <param name="halign">The horizontal alignment.</param> /// <param name="valign">The vertical alignment.</param> /// <param name="maxSize">Size of the max.</param> public override void DrawText(ScreenPoint p, string text, OxyColor c, string fontFamily, double fontSize, double fontWeight, double rotate, OxyPlot.HorizontalAlignment halign, OxyPlot.VerticalAlignment valign, OxySize?maxSize) { if (string.IsNullOrEmpty(text)) { return; } string[] array = Regex.Split(text, "\r\n"); if (valign == OxyPlot.VerticalAlignment.Bottom) { for (int i = array.Length - 1; i >= 0; i--) { string text2 = array[i]; OxySize oxySize = this.MeasureText(text2, fontFamily, fontSize, fontWeight); this.w.WriteText(p, text2, c, fontFamily, fontSize, fontWeight, rotate, halign, valign); p += new ScreenVector(Math.Sin(rotate / 180.0 * 3.1415926535897931) * oxySize.Height, Math.Cos(rotate / 180.0 * 3.1415926535897931) * oxySize.Height); } return; } string[] array2 = array; if (text.Contains(".")) { p += new ScreenVector(0.0, 8.0); } else { p += new ScreenVector(0.0, 14.0); } for (int j = 0; j < array2.Length; j++) { string text3 = array2[j]; OxySize oxySize2 = this.MeasureText(text3, fontFamily, fontSize, fontWeight); this.w.WriteText(p, text3, c, fontFamily, fontSize, fontWeight, rotate, halign, valign); p += new ScreenVector(-Math.Sin(rotate / 180.0 * 3.1415926535897931) * oxySize2.Height, Math.Cos(rotate / 180.0 * 3.1415926535897931) * oxySize2.Height); } }
void IRenderContext.DrawText(ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotation, OxyPlot.HorizontalAlignment horizontalAlignment, OxyPlot.VerticalAlignment verticalAlignment, OxySize?maxSize) { throw new NotImplementedException(); }
private void AddText(string textToAdd, DrawingContext drawContext, int canvasWidth, int canvasHeight, OxyPlot.HorizontalAlignment hAlign, OxyPlot.VerticalAlignment vAlign, int padding) { var usCulture = CultureInfo.GetCultureInfo("en-us"); // var fontTypeface = new Typeface(new FontFamily("Arial"), FontStyles.Normal, System.Windows.FontWeights.Normal, FontStretches.Normal); var fontTypeface = new Typeface("Arial"); var fontSizeEm = FontSizeBase + 1; var newText = new FormattedText(textToAdd, usCulture, FlowDirection.LeftToRight, fontTypeface, fontSizeEm, Brushes.Black, null, PIXELS_PER_DIP); var textRect = new Rect(0, 0, canvasWidth, canvasHeight); var position = textRect.Location; switch (hAlign) { case OxyPlot.HorizontalAlignment.Left: position.X += padding; break; case OxyPlot.HorizontalAlignment.Center: position.X += (textRect.Width - newText.Width) / 2; break; case OxyPlot.HorizontalAlignment.Right: position.X += textRect.Width - newText.Width - padding; break; } switch (vAlign) { case OxyPlot.VerticalAlignment.Top: position.Y += padding; break; case OxyPlot.VerticalAlignment.Middle: position.Y += (textRect.Height - newText.Height) / 2; break; case OxyPlot.VerticalAlignment.Bottom: position.Y += textRect.Height - newText.Height - padding; break; } drawContext.DrawText(newText, position); }