User Tools

Site Tools

Translations of this page?:

en:template:custom-fonts

Custom Fonts

Custom fonts are an optional field of the template. It's added at the root of the template, at the same levels than description or styles :

{
    "styles": [ ],
    "fonts" : [ ],
    "description": { }
};

In the fonts array, you can add as many custom fonts as you need. But what is a custom font ?

What is a Custom Font ?

A custom font is a font you want to ensure will be accessible by anyone. A custom font is basically two things : a fontFamily that indicates the string we'll use to say “We use that font”, and an url to the font file.

{
    "styles": [ ],
    "fonts" : [
        { "fontFamily": "MyFontFamily", "src": "url" } 
    ],
    "description": { }
};

We'll use this font as a CSS font-face.

The font file and Url

If you host geckos, you can add your needed font on you server, and set a relative path to it as the url :

{ "fontFamily": "MyFontFamily", "src": "fonts/myFont.woff" }

You can also sets the url to a distant server, but it might sometimes create bugs (server down, firewall preventing access to the server, server path changed, …).

{ "fontFamily": "MyFontFamily", "src": "http://www.fonts.com/myFont.woff" }

Finally, as for the images of the canvas, we can use the DataUrl of a font file. You can find some explanations of this on SoSweetCreative, but the goal is the same as for the images : the font file is translated in a string format, embedded into the template code, and is sure to be present for the user.

{ "fontFamily": "MyFontFamily", "src": "data:application/octet-stream;base64,T1RUTw......" }

See for example the Warhammer Quest - Silver tower template, that uses such a font.

The FontFamily

The fontFamily property is a String that represents the name of the font. It's better with no spaces or funky characters. This name could follow the original one of the font, but it's not mandatory.

It's now the name that your template will use in order to display text with that font. Any Text, Textbox or similar fields you will use in the Canvas can use that font :

{ "type": "textbox", "left": 0, "top": 0, "width": 100, "text": "$name", "fontFamily": "MyFontFamily" },

That's how you use Custom fonts in Geckos !

Optional - The Font Style

The font you just added is added to the webpage as a Regular font. It means you can use that font to display regular text (ie not italic). But what if you want to display italic text ?

If your font is only meant to be used in italic, you can set the italic version of the font as the src and use it. It will work just fine.

If you plan to use your font in both regular and italic version, it will not work this way. Instead, you need to add two custom fonts : one for the regular style, one for the italic :

"fonts" : [
    { "fontFamily": "MyFontFamily", "src": "data:application/octet-stream;base64,T1RUTw......" },
    { "fontFamily": "MyFontFamily", "fontStyle": "italic", "src": "data:application/octet-stream;base64,T1RUTw......" }
]

The src part of the italic font need to be the italic version file of the font. Or another font ? Yes, it's up to you, template creator, to play with this ! For example, you could mix two totally different fonts inside a Rich Text field by setting one to the Italic mode.

What about the bold ?

The bold version of a font is sometimes a different file as well. For the moment, Geckos don't use that possibility of using specific bold version of a font file, but instead render bold text automatically. It could be a later addition to the software.

en/template/custom-fonts.txt · Last modified: 2016/08/10 16:20 by Nicolas Ronvel