Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/base/inc/TAttText.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class TAttText {
virtual Color_t GetTextColor() const {return fTextColor;} ///< Return the text color
virtual Font_t GetTextFont() const {return fTextFont;} ///< Return the text font
virtual Float_t GetTextSize() const {return fTextSize;} ///< Return the text size
virtual Float_t GetTextSizePercent(Float_t size); ///< Return the text in percent of the pad size
virtual Float_t GetTextSizePercent(Float_t size); ///< Return the text in percent of the pad size
virtual Float_t GetTextSizePixels(TVirtualPad &pad) const; ///< Return the text size in pixels for specified pad
virtual Float_t GetTextSizeRelative(TVirtualPad &pad) const; ///< Return the text size in relative units
virtual void Modify();
virtual void ModifyOn(TVirtualPad &pad);
virtual void ResetAttText(Option_t *toption="");
Expand Down
9 changes: 9 additions & 0 deletions core/base/inc/TVirtualPadPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ class TVirtualPadPainter {
virtual void LockPainter();
virtual void NewPage() {}

//Methods for text dimensions handling
virtual Bool_t HasTTFonts() const;
virtual void GetTextExtent(Font_t /* font */, Double_t /* size */, UInt_t & /* w */, UInt_t & /* h */, const char * /* mess */) {}
virtual void GetTextExtent(Font_t /* font */, Double_t /* size */, UInt_t & /* w */, UInt_t & /* h */, const wchar_t * /* mess */) {}
virtual void GetTextAscentDescent(Font_t /* font */, Double_t /* size */, UInt_t & /* w */, UInt_t & /* h */, const char * /* mess */) {}
virtual void GetTextAscentDescent(Font_t /* font */, Double_t /* size */, UInt_t & /* w */, UInt_t & /* h */, const wchar_t * /* mess */) {}
virtual UInt_t GetTextAdvance(Font_t /* font */, Double_t /* size */, const char * /* text */, Bool_t /* kern */ ) { return 0; }


//Now, drawing primitives.
virtual void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) = 0;
virtual void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) = 0;
Expand Down
23 changes: 15 additions & 8 deletions core/base/inc/TVirtualX.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ class TVirtualX : public TNamed, public TAttLine, public TAttFill, public TAttTe
virtual void ClearWindow();
virtual void ClosePixmap();
virtual void CloseWindow();
virtual void CopyPixmap(Int_t wid, Int_t xpos, Int_t ypos);
virtual void CreateOpenGLContext(Int_t wid=0);
virtual void DeleteOpenGLContext(Int_t wid=0);


//---- Old graphics interface -----
//---- Old, no longer used graphics interface -----

virtual void CopyPixmap(Int_t wid, Int_t xpos, Int_t ypos);

void SetFillColor(Color_t cindex) override;
void SetFillStyle(Style_t style) override;
Expand Down Expand Up @@ -101,6 +102,14 @@ class TVirtualX : public TNamed, public TAttLine, public TAttFill, public TAttTe
virtual void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const wchar_t *text,
ETextMode mode);

virtual void GetTextExtent(UInt_t &w, UInt_t &h, char *mess);
virtual void GetTextExtent(UInt_t &w, UInt_t &h, wchar_t *mess);
virtual Int_t GetFontAscent() const;
virtual Int_t GetFontAscent(const char *mess) const;
virtual Int_t GetFontDescent() const;
virtual Int_t GetFontDescent(const char *mess) const;


//---- New graphics interface -----

virtual WinContext_t GetWindowContext(Int_t wid);
Expand All @@ -125,6 +134,10 @@ class TVirtualX : public TNamed, public TAttLine, public TAttFill, public TAttTe
virtual void DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const wchar_t *text, ETextMode mode);
virtual Int_t WriteGIFW(WinContext_t wctxt, const char *name);

virtual Bool_t GetTextExtentA(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *mess);
virtual Bool_t GetTextExtentA(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const wchar_t *mess);
virtual Bool_t GetFontAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *mess);


//---- OpenGL related stuff, required only with R__HAS_COCOA ----
virtual Double_t GetOpenGLScalingFactor();
Expand All @@ -144,12 +157,6 @@ class TVirtualX : public TNamed, public TAttLine, public TAttFill, public TAttTe
virtual ULong_t GetPixel(Color_t cindex);
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 void GetTextExtent(UInt_t &w, UInt_t &h, wchar_t *mess);
virtual Int_t GetFontAscent() const;
virtual Int_t GetFontAscent(const char *mess) const;
virtual Int_t GetFontDescent() const;
virtual Int_t GetFontDescent(const char *mess) const;
virtual Float_t GetTextMagnitude();
virtual Window_t GetWindowID(Int_t wid);
virtual Bool_t HasTTFonts() const;
Expand Down
86 changes: 52 additions & 34 deletions core/base/src/TAttText.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "TVirtualPad.h"
#include "TVirtualPadPainter.h"
#include "TVirtualPadEditor.h"
#include "TMathBase.h"
#include "TStyle.h"
#include "TError.h"
#include "TColor.h"
Expand Down Expand Up @@ -147,7 +148,7 @@ If the text precision (see next paragraph) is smaller than 3, the text
size (`textsize`) is a fraction of the current pad size. Therefore the
same `textsize` value can generate text outputs with different absolute
sizes in two different pads.
The text size in pixels (`charheight`) is computed the following way:
The text size in pixels (`charheight`) computed in the following way:

~~~ {.cpp}
pad_width = gPad->XtoPixel(gPad->GetX2());
Expand All @@ -156,6 +157,13 @@ The text size in pixels (`charheight`) is computed the following way:
else charheight = textsize*pad_height;
~~~

This value can be obtained using GetTextSizePixels() method:

~~~ {.cpp}
TText txt;
auto charheight = text.GetTextSizePixels(*gPad);
~~~

If the text precision is equal to 3, the text size doesn't depend on the pad's
dimensions. A given `textsize` value always generates the same absolute
size. The text size (`charheight`) is given in pixels:
Expand Down Expand Up @@ -301,26 +309,57 @@ void TAttText::Copy(TAttText &atttext) const
}

////////////////////////////////////////////////////////////////////////////////
/// Return the text in percent of the pad size.
/// Return the text size in percent of the pad size.
///
/// If the font precision is greater than 2, the text size returned is the size in pixel
/// converted into percent of the pad size, otherwise the size returned is the same as the
/// size given as input parameter.

Float_t TAttText::GetTextSizePercent(Float_t size)
{
Float_t rsize = size;
if (fTextFont%10 > 2 && gPad) {
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
rsize = rsize/h;
if ((GetTextFont() % 2 < 3) || !gPad)
return size;

auto size0 = fTextSize;
fTextSize = size;
size = GetTextSizeRelative(*gPad);
fTextSize = size0;
return size;
}

////////////////////////////////////////////////////////////////////////////////
/// Return the text size in relative units
///
/// If the font precision grater then 2 use pad dimensions to get value

Float_t TAttText::GetTextSizeRelative(TVirtualPad &pad) const
{
Float_t rsize = GetTextSize();
if (GetTextFont() % 10 > 2) {
auto wh = pad.XtoPixel(pad.GetX2());
auto hh = pad.YtoPixel(pad.GetY1());
rsize = rsize / TMath::Max(1, TMath::Min(wh, hh));
}
return rsize;
}

////////////////////////////////////////////////////////////////////////////////
/// Return the text size in pixels for the specified pad
///
/// If the font precision less than 3 size defined as percent of pad size and
/// scaled to minimal pad size

Float_t TAttText::GetTextSizePixels(TVirtualPad &pad) const
{
Float_t tsize = GetTextSize();
if (GetTextFont() % 10 <= 2) {
auto wh = pad.XtoPixel(pad.GetX2());
auto hh = pad.YtoPixel(pad.GetY1());
tsize *= TMath::Min(wh, hh);
}
return tsize;
}

////////////////////////////////////////////////////////////////////////////////
/// Change current text attributes if necessary.

Expand All @@ -340,29 +379,9 @@ void TAttText::ModifyOn(TVirtualPad &pad)
return;

Float_t tsize0 = fTextSize;
Float_t tsize = fTextSize;

// there was difference in text size handling, keep it in one place
if (pp->IsNative()) {
if (fTextFont % 10 <= 2) {
auto wh = pad.XtoPixel(pad.GetX2());
auto hh = pad.YtoPixel(pad.GetY1());
if (wh < hh) tsize *= wh;
else tsize *= hh;
}
} else {
if (fTextFont % 10 > 2) {
Float_t wh = pad.XtoPixel(pad.GetX2());
Float_t hh = pad.YtoPixel(pad.GetY1());
if (wh < hh) {
Float_t dy = pad.AbsPixeltoX(Int_t(tsize)) - pad.AbsPixeltoX(0);
tsize = dy/(pad.GetX2() - pad.GetX1());
} else {
Float_t dy = pad.AbsPixeltoY(0) - pad.AbsPixeltoY(Int_t(tsize));
tsize = dy/(pad.GetY2() - pad.GetY1());
}
}
}

// PS-based painter uses relative size, gVirtualX - pixels
Float_t tsize = pp->GetPS() ? GetTextSizeRelative(pad) : GetTextSizePixels(pad);

fTextSize = tsize;

Expand All @@ -371,7 +390,6 @@ void TAttText::ModifyOn(TVirtualPad &pad)
fTextSize = tsize0;
}


////////////////////////////////////////////////////////////////////////////////
/// Reset this text attributes to default values.

Expand Down
8 changes: 8 additions & 0 deletions core/base/src/TVirtualPadPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,11 @@ void TVirtualPadPainter::SetCursor(Int_t device, ECursor cursor)
if (gVirtualX)
gVirtualX->SetCursor(device, cursor);
}

////////////////////////////////////////////////////////////////////////////////
/// Return true if TTF font can be used

Bool_t TVirtualPadPainter::HasTTFonts() const
{
return gVirtualX ? gVirtualX->HasTTFonts() : kFALSE;
}
28 changes: 28 additions & 0 deletions core/base/src/TVirtualX.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,34 @@ void TVirtualX::GetTextExtent(UInt_t &w, UInt_t &h, wchar_t * /*mess*/)
w = h = 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Returns the size of the specified character string "mess" for font and size.

Bool_t TVirtualX::GetTextExtentA(Font_t, Double_t, UInt_t &w, UInt_t &h, const char *)
{
w = h = 0;
return kFALSE;
}

////////////////////////////////////////////////////////////////////////////////
/// Returns the size of the specified character string "mess" for font and size.

Bool_t TVirtualX::GetTextExtentA(Font_t, Double_t, UInt_t &w, UInt_t &h, const wchar_t *)
{
w = h = 0;
return kFALSE;
}

////////////////////////////////////////////////////////////////////////////////
/// Returns ascent/descent for specified character string "mess" with font and size.


Bool_t TVirtualX::GetFontAscentDescent(Font_t, Double_t, UInt_t &a, UInt_t &d, const char *)
{
a = d = 0;
return kFALSE;
}

////////////////////////////////////////////////////////////////////////////////
/// Returns the ascent of the current font (in pixels).
/// The ascent of a font is the distance from the baseline
Expand Down
16 changes: 8 additions & 8 deletions graf2d/cocoa/inc/FontCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class FontCache {

//Typographical bounds (whatever it means),
//for the current selected font and text.
void GetTextBounds(UInt_t &w, UInt_t &h, const char *text)const;
void GetTextBounds(UInt_t &w, UInt_t &h, const std::vector<UniChar> & unichars)const;
void GetTextBounds(CTFontRef fontref, UInt_t &w, UInt_t &h, const char *text)const;
void GetTextBounds(CTFontRef fontref, UInt_t &w, UInt_t &h, const std::vector<UniChar> & unichars)const;
//
double GetAscent()const;
double GetAscent(const char *text)const;
double GetAscent(const std::vector<UniChar> & unichars)const;
double GetDescent()const;
double GetDescent(const char *text)const;
double GetDescent(const std::vector<UniChar> & unichars)const;
double GetAscent(CTFontRef fontref) const;
double GetAscent(CTFontRef fontref, const char *text) const;
double GetAscent(CTFontRef fontref, const std::vector<UniChar> &unichars) const;
double GetDescent(CTFontRef fontref) const;
double GetDescent(CTFontRef fontref, const char *text) const;
double GetDescent(CTFontRef fontref, const std::vector<UniChar> &unichars) const;
double GetLeading()const;

private:
Expand Down
4 changes: 4 additions & 0 deletions graf2d/cocoa/inc/TGQuartz.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class TGQuartz : public TGCocoa {
Int_t GetFontAscent(const char *text) const override;
Int_t GetFontDescent() const override;
Int_t GetFontDescent(const char *text) const override;

Float_t GetTextMagnitude() override;

//---- Methods used for new graphics -----
Expand All @@ -91,6 +92,9 @@ class TGQuartz : public TGCocoa {
void DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode) override;
void DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const wchar_t *text, ETextMode mode) override;

Bool_t GetTextExtentA(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *mess) override;
Bool_t GetTextExtentA(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const wchar_t *mess) override;
Bool_t GetFontAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *mess) override;

private:

Expand Down
Loading
Loading