Skip to content

Commit

Permalink
Wpf: TextFormattingMode should be consistent for text measuring and d…
Browse files Browse the repository at this point in the history
…rawing

Setting default text formatting mode to Display.
  • Loading branch information
objorke committed Jul 11, 2014
1 parent c7efec2 commit d26989a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Source/OxyPlot.Wpf/RenderContexts/ShapesRenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class ShapesRenderContext : IRenderContext
public ShapesRenderContext(Canvas canvas)
{
this.canvas = canvas;
this.TextFormattingMode = TextFormattingMode.Display;
this.TextMeasurementMethod = TextMeasurementMethod.TextBlock;
this.UseStreamGeometry = true;
this.RendersToScreen = true;
Expand All @@ -135,6 +136,12 @@ public ShapesRenderContext(Canvas canvas)
/// <value>The text measurement method.</value>
public TextMeasurementMethod TextMeasurementMethod { get; set; }

/// <summary>
/// Gets or sets the text formatting mode.
/// </summary>
/// <value>The text formatting mode. The default value is <see cref="System.Windows.Media.TextFormattingMode.Display"/>.</value>
public TextFormattingMode TextFormattingMode { get; set; }

/// <summary>
/// Gets or sets the thickness limit for "balanced" line drawing.
/// </summary>
Expand Down Expand Up @@ -531,6 +538,8 @@ public void DrawText(
tb.FontWeight = GetFontWeight(fontWeight);
}

TextOptions.SetTextFormattingMode(tb, this.TextFormattingMode);

double dx = 0;
double dy = 0;

Expand Down Expand Up @@ -629,6 +638,8 @@ public OxySize MeasureText(string text, string fontFamily, double fontSize, doub

var tb = new TextBlock { Text = text };

TextOptions.SetTextFormattingMode(tb, this.TextFormattingMode);

if (fontFamily != null)
{
tb.FontFamily = new FontFamily(fontFamily);
Expand Down
13 changes: 10 additions & 3 deletions Source/OxyPlot.Xps/XpsExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace OxyPlot.Xps
using System.Printing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Xps.Packaging;

using OxyPlot.Wpf;
Expand Down Expand Up @@ -69,6 +70,12 @@ public XpsExporter()
/// </summary>
public OxyColor Background { get; set; }

/// <summary>
/// Gets or sets the text formatting mode.
/// </summary>
/// <value>The text formatting mode.</value>
public TextFormattingMode TextFormattingMode { get; set; }

/// <summary>
/// Exports the specified plot model to an xps file.
/// </summary>
Expand All @@ -87,7 +94,7 @@ public static void Export(IPlotModel model, string fileName, double width, doubl
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, width, height));

var rc = new ShapesRenderContext(canvas);
var rc = new ShapesRenderContext(canvas) { TextFormattingMode = TextFormattingMode.Ideal };
model.Update(true);
model.Render(rc, width, height);

Expand Down Expand Up @@ -139,7 +146,7 @@ public void Export(IPlotModel model, Stream stream)
canvas.Measure(new Size(this.Width, this.Height));
canvas.Arrange(new Rect(0, 0, this.Width, this.Height));

var rc = new ShapesRenderContext(canvas);
var rc = new ShapesRenderContext(canvas) { TextFormattingMode = this.TextFormattingMode };
model.Update(true);
model.Render(rc, this.Width, this.Height);

Expand Down Expand Up @@ -177,7 +184,7 @@ public void Print(IPlotModel model)
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, width, height));

var rc = new ShapesRenderContext(canvas);
var rc = new ShapesRenderContext(canvas) { TextFormattingMode = this.TextFormattingMode };
model.Update(true);
model.Render(rc, width, height);

Expand Down

0 comments on commit d26989a

Please sign in to comment.