-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdip-FreeTypeTool.html
287 lines (285 loc) · 21.4 KB
/
dip-FreeTypeTool.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>dip::FreeTypeTool class | DIPlib | a library for quantitative image analysis</title>
<link rel="stylesheet" href="m-dip+documentation.compiled.css" />
<link rel="icon" href="DIPlib_logo_32.png" type="image/png" />
<link rel="search" type="application/opensearchdescription+xml" href="opensearch.xml" title="Search DIPlib documentation" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#ffffff" />
</head>
<body>
<header><nav id="navigation">
<div class="m-container">
<div class="m-row">
<span id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">
<a href="https://diplib.org"><img src="DIPlib_logo.svg" alt="" />DIPlib</a><span class="m-breadcrumb">┃</span><a href="index.html" class="m-thin">a library for quantitative image analysis</a><span class="m-breadcrumb">┃</span><a href="https://github.com/DIPlib/diplib/releases/tag/3.5.2" class="m-thin">version 3.5.2</a> </span>
<div class="m-col-t-4 m-hide-m m-text-right m-nopadr">
<a href="#search" class="m-doc-search-icon" title="Search" onclick="return showSearch()"><svg style="height: 0.9rem;" viewBox="0 0 16 16">
<path id="m-doc-search-icon-path" d="m6 0c-3.31 0-6 2.69-6 6 0 3.31 2.69 6 6 6 1.49 0 2.85-0.541 3.89-1.44-0.0164 0.338 0.147 0.759 0.5 1.15l3.22 3.79c0.552 0.614 1.45 0.665 2 0.115 0.55-0.55 0.499-1.45-0.115-2l-3.79-3.22c-0.392-0.353-0.812-0.515-1.15-0.5 0.895-1.05 1.44-2.41 1.44-3.89 0-3.31-2.69-6-6-6zm0 1.56a4.44 4.44 0 0 1 4.44 4.44 4.44 4.44 0 0 1-4.44 4.44 4.44 4.44 0 0 1-4.44-4.44 4.44 4.44 0 0 1 4.44-4.44z"/>
</svg></a>
<a id="m-navbar-show" href="#navigation" title="Show navigation"></a>
<a id="m-navbar-hide" href="#" title="Hide navigation"></a>
</div>
<div id="m-navbar-collapse" class="m-col-t-12 m-show-m m-col-m-none m-right-m">
<div class="m-row">
<ol class="m-col-t-6 m-col-m-none">
<li><a href="pages.html">Pages</a></li>
<li><a href="modules.html">Modules</a></li>
</ol>
<ol class="m-col-t-6 m-col-m-none" start="3">
<li><a href="classes.html">Classes</a></li>
<li><a href="files.html">Files</a></li>
<li class="m-show-m"><a href="#search" class="m-doc-search-icon" title="Search" onclick="return showSearch()"><svg style="height: 0.9rem;" viewBox="0 0 16 16">
<use href="#m-doc-search-icon-path" />
</svg></a></li>
</ol>
</div>
</div>
</div>
</div>
</nav></header>
<main><article>
<div class="m-container m-container-inflatable">
<div class="m-row">
<div class="m-col-l-10 m-push-l-1">
<h1>
<div class="m-doc-include m-thin m-right-m m-text-right">
<a href="generation_drawing.html" class="m-doc">Drawing</a> module<br/><span class="m-code m-thin">#include <a href="file--diplib--generation-h.html">"diplib/generation.h"</a></span> </div>
<span class="m-breadcrumb"><a href="dip.html">dip</a>::<wbr/></span>FreeTypeTool <span class="m-thin">class</span> </h1>
<p>Class used to draw text using a specified font file (TTF, OTF, etc).</p>
<div class="m-block m-default">
<h3>Contents</h3>
<ul>
<li>
Reference
<ul>
<li><a href="#typeless-methods">Constructors, destructors, assignment and conversion operators</a></li>
<li><a href="#nested-classes">Classes</a></li>
<li><a href="#function-members">Functions</a></li>
</ul>
</li>
</ul>
</div>
<p>An object of this class must first be given the file name of a font on disk, which can be done either in the
constructor or through <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-SetFont-String-CL"><code>dip::FreeTypeTool::SetFont</code></a>. This font is subsequently used to render text in an image using <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL"><code>dip::FreeTypeTool::DrawText</code></a>.
The text size can be specified by calling <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-SetSize-dfloat-"><code>dip::FreeTypeTool::SetSize</code></a> before rendering.</p>
<p>This class supports the most common font file formats (TrueType, Type 1, CID-keyed and OpenType/CFF fonts are
supported). A default font is not provided because there is no standard for where these files are
to be found (on some platforms it’s an easier problem than on others). A program that uses <code>FreeTypeTool</code> could
be distributed with a font file.</p>
<p>Example usage:</p>
<div class="m-code"><pre><span></span><span class="n">dip</span><span class="o">::</span><span class="n">FreeTypeTool</span><span class="w"> </span><span class="n">freeTypeTool</span><span class="p">(</span><span class="w"> </span><span class="s">"/usr/share/fonts/truetype/times.ttf"</span><span class="w"> </span><span class="p">);</span>
</pre></div>
<aside class="m-note m-primary">
<h4>Note on thread-safety</h4>
<p>Setting a font through <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-SetFont-String-CL"><code>dip::FreeTypeTool::SetFont</code></a> is not thread-safe. The FreeType documentation says that the functionality
used in <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL"><code>dip::FreeTypeTool::DrawText</code></a> is thread-safe, though I don’t see how this function would work properly if called from
two threads at the same time. I would recommend using a mutex in a multi-threaded environment if the same object
is shared among threads. Ideally, each thread would create their own <code>FreeTypeTool</code> object, which is perfectly
safe to do.</p>
</aside>
<p><code>FreeTypeTool</code> objects cannot be copied, they can only be moved.</p>
<aside class="m-note m-warning">
<h4>Warning</h4>
<p>This class only works if <em>DIPlib</em> was configured to link to the FreeType library. By default this is not the
case, and none of the binary releases produced by the <em>DIPlib</em> project enable this functionality. If you want
to use this class, you need to compile <em>DIPlib</em> yourself. Otherwise, use <a href="generation_drawing.html#dip-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL"><code>dip::DrawText</code></a>, which uses a
hard-coded font.</p>
</aside>
<section id="typeless-methods">
<h2>Constructors, destructors, assignment and conversion operators</h2>
<dl class="m-doc">
<dt id="dip-FreeTypeTool-FreeTypeTool">
<span class="m-doc-wrap-bumper"><a href="#dip-FreeTypeTool-FreeTypeTool" class="m-doc-self">FreeTypeTool</a>(</span><span class="m-doc-wrap">)</span>
</dt>
<dd>A default-constructed object cannot be used until a font is set with <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-SetFont-String-CL"><code>dip::FreeTypeTool::SetFont</code></a>.</dd>
<dt id="dip-FreeTypeTool-FreeTypeTool-String-CL">
<span class="m-doc-wrap-bumper"><a href="#dip-FreeTypeTool-FreeTypeTool-String-CL" class="m-doc-self">FreeTypeTool</a>(</span><span class="m-doc-wrap"><a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& font) <span class="m-label m-flat m-info">explicit</span> </span>
</dt>
<dd>This constructor immediately sets a font, see <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-SetFont-String-CL"><code>dip::FreeTypeTool::SetFont</code></a> for details.</dd>
</dl>
</section>
<section id="nested-classes">
<h2>Classes</h2>
<dl class="m-doc">
<dt>
struct <a href="#dip-FreeTypeTool-TextInfo" class="m-doc">TextInfo</a>
</dt>
<dd>Data structure returned by <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-DrawText-String-CL-dfloat-"><code>dip::FreeTypeTool::DrawText</code></a>. <a href="#dip-FreeTypeTool-TextInfo">more...</a></dd>
</dl>
</section>
<section id="function-members">
<h2>Functions</h2>
<dl class="m-doc">
<dt>
<span class="m-doc-wrap-bumper">void <a href="#dip-FreeTypeTool-SetFont-String-CL" class="m-doc">SetFont</a>(</span><span class="m-doc-wrap"><a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& font)</span>
</dt>
<dd>Set the font to be used to render text. <a href="#dip-FreeTypeTool-SetFont-String-CL">more...</a></dd>
<dt>
<span class="m-doc-wrap-bumper">void <a href="#dip-FreeTypeTool-SetSize-dfloat-" class="m-doc">SetSize</a>(</span><span class="m-doc-wrap"><a href="pixeltypes.html#dip-dfloat" class="m-doc">dip::dfloat</a> size)</span>
</dt>
<dd>Set the font size to be used to render text. <a href="#dip-FreeTypeTool-SetSize-dfloat-">more...</a></dd>
<dt>
<span class="m-doc-wrap-bumper">void <a href="#dip-FreeTypeTool-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL" class="m-doc">DrawText</a>(</span><span class="m-doc-wrap"><a href="dip-Image.html" class="m-doc">dip::Image</a>& out,
<a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& text,
<a href="supporttypes.html#dip-FloatArray" class="m-doc">dip::FloatArray</a> origin,
<a href="dip-Image-Pixel.html" class="m-doc">dip::Image::Pixel</a> const& value = {1},
<a href="pixeltypes.html#dip-dfloat" class="m-doc">dip::dfloat</a> orientation = 0,
<a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& align = S::LEFT)</span>
</dt>
<dd>Render text in an existing image. <a href="#dip-FreeTypeTool-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL">more...</a></dd>
<dt>
<span class="m-doc-wrap-bumper">auto <a href="#dip-FreeTypeTool-DrawText-String-CL-dfloat-" class="m-doc">DrawText</a>(</span><span class="m-doc-wrap"><a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& text,
<a href="pixeltypes.html#dip-dfloat" class="m-doc">dip::dfloat</a> orientation = 0) -> <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-TextInfo" class="m-doc">dip::FreeTypeTool::TextInfo</a></span>
</dt>
<dd>Alternate version of the function above that returns a new image tightly cropped around the rendered text. <a href="#dip-FreeTypeTool-DrawText-String-CL-dfloat-">more...</a></dd>
</dl>
</section>
<section>
<h2>Class documentation</h2>
<section class="m-doc-details" id="dip-FreeTypeTool-TextInfo"><div>
<h3>
struct <a href="#dip-FreeTypeTool-TextInfo" class="m-doc-self">TextInfo</a>
</h3>
<p>Data structure returned by <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-DrawText-String-CL-dfloat-"><code>dip::FreeTypeTool::DrawText</code></a>.</p>
<table class="m-table m-fullwidth m-first-tight m-flat m-doc">
<thead><tr><th>Variables</th><th></th></tr></thead>
<tbody>
<tr>
<td>
<a href="dip-Image.html" class="m-doc">dip::Image</a> <a href="#dip-FreeTypeTool-TextInfo-image" class="m-doc-self" id="dip-FreeTypeTool-TextInfo-image">image</a> </td>
<td>
The image with the rendered text.
</td>
</tr>
<tr>
<td>
<a href="supporttypes.html#dip-IntegerArray" class="m-doc">dip::IntegerArray</a> <a href="#dip-FreeTypeTool-TextInfo-left" class="m-doc-self" id="dip-FreeTypeTool-TextInfo-left">left</a> </td>
<td>
Coordinates within <code>image</code> of the point on the baseline at the left edge of the text.
</td>
</tr>
<tr>
<td>
<a href="supporttypes.html#dip-IntegerArray" class="m-doc">dip::IntegerArray</a> <a href="#dip-FreeTypeTool-TextInfo-right" class="m-doc-self" id="dip-FreeTypeTool-TextInfo-right">right</a> </td>
<td>
Coordinates within <code>image</code> of the point on the baseline at the right edge of the text.
</td>
</tr>
</tbody>
</table>
</div></section>
</section>
<section>
<h2>Function documentation</h2>
<section class="m-doc-details" id="dip-FreeTypeTool-SetFont-String-CL"><div>
<h3>
<span class="m-doc-wrap-bumper">void
</span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#dip-FreeTypeTool-SetFont-String-CL" class="m-doc-self">SetFont</a>(</span><span class="m-doc-wrap"><a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& font)</span></span>
</h3>
<p>Set the font to be used to render text.</p>
<p><code>font</code> is the full path to a file with a type face description (TrueType, Type 1, CID-keyed and OpenType/CFF
fonts are supported).</p>
<p>It is fine to switch fonts in between calls to <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL"><code>dip::FreeTypeTool::DrawText</code></a>. When changing the font, the size selected
through <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-SetSize-dfloat-"><code>dip::FreeTypeTool::SetSize</code></a> is not preserved, and needs to be set anew. By default, the size is set to 12 pixels.</p>
<p>This function is not thread-safe.</p>
</div></section>
<section class="m-doc-details" id="dip-FreeTypeTool-SetSize-dfloat-"><div>
<h3>
<span class="m-doc-wrap-bumper">void
</span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#dip-FreeTypeTool-SetSize-dfloat-" class="m-doc-self">SetSize</a>(</span><span class="m-doc-wrap"><a href="pixeltypes.html#dip-dfloat" class="m-doc">dip::dfloat</a> size)</span></span>
</h3>
<p>Set the font size to be used to render text.</p>
<p><code>size</code> is the EM square size in pixels (equivalent to the size in points at 72 dpi). It depends on the
selected font how many pixels a letter actually takes up.</p>
</div></section>
<section class="m-doc-details" id="dip-FreeTypeTool-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL"><div>
<h3>
<span class="m-doc-wrap-bumper">void
</span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#dip-FreeTypeTool-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL" class="m-doc-self">DrawText</a>(</span><span class="m-doc-wrap"><a href="dip-Image.html" class="m-doc">dip::Image</a>& out,
<a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& text,
<a href="supporttypes.html#dip-FloatArray" class="m-doc">dip::FloatArray</a> origin,
<a href="dip-Image-Pixel.html" class="m-doc">dip::Image::Pixel</a> const& value = {1},
<a href="pixeltypes.html#dip-dfloat" class="m-doc">dip::dfloat</a> orientation = 0,
<a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& align = S::LEFT)</span></span>
</h3>
<p>Render text in an existing image.</p>
<p>Draws text in the image <code>out</code>, at location <code>origin</code>, with a color given by <code>value</code>, and rotated according to
<code>orientation</code>.</p>
<p><code>text</code> is any UTF-8 encoded string, even if Unicode support was not enabled when building <em>DIPlib</em>. But note
that any ASCII string is also a properly UTF-8 encoded string. Characters that don’t have a glyph in the given
type face <code>font</code> will be rendered with the character known as “missing glyph”, typically a box or a space.
Note that control characters such as the newline and the backspace are not treated specially, and thus they
will be drawn as a missing glyph. To draw multiple lines of text, call this function for each line in turn.</p>
<p><code>origin</code> is the pixel coordinates of a point on the base line. If <code>align</code> is <code>"left"</code>, <code>origin</code> is a point
on the left edge of the rendered text; if <code>align</code> is <code>"right"</code>, it is a point on the right edge; and if it
is <code>"center"</code>, it is the point halfway between the left and right edges.
<code>orientation</code> is in radian, with 0 for horizontal text, and increasing clockwise.</p>
<p><code>out</code> must be a forged 2D image. If <code>out</code> is binary, the anti-aliased glyphs will be thresholded.
<code>value</code> must have the same number of tensor elements as <code>out</code>. If <code>value</code> is scalar, this value will be used
for all tensor elements.</p>
</div></section>
<section class="m-doc-details" id="dip-FreeTypeTool-DrawText-String-CL-dfloat-"><div>
<h3>
<span class="m-doc-wrap-bumper"><a href="dip-FreeTypeTool.html#dip-FreeTypeTool-TextInfo" class="m-doc">dip::FreeTypeTool::TextInfo</a>
</span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#dip-FreeTypeTool-DrawText-String-CL-dfloat-" class="m-doc-self">DrawText</a>(</span><span class="m-doc-wrap"><a href="supporttypes.html#dip-String" class="m-doc">dip::String</a> const& text,
<a href="pixeltypes.html#dip-dfloat" class="m-doc">dip::dfloat</a> orientation = 0)</span></span>
</h3>
<p>Alternate version of the function above that returns a new image tightly cropped around the rendered text.</p>
<p>The output image is a 2D scalar image of type <a href="pixeltypes.html#dip-DT_UINT8"><code>dip::DT_UINT8</code></a>, with white text on a black background.
The output data structure additionally contains the two end points of the baseline, on either side of the
rendered text.</p>
<p>See <a href="dip-FreeTypeTool.html#dip-FreeTypeTool-DrawText-Image-L-String-CL-FloatArray--Image-Pixel-CL-dfloat--String-CL"><code>dip::FreeTypeTool::DrawText</code></a>
for a description of the <code>text</code> and <code>orientation</code> arguments.</p>
</div></section>
</section>
</div>
</div>
</div>
</article></main>
<div class="m-doc-search" id="search">
<a href="#!" onclick="return hideSearch()"></a>
<div class="m-container">
<div class="m-row">
<div class="m-col-m-8 m-push-m-2">
<div class="m-doc-search-header m-text m-small">
<div><span class="m-label m-default">Tab</span> / <span class="m-label m-default">T</span> to search, <span class="m-label m-default">Esc</span> to close</div>
<div id="search-symbolcount">…</div>
</div>
<div class="m-doc-search-content">
<form action="https://diplib.org/diplib-docs/#search">
<input type="search" name="q" id="search-input" placeholder="Loading …" disabled="disabled" autofocus="autofocus" autocomplete="off" spellcheck="false" />
</form>
<noscript class="m-text m-danger m-text-center">Unlike everything else in the docs, the search functionality <em>requires</em> JavaScript. Enable it or <a href="https://google.com/search?q=site:diplib.org+">use an external search engine</a>.</noscript>
<div id="search-help" class="m-text m-dim m-text-center">
<p class="m-noindent">Search for symbols, directories, files, pages or modules.
You can omit any prefix from the symbol or file path; adding a <code>:</code> or
<code>/</code> suffix lists all members of given symbol or directory.</p>
<p class="m-noindent">Use <span class="m-label m-dim">↓</span> / <span class="m-label m-dim">↑</span> to navigate through the list,
<span class="m-label m-dim">Enter</span> to go.
<span class="m-label m-dim">Tab</span> autocompletes common prefix.
You can copy a link to the result using <span class="m-label m-dim">⌘</span> <span class="m-label m-dim">L</span>,
or <span class="m-label m-dim">⌘</span> <span class="m-label m-dim">M</span> to copy a Markdown link.</p>
</div>
<div id="search-notfound" class="m-text m-warning m-text-center">Sorry, nothing was found.<br />Maybe try a full-text <a href="#" id="search-external" data-search-engine="https://google.com/search?q=site:diplib.org+{query}">search with external engine</a>?</div>
<ul id="search-results"></ul>
</div>
</div>
</div>
</div>
</div>
<script src="search-v1.js"></script>
<script src="searchdata-v1.js" async="async"></script>
<footer><nav>
<div class="m-container">
<div class="m-row">
<div class="m-col-l-10 m-push-l-1">
<p>DIPlib, a library for quantitative image analysis. Documentation compiled with <a href="https://crisluengo.github.io/doxpp/">dox++</a> and styled with <a href="https://mcss.mosra.cz/">m.css</a>.</p>
</div>
</div>
</div>
</nav></footer>
</body>
</html>