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#include <cstdlib>
25
26#include <ft2build.h>
27#include FT_FREETYPE_H
28#include FT_GLYPH_H
29#include "TGX11TTF.h"
30#include "TEnv.h"
31
32#include <X11/Xlib.h>
33#include <X11/Xutil.h>
34#include <X11/Xatom.h>
35#include <X11/cursorfont.h>
36#include <X11/keysym.h>
37#include <X11/xpm.h>
38
39struct RXColor:XColor{};
40struct RVisual:Visual{};
41struct RXImage:XImage{};
42
43#ifdef R__HAS_XFT
44
45#include "THashTable.h"
46#include "TRefCnt.h"
47#include <X11/Xft/Xft.h>
48
49///////////////////////// xft font data //////////////////////////////////////
50class TXftFontData : public TNamed, public TRefCnt {
51public:
52 GContext_t fGC; // graphics context
53 XftFont *fXftFont; // xft font
54
55 TXftFontData(GContext_t gc, XftFont *xftfont, const char *name) :
56 TNamed(name, ""), TRefCnt(), fXftFont(xftfont)
57 {
58 SetRefCount(1);
59 fGC = gc;
60 }
61
62 void MapGCFont(GContext_t gc, FontStruct_t font)
63 {
64 fGC = gc; fXftFont = (XftFont *)font;
65 }
66
67 ~TXftFontData()
68 {
69 if (References() == 1) {
70 if (fXftFont) XftFontClose((Display*)gVirtualX->GetDisplay(), fXftFont);
71 }
72 }
73};
74
75/////////////////// hash table //////////////////////////////////////////////
76class TXftFontHash {
77public:
78 THashTable *fList; // hash table
79
80 TXftFontHash() { fList = new THashTable(50); }
81
82 TXftFontData *FindByName(const char *name)
83 {
84 return (TXftFontData*)fList->FindObject(name);
85 }
86
87 TXftFontData *FindByFont(FontStruct_t font)
88 {
89 TIter next(fList);
90
91 while (auto d = (TXftFontData*) next()) {
92 if (d->fXftFont == (XftFont *)font)
93 return d;
94 }
95 return nullptr;
96 }
97
98 TXftFontData *FindByGC(GContext_t gc)
99 {
100 TIter next(fList);
101
102 while (auto d = (TXftFontData*) next()) {
103 if (d->fGC == gc)
104 return d;
105 }
106 return nullptr;
107 }
108
109 void AddFont(TXftFontData *data)
110 {
111 // Loop over all existing TXftFontData, if we already have one with the same
112 // font data, set the reference counter of this one beyond 1 so it does
113 // delete the font pointer
114 TIter next(fList);
115
116 while (auto d = (TXftFontData*) next()) {
117 if (d->fXftFont == data->fXftFont)
118 data->AddReference();
119 }
120
121 fList->Add(data);
122 }
123
124 void FreeFont(TXftFontData *data)
125 {
126 fList->Remove(data);
127 delete data;
128 }
129};
130#endif // R__HAS_XFT
131
132/** \class TTFX11Init
133\ingroup GraphicsBackends
134
135Small utility class that takes care of switching the current
136gVirtualX to the new TGX11TTF class as soon as the shared library
137containing this class is loaded.
138*/
139
141public:
143};
145
146
148
149////////////////////////////////////////////////////////////////////////////////
150/// Create copy of TGX11 but now use TrueType fonts.
151
153{
154 SetName("X11TTF");
155 SetTitle("ROOT interface to X11 with TrueType fonts");
156
157 if (!TTF::fgInit) TTF::Init();
158
160 fHasXft = kFALSE;
161 fAlign.x = 0;
162 fAlign.y = 0;
163
164#ifdef R__HAS_XFT
165 fXftFontHash = nullptr;
166#endif
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Static method setting TGX11TTF as the acting gVirtualX.
171
173{
174 if (gVirtualX && dynamic_cast<TGX11*>(gVirtualX)) {
175 TGX11 *oldg = (TGX11 *) gVirtualX;
176 gVirtualX = new TGX11TTF(*oldg);
177 delete oldg;
178 }
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Initialize X11 system. Returns kFALSE in case of failure.
183
184Bool_t TGX11TTF::Init(void *display)
185{
186#ifdef R__HAS_XFT
187 fXftFontHash = nullptr;
188 XFontStruct *fs = nullptr;
189 if (display) fs = XLoadQueryFont((Display *)display, "-*-helvetica-*-r-*-*-14-*-*-*-*-*-*-*");
190 if (!fs) gEnv->SetValue("X11.UseXft", 1);
191 if (display && fs) XFreeFont((Display *)display, fs);
192 if (gEnv->GetValue("X11.UseXft", 0)) {
193 fHasXft = kTRUE;
194 fXftFontHash = new TXftFontHash();
195 }
196#endif
197 Bool_t r = TGX11::Init(display);
198
199 if (fDepth > 8) {
201 } else {
203 }
204
205 return r;
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Compute alignment variables. The alignment is done on the horizontal string
210/// then the rotation is applied on the alignment variables.
211/// SetRotation and LayoutGlyphs should have been called before.
212
214{
215 EAlign align = (EAlign) fTextAlign;
216
217 // vertical alignment
218 if (align == kTLeft || align == kTCenter || align == kTRight) {
220 } else if (align == kMLeft || align == kMCenter || align == kMRight) {
221 fAlign.y = TTF::fgAscent/2;
222 } else {
223 fAlign.y = 0;
224 }
225
226 // horizontal alignment
227 if (align == kTRight || align == kMRight || align == kBRight) {
229 } else if (align == kTCenter || align == kMCenter || align == kBCenter) {
230 fAlign.x = TTF::fgWidth/2;
231 } else {
232 fAlign.x = 0;
233 }
234
235 FT_Vector_Transform(&fAlign, TTF::fgRotMatrix);
236 fAlign.x = fAlign.x >> 6;
237 fAlign.y = fAlign.y >> 6;
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Draw FT_Bitmap bitmap to xim image at position bx,by using specified
242/// foreground color.
243
244void TGX11TTF::DrawImage(FT_Bitmap *source, ULong_t fore, ULong_t back,
245 RXImage *xim, Int_t bx, Int_t by)
246{
247 UChar_t d = 0, *s = source->buffer;
248
249 if (TTF::fgSmoothing) {
250
251 static RXColor col[5];
252 RXColor *bcol = nullptr;
253 XColor *bc;
254 Int_t x, y;
255
256 // background kClear, i.e. transparent, we take as background color
257 // the average of the rgb values of all pixels covered by this character
258 if (back == (ULong_t) -1 && (UInt_t)source->width) {
259 ULong_t r, g, b;
260 Int_t dots, dotcnt;
261 const Int_t maxdots = 50000;
262
263 dots = Int_t(source->width * source->rows);
264 dots = dots > maxdots ? maxdots : dots;
265 bcol = new RXColor[dots];
266 if (!bcol) return;
267 bc = bcol;
268 dotcnt = 0;
269 for (y = 0; y < (int) source->rows; y++) {
270 for (x = 0; x < (int) source->width; x++, bc++) {
271/// bc->pixel = XGetPixel(xim, bx + x, by - c->TTF::fgAscent + y);
272 bc->pixel = XGetPixel(xim, bx + x, by + y);
273 bc->flags = DoRed | DoGreen | DoBlue;
274 if (++dotcnt >= maxdots) break;
275 }
276 }
277 QueryColors(fColormap, bcol, dots);
278 r = g = b = 0;
279 bc = bcol;
280 dotcnt = 0;
281 for (y = 0; y < (int) source->rows; y++) {
282 for (x = 0; x < (int) source->width; x++, bc++) {
283 r += bc->red;
284 g += bc->green;
285 b += bc->blue;
286 if (++dotcnt >= maxdots) break;
287 }
288 }
289 if (dots != 0) {
290 r /= dots;
291 g /= dots;
292 b /= dots;
293 }
294 bc = &col[0];
295 if (bc->red == r && bc->green == g && bc->blue == b)
296 bc->pixel = back;
297 else {
298 bc->pixel = ~back;
299 bc->red = (UShort_t) r;
300 bc->green = (UShort_t) g;
301 bc->blue = (UShort_t) b;
302 }
303 }
304 delete [] bcol;
305
306 // if fore or background have changed from previous character
307 // recalculate the 3 smoothing colors (interpolation between fore-
308 // and background colors)
309 if (fore != col[4].pixel || back != col[0].pixel) {
310 col[4].pixel = fore;
311 col[4].flags = DoRed|DoGreen|DoBlue;
312 if (back != (ULong_t) -1) {
313 col[3].pixel = back;
314 col[3].flags = DoRed | DoGreen | DoBlue;
315 QueryColors(fColormap, &col[3], 2);
316 col[0] = col[3];
317 } else {
318 QueryColors(fColormap, &col[4], 1);
319 }
320
321 // interpolate between fore and background colors
322 for (x = 3; x > 0; x--) {
323 col[x].red = (col[4].red *x + col[0].red *(4-x)) /4;
324 col[x].green = (col[4].green*x + col[0].green*(4-x)) /4;
325 col[x].blue = (col[4].blue *x + col[0].blue *(4-x)) /4;
326 if (!AllocColor(fColormap, &col[x])) {
327 Warning("DrawImage", "cannot allocate smoothing color");
328 col[x].pixel = col[x+1].pixel;
329 }
330 }
331 }
332
333 // put smoothed character, character pixmap values are an index
334 // into the 5 colors used for aliasing (4 = foreground, 0 = background)
335 for (y = 0; y < (int) source->rows; y++) {
336 for (x = 0; x < (int) source->width; x++) {
337 d = *s++ & 0xff;
338 d = ((d + 10) * 5) / 256;
339 if (d > 4) d = 4;
340 if (d && x < (int) source->width) {
341 ULong_t p = col[d].pixel;
342 XPutPixel(xim, bx + x, by + y, p);
343 }
344 }
345 }
346 } else {
347 // no smoothing, just put character using foreground color
348 UChar_t* row=s;
349 for (int y = 0; y < (int) source->rows; y++) {
350 int n = 0;
351 s = row;
352 for (int x = 0; x < (int) source->width; x++) {
353 if (n == 0) d = *s++;
354 if (TESTBIT(d,7-n))
355 XPutPixel(xim, bx + x, by + y, fore);
356 if (++n == (int) kBitsPerByte) n = 0;
357 }
358 row += source->pitch;
359 }
360 }
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Draw text using TrueType fonts. If TrueType fonts are not available the
365/// text is drawn with TGX11::DrawText.
366
368 const char *text, ETextMode mode)
369{
370 if (!fHasTTFonts) {
372 } else {
373 if (!TTF::fgInit) TTF::Init();
377 Align();
378 RenderString(x, y, mode);
379 }
380}
381
382////////////////////////////////////////////////////////////////////////////////
383/// Draw text using TrueType fonts. If TrueType fonts are not available the
384/// text is drawn with TGX11::DrawText.
385
387 const wchar_t *text, ETextMode mode)
388{
389 if (!fHasTTFonts) {
391 } else {
392 if (!TTF::fgInit) TTF::Init();
396 Align();
397 RenderString(x, y, mode);
398 }
399}
400
401////////////////////////////////////////////////////////////////////////////////
402/// Get the background of the current window in an XImage.
403
405{
409 Int_t xy;
410 gVirtualX->GetWindowSize(cws, xy, xy, width, height);
411
412 if (x < 0) {
413 w += x;
414 x = 0;
415 }
416 if (y < 0) {
417 h += y;
418 y = 0;
419 }
420
421 if (x+w > width) w = width - x;
422 if (y+h > height) h = height - y;
423
424 return (RXImage*)XGetImage((Display*)fDisplay, cws, x, y, w, h, AllPlanes, ZPixmap);
425}
426
427////////////////////////////////////////////////////////////////////////////////
428/// Test if there is really something to render.
429
431{
435 Int_t xy;
436 gVirtualX->GetWindowSize(cws, xy, xy, width, height);
437
438 // If w or h is 0, very likely the string is only blank characters
439 if ((int)w == 0 || (int)h == 0) return kFALSE;
440
441 // If string falls outside window, there is probably no need to draw it.
442 if (x + (int)w <= 0 || x >= (int)width) return kFALSE;
443 if (y + (int)h <= 0 || y >= (int)height) return kFALSE;
444
445 // If w or h are much larger than the window size, there is probably no need
446 // to draw it. Moreover a to large text size may produce a Seg Fault in
447 // malloc in RenderString.
448 if (w > 10*width) return kFALSE;
449 if (h > 10*height) return kFALSE;
450
451 return kTRUE;
452}
453
454////////////////////////////////////////////////////////////////////////////////
455/// Perform the string rendering in the pad.
456/// LayoutGlyphs should have been called before.
457
459{
461
462 // compute the size and position of the XImage that will contain the text
463 Int_t Xoff = 0; if (TTF::GetBox().xMin < 0) Xoff = -TTF::GetBox().xMin;
464 Int_t Yoff = 0; if (TTF::GetBox().yMin < 0) Yoff = -TTF::GetBox().yMin;
465 Int_t w = TTF::GetBox().xMax + Xoff;
466 Int_t h = TTF::GetBox().yMax + Yoff;
467 Int_t x1 = x-Xoff-fAlign.x;
468 Int_t y1 = y+Yoff+fAlign.y-h;
469
470 if (!IsVisible(x1, y1, w, h)) return;
471
472 // create the XImage that will contain the text
473 UInt_t depth = fDepth;
474 XImage *xim = XCreateImage((Display*)fDisplay, fVisual,
475 depth, ZPixmap, 0, nullptr, w, h,
476 depth <= 8 ? 8 : (depth <= 16 ? 16 : 32), 0);
477 //bitmap_pad should be 8, 16 or 32 https://www.x.org/releases/X11R7.5/doc/man/man3/XPutPixel.3.html
478 if (!xim) return;
479
480 // use malloc since Xlib will use free() in XDestroyImage
481 xim->data = (char *) malloc(xim->bytes_per_line * h);
482 memset(xim->data, 0, xim->bytes_per_line * h);
483
484 ULong_t bg;
485 XGCValues values;
486 GC *gc = (GC*)GetGC(3);
487 if (!gc) {
488 Error("DrawText", "error getting Graphics Context");
489 return;
490 }
491 XGetGCValues((Display*)fDisplay, *gc, GCForeground | GCBackground, &values);
492
493 // get the background
494 if (mode == kClear) {
495 // if mode == kClear we need to get an image of the background
496 XImage *bim = GetBackground(x1, y1, w, h);
497 if (!bim) {
498 Error("DrawText", "error getting background image");
499 return;
500 }
501
502 // and copy it into the text image
503 Int_t xo = 0, yo = 0;
504 if (x1 < 0) xo = -x1;
505 if (y1 < 0) yo = -y1;
506
507 for (int yp = 0; yp < (int) bim->height; yp++) {
508 for (int xp = 0; xp < (int) bim->width; xp++) {
509 ULong_t pixel = XGetPixel(bim, xp, yp);
510 XPutPixel(xim, xo+xp, yo+yp, pixel);
511 }
512 }
513 XDestroyImage(bim);
514 bg = (ULong_t) -1;
515 } else {
516 // if mode == kOpaque its simple, we just draw the background
517 XAddPixel(xim, values.background);
518 bg = values.background;
519 }
520
521 // paint the glyphs in the XImage
522 glyph = TTF::fgGlyphs;
523 for (int n = 0; n < TTF::fgNumGlyphs; n++, glyph++) {
524 if (FT_Glyph_To_Bitmap(&glyph->fImage,
525 TTF::fgSmoothing ? ft_render_mode_normal
526 : ft_render_mode_mono,
527 nullptr, 1 )) continue;
528 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph->fImage;
529 FT_Bitmap* source = &bitmap->bitmap;
530 Int_t bx, by;
531
532 bx = bitmap->left+Xoff;
533 by = h - bitmap->top-Yoff;
534 DrawImage(source, values.foreground, bg, (RXImage*)xim, bx, by);
535 }
536
537 // put the Ximage on the screen
539 gc = (GC*)GetGC(6);
540 if (gc) XPutImage((Display*)fDisplay, cws, *gc, xim, 0, 0, x1, y1, w, h);
541 XDestroyImage(xim);
542}
543
544////////////////////////////////////////////////////////////////////////////////
545/// Set specified font.
546
548{
550 if (!fHasTTFonts) {
552 } else {
554 }
555}
556
557////////////////////////////////////////////////////////////////////////////////
558/// Set text font to specified name.
559/// mode : loading flag
560/// mode=0 : search if the font exist (kCheck)
561/// mode=1 : search the font and load it if it exists (kLoad)
562/// font : font name
563///
564/// Set text font to specified name. This function returns 0 if
565/// the specified font is found, 1 if not.
566
568{
569 if (!fHasTTFonts) {
571 } else {
573 }
574}
575
576////////////////////////////////////////////////////////////////////////////////
577/// Set current text size.
578
580{
582 if (!fHasTTFonts) {
584 } else {
586 }
587}
588
589#ifdef R__HAS_XFT
590
591///////////////////////////// Xft font methods /////////////////////////////////
592////////////////////////////////////////////////////////////////////////////////
593/// Parses an XLFD name and opens a font.
594
595FontStruct_t TGX11TTF::LoadQueryFont(const char *font_name)
596{
597 if (!fXftFontHash) {
598 return TGX11::LoadQueryFont(font_name);
599 }
600
601 TXftFontData *data = fXftFontHash->FindByName(font_name);
602
603 // already loaded
604 if (data) {
605 return (FontStruct_t)data->fXftFont;
606 }
607
608 XftFont *xftfont = XftFontOpenXlfd((Display*)fDisplay, fScreenNumber, font_name);
609
610 data = new TXftFontData(0, xftfont, font_name);
611 fXftFontHash->AddFont(data);
612
613 return (FontStruct_t)xftfont;
614}
615
616////////////////////////////////////////////////////////////////////////////////
617/// Explicitly delete font structure obtained with LoadQueryFont().
618
620{
621 if (!fXftFontHash) {
623 return;
624 }
625
626 TXftFontData *data = fXftFontHash->FindByFont(fs);
627
628 if (data)
629 fXftFontHash->FreeFont(data);
630}
631
632////////////////////////////////////////////////////////////////////////////////
633/// Explicitly delete a graphics context.
634
636{
637 if (!fXftFontHash) {
639 return;
640 }
641
642 TXftFontData *gcdata = fXftFontHash->FindByGC(gc);
643 if (gcdata) fXftFontHash->FreeFont(gcdata);
645}
646
647////////////////////////////////////////////////////////////////////////////////
648/// Return handle to font described by font structure.
649
651{
652 if (!fXftFontHash) {
653 return TGX11::GetFontHandle(fs);
654 }
655
656 return (FontH_t)fs;
657}
658
659////////////////////////////////////////////////////////////////////////////////
660/// Return the font associated with the graphics context gc
661
663{
664 if (!fXftFontHash) {
665 return 0;
666 }
667
668 TXftFontData *data = fXftFontHash->FindByGC(gc);
669
670 // no XftFont data
671 if (!data) return 0;
672
673 return (FontStruct_t)data->fXftFont;
674}
675
676////////////////////////////////////////////////////////////////////////////////
677/// Map the XftFont with the Graphics Context using it.
678
680{
681 if (!fXftFontHash)
682 return;
683
684 TXftFontData *gcdata = fXftFontHash->FindByGC(gc);
685 TXftFontData *fontdata = fXftFontHash->FindByFont(font);
686
687 if (gcdata) { // && (gcdata->fXftFont == 0)) {
688 gcdata->fXftFont = (XftFont *)font;
689 }
690 else if (fontdata) {
691 TXftFontData *data = new TXftFontData(gc, (XftFont *)font, fontdata->GetName());
692 fXftFontHash->AddFont(data);
693 }
694}
695
696////////////////////////////////////////////////////////////////////////////////
697/// Return length of string in pixels. Size depends on font
698
699Int_t TGX11TTF::TextWidth(FontStruct_t font, const char *s, Int_t len)
700{
701 if (!fXftFontHash) {
702 return TGX11::TextWidth(font, s, len);
703 }
704
705 TXftFontData *data = fXftFontHash->FindByFont(font);
706
707 if (!data) return 0;
708
709 XftFont *xftfont = data->fXftFont;
710
711 if (xftfont) {
712 XGlyphInfo glyph_info;
713 XftTextExtents8((Display *)fDisplay, xftfont, (XftChar8 *)s, len, &glyph_info);
714 return glyph_info.xOff;
715 }
716 return 0;
717}
718
719////////////////////////////////////////////////////////////////////////////////
720/// Return some font properties
721
722void TGX11TTF::GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent)
723{
724 if (!fXftFontHash) {
725 TGX11::GetFontProperties(font, max_ascent, max_descent);
726 return;
727 }
728
729 TXftFontData *data = fXftFontHash->FindByFont(font);
730
731 if (!data) {
732 TGX11::GetFontProperties(font, max_ascent, max_descent);
733 return;
734 }
735
736 XftFont *xftfont = data->fXftFont;
737
738 if (!xftfont) {
739 TGX11::GetFontProperties(font, max_ascent, max_descent);
740 return;
741 }
742
743 max_ascent = xftfont->ascent;
744 max_descent = xftfont->descent;
745}
746
747////////////////////////////////////////////////////////////////////////////////
748/// Draw text string
749
751 const char *text, Int_t len)
752{
753 XftDraw *xftdraw;
754 XftColor xftcolor;
755 XColor xcolor;
756 XftFont *xftfont;
757
758 if (!xwindow) {
759 return;
760 }
761
762 if (!gc) {
763 return;
764 }
765
766 if (!text || (len < 1) || !text[0]) {
767 return;
768 }
769
770 if (!fXftFontHash) {
771 TGX11::DrawString(xwindow, gc, x, y, text, len);
772 return;
773 }
774
776 gval.fMask = kGCForeground | kGCBackground; // retrieve GC values
778
779 TXftFontData *data = fXftFontHash->FindByGC(gc);
780
781 // no XftFont data
782 if (!data) {
783 TGX11::DrawString(xwindow, gc, x, y, text, len);
784 return;
785 }
786
787 xftfont = data->fXftFont;
788
789 // no Xft font
790 if (!xftfont) {
791 TGX11::DrawString(xwindow, gc, x, y, text, len);
792 return;
793 }
794
795 // dummies
796 Window droot;
797 Int_t dx,dy;
798 UInt_t bwidth, width, height, depth;
799
800 // check if drawable is bitmap
801 XGetGeometry((Display*)fDisplay, (Drawable)xwindow, &droot, &dx, &dy,
802 &width, &height, &bwidth, &depth);
803
804 if (depth <= 1) {
805 TGX11::DrawString(xwindow, gc, x, y, text, len);
806 return;
807 }
808
809 memset(&xcolor, 0, sizeof(xcolor));
810 xcolor.pixel = gval.fForeground;
811
812 XQueryColor((Display*)fDisplay, fColormap, &xcolor);
813
814 // create XftDraw
815 xftdraw = XftDrawCreate((Display*)fDisplay, (Drawable)xwindow, fVisual, fColormap);
816
817 if (!xftdraw) {
818 //Warning("could not create an XftDraw");
819 TGX11::DrawString(xwindow, gc, x, y, text, len);
820 return;
821 }
822
823 xftcolor.color.red = xcolor.red;
824 xftcolor.color.green = xcolor.green;
825 xftcolor.color.blue = xcolor.blue;
826 xftcolor.color.alpha = 0xffff;
827 xftcolor.pixel = gval.fForeground;
828
829 XftDrawString8(xftdraw, &xftcolor, xftfont, x, y, (XftChar8 *)text, len);
830
831 // cleanup
832 XftDrawDestroy(xftdraw);
833}
834
835#endif // R__HAS_XFT
const Mask_t kGCBackground
Definition GuiTypes.h:289
const Mask_t kGCForeground
Definition GuiTypes.h:288
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Definition GuiTypes.h:35
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
Handle_t Drawable_t
Drawable handle.
Definition GuiTypes.h:31
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
#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
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
constexpr ULong_t kBitsPerByte
Definition RtypesCore.h:123
unsigned long ULong_t
Definition RtypesCore.h:55
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
short Font_t
Definition RtypesCore.h:88
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
#define TESTBIT(n, i)
Definition Rtypes.h:88
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
winID h TVirtualViewer3D TVirtualGLPainter p
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 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 r
Option_t Option_t fontnumber
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 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 bitmap
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t textsize
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 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 fontname
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:144
char name[80]
Definition TGX11.cxx:110
XID Window
Definition TGX11.h:36
XID Drawable
Definition TGX11.h:33
#define gVirtualX
Definition TVirtualX.h:337
#define malloc
Definition civetweb.c:1536
Font_t fTextFont
Text font.
Definition TAttText.h:25
Float_t fTextSize
Text size.
Definition TAttText.h:22
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
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:736
Interface to low level X11 (Xlib).
Definition TGX11TTF.h:27
void RenderString(Int_t x, Int_t y, ETextMode mode)
Perform the string rendering in the pad.
Definition TGX11TTF.cxx:458
static void Activate()
Static method setting TGX11TTF as the acting gVirtualX.
Definition TGX11TTF.cxx:172
void Align(void)
Compute alignment variables.
Definition TGX11TTF.cxx:213
RXImage * GetBackground(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:404
Bool_t Init(void *display) override
Initialize X11 system. Returns kFALSE in case of failure.
Definition TGX11TTF.cxx:184
void SetTextSize(Float_t textsize) override
Set current text size.
Definition TGX11TTF.cxx:579
void DrawImage(FT_Bitmap *source, ULong_t fore, ULong_t back, RXImage *xim, Int_t bx, Int_t by)
Draw FT_Bitmap bitmap to xim image at position bx,by using specified foreground color.
Definition TGX11TTF.cxx:244
FT_Vector fAlign
alignment vector
Definition TGX11TTF.h:33
void SetTextFont(Font_t fontnumber) override
Set specified font.
Definition TGX11TTF.cxx:547
TGX11TTF(const TGX11 &org)
Create copy of TGX11 but now use TrueType fonts.
Definition TGX11TTF.cxx:152
Bool_t IsVisible(Int_t x, Int_t y, UInt_t w, UInt_t h)
Test if there is really something to render.
Definition TGX11TTF.cxx:430
@ kTCenter
Definition TGX11TTF.h:30
@ kBRight
Definition TGX11TTF.h:31
@ kBCenter
Definition TGX11TTF.h:31
@ kMCenter
Definition TGX11TTF.h:30
@ kMRight
Definition TGX11TTF.h:30
@ kTRight
Definition TGX11TTF.h:30
void DrawText(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:367
This class is the basic interface to the X11 (Xlib) graphics system.
Definition TGX11.h:80
void * fDisplay
Pointer to display.
Definition TGX11.h:125
Colormap fColormap
Default colormap, 0 if b/w.
Definition TGX11.h:129
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:132
Bool_t AllocColor(Colormap cmap, RXColor *color)
Allocate color in colormap.
Definition TGX11.cxx:366
void DrawText(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.
Definition TGX11.cxx:751
void QueryColors(Colormap cmap, RXColor *colors, Int_t ncolors)
Returns the current RGB value for the pixel in the XColor structure.
Definition TGX11.cxx:383
void * GetGC(Int_t which) const
Return desired Graphics Context ("which" maps directly on gGCList[]).
Definition TGX11.cxx:931
Bool_t fHasXft
True when XftFonts are used.
Definition TGX11.h:147
Int_t SetTextFont(char *fontname, ETextSetMode mode) override
Set text font to specified name.
Definition TGX11.cxx:3154
Int_t fTextAlign
Text alignment (set in SetTextAlign)
Definition TGX11.h:135
Int_t fDepth
Number of color planes.
Definition TGX11.h:139
Bool_t Init(void *display) override
Initialize X11 system. Returns kFALSE in case of failure.
Definition TGX11.cxx:342
void DeleteGC(GContext_t gc) override
Explicitly delete a graphics context.
Definition GX11Gui.cxx:1032
void SetTextSize(Float_t textsize) override
Set current text size.
Definition TGX11.cxx:3203
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:2069
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:2058
RVisual * fVisual
Pointer to visual used by all windows.
Definition TGX11.h:126
Window_t GetCurrentWindow() const override
Return current window pointer. Protected method used by TGX11TTF.
Definition TGX11.cxx:922
void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent) override
Return some font properties.
Definition GX11Gui.cxx:2077
Bool_t fHasTTFonts
True when TrueType fonts are used.
Definition TGX11.h:146
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:164
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
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:140
TTF helper class containing glyphs description.
Definition TTF.h:65
FT_Glyph fImage
glyph image
Definition TTF.h:69
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
Definition TTF.cxx:250
static TTF::TTGlyph fgGlyphs[kMaxGlyphs]
glyphs
Definition TTF.h:83
static Bool_t fgSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
Definition TTF.h:90
static void Init()
Initialise the TrueType fonts interface.
Definition TTF.cxx:65
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Definition TTF.cxx:181
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
Definition TTF.cxx:365
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
Definition TTF.cxx:342
static void SetTextFont(Font_t fontnumber)
Set specified font.
Definition TTF.cxx:490
static Int_t fgAscent
string ascent, used to compute Y alignment
Definition TTF.h:75
static Int_t fgWidth
string width, used to compute X alignment
Definition TTF.h:92
static Bool_t fgInit
true if the Init has been called
Definition TTF.h:85
static const FT_BBox & GetBox()
Definition TTF.cxx:644
static Int_t fgNumGlyphs
number of glyphs in the string
Definition TTF.h:88
static FT_Matrix * fgRotMatrix
rotation matrix
Definition TTF.h:89
static void SetTextSize(Float_t textsize)
Set current text size.
Definition TTF.cxx:561
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
Graphics context structure.
Definition GuiTypes.h:224