Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGX11TTF.cxx
Go to the documentation of this file.
1// @(#)root/x11ttf:$Id: 80028b538e60290371c1c5d73728f78b1c32f09a $
2// Author: Valeriy Onuchin (Xft support) 02/10/07
3// Author: Olivier Couet 01/10/02
4// Author: Fons Rademakers 21/11/98
5
6/*************************************************************************
7 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14/** \class TGX11TTF
15\ingroup x11
16
17Interface to low level X11 (Xlib). This class gives access to basic
18X11 graphics via the parent class TGX11. However, all text and font
19handling is done via the Freetype TrueType library. When the
20shared library containing this class is loaded the global gVirtualX
21is redirected to point to this class.
22*/
23
24
25#include "TGX11TTF.h"
26
27#ifdef R__HAS_XFT
28#include "THashTable.h"
29#include "TRefCnt.h"
30#include <X11/Xft/Xft.h>
31#endif
32
33#include <X11/Xlib.h>
34#include <X11/Xutil.h>
35#include <X11/Xatom.h>
36#include <X11/cursorfont.h>
37#include <X11/keysym.h>
38#include <X11/xpm.h>
39
40
41#include <cstdlib>
42
43#include "TEnv.h"
44#include "TTFhandle.h"
45#include "TMathBase.h"
46
47
48struct RXColor:XColor{};
49struct RVisual:Visual{};
50struct RXImage:XImage{};
51
52#ifdef R__HAS_XFT
53
54///////////////////////// xft font data //////////////////////////////////////
55class TXftFontData : public TNamed, public TRefCnt {
56public:
57 GContext_t fGC; // graphics context
58 XftFont *fXftFont; // xft font
59
60 TXftFontData(GContext_t gc, XftFont *xftfont, const char *name) :
61 TNamed(name, ""), TRefCnt(), fXftFont(xftfont)
62 {
63 SetRefCount(1);
64 fGC = gc;
65 }
66
67 void MapGCFont(GContext_t gc, FontStruct_t font)
68 {
69 fGC = gc; fXftFont = (XftFont *)font;
70 }
71
72 ~TXftFontData() override
73 {
74 if (References() == 1) {
75 if (fXftFont) XftFontClose((Display*)gVirtualX->GetDisplay(), fXftFont);
76 }
77 }
78};
79
80/////////////////// hash table //////////////////////////////////////////////
81class TXftFontHash {
82public:
83 THashTable *fList; // hash table
84
85 TXftFontHash() { fList = new THashTable(50); }
86
87 TXftFontData *FindByName(const char *name)
88 {
89 return (TXftFontData*)fList->FindObject(name);
90 }
91
92 TXftFontData *FindByFont(FontStruct_t font)
93 {
94 TIter next(fList);
95
96 while (auto d = (TXftFontData*) next()) {
97 if (d->fXftFont == (XftFont *)font)
98 return d;
99 }
100 return nullptr;
101 }
102
103 TXftFontData *FindByGC(GContext_t gc)
104 {
105 TIter next(fList);
106
107 while (auto d = (TXftFontData*) next()) {
108 if (d->fGC == gc)
109 return d;
110 }
111 return nullptr;
112 }
113
114 void AddFont(TXftFontData *data)
115 {
116 // Loop over all existing TXftFontData, if we already have one with the same
117 // font data, set the reference counter of this one beyond 1 so it does
118 // delete the font pointer
119 TIter next(fList);
120
121 while (auto d = (TXftFontData*) next()) {
122 if (d->fXftFont == data->fXftFont)
123 data->AddReference();
124 }
125
126 fList->Add(data);
127 }
128
129 void FreeFont(TXftFontData *data)
130 {
131 fList->Remove(data);
132 delete data;
133 }
134};
135
136Bool_t TGX11TTF::gXftInit = kFALSE;
137
138#endif // R__HAS_XFT
139
140/** \class TTFX11Init
141\ingroup GraphicsBackends
142
143Small utility class that takes care of switching the current
144gVirtualX to the new TGX11TTF class as soon as the shared library
145containing this class is loaded.
146*/
147
149public:
151};
153
154
155
156////////////////////////////////////////////////////////////////////////////////
157/// Create copy of TGX11 but now use TrueType fonts.
158
160{
161 SetName("X11TTF");
162 SetTitle("ROOT interface to X11 with TrueType fonts");
163
165 fHasXft = kFALSE;
166
167#ifdef R__HAS_XFT
168 fXftFontHash = nullptr;
169#endif
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Static method setting TGX11TTF as the acting gVirtualX.
174
176{
177 if (auto oldg = dynamic_cast<TGX11*>(gVirtualX)) {
178 gVirtualX = new TGX11TTF(std::move(*oldg));
179 delete oldg;
180 }
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Initialize X11 system. Returns kFALSE in case of failure.
185
186Bool_t TGX11TTF::Init(void *display)
187{
188#ifdef R__HAS_XFT
189 fXftFontHash = nullptr;
190 XFontStruct *fs = nullptr;
191 if (display) fs = XLoadQueryFont((Display *)display, "-*-helvetica-*-r-*-*-14-*-*-*-*-*-*-*");
192 if (!fs) gEnv->SetValue("X11.UseXft", 1);
193 if (display && fs) XFreeFont((Display *)display, fs);
194 if (gEnv->GetValue("X11.UseXft", 0)) {
195 fHasXft = kTRUE;
196 fXftFontHash = new TXftFontHash();
197 }
198#endif
199 Bool_t res = TGX11::Init(display);
200
201 if (res)
203
204 return res;
205}
206
207
208template<typename CharType>
210 const CharType *text, ETextMode mode)
211{
212 if (!fHasTTFonts) {
213 TGX11::DrawTextW(wctxt, x, y, angle, mgn, text, mode);
214 return;
215 }
216
217 if (!wctxt)
218 return;
219
220 Window_t cws = GetWindow(wctxt);
222 Int_t xy;
223 GetWindowSize(cws, xy, xy, width, height);
224
225 auto &att = GetTextAttW(wctxt);
226
227 TTFhandle ttf;
228 ttf.SetTextFont(att.GetTextFont());
229 ttf.SetTextSize(att.GetTextSize());
231 ttf.PrepareString(text);
232 ttf.LayoutGlyphs();
233 if (ttf.ApplyAlignRotate(x, y, att.GetTextAlign(), width, height))
234 DrawTTFglyphsW(wctxt, x, y, ttf, mode);
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Draw TTF glyphs on the specified window context
239
241{
242 Int_t w = ttf.GetGlyphsWidth();
243 Int_t h = ttf.GetGlyphsHeight();
244
245 Window_t cws = GetWindow(wctxt);
246
247 UInt_t depth = fDepth;
248 XImage *xim = XCreateImage((Display*)fDisplay, fVisual,
249 depth, ZPixmap, 0, nullptr, w, h,
250 depth <= 8 ? 8 : (depth <= 16 ? 16 : 32), 0);
251 //bitmap_pad should be 8, 16 or 32 https://www.x.org/releases/X11R7.5/doc/man/man3/XPutPixel.3.html
252 if (!xim)
253 return;
254
255 // use malloc since Xlib will use free() in XDestroyImage
256 xim->data = (char *) malloc(xim->bytes_per_line * h);
257 memset(xim->data, 0, xim->bytes_per_line * h);
258
259 XGCValues values;
260 auto gc = (GC *) GetGCW(wctxt, 3);
261 if (!gc) {
262 Error("DrawTTFglyphsW", "error getting Graphics Context");
263 return;
264 }
265 XGetGCValues((Display*)fDisplay, *gc, GCForeground | GCBackground, &values);
266
267 // get the background
268 if (mode == kClear) {
269 // if mode == kClear we need to get an image of the background
270 XImage *bim = GetBackground(wctxt, x1, y1, w, h);
271 if (!bim) {
272 Error("DrawTTFglyphsW", "error getting background image");
273 return;
274 }
275
276 // and copy it into the text image
277 Int_t xo = x1 < 0 ? -x1 : 0;
278 Int_t yo = y1 < 0 ? -y1 : 0;
279
280 for (int yp = 0; yp < (int) bim->height; yp++) {
281 for (int xp = 0; xp < (int) bim->width; xp++) {
282 ULong_t pixel = XGetPixel(bim, xp, yp);
283 XPutPixel(xim, xo + xp, yo + yp, pixel);
284 }
285 }
286 XDestroyImage(bim);
287 } else {
288 // if mode == kOpaque its simple, we just draw the background
289 XAddPixel(xim, values.background);
290 }
291
292 // paint the glyphs in the XImage
293 for (UInt_t nglyph = 0; nglyph < ttf.GetNumGlyphs(); nglyph++) {
294 Int_t bx = 0, by = 0;
295 UChar_t *buffer = nullptr;
296 UInt_t width = 0, rows = 0, pitch = 0;
297 if (!ttf.GetGlyphData(nglyph, bx, by, buffer, width, rows, pitch))
298 continue;
299
300 if (ttf.GetSmoothing()) {
301 RXColor col[5];
302
303 // background kClear, i.e. transparent, we take as background color
304 // the average of the rgb values of all pixels covered by this character
305 if (mode == kClear) {
306 const UInt_t ndots = TMath::Min((UInt_t) 50000, width * rows);
307
308 std::vector<RXColor> bcol(ndots);
309 if (!bcol.size()) {
310 Error("DrawTTFglyphsW", "Allocation failure with bcol vector");
311 return;
312 }
313 for (unsigned y = 0, dotcnt = 0; y < rows; y++) {
314 for (unsigned x = 0; (x < width) && (dotcnt < bcol.size()); x++) {
315 bcol[dotcnt].pixel = XGetPixel(xim, bx + x, by + y);
316 bcol[dotcnt].flags = DoRed | DoGreen | DoBlue;
317 dotcnt++;
318 }
319 }
320 QueryColors(fColormap, bcol.data(), bcol.size());
321 ULong_t r = 0, g = 0, b = 0;
322 for (auto &entry : bcol) {
323 r += entry.red;
324 g += entry.green;
325 b += entry.blue;
326 }
327 col[0].red = (UShort_t) (r / bcol.size());
328 col[0].green = (UShort_t) (g / bcol.size());
329 col[0].blue = (UShort_t) (b / bcol.size());
330 } else {
331 // just request rgb value for background color
332 col[0].pixel = values.background;
333 col[0].flags = DoRed | DoGreen | DoBlue;
334 QueryColors(fColormap, &col[0], 1);
335 }
336
337 // request rgb value for foreground color
338 col[4].pixel = values.foreground;
339 col[4].flags = DoRed | DoGreen | DoBlue;
340 QueryColors(fColormap, &col[4], 1);
341
342 // recalculate the 3 smoothing colors
343 // (interpolation between fore- and background colors)
344 for (int x = 3; x > 0; x--) {
345 col[x].red = (col[4].red *x + col[0].red *(4-x)) /4;
346 col[x].green = (col[4].green*x + col[0].green*(4-x)) /4;
347 col[x].blue = (col[4].blue *x + col[0].blue *(4-x)) /4;
348 if (!AllocColor(fColormap, &col[x])) {
349 Warning("DrawTTFglyphsW", "cannot allocate smoothing color");
350 col[x].pixel = col[x+1].pixel;
351 }
352 }
353
354 UChar_t *s = buffer;
355 // put smoothed character, character pixmap values are an index
356 // into the 5 colors used for aliasing (4 = foreground, 0 = background)
357 for (unsigned y = 0; y < rows; y++) {
358 for (unsigned x = 0; x < width; x++) {
359 UChar_t d = TMath::Min((UChar_t) 4, (UChar_t)((((*s++ & 0xff) + 10) * 5) / 256));
360 if (d > 0)
361 XPutPixel(xim, bx + x, by + y, col[d].pixel);
362 }
363 }
364 } else {
365 // no smoothing, just put character using foreground color
366 UChar_t *row = buffer;
367 for (unsigned y = 0; y < rows; y++) {
368 unsigned n = 0;
369 UChar_t d = 0;
370 UChar_t *s = row;
371 for (unsigned x = 0; x < width; x++) {
372 if (n == 0) d = *s++;
373 if (TESTBIT(d,7-n))
374 XPutPixel(xim, bx + x, by + y, values.foreground);
375 if (++n == kBitsPerByte) n = 0;
376 }
377 row += pitch;
378 }
379 }
380 }
381
382 // put the Ximage on the screen
383 gc = (GC *) GetGCW(wctxt, 6);
384 if (gc)
385 XPutImage((Display*)fDisplay, cws, *gc, xim, 0, 0, x1, y1, w, h);
386 XDestroyImage(xim);
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Draw text using TrueType fonts. If TrueType fonts are not available the
391/// text is drawn with TGX11::DrawTextW.
392
394 const char *text, ETextMode mode)
395{
396 DrawTextHelper(wctxt, x, y, angle, mgn, text, mode);
397}
398
399////////////////////////////////////////////////////////////////////////////////
400/// Draw text using TrueType fonts. If TrueType fonts are not available the
401/// text is drawn with TGX11::DrawTextW.
402
404 const wchar_t *text, ETextMode mode)
405{
406 DrawTextHelper(wctxt, x, y, angle, mgn, text, mode);
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Get the background of the current window in an XImage.
411
413{
414 Window_t cws = GetWindow(wctxt);
417 Int_t xy;
418 GetWindowSize(cws, xy, xy, width, height);
419
420 if (x < 0) {
421 w += x;
422 x = 0;
423 }
424 if (y < 0) {
425 h += y;
426 y = 0;
427 }
428
429 if (x+w > width) w = width - x;
430 if (y+h > height) h = height - y;
431
432 return (RXImage *)XGetImage((Display*)fDisplay, cws, x, y, w, h, AllPlanes, ZPixmap);
433}
434
435
436#ifdef R__HAS_XFT
437
438///////////////////////////// Xft font methods /////////////////////////////////
439////////////////////////////////////////////////////////////////////////////////
440/// Parses an XLFD name and opens a font.
441
442FontStruct_t TGX11TTF::LoadQueryFont(const char *font_name)
443{
444 if (!fXftFontHash) {
445 return TGX11::LoadQueryFont(font_name);
446 }
447
448 TXftFontData *data = fXftFontHash->FindByName(font_name);
449
450 // already loaded
451 if (data) {
452 return (FontStruct_t)data->fXftFont;
453 }
454
455 if (!gXftInit) {
456 XftInit(nullptr);
457 gXftInit = kTRUE;
458 }
459
460 XftFont *xftfont = XftFontOpenXlfd((Display*)fDisplay, fScreenNumber, font_name);
461
462 data = new TXftFontData(0, xftfont, font_name);
463 fXftFontHash->AddFont(data);
464
465 return (FontStruct_t)xftfont;
466}
467
468////////////////////////////////////////////////////////////////////////////////
469/// Explicitly delete font structure obtained with LoadQueryFont().
470
472{
473 if (!fXftFontHash) {
475 return;
476 }
477
478 TXftFontData *data = fXftFontHash->FindByFont(fs);
479
480 if (data)
481 fXftFontHash->FreeFont(data);
482}
483
484////////////////////////////////////////////////////////////////////////////////
485/// Explicitly delete a graphics context.
486
488{
489 if (!fXftFontHash) {
491 return;
492 }
493
494 TXftFontData *gcdata = fXftFontHash->FindByGC(gc);
495 if (gcdata) fXftFontHash->FreeFont(gcdata);
497}
498
499////////////////////////////////////////////////////////////////////////////////
500/// Return handle to font described by font structure.
501
503{
504 if (!fXftFontHash) {
505 return TGX11::GetFontHandle(fs);
506 }
507
508 return (FontH_t)fs;
509}
510
511////////////////////////////////////////////////////////////////////////////////
512/// Return the font associated with the graphics context gc
513
515{
516 if (!fXftFontHash) {
517 return 0;
518 }
519
520 TXftFontData *data = fXftFontHash->FindByGC(gc);
521
522 // no XftFont data
523 if (!data) return 0;
524
525 return (FontStruct_t)data->fXftFont;
526}
527
528////////////////////////////////////////////////////////////////////////////////
529/// Map the XftFont with the Graphics Context using it.
530
532{
533 if (!fXftFontHash)
534 return;
535
536 TXftFontData *gcdata = fXftFontHash->FindByGC(gc);
537 TXftFontData *fontdata = fXftFontHash->FindByFont(font);
538
539 if (gcdata) { // && (gcdata->fXftFont == 0)) {
540 gcdata->fXftFont = (XftFont *)font;
541 }
542 else if (fontdata) {
543 TXftFontData *data = new TXftFontData(gc, (XftFont *)font, fontdata->GetName());
544 fXftFontHash->AddFont(data);
545 }
546}
547
548////////////////////////////////////////////////////////////////////////////////
549/// Return length of string in pixels. Size depends on font
550
551Int_t TGX11TTF::TextWidth(FontStruct_t font, const char *s, Int_t len)
552{
553 if (!fXftFontHash) {
554 return TGX11::TextWidth(font, s, len);
555 }
556
557 TXftFontData *data = fXftFontHash->FindByFont(font);
558
559 if (!data) return 0;
560
561 XftFont *xftfont = data->fXftFont;
562
563 if (xftfont) {
564 XGlyphInfo glyph_info;
565 XftTextExtents8((Display *)fDisplay, xftfont, (XftChar8 *)s, len, &glyph_info);
566 return glyph_info.xOff;
567 }
568 return 0;
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// Return some font properties
573
574void TGX11TTF::GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent)
575{
576 if (!fXftFontHash) {
577 TGX11::GetFontProperties(font, max_ascent, max_descent);
578 return;
579 }
580
581 TXftFontData *data = fXftFontHash->FindByFont(font);
582
583 if (!data) {
584 TGX11::GetFontProperties(font, max_ascent, max_descent);
585 return;
586 }
587
588 XftFont *xftfont = data->fXftFont;
589
590 if (!xftfont) {
591 TGX11::GetFontProperties(font, max_ascent, max_descent);
592 return;
593 }
594
595 max_ascent = xftfont->ascent;
596 max_descent = xftfont->descent;
597}
598
599////////////////////////////////////////////////////////////////////////////////
600/// Draw text string
601
603 const char *text, Int_t len)
604{
605 XftDraw *xftdraw;
606 XftColor xftcolor;
607 XColor xcolor;
608 XftFont *xftfont;
609
610 if (!xwindow) {
611 return;
612 }
613
614 if (!gc) {
615 return;
616 }
617
618 if (!text || (len < 1) || !text[0]) {
619 return;
620 }
621
622 if (!fXftFontHash) {
623 TGX11::DrawString(xwindow, gc, x, y, text, len);
624 return;
625 }
626
628 gval.fMask = kGCForeground | kGCBackground; // retrieve GC values
630
631 TXftFontData *data = fXftFontHash->FindByGC(gc);
632
633 // no XftFont data
634 if (!data) {
635 TGX11::DrawString(xwindow, gc, x, y, text, len);
636 return;
637 }
638
639 xftfont = data->fXftFont;
640
641 // no Xft font
642 if (!xftfont) {
643 TGX11::DrawString(xwindow, gc, x, y, text, len);
644 return;
645 }
646
647 // dummies
648 Window droot;
649 Int_t dx,dy;
650 UInt_t bwidth, width, height, depth;
651
652 // check if drawable is bitmap
653 XGetGeometry((Display*)fDisplay, (Drawable)xwindow, &droot, &dx, &dy,
654 &width, &height, &bwidth, &depth);
655
656 if (depth <= 1) {
657 TGX11::DrawString(xwindow, gc, x, y, text, len);
658 return;
659 }
660
661 memset(&xcolor, 0, sizeof(xcolor));
662 xcolor.pixel = gval.fForeground;
663
664 XQueryColor((Display*)fDisplay, fColormap, &xcolor);
665
666 // create XftDraw
667 xftdraw = XftDrawCreate((Display*)fDisplay, (Drawable)xwindow, fVisual, fColormap);
668
669 if (!xftdraw) {
670 //Warning("could not create an XftDraw");
671 TGX11::DrawString(xwindow, gc, x, y, text, len);
672 return;
673 }
674
675 xftcolor.color.red = xcolor.red;
676 xftcolor.color.green = xcolor.green;
677 xftcolor.color.blue = xcolor.blue;
678 xftcolor.color.alpha = 0xffff;
679 xftcolor.pixel = gval.fForeground;
680
681 XftDrawString8(xftdraw, &xftcolor, xftfont, x, y, (XftChar8 *)text, len);
682
683 // cleanup
684 XftDrawDestroy(xftdraw);
685}
686
687#endif // R__HAS_XFT
Handle_t WinContext_t
Window drawing context.
Definition GuiTypes.h:30
const Mask_t kGCBackground
Definition GuiTypes.h:290
const Mask_t kGCForeground
Definition GuiTypes.h:289
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Definition GuiTypes.h:36
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:39
Handle_t Drawable_t
Drawable handle.
Definition GuiTypes.h:32
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:40
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short)
Definition RtypesCore.h:55
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:53
constexpr ULong_t kBitsPerByte
Definition RtypesCore.h:131
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:70
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
#define TESTBIT(n, i)
Definition Rtypes.h:93
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t GetWindowSize
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GetGCValues
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pixel
Option_t Option_t mgn
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint xy
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t org
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t gval
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
static TTFX11Init gTTFX11Init
Definition TGX11TTF.cxx:152
char name[80]
Definition TGX11.cxx:142
XID Window
Definition TGX11.h:38
XID Drawable
Definition TGX11.h:35
#define gVirtualX
Definition TVirtualX.h:391
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.
Definition TEnv.cxx:753
static void Activate()
Static method setting TGX11TTF as the acting gVirtualX.
Definition TGX11TTF.cxx:175
void DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode) override
Draw text using TrueType fonts.
Definition TGX11TTF.cxx:393
Bool_t Init(void *display) override
Initialize X11 system. Returns kFALSE in case of failure.
Definition TGX11TTF.cxx:186
TGX11TTF(TGX11 &&org)
Create copy of TGX11 but now use TrueType fonts.
Definition TGX11TTF.cxx:159
void DrawTextHelper(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const CharType *text, ETextMode mode)
Definition TGX11TTF.cxx:209
RXImage * GetBackground(WinContext_t wctxt, Int_t x, Int_t y, UInt_t w, UInt_t h)
Get the background of the current window in an XImage.
Definition TGX11TTF.cxx:412
void DrawTTFglyphsW(WinContext_t wctxt, Int_t x, Int_t y, TTFhandle &ttf, ETextMode mode) override
Draw TTF glyphs on the specified window context.
Definition TGX11TTF.cxx:240
This class is the basic interface to the X11 (Xlib) graphics system.
Definition TGX11.h:64
void * fDisplay
Pointer to display.
Definition TGX11.h:100
const TAttText & GetTextAttW(WinContext_t wctxt) const
Return text attributes for specified window context.
Definition TGX11.cxx:1078
Colormap fColormap
Default colormap, 0 if b/w.
Definition TGX11.h:104
FontStruct_t LoadQueryFont(const char *font_name) override
Load font and query font.
Definition GX11Gui.cxx:941
Int_t fScreenNumber
Screen number.
Definition TGX11.h:107
Bool_t AllocColor(Colormap cmap, RXColor *color)
Allocate color in colormap.
Definition TGX11.cxx:338
void QueryColors(Colormap cmap, RXColor *colors, Int_t ncolors)
Returns the current RGB value for the pixel in the XColor structure.
Definition TGX11.cxx:355
void DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode) override
Draw a text string using current font on specified window.
Definition TGX11.cxx:844
Bool_t fHasXft
True when XftFonts are used.
Definition TGX11.h:119
void * GetGCW(WinContext_t wctxt, Int_t which) const
Return X11 Graphics Context for specified window context.
Definition TGX11.cxx:1059
Int_t fDepth
Number of color planes.
Definition TGX11.h:111
Bool_t Init(void *display) override
Initialize X11 system. Returns kFALSE in case of failure.
Definition TGX11.cxx:313
Window_t GetWindow(WinContext_t wctxt) const
Return X11 window for specified window context.
Definition TGX11.cxx:1049
void DeleteGC(GContext_t gc) override
Explicitly delete a graphics context.
Definition GX11Gui.cxx:1032
void DeleteFont(FontStruct_t fs) override
Explicitly delete font structure obtained with LoadQueryFont().
Definition GX11Gui.cxx:962
Int_t TextWidth(FontStruct_t font, const char *s, Int_t len) override
Return length of string in pixels. Size depends on font.
Definition GX11Gui.cxx:2090
FontH_t GetFontHandle(FontStruct_t fs) override
Return handle to font described by font structure.
Definition GX11Gui.cxx:950
void DrawString(Drawable_t id, GContext_t gc, Int_t x, Int_t y, const char *s, Int_t len) override
Draw a string using a specific graphics context in position (x,y).
Definition GX11Gui.cxx:2079
RVisual * fVisual
Pointer to visual used by all windows.
Definition TGX11.h:101
void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent) override
Return some font properties.
Definition GX11Gui.cxx:2098
Bool_t fHasTTFonts
True when TrueType fonts are used.
Definition TGX11.h:118
THashTable implements a hash table to store TObject's.
Definition THashTable.h:35
void Add(TObject *obj) override
Add object to the hash table.
TObject * Remove(TObject *obj) override
Remove object from the hashtable.
TObject * FindObject(const char *name) const override
Find object using its name.
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
Definitions for TRefCnt, base class for reference counted objects.
Definition TRefCnt.h:27
void SetRefCount(UInt_t r)
Definition TRefCnt.h:39
UInt_t References() const
Definition TRefCnt.h:38
Small utility class that takes care of switching the current gVirtualX to the new TGX11TTF class as s...
Definition TGX11TTF.cxx:148
Dynamic handle to work with freetype 2 library.
Definition TTFhandle.h:22
Bool_t SetTextSize(Float_t textsize)
Set current text size.
void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
static Bool_t Init()
static void SetSmoothingPrefer(Bool_t on)
Set global flag to switch on/off smoothing of TTF text drawing This flag is used when SetSmoothing() ...
UInt_t GetNumGlyphs() const
return number of glyphs
Int_t GetGlyphsHeight() const
Returns height of all glyphs.
void SetTextFont(Font_t fontnumber)
Set specified font.
Int_t GetGlyphsWidth() const
Returns width of all glyphs.
void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Bool_t GetSmoothing() const
Returns true if smoothing for this instance is enabled If SetSmoothing() was not called before - use ...
Bool_t GetGlyphData(UInt_t n, Int_t &offx, Int_t &offy, UChar_t *&buffer, UInt_t &width, UInt_t &rows, UInt_t &pitch)
Returns data for glyph bitmap Instead direct access to FT_BitmapGlyph one can obtain all relevant fie...
Bool_t ApplyAlignRotate(Int_t &px, Int_t &py, Int_t align, Int_t pad_width, Int_t pad_height)
Apply align and configured rotation matrix to text position px and py will be shifted to the place wh...
virtual void DeleteFont(FontStruct_t fs)
Explicitly deletes the font structure "fs" obtained via LoadQueryFont().
virtual FontStruct_t GetGCFont(GContext_t gc)
Return the font associated with the graphics context gc.
virtual FontStruct_t LoadQueryFont(const char *font_name)
Provides the most common way for accessing a font: opens (loads) the specified font and returns a poi...
virtual FontH_t GetFontHandle(FontStruct_t fs)
Returns the font handle of the specified font structure "fs".
virtual void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent)
Returns the font properties.
virtual void DeleteGC(GContext_t gc)
Deletes the specified GC "gc".
virtual void DrawString(Drawable_t id, GContext_t gc, Int_t x, Int_t y, const char *s, Int_t len)
Each character image, as defined by the font in the GC, is treated as an additional mask for a fill o...
virtual void MapGCFont(GContext_t, FontStruct_t)
Map the XftFont with the Graphics Context using it.
virtual Int_t TextWidth(FontStruct_t font, const char *s, Int_t len)
Return length of the string "s" in pixels. Size depends on font.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
Graphics context structure.
Definition GuiTypes.h:225