diff --git a/core/base/inc/TVirtualPad.h b/core/base/inc/TVirtualPad.h index b51e86c9d3d2f..3c91b540036ea 100644 --- a/core/base/inc/TVirtualPad.h +++ b/core/base/inc/TVirtualPad.h @@ -254,6 +254,8 @@ class TVirtualPad : public TObject, public TAttLine, public TAttFill, virtual Int_t VtoPixel(Double_t v) const = 0; virtual Int_t XtoAbsPixel(Double_t x) const = 0; virtual Int_t YtoAbsPixel(Double_t y) const = 0; + virtual Int_t HtoAbsPixel(Double_t y1, Double_t y2) const = 0; + virtual Int_t WtoAbsPixel(Double_t x1, Double_t x2) const = 0; virtual Double_t XtoPad(Double_t x) const = 0; virtual Double_t YtoPad(Double_t y) const = 0; virtual Int_t XtoPixel(Double_t x) const = 0; diff --git a/core/base/src/TAttText.cxx b/core/base/src/TAttText.cxx index a238f7bd72219..64a7959d0c34c 100644 --- a/core/base/src/TAttText.cxx +++ b/core/base/src/TAttText.cxx @@ -312,10 +312,8 @@ Float_t TAttText::GetTextSizePercent(Float_t size) { Float_t rsize = size; if (fTextFont%10 > 2 && gPad) { - UInt_t w = TMath::Abs(gPad->XtoAbsPixel(gPad->GetX2()) - - gPad->XtoAbsPixel(gPad->GetX1())); - UInt_t h = TMath::Abs(gPad->YtoAbsPixel(gPad->GetY2()) - - gPad->YtoAbsPixel(gPad->GetY1())); + UInt_t w = gPad->WtoAbsPixel(gPad->GetX1(), gPad->GetX2()); + UInt_t h = gPad->HtoAbsPixel(gPad->GetY1(), gPad->GetY2()); if (w < h) rsize = rsize/w; else diff --git a/graf2d/gpad/inc/TPad.h b/graf2d/gpad/inc/TPad.h index 8166feba7ef4b..cd2e1d1589a4f 100644 --- a/graf2d/gpad/inc/TPad.h +++ b/graf2d/gpad/inc/TPad.h @@ -377,6 +377,8 @@ friend class TWebCanvas; TObject *WaitPrimitive(const char *pname="", const char *emode="") override; Int_t XtoAbsPixel(Double_t x) const override; Int_t YtoAbsPixel(Double_t y) const override; + Int_t HtoAbsPixel(Double_t y1, Double_t y2) const override; + Int_t WtoAbsPixel(Double_t x1, Double_t x2) const override; Double_t XtoPad(Double_t x) const override; Double_t YtoPad(Double_t y) const override; Int_t XtoPixel(Double_t x) const override; diff --git a/graf2d/gpad/src/TPad.cxx b/graf2d/gpad/src/TPad.cxx index 53e0cf7bd20b9..a9234301f2de8 100644 --- a/graf2d/gpad/src/TPad.cxx +++ b/graf2d/gpad/src/TPad.cxx @@ -7492,6 +7492,26 @@ Int_t TPad::YtoAbsPixel(Double_t y) const return TMath::Nint(val); } +//////////////////////////////////////////////////////////////////////////////// +/// Convert a vertical distance [y1,y2] to pixel + +Int_t TPad::HtoAbsPixel(Double_t y1, Double_t y2) const +{ + double h1 = fYtoAbsPixelk + y1 * fYtoPixel; + double h2 = fYtoAbsPixelk + y2 * fYtoPixel; + return TMath::Nint(std::abs(h1 - h2)); +} + +//////////////////////////////////////////////////////////////////////////////// +/// Convert a horizontal distance [x1,x2] to pixel + +Int_t TPad::WtoAbsPixel(Double_t x1, Double_t x2) const +{ + double w1 = fXtoAbsPixelk + x1 * fXtoPixel; + double w2 = fXtoAbsPixelk + x2 * fXtoPixel; + return TMath::Nint(std::abs(w1 - w2)); +} + //////////////////////////////////////////////////////////////////////////////// /// Convert Y coordinate to pixel