无法使用XLoadFont加载个人字体

时间:2019-03-08 09:24:35

标签: c fonts x11

嗨,我是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

https://tronche.com/gui/x/

但是我找不到为什么会发疯。

这是实际的错误:

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

1 个答案:

答案 0 :(得分:0)

XLoadFont()只能加载X服务器已经可用的X11位图字体。它无法加载TTF字体文件,也无法从您指定的文件中加载字体。

要查找系统上可用字体的名称,请运行xfontsel

几乎所有现代软件都使用诸如Cairo之类的外部库来绘制文本。 X11字体仅由一些非常古老的应用程序使用,例如xterm。