无法使用 XLoadFont 加载个人字体
Can not load personal font using XLoadFont
嗨,我是 X11 的新手,我正在尝试使用 XLoadFont 从目录加载字体,然后使用 XDrawText 打印一些文本,但出于某种原因,我无法加载字体(.ttf 格式),其中我载入字体:
static void setFont(
Object *_this,
const char *path)
{
mc_textPr *this = _this;
Display *display = getDisplay();
Font tmp = XLoadFont(display, path);
if (!tmp) {
raise("Invalid path to font\n");
return;
}
unloadFont(this->text.font, display);
this->text.font = tmp;
}
在你之前,告诉我 X11 很难,应该使用其他东西,它适用于需要使用 X11 的学校项目。
我也知道这个资源
http://xopendisplay.hilltopia.ca/2009/Feb/Xlib-tutorial-part-4----Text.html
但我不明白为什么它会崩溃。
这是实际的错误:
X Error of failed request: BadName (named color or font does not exist)
Major opcode of failed request: 45 (X_OpenFont)
Serial number of failed request: 17
Current serial number in output stream: 27
XLoadFont()
只能加载 X 服务器已经可用的 X11 位图字体。它无法加载 TTF 字体文件,也无法从您指定的文件中加载字体。
要查找系统上可用的字体名称,运行 xfontsel
。
几乎所有现代软件都使用外部库(如 Cairo)来绘制文本。 X11 字体仅由一些非常古老的应用程序使用,例如 xterm。
嗨,我是 X11 的新手,我正在尝试使用 XLoadFont 从目录加载字体,然后使用 XDrawText 打印一些文本,但出于某种原因,我无法加载字体(.ttf 格式),其中我载入字体:
static void setFont(
Object *_this,
const char *path)
{
mc_textPr *this = _this;
Display *display = getDisplay();
Font tmp = XLoadFont(display, path);
if (!tmp) {
raise("Invalid path to font\n");
return;
}
unloadFont(this->text.font, display);
this->text.font = tmp;
}
在你之前,告诉我 X11 很难,应该使用其他东西,它适用于需要使用 X11 的学校项目。
我也知道这个资源
http://xopendisplay.hilltopia.ca/2009/Feb/Xlib-tutorial-part-4----Text.html
但我不明白为什么它会崩溃。
这是实际的错误:
X Error of failed request: BadName (named color or font does not exist)
Major opcode of failed request: 45 (X_OpenFont)
Serial number of failed request: 17
Current serial number in output stream: 27
XLoadFont()
只能加载 X 服务器已经可用的 X11 位图字体。它无法加载 TTF 字体文件,也无法从您指定的文件中加载字体。
要查找系统上可用的字体名称,运行 xfontsel
。
几乎所有现代软件都使用外部库(如 Cairo)来绘制文本。 X11 字体仅由一些非常古老的应用程序使用,例如 xterm。