26 # include <ft2build.h>
27 # include FT_FREETYPE_H
34 #include <X11/Xutil.h>
35 #include <X11/Xatom.h>
36 #include <X11/cursorfont.h>
37 #include <X11/keysym.h>
40 struct RXColor:XColor{};
41 struct RVisual:Visual{};
42 struct RXImage:XImage{};
48 #include <X11/Xft/Xft.h>
56 TXftFontData(
GContext_t gc, XftFont *xftfont,
const char *name) :
65 fGC = gc; fXftFont = (XftFont *)font;
70 if (fXftFont) XftFontClose((Display*)
gVirtualX->GetDisplay(), fXftFont);
81 TXftFontData *FindByName(
const char *name)
83 return (TXftFontData*)fList->FindObject(name);
91 while ((d = (TXftFontData*)
next())) {
92 if (d->fXftFont == (XftFont *)font) {
104 while ((d = (TXftFontData*)
next())) {
112 void AddFont(TXftFontData *data)
117 void FreeFont(TXftFontData *data)
119 if (data->RemoveReference() > 0)
return;
149 SetTitle(
"ROOT interface to X11 with TrueType fonts");
183 if (display) fs = XLoadQueryFont((Display *)display,
"-*-helvetica-*-r-*-*-14-*-*-*-*-*-*-*");
185 if (display && fs) XFreeFont((Display *)display, fs);
188 fXftFontHash =
new TXftFontHash();
241 UChar_t d = 0, *s = source->buffer;
245 static RXColor col[5];
255 const Int_t maxdots = 50000;
257 dots =
Int_t(source->width * source->rows);
258 dots = dots > maxdots ? maxdots : dots;
259 bcol =
new RXColor[dots];
263 for (y = 0; y < (int) source->rows; y++) {
264 for (x = 0; x < (int) source->width; x++, bc++) {
266 bc->pixel = XGetPixel(xim, bx + x, by + y);
267 bc->flags = DoRed | DoGreen | DoBlue;
268 if (++dotcnt >= maxdots)
break;
275 for (y = 0; y < (int) source->rows; y++) {
276 for (x = 0; x < (int) source->width; x++, bc++) {
280 if (++dotcnt >= maxdots)
break;
289 if (bc->red == r && bc->green == g && bc->blue == b)
303 if (fore != col[4].pixel || back != col[0].pixel) {
305 col[4].flags = DoRed|DoGreen|DoBlue;
308 col[3].flags = DoRed | DoGreen | DoBlue;
316 for (x = 3; x > 0; x--) {
317 col[
x].red = (col[4].red *x + col[0].red *(4-
x)) /4;
318 col[
x].green = (col[4].green*x + col[0].green*(4-
x)) /4;
319 col[
x].blue = (col[4].blue *x + col[0].blue *(4-
x)) /4;
321 Warning(
"DrawImage",
"cannot allocate smoothing color");
322 col[
x].pixel = col[x+1].pixel;
329 for (y = 0; y < (int) source->rows; y++) {
330 for (x = 0; x < (int) source->width; x++) {
332 d = ((d + 10) * 5) / 256;
334 if (d && x < (
int) source->width) {
336 XPutPixel(xim, bx + x, by + y, p);
343 for (
int y = 0; y < (int) source->rows; y++) {
346 for (
int x = 0; x < (int) source->width; x++) {
347 if (n == 0) d = *s++;
349 XPutPixel(xim, bx + x, by + y, fore);
352 row += source->pitch;
404 gVirtualX->GetWindowSize(cws, xy, xy, width, height);
415 if (x+w > width) w = width -
x;
416 if (y+h > height) h = height -
y;
418 return (RXImage*)XGetImage((Display*)
fDisplay, cws, x, y, w, h, AllPlanes, ZPixmap);
430 gVirtualX->GetWindowSize(cws, xy, xy, width, height);
433 if ((
int)w == 0 || (
int)h == 0)
return kFALSE;
436 if (x + (
int)w <= 0 || x >= (
int)width)
return kFALSE;
437 if (y + (
int)h <= 0 || y >= (
int)height)
return kFALSE;
442 if (w > 10*width)
return kFALSE;
443 if (h > 10*height)
return kFALSE;
471 depth, ZPixmap, 0, 0, w, h,
472 depth == 24 ? 32 : (depth==15?16:depth), 0);
476 xim->data = (
char *)
malloc(xim->bytes_per_line * h);
477 memset(xim->data, 0, xim->bytes_per_line * h);
483 Error(
"DrawText",
"error getting Graphics Context");
486 XGetGCValues((Display*)
fDisplay, *gc, GCForeground | GCBackground, &values);
493 Error(
"DrawText",
"error getting background image");
498 Int_t xo = 0, yo = 0;
499 if (x1 < 0) xo = -
x1;
500 if (y1 < 0) yo = -y1;
502 for (
int yp = 0; yp < (int) bim->height; yp++) {
503 for (
int xp = 0; xp < (int) bim->width; xp++) {
504 ULong_t pixel = XGetPixel(bim, xp, yp);
505 XPutPixel(xim, xo+xp, yo+yp, pixel);
512 XAddPixel(xim, values.background);
513 bg = values.background;
519 if (FT_Glyph_To_Bitmap(&glyph->
fImage,
521 : ft_render_mode_mono,
523 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph->
fImage;
524 FT_Bitmap* source = &bitmap->bitmap;
527 bx = bitmap->left+Xoff;
528 by = h - bitmap->top-Yoff;
529 DrawImage(source, values.foreground, bg, (RXImage*)xim, bx, by);
535 if (gc) XPutImage((Display*)
fDisplay, cws, *gc, xim, 0, 0, x1, y1, w, h);
596 TXftFontData *data = fXftFontHash->FindByName(font_name);
600 data->AddReference();
606 data =
new TXftFontData(0, xftfont, font_name);
607 fXftFontHash->AddFont(data);
622 TXftFontData *data = fXftFontHash->FindByFont(fs);
625 fXftFontHash->FreeFont(data);
638 TXftFontData *gcdata = fXftFontHash->FindByGC(gc);
639 if (gcdata) fXftFontHash->FreeFont(gcdata);
664 TXftFontData *data = fXftFontHash->FindByGC(gc);
680 TXftFontData *gcdata = fXftFontHash->FindByGC(gc);
681 TXftFontData *fontdata = fXftFontHash->FindByFont(font);
684 gcdata->fXftFont = (XftFont *)font;
687 TXftFontData *data =
new TXftFontData(gc, (XftFont *)font, fontdata->GetName());
688 fXftFontHash->AddFont(data);
701 TXftFontData *data = fXftFontHash->FindByFont(font);
705 XftFont *xftfont = data->fXftFont;
708 XGlyphInfo glyph_info;
709 XftTextExtents8((Display *)
fDisplay, xftfont, (XftChar8 *)s, len, &glyph_info);
710 return glyph_info.xOff;
725 TXftFontData *data = fXftFontHash->FindByFont(font);
732 XftFont *xftfont = data->fXftFont;
739 max_ascent = xftfont->ascent;
740 max_descent = xftfont->descent;
747 const char *text,
Int_t len)
762 if (!text || (len < 1) || !text[0]) {
775 TXftFontData *data = fXftFontHash->FindByGC(gc);
783 xftfont = data->fXftFont;
794 UInt_t bwidth, width, height, depth;
798 &width, &height, &bwidth, &depth);
805 memset(&xcolor, 0,
sizeof(xcolor));
819 xftcolor.color.red = xcolor.red;
820 xftcolor.color.green = xcolor.green;
821 xftcolor.color.blue = xcolor.blue;
822 xftcolor.color.alpha = 0xffff;
825 XftDrawString8(xftdraw, &xftcolor, xftfont, x, y, (XftChar8 *)text, len);
828 XftDrawDestroy(xftdraw);
static void Activate()
Static method setting TGX11TTF as the acting gVirtualX.
void GetGCValues(GContext_t gc, GCValues_t &gval)
Get current values from graphics context gc.
void * fDisplay
Pointer to display.
static void Init()
Initialise the TrueType fonts interface.
void DeleteFont(FontStruct_t fs)
Explicitly delete font structure obtained with LoadQueryFont().
static FT_Matrix * fgRotMatrix
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Bool_t Init(void *display)
Initialize X11 system. Returns kFALSE in case of failure.
Bool_t fHasXft
True when XftFonts are used.
Int_t fScreenNumber
Screen number.
Definitions for TRefCnt, base class for reference counted objects.
std::vector< double > values
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.
Int_t fTextAlign
Text alignment (set in SetTextAlign)
Interface to low level X11 (Xlib).
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
virtual Int_t SetTextFont(char *fontname, ETextSetMode mode)
Set text font to specified name.
void * GetGC(Int_t which) const
Return desired Graphics Context ("which" maps directly on gGCList[]).
THashTable implements a hash table to store TObject's.
static TTF::TTGlyph fgGlyphs[kMaxGlyphs]
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Window_t GetCurrentWindow() const
Return current window pointer. Protected method used by TGX11TTF.
static void SetTextFont(Font_t fontnumber)
Set specified font.
The TNamed class is the base class for all named ROOT classes.
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
Colormap fColormap
Default colormap, 0 if b/w.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void QueryColors(Colormap cmap, RXColor *colors, Int_t ncolors)
Returns the current RGB value for the pixel in the XColor structure.
Int_t fDepth
Number of color planes.
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
void SetRefCount(UInt_t r)
void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent)
Return some font properties.
virtual void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode)
Draw a text string using current font.
void SetTextSize(Float_t textsize)
Set current text size.
FontH_t GetFontHandle(FontStruct_t fs)
Return handle to font described by font structure.
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
void DrawString(Drawable_t id, GContext_t gc, Int_t x, Int_t y, const char *s, Int_t len)
Draw a string using a specific graphics context in position (x,y).
void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode)
Draw text using TrueType fonts.
FontStruct_t LoadQueryFont(const char *font_name)
Load font and query font.
TTF helper class containing glyphs description.
Bool_t fHasTTFonts
True when TrueType fonts are used.
virtual FontStruct_t GetGCFont(GContext_t gc)
Return the font associated with the graphics context gc.
TGX11TTF(const TGX11 &org)
void SetTextFont(Font_t fontnumber)
Set specified font.
This class is the basic interface to the X11 (Xlib) graphics system.
void RenderString(Int_t x, Int_t y, ETextMode mode)
Perform the string rendering in the pad.
virtual void SetTextSize(Float_t textsize)
Set current text size.
static const double x1[5]
Bool_t AllocColor(Colormap cmap, RXColor *color)
Allocate color in colormap.
static TTFX11Init gTTFX11Init
const Mask_t kGCForeground
void Align(void)
Compute alignment variables.
void DeleteGC(GContext_t gc)
Explicitly delete a graphics context.
#define org(otri, vertexptr)
static Bool_t fgSmoothing
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
const size_t kBitsPerByte
RVisual * fVisual
Pointer to visual used by all windows.
const Mask_t kGCBackground
virtual void MapGCFont(GContext_t, FontStruct_t)
Map the XftFont with the Graphics Context using it.
Bool_t Init(void *display)
Initialize X11 system. Returns kFALSE in case of failure.
Bool_t IsVisible(Int_t x, Int_t y, UInt_t w, UInt_t h)
Test if there is really something to render.
static void SetTextSize(Float_t textsize)
Set current text size.
ClassImp(TGX11TTF) TGX11TTF
Create copy of TGX11 but now use TrueType fonts.
RXImage * GetBackground(Int_t x, Int_t y, UInt_t w, UInt_t h)
Get the background of the current window in an XImage.
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
Int_t TextWidth(FontStruct_t font, const char *s, Int_t len)
Return length of string in pixels. Size depends on font.
static const FT_BBox & GetBox()
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.