Reputation: 31
I want to add fonts in my x11 application. I tried adding but am finding difficulty in changing its size using the font name. When I changed the font's points and pixel, it turned into very small fonts. Can anyone help in getting the large font name.
Here, I have attached sample code which I tried,
#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;
}
These sizes are not enough for my application. For example, I need size-96 (while selecting in LibreOffice Writer) this is the font selected in LibreOffice Writer, this is size-96. I want like this
Also suggest for loading TrueType fonts
Upvotes: 1
Views: 2959
Reputation: 2449
[LONG explanation since short comments seem insufficient]
One upon a time :
So people wrote something called the X11 core font system whose main objective was to help you select among a stash of server-side expensive paid-for corporate 256-character single-resolution bitmap fonts. And "help" took the form of obscure XFLD strings, with xfontsel as helper.
Then happened:
Users started not caring about 90% of the settings of XFLD strings.
The X11 core fonts system started failing over. Its server-side caching model is really designed for small single-size bitmap fonts, not complex multi-megabyte vector files.
The X11 core fonts maintainers (XFRee86 then Xorg) struggled a while to adapt it to modern times then gave up since the whole design is completely inadapted.
Every complex open-source software manipulating text that mattered was ported to the new stack. Including massive codebases such as LibreOffice
Big vendors noticed and started contributing directly to those projects (for example, the CFF engine used by freetype nowadays was written by Adobe. Most Opentype OTF fonts on the market use CFF shapes).
The only people who didn't care are vendors of proprietary UNIX software that are quite happy to sell you obsolete graphical code designed around the capabilities of 1980's SGI/Solaris/HP-UX workstations, like to look down on Linux systems, and wait for Windows NT to take up the world by storm. Their target customers are usually engineering/scientific people that are ready to cope with broken text as long as there is no alternative and the computations seem right. Though those people love their data visualisation graphs. I suspect HiDPI will be the end of scientific software stuck in X11 bitmap fonts era.
Therefore:
Upvotes: 5