WPF/XAML: Typography.Capitals seems to have no effect

好久不见. 提交于 2019-12-07 03:21:09

问题


All of these bits of text look the same, but I am trying to get them to look different. I want small caps text. What am I missing here to get the small caps typography effect to work?

To reproduce this, open Visual Studio 2008, Do File|New Project, create a new Windows|WPF application, paste the mark-up below into Window1.xaml, then run it.

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <FlowDocumentReader>
        <FlowDocument>
            <Paragraph>
                <Run>Some text</Run> <LineBreak />
                <Run Typography.Capitals="SmallCaps">Some text</Run> <LineBreak />
                <Run Typography.Capitals="AllSmallCaps">Some text</Run> <LineBreak />
                <Run Typography.Capitals="PetiteCaps">Some text</Run> <LineBreak />
                <Run Typography.Capitals="AllPetiteCaps">Some text</Run> <LineBreak />
            </Paragraph>
        </FlowDocument>
        </FlowDocumentReader>
    </Grid>
</Window>   

Based on the first answer, it seems that if you specify a particular font, you can get somewhere. Change the FlowDocument start tag to:

   <FlowDocument FontFamily="Palatino Linotype">

.. and you get SmallCaps and AllSmallCaps, but not PetiteCaps or AllPetiteCaps. So it depends on the font. But this gives rise to other questions:

  • Why doesn't the default font (which looks a lot like Times New Roman) support these?
  • Do other widely used fonts (e.g. the local Courier New equivalent) support these?
  • Is there a list of which fonts support what?
  • What percentage of fonts will support this - most, some, or few?
  • Can you determine in code what the font supports - if this is the case, I could fake the AllSmallCaps - e.g. by converting the text to all capitals and scaling by 80%. But not SmallCaps.

回答1:


This only works with specific OpenType fonts - the example in Help uses Pescadero which is in the Open Type Sample. Even then, only SmallCaps and AllSmallCaps are supported.




回答2:


I noticed that default font with a "bold" fontweight does render the SmallCaps properly:

<StackPanel>
    <TextBlock Typography.Capitals="SmallCaps" FontFamily="Pescadero" Padding="2">2pm</TextBlock>
    <TextBlock Typography.Capitals="SmallCaps" FontWeight="Bold" Padding="2">2pm</TextBlock>
</StackPanel>


来源:https://stackoverflow.com/questions/636454/wpf-xaml-typography-capitals-seems-to-have-no-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!