如何在应用程序中使用自定义CompositeFont?
问题描述:
我们需要为特定的外语使用特定的字体。基于这个问题的答案,似乎CompositeFont将是处理这个问题的最好方法。如何在应用程序中使用自定义CompositeFont?
Best way to localize fonts in wpf
但我努力让这该死的东西的工作。
我如下
<FontFamily xmlns="http://schemas.microsoft.com/winfx/2006/xaml/composite-font"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Baseline="0.9"
LineSpacing="1.2">
<!-- Name mapping -->
<FontFamily.FamilyNames>
<System:String Key="en-US">MyFont</System:String>
</FontFamily.FamilyNames>
<!-- Faces to report in font chooser UI -->
<FontFamily.FamilyTypefaces>
<FamilyTypeface Weight="Normal"
Stretch="Normal"
Style="Normal"
UnderlinePosition="-0.1"
UnderlineThickness="0.05"
StrikethroughPosition="0.3"
StrikethroughThickness="0.05"
CapsHeight="0.5"
XHeight="0.3" />
<FamilyTypeface Weight="Bold"
Stretch="Normal"
Style="Normal"
UnderlinePosition="-0.1"
UnderlineThickness="0.05"
StrikethroughPosition="0.3"
StrikethroughThickness="0.05"
CapsHeight="0.5"
XHeight="0.3" />
</FontFamily.FamilyTypefaces>
<FontFamily.FamilyMaps>
<FontFamilyMap Unicode="0000-052F, 1D00-1FFF, FB00-FB0F"
Target="Comic Sans MS"
Scale="1.0" />
</FontFamily.FamilyMaps>
</FontFamily>
构建属性已被设置为资源,并且它被保存在.CompositeFont名创建Font.CompositeFont文件。
但是,将我的任何字体的FontFamily设置为“/#MyFont”似乎没有设置字体。我确定我在某个地方错过了一个步骤,但如果我能找到有关该步骤的任何资源,我会被诅咒。 (我会继续找然而)
在样式设置字体如下
<Style x:Key="defaultLabelFont"
TargetType="Label">
<Setter Property="FontFamily"
Value="#MyFont" />
<Setter Property="FontSize"
Value="12" />
<Setter Property="VerticalAlignment"
Value="Bottom" />
<Setter Property="HorizontalAlignment"
Value="Center" />
</Style>
如果任何人都可以在正确的方向指向我什么我已经错过了它会不胜感激。
答
我建议处理InputLanguageChanged
事件
System.Windows.Input.InputLanguageManager.Current.InputLanguageChanged +=
Current_InputLanguageChanged;
,并决定有关字体家庭或大小或等
private void Current_InputLanguageChanged(object sender, InputLanguageEventArgs e)
{
if (e.NewLanguage.EnglishName == "...")
Application.Current.MainWindow.FontFamily = new FontFamily("Times New Roman");
else
{
// ...
}
}
+0
对不起,迟到的答复,并感谢您的建议。我已经考虑过这样的事情,但我们使用了许多不同的字体大小/颜色,这看起来并不经济。我们并不担心输入语言,只是翻译的输出。 CompositeFont真的是一个完美的答案,只是希望有关于如何正确使用它的文档。 – user3265613
开始,让你只能在您的应用程序这种方式.TTF的感觉,而不是复合字体。 – user3265613