Text rendering bug related to Tex GyreHeros font (since v6.32)

Describe the bug

Dear ROOT developers,
I have encountered a minor issue with the rendering of symbols since v6.32.00. The issue happens when some text (TLatex) on a canvas includes a mathematical symbol (such as #pm or #leq) preceded by a space, and the font is set to 42. In this case, the space preceding the symbol is significantly larger than other spaces in the text.

See the following picture as an example. The text strings rendered in it are

  • On the first row: With space 123 #pm 456 123 < 456 123 #leq 456
  • On the second row: Without space 123#pm456 123<456 123#leq456

As you can see from the picture

  • not all symbols are affected (seemingly only those generated by # sequences, but I have not tested all of them);
  • there is no extra spacing following the symbols;
  • there is no unexpected spacing if there is no space character preceding the symbol.

The problem is also visible in PDF files produced with canvas->Print("file.pdf", "pdf"), as you can see in this file bug_texgyreheros.pdf (13.9 KB).

Expected behavior

In ROOT versions before v6.32, and after the fix described in Additional context, the canvas looks like this.

See also this PDF file bug_texgyreheros_fixed.pdf (13.9 KB).

To Reproduce

gStyle->SetTextFont(42);
gStyle->SetTextSize(0.05);
TCanvas *c = new TCanvas;
TLatex l;
l.DrawLatexNDC(0.1, 0.9, "With space 123 #pm 456 123 < 456 123 #leq 456");
l.DrawLatexNDC(0.1, 0.9, "Without space 123#pm456 123<456 123#leq456");
c->Print("file.png");
c->Print("file.pdf", "pdf");

Setup

ROOT v6.32.02
Built for linuxx8664gcc on Jun 22 2024, 18:26:29
From heads/master@tags/v6-32-02
With c++ (GCC) 14.1.1 20240522
Binary directory: /usr/bin

Running on Arch linux using the official package, version 6.32.02-2.

Additional context

It seems that the bug is related to the adoption of the Tex GyreHeros font, which was done in #14841. If I rebuild the root package (v6.32.02) with the following patch (which reverts the changes to graf2d/graf/src/TTF.cxx) I get the correct behaviour.

diff --color --unified --recursive --text root-6.32.02/graf2d/graf/src/TTF.cxx root-6.32.02.patched/graf2d/graf/src/TTF.cxx
--- root-6.32.02/graf2d/graf/src/TTF.cxx	2024-06-18 05:44:55.000000000 +0200
+++ root-6.32.02.patched/graf2d/graf/src/TTF.cxx	2024-06-27 10:09:52.614987725 +0200
@@ -497,10 +497,10 @@
      { "Root.TTFont.1", "FreeSerifItalic.otf" },
      { "Root.TTFont.2", "FreeSerifBold.otf" },
      { "Root.TTFont.3", "FreeSerifBoldItalic.otf" },
-     { "Root.TTFont.4", "texgyreheros-regular.otf" },
-     { "Root.TTFont.5", "texgyreheros-italic.otf" },
-     { "Root.TTFont.6", "texgyreheros-bold.otf" },
-     { "Root.TTFont.7", "texgyreheros-bolditalic.otf" },
+     { "Root.TTFont.4", "FreeSans.otf" },
+     { "Root.TTFont.5", "FreeSansOblique.otf" },
+     { "Root.TTFont.6", "FreeSansBold.otf" },
+     { "Root.TTFont.7", "FreeSansBoldOblique.otf" },
      { "Root.TTFont.8", "FreeMono.otf" },
      { "Root.TTFont.9", "FreeMonoOblique.otf" },
      { "Root.TTFont.10", "FreeMonoBold.otf" },

I’ll check. Thanks for reporting

On macOS, I observe the problem in the PDF output but not on the screen. I will investigate further. The change was requested by the CMS experiment. I need to debug it. Reverting that change is not the preferred solution to fix this issue.

Thank you very much for promptly looking into this. I indeed agree that reverting should only be a temporary workaround.

After investigation I made I made a GitHub issue with this problem.
As far as I can se there is no other way than reverting the PR .

1 Like

The PR is merged. Thanks again for having seen this problem.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.