我正在使用Glyphs
元素制作WPF文本编辑器。
我有一个问题,即文本绘制不正确
如图所示,我该如何解决这个问题?
有两个问题:
我通过GetKerningPairs
函数解决的第一个问题。
我如何解决这个问题,也许我错了?
<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>
答案 0 :(得分:4)
TrueType字体中不存在变音符号的字距, 因此,您必须为变音符号定义自己的对列表,并给出相应的字距调整。在大多数字母中,变音符号是居中的,而其他字母则位于右侧。显然文本块执行上述操作。
答案 1 :(得分:2)
正如@Codedom所说,你必须定义自己的列表,如下所示:
class Program
{
static void Main(string[] args)
{
var list = new List<DiacriticsKerning>();
list.Add(new DiacriticsKerning('א', 'ָ', HorizontalAlignment.Center, VerticalAlignment.None));
list.Add(new DiacriticsKerning('ב', 'ָ', HorizontalAlignment.Center, VerticalAlignment.None));
list.Add(new DiacriticsKerning('ג', 'ָ', HorizontalAlignment.Center, VerticalAlignment.None));
list.Add(new DiacriticsKerning('ד', 'ָ', HorizontalAlignment.Right, VerticalAlignment.None));
list.Add(new DiacriticsKerning('ה', 'ָ', HorizontalAlignment.Center, VerticalAlignment.None));
list.Add(new DiacriticsKerning('ו', 'ָ', HorizontalAlignment.Center, VerticalAlignment.None));
// ...
}
}
struct DiacriticsKerning
{
public DiacriticsKerning(char letter, char diacritics, HorizontalAlignment alignmentHorizontal, VerticalAlignment alignmentVertical)
{
Letters = letter;
Diacritics = diacritics;
HorizontalAlignment = alignmentHorizontal;
VerticalAlignment = alignmentVertical;
}
char Letters;
char Diacritics;
HorizontalAlignment HorizontalAlignment;
VerticalAlignment VerticalAlignment;
}
enum HorizontalAlignment { None, Center, Left, Right, }
enum VerticalAlignment { None, Center, Left, Right, }