WPF字形不像TextBlock那样正确呈现文本 [英] WPF `Glyphs` not rendering the text right like `TextBlock`

查看:64
本文介绍了WPF字形不像TextBlock那样正确呈现文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Glyphs 元素制作WPF文本编辑器.而且我有一个问题,就是文字绘制不正确如您在图片中看到的,我该如何解决这个问题?

I'm making a WPF text-editor using Glyphs element. And I have a problem that the text is not drawn correctly as you can see in the picture, how can I solve this problem?

有两个问题:

  1. 紧缩字母.
  2. 紧握字母和变音符号.

我通过 GetKerningPairs 函数解决的第一个问题.

The first problem I solved by GetKerningPairs function.

我该如何解决这个问题,也许我错了?

How do I solve this problem, maybe I'm wrong?

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="200" Width="525">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="AUTO"/>
            <RowDefinition Height="AUTO"/>
        </Grid.RowDefinitions>

        <TextBlock Text="TextBlock" VerticalAlignment="Center" Margin="6"/>
        <TextBlock Grid.Row="1" Text="Glyphs" VerticalAlignment="Center" Margin="6"/>

        <TextBlock Text="בְּרֵאשִׁית" Grid.Column="1" FontSize="50" FontFamily="Times New Roman"
                   FontWeight="Normal" Grid.Row="0"/>

        <Glyphs Grid.Row="1" Grid.Column="1"
            FontUri             = "C:\WINDOWS\Fonts\TIMES.TTF"
            FontRenderingEmSize = "50"
            UnicodeString       = "בְּרֵאשִׁית"
            BidiLevel="1"
            Fill                = "Black"/>

        <TextBlock Text="AVAV" Grid.Column="2" FontSize="50" FontFamily="Times New Roman"
                   FontWeight="Normal" Grid.Row="0"/>

        <Glyphs Grid.Row="1" Grid.Column="2"
            FontUri             = "C:\WINDOWS\Fonts\TIMES.TTF"
            FontRenderingEmSize = "50"
            UnicodeString       = "AVAV"
            BidiLevel="0"
            Fill                = "Black"/>

    </Grid>
</Window>

推荐答案

在TrueType字体中不存在变音符号的紧缩,因此,您必须定义自己的变音符号对列表,并给出相应的字距调整.在大多数字母中,变音符号是居中的,而在其他字母中则是在右边.显然,文本块可以完成上述操作.

Kerning for diacritics does not exist in TrueType fonts, So you must define your own list of pairs for diacritics, and give the corresponding kerning. In most letters, the diacritics is centered, and in the others on the right side. Apparently Text Block does the above.

这篇关于WPF字形不像TextBlock那样正确呈现文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆