FontData

From Space Engineers Wiki
Jump to navigation Jump to search

The font data (.xml file).

Used in font folders and linked by Font definitions (Fonts.sbc).

Creating a font

This XML file can be generated by the font tools included in the game folder.

  1. Navigate to your game's install folder or SDK folder, then /Tools/Fonts/.
  2. There duplicate Options_dialog.txt and MakeFontDataDialog.bat with new names.
  3. Edit your duplicated .bat with notepad to change the Options_dialog.txt into whatever name you gave your duplicated .txt file.
  4. Edit your duplicated .txt file to change -output's value which decides the names of the files.
  5. Run the duplicated .bat which will open a popup to choose the font to convert into a bitmap font.
  6. Now you have an .xml file and one or more .png textures, you should convert the .png files to .dds and edit the .xml to point to them.
  7. Place these files in your mod's Fonts\YourFontName\.
  8. The last step is to have a Fonts.sbc in your mod's Data folder which points to the xml.

For further documentation on BMFontGen, open BMFontGen/bmfontgen.html.

Glyph data

Visualization of the glyph chracteristics:
FontGlyphData.png

Baseline being the line where you write on, most characters are above this line. Some characters can stretch under it, for example: g, y, q, etc.

Example syntax

You should not be creating this file manually, the docs and example are merely as an idea of what to expect, use the guide above to create a font.

Short example to see the overall syntax

From white font's FontDataPA.xml but trimmed to have an overview, and stripped unused attributes for clarity:

<?xml version="1.0" encoding="UTF-8" ?>
<font
	xmlns="http://xna.microsoft.com/bitmapfont"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xna.microsoft.com/bitmapfont bitmapfont.xsd"
	base="30" height="37">
<bitmaps>
  <bitmap id="0" name="FontDataPA-0.dds" size="1024x1024" />
  <!-- ... -->
</bitmaps>
<glyphs>
  <glyph ch=" "       bm="0" origin="0,0"   size="15x45" aw="8" lsb="-7" ho="0" />
  <glyph ch="&quot;"  bm="0" origin="39,0"  size="25x45" aw="10" lsb="-7" ho="0" />
  <!-- ... -->
</glyphs>
<kernpairs>
  <kernpair left="Ж" right="в" adjust="-1" />
  <!-- ... -->
</kernpairs>
</font>

Elements

base

base (attribute[1])
Type: Int32Default(required)
Distance from top of font to the baseline.

height

height (attribute[1])
Type: Int32Default(required)
Distance from top to bottom of the font.

bitmaps

<bitmaps>
Type: bitmap[]Defaultnull
List of textures that can be used by the <glyph> elements.
id (attribute[1])Type: Int32Default(required)
The number by which this texture is referenced by the <glyph>.
name (attribute[1])Type: stringDefault(required)
Texture file name (preferably .dds) in the same folder as this .xml file.
Note: if this contains FontDataPA or the file is a "Raw RGBA format" (R8G8B8A8 and etc), then it expects the texture to already have color premultiplied by alpha. Otherwise it premultiplies on the pixel shader (which is probably slower).
size (attribute[1])Type: stringDefault(required)
Expects 2 integers separated by x, which specifies the texture's resolution (or max coordinates).
Example:
<bitmaps>
  <bitmap id="0" name="FontDataPA-0.dds" size="1024x1024" />
  <!-- ... -->
</bitmaps>

glyphs

<glyphs>
Type: glyph[]Defaultnull
List of characters supported by this font.
bm (attribute[1])Type: UInt16Default(required)
Texture bitmap id to use. Valid range 0 to 65535.
ch (attribute[1])Type: charDefault(required)
Text character that will be represented. Anything more than one character will be ignored.
origin (attribute[1])Type: stringDefault(required)
X and Y pixel coordinates on the texture to start the boundingbox, from top-left corner.
Values separated by , (comma).
Valid range per value 0 to 65535.
size (attribute[1])Type: stringDefault(required)
Width and height in pixels of the boundingbox.
Values separated by x.
Valid range per value 0 to 255.
lsb (attribute[1])Type: sbyteDefault(required)
Left side bearing, in pixels. Valid range -128 to 127.
aw (attribute[1])Type: byteDefault(required)
Advance width in pixels (see image above). Valid range 0 to 255.
ho (attribute[1])Type: sbyteDefault0
Height offset in pixels. Valid range -128 to 127.
Unused or obsolete elements
wo (attribute[1])Type: -Default-
Not used.
code (attribute[1])Type: stringDefault-
Not used.
forcewhite (attribute[1])Type: boolDefault-
Not used.
Example:
<glyphs>
  <glyph bm="0" ch="+" origin="305,0" size="34x45" lsb="-7" aw="18" ho="0" />
  <!-- ... -->
</glyphs>

kernpairs

<kernpairs>
Type: kernpair[]Defaultnull
Optional list of pairs of characters to ajust spacing between them (kerning).
left (attribute[1])Type: charDefault(required)
A single character, anything more will be ignored.
right (attribute[1])Type: charDefault(required)
A single character, anything more will be ignored.
adjust (attribute[1])Type: sbyteDefault(required)
Offsets advance width by this many pixels. Valid range -128 to 127.
Example:
<kernpairs>
  <kernpair left="Ж" right="в" adjust="-1" />
  <!-- ... -->
</kernpairs>

Obsolete Elements

Elements that exist in the game code or vanilla SBC, but do nothing

Note: this list only contains root-level from this definition only, nothing from inherited ones.

name (attribute[1])Type: StringDefault-
Not used.
face (attribute[1])Type: StringDefault-
Not used.
size (attribute[1])Type: StringDefault-
Not used.