From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: implement the tbl(7) "center" layout option
Date: Tue, 27 Jan 2015 23:20:05 -0500 (EST) [thread overview]
Message-ID: <14965663987573997446.enqueue@fantadrom.bsd.lv> (raw)
Log Message:
-----------
implement the tbl(7) "center" layout option
Modified Files:
--------------
mdocml:
tbl.7
tbl_term.c
Revision Data
-------------
Index: tbl.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl.7,v
retrieving revision 1.24
retrieving revision 1.25
diff -Ltbl.7 -Ltbl.7 -u -p -r1.24 -r1.25
--- tbl.7
+++ tbl.7
@@ -152,7 +152,6 @@ For GNU compatibility, this may also be
.Cm frame .
.It Cm center
Center the table instead of left-adjusting it.
-Currently ignored.
For GNU compatibility, this may also be invoked with
.Cm centre .
.It Cm decimalpoint
Index: tbl_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl_term.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -Ltbl_term.c -Ltbl_term.c -u -p -r1.33 -r1.34
--- tbl_term.c
+++ tbl_term.c
@@ -63,8 +63,9 @@ term_tbl(struct termp *tp, const struct
const struct tbl_head *hp;
const struct tbl_cell *cp;
const struct tbl_dat *dp;
+ static size_t offset;
+ size_t rmargin, maxrmargin, tsz;
int horiz, spans, vert;
- size_t rmargin, maxrmargin;
rmargin = tp->rmargin;
maxrmargin = tp->maxrmargin;
@@ -90,6 +91,21 @@ term_tbl(struct termp *tp, const struct
tblcalc(&tp->tbl, sp, rmargin - tp->offset);
+ /* Center the table as a whole. */
+
+ offset = tp->offset;
+ if (sp->opts->opts & TBL_OPT_CENTRE) {
+ tsz = sp->opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX)
+ ? 2 : !!sp->opts->lvert + !!sp->opts->rvert;
+ for (hp = sp->head; hp != NULL; hp = hp->next)
+ tsz += tp->tbl.cols[hp->ident].width + 3;
+ tsz -= 3;
+ if (offset + tsz > rmargin)
+ tsz -= 1;
+ tp->offset = (offset + rmargin > tsz) ?
+ (offset + rmargin - tsz) / 2 : 0;
+ }
+
/* Horizontal frame at the start of boxed tables. */
if (sp->opts->opts & TBL_OPT_DBOX)
@@ -189,12 +205,12 @@ term_tbl(struct termp *tp, const struct
assert(tp->tbl.cols);
free(tp->tbl.cols);
tp->tbl.cols = NULL;
+ tp->offset = offset;
}
tp->flags &= ~TERMP_NONOSPACE;
tp->rmargin = rmargin;
tp->maxrmargin = maxrmargin;
-
}
/*
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2015-01-28 4:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14965663987573997446.enqueue@fantadrom.bsd.lv \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).