30#include <X11/Xft/Xft.h>
36#include <X11/cursorfont.h>
37#include <X11/keysym.h>
69 fGC =
gc; fXftFont = (XftFont *)font;
72 ~TXftFontData()
override
75 if (fXftFont) XftFontClose((Display*)
gVirtualX->GetDisplay(), fXftFont);
87 TXftFontData *FindByName(
const char *
name)
96 while (
auto d = (TXftFontData*) next()) {
97 if (
d->fXftFont == (XftFont *)font)
107 while (
auto d = (TXftFontData*) next()) {
114 void AddFont(TXftFontData *
data)
121 while (
auto d = (TXftFontData*) next()) {
122 if (
d->fXftFont ==
data->fXftFont)
123 data->AddReference();
129 void FreeFont(TXftFontData *
data)
162 SetTitle(
"ROOT interface to X11 with TrueType fonts");
168 fXftFontHash =
nullptr;
189 fXftFontHash =
nullptr;
190 XFontStruct *
fs =
nullptr;
191 if (display)
fs = XLoadQueryFont((Display *)display,
"-*-helvetica-*-r-*-*-14-*-*-*-*-*-*-*");
193 if (display &&
fs) XFreeFont((Display *)display,
fs);
196 fXftFontHash =
new TXftFontHash();
205template<
typename CharType>
247 depth, ZPixmap, 0,
nullptr,
w,
h,
248 depth <= 8 ? 8 : (depth <= 16 ? 16 : 32), 0);
254 xim->data = (
char *) malloc(xim->bytes_per_line *
h);
255 memset(xim->data, 0, xim->bytes_per_line *
h);
260 Error(
"DrawTTFglyphsW",
"error getting Graphics Context");
263 XGetGCValues((Display*)
fDisplay, *
gc, GCForeground | GCBackground, &values);
270 Error(
"DrawTTFglyphsW",
"error getting background image");
278 for (
int yp = 0; yp < (
int) bim->height; yp++) {
279 for (
int xp = 0; xp < (
int) bim->width; xp++) {
281 XPutPixel(xim, xo + xp, yo + yp,
pixel);
287 XAddPixel(xim, values.background);
292 Int_t bx = 0, by = 0;
306 std::vector<RXColor> bcol(ndots);
308 Error(
"DrawTTFglyphsW",
"Allocation failure with bcol vector");
311 for (
unsigned y = 0, dotcnt = 0;
y < rows;
y++) {
312 for (
unsigned x = 0; (
x <
width) && (dotcnt < bcol.size());
x++) {
313 bcol[dotcnt].pixel = XGetPixel(xim, bx +
x, by +
y);
314 bcol[dotcnt].flags = DoRed | DoGreen | DoBlue;
320 for (
auto &entry : bcol) {
325 col[0].red = (
UShort_t) (
r / bcol.size());
326 col[0].green = (
UShort_t) (
g / bcol.size());
327 col[0].blue = (
UShort_t) (
b / bcol.size());
330 col[0].pixel = values.background;
331 col[0].flags = DoRed | DoGreen | DoBlue;
336 col[4].pixel = values.foreground;
337 col[4].flags = DoRed | DoGreen | DoBlue;
342 for (
int x = 3;
x > 0;
x--) {
343 col[
x].red = (col[4].red *
x + col[0].red *(4-
x)) /4;
344 col[
x].green = (col[4].green*
x + col[0].green*(4-
x)) /4;
345 col[
x].blue = (col[4].blue *
x + col[0].blue *(4-
x)) /4;
347 Warning(
"DrawTTFglyphsW",
"cannot allocate smoothing color");
348 col[
x].pixel = col[
x+1].pixel;
355 for (
unsigned y = 0;
y < rows;
y++) {
356 for (
unsigned x = 0;
x <
width;
x++) {
359 XPutPixel(xim, bx +
x, by +
y, col[
d].
pixel);
365 for (
unsigned y = 0;
y < rows;
y++) {
369 for (
unsigned x = 0;
x <
width;
x++) {
370 if (
n == 0)
d = *s++;
372 XPutPixel(xim, bx +
x, by +
y, values.foreground);
446 TXftFontData *
data = fXftFontHash->FindByName(font_name);
460 data =
new TXftFontData(0, xftfont, font_name);
461 fXftFontHash->AddFont(
data);
476 TXftFontData *
data = fXftFontHash->FindByFont(
fs);
479 fXftFontHash->FreeFont(
data);
492 TXftFontData *gcdata = fXftFontHash->FindByGC(
gc);
493 if (gcdata) fXftFontHash->FreeFont(gcdata);
518 TXftFontData *
data = fXftFontHash->FindByGC(
gc);
534 TXftFontData *gcdata = fXftFontHash->FindByGC(
gc);
535 TXftFontData *fontdata = fXftFontHash->FindByFont(font);
538 gcdata->fXftFont = (XftFont *)font;
541 TXftFontData *
data =
new TXftFontData(
gc, (XftFont *)font, fontdata->GetName());
542 fXftFontHash->AddFont(
data);
555 TXftFontData *
data = fXftFontHash->FindByFont(font);
559 XftFont *xftfont =
data->fXftFont;
562 XGlyphInfo glyph_info;
563 XftTextExtents8((Display *)
fDisplay, xftfont, (XftChar8 *)s,
len, &glyph_info);
564 return glyph_info.xOff;
579 TXftFontData *
data = fXftFontHash->FindByFont(font);
586 XftFont *xftfont =
data->fXftFont;
593 max_ascent = xftfont->ascent;
594 max_descent = xftfont->descent;
629 TXftFontData *
data = fXftFontHash->FindByGC(
gc);
637 xftfont =
data->fXftFont;
659 memset(&xcolor, 0,
sizeof(xcolor));
660 xcolor.pixel =
gval.fForeground;
673 xftcolor.color.red = xcolor.red;
674 xftcolor.color.green = xcolor.green;
675 xftcolor.color.blue = xcolor.blue;
676 xftcolor.color.alpha = 0xffff;
677 xftcolor.pixel =
gval.fForeground;
679 XftDrawString8(xftdraw, &xftcolor, xftfont,
x,
y, (XftChar8 *)
text,
len);
682 XftDrawDestroy(xftdraw);
Handle_t WinContext_t
Window drawing context.
const Mask_t kGCBackground
const Mask_t kGCForeground
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Handle_t Window_t
Window handle.
Handle_t GContext_t
Graphics context handle.
Handle_t Drawable_t
Drawable handle.
Handle_t FontStruct_t
Pointer to font structure.
bool Bool_t
Boolean (0=false, 1=true) (bool)
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short)
int Int_t
Signed integer 4 bytes (int)
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
constexpr ULong_t kBitsPerByte
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
float Float_t
Float 4 bytes (float)
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 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 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
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
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.
static void Activate()
Static method setting TGX11TTF as the acting gVirtualX.
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.
Bool_t Init(void *display) override
Initialize X11 system. Returns kFALSE in case of failure.
TGX11TTF(TGX11 &&org)
Create copy of TGX11 but now use TrueType fonts.
void DrawTextHelper(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const CharType *text, ETextMode mode)
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.
void DrawTTFglyphsW(WinContext_t wctxt, Int_t x, Int_t y, TTFhandle &ttf, ETextMode mode) override
Draw TTF glyphs on the specified window context.
This class is the basic interface to the X11 (Xlib) graphics system.
void * fDisplay
Pointer to display.
const TAttText & GetTextAttW(WinContext_t wctxt) const
Return text attributes for specified window context.
Colormap fColormap
Default colormap, 0 if b/w.
FontStruct_t LoadQueryFont(const char *font_name) override
Load font and query font.
Int_t fScreenNumber
Screen number.
Bool_t AllocColor(Colormap cmap, RXColor *color)
Allocate color in colormap.
void QueryColors(Colormap cmap, RXColor *colors, Int_t ncolors)
Returns the current RGB value for the pixel in the XColor structure.
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.
Bool_t fHasXft
True when XftFonts are used.
void * GetGCW(WinContext_t wctxt, Int_t which) const
Return X11 Graphics Context for specified window context.
Int_t fDepth
Number of color planes.
Bool_t Init(void *display) override
Initialize X11 system. Returns kFALSE in case of failure.
Window_t GetWindow(WinContext_t wctxt) const
Return X11 window for specified window context.
void DeleteGC(GContext_t gc) override
Explicitly delete a graphics context.
void DeleteFont(FontStruct_t fs) override
Explicitly delete font structure obtained with LoadQueryFont().
Int_t TextWidth(FontStruct_t font, const char *s, Int_t len) override
Return length of string in pixels. Size depends on font.
FontH_t GetFontHandle(FontStruct_t fs) override
Return handle to font described by font structure.
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).
RVisual * fVisual
Pointer to visual used by all windows.
void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent) override
Return some font properties.
Bool_t fHasTTFonts
True when TrueType fonts are used.
THashTable implements a hash table to store TObject's.
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.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definitions for TRefCnt, base class for reference counted objects.
void SetRefCount(UInt_t r)
UInt_t References() const
Small utility class that takes care of switching the current gVirtualX to the new TGX11TTF class as s...
Dynamic handle to work with freetype 2 library.
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.
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
void SetSmoothing(Bool_t state)
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.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Graphics context structure.