在 x11 中添加非常大的字体

Pop*_*ops 1 c linux x11 fonts truetype

我想在我的 x11 应用程序中添加字体。我尝试添加,但发现使用字体名称更改其大小很困难。当我改变字体的点和像素时,它变成了非常小的字体。谁能帮忙获得大字体名称。

在这里,我附上了我尝试过的示例代码,

#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    Display *d;
    Window w,w1, w2, w3;
    XEvent e;
    int s;
    XGCValues gr_values1 , gr_values2, gr_values3;
    XFontStruct *font1, *font2, *font3;
    GC gr_context1, gr_context2, gr_context3;
    XColor color, dummy;

    d=XOpenDisplay(NULL);
    if (d == NULL) {
        fprintf(stderr,"cant't open the display");
        exit(1);
    }
    s=DefaultScreen(d);

    w=XCreateSimpleWindow(d,RootWindow(d,s),0,0,DisplayWidth(d,s),DisplayHeight(d,s),2,BlackPixel(d,s),WhitePixel(d,s));
    w1=XCreateSimpleWindow(d,w,200,200,200,100,2,BlackPixel(d,s),WhitePixel(d,s));
    w2=XCreateSimpleWindow(d,w,400,200,200,100,2,BlackPixel(d,s),WhitePixel(d,s));
    w3=XCreateSimpleWindow(d,w,600,200,200,100,2,BlackPixel(d,s),WhitePixel(d,s));

    font1 = XLoadQueryFont(d, "-adobe-new century schoolbook-bold-r-normal--24-240-75-75-p-149-iso8859-9");
    font2 = XLoadQueryFont(d, "-adobe-new century schoolbook-bold-r-normal--18-180-75-75-p-113-iso8859-9");
    font3 = XLoadQueryFont(d, "-adobe-new century schoolbook-bold-r-normal--12-120-75-75-p-77-iso8859-9");
    XAllocNamedColor(d, DefaultColormap(d, s),"purple",&color,&dummy);

    gr_values1.font = font1->fid;
    gr_values1.foreground = color.pixel;
    gr_context1=XCreateGC(d,w,GCFont+GCForeground, &gr_values1);
    gr_values2.font = font2->fid;
    gr_values2.foreground = color.pixel;
    gr_context2=XCreateGC(d,w,GCFont+GCForeground, &gr_values2);
    gr_values3.font = font3->fid;
    gr_values3.foreground = color.pixel;
    gr_context3=XCreateGC(d,w,GCFont+GCForeground, &gr_values3);

    XSetFont(d,gr_context1,font1->fid);
    XSetFont(d,gr_context2,font2->fid);
    XSetFont(d,gr_context3,font3->fid);

    XSelectInput(d,w,ExposureMask);
    XSelectInput(d,w1,KeyPressMask);
    XSelectInput(d,w2,KeyPressMask);
    XSelectInput(d,w3,KeyPressMask);

    XMapWindow(d,w);

    while(1){
        XNextEvent(d, &e);
        if (e.xany.window == w) {
            if (e.type == Expose) {
                 XMapWindow(d,w1);
                 XMapWindow(d,w2);
                 XMapWindow(d,w3);
            }
        }
        if (e.xany.window == w1) {
            if (e.type == KeyPress) {
                XDrawString(d,w1,gr_context1,50,50,"hello",5);
                XDrawString(d,w2,gr_context2,50,50,"hello",5);
                XDrawString(d,w3,gr_context3,50,50,"hello",5);
            }
        }
    }
    XCloseDisplay(d);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

上述代码的输出

这些尺寸不足以满足我的应用。例如,我需要 size-96(在 LibreOffice Writer 中选择时) 这是在 LibreOffice Writer 中选择的字体,这是 size-96。我想要这样

还建议加载 TrueType 字体

nim*_*nim 5

[很长的解释,因为简短的评论似乎不够]

\n\n

曾几何时\xc2\xa0:

\n\n
    \n
  • 7/8 位字符编码(每个字体最多 256 个符号)规则,
  • \n
  • 低分辨率屏幕(最大 800\xc3\x97600)是常态,
  • \n
  • 字体稀缺(没有真正的字体创建工具,逐像素设计)。
  • \n
\n\n

因此,人们编写了一种称为 X11 核心字体系统的东西,其主要目标是帮助您在服务器端昂贵的付费企业 256 字符单分辨率位图字体中进行选择。“帮助”采用晦涩的 XFLD 字符串的形式,以 xfontsel 作为帮助器。

\n\n

然后发生了:

\n\n
    \n
  • 桌面出版,
  • \n
  • 矢量字体(Postscript),
  • \n
  • 智能字体(TrueType 然后 OpenType:砂砾拟合、提示、复杂的字形组成和定位、连字等),
  • \n
  • 大编码字体(Unicode),
  • \n
  • 多向语言,
  • \n
  • 多面字体(不仅是常规+粗体+斜体),
  • \n
  • 更大的字体可用性(Microsoft 网络核心字体,然后是 GNOME 的 Bitstream Vera,然后是 Open Fonts 库,然后是 Google 字体目录)
  • \n
  • 更高分辨率的屏幕
  • \n
  • 高DPI
  • \n
  • 彩色字体
  • \n
  • 符号字体(数学、工程符号和表情符号)
  • \n
\n\n

用户开始不关心 XFLD 字符串 90% 的设置。

\n\n

X11 核心字体系统开始出现故障转移。它的服务器端缓存模型实际上是为小型单一尺寸位图字体设计的,而不是复杂的多兆字节矢量文件。

\n\n

X11 核心字体维护者(XFRee86,然后是 Xorg)花了一段时间才使它适应现代,然后放弃了,因为整个设计完全不适应。

\n\n
    \n
  • 他们将矢量字体光栅化(从矢量到位图的转换)外包给 freetype。
  • \n
  • 字形缓存已通过 fontconfig 移至客户端(使用 Xft 作为垫脚石,您应该完全忘记)
  • \n
  • 文本方向已改为 freebidi。
  • \n
  • TrueType/OpenType 的“智能”部分对于 freetype 来说过于复杂,因此再次外包给 GTK (pango\xe2\x80\xa6) 和 QT 整形引擎
  • \n
  • 然后(一旦两个团队都厌倦了分别处理 OpenType 细节和规范更新)在 harfbuzz-ng 中再次合并。
  • \n
\n\n

每个复杂的开源软件操作重要的文本都被移植到新的堆栈中。包括 LibreOffice 等海量代码库

\n\n

大供应商注意到并开始直接为这些项目做出贡献(例如,现在 freetype 使用的 CFF 引擎是由 Adob​​e 编写的。市场上大多数 Opentype OTF 字体都使用 CFF 形状)。

\n\n

唯一不关心的是专有 UNIX 软件的供应商,他们很乐意向您出售围绕 1980 年 SGI/Solaris/HP-UX 工作站功能设计的过时图形代码,就像看不起 Linux 系统一样,等待 Windows NT 席卷全球。他们的目标客户通常是工程/科学家,只要没有其他选择并且计算看起来正确,他们就准备好应对破碎的文本。尽管这些人喜欢他们的数据可视化图表。我怀疑 HiDPI 将是陷入 X11 位图字体时代的科学软件的终结。

\n\n

所以:

\n\n
    \n
  • 不要试图让 X11 核心字体系统超越其极限,许多其他人在你之前尝试过,但最终放弃了它
  • \n
  • 除非你想和上个世纪的 Unix 工作站一样被归入同一个墓地,否则在你还有一些用户的时候将你的代码移植到 fontconfig+freebidy+freetype+harfbuzz-ng
  • \n
\n