简体   繁体   English

如何确定 Windows 操作系统字体是否支持粗体或斜体

[英]How to determine if a Windows OS font would support bold or italic

How do you determine if a particular font supports bold or italic regardless whether it's a True Type or Type 1?您如何确定特定字体是否支持粗体或斜体,而不管它是 True Type 还是 Type 1? I have the following scenarios relating to embedding a Flex font issue:我有以下与嵌入 Flex 字体问题相关的场景:

  • I have 3 TTF font files called Unknown1, Unknown2 and Unknown3.我有 3 个 TTF 字体文件,名为 Unknown1、Unknown2 和 Unknown3。 Let's say they're installed for now假设他们现在已经安装
  • When I embed the fonts, Flex tells me that Unknown2.ttf doesn't support a bold weight or Unknown3.ttf doesn't support an italic style当我嵌入字体时,Flex 告诉我 Unknown2.ttf 不支持粗体或 Unknown3.ttf 不支持斜体样式

My question is, how did Flex knew all of that?我的问题是,Flex 是如何知道所有这些的? I've been searching through C# and Java libraries but none of them seem to offer what I need.我一直在搜索 C# 和 Java 库,但它们似乎都没有提供我需要的东西。 Or apparently, I'm not looking hard enough.或者显然,我看起来不够努力。 Anyways, are there classes in Java or C# that can provide me with some signature like:无论如何,是否有 Java 或 C# 中的类可以为我提供一些签名,例如:

Font unknownFont = Font.getFontFromAnyDirectory("Unknown2.ttf"); Font unknownFont = Font.getFontFromAnyDirectory("Unknown2.ttf"); unknownFont.supportsAnyStyleCalled(Font.BOLD);//Returns false. unknownFont.supportsAnyStyleCalled(Font.BOLD);//返回false。 unknownFont.supportsAnyStyleCalled(Font.ITALIC);//Returns true. unknownFont.supportsAnyStyleCalled(Font.ITALIC);//返回true。 // unknownFont = Font.getFontFromAnyDirectory("Unknown3.ttf"); // unknownFont = Font.getFontFromAnyDirectory("Unknown3.ttf"); unknownFont.supportsAnyStyleCalled(Font.BOLD);//Returns true. unknownFont.supportsAnyStyleCalled(Font.BOLD);//返回true。 unknownFont.supportsAnyStyleCalled(Font.ITALIC);//Returns false. unknownFont.supportsAnyStyleCalled(Font.ITALIC);//返回false。

在 C# 中,您可以通过调用FontFamily.IsStyleAvailable 来实现

I know the question is pretty old, I had the same problem and the solution is stated in C# get font style from .ttf .我知道这个问题很老了,我遇到了同样的问题,解决方案在C# get font style from .ttf 中说明

You can use:您可以使用:

GlyphTypeface ttf = new GlyphTypeface(new Uri(@"C:\Windows\Fonts\calibrii.ttf"));
Debug.Print(ttf.Style.ToString()); //=Italic or Normal
Debug.Print(ttf.Weight.ToString()); //=Bold or Normal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM