Skip to content

Commit 296a013

Browse files
committed
[gl] use TTFhandle for text extension method
Always use TTFhandle methods for text extension methods. Unfortunately, libFTGL has several problems and not always correctly return text extension for special symbols like integral from symbol.tff When getting text extension GL - use scaling factor 1/0.93376 to be consistent with FTGL painting.
1 parent a622764 commit 296a013

4 files changed

Lines changed: 9 additions & 96 deletions

File tree

graf2d/gpad/inc/TPadPainterBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ class TPadPainterBase : public TVirtualPadPainter {
2424
TAttLine fAttLine; ///< current line attributes
2525
TAttMarker fAttMarker; ///< current marker attributes
2626
TAttText fAttText; ///< current text attributes
27-
Bool_t fFullyTransparent = kFALSE; ///< if transformed fill attributes fully transparent
27+
Bool_t fFullyTransparent = kFALSE; ///< if transformed fill attributes fully transparent
2828

2929
TAttFill GetAttFillInternal(Bool_t with_transparency);
30+
virtual Double_t GetTTFScale() const { return 1.; }
3031

3132
public:
3233

graf2d/gpad/src/TPadPainterBase.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void TPadPainterBase::GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_
5858
if (!res) {
5959
TTFhandle ttf;
6060
ttf.SetTextFont(font);
61-
ttf.SetTextSize(size);
61+
ttf.SetTextSize(size * GetTTFScale());
6262
ttf.GetTextExtent(w, h, mess);
6363
}
6464
}
@@ -76,7 +76,7 @@ void TPadPainterBase::GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_
7676
if (!res) {
7777
TTFhandle ttf;
7878
ttf.SetTextFont(font);
79-
ttf.SetTextSize(size);
79+
ttf.SetTextSize(size * GetTTFScale());
8080
ttf.GetTextExtent(w, h, mess);
8181
}
8282
}
@@ -99,7 +99,7 @@ void TPadPainterBase::GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a
9999
if (!res) {
100100
TTFhandle ttf;
101101
ttf.SetTextFont(font);
102-
ttf.SetTextSize(size);
102+
ttf.SetTextSize(size * GetTTFScale());
103103
UInt_t w, h;
104104
ttf.GetTextExtent(w, h, mess);
105105
a = ttf.GetBox().yMax;
@@ -126,7 +126,7 @@ void TPadPainterBase::GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a
126126
if (!res) {
127127
TTFhandle ttf;
128128
ttf.SetTextFont(font);
129-
ttf.SetTextSize(size);
129+
ttf.SetTextSize(size * GetTTFScale());
130130
UInt_t w, h;
131131
ttf.GetTextExtent(w, h, mess);
132132
a = ttf.GetBox().yMax;
@@ -147,7 +147,7 @@ UInt_t TPadPainterBase::GetTextAdvance(Font_t font, Double_t size, const char *m
147147

148148
TTFhandle ttf;
149149
ttf.SetTextFont(font);
150-
ttf.SetTextSize(size);
150+
ttf.SetTextSize(size * GetTTFScale());
151151
ttf.SetKerning(kern);
152152

153153
UInt_t a = 0;

graf3d/gl/inc/TGLPadPainter.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ class TGLPadPainter : public TPadPainterBase {
6060
template<class Char_t>
6161
void DrawTextHelper(Double_t x, Double_t y, const Char_t *text, ETextMode mode);
6262

63-
template<class Char_t>
64-
void TextExtentHelper(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const Char_t *text);
63+
protected:
6564

66-
template<class Char_t>
67-
void TextAscentDescentHelper(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const Char_t *text);
65+
Double_t GetTTFScale() const override { return 1./0.93376068; }
6866

6967
public:
7068
TGLPadPainter();
@@ -117,12 +115,6 @@ class TGLPadPainter : public TPadPainterBase {
117115
void DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode) override;
118116
void DrawTextNDC(Double_t, Double_t, const wchar_t *, ETextMode) override;
119117

120-
void GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *mess) override;
121-
void GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const wchar_t *mess) override;
122-
void GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *mess) override;
123-
void GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const wchar_t *mess) override;
124-
UInt_t GetTextAdvance(Font_t font, Double_t size, const char *text, Bool_t kern) override;
125-
126118
//jpg, png, gif and bmp output.
127119
void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const override;
128120

graf3d/gl/src/TGLPadPainter.cxx

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -846,42 +846,6 @@ void TGLPadPainter::DrawTextHelper(Double_t x, Double_t y, const Char *text, ETe
846846
glMatrixMode(GL_MODELVIEW);
847847
}
848848

849-
////////////////////////////////////////////////////////////////////////////////
850-
/// Helper function to get text extent
851-
852-
template<class Char_t>
853-
void TGLPadPainter::TextExtentHelper(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const Char_t *text)
854-
{
855-
SelectGLFont(font, size);
856-
857-
Float_t llx, lly, llz, urx, ury, urz;
858-
fF.BBox(text, llx, lly, llz, urx, ury, urz);
859-
urx -= llx;
860-
ury -= lly;
861-
w = (UInt_t) (urx > 0. ? urx : 0.);
862-
h = (UInt_t) (ury > 0. ? ury : 0.);
863-
(void) llz;
864-
(void) urz;
865-
}
866-
867-
////////////////////////////////////////////////////////////////////////////////
868-
/// Helper function to get text ascent / descent
869-
870-
template<class Char_t>
871-
void TGLPadPainter::TextAscentDescentHelper(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const Char_t *text)
872-
{
873-
SelectGLFont(font, size);
874-
875-
Float_t llx, lly, llz, urx, ury, urz;
876-
fF.BBox(text, llx, lly, llz, urx, ury, urz);
877-
a = (UInt_t) (ury > 0. ? ury : 0.);
878-
d = (UInt_t) (lly < 0. ? -lly : 0.);
879-
(void) llx;
880-
(void) llz;
881-
(void) urx;
882-
(void) urz;
883-
}
884-
885849
////////////////////////////////////////////////////////////////////////////////
886850
///Draw text. This operation is especially
887851
///dangerous if in locked state -
@@ -925,50 +889,6 @@ void TGLPadPainter::DrawTextNDC(Double_t u, Double_t v, const char *text, ETextM
925889
DrawText(gPad->GetX1() + u * xRange, gPad->GetY1() + v * yRange, text, mode);
926890
}
927891

928-
////////////////////////////////////////////////////////////////////////////////
929-
/// Get text extent
930-
931-
void TGLPadPainter::GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *text)
932-
{
933-
TextExtentHelper(font, size, w, h, text);
934-
}
935-
936-
////////////////////////////////////////////////////////////////////////////////
937-
/// Get text extent
938-
939-
void TGLPadPainter::GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const wchar_t *text)
940-
{
941-
TextExtentHelper(font, size, w, h, text);
942-
}
943-
944-
////////////////////////////////////////////////////////////////////////////////
945-
/// Get text extent
946-
947-
void TGLPadPainter::GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *text)
948-
{
949-
TextAscentDescentHelper(font, size, a, d, text);
950-
}
951-
952-
////////////////////////////////////////////////////////////////////////////////
953-
/// Get text extent
954-
955-
void TGLPadPainter::GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const wchar_t *text)
956-
{
957-
TextAscentDescentHelper(font, size, a, d, text);
958-
}
959-
960-
////////////////////////////////////////////////////////////////////////////////
961-
/// Get text advance
962-
963-
UInt_t TGLPadPainter::GetTextAdvance(Font_t font, Double_t size, const char *text, Bool_t)
964-
{
965-
SelectGLFont(font, size);
966-
967-
auto advance = fF.Advance(text);
968-
969-
return (UInt_t) (advance > 0. ? advance : 0.);
970-
}
971-
972892
////////////////////////////////////////////////////////////////////////////////
973893
///Draw text in NDC. This operation is especially
974894
///dangerous if in locked state -

0 commit comments

Comments
 (0)