Wpf 4.0: Drawing Aliased FormattedText/GlyphRun?
In Wpf 4.0 you can turn off Text antialiasing for a Frameworkelement and all its children by putti开发者_如何转开发ng this e.g. in the main window:
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
TextOptions.SetTextRenderingMode(this, TextRenderingMode.Aliased);
This works fine for TextBlocks etc. but it does not seem to have any effect when using the DrawingContext's methods DrawText(FormattedText) or DrawGlyphRun(..).
Is there any chance of drawing aliased Text via DrawingContext ? (I know about the FormattedText.BuildGeometry() trick , but this looks awful when using small text sizes)
How to remove glyphrun blur effect:
var glyphRun = new GlyphRun(typeface, 0, false, emSize, glyphIndices, p, advanceWidths, null, null, null, null, null, null);
var rect = glyphRun.ComputeAlignmentBox();
Double halfPenWidth = 0.5;
GuidelineSet guidelines = new GuidelineSet();
guidelines.GuidelinesX.Add(rect.Left + halfPenWidth);
guidelines.GuidelinesX.Add(rect.Right + halfPenWidth);
guidelines.GuidelinesY.Add(rect.Top + halfPenWidth);
guidelines.GuidelinesY.Add(rect.Bottom + halfPenWidth);
drawingContext.PushGuidelineSet(guidelines);
drawingContext.DrawGlyphRun(brush, glyphRun);
drawingContext.Pop();
I dont have WPF4 right now, so I cant test it. But quick scan through MSDN shows you can use DrawingVisual. Set your RenderingMode here and then use RenderOpen
to get DrawingContext.
Question is where and how you want to draw this text.
There's an overloaded constructor for FormattedText
that allows specifying a TextFormattingMode
: http://msdn.microsoft.com/en-us/library/ee474866.aspx
精彩评论