Wrongly drawn TPaveText under Qt

Hello,

since long, I’ve been witnessing incorrectly drawn TPaveText instances. The problem is shown in the attachment - the text is leaking out of the box. This only happens when a canvas is embedded into Qt application or if one choses qt gui factory and backend in the .rootrc file. Would you know where the problem is?

Many thanks in advance, Kašpi.

Please, indicates your ROOT /Qt / QtRoot versions?
QtRoot version is reported with

** $Id: TGQt.cxx, ....line
In addition, please, try to set ROOTFONTFACTOR env variable, for example export ROOTFONTFACTOR=0.95and let me know whether it changes the font appearance.


Sorry, I will remember next time.

Yes, this trick has got it done! Is it documented somewhere? I tried to find it in ROOT User’s and Reference guides with no success.

Thanks again, Kašpi.

This is one of the many places where the Qt interface is bad. With normal ROOT you do not need this FONTFACTOR. Normal ROOT is computing the FONT size very precisely. The Qt interface is making a wrong adaptation of the required font size. You should fix the problem in the interface and not publish this complex interface that nobody can remember.

Rene

[quote=“brun”]This is one of the many places where the Qt interface is bad. [/quote]Yes, the messenger has to be killed for the “bad news”. We know that. Frankly, I believe, this is a good example that shows why QtRoot is a good thing for ROOT. It reveals the weak places within the core of ROOT interfaces. It is essential to keep ROOT healthy.

[quote=“brun”]With normal ROOT you do not need this FONTFACTOR.[/quote]It is not true. It does need that factor (see below) [quote=“brun”] Normal ROOT is computing the FONT size very precisely. The Qt interface is making a wrong adaptation of the required font size. You should fix the problem in the interface and not publish this complex interface that nobody can remember.[/quote] I did not publish anything. As you see I could not reproduce the complain. The variable is left in the code to diagnoze the possible remote problem that I can not reproduce localy myself.
What is wrong with such approach?
What about the interface. You are correct. Thank you very much for your remark. It is one more case when Qt reveals :bulb: the internal ROOT issue. The problem is not Qt-related. The origin of the problem can be found within root.cern.ch/viewvc/trunk/graf2d … iew=markup with ths statement

// to scale fonts to the same size as the old TT version const Float_t kScale = 0.93376068;That hardcoded constant is tailored for the hardcoded set of TTF fonts. As soon as one wants to use any other glyphs that constant has to be recalculate but … it is hardcoded. With Qt I tried to compensate this but it is too late (there is no ROOT interface to handle the arbitrary fonts).
The simple solution is to use the ROOT MS ttf fonts within Qt too. It is possible, Qt has not hardwired fonts. Qt can use ANY fonts. However, using the ROOT provided ttf one is going to lose the performance. The text rendering will be as slow (or as fast) as one provided by ROOT. I doubt ROOT can survive with the hardwired 12 years ago fonts for the LHC lifespan. Instead of the killing “messenger” for the bad news one should take this opportunity to fix the issue. To solve the issue ROOT interface has to be improved. See attachment. Such correction is not going to resolve all “font size” related issues within ROOT . However it will be the step in the right direction. The correction does not address the “factor” issue yet.

[code]Index: core/base/src/TVirtualX.cxx

— core/base/src/TVirtualX.cxx (revision 29434)
+++ core/base/src/TVirtualX.cxx (working copy)
@@ -370,6 +370,22 @@

w = h = 0;

}
+//______________________________________________________________________________
+Int_t TVirtualX::GetFontAscent() const
+{

  • // Returns the ascent of the current font (in pixels).
  • // The ascent of a font is the distance from the baseline
  • // to the highest position characters extend to
  • return 0;
    +}
    +//______________________________________________________________________________
    +Int_t TVirtualX::GetFontDescent() const
    +{
  • // Returns the descent of the current font (in pixels.
  • // The descent is the distance from the base line
  • // to the lowest point characters extend to.
  • return 0;
    +}

//______________________________________________________________________________
Float_t TVirtualX::GetTextMagnitude()
Index: core/base/inc/TVirtualX.h

— core/base/inc/TVirtualX.h (revision 29434)
+++ core/base/inc/TVirtualX.h (working copy)
@@ -107,6 +107,8 @@
virtual void GetPlanes(Int_t &nplanes);
virtual void GetRGB(Int_t index, Float_t &r, Float_t &g, Float_t &b);
virtual void GetTextExtent(UInt_t &w, UInt_t &h, char *mess);

  • virtual Int_t GetFontAscent() const;
  • virtual Int_t GetFontDescent() const ;
    virtual Float_t GetTextMagnitude();
    virtual Window_t GetWindowID(Int_t wid);
    virtual Bool_t HasTTFonts() const;
    Index: graf2d/graf/src/TText.cxx
    ===================================================================
    — graf2d/graf/src/TText.cxx (revision 29434)
    +++ graf2d/graf/src/TText.cxx (working copy)
    @@ -422,10 +422,13 @@
    a = TTF::GetBox().yMax;
    d = TMath::Abs(TTF::GetBox().yMin);
    } else {
  •  UInt_t w;
     gVirtualX->SetTextSize((int)tsize);
    
  •  gVirtualX->GetTextExtent(w, a, (char*)text);
    
  •  d = 0;
    
  •  a = gVirtualX->GetFontAscent();
    
  •  if (!a) {
    
  •     UInt_t w;
    
  •     gVirtualX->GetTextExtent(w, a, (char*)text);
    
  •  }
    
  •  d = gVirtualX->GetFontDescent();
    
    }
    }[/code]

[quote=“brun”]This is one of the many places where the Qt interface is bad. With normal ROOT you do not need this FONTFACTOR. Normal ROOT is computing the FONT size very precisely. The Qt interface is making a wrong adaptation of the required font size. You should fix the problem in the interface and not publish this complex interface that nobody can remember.
[/quote]

OK, I see your point. And I agree that User’s manual is not the best place where to mention it. However, I can’t see any reason why it should stay completely undocumented. It is a part of a SW product that is given to a broad public and as such, it shall be documented (in my opinion). Despite the best will and greatest effort of the developers, the interface might be found behaving inadequately (this is what happened to me) and then the documentation becomes extremely important. Again, in my subjective opinion. Maybe just a small note in the class documentation, like here
root.cern.ch/root/html524/TQtPadFont.html

Well, to turn my post into a constructive critique :smiley:, the code below (from CalibrateFont function in TQtPadFont.cxx)

          TQtPadFont pattern;
          pattern.SetTextFont(62);

          int w,h;
          QFontMetrics metrics(pattern);
          w = metrics.width("This is a PX distribution");
          h = metrics.height();

returns w = 133 and h = 15 in my case. The fontCalibFactor of 0.95 seems to work well for me.

Cheers, Kašpi.

Valeri,

You seem to ignore that the SAME picture must be produced on screen, ps, pdf, gif and this in batch or interactive mode. Setting your FACTOR might be a very dirty patch to make the Qt interface working correctly, but the poor user following your advice will immediately send a mail when he will discover that this setting has a bad effect when printing on other media.
There is a good reason, that we explained to you thousands of times, but you have always been opaque to these remarks, why we use internally TTF.
We could have used any other system, if it had proven to be superior.
So, I can only reiterate my comment: fix the problem in the Qt interface.

Rene

[quote=“brun”]
You seem to ignore that the SAME picture must be produced on screen, ps, pdf, gif and this in batch or interactive mode. [/quote]No, I am not. I do know why ROOT uses those set of fonts. [quote=“brun”]Setting your FACTOR might be a very dirty patch to make the Qt interface working correctly, but the poor user following your advice will immediately send a mail when he will discover that this setting has a bad effect when printing on other media.[/quote]Just opposite this factor was introduced to make sure the screen font matches the paper one. It does implement what you want.[quote=“brun”]There is a good reason, that we explained to you thousands of times, but you have always been opaque to these remarks, why we use internally TTF.[/quote]Why? To accommodate very this feature the Qt interface introduces the flexible “factor” to calibrate screen fonts “semi”-automatically to meet ROOT and your requirement for non-TTF screen fonts too. For TTF it works with no extra correction. So it is not hardcoded. It is up to QtRoot user to choose what fits his/her task best. To make it completely hidden (automatically ) i.e. to “fix Qt interface” as you said I need the correction proposed. It is cheap and easy to implement and it should not produce any “side effect” either.

[quote=“kaspi”]Yes, this trick has got it done! Is it documented somewhere? I tried to find it in ROOT User’s and Reference guides with no success.[/quote]Well, it is a common practice. “grep” Qt code for example and you may discover the bunch of the undocumented env variables those serve the same purpose. They should be used by developer only to diagnose some remote problem.
Anyway, I’ll add an appendix to my “how2install” page with the list of the ROOT resource and env variables.

[quote=“fine”]
Anyway, I’ll add an appendix to my “how2install” page with the list of the ROOT resource and env variables.[/quote]

Great, many thanks! :smiley:

Kašpi