blob: 5e1b09ab6cadaaea7a53e02e5d6054824f7df240 [file] [log] [blame]
allocsubfont, freesubfont, installsubfont, lookupsubfont, uninstallsubfont, subfontname, readsubfont, readsubfonti, writesubfont, stringsubfont, strsubfontwidth, mkfont \- subfont manipulation
.B #include <u.h>
.B #include <libc.h>
.B #include <draw.h>
.ta \w'\fLSubfont* 'u
Subfont* allocsubfont(char *name, int n, int height, int ascent,
Fontchar *info, Image *i)
void freesubfont(Subfont *f)
void installsubfont(char *name, Subfont *f)
Subfont* lookupsubfont(Subfont *f)
void uninstallsubfont(Subfont *f)
Subfont* readsubfont(Display *d, char *name, int fd, int dolock)
Subfont* readsubfonti(Display *d, char *name, int fd, Image *im,
int dolock)
int writesubfont(int fd, Subfont *f)
Point stringsubfont(Image *dst, Point p, Image *src,
Subfont *f, char *str)
Point strsubfontwidth(Subfont *f, char *s)
Font* mkfont(Subfont *f, Rune min)
Subfonts are the components of fonts that hold the character images.
A font comprises an array of subfonts; see
.IR cachechars (3).
A new
.B Subfont
is allocated and initialized with
.IR allocsubfont .
.IR cachechars (3)
for the meaning of
.IR n ,
.IR height ,
.IR ascent ,
.IR info ,
and the arrangement of characters in
.IR i .
.I name
is used to identify the subfont in the subfont cache; see the descriptions
.I lookupsubfont
.IR installsubfont
.RI ( q.v. ).
The appropriate fields of the returned
.B Subfont
structure are set to
the passed arguments, and the image is registered as a subfont
with the graphics device
.IR draw (3).
.I Allocsubfont
returns 0 on failure.
.I Freesubfont
frees a subfont and all its associated structure including the
associated image.
.I freesbufont
.I free
.BR f->info ,
.B f->info
was not allocated by
.IR malloc (3)
it should be zeroed before calling
.IR subffree .
A number of subfonts are kept in external files.
The convention for naming subfont files is:
.B \*9/font/\fIname\fP/\fIclass\fP.\fIsize\fP.\fIdepth
.I size
is approximately the height in pixels of the lower case letters
(without ascenders or descenders).
If there is only one version of the subfont, the
.BI \&. depth
extension is elided.
.I Class
describes the range of runes encoded in the subfont:
.BR ascii ,
.BR latin1 ,
.BR greek ,
Subfonts are cached within the program, so a subfont shared between fonts will be loaded only once.
.I Installsubfont
stores subfont
.I f
under the given
.IR name ,
typically the file name from which it was read.
.I Uninstallsubfont
removes the subfont from the cache.
.I lookupsubfont
searches for a subfont with the given
.I name
in the cache and returns it, or nil if no such subfont exists.
.I Subfontname
is used to locate subfonts given their names within the fonts.
The default version constructs a name given the
.IR cfname ,
its name within the font,
.IR fname ,
the name of the font, and the maximum depth suitable for this subfont.
This interface allows a partially specified name within a font to be resolved
at run-time to the name of a file holding a suitable subfont.
Although it is principally a routine internal to the library,
.I subfontname
may be substituted by the application to provide a less file-oriented subfont naming scheme.
The format of a subfont file is described in
.IR font (7).
Briefly, it contains a image with all the characters in it,
followed by a subfont header, followed by character information.
.I Readsubfont
reads a subfont from the file descriptor
.IR fd .
.I name
is used to identify the font in the cache.
.I dolock
argument specifies whether the routine should synchronize
use of the
.I Display
with other processes; for single-threaded applications it may
always be zero.
.I Readsubfonti
does the same for a subfont whose associated image is already in memory; it is passed as the
.IR im .
In other words,
.I readsubfonti
reads only the header and character information from the file descriptor.
.I Writesubfont
writes on
.I fd
the part of a subfont file that comes after the image. It should be preceded by
a call to
.IR writeimage
.IR allocimage (3)).
.I Stringsubfont
is analogous to
.B string
.IR draw (3))
for subfonts. Rather than use the underlying font caching primitives,
it calls
.B draw
for each character.
It is intended for stand-alone environments such as operating system kernels.
.I Strsubfontwidth
returns the width of the string
.I s
as it would appear if drawn with
.I stringsubfont
.B Subfont
.BR f .
.I Mkfont
takes as argument a
.B Subfont
.I s
and returns a pointer to a
.B Font
that maps the character images in
.I s
into the
.B Runes
.I min
.IB min + s ->n-1\f1.
.TF \*9/font
.B \*9/font
bitmap font file tree
.B \*9/src/libdraw
.IR graphics (3),
.IR allocimage (3),
.IR draw (3),
.IR cachechars (3),
.IR image (7),
.IR font (7)
All of the functions use the graphics error function (see
.IR graphics (3)).