summary refs log tree commit diff
path: root/pbmtext.html
blob: 38dc2c899a127c2aace737c8f26d780344de0cbf (plain) (blame)
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD><TITLE>Pbmtext User Manual</TITLE></HEAD>
<BODY>
<H1>pbmtext</H1>
Updated: 14 June 2010
<BR>
<A HREF="#index">Table Of Contents</A>

<H2>NAME</H2>

pbmtext - render text into a PBM image

<H2 id="synopsis">SYNOPSIS</H2>

<B>pbmtext</B>
[<B>-font</B> <I>fontfile</I>]
[<B>-builtin</B> <I>fontname</I>]
[<B>-space</B> <I>pixels</I>]
[<B>-lspace</B> <I>pixels</I>]
[<B>-nomargins</B>]
[<B>-width</B> <i>pixels</i>]
[<I>text</I>]

<p>Minimum unique abbreviation of option is acceptable.  You may use double
hyphens instead of single hyphen to denote options.  You may use white
space in place of the equals sign to separate an option name from its value.


<H2 id="description">DESCRIPTION</H2>

<p>This program is part of <a href="index.html">Netpbm</a>.

<P><b>pbmtext</b> takes the specified text, either a single line from
the command line or multiple lines from standard input, and renders it
into a PBM graphical image.

<P>In the image, each line of input is a line of output.  Formatting
characters such as newline have no effect on the formatting; like any
unprintable character, they turn into spaces.

<P>The image is just wide enough for the longest line of text, plus
margins, and just high enough to contain the lines of text, plus
margins.

<P>The left and right margins are twice the width of the widest
character in the font; the top and bottom margins are the height of
the tallest character in the font.  But if the text is only one line,
all the margins are half of this.  You can use the <b>-nomargins</b> option
to eliminate the margins.

<p><b>pbmtextps</b> does the same thing as <b>pbmtext</b>, but uses
Ghostscript to generate the characters, which means you can use
Postscript fonts.  But it also means you have to have Ghostscript
installed and it isn't as fast.  Also, <b>pbmtextps</b> generates only
one line of text, whereas <b>pbmtext</b> can create multiple lines.

<p><b>pbmtext</b> is meant for small quantities of simple text.  If you're
working with a <em>document</em>, you would be better off using a document
formatting program to &quot;print&quot; to a Postscript file, then
feeding that Postscript to <b>pstopnm</b>.

<H2 id="options">OPTIONS</H2>

<DL COMPACT>

<DT><B>-font</B>
<DT><B>-builtin</B>

<DD>

<b>-builtin</b> selects a font among those built into Netpbm.

<b>-font</b> selects a font that you supply yourself either as an X
Window System <a href="http://xfree86.org/current/bdf.pdf">BDF (Bitmap
Distribution Format)</a> file or as a PBM file in a special form.

<p>The default is the built in font &quot;bdf.&quot;

<p>&quot;bdf&quot; is Times-Roman 15 pixels high.  (That's about 14
point type printed at 75 dpi).

<p>&quot;fixed&quot; is a built in fixed width font.

<p>For information about other fonts, and how to make one of your own,
see <a href="#fonts">Fonts</a> below.


<DT><B>-space</B> <I>pixels</I>

<DD> Add <I>pixels</I> pixels of space between characters.  This is in
addition to whatever space surrounding characters is built into the
font, which is usually enough to produce a reasonable string of text.

<P><I>pixels</I> may be fractional, in which case the number of
pixels added varies so as to achieve the specified average.  For
example <B>-space=1.5</B> causes half the spaces to be 1 pixel and
half to be 2 pixels.

<P><I>pixels</I> may be negative to crowd text together, but the
author has not put much thought or testing into how this works in
every possible case, so it might cause disastrous results.

<DT><B>-lspace</B> <I>pixels</I>

<DD> Add <I>pixels</I> pixels of space between lines.  This is in
addition to whatever space above and below characters is built into
the font, which is usually enough to produce a reasonable line
spacing.

<P><I>pixels</I> must be a whole number.

<P><I>pixels</I> may be negative to crowd lines together, but the
author has not put much thought or testing into how this works in
every possible case, so it might cause disastrous results.

<DT><b>-nomargins</b>

<DD>By default, <b>pbmtext</b> adds margins all around the image as
described above.  This option causes <b>pbmtext</b> not to add any
margins.

<p>Note that there may still be space beyond the edges of the type
because a character itself may include space at its edges.  To eliminate
all surrounding background, so the type touches all four edges of the
image, use <b>pnmcrop</b>.

<DT><b>-width</b> <i>pixels</i>

<DD>This specifies how much horizontal space the text is supposed to fit
into.  

<p>If the input is one line, <b>pbmtext</b> breaks it into multiple
lines as needed to fit the specified width.  It breaks it between
characters, but does not pay attention to white space; it may break in
the middle of a word and a line may begin or end with white space.

<p>If the input is multiple lines, <b>pbmtext</b> assumes you already
have line breaks where they make sense, and <b>pbmtext</b> simply
truncates each line as needed to fit the specified width.

</DL>


<H2 id="usage">USAGE</H2>

<P>Often, you want to place text over another image.  One way to do this is
with <B>ppmlabel</B>.  For more flexible (but complex) drawing of text on an
image, there is <b>ppmdraw</b>.  These do not give you the font options that
<B>pbmtext</B> does, though.

<P>Another way is to use <B>pbmtext</B> to create an image containing
the text, then use <B>pamcomp</B> to overlay the text image onto your
base image.  To make only the text (and not the entire rectangle
containing it) cover the base image, you will need to give
<B>pamcomp</B> a mask, via its <B>-alpha</B> option.  You can just use
the text image itself as the mask, as long as you also specify the
<B>-invert</B> option to <B>pamcomp</B>.

<P>If you want to overlay colored text instead of black, just use
<B>ppmchange</B> to change all black pixels to the color of your
choice before overlaying the text image.  But still use the original
black and white image for the alpha mask.

<P>If you want the text at an angle, use <B>pnmrotate</B> on the text
image (and alpha mask) before overlaying.

<h2 id="fonts">FONTS</h2>

<p>There are three kinds of fonts you an use with <b>pbmtext</b>:

<ul>
<li>built in
<li>BDF
<li>PBM
</ul>

<h3>Built In Fonts</h3>

<p>There are two built in fonts: <b>bdf</b> and <b>fixed</b>.  You select
these fonts with a <b>-builtin</b> option.

<p><b>bdf</b> is the default when you specify no font information on the
command line.

<p><b>bdf</b> is encoded in ISO 8859-1 (Latin 1, 8-bit).  In addition to
English it can handle most West European languages (Spanish, French, German,
Swedish ...)  This set lacks the Euro currency sign.

<p><b>fixed</b> is ASCII (7-bit) only.


<h3>BDF Font</h3>

<p>BDF is an ancient font format that at one time was standard for the
X Window System.  Now, you don't see it very often, but you can find
some BDF fonts on the <a
href="http://cvsweb.xfree86.org/cvsweb/xc/fonts/bdf/">Xfree86</a>
web site.

<p>You can get the full package of the BDF fonts from XFree86 (see
above) from the <a
href="http://netpbm.sourceforge.net/bdffont.tgz">Netpbm web site</a>.

<h3>PBM Font</h3>

<p>To create a font as a PBM file (to use with the <b>-font</b>
option), you just create a PBM image of the text matrix below.

<p>The first step is to display text matrix below on the screen,
e.g. in an X11 window.

<PRE>

    M &quot;,/^_[`jpqy| M

    /  !&quot;#$%&amp;'()*+ /
    &lt; ,-./01234567 &lt;
    &gt; 89:;&lt;=&gt;?@ABC &gt;
    @ DEFGHIJKLMNO @
    _ PQRSTUVWXYZ[ _
    { \]^_`abcdefg {
    } hijklmnopqrs }
    ~ tuvwxyz{|}~  ~

    M &quot;,/^_[`jpqy| M

</PRE>

<p>Make sure it's a fixed width font -- This should display as a
perfect rectangle.

<p>Also, try to use a simple display program.  Pbmtext divides this
into a matrix of cells, all the same size, each containing one
character, so it is important that whatever you use to display it
display with uniform horizontal and vertical spacing.  Fancy word
processing programs sometimes stretch characters in both directions to
fit certain dimensions, and that won't work.  Sometimes a display
program scales a font to show a character larger or smaller than its
natural size.  That too won't often work because the rounding involved
in such scaling causes non-uniform distances between characters.

<p>If you display the text matrix improperly, the usual symptom is
that when you try to use the font, <b>pbmtext</b> fails with an error
message telling you that the number of lines in the font isn't
divisible by 11, or it can't find the blank band around the inner
rectangle.  Sometimes the symptom is that one of the characters
displays with a piece of the character that is next to it in the
matrix.  For example, &quot;l&quot; might display with a little piece
of the &quot;m&quot; attached on its right.

<p>Do a screen grab or window dump of that text, using for instance
<B>xwd</B>, <B>xgrabsc</B>, or <B>screendump</B>.  Convert the result
into a pbm file.  If necessary, use <B>pamcut</B> to remove anything
you grabbed in addition to the text pictured above (or be a wimp and
use a graphical editor such as ImageMagick).  Finally, run it through
<B>pnmcrop</B>.  to make sure the edges are right up against the text.
<B>pbmtext</B> can figure out the sizes and spacings from that.


<h2 id="nonenglish">NON-ENGLISH TEXT</h2>

<p><b>pbmtext</b> does little to accommodate the special needs of non-English
text.

<p><b>pbmtext</b> reads input in byte units.  Unicode (utf-7, utf-8, utf-16,
etc.) text which contains multibyte characters does not work.

<p><b>pbmtext</b> can handle 7-bit and 8-bit character sets.  Examples are
ASCII, ISO 8859 family, koi8-r/u and VISCII.  It is up to the user to supply a
BDF file covering the necessary glyphs with the "-font" option.  The font file
must be in the right encoding.

<p><b>pbmtext</b> does not recognize locale.  It ignores the associated
environment variables.

<p><b>pbmtext</b> cannot render vertically or right to left.


<h2 id="tips">TIPS</h2>

<p>If you get garbled output, check whether the font file encoding corresponds
to the input text encoding.  Also make sure that your input is not in utf-* or
any other multi-byte format.

<p>To dump characters in a BDF font file run this command:

<pre>
<tt>
    $ awk 'BEGIN { for (i=0x01; i&lt;=0xFF; i++)  
                    { printf(&quot;%c%s&quot;,i,i%16==15 ? &quot;\n&quot;:&quot;&quot;); } }' |\
      pbmtext -f font.bdf &gt; dump.pbm
</tt>
</pre>

<p>If you need only ASCII, change the for statement to:

<pre>
<tt>
     for (i=0x20; i&lt;=0x7E; i++)  
</tt>
</pre>

<p>To check the encoding of a BDF file, examine the CHARSET_REGISTRY
line and the next line, which should be CHARSET_ENCODING:

<pre>
<tt>
    $ grep -A1 CHARSET_REGISTRY font-a.bdf
    CHARSET_REGISTRY &quot;ISO8859&quot;
    CHARSET_ENCODING &quot;1&quot;
    
    $ grep -A1 CHARSET_REGISTRY font-b.bdf
    CHARSET_REGISTRY &quot;ISO10646&quot;
    CHARSET_ENCODING &quot;1&quot;
</tt>
</pre>

<p>The latter is Unicode.  BDF files coded in ISO 16046-1 usually work for
Western European languages, because ISO 16046-1 expands ISO 8859-1 (also
called &quot;Latin-1&quot;) while maintaining the first 256 code points.  ISO
8859-1 itself is a superset of ASCII.  Run the above command and verify the
necessary glyphs are present.

<p>It may sound strange that <b>pbmtext</b> accepts font files encoded in
Unicode but not input text in Unicode.  This is because Unicode provides
several &quot;numbering schemes&quot;.

<p>When rendering text in character sets other than ISO 8859-1, one often has
to produce a BDF file in the given encoding from a master BDF file encoded in
ISO 10646-1.

<p>In particular, 75% of the BDF files in the font collection available from
<a href="http://netpbm.sourceforge.net/bdffont.tgz">the Netpbm website</a> are
in ISO 10646-1.  Many have the Euro sign, Greek letters, etc, but they are
placed in code points beyond what <b>pbmtext</b> sees.

<p>There are several programs that perform BDF encoding conversion.  If you
have the X Window System installed, first look for <b>ucs2any</b>.  If you
don't, you can download <b>ucs2any.pl</b> from <a
href="http://www.cl.cam.ac.uk/~mgk25/ucs-fonts.html">Unicode fonts and tools
for X11</a>.  This website has much useful information on fonts.

<p>Another converter is <b>trbdf</b>, included in the &quot;trscripts&quot;
package, available in some GNU/Linux distributions.

<p>BDF files encoded in ISO 8859-2, ISO 8859-7, koi8-r, etc. are available
from <a href="http://czyborra.com/charsets/iso8859.html">ISO 8859 Alphabet
Soup</a> and its sister page <a
href="http://czyborra.com/charsets/cyrillic.html">The Cyrillic Charset
Soup</a>.  Though the information is dated, these pages give a good overview
of 8-bit character sets.

<p>To convert OTF or TTF font files to BDF, use 

<a href="http://www.math.nmsu.edu/~mleisher/Software/otf2bdf">
<b>otf2bdf</b> by Mike Leisher</a>.


<H2 id="seealso">SEE ALSO</H2>

<B><A HREF="pbmtextps.html">pbmtextps</A></B>,
<B><A HREF="pamcut.html">pamcut</A></B>,
<B><A HREF="pnmcrop.html">pnmcrop</A></B>,
<B><A HREF="pamcomp.html">pamcomp</A></B>,
<B><A HREF="ppmchange.html">ppmchange</A></B>,
<B><A HREF="pnmrotate.html">pnmrotate</A></B>,
<B><A HREF="ppmlabel.html">ppmlabel</A></B>,
<B><A HREF="ppmdraw.html">ppmdraw</A></B>,
<B><A HREF="pstopnm.html">pstopnm</A></B>,
<B><A HREF="pbm.html">pbm</A></B>,
<b><a href="http://www.pango.org">Pango</a></b>,
<b><a href="http://cairographics.org">Cairo</a></b>

<H2 id="author">AUTHOR</H2>

Copyright (C) 1993 by Jef Poskanzer and George Phillips

<HR>
<H2 id="index">Table Of Contents</H2>
<UL>
<LI><A HREF="#synopsis">SYNOPSIS</A>
<LI><A HREF="#description">DESCRIPTION</A>
<LI><A HREF="#options">OPTIONS</A>
<LI><A HREF="#usage">USAGE</A>
<LI><A HREF="#fonts">FONTS</A>
<LI><A HREF="#nonenglish">Non-English Text</A>
<LI><A HREF="#tips">TIPS</A>
<LI><A HREF="#seealso">SEE ALSO</A>
<LI><A HREF="#author">AUTHOR</A>
</UL>
</BODY>
</HTML>