35#include <X11/cursorfont.h>
36#include <X11/keysym.h>
47#include <X11/Xft/Xft.h>
56 TNamed(
name,
""), TRefCnt(), fXftFont(xftfont)
64 fGC =
gc; fXftFont = (XftFont *)font;
70 if (fXftFont) XftFontClose((Display*)
gVirtualX->GetDisplay(), fXftFont);
80 TXftFontHash() { fList =
new THashTable(50); }
82 TXftFontData *FindByName(
const char *
name)
91 while (
auto d = (TXftFontData*) next()) {
92 if (
d->fXftFont == (XftFont *)font)
102 while (
auto d = (TXftFontData*) next()) {
109 void AddFont(TXftFontData *
data)
116 while (
auto d = (TXftFontData*) next()) {
117 if (
d->fXftFont ==
data->fXftFont)
118 data->AddReference();
124 void FreeFont(TXftFontData *
data)
158 SetTitle(
"ROOT interface to X11 with TrueType fonts");
168 fXftFontHash =
nullptr;
190 fXftFontHash =
nullptr;
191 XFontStruct *
fs =
nullptr;
192 if (display)
fs = XLoadQueryFont((Display *)display,
"-*-helvetica-*-r-*-*-14-*-*-*-*-*-*-*");
193 if (!
fs)
gEnv->SetValue(
"X11.UseXft", 1);
194 if (display &&
fs) XFreeFont((Display *)display,
fs);
195 if (
gEnv->GetValue(
"X11.UseXft", 0)) {
197 fXftFontHash =
new TXftFontHash();
264 const Int_t maxdots = 50000;
266 dots =
Int_t(source->width * source->rows);
267 dots = dots > maxdots ? maxdots : dots;
272 for (
y = 0;
y < (
int) source->rows;
y++) {
273 for (
x = 0;
x < (
int) source->width;
x++, bc++) {
275 bc->pixel = XGetPixel(xim, bx +
x, by +
y);
276 bc->flags = DoRed | DoGreen | DoBlue;
277 if (++dotcnt >= maxdots)
break;
284 for (
y = 0;
y < (
int) source->rows;
y++) {
285 for (
x = 0;
x < (
int) source->width;
x++, bc++) {
289 if (++dotcnt >= maxdots)
break;
298 if (bc->red ==
r && bc->green ==
g && bc->blue ==
b)
312 if (fore != col[4].
pixel || back != col[0].
pixel) {
314 col[4].flags = DoRed|DoGreen|DoBlue;
317 col[3].flags = DoRed | DoGreen | DoBlue;
325 for (
x = 3;
x > 0;
x--) {
326 col[
x].red = (col[4].red *
x + col[0].red *(4-
x)) /4;
327 col[
x].green = (col[4].green*
x + col[0].green*(4-
x)) /4;
328 col[
x].blue = (col[4].blue *
x + col[0].blue *(4-
x)) /4;
330 Warning(
"DrawImage",
"cannot allocate smoothing color");
331 col[
x].pixel = col[
x+1].pixel;
338 for (
y = 0;
y < (
int) source->rows;
y++) {
339 for (
x = 0;
x < (
int) source->width;
x++) {
341 d = ((
d + 10) * 5) / 256;
343 if (
d &&
x < (
int) source->width) {
345 XPutPixel(xim, bx +
x, by +
y, p);
352 for (
int y = 0;
y < (
int) source->rows;
y++) {
355 for (
int x = 0;
x < (
int) source->width;
x++) {
356 if (
n == 0)
d = *s++;
358 XPutPixel(xim, bx +
x, by +
y, fore);
361 row += source->pitch;
442 if ((
int)
w == 0 || (
int)
h == 0)
return kFALSE;
478 depth, ZPixmap, 0,
nullptr,
w,
h,
479 depth <= 8 ? 8 : (depth <= 16 ? 16 : 32), 0);
484 xim->data = (
char *)
malloc(xim->bytes_per_line *
h);
485 memset(xim->data, 0, xim->bytes_per_line *
h);
491 Error(
"DrawText",
"error getting Graphics Context");
494 XGetGCValues((Display*)
fDisplay, *
gc, GCForeground | GCBackground, &values);
501 Error(
"DrawText",
"error getting background image");
506 Int_t xo = 0, yo = 0;
507 if (
x1 < 0) xo = -
x1;
508 if (
y1 < 0) yo = -
y1;
510 for (
int yp = 0; yp < (
int) bim->height; yp++) {
511 for (
int xp = 0; xp < (
int) bim->width; xp++) {
513 XPutPixel(xim, xo+xp, yo+yp,
pixel);
520 XAddPixel(xim, values.background);
521 bg = values.background;
527 if (FT_Glyph_To_Bitmap(&glyph->
fImage,
529 : ft_render_mode_mono,
530 nullptr, 1 ))
continue;
532 FT_Bitmap* source = &
bitmap->bitmap;
604 TXftFontData *
data = fXftFontHash->FindByName(font_name);
618 data =
new TXftFontData(0, xftfont, font_name);
619 fXftFontHash->AddFont(
data);
634 TXftFontData *
data = fXftFontHash->FindByFont(
fs);
637 fXftFontHash->FreeFont(
data);
650 TXftFontData *gcdata = fXftFontHash->FindByGC(
gc);
651 if (gcdata) fXftFontHash->FreeFont(gcdata);
676 TXftFontData *
data = fXftFontHash->FindByGC(
gc);
692 TXftFontData *gcdata = fXftFontHash->FindByGC(
gc);
693 TXftFontData *fontdata = fXftFontHash->FindByFont(font);
696 gcdata->fXftFont = (XftFont *)font;
699 TXftFontData *
data =
new TXftFontData(
gc, (XftFont *)font, fontdata->GetName());
700 fXftFontHash->AddFont(
data);
713 TXftFontData *
data = fXftFontHash->FindByFont(font);
717 XftFont *xftfont =
data->fXftFont;
720 XGlyphInfo glyph_info;
721 XftTextExtents8((Display *)
fDisplay, xftfont, (XftChar8 *)s,
len, &glyph_info);
722 return glyph_info.xOff;
737 TXftFontData *
data = fXftFontHash->FindByFont(font);
744 XftFont *xftfont =
data->fXftFont;
751 max_ascent = xftfont->ascent;
752 max_descent = xftfont->descent;
787 TXftFontData *
data = fXftFontHash->FindByGC(
gc);
795 xftfont =
data->fXftFont;
817 memset(&xcolor, 0,
sizeof(xcolor));
818 xcolor.pixel =
gval.fForeground;
831 xftcolor.color.red = xcolor.red;
832 xftcolor.color.green = xcolor.green;
833 xftcolor.color.blue = xcolor.blue;
834 xftcolor.color.alpha = 0xffff;
835 xftcolor.pixel =
gval.fForeground;
837 XftDrawString8(xftdraw, &xftcolor, xftfont,
x,
y, (XftChar8 *)
text,
len);
840 XftDrawDestroy(xftdraw);
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.
constexpr ULong_t kBitsPerByte
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void w
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 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 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
Font_t fTextFont
Text font.
Float_t fTextSize
Text size.
Interface to low level X11 (Xlib).
void RenderString(Int_t x, Int_t y, ETextMode mode)
Perform the string rendering in the pad.
static void Activate()
Static method setting TGX11TTF as the acting gVirtualX.
void Align(void)
Compute alignment variables.
RXImage * GetBackground(Int_t x, Int_t y, UInt_t w, UInt_t h)
Get the background of the current window in an XImage.
Bool_t Init(void *display) override
Initialize X11 system. Returns kFALSE in case of failure.
void SetTextSize(Float_t textsize) override
Set current text size.
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.
FT_Vector fAlign
alignment vector
void SetTextFont(Font_t fontnumber) override
Set specified font.
TGX11TTF(const TGX11 &org)
Create copy of TGX11 but now use TrueType fonts.
Bool_t IsVisible(Int_t x, Int_t y, UInt_t w, UInt_t h)
Test if there is really something to render.
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.
void * fDisplay
Pointer to display.
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 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.
void QueryColors(Colormap cmap, RXColor *colors, Int_t ncolors)
Returns the current RGB value for the pixel in the XColor structure.
void * GetGC(Int_t which) const
Return desired Graphics Context ("which" maps directly on gGCList[]).
Bool_t fHasXft
True when XftFonts are used.
Int_t SetTextFont(char *fontname, ETextSetMode mode) override
Set text font to specified name.
Int_t fTextAlign
Text alignment (set in SetTextAlign)
Int_t fDepth
Number of color planes.
Bool_t Init(void *display) override
Initialize X11 system. Returns kFALSE in case of failure.
void DeleteGC(GContext_t gc) override
Explicitly delete a graphics context.
void SetTextSize(Float_t textsize) override
Set current text size.
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.
TGX11()
Default constructor.
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.
Window_t GetCurrentWindow() const override
Return current window pointer. Protected method used by TGX11TTF.
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.
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...
TTF helper class containing glyphs description.
FT_Glyph fImage
glyph image
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
static TTF::TTGlyph fgGlyphs[kMaxGlyphs]
glyphs
static Bool_t fgSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
static void Init()
Initialise the TrueType fonts interface.
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
static void SetTextFont(Font_t fontnumber)
Set specified font.
static Int_t fgAscent
string ascent, used to compute Y alignment
static Int_t fgWidth
string width, used to compute X alignment
static Bool_t fgInit
true if the Init has been called
static const FT_BBox & GetBox()
static Int_t fgNumGlyphs
number of glyphs in the string
static FT_Matrix * fgRotMatrix
rotation matrix
static void SetTextSize(Float_t textsize)
Set current text size.
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.