在Silverlight中新增了對OpenType字型屬性的支援,它主要通過Typography類的相關屬性來控制。下面我們來看看它增加了哪些屬性。
注意:必須使用系統的OpenType字型才行,是以FontFamily="Gabriola"。
一、連筆字
在"ft"之間相連起來,如下圖綠色框内所示主要通過 Typography.StandardLigatures的True或者False來決定是否連筆:
<a href="http://blog.51cto.com/attachment/201204/172357470.jpg" target="_blank"></a>
然後我們看代碼如下:
<TextBlock FontFamily="Gabriola" FontSize="100" HorizontalAlignment="Center"
Margin="33,304,142,114" Text="NewsftepSet-"
Typography.StandardLigatures="False" Width="525" />
<TextBlock FontFamily="Gabriola" FontSize="100" HorizontalAlignment="Center"
Margin="33,406,142,12" Text="NewsftepSet-"
Typography.StandardLigatures="True" Width="525" />
二、分數字
将1/5、4/13等分數按照數學上的分數字來顯示,通過設定Typography.Fraction屬性為Normal、Slashed、Stacked來控制。
<a href="http://blog.51cto.com/attachment/201204/172433624.png" target="_blank"></a>
其代碼如下:
<TextBlock Text="5/152 Normal" HorizontalAlignment="Center"
FontFamily="Gabriola" FontSize="50" Height="100"
Typography.Fraction="Normal" Margin="487,313,12,187" />
<TextBlock Text="5/152 Slashed" HorizontalAlignment="Center"
Typography.Fraction="Slashed" Margin="487,373,31,0" VerticalAlignment="Top" />
<TextBlock Text="5/152 Stacked" HorizontalAlignment="Center"
FontFamily="Gabriola" FontSize="50" Height="100"
Typography.Fraction="Stacked" Margin="487,419,9,81" />
三、上下标字
比如化學裡的三氧化二鐵等,通過設定Typography.Variants屬性為Subscript、Superscript來實作上下标。如下圖:
其具體代碼如下:
<TextBlock FontFamily="Gabriola" FontSize="50" Height="100"
HorizontalAlignment="Center" Margin="487,488,117,12" >
<Run Text="Fe" Typography.Variants="Normal" />
<Run Text="2" Typography.Variants="Subscript" />
<Run Text="O" Typography.Variants="Normal" />
<Run Text="3" Typography.Variants="Superscript" />
</TextBlock>
四、手寫字
在生活中我們需要一些比較漂亮的手寫字,在Silverlight 5 RC版本中準備了7種樣式的手寫字,通過設定Typography.StylisticSet*的True、False來實作,其中*号是從1到7的整數 字來代替,8以上的數字設定是無效的。如下圖:
<a href="http://blog.51cto.com/attachment/201204/172503518.png" target="_blank"></a>
其代碼如下所示:
<TextBlock Text="NewsftepSet-" HorizontalAlignment="Center" FontSize="50"
Height="100" FontFamily="Gabriola" Margin="20,12,484,488" />
<TextBlock Text="NewsftepSet1" HorizontalAlignment="Center" FontSize="50" FontFamily="Gabriola"
Typography.StylisticSet1="True" Height="100" Margin="245,12,255,488" />
<TextBlock FontFamily="Gabriola" FontSize="50" Height="100" HorizontalAlignment="Center"
Margin="471,12,28,488" Text="NewsftepSet2" Typography.StylisticSet2="True" />
Margin="20,118,478,382" Text="NewsftepSet3" Typography.StylisticSet3="True" />
Margin="246,118,246,382" Text="NewsftepSet4" Typography.StylisticSet4="True" />
Margin="471,118,25,382" Text="NewsftepSet5" Typography.StylisticSet5="True" />
<TextBlock FontFamily="Gabriola" FontSize="50" HorizontalAlignment="Center" Width="221"
Margin="20,224,459,253" Text="NewsftepSet6" Typography.StylisticSet6="True" />
<TextBlock FontFamily="Gabriola" FontSize="50" HorizontalAlignment="Center" Width="218"
Margin="247,224,235,253" Text="NewsftepSet7" Typography.StylisticSet7="True" />
本文轉自程興亮 51CTO部落格,原文連結:http://blog.51cto.com/chengxingliang/827065