A script can carry whole files inside its [Fonts] and
[Graphics] sections. The encoding is defined in Appendix B of the
SubStation Alpha specification. In practice, Matroska files more often carry fonts
as separate attachments.
Sections
| Section | First line of each file | Notes |
|---|---|---|
[Fonts] | fontname: name | Only TrueType fonts can be embedded. The file name is the font’s name, then _, an optional B for bold, an optional I for italic, a character set number and .ttf, as in comic_0.ttf. |
[Graphics] | filename: name | Files are saved to a Pictures folder, and looked up first beside the script. |
The keyword must be lower case, because upper-case letters cannot appear in the encoded data, and that is how a reader finds the next file.
Encoding
The encoded data is ASCII text. It works like the older uuencode scheme.
- Take the data three bytes at a time, as 24 bits.
- Split those bits into four 6-bit values.
- Add 33 to each value and write the ASCII character.
- Write lines of 80 characters, the last being shorter.
| Bytes left at the end | Rule | Characters |
|---|---|---|
| 1 | Multiply by 0x100, encode the top 12 bits. | 2 |
| 2 | Multiply by 0x10000, encode the top 18 bits. | 3 |
There is no terminator. A file ends at a new [section], a new
fontname: or filename: line, or the end of the script.
Worked example
Bytes 41 42 43 "ABC"
Bits 010000 010100 001001 000011
Values 16 20 9 3
+33 49 53 42 36
Text 1 5 * $
15*$.