-
Notifications
You must be signed in to change notification settings - Fork 5
Fonts
This library supports the font, font-size, font-family, font-style, font-weight, and text-decoration properties, as well at the @font-face CSS "at" rule for including TTF/OTF fonts.
By default, CN1’s native fonts are used. The appropriate native font is selected for the provided font-weight and font-style properties. You can also explicitly specify the native font you wish to use in the font-family
property. E.g.
SideCommand {
font-family: "native:MainThin";
}
If you omit the font-family
directive altogether, it will use native:MainRegular
. The following native fonts are available:
-
native:MainThin
-
native:MainLight
-
native:MainRegular
-
native:MainBold
-
native:MainBlack
-
native:ItalicThin
-
native:ItalicLight
-
native:ItalicRegular
-
native:ItalicBold
-
native:ItalicBlack
If you want to use a font other than the built-in fonts, you’ll need to define the font using the @font-face
rule. E.g.
@font-face {
font-family: "Montserrat";
src: url(res/Montserrat-Regular.ttf);
}
Then you’ll be able to reference the font using the specified font-family
in any CSS element. E.g.
MyLabel {
font-family: "Montserrat";
}
The @font-face
directive’s src
property will accept both local and remote URLs. E.g.
@font-face {
font-family: "MyFont";
src: url(http://example.com/path/to/myfont.ttf);
}
In this case, it will download the myfont.ttf
file to the same directory as the CSS file. From then on it will use that locally downloaded version of the font so that it doesn’t have to make a network request for each build.
Fonts are automatically copied to the project’s "src" directory when the CSS file is compiled so that they will be distributed with the app and available at runtime.
Github URLs
Fonts hosted on GitHub are accessible using a special github:
protocol to make it easier to reference such fonts. E.g. the following directive includes the "FontAwesome" font directly from Github
@font-face {
font-family: "FontAwesome";
src: url(github://FontAwesome/Font-Awesome/blob/master/fonts/fontawesome-webfont.ttf);
}
Note
|
Apparently FontAwesome has removed its public repositories from Github so this URL no longer works. |
It is best practice to size your fonts using millimetres (mm
) (or another "real-world" measurement unit such as inches (in
), centimetres (cm
). This will allow the font to be sized appropriate for all display densities. If you specify size in pixels (px
), it will treat it the same as if you sized it in points (pt
), where 1pt == 1/72 inches (one seventy-second of an inch).
If you size your font in percentage units (e.g. 150%
) it will set the font size relative to the medium font size of the platform. This is different than the standard behaviour of a web browser, which would size it relative to the parent element’s font size.
You can use system fonts, true type fonts, and native fonts in your CSS stylesheet. True Type fonts need to be defined in a @font-face
directive before they can be referenced. True-type fonts and native fonts have the advantage that you can specify their sizes in generic terms (e.g. small
, medium
, large
) and in more specific units such as millimeters (mm
) or pixels (px
).
See the text-decoration section in the "Supported Properties" page.
@font-face {
font-family: "Montserrat";
src: url(res/Montserrat-Regular.ttf);
}
@font-face {
font-family: "Montserrat-Bold";
src: url(res/Montserrat-Bold.ttf);
}
@font-face {
font-family: "FontAwesome";
src: url(github://FontAwesome/Font-Awesome/blob/master/fonts/fontawesome-webfont.ttf);
}
PlainText0p5mm {
font-size: 0.5mm;
}
PlainText1mm {
font-size: 1mm;
}
PlainText2mm {
font-size: 2mm;
}
PlainText5mm {
font-size: 5mm;
}
PlainText10mm {
font-size: 10mm;
}
PlainText50mm {
font-size: 50mm;
}
PlainTextSmall {
font-size: small;
}
PlainTextMedium {
font-size: medium;
}
PlainTextLarge {
font-size: large;
}
PlainText3pt {
font-size: 3pt;
}
PlainText6pt {
font-size: 6pt;
}
PlainText12pt {
font-size: 12pt;
}
PlainText20pt {
font-size: 20pt;
}
PlainText36pt {
font-size: 36pt;
}
BoldText {
font-weight: bold;
}
BoldText1mm {
font-weight: bold;
font-size: 1mm;
}
BoldText2mm {
font-weight: bold;
font-size: 2mm;
}
BoldText3mm {
font-weight: bold;
font-size: 3mm;
}
BoldText5mm {
font-weight: bold;
font-size: 5mm;
}
ItalicText {
font-style: italic;
}
ItalicText3mm {
font-style: italic;
font-size: 3mm;
}
ItalicBoldText {
font-style: italic;
font-weight: bold;
}
PlainTextUnderline {
text-decoration: underline;
}
BoldTextUnderline {
text-decoration: underline;
font-weight: bold;
}
ItalicTextUnderline {
text-decoration: underline;
font-style: italic;
}
PlainText3d {
text-decoration: cn1-3d;
color:white;
background-color: #3399ff
}
BoldText3d {
text-decoration: cn1-3d;
font-weight: bold;
color:white;
background-color: #3399ff;
}
ItalicText3d {
text-decoration: cn1-3d;
font-style: italic;
color:white;
background-color: #3399ff;
}
PlainText3dLowered {
text-decoration: cn1-3d-lowered;
color:black;
background-color: #3399ff;
}
BoldText3dLowered {
text-decoration: cn1-3d-lowered;
font-weight: bold;
color:black;
background-color: #3399ff;
}
ItalicText3dLowered {
text-decoration: cn1-3d-lowered;
font-style: italic;
color:black;
background-color: #3399ff;
}
PlainText3dShadow {
text-decoration: cn1-3d-shadow-north;
color:white;
background-color: #3399ff;
}
BoldText3dShadow {
text-decoration: cn1-3d-shadow-north;
font-weight: bold;
color:white;
background-color: #3399ff;
}
ItalicText3dShadow {
text-decoration: cn1-3d-shadow-north;
font-style: italic;
color:white;
background-color: #3399ff;
}
MainThin {
font-size: 200%;
background: radial-gradient(circle at top left, yellow, blue 100%);
}
MainRegular0001 {
font-family: "native:MainRegular";
/*background: cn1-pill-border;
background-color: red;*/
color: blue;
border: 1px cn1-pill-border blue;
/*box-shadow: 1mm 1mm 0 2mm rgba(0,0,0,1.0);*/
padding: 2mm;
}
MainRegular0001.pressed {
font-family: "native:MainRegular";
background: cn1-pill-border blue;
/*background-color: red;*/
color: white;
border: 1px solid white;
/*box-shadow: 1mm 1mm 0 2mm rgba(0,0,0,1.0);*/
padding: 2mm;
}
Heading {
font-size: 4mm;
font-family: "Montserrat-Bold";
color: black;
padding: 2mm;
text-align: center;
}
XMLVIewIcon {
font-family: "FontAwesome";
}