Pops
Pops

Reputation: 31

Adding fonts with very large size in x11

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;
}

output of above code

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

Answers (1)

nim
nim

Reputation: 2449

[LONG explanation since short comments seem insufficient]

One upon a time :

  • 7/8-bit character encodings (256 symbols per font max) ruled,
  • low resolution screens (800×600 max) were the norm,
  • fonts were scarce (no real font creation tooling, pixel by pixel design).

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:

  • desktop publishing,
  • vector fonts (Postscript),
  • smart fonts (TrueType then OpenType: grit-fitting, hinting, complex glyph composition and positioning, ligatures, etc),
  • large encoding fonts (Unicode),
  • multi-directionnal languages,
  • multifaced fonts (not only regular + bold + italic),
  • larger font availability (Microsoft core fonts for the web, then GNOME's Bitstream Vera, then the Open Fonts library, then the Google fonts directory)
  • better resolution screens
  • HiDPI
  • color fonts
  • symbol fonts (math, engineering symbols and emoticons)

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.

  • They outsourced vector font rasterization (conversion from vector to bitmap) to freetype.
  • Glyph caching was moved client-side with fontconfig (with Xft as a stepping stone that you should completely forget about)
  • Text orientation moved to freebidi.
  • The "smart" part of TrueType/OpenType proved too complex for freetype, so it was outsourced again to GTK (pango…) and QT shaping engines
  • And then (once both teams were fed up with handling OpenType specifics and specification updates separately) merged again in harfbuzz-ng.

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:

  • don't try to push the X11 core fonts system past its limits, many others tried before you and ended up giving up on it
  • unless you want to be relegated to the same graveyard as past century Unix workstations, port your code to fontconfig+freebidy+freetype+harfbuzz-ng while you still have some users

Upvotes: 5

Related Questions