On Sun, Jun 28, 2020 at 12:44:09PM +0100, Stuart Henderson wrote:
> On 2020/06/28 12:53, Antoine Jacoutot wrote:
> > On Sat, Jun 27, 2020 at 04:14:35PM +0200, Christopher Zimmermann wrote:
> > > Hi,
> > > 
> > > I'm trying to fix monospace bitmap font support for gvim (gtk-2 flavor),
> > > which has been broken since pango 1.44.
> > > It requires several changes:
> > > 
> > > 1. fix metrics rounding in vim https://github.com/vim/vim/pull/6168,
> > > already included in our vim port.
> > > 2. fix fonttosfnt in our xenocara or rely on something like fontforge    
> > > for
> > > the same job.
> > > (https://gitlab.freedesktop.org/xorg/app/fonttosfnt/-/merge_requests/7)
> 
> FWIW the current fonttosfnt in xenocara might have some problems with
> spacing but is still good enough to create terminus font .otbs
> demonstrating the problem. Makefile fragment for terminus-font to
> convert:
> 
> cd ${WRKSRC}; for i in ter-u*[nb].pcf; do fonttosfnt -c -g 2 -m 2 -o 
> $${i%.pcf}.otb $$i; done
> 
> Then run gvim, edit/select font, Terminus
> 
> > > 3. fix pango, so it does not accidentally use unsupported pcf fonts when
> > > supported OpenType fonts are present:
> > >    https://gitlab.gnome.org/GNOME/pango/-/issues/484
> > > 4. ship bitmap fonts in an OpenType container, too.
> > > 
> > > Attached is a diff to update pango to the latest release and backport 
> > > above
> > > mentioned fix.
> > 
> > This is the latest *development* release, not stable.
> > I don't think we want this in our tree, do we?
> 
> I agree. Here is a backport to the 1.44 branch which fixes the reported
> problem with gvim (which I don't normally ever use ;)
> 
> I'll run with it on my workstation for now but I have not tested it
> extensively with other software.
> 
> Current situation in ports is that .pcf fonts don't work with Pango (so
> generally what happens is it will fallback to a not-wanted font). *but*
> if we ship .otb versions alongside the .pcf then software using Pango
> will now see the .otb font and permit the font to be chosen, but will
> actually try to use the unsupported pcf not the otb, resulting in
> broken characters (the usual unicode "missing char" boxes).
> 
> The alternative workaround is to change all ports installing pcf fonts
> and convert them to otb (removing the pcf) - but that doesn't help for
> user-installed fonts and maybe there are some programs that still
> require pcf. So fixing in pango seems the right thing to do (especially
> as it's a bug which they've acknowledged/fixed in master).

Thanks.
If this works out for you folks, OK with me.

> 
> 
> 
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/devel/pango/Makefile,v
> retrieving revision 1.129
> diff -u -p -r1.129 Makefile
> --- Makefile  21 Dec 2019 14:38:47 -0000      1.129
> +++ Makefile  28 Jun 2020 11:33:05 -0000
> @@ -3,7 +3,7 @@
>  COMMENT=             library for layout and rendering of text
>  
>  GNOME_VERSION=               1.44.7
> -REVISION=            0
> +REVISION=            1
>  GNOME_PROJECT=               pango
>  
>  SHARED_LIBS += pango-1.0                 3801.0 # 0.4400.7
> Index: patches/patch-pango_pangofc-fontmap_c
> ===================================================================
> RCS file: patches/patch-pango_pangofc-fontmap_c
> diff -N patches/patch-pango_pangofc-fontmap_c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-pango_pangofc-fontmap_c     28 Jun 2020 11:33:05 -0000
> @@ -0,0 +1,110 @@
> +$OpenBSD$
> +
> +Backported from below commit (slightly different due to code reorganisation)
> +
> +From fe1ee773310bac83d8e5d3c062b13a51fb5fb4ad Mon Sep 17 00:00:00 2001
> +From: Khaled Hosny <khaledho...@eglug.org>
> +Date: Thu, 25 Jun 2020 10:02:21 +0200
> +Subject: [PATCH] fcfontmap: Always reject unsupported font formats
> +
> +Fixes https://gitlab.gnome.org/GNOME/pango/-/issues/484 and
> +https://gitlab.gnome.org/GNOME/pango/-/issues/457
> +---
> + pango/pangofc-fontmap.c | 52 ++++++++++++++++++++---------------------
> + 1 file changed, 26 insertions(+), 26 deletions(-)
> +
> +Index: pango/pangofc-fontmap.c
> +--- pango/pangofc-fontmap.c.orig
> ++++ pango/pangofc-fontmap.c
> +@@ -808,8 +808,15 @@ pango_fc_patterns_get_pattern (PangoFcPatterns *pats)
> + }
> + 
> + static gboolean
> +-pango_fc_is_supported_font_format (const char *fontformat)
> ++pango_fc_is_supported_font_format (FcPattern* pattern)
> + {
> ++  FcResult res;
> ++  const char *fontformat;
> ++
> ++  res = FcPatternGetString (pattern, FC_FONTFORMAT, 0, (FcChar8 
> **)(void*)&fontformat);
> ++  if (res != FcResultMatch)
> ++    return FALSE;
> ++
> +   /* harfbuzz supports only SFNT fonts. */
> +   /* FIXME: "CFF" is used for both CFF in OpenType and bare CFF files, but
> +    * HarfBuzz does not support the later and FontConfig does not seem
> +@@ -831,11 +838,7 @@ filter_fontset_by_format (FcFontSet *fontset)
> + 
> +   for (i = 0; i < fontset->nfont; i++)
> +     {
> +-      FcResult res;
> +-      const char *s;
> +-
> +-      res = FcPatternGetString (fontset->fonts[i], FC_FONTFORMAT, 0, 
> (FcChar8 **)(void*)&s);
> +-      if (res == FcResultMatch && pango_fc_is_supported_font_format (s))
> ++      if (pango_fc_is_supported_font_format (fontset->fonts[i]))
> +         FcFontSetAdd (result, FcPatternDuplicate (fontset->fonts[i]));
> +     }
> + 
> +@@ -851,34 +854,32 @@ pango_fc_patterns_get_font_pattern (PangoFcPatterns *p
> +       if (!pats->match && !pats->fontset)
> +     pats->match = FcFontMatch (pats->fontmap->priv->config, pats->pattern, 
> &result);
> + 
> +-      if (pats->match)
> ++      if (pats->match && pango_fc_is_supported_font_format (pats->match))
> +     {
> +       *prepare = FALSE;
> +       return pats->match;
> +     }
> +     }
> +-  else
> ++
> ++  if (!pats->fontset)
> +     {
> +-      if (!pats->fontset)
> +-        {
> +-      FcResult result;
> +-          FcFontSet *fontset;
> +-          FcFontSet *filtered;
> ++      FcResult result;
> ++      FcFontSet *fontset;
> ++      FcFontSet *filtered;
> + 
> +-      fontset = FcFontSort (pats->fontmap->priv->config, pats->pattern, 
> FcFalse, NULL, &result);
> +-          filtered = filter_fontset_by_format (fontset);
> +-          FcFontSetDestroy (fontset);
> ++      fontset = FcFontSort (pats->fontmap->priv->config, pats->pattern, 
> FcFalse, NULL, &result);
> ++      filtered = filter_fontset_by_format (fontset);
> ++      FcFontSetDestroy (fontset);
> + 
> +-          pats->fontset = FcFontSetSort (pats->fontmap->priv->config, 
> &filtered, 1, pats->pattern, FcTrue, NULL, &result);
> ++      pats->fontset = FcFontSetSort (pats->fontmap->priv->config, 
> &filtered, 1, pats->pattern, FcTrue, NULL, &result);
> + 
> +-          FcFontSetDestroy (filtered);
> ++      FcFontSetDestroy (filtered);
> + 
> +-      if (pats->match)
> +-        {
> +-          FcPatternDestroy (pats->match);
> +-          pats->match = NULL;
> +-        }
> +-    }
> ++      if (pats->match)
> ++        {
> ++          FcPatternDestroy (pats->match);
> ++          pats->match = NULL;
> ++        }
> +     }
> + 
> +   *prepare = TRUE;
> +@@ -1404,9 +1405,7 @@ pango_fc_font_map_list_families (PangoFontMap      *fo
> +           int variable;
> +       PangoFcFamily *temp_family;
> + 
> +-      res = FcPatternGetString (fontset->fonts[i], FC_FONTFORMAT, 0, 
> (FcChar8 **)(void*)&s);
> +-      g_assert (res == FcResultMatch);
> +-          if (!pango_fc_is_supported_font_format (s))
> ++          if (!pango_fc_is_supported_font_format (fontset->fonts[i]))
> +             continue;
> + 
> +       res = FcPatternGetString (fontset->fonts[i], FC_FAMILY, 0, (FcChar8 
> **)(void*)&s);
> 

-- 
Antoine

Reply via email to