xref: /illumos-gate/usr/src/cmd/mandoc/out.h (revision 6e6545bfaed3bab9ce836ee82d1abd8f2edba89a)
1 /*	$Id: out.h,v 1.33 2018/08/18 20:18:14 schwarze Exp $ */
2 /*
3  * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4  * Copyright (c) 2014, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 enum	roffscale {
20 	SCALE_CM, /* centimeters (c) */
21 	SCALE_IN, /* inches (i) */
22 	SCALE_PC, /* pica (P) */
23 	SCALE_PT, /* points (p) */
24 	SCALE_EM, /* ems (m) */
25 	SCALE_MM, /* mini-ems (M) */
26 	SCALE_EN, /* ens (n) */
27 	SCALE_BU, /* default horizontal (u) */
28 	SCALE_VS, /* default vertical (v) */
29 	SCALE_FS, /* syn. for u (f) */
30 	SCALE_MAX
31 };
32 
33 struct	roffcol {
34 	size_t		 width; /* width of cell */
35 	size_t		 nwidth; /* max. width of number in cell */
36 	size_t		 decimal; /* decimal position in cell */
37 	size_t		 spacing; /* spacing after the column */
38 	int		 flags; /* layout flags, see tbl_cell */
39 };
40 
41 struct	roffsu {
42 	enum roffscale	  unit;
43 	double		  scale;
44 };
45 
46 typedef	size_t	(*tbl_sulen)(const struct roffsu *, void *);
47 typedef	size_t	(*tbl_strlen)(const char *, void *);
48 typedef	size_t	(*tbl_len)(size_t, void *);
49 
50 struct	rofftbl {
51 	tbl_sulen	 sulen; /* calculate scaling unit length */
52 	tbl_strlen	 slen; /* calculate string length */
53 	tbl_len		 len; /* produce width of empty space */
54 	struct roffcol	*cols; /* master column specifiers */
55 	void		*arg; /* passed to sulen, slen, and len */
56 };
57 
58 #define	SCALE_HS_INIT(p, v) \
59 	do { (p)->unit = SCALE_EN; \
60 	     (p)->scale = (v); } \
61 	while (/* CONSTCOND */ 0)
62 
63 
64 struct	tbl_span;
65 
66 const char	 *a2roffsu(const char *, struct roffsu *, enum roffscale);
67 void		  tblcalc(struct rofftbl *tbl,
68 			const struct tbl_span *, size_t, size_t);
69