0
我想用XDrawString()
显示西里尔符号,但在屏幕上它们显示为错误的编码。XDrawString不正确的编码
我已经在我的系统(ubuntu 14.04)中安装了xfonts-cyrillic
,但仍然从xlsfonts
列表中显示错误的结果。
我的代码(main.cpp中):
#include <X11/Xlib.h>
#include <string.h>
int main(int, char**)
{
Display *d = XOpenDisplay(0);
Window r = DefaultRootWindow(d);
Window w = XCreateSimpleWindow(d, r, 0, 0, 256, 256, 0, 0, 0xffffff);
GC gc = DefaultGC(d, 0);
XMapRaised(d, w);
XSelectInput(d, w, ExposureMask);
Font font = XLoadFont(d, "9x15-cyrillic");
XSetFont(d, gc, font);
const char *msg = "тут текст"; // cyrillic symbols
while (1)
{
XEvent e;
XNextEvent(d, &e);
XDrawString(d, w, gc, 16, 16, msg, (int) strlen(msg));
}
}
编译:
g++ -Wall -g -std=c++11 main.cpp -L/usr/lib/X11 -lX11 -o output
我的结果是:
为什么在结果窗口中的文字是错误的编码?我错过了什么?