Search code examples
fontsthemeswebspherebusiness-process-management

How Do I include custom fonts in IBM BPM/BAW theme


We are using BAWoC (BAW on Cloud) and are customizing the Theme, but we need to include some file WOFF, TTTF using URL (look the image) Where I can include these files? I included these files on project WEB FILE and DESIGN FILE but doesn’t have a URL where I can get and include them on my theme source.

Our Theme file entry looks like this

/* ubuntu-regular - latin */
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 400;
  src: url('ubuntu-v15-latin-regular.eot'); /* IE9 Compat Modes */
  src: local(''),
       url('ubuntu-v15-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('ubuntu-v15-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
       url('ubuntu-v15-latin-regular.woff') format('woff'), /* Modern Browsers */
       url('ubuntu-v15-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
       url('ubuntu-v15-latin-regular.svg#Ubuntu') format('svg'); /* Legacy iOS */
}
/* ubuntu-500 - latin */
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 500;
  src: url('ubuntu-v15-latin-500.eot'); /* IE9 Compat Modes */
  src: local(''),
       url('ubuntu-v15-latin-500.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('ubuntu-v15-latin-500.woff2') format('woff2'), /* Super Modern Browsers */
       url('ubuntu-v15-latin-500.woff') format('woff'), /* Modern Browsers */
       url('ubuntu-v15-latin-500.ttf') format('truetype'), /* Safari, Android, iOS */
       url('ubuntu-v15-latin-500.svg#Ubuntu') format('svg'); /* Legacy iOS */
}
/* ubuntu-700 - latin */
@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: 700;
  src: url('ubuntu-v15-latin-700.eot'); /* IE9 Compat Modes */
  src: local(''),
       url('ubuntu-v15-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('ubuntu-v15-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
       url('ubuntu-v15-latin-700.woff') format('woff'), /* Modern Browsers */
       url('ubuntu-v15-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */
       url('ubuntu-v15-latin-700.svg#Ubuntu') format('svg'); /* Legacy iOS */
}

Image of Error on Console tab of Chrome

I would like to refer to the files uploaded as managed WEB files, but not quite sure how to do the same.


Solution

  • There are multiple ways to achieve this. I’ll list out 2 of them and you can choose the one that best fits your situation. But, before going into the solution, it is necessary that we understand why this problem is occurring. When we provide an “URL” property to “font-face”, it can be an absolute URL or a relative one (in your case it is relative). Hence, it will try to find the font file (woff, ttf, svg, …) relative to the css file. In BPM when we create the theme file, it is basically a “less” file which gets pre-processed an a CSS file is auto-generated. This autogenerated CSS file is served from within the System UI toolkit’s context. Hence, we need to change the way the font-file is being referenced.

    Now coming to the solutions:

    1. If you are ok with accessing files from a CDN: Use an “@import” statement in the theme file to access a CDN/externally hosted CSS file with the same “font-face” declaration. The font-files can be relative to this css. For example “https://cdn.jsdelivr.net/npm/[email protected]/css/fonts.css”.
    2. If you are not ok with an externally hosted CSS/font-file (You are using some proprietary font), you can encode the font-file into base-64 and embed them in the theme. You can follow this comprehensive article http://stephenscaff.com/articles/2013/09/font-face-and-base64-data-uri/. Only thing to keep in mind is the additional weight of loading the font-files even though you may not use them. (Browsers are smart enough to not load font files until they see them being used in the css). Also if you are targeting modern desktop browsers only then using the “woff or woff2” format is your best bet as it has very wide support and are light-weight. You can use website like https://www.fontsquirrel.com/ to generate the woff/woff2 file from other formats.