【问题标题】:Can not load personal font using XLoadFont无法使用 XLoadFont 加载个人字体
【发布时间】:2019-03-08 17:30:33
【问题描述】:

您好,我是 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

【问题讨论】:

    标签: c fonts x11


    【解决方案1】:

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

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

    几乎所有现代软件都使用外部库(例如 Cairo)来绘制文本。 X11 字体仅被少数非常古老的应用程序使用,例如 xterm。

    【讨论】:

    • 谢谢。我想我会用像素图字体然后
    猜你喜欢
    • 2011-04-10
    • 2016-12-24
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 2017-05-27
    • 1970-01-01
    • 2017-06-02
    相关资源
    最近更新 更多