以下是一个简短的示例,用于描述问题。使用以下文件(和OpenSans字体)设置一个常规的Flex移动项目。
Main.mxml
请注意,本次翻译仅涉及语言转换,不涉及技术解释。
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
applicationDPI="160">
<s:layout><s:VerticalLayout/></s:layout>
<fx:Style source="style.css"/>
<s:Label text="Static Label"/>
<s:Button label="Static Button" skinClass="MyButtonSkin"/>
</s:Application>
style.css
@namespace s "library://ns.adobe.com/flex/spark";
@font-face {
src: url("fonts/opensans/OpenSans-Bold.ttf");
fontFamily: OpenSansBoldEmbedded;
embedAsCFF: true;
}
s|Label,
s|Button
{
fontFamily: OpenSansBoldEmbedded;
font-lookup: embeddedCFF;
}
MyButtonSkin.mxml
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
<!-- host component -->
<fx:Metadata>
[HostComponent("spark.components.Button")]
</fx:Metadata>
<s:Label id="labelDisplay" />
</s:Skin>
结果是简单的标签使用了嵌入式字体进行样式设置,但按钮中的标签没有。因此它看起来像这样:http://img813.imageshack.us/img813/44/skinningtest.png 我已经尝试了其他CSS属性,如颜色和字体大小,并且两者都有效。只有嵌入式字体在Spark皮肤中无法正常工作。
我缺少什么来使用嵌入式字体对按钮中的标签进行样式设置?
解决方案:在导入(@font-face)和使用(.OpenSansEmbeddedBold)时使用fontWeight和fontStyle属性。仅嵌入粗体字体并使用它是不够的。
/* Import the different font weights and styles */
@font-face {
src: url("fonts/opensans/OpenSans-Regular.ttf");
fontFamily: OpenSansEmbedded;
}
@font-face {
src: url("fonts/opensans/OpenSans-Bold.ttf");
fontFamily: OpenSansEmbedded;
fontWeight: bold;
}
@font-face {
src: url("fonts/opensans/OpenSans-Italic.ttf");
fontFamily: OpenSansEmbedded;
fontStyle: italic;
}
@font-face {
src: url("fonts/opensans/OpenSans-BoldItalic.ttf");
fontFamily: OpenSansEmbedded;
fontWeight: bold;
fontStyle: italic;
}
/* Register fonts as styleNames for further use */
.OpenSansEmbedded
{
fontFamily: OpenSansEmbedded;
}
.OpenSansEmbeddedBold
{
fontFamily: OpenSansEmbedded;
fontWeight: bold;
}
.OpenSansEmbeddedItalic
{
fontFamily: OpenSansEmbedded;
fontStyle: italic;
}
.OpenSansEmbeddedBoldItalic
{
fontFamily: OpenSansEmbedded;
fontWeight: bold;
fontStyle: italic;
}
在MXML中使用定义好的类作为styleName。
<s:Label text="Static Label" styleName="OpenSansEmbeddedBold"/>
fontWeight: bold;
。对于斜体字样式,您需要添加fontStyle: italic;
。 - Holger Stitz