Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
distancefieldgenerator-manual.qdoc
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page qtdistancefieldgenerator-index.html
6 \title Qt Distance Field Generator Manual
7 \ingroup qttools
8
9 If the user interface of an application has a lot of text, it
10 may cause a small, but noticeable, performance impact the first
11 time it is displayed to the user. This is especially true if the
12 text is rendered in multiple different fonts or use a large amount
13 of distinct characters (common for instance in writing systems such
14 as Hanzi, written Chinese).
15
16 The reason is that in order to render the text efficiently later,
17 Qt will spend some time creating graphical assets for each of the
18 glyphs that will later be reused. This happens the first time a
19 glyph is displayed in the scene.
20
21 For advanced users who want to optimize startup performance, it is
22 possible to pregenerate this font cache, as long as Text.QtRendering
23 is the rendering type in use. The Qt Distance Field Generator tool can
24 be used to pregenerate the cache, either for all glyphs in the fonts,
25 or just a selection that are known to be displayed during a critical
26 phase.
27
28 \note This is a tool that may be used by advanced users
29 to streamline their application in ways that cannot be done
30 automatically by Qt. For most common use cases, the default behavior
31 in Qt will be sufficient.
32
33 \image distancefieldgenerator.png "Qt Distance Field Generator UI"
34
35 \section1 General Usage
36
37 Use the Qt Distance Field Generator in the following way:
38
39 \list
40 \li Load a font file with \gui File > \gui Open font. If the font
41 file is large, there will be some waiting as it reads the fonts
42 and generates the distance fields.
43 \li Once this is done, select the glyphs that you want to save in
44 the pregenerated cache. This should ideally be the glyphs that
45 are used by your application during a performance-critical phase,
46 so that doing the generation ahead of time will give a visible
47 impact on performance.
48 \li Finally, click \gui Save to save the new font file.
49 \endlist
50
51 \note In order to modify a font in this way, you will need to make sure
52 its license does not prohibit it.
53
54 \section1 Selecting Glyphs
55
56 Glyphs can be selected in multiple ways. The simplest way is to click
57 the grid of glyphs to select a particular glyph. You can cancel the
58 selection by clicking on the glyph again.
59
60 In addition, you can use the list of Unicode ranges to select all glyphs
61 matching the characters in a certain range.
62
63 If you want to make sure you pregenerate the glyphs for a specific string
64 from your user interface, you can use the \gui Select > \gui Select string
65 function.
66
67 \note Both of the two latter selection methods base the results
68 on the CMAP table in the font and will not do any shaping.
69
70 \section1 Using the File
71
72 Once you have prepared a file, the next step is to load it in your application.
73 The saved file is a copy of the original font file, and can thus be used in
74 the same ways as any other font file. In addition, it has a special font table
75 which is recognized by Qt and used to prepopulate the glyph cache when the
76 font is used in Qt Quick.
77
78 You can, for instance, load the font using a \c FontLoader in your application
79 code. When it is used to display text in a \c Text element with \c renderType
80 set to \c Text.QtRendering (the default), then the pregenerated cache will be
81 loaded and used.
82
83 \section1 Measuring performance
84
85 For analyzing the impact of distance field generation on your application, you
86 can set the \c QT_LOGGING_RULES environment variable to
87 \c "qt.scenegraph.time.glyph=true".
88
89 When using normal fonts with no built-in cache, you will give output similar to
90 this:
91
92 \code
93 qt.scenegraph.time.glyph: distancefield: 50 glyphs prepared in 16ms, rendering=15, upload=1
94 \endcode
95
96 If you have pregenerated all the glyphs in use, the output will instead read something like
97 this:
98
99 \code
100 qt.scenegraph.time.glyph: distancefield: 50 pre-generated glyphs loaded in 2ms
101 \endcode
102
103 In this case, the time used to prepare the distance fields used to render in the application
104 has been reduced from one full frame (16 ms) to 2 ms. You can also use the output to verify
105 that all the glyphs in use are being loaded from the cache and to identify problematic phases
106 in your application's life cycle, performance-wise.
107*/