Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPadPainterBase.cxx
Go to the documentation of this file.
1// @(#)root/gpad:$Id$
2// Author: Sergey Linev 17/04/2026
3
4/*************************************************************************
5 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TPadPainterBase.h"
13#include "TColor.h"
14
15#include "TTF.h"
16#include "TVirtualX.h"
17#include "TMathBase.h"
18
19/** \class TPadPainterBase
20\ingroup gpad
21
22Extends TVirtualPadPainter interface to simplify work with graphical attributes
23
24Plus for now central place for TTF handling
25*/
26
27////////////////////////////////////////////////////////////////////////////////
28/// Returns fill attributes after modification
29/// Checks for special fill styles 4000 .. 4100
30
32{
33 Style_t style = GetAttFill().GetFillStyle();
34 Color_t color = GetAttFill().GetFillColor();
35
36 fFullyTransparent = (style == 4000) || (style == 0);
38 style = 0;
39 } else if ((style > 4000) && (style <= 4100)) {
40 if ((style < 4100) && with_transparency)
41 color = TColor::GetColorTransparent(color, (style - 4000) / 100.);
42 style = 1001;
43 }
44
45 return { color, style };
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Returns text extend
50
52{
53 Bool_t res = kFALSE;
54
55 if (!HasTTFonts() && gVirtualX)
56 res = gVirtualX->GetTextExtentA(font, size, w, h, mess);
57
58 if (!res) {
60 ttf.SetTextFont(font);
61 ttf.SetTextSize(size);
62 ttf.GetTextExtent(w, h, mess);
63 }
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Returns text extend
68
70{
71 Bool_t res = kFALSE;
72
73 if (!HasTTFonts() && gVirtualX)
74 res = gVirtualX->GetTextExtentA(font, size, w, h, mess);
75
76 if (!res) {
78 ttf.SetTextFont(font);
79 ttf.SetTextSize(size);
80 ttf.GetTextExtent(w, h, mess);
81 }
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Returns text accent / descent
86
88{
89 Bool_t res = kFALSE;
90
91 if (!HasTTFonts() && gVirtualX) {
92 res = gVirtualX->GetFontAscentDescent(font, size, a, d, mess);
93 if (res & !a) {
94 UInt_t w = 0;
95 gVirtualX->GetTextExtentA(font, size, w, a, mess);
96 }
97 }
98
99 if (!res) {
101 ttf.SetTextFont(font);
102 ttf.SetTextSize(size);
103 UInt_t w, h;
104 ttf.GetTextExtent(w, h, mess);
105 a = ttf.GetBox().yMax;
106 d = TMath::Abs(ttf.GetBox().yMin);
107 }
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Returns text accent / descent
112
114{
115 Bool_t res = kFALSE;
116
117 // special use case for MacOS - directly use TTF
118 if (!HasTTFonts() && !IsCocoa() && gVirtualX) {
119 res = gVirtualX->GetFontAscentDescent(font, size, a, d, "");
120 if (res & !a) {
121 UInt_t w = 0;
122 gVirtualX->GetTextExtentA(font, size, w, a, mess);
123 }
124 }
125
126 if (!res) {
128 ttf.SetTextFont(font);
129 ttf.SetTextSize(size);
130 UInt_t w, h;
131 ttf.GetTextExtent(w, h, mess);
132 a = ttf.GetBox().yMax;
133 d = TMath::Abs(ttf.GetBox().yMin);
134 }
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Returns text advance
139
141{
142 if (!HasTTFonts() && gVirtualX) {
143 UInt_t a = 0, h;
144 if (gVirtualX->GetTextExtentA(font, size, a, h, mess))
145 return a;
146 }
147
149 ttf.SetTextFont(font);
150 ttf.SetTextSize(size);
151 ttf.SetKerning(kern);
152
153 UInt_t a = 0;
154 ttf.GetTextAdvance(a, mess);
155 return a;
156}
#define d(i)
Definition RSha256.hxx:102
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Style_t
Style number (short)
Definition RtypesCore.h:96
short Color_t
Color number (short)
Definition RtypesCore.h:99
short Font_t
Font number (short)
Definition RtypesCore.h:95
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t style
#define gVirtualX
Definition TVirtualX.h:375
Fill Area Attributes class.
Definition TAttFill.h:21
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2182
void GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *mess) override
Returns text extend.
UInt_t GetTextAdvance(Font_t font, Double_t size, const char *text, Bool_t kern) override
Returns text advance.
const TAttFill & GetAttFill() const override
Bool_t fFullyTransparent
if transformed fill attributes fully transparent
TAttFill GetAttFillInternal(Bool_t with_transparency)
Returns fill attributes after modification Checks for special fill styles 4000 .
void GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *mess) override
Returns text accent / descent.
Dynamic handle to work with freetype 2 library.
Definition TTF.h:119
virtual Bool_t IsCocoa() const
virtual Bool_t HasTTFonts() const
Return true if TTF font can be used.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122