My project use some font like Arabic character, I also need use stroke on the font. I already try some way to display the Stroke, like :
我的项目使用像阿拉伯字符这样的字体,我也需要在字体上使用笔划。我已经尝试过某种方式来显示笔划,例如:
https://stackoverflow.com/a/9887123/1900498 (OuterTextBlock)
https://stackoverflow.com/a/97728/1900498 (OutlineText)
The Stroke can display now, but the problem is the Arabic character connection position still display some stroke, So I need to remove it.
笔画现在可以显示,但问题是阿拉伯字符连接位置仍然显示一些笔划,所以我需要删除它。
the result like this:
结果是这样的:
So Is there any way I can remove the stroke from the connection position? I mean If the character is connection, just stroke on the full connection outsize, not all character stroke 1 time.
那么有什么方法可以从连接位置移除笔划?我的意思是如果角色是连接,只是在完整连接上的笔划超大,而不是所有字符笔划1次。
I need the result like this(I'm using PHOTOSHOP to edit the second picture and remove the stroke from character connection position, not WPF, that is just for you understand the correct result must handle by WPF)
我需要这样的结果(我正在使用PHOTOSHOP来编辑第二张图片并从字符连接位置移除笔划,而不是WPF,这只是为了让您了解WPF必须处理的正确结果)
UPDATE: please download the 2 class from the 2 link , then use This code :
更新:请从2链接下载2类,然后使用此代码:
ئالما1 个解决方案
#1
4
Initial observations: The artifacts you are seeing seem to be the actual edges of the single characters. The characters touch and overlap slightly, while you would like to perceive several characters as one consecutive shape.
初步观察:您看到的工件似乎是单个字符的实际边缘。字符会轻微触摸和重叠,而您希望将多个字符视为一个连续的形状。
I have tried my suggestion from the comments by extending the OutlinedTextBlock class from the first linked answer by Kent Boogaart.
我已经从评论中尝试了我的建议,从Kent Boogaart的第一个链接答案中扩展了OutlinedTextBlock类。
The Geometry instance obtained by OutlinedTextBlock from the BuildGeometry method consists of nested GeometryGroup instances (at least, separate such groups are created when incorporating text with several reading directions). After diving through those groups, you will find one PathGeometry instance per character.
由BuildGeometry方法中的OutlinedTextBlock获取的Geometry实例由嵌套的GeometryGroup实例组成(至少,在合并具有多个阅读方向的文本时会创建单独的此类组)。在浏览这些组之后,您将在每个角色中找到一个PathGeometry实例。
N.B.: This is what I figured out when looking at the data. It is probably undocumented (?), and if it ever changes, this solution may not work any more.
N.B。:这是我在查看数据时想到的。它可能没有文档(?),如果它发生变化,这个解决方案可能不再起作用了。
By using the Geometry.Combine method, all of these PathGeometry instances can be combined with GeometryCombineMode.Union, which means that overlapping areas will be merged.
通过使用Geometry.Combine方法,所有这些PathGeometry实例都可以与GeometryCombineMode.Union结合使用,这意味着将合并重叠区域。
First, I have defined a method for finding all the PathGeometry objects. It recursively dives into the hierarchy of GeometryGroup objects and is rather not very efficient, but it serves to demonstrate the point - feel free to optimize this performance-wise:
首先,我定义了一种查找所有PathGeometry对象的方法。它递归地潜入GeometryGroup对象的层次结构,而且效率不是很高,但它有助于证明这一点 - 随意优化这种性能:
private IEnumerable 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 have modified the OutlinedTextBox.EnsureGeometry method. Originally, the geometry retrieved from BuildGeometry was directly displayed:
然后,我修改了OutlinedTextBox.EnsureGeometry方法。最初,直接显示从BuildGeometry检索的几何体:
private void EnsureGeometry(){ if (this.textGeometry != null) { return; } this.EnsureFormattedText(); this.textGeometry = this.formattedText.BuildGeometry(new Point(0, 0));}Instead, I now process that geometry by iterating over all of the contained PathGeometry instances and incrementally combining them with the Union mode. For the sake of convenience (and so you can actually observe the difference), I have made that behaviour optional by adding a MergeShapes property:
相反,我现在通过迭代所有包含的PathGeometry实例并逐步将它们与Union模式组合来处理该几何。为方便起见(因此您可以实际观察差异),我通过添加MergeShapes属性使该行为可选:
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); }}【文章原创作者:武汉网站制作公司 http://www.1234xp.com/wuhan.html 网络转载请说明出处】