/// <summary> /// Draws text with metrics. /// </summary> /// <param name="text">The text.</param> /// <param name="font">The font.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="expectedWidth">The expected width.</param> /// <param name="expectedHeight">The expected height.</param> /// <param name="baseline">The baseline position.</param> /// <param name="xheight">The x-height position.</param> /// <param name="ascent">The ascent position.</param> /// <param name="descent">The descent position.</param> /// <param name="before">The before position.</param> /// <param name="after">The after position.</param> /// <param name="platform">The platform.</param> /// <returns> /// A plot model. /// </returns> private static PlotModel DrawTextWithMetrics(string text, string font, double fontSize, double expectedWidth, double expectedHeight, double baseline, double xheight, double ascent, double descent, double before, double after, string platform) { // http://msdn.microsoft.com/en-us/library/ms742190(v=vs.110).aspx // http://msdn.microsoft.com/en-us/library/xwf9s90b(v=vs.110).aspx // http://msdn.microsoft.com/en-us/library/windows/desktop/ms533824(v=vs.85).aspx // https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/FontHandling/FontHandling.html var model = new PlotModel(); model.Annotations.Add( new DelegateAnnotation( rc => { var size = rc.MeasureText(text, font, fontSize); var expectedSize = new OxySize(expectedWidth, expectedHeight); rc.DrawText(new ScreenPoint(300, 50), "Font size: " + fontSize, OxyColors.Black, font, 12); rc.DrawText(new ScreenPoint(300, 70), "Actual size: " + size.ToString("0.00", CultureInfo.InvariantCulture), OxyColors.Black, font, 12); rc.DrawText(new ScreenPoint(300, 90), "Size on " + platform + ": " + expectedSize.ToString("0.00", CultureInfo.InvariantCulture), OxyColors.Green, font, 12); var p = new ScreenPoint(20, 50); rc.DrawText(p, text, OxyColors.Black, font, fontSize); rc.FillCircle(p, 3, OxyColors.Black); // actual bounds rc.DrawRectangle(new OxyRect(p, size), OxyColors.Undefined, OxyColors.Black); // Expected bounds (WPF) rc.DrawRectangle(new OxyRect(p, expectedSize), OxyColors.Undefined, OxyColors.Green); var color = OxyColor.FromAColor(180, OxyColors.Red); var pen = new OxyPen(color); // Expected vertical positions (WPF) var x1 = p.X - 10; var x2 = p.X + expectedSize.Width + 10; rc.DrawLine(x1, baseline, x2, baseline, pen); rc.DrawLine(x1, xheight, x2, xheight, pen); rc.DrawLine(x1, ascent, x2, ascent, pen); rc.DrawLine(x1, descent, x2, descent, pen); // Expected horizonal positions (WPF) var y1 = p.Y - 10; var y2 = p.Y + expectedSize.Height + 10; rc.DrawLine(before, y1, before, y2, pen); rc.DrawLine(after, y1, after, y2, pen); })); model.MouseDown += (s, e) => Debug.WriteLine(e.Position); return(model); }