gpt4 book ai didi

wpf - 如何获取字体样式列表(wpf)

转载 作者:行者123 更新时间:2023-12-04 21:02:54 25 4
gpt4 key购买 nike

fontdialog 从哪里得到它的字体样式列表?

FontStyles 仅包含 Normal、Oblique 和 Italic。然而,通过各种字体的字体样式,有以下组合:medium、light、demi、bold、roman、narrow、heavy、cond……等等。

Arial 显示的字体对话框:

窄斜体,斜体,常规的,窄粗体,窄粗斜体,大胆的,加粗斜体,黑色的,黑色斜交

他们从哪里得到这个列表?其中一些名字似乎没有出现在任何地方。是否有一些具有其他指定名称或其他名称的 FamilyTypeface 重量、样式和拉伸(stretch)组合列表?

感谢您的帮助!

最佳答案

对于系统字体,您可以获得 typefaces 的列表对于 FontFamily。字体本身具有所有属性的详细信息,例如粗细、样式、拉伸(stretch)等。

示例代码

<Grid Margin="20">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<ListBox x:Name="fontSelector"
ItemsSource="{x:Static Fonts.SystemFontFamilies}" />

<ListBox x:Name="typefaceSelector"
ItemsSource="{Binding SelectedItem.FamilyTypefaces, ElementName=fontSelector}" DisplayMemberPath="AdjustedFaceNames[en-US]"
Grid.Column="1" />

<TextBlock FontFamily="{Binding SelectedItem.Source, ElementName=fontSelector}"
FontStretch="{Binding SelectedItem.Stretch, ElementName=typefaceSelector}"
FontStyle="{Binding SelectedItem.Style, ElementName=typefaceSelector}"
FontWeight="{Binding SelectedItem.Weight, ElementName=typefaceSelector}"
Grid.ColumnSpan="2" Grid.Row="1"
Text="Sample"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>

enter image description here

要在 WPF 中进一步扩展此列表,您可以使用 win-forms 中的 InstalledFontCollection 获取已安装字体的列表,并将其转换为 WPF 字体类型。

var installedFontCollection = new System.Drawing.Text.InstalledFontCollection();

// Get the array of FontFamily objects.
var fontFamilies = installedFontCollection.Families;
foreach(var fontFamily in fontFamilies)
{
var mfont = new FontFamily(fontFamily.Name);
fontSelector.Items.Add(mfont);
}

enter image description here

关于wpf - 如何获取字体样式列表(wpf),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45716578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com