source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Implement centering and adjustment to the right margin directly
Date: Thu, 3 Jan 2019 22:21:32 -0500 (EST)	[thread overview]
Message-ID: <05f951e0144c3351@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Implement centering and adjustment to the right margin directly in
the terminal filling routine, controlled by new flags TERMP_CENTER
and TERMP_RIGHT.
This became possible by the recent term_flushln() rewrite.  
No functional change yet, but to be used by upcoming commits.

Modified Files:
--------------
    mandoc:
        term.c
        term.h

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term.c,v
retrieving revision 1.278
retrieving revision 1.279
diff -Lterm.c -Lterm.c -u -p -r1.278 -r1.279
--- term.c
+++ term.c
@@ -135,12 +135,26 @@ term_flushln(struct termp *p)
 		/*
 		 * Figure out how much text will fit in the field.
 		 * If there is whitespace only, print nothing.
-		 * Otherwise, print the field content.
 		 */
 
 		term_fill(p, &nbr, &vbr, vtarget);
 		if (nbr == 0)
 			break;
+
+		/*
+		 * With the CENTER or RIGHT flag, increase the indentation
+		 * to center the text between the left and right margins
+		 * or to adjust it to the right margin, respectively.
+		 */
+
+		if (vbr < vtarget) {
+			if (p->flags & TERMP_CENTER)
+				vbl += (vtarget - vbr) / 2;
+			else if (p->flags & TERMP_RIGHT)
+				vbl += vtarget - vbr;
+		}
+
+		/* Finally, print the field content. */
 
 		term_field(p, vbl, nbr, vbr, vtarget);
 
Index: term.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term.h,v
retrieving revision 1.130
retrieving revision 1.131
diff -Lterm.h -Lterm.h -u -p -r1.130 -r1.131
--- term.h
+++ term.h
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2015, 2017, 2019 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -99,6 +99,8 @@ struct	termp {
 #define	TERMP_NEWMC	 (1 << 18)	/* No .mc printed yet. */
 #define	TERMP_ENDMC	 (1 << 19)	/* Next break ends .mc mode. */
 #define	TERMP_MULTICOL	 (1 << 20)	/* Multiple column mode. */
+#define	TERMP_CENTER	 (1 << 21)	/* Center output lines. */
+#define	TERMP_RIGHT	 (1 << 22)	/* Adjust to the right margin. */
 	enum termtype	  type;		/* Terminal, PS, or PDF. */
 	enum termenc	  enc;		/* Type of encoding. */
 	enum termfont	  fontl;	/* Last font set. */
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2019-01-04  3:21 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=05f951e0144c3351@fantadrom.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.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).