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

**URL:** <https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032>\
**Category:** ROOT\
**Tags:** bug\
**Created:** [June 27, 2024, 11:09am UTC](https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032 "2024-06-27T11:09:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmassa](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lmassa](https://root-forum.cern.ch/u/lmassa)\
**Post date:** [June 27, 2024, 11:09am UTC](https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032/1 "2024-06-27T11:09:36Z")

</div>

### 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`

 ![bug_texgyreheros](https://root-forum.cern.ch/uploads/default/original/3X/d/6/d6e34f035994a5c6478074c9c4bebf3b156aebd0.png)

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](https://root-forum.cern.ch/uploads/short-url/eglpfp5aID33HB9OzVznb1LqzIh.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.

 ![bug_texgyreheros_fixed](https://root-forum.cern.ch/uploads/default/original/3X/9/1/91f43555d9e3224fe5d68b72f9595057b53582dd.png)

See also this PDF file [bug\_texgyreheros\_fixed.pdf](https://root-forum.cern.ch/uploads/short-url/yH2FeMQvhZtwpSzYMZovfwkfO3H.pdf) (13.9 KB).

### To Reproduce

```CPP
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

```plaintext
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](https://archlinux.org/packages/extra/x86_64/root/), 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](https://github.com/root-project/root/pull/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.

```patch
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" },

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 27, 2024, 11:22am UTC](https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032/2 "2024-06-27T11:22:35Z")

</div>

I’ll check. Thanks for reporting

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 27, 2024, 12:55pm UTC](https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032/3 "2024-06-27T12:55:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lmassa](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lmassa](https://root-forum.cern.ch/u/lmassa)\
**Post date:** [June 27, 2024, 1:12pm UTC](https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032/4 "2024-06-27T13:12:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 27, 2024, 2:35pm UTC](https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032/5 "2024-06-27T14:35:17Z")

</div>

After investigation I made I made [a GitHub issue](https://github.com/root-project/root/issues/15948) with this problem.  
As far as I can se there is no other way than reverting the PR .

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 2, 2024, 2:05pm UTC](https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032/7 "2024-07-02T14:05:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 16, 2024, 2:05pm UTC](https://root-forum.cern.ch/t/text-rendering-bug-related-to-tex-gyreheros-font-since-v6-32/60032/8 "2024-07-16T14:05:45Z")

</div>

Closed on July 16, 2024, 2:05pm UTC

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