描述问题的简短示例。使用以下文件(和OpenSans font)设置常用的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"/>
答案 0 :(得分:2)
我不确切知道原因,但尝试在您的CSS中添加fontWeight: normal;
,这会有所帮助。在将fontFamily更改为Verdana并看到该按钮标签为粗体后,我得出了这个结论。
答案 1 :(得分:0)
对于你应该使用的按钮embedAsCFF:false
@namespace s "library://ns.adobe.com/flex/spark";
@font-face {
src: url("fonts/opensans/OpenSans-Bold.ttf");
fontFamily: OpenSansBoldEmbedded;
embedAsCFF: true;
}
@font-face {
src: url("fonts/opensans/OpenSans-Bold.ttf");
fontFamily: OpenSansBoldEmbeddedForBtn;
embedAsCFF: false;
}
s|Label
{
fontFamily: OpenSansBoldEmbedded;
font-lookup: embeddedCFF;
}
s|Button
{
fontFamily: OpenSansBoldEmbeddedForBtn;
}