【发布时间】:2017-03-31 17:37:22
【问题描述】:
我想在我的 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;
}
这些尺寸对于我的应用来说是不够的。例如,我需要 size-96(在 LibreOffice Writer 中选择时) this is the font selected in LibreOffice Writer, this is size-96. I want like this
还建议加载 TrueType 字体
【问题讨论】:
-
没有“找难度”之类的错误
-
我不知道如何更改字体大小,所以请帮助我。
-
您能否再次阅读"how do I ask a good question" 并相应地更新您的帖子?这三行代码肯定不足以看出你的代码可能出了什么问题,所以至少看看你是否可以创建一个minimal reproducible example,这样人们才能真正理解这个问题。缺乏这一点,您将不得不更详细地了解您正在做什么。您遗漏了许多您可能认为很明显的信息,但对于不是您的人来说,这根本不明显。
-
再次,使用客户端字体。如果您出于某种未知原因需要服务器端字体,您可以在服务器端安装可缩放字体(ttf、opentype)。几乎没有人这样做,因为客户端字体更好。
标签: c linux fonts x11 truetype