How to remove a stroke from an Arabic character position in WPF?

My project uses some font that looks like an Arabic character , I also need to use a font stroke. I'm already trying to somehow display Stroke, for example:

stack overflow

stack overflow

A stroke may now display , but the problem in the join position of the Arabic character still shows some stroke, so I need to remove it .

Result: enter image description here

So, is there a way to remove the punch from the join position? I mean, if the character is a mix, just hit the full mix, and not every measure 1 time.

I need a result like this (I use PHOTOSHOP to edit the second image and remove the stroke from the character join position, not WPF strong>, it's just for you to understand that the correct result should be handled by WPF) enter image description here

UPDATE: download the 2nd class from 2 links, then use this code:

<Window x:Class="test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:test" Title="MainWindow" Height="200" Width="400"> <Grid Background="Black"> <local:OutlinedTextBlock HorizontalAlignment="Left" Height="200" VerticalAlignment="Bottom" FontSize="150" StrokeThickness="1" Fill="White" Stroke="Red" TextDecorations="">ئالما</local:OutlinedTextBlock> <local:OutlinedText HorizontalAlignment="Right" Height="200" VerticalAlignment="Top" FontSize="150" StrokeThickness="1" Fill="White" Stroke="Red" Text="ئالما"></local:OutlinedText> </Grid> 

+4
c # wpf
Aug 19 '14 at 11:46
source share
1 answer

Initial Observations: The artifacts that you see are the actual edges of the individual characters. Symbols are slightly touching and slightly overlapping, while you would like to perceive several symbols as one consecutive form.

I tried my suggestion from the comments by extending the OutlinedTextBlock class from Kent Boogaart 's first related answer .

The Geometry instance obtained by the OutlinedTextBlock from the BuildGeometry consists of nested GeometryGroup instances (at least individual groups are created when text with multiple reads is included). After diving through these groups, you will find one PathGeometry instance per character.

NB: This is what I found out when viewing the data. This is probably undocumented (?), And if it ever changes, this solution may no longer work.

Using the Geometry.Combine method , all of these PathGeometry instances can be combined with GeometryCombineMode.Union , which means that the overlapping regions will be merged.

First, I defined a search method for all PathGeometry objects. It recursively plunges into the hierarchy of GeometryGroup objects and, rather, is not very efficient, but serves to demonstrate a point - do not hesitate to optimize this performance:

 private IEnumerable<PathGeometry> FindAllPathGeometries(Geometry geometry) { var pathGeometry = geometry as PathGeometry; if (pathGeometry != null) { yield return pathGeometry; } else { var geoGroup = geometry as GeometryGroup; if (geoGroup != null) { foreach (var geo in geoGroup.Children) { foreach (var pg in FindAllPathGeometries(geo)) { yield return pg; } } } } } 

Then I changed the OutlinedTextBox.EnsureGeometry method. The geometry originally derived from BuildGeometry initially displayed:

 private void EnsureGeometry() { if (this.textGeometry != null) { return; } this.EnsureFormattedText(); this.textGeometry = this.formattedText.BuildGeometry(new Point(0, 0)); } 

Instead, I now process this geometry by iterating over all contained PathGeometry instances and gradually adding them to Union mode. For convenience (and therefore you can observe the difference), I made this behavior optional by adding the MergeShapes property:

 private void EnsureGeometry() { if (this.textGeometry != null) { return; } this.EnsureFormattedText(); var originalGeometry = this.formattedText.BuildGeometry(new Point(0, 0)); if (MergeShapes) { PathGeometry newGeo = new PathGeometry(); foreach (var pg in FindAllPathGeometries(originalGeometry)) { newGeo = Geometry.Combine(newGeo, pg, GeometryCombineMode.Union, null); } this.textGeometry = newGeo; } else { this.textGeometry = originalGeometry; } } public static readonly DependencyProperty MergeShapesProperty = DependencyProperty.Register("MergeShapes", typeof(bool), typeof(OutlinedTextBlock), new FrameworkPropertyMetadata(OnFormattedTextUpdated)); public bool MergeShapes { get { return (bool)GetValue(MergeShapesProperty); } set { SetValue(MergeShapesProperty, value); } } 
+4
Aug 19 '14 at 16:17
source share



All Articles