Clarify some documentation slightly.
[dcpomatic.git] / doc / design / fonts
1 How a font makes its way through the encoding process
2
3
4 Import a DCP containing some subtitles with fonts.
5
6 * Examiner
7
8 Builds _fonts containing (font-ID, font-TTF-data)
9 Add to allocator (asset-ID, font-ID)
10
11 font-ID will be unique in its own asset, but not more widely.
12
13 Use the allocator to set the font ID to N_font-ID where N is an integer unique for all fonts in the DCP.
14
15 If there's no fonts in the DCP, add one with an empty ID - we want something in the content for users
16 to edit.
17
18
19 Now the text content contains fonts with IDs unique within the content.
20
21
22 * DCP Decoder
23
24 Some subtitle arrives with an "original" font ID.
25 Use an allocator (built the same way as in the examiner) to replace the ID with a new one N_font-ID.
26
27
28 Q: Why do we need the allocator?
29 A: Because we need an ID to refer to each font in the content (to be stored in metadata.xml)
30    and we need to turn this ID back into an actual Font C++ object so it must be unique within
31    the content.  Also we allow these fonts to have their settings altered so they must have unique
32    IDs for that.
33
34
35 * Text Decoder
36
37 Calls content->get_font() to get the Font C++ object by the (newly-allocated) ID.  This works because
38 the allocated font-ID is unique within the content.
39
40 The Font C++ object pointer is written to the subtitle.
41
42
43 * Player
44
45 Passes subtitles through.
46
47
48 * Writer
49
50 Gets all fonts, puts them in the FontIDMap using the font's re-written ID.
51
52
53 * Reel Writer
54
55 Gets subtitles, uses FontIDMap to find the ID from the Font C++ object pointer.  Puts this ID in
56 the font and writes it to the asset.  Ensures the required LoadFont is added.
57
58
59
60 To put this all another way, we need to:
61
62 1. Make some Content-unique ID from a random font ID.  Then we can store this in the metadata.xml, and the user can change the font.
63
64 2. Then do the same trick later, with the same result, so the decoder can receive the random font ID and go via the Content-unique
65 ID to get the actual font TTF from the Content.
66
67 In both these situations a string is the easiest thing (to go in some XML, and to go in a dcp::SubtitleString).
68
69 This whole problem really is just that a single TextContent represents multiple
70 DCP reels, and each reel can have a different font with the same font ID.