Created
November 3, 2017 17:30
-
-
Save yath/a0d0b4839b030ef4e76b36abb556bacc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* $ gcc -W -Wall -Wextra -o fttest fttest.c -lX11 -lXft `pkg-config --cflags freetype2` | |
* $ ./fttest "DejaVu Sans Mono" | |
* $ ./fttest "Noto Color Emoji" | |
* X Error of failed request: BadLength (poly request too large or internal Xlib length error) | |
* Major opcode of failed request: 139 (RENDER) | |
* Minor opcode of failed request: 20 (RenderAddGlyphs) | |
* Serial number of failed request: 21 | |
* Current serial number in output stream: 23 | |
*/ | |
#include <unistd.h> | |
#include <X11/Xlib.h> | |
#include <X11/Xutil.h> | |
#include <X11/Xft/Xft.h> | |
#define ELEMS(x) (sizeof(x) / sizeof((x)[0])) | |
XftChar32 msg[] = { ':', ')', ' ', 0x263a }; // ":) ☺" | |
void redraw(XftDraw *d, XftColor *c, XftFont *f) { | |
XftDrawString32(d, c, f, 20, 70, msg, ELEMS(msg)); | |
} | |
int main(int argc, char **argv) | |
{ | |
Display *display; | |
XftFont *font; | |
XftDraw *xftdraw; | |
XEvent event; | |
if (argc != 2) { | |
fprintf(stderr, "Usage: %s <font>\n", argv[0]); | |
return 1; | |
} | |
display = XOpenDisplay(0); | |
Window w = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, 360, 90, 0, 0, 0); | |
XMapWindow(display, w); | |
XSelectInput(display, w, ExposureMask | KeyPressMask); | |
font = XftFontOpenName(display, 0, argv[1]); | |
if (!font) { | |
fprintf(stderr, "XftFontOpenName failed\n"); | |
return 1; | |
} | |
xftdraw = XftDrawCreate(display, w, DefaultVisual(display, 0), DefaultColormap(display, 0)); | |
XRenderColor xrcolor = {.red = 0xffff,.alpha = 0xffff }; | |
XftColor xftcolor; | |
XftColorAllocValue(display, DefaultVisual(display, 0), DefaultColormap(display, 0), &xrcolor, &xftcolor); | |
redraw(xftdraw, &xftcolor, font); | |
while (1) { | |
XNextEvent(display, &event); | |
if (event.type == Expose) | |
redraw(xftdraw, &xftcolor, font); | |
if (event.type == KeyPress) | |
break; | |
} | |
XftColorFree(display, DefaultVisual(display, 0), | |
DefaultColormap(display, 0), &xftcolor); | |
XftDrawDestroy(xftdraw); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment