[英]Why FontStretch does not work in WPF?
我正在嘗試在WPF中的TextBlock上設置FontStretch屬性,但似乎它不起作用。 我嘗試過Expanded,Condensed等,但文字外觀沒有變化。
我正在使用帶有Framework 4.0的Windows XP,並使用Verdana和Arial進行了測試。
它僅適用於Windows 7或僅適用於某些特定字體嗎?
編輯 :如果它不適用於所有字體,是否有支持此功能的字體列表? 或者是否可以修改像Verdana / Arial這樣的字體來支持它?
要以不支持FontStretch的字體獲得與FontStretch類似的效果,可以在TextBlock上使用LayoutTransform:
<Application.Resources>
<ScaleTransform x:Key="FontStretchCondensed" ScaleX="0.8" />
<ScaleTransform x:Key="FontStretchExpanded" ScaleX="1.2" />
</Application.Resources>
...
<TextBlock Text="This is my text"
LayoutTransform="{StaticResource FontStretchCondensed}" />
如果要使TextBlocks中的所有文本都顯示為濃縮,也可以在樣式中設置:
<Style TargetType="TextBlock">
<Style.Setters>
<Setter Property="LayoutTransform" Value="{StaticResource FontStretchCondensed}" />
</Style.Setters>
</Style>
與粗體或斜體等字體屬性不同,WPF不會模擬拉伸或小型字體等字體屬性。 使用的字體必須支持這個。
要查看哪些字體支持FontStretch,您需要查找具有單獨字體文件的字體,例如Condensed或Expanded。 然后只有正確鏈接的TrueType / OpenType字體才能工作。 某些字體供應商沒有正確地將其字體的拉伸或壓縮變體鏈接到常規版本,因此WPF不知道這些字體變體是相關的。
通過測量一些文本(TextBlock.Measure),我發現Arial Narrow是Arial的寬度×0.82。
所以textBlock.LayoutTransform = new System.Windows.Media.ScaleTransform(0.82, 1.0);
當應用於Arial時可能會接近Arial Narrow。
我相信FontStretch不適用於所有字體。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.