source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Improve overstriking.
Date: Wed, 21 Jan 2015 14:41:24 -0500 (EST)	[thread overview]
Message-ID: <830754541940002337.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Improve overstriking.  When overstriking a wider character with a
narrower one, center the latter horizontally.  After a group of
characters printed in the same position, advance by the width of
the widest one among them.

Modified Files:
--------------
    mdocml:
        term_ps.c

Revision Data
-------------
Index: term_ps.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term_ps.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.71 -r1.72
--- term_ps.c
+++ term_ps.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015 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
@@ -60,6 +60,7 @@ struct	termp_ps {
 #define	PS_NEWPAGE	 (1 << 2)	/* new page, no words yet */
 #define	PS_BACKSP	 (1 << 3)	/* last character was backspace */
 	size_t		  pscol;	/* visible column (AFM units) */
+	size_t		  pscolnext;	/* used for overstrike */
 	size_t		  psrow;	/* visible row (AFM units) */
 	char		 *psmarg;	/* margin buf */
 	size_t		  psmargsz;	/* margin buf size */
@@ -1072,7 +1073,7 @@ ps_fclose(struct termp *p)
 static void
 ps_letter(struct termp *p, int arg)
 {
-	size_t		savecol;
+	size_t		savecol, wx;
 	char		c;
 
 	c = arg >= 128 || arg <= 0 ? '?' : arg;
@@ -1144,7 +1145,30 @@ ps_letter(struct termp *p, int arg)
 			ps_setfont(p, p->ps->nextf);
 		}
 		p->ps->nextf = TERMFONT_NONE;
+
+		/*
+		 * For an overstrike, if a previous character
+		 * was wider, advance to center the new one.
+		 */
+
+		if (p->ps->pscolnext) {
+			wx = fonts[p->ps->lastf].gly[(int)p->ps->last-32].wx;
+			if (p->ps->pscol + wx < p->ps->pscolnext)
+				p->ps->pscol = (p->ps->pscol +
+				    p->ps->pscolnext - wx) / 2;
+		}
+
 		ps_pletter(p, p->ps->last);
+
+		/*
+		 * For an overstrike, if a previous character
+		 * was wider, advance to the end of the old one.
+		 */
+
+		if (p->ps->pscol < p->ps->pscolnext) {
+			ps_pclose(p);
+			p->ps->pscol = p->ps->pscolnext;
+		}
 	}
 
 	/*
@@ -1158,13 +1182,19 @@ ps_letter(struct termp *p, int arg)
 
 	/*
 	 * For an overstrike, back up to the previous position.
+	 * If the previous character is wider than any it overstrikes,
+	 * remember the current position, because it might also be
+	 * wider than all that will overstrike it.
 	 */
 
 	if (savecol != SIZE_MAX) {
+		if (p->ps->pscolnext < p->ps->pscol)
+			p->ps->pscolnext = p->ps->pscol;
 		ps_pclose(p);
 		p->ps->pscol = savecol;
 		p->ps->flags &= ~PS_BACKSP;
-	}
+	} else
+		p->ps->pscolnext = 0;
 }
 
 static void
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2015-01-21 19:41 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=830754541940002337.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).