Hi,

pango 1.44 dropped support for pcf and bdf bitmap fonts. This makes for example the terminus font unavailable in all gtk applications, including gvim.

Making changes to gvim, fonttosfnt, terminus-font and the fontconfig configuration I can now use bitmap fonts in gvim again:


## fonttosfnt

It is possible to convert pcf and bdf fonts to OpenType .otb files using fonttosfnt shipped with xenocara. The current version of fonttosfnt does strange things to the font metrics which will confuse applications like gvim or gnome-terminal and cause them to use too large character cells resulting in a stretched look. Although I do understand only little about font formats and metrics I tried successfully to "fix" fonttosfnt:
https://gitlab.freedesktop.org/xorg/app/fonttosfnt/-/merge_requests/7
Cave: You must not put more than one font face into a single otf file (although fonttosfnt offers this option). It would not work properly in several ways.
A diff for our xenocara fonttosfnt is attached.


## gvim

gVim would mess up rounding of character cell sizes until 8.2.0857:
https://github.com/vim/vim/pull/6168
A diff for editors/vim port is attached.


## fontconfig

fontconfig (being used by pango-gtk-gvim) will prefer pcf fonts over otf (TrueType) fonts and therefore provide pango with font data that it cannot handle anymore and display just garbage. In the hope that every application using fontconfig will also support TrueType fonts I use this sledgehammer to prefer TrueType:

/usr/src/xenocara/dist/fontconfig/conf.d/48-truetype.conf:
```
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!--
  Prefer truetype (ttf, otf, otb) fonts
  because pango dropped support for pcf / bdf fonts
 -->
        <match>
                <edit mode="append" name="fontformat">
                        <string>TrueType</string>
                </edit>
        </match>
</fontconfig>
```

I'm afraid this may prevent PCF fonts from being accessed by fontconfig applications, but I'm not yet sure of this. Other options might be to request TrueType only for fonts providing .otb files or for special apps. On second thought it might be enough to patch pango to always request TrueType fontformat?


## Terminus and other bitmap fonts

With all those "fixes" in place one can now simply generate the .otb files in the font ports. The diff for terminus-font is attached.


Thoughts? OKs?

Christopher



--
http://gmerlin.de
OpenPGP: http://gmerlin.de/christopher.pub
CB07 DA40 B0B6 571D 35E2  0DEF 87E2 92A7 13E5 DEE1
Index: struct.c
===================================================================
RCS file: /cvs/xenocara/app/fonttosfnt/struct.c,v
retrieving revision 1.3
diff -u -p -r1.3 struct.c
--- struct.c	14 Jan 2020 20:52:17 -0000	1.3
+++ struct.c	16 Jun 2020 08:46:03 -0000
@@ -453,7 +453,7 @@ glyphMetrics(FontPtr font, int code,
         if(bitmap) {
             if(width_return)
                 *width_return = 
-                    (((float)bitmap->advanceWidth + 0.5) / strike->sizeX) *
+                    (((float)bitmap->advanceWidth) / strike->sizeX) *
                     TWO_SIXTEENTH;
             if(x_min_return)
                 *x_min_return =
@@ -463,17 +463,13 @@ glyphMetrics(FontPtr font, int code,
                 *y_min_return =
                     (((float)bitmap->horiBearingY - bitmap->height) 
                      / strike->sizeY) * TWO_SIXTEENTH;
-            /* For the following two, 0.9 instead of 0.5 might make
-               more sense.  However, using different rounding rules
-               for x_max and awidth causes problems for detecting
-               charcell fonts. */
             if(x_max_return)
                 *x_max_return =
-                    (((float)bitmap->horiBearingX + bitmap->width + 0.5)
+                    (((float)bitmap->horiBearingX + bitmap->width)
                      / strike->sizeX) * TWO_SIXTEENTH;
             if(y_max_return)
                 *y_max_return =
-                    (((float)bitmap->horiBearingY + 0.5) / strike->sizeY) *
+                    (((float)bitmap->horiBearingY) / strike->sizeY) *
                     TWO_SIXTEENTH;
             return 1;
         }
Index: util.c
===================================================================
RCS file: /cvs/xenocara/app/fonttosfnt/util.c,v
retrieving revision 1.4
diff -u -p -r1.4 util.c
--- util.c	14 Jan 2020 20:52:17 -0000	1.4
+++ util.c	16 Jun 2020 08:46:03 -0000
@@ -237,6 +237,7 @@ macTime(int *hi, unsigned *lo)
 unsigned
 faceFoundry(FT_Face face)
 {
+    char buf[5];
     int rc;
     BDF_PropertyRec prop;
 
@@ -280,8 +281,10 @@ faceFoundry(FT_Face face)
             return makeName("URW ");
         else if(strcasecmp(prop.u.atom, "y&y") == 0)
             return makeName("Y&Y ");
-        else
-            return makeName("UNKN");
+        else {
+	    strncpy(buf, prop.u.atom, sizeof(buf) - 1);
+            return makeName(buf);
+	}
     }
     /* For now */
     return makeName("UNKN");
Index: write.c
===================================================================
RCS file: /cvs/xenocara/app/fonttosfnt/write.c,v
retrieving revision 1.2
diff -u -p -r1.2 write.c
--- write.c	13 Jun 2008 00:04:06 -0000	1.2
+++ write.c	16 Jun 2020 08:46:03 -0000
@@ -851,7 +851,7 @@ writehhea(FILE* out, FontPtr font)
     writeULONG(out, 0x00010000); /* version */
     writeSHORT(out, FONT_UNITS_CEIL(max_y)); /* ascender */
     writeSHORT(out, FONT_UNITS_FLOOR(min_y)); /* descender */
-    writeSHORT(out, FONT_UNITS(TWO_SIXTEENTH / 20)); /* lineGap */
+    writeSHORT(out, 0);		/* lineGap */
     writeUSHORT(out, FONT_UNITS(max_awidth)); /* advanceWidthMax */
     writeSHORT(out, FONT_UNITS_FLOOR(min_x)); /* minLeftSideBearing */
     writeSHORT(out, FONT_UNITS_FLOOR(min_x)); /* minRightSideBearing */
@@ -1017,9 +1017,8 @@ writeOS2(FILE* out, FontPtr font)
     writeUSHORT(out, 0x20);     /* usFirstCharIndex; */
     writeUSHORT(out, 0xFFFD);   /* usLastCharIndex; */
     writeUSHORT(out, FONT_UNITS_CEIL(max_y)); /* sTypoAscender; */
-    writeUSHORT(out, -FONT_UNITS_FLOOR(min_y)); /* sTypoDescender; */
-    writeUSHORT(out, FONT_UNITS(max_y - min_y));
-    /* sTypoLineGap; */
+    writeUSHORT(out, FONT_UNITS_FLOOR(min_y)); /* sTypoDescender; */
+    writeUSHORT(out, 0);	/* sTypoLineGap; */
     writeUSHORT(out, FONT_UNITS_CEIL(max_y)); /* usWinAscent; */
     writeUSHORT(out, -FONT_UNITS_FLOOR(min_y)); /* usWinDescent; */
     writeULONG(out, 3);         /* ulCodePageRange1; */
Index: Makefile
===================================================================
RCS file: /cvs/ports/editors/vim/Makefile,v
retrieving revision 1.199
diff -u -p -r1.199 Makefile
--- Makefile    2 Jun 2020 20:09:55 -0000       1.199
+++ Makefile    16 Jun 2020 08:49:28 -0000
@@ -3,7 +3,7 @@
 COMMENT-main=  vi clone, many additional features
 COMMENT-lang=  vi clone, NLS subpackage
 
-V=             8.2.0885
+V=             8.2.0986
 GH_ACCOUNT=    vim
 GH_PROJECT=    vim
 GH_TAGNAME=    v$V
Index: distinfo
===================================================================
RCS file: /cvs/ports/editors/vim/distinfo,v
retrieving revision 1.77
diff -u -p -r1.77 distinfo
--- distinfo    2 Jun 2020 20:09:55 -0000       1.77
+++ distinfo    16 Jun 2020 08:49:28 -0000
@@ -1,2 +1,2 @@
-SHA256 (vim-8.2.0885.tar.gz) = 2c/96DcojqHEBJ16yDoQ3+UqzQ0j8l90Z3q1zHRzygQ=
-SIZE (vim-8.2.0885.tar.gz) = 14984424
+SHA256 (vim-8.2.0986.tar.gz) = 7jqaXm3vppWcTTzHh+wdTiT4FTm8pAveCPDaeFNHx3k=
+SIZE (vim-8.2.0986.tar.gz) = 15016978
Index: pkg/PLIST-main
===================================================================
RCS file: /cvs/ports/editors/vim/pkg/PLIST-main,v
retrieving revision 1.37
diff -u -p -r1.37 PLIST-main
--- pkg/PLIST-main      2 Jun 2020 20:09:55 -0000       1.37
+++ pkg/PLIST-main      16 Jun 2020 08:49:28 -0000
@@ -295,6 +295,7 @@ share/vim/${P}/doc/usr_42.txt
 share/vim/${P}/doc/usr_43.txt
 share/vim/${P}/doc/usr_44.txt
 share/vim/${P}/doc/usr_45.txt
+share/vim/${P}/doc/usr_46.txt
 share/vim/${P}/doc/usr_90.txt
 share/vim/${P}/doc/usr_toc.txt
 share/vim/${P}/doc/various.txt
@@ -325,6 +326,7 @@ share/vim/${P}/ftplugin/alsaconf.vim
 share/vim/${P}/ftplugin/ant.vim
 share/vim/${P}/ftplugin/arch.vim
 share/vim/${P}/ftplugin/art.vim
+share/vim/${P}/ftplugin/asm.vim
 share/vim/${P}/ftplugin/aspvbs.vim
 share/vim/${P}/ftplugin/automake.vim
 share/vim/${P}/ftplugin/awk.vim
@@ -370,6 +372,7 @@ share/vim/${P}/ftplugin/dtrace.vim
 share/vim/${P}/ftplugin/dune.vim
 share/vim/${P}/ftplugin/eiffel.vim
 share/vim/${P}/ftplugin/elinks.vim
+share/vim/${P}/ftplugin/elm.vim
 share/vim/${P}/ftplugin/erlang.vim
 share/vim/${P}/ftplugin/eruby.vim
 share/vim/${P}/ftplugin/eterm.vim
@@ -578,6 +581,7 @@ share/vim/${P}/indent/dtd.vim
 share/vim/${P}/indent/dtrace.vim
 share/vim/${P}/indent/dylan.vim
 share/vim/${P}/indent/eiffel.vim
+share/vim/${P}/indent/elm.vim
 share/vim/${P}/indent/erlang.vim
 share/vim/${P}/indent/eruby.vim
 share/vim/${P}/indent/eterm.vim
@@ -1052,6 +1056,7 @@ share/vim/${P}/syntax/edif.vim
 share/vim/${P}/syntax/eiffel.vim
 share/vim/${P}/syntax/elf.vim
 share/vim/${P}/syntax/elinks.vim
+share/vim/${P}/syntax/elm.vim
 share/vim/${P}/syntax/elmfilt.vim
 share/vim/${P}/syntax/erlang.vim
 share/vim/${P}/syntax/eruby.vim
Index: Makefile
===================================================================
RCS file: /cvs/ports/fonts/terminus-font/Makefile,v
retrieving revision 1.17
diff -u -p -r1.17 Makefile
--- Makefile    25 May 2020 04:30:13 -0000      1.17
+++ Makefile    16 Jun 2020 08:50:03 -0000
@@ -4,7 +4,7 @@ COMMENT =               fixed width fonts especially 
 
 DISTNAME =             terminus-font-4.47
 CATEGORIES =           fonts x11
-REVISION =             1
+REVISION =             2
 
 HOMEPAGE =             http://terminus-font.sourceforge.net/
 
@@ -45,13 +45,20 @@ PATCH_LIST = patch-* ${FLAVOR_PATCHES}
 
 PKG_ARCH =     *
 
-do-install:
+post-build:
+       cd ${WRKSRC} && \
+       for bdf in ter-u???.bdf; do \
+               ${X11BASE}/bin/fonttosfnt -o `basename $$bdf .bdf`.otb $$bdf; \
+       done
        ${GZIP_CMD} ${WRKSRC}/*.pcf
+
+do-install:
        ${X11BASE}/bin/mkfontdir ${WRKSRC}
        egrep '\.pcf\.gz' ${WRKSRC}/fonts.dir | \
                sed 's/\.pcf\.gz//g' > ${WRKSRC}/fonts.alias
        ${INSTALL_DATA_DIR} ${FONTDIR}
        ${INSTALL_DATA} ${WRKSRC}/*.pcf.gz ${FONTDIR}
+       ${INSTALL_DATA} ${WRKSRC}/*.otb ${FONTDIR}
        ${INSTALL_DATA} ${WRKBUILD}/fonts.alias ${FONTDIR}/fonts.alias-terminus
 
        ${INSTALL_DATA_DIR} ${PREFIX}/share/misc/pcvtfonts
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/fonts/terminus-font/pkg/PLIST,v
retrieving revision 1.5
diff -u -p -r1.5 PLIST
--- pkg/PLIST   17 Mar 2019 15:24:15 -0000      1.5
+++ pkg/PLIST   16 Jun 2020 08:50:03 -0000
@@ -220,23 +220,43 @@ share/fonts/terminus/ter-p28b.pcf.gz
 share/fonts/terminus/ter-p28n.pcf.gz
 share/fonts/terminus/ter-p32b.pcf.gz
 share/fonts/terminus/ter-p32n.pcf.gz
+share/fonts/terminus/ter-u12b.otb
 @comment share/fonts/terminus/ter-u12b.pcf.gz
+share/fonts/terminus/ter-u12n.otb
 share/fonts/terminus/ter-u12n.pcf.gz
+share/fonts/terminus/ter-u14b.otb
 share/fonts/terminus/ter-u14b.pcf.gz
+share/fonts/terminus/ter-u14n.otb
 share/fonts/terminus/ter-u14n.pcf.gz
+share/fonts/terminus/ter-u14v.otb
+share/fonts/terminus/ter-u16b.otb
 share/fonts/terminus/ter-u16b.pcf.gz
+share/fonts/terminus/ter-u16n.otb
 share/fonts/terminus/ter-u16n.pcf.gz
+share/fonts/terminus/ter-u16v.otb
+share/fonts/terminus/ter-u18b.otb
 share/fonts/terminus/ter-u18b.pcf.gz
+share/fonts/terminus/ter-u18n.otb
 share/fonts/terminus/ter-u18n.pcf.gz
+share/fonts/terminus/ter-u20b.otb
 share/fonts/terminus/ter-u20b.pcf.gz
+share/fonts/terminus/ter-u20n.otb
 share/fonts/terminus/ter-u20n.pcf.gz
+share/fonts/terminus/ter-u22b.otb
 share/fonts/terminus/ter-u22b.pcf.gz
+share/fonts/terminus/ter-u22n.otb
 share/fonts/terminus/ter-u22n.pcf.gz
+share/fonts/terminus/ter-u24b.otb
 share/fonts/terminus/ter-u24b.pcf.gz
+share/fonts/terminus/ter-u24n.otb
 share/fonts/terminus/ter-u24n.pcf.gz
+share/fonts/terminus/ter-u28b.otb
 share/fonts/terminus/ter-u28b.pcf.gz
+share/fonts/terminus/ter-u28n.otb
 share/fonts/terminus/ter-u28n.pcf.gz
+share/fonts/terminus/ter-u32b.otb
 share/fonts/terminus/ter-u32b.pcf.gz
+share/fonts/terminus/ter-u32n.otb
 share/fonts/terminus/ter-u32n.pcf.gz
 @comment share/fonts/terminus/ter-x12b.pcf.gz
 share/fonts/terminus/ter-x12n.pcf.gz

Reply via email to