Looking back through the archives there's a recurring theme of people
having problems with the letter spacing of xft fonts when used with
rxvt-unicode. The root cause of this seems to be variability in the
metrics reported by different versions of xft - having just upgraded
from Ubuntu 8.10 to 9.04 I found the rxvt was spacing the same font out
by a couple of pixels extra compared to the previous version, and rxvt's
font metric code doesn't appear to have changed between the two
releases.

So I've implemented an option to allow people to work around these
variations in font metrics. In the same way that the lineSpace option
allows extra pixels to be added between lines of text, I've added a
letterSpace option that allows extra pixels to be added (or removed)
between columns. If the font you prefer has metrics that result in rxvt
spacing it out more than you'd like you can use the letterSpace option
to squeeze the characters together again.

The patch makes no changes to rxvt's existing font metric computation
code, and the default letter spacing adjustment is 0 so the patch has no
effect unless the user explicitly adjusts the letter spacing, either on
the command line or in X resources.

Thoughts?

-Mark.

From 26cf73f0168f335d946b9e3ef56815937099e775 Mon Sep 17 00:00:00 2001
From: Mark H. Wilkinson <m...@kremvax.net>
Date: Wed, 6 May 2009 17:57:56 +0100
Subject: [PATCH] Add letterSpace option to adjust character letter spacing.

---
 doc/rxvt.1.man.in |    6 +++++
 doc/rxvt.1.pod    |    7 ++++++
 src/feature.h     |    5 ++++
 src/init.C        |    4 +++
 src/main.C        |    1 +
 src/rsinc.h       |    1 +
 src/rxvt.h        |    1 +
 src/rxvtperl.xs   |   62 +++++++++++++++++++++++++++-------------------------
 src/urxvt.pm      |    6 ++--
 src/xdefaults.C   |    1 +
 10 files changed, 61 insertions(+), 33 deletions(-)

diff --git a/doc/rxvt.1.man.in b/doc/rxvt.1.man.in
index 37a548f..e795ce1 100644
--- a/doc/rxvt.1.man.in
+++ b/doc/rxvt.1.man.in
@@ -456,6 +456,12 @@ resource \fBskipBuiltinGlyphs\fR.
 Compile \fIfrills\fR: Lines (pixel height) to insert between each row of
 the display. Useful to work around font rendering problems; resource
 \&\fBlineSpace\fR.
+.IP "\fB\-letsp\fR \fInumber\fR" 4
+.IX Item "-letsp number"
+Compile \fIfrills\fR: Amount to adjust the computed character width by
+to control overall letter spacing. Negative values will tighten up the
+letter spacing, positive values will space letters out more. Useful to
+work around odd font metrics; resource \&\fBletterSpace\fR.
 .IP "\fB\-tn\fR \fItermname\fR" 4
 .IX Item "-tn termname"
 This option specifies the name of the terminal type to be set in the
diff --git a/doc/rxvt.1.pod b/doc/rxvt.1.pod
index 841c0b3..3de6766 100644
--- a/doc/rxvt.1.pod
+++ b/doc/rxvt.1.pod
@@ -369,6 +369,13 @@ Compile I<frills>: Lines (pixel height) to insert between each row of
 the display. Useful to work around font rendering problems; resource
 B<lineSpace>.
 
+=item B<-letsp> I<number>
+
+Compile I<frills>: Amount to adjust the computed character width by
+to control overall letter spacing. Negative values will tighten up the
+letter spacing, positive values will space letters out more. Useful to
+work around odd font metrics; resource B<letterSpace>.
+
 =item B<-tn> I<termname>
 
 This option specifies the name of the terminal type to be set in the
diff --git a/src/feature.h b/src/feature.h
index df1af13..3507cca 100644
--- a/src/feature.h
+++ b/src/feature.h
@@ -379,6 +379,11 @@
 #define LINESPACE	0
 
 /*
+ * Default number of extra dots between columns
+ */
+#define LETTERSPACE	0
+
+/*
  * Default number of lines in the scrollback buffer
  */
 #define SAVELINES	1000
diff --git a/src/init.C b/src/init.C
index 6c9e640..e0142c3 100644
--- a/src/init.C
+++ b/src/init.C
@@ -295,6 +295,7 @@ rxvt_term::init_vars ()
   int_bwidth = INTERNALBORDERWIDTH;
   ext_bwidth = EXTERNALBORDERWIDTH;
   lineSpace = LINESPACE;
+  letterSpace = LETTERSPACE;
   saveLines = SAVELINES;
 
   refresh_type = SLOW_REFRESH;
@@ -450,6 +451,9 @@ rxvt_term::init_resources (int argc, const char *const *argv)
 
   if (rs[Rs_lineSpace] && (i = atoi (rs[Rs_lineSpace])) >= 0)
     lineSpace = min (i, std::numeric_limits<int16_t>::max ());
+
+  if (rs[Rs_letterSpace])
+    letterSpace = atoi (rs[Rs_letterSpace]);
 #endif
 
 #ifdef POINTER_BLANK
diff --git a/src/main.C b/src/main.C
index fd126ff..aa96337 100644
--- a/src/main.C
+++ b/src/main.C
@@ -690,6 +690,7 @@ rxvt_term::set_fonts ()
 
   prop = (*fs)[1]->properties ();
   prop.height += lineSpace;
+  prop.width += letterSpace;
 
   fs->set_prop (prop, false);
 
diff --git a/src/rsinc.h b/src/rsinc.h
index 903a771..0667bf8 100644
--- a/src/rsinc.h
+++ b/src/rsinc.h
@@ -75,6 +75,7 @@
   def (int_bwidth)
   def (borderLess)
   def (lineSpace)
+  def (letterSpace)
   def (cursorUnderline)
   def (urgentOnBell)
 #endif
diff --git a/src/rxvt.h b/src/rxvt.h
index e19f201..39a313e 100644
--- a/src/rxvt.h
+++ b/src/rxvt.h
@@ -849,6 +849,7 @@ struct TermWin_t
   int            int_bwidth;    /* internal border width                    */
   int            ext_bwidth;    /* external border width                    */
   int            lineSpace;     /* number of extra pixels between rows      */
+  int            letterSpace;   /* number of extra pixels between columns   */
   int            saveLines;     /* number of lines that fit in scrollback   */
   int            total_rows;    /* total number of rows in this terminal    */
   int            term_start;    /* term lines start here                    */
diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs
index 369e3ce..924981f 100644
--- a/src/rxvtperl.xs
+++ b/src/rxvtperl.xs
@@ -1057,40 +1057,42 @@ rxvt_term::locale ()
 
 #define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
 
-#define TERM_OFFSET_width      TERM_OFFSET(width)
-#define TERM_OFFSET_height     TERM_OFFSET(height)
-#define TERM_OFFSET_fwidth     TERM_OFFSET(fwidth)
-#define TERM_OFFSET_fheight    TERM_OFFSET(fheight)
-#define TERM_OFFSET_fbase      TERM_OFFSET(fbase)
-#define TERM_OFFSET_nrow       TERM_OFFSET(nrow)
-#define TERM_OFFSET_ncol       TERM_OFFSET(ncol)
-#define TERM_OFFSET_focus      TERM_OFFSET(focus)
-#define TERM_OFFSET_mapped     TERM_OFFSET(mapped)
-#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
-#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
-#define TERM_OFFSET_lineSpace  TERM_OFFSET(lineSpace)
-#define TERM_OFFSET_saveLines  TERM_OFFSET(saveLines)
-#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
-#define TERM_OFFSET_top_row    TERM_OFFSET(top_row)
+#define TERM_OFFSET_width       TERM_OFFSET(width)
+#define TERM_OFFSET_height      TERM_OFFSET(height)
+#define TERM_OFFSET_fwidth      TERM_OFFSET(fwidth)
+#define TERM_OFFSET_fheight     TERM_OFFSET(fheight)
+#define TERM_OFFSET_fbase       TERM_OFFSET(fbase)
+#define TERM_OFFSET_nrow        TERM_OFFSET(nrow)
+#define TERM_OFFSET_ncol        TERM_OFFSET(ncol)
+#define TERM_OFFSET_focus       TERM_OFFSET(focus)
+#define TERM_OFFSET_mapped      TERM_OFFSET(mapped)
+#define TERM_OFFSET_int_bwidth  TERM_OFFSET(int_bwidth)
+#define TERM_OFFSET_ext_bwidth  TERM_OFFSET(ext_bwidth)
+#define TERM_OFFSET_lineSpace   TERM_OFFSET(lineSpace)
+#define TERM_OFFSET_letterSpace TERM_OFFSET(letterSpace)
+#define TERM_OFFSET_saveLines   TERM_OFFSET(saveLines)
+#define TERM_OFFSET_total_rows  TERM_OFFSET(total_rows)
+#define TERM_OFFSET_top_row     TERM_OFFSET(top_row)
 
 int
 rxvt_term::width ()
 	ALIAS:
-           width      = TERM_OFFSET_width
-           height     = TERM_OFFSET_height
-           fwidth     = TERM_OFFSET_fwidth
-           fheight    = TERM_OFFSET_fheight
-           fbase      = TERM_OFFSET_fbase
-           nrow       = TERM_OFFSET_nrow
-           ncol       = TERM_OFFSET_ncol
-           focus      = TERM_OFFSET_focus
-           mapped     = TERM_OFFSET_mapped
-           int_bwidth = TERM_OFFSET_int_bwidth
-           ext_bwidth = TERM_OFFSET_ext_bwidth
-           lineSpace  = TERM_OFFSET_lineSpace
-           saveLines  = TERM_OFFSET_saveLines
-           total_rows = TERM_OFFSET_total_rows
-           top_row    = TERM_OFFSET_top_row
+           width       = TERM_OFFSET_width
+           height      = TERM_OFFSET_height
+           fwidth      = TERM_OFFSET_fwidth
+           fheight     = TERM_OFFSET_fheight
+           fbase       = TERM_OFFSET_fbase
+           nrow        = TERM_OFFSET_nrow
+           ncol        = TERM_OFFSET_ncol
+           focus       = TERM_OFFSET_focus
+           mapped      = TERM_OFFSET_mapped
+           int_bwidth  = TERM_OFFSET_int_bwidth
+           ext_bwidth  = TERM_OFFSET_ext_bwidth
+           lineSpace   = TERM_OFFSET_lineSpace
+           letterSpace = TERM_OFFSET_letterSpace
+           saveLines   = TERM_OFFSET_saveLines
+           total_rows  = TERM_OFFSET_total_rows
+           top_row     = TERM_OFFSET_top_row
 	CODE:
         RETVAL = *(int *)((char *)THIS + ix);
         OUTPUT:
diff --git a/src/urxvt.pm b/src/urxvt.pm
index e8b6e0d..690a89b 100644
--- a/src/urxvt.pm
+++ b/src/urxvt.pm
@@ -1286,9 +1286,9 @@ to see the actual list:
   borderLess chdir color cursorBlink cursorUnderline cutchars delete_key
   display_name embed ext_bwidth fade font geometry hold iconName
   imFont imLocale inputMethod insecure int_bwidth intensityStyles
-  italicFont jumpScroll lineSpace loginShell mapAlert meta8 modifier
-  mouseWheelScrollPage name override_redirect pastableTabs path perl_eval
-  perl_ext_1 perl_ext_2 perl_lib pointerBlank pointerBlankDelay
+  italicFont jumpScroll lineSpace letterSpace loginShell mapAlert meta8
+  modifier mouseWheelScrollPage name override_redirect pastableTabs path
+  perl_eval perl_ext_1 perl_ext_2 perl_lib pointerBlank pointerBlankDelay
   preeditType print_pipe pty_fd reverseVideo saveLines scrollBar
   scrollBar_align scrollBar_floating scrollBar_right scrollBar_thickness
   scrollTtyKeypress scrollTtyOutput scrollWithBuffer scrollstyle
diff --git a/src/xdefaults.C b/src/xdefaults.C
index 1b654c5..4edb00c 100644
--- a/src/xdefaults.C
+++ b/src/xdefaults.C
@@ -229,6 +229,7 @@ optList[] = {
               STRG (Rs_int_bwidth, "internalBorder", "b", "number", "internal border in pixels"),
               BOOL (Rs_borderLess, "borderLess", "bl", Opt_borderLess, 0, "borderless window"),
               STRG (Rs_lineSpace, "lineSpace", "lsp", "number", "number of extra pixels between rows"),
+              STRG (Rs_letterSpace, "letterSpace", "letsp", "number", "letter spacing adjustment"),
 #endif
 #ifdef BUILTIN_GLYPHS
               BOOL (Rs_skipBuiltinGlyphs, "skipBuiltinGlyphs", "sbg", Opt_skipBuiltinGlyphs, 0, "do not use internal glyphs"),
-- 
1.6.1

_______________________________________________
rxvt-unicode mailing list
rxvt-unicode@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/rxvt-unicode

Reply via email to