diff --git a/core/base/inc/TVirtualPad.h b/core/base/inc/TVirtualPad.h index 9e527e1559286..2153eb9766469 100644 --- a/core/base/inc/TVirtualPad.h +++ b/core/base/inc/TVirtualPad.h @@ -257,6 +257,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 void XYtoAbsPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const = 0; virtual void XYtoAbsPixel(Double_t x, Double_t y, Double_t &xpixel, Double_t &ypixel) const = 0; virtual Double_t XtoPad(Double_t x) const = 0; diff --git a/core/base/src/TAttText.cxx b/core/base/src/TAttText.cxx index d8808e656729c..fe879ec5d3b2b 100644 --- a/core/base/src/TAttText.cxx +++ b/core/base/src/TAttText.cxx @@ -311,10 +311,8 @@ Float_t TAttText::GetTextSizePercent(Float_t size) { Float_t rsize = size; if (fTextFont%10 > 2 && gPad) { - UInt_t w = std::abs(gPad->XtoAbsPixel(gPad->GetX2()) - - gPad->XtoAbsPixel(gPad->GetX1())); - UInt_t h = std::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 5bc9c9f481276..b33188d5b1d05 100644 --- a/graf2d/gpad/inc/TPad.h +++ b/graf2d/gpad/inc/TPad.h @@ -379,6 +379,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 cf9eeee37086a..dbb48e79ee232 100644 --- a/graf2d/gpad/src/TPad.cxx +++ b/graf2d/gpad/src/TPad.cxx @@ -7652,6 +7652,27 @@ Int_t TPad::YtoAbsPixel(Double_t y) const return TMath::Nint(pixel_boundary(fYtoAbsPixelk + y*fYtoPixel)); } +//////////////////////////////////////////////////////////////////////////////// +/// 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(pixel_boundary(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(pixel_boundary(std::abs(w1 - w2))); +} + + //////////////////////////////////////////////////////////////////////////////// /// Convert Y coordinate to pixel