How to use embedded fonts with CSS in Spark shells of Flex mobile project?

A brief example to describe the problem. Set up your regular Flex mobile project with the following files (and the OpenSans font ).

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>

As a result, a simple label is written with an embedded font, but there is no button on the label. So it looks like this: http://img813.imageshack.us/img813/44/skinningtest.png

I tried other CSS properties, such as color and font size, and it works for both. Only embedded fonts will not work in Spark skins.

What am I missing to style a shortcut in a button with an embedded font?


Decision

fontWeight fontStyle (@font-face) (.OpenSansEmbeddedBold). , .

/* 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;
}

styleName MXML

<s:Label text="Static Label" styleName="OpenSansEmbeddedBold"/>
+3
2

, , fontWeight: normal; css, . fontFamily Verdana , .

+2

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;
}
0

All Articles