1 /* $Id: out.h,v 1.36 2025/07/16 14:33:08 schwarze Exp $ */ 2 /* 3 * Copyright (c) 2011,2014,2017,2018,2025 Ingo Schwarze <schwarze@openbsd.org> 4 * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 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 * Utilities for use by multiple mandoc(1) formatters. 19 */ 20 21 enum roffscale { 22 SCALE_CM, /* centimeters (c) */ 23 SCALE_IN, /* inches (i) */ 24 SCALE_PC, /* pica (P) */ 25 SCALE_PT, /* points (p) */ 26 SCALE_EM, /* ems (m) */ 27 SCALE_MM, /* mini-ems (M) */ 28 SCALE_EN, /* ens (n) */ 29 SCALE_BU, /* default horizontal (u) */ 30 SCALE_VS, /* default vertical (v) */ 31 SCALE_FS, /* syn. for u (f) */ 32 SCALE_MAX 33 }; 34 35 struct roffcol { 36 size_t width; /* Width of cell [BU]. */ 37 size_t nwidth; /* Maximum width of number [BU]. */ 38 size_t decimal; /* Decimal position [BU]. */ 39 size_t spacing; /* Spacing after the column [EN]. */ 40 int flags; /* Layout flags, see tbl_cell. */ 41 }; 42 43 struct roffsu { 44 enum roffscale unit; 45 double scale; 46 }; 47 48 typedef size_t (*tbl_strlen)(const char *, void *); 49 typedef size_t (*tbl_len)(size_t, void *); 50 51 struct rofftbl { 52 tbl_strlen slen; /* Calculate string length [BU]. */ 53 tbl_len len; /* Produce width of empty space [BU]. */ 54 struct roffcol *cols; /* Master column specifiers. */ 55 void *arg; /* Passed to slen() and len(). */ 56 }; 57 58 59 struct tbl_span; 60 61 const char *a2roffsu(const char *, struct roffsu *, enum roffscale); 62 void tblcalc(struct rofftbl *, 63 const struct tbl_span *, size_t, size_t); 64