This procedure shows you how to install fonts and make them available for applications in
your customization project.
Before you begin:Download the font you wish to install. If you need to familiarize
yourself with CSS Web Font formats and browser support, you may find the W3Schools CSS Web
Fonts and Can I use
sites useful.
Warning:
The font you install, whether it is free to download or purchase, comes with a license explaining
how you may and may not use it. Be sure to read the End User License Agreement that defines your
rights and obligations.
Steps
-
Install the fonts in your customization directory.
-
In your customization-project-dir/resources
directory, create the "fonts" directory if it does not exist.
-
Install the font in your customization-project-dir/resources/fonts directory
-
In your customization-project-dir/sass
directory, create a file called MyFonts.scss and add the following code:
// in the MyFonts.scss
@font-face {
font-family: AmazonEmberReg;
src: url("$$RES/fonts/AmazonEmber_W_Rg.woff2") format('woff2'),
url("$$RES/fonts/AmazonEmber_W_Rg.woff") format('woff'),
url("$$RES/fonts/AmazonEmber_Rg.ttf") format('truetype');
}
Where:
- The
@font-face
rule is added to the style sheet.
- The
font-family
specifies the font family — a collection of fonts. The font
family is "AmazonEmberReg" in the example.
- The
src
gives the URL for three different file formats of the font, using
$$RES
to specify the path in your customization-project-dir/resources/fonts directoryA font can be defined in several formats, but as Web Open
Font Format (WOFF2 and WOFF) and TrueType Fonts (TTF) are supported by most modern browsers,
typically, you only need to install these formats. Therefore,in the example, the URLs are
referencing those formats of the AmazonEmber font intstalled in the customization-project-dir/resources/fonts directory.
-
Open the customization-project-dir/sass/customization.scss
file and add the following import statement:
@import "MyFonts";
In this example we import the MyFonts
style.
-
Save your changes and rebuild your customization using
gbc build
:
$ gbc build
--customization customization-project-dir
Your new fonts are added to the default ones in the customization-project-dir/resources/fonts directory.
-
Test that your changes work as expected.
There are different ways to use the new font in your project:
View the changes by running an application that uses the fonts.
Tip:
You may need to use CTRL + F5 to clear the browser cache before you see your
changes.