Displaying Text in the Window

Now let's load a big font and write a message in the window.

     | ?- load_font('*-times-bold-i-normal--24-*', Font),
          put_graphics_attributes(Window, [font(Font)]),
          draw_string(Window, 10, 50, 'Hello, world!!').
     Font = font(1787304),
     Window = window(2376568)

load_font/2 does just what it sounds like. The atom, '*-times-bold-i-*-240-*' is the specification of a font that is known to the X11 server.1 To see all of the fonts known to your X11 server, use the shell command xlsfonts.

put_graphics_attributes/2 will change graphics attributes of its first argument (aspects you might expect to specify when drawing). In this case, we're specifying that we want to use the font we just loaded when we draw text in this window. Then we call draw_string/4 to write the message Hello, world!! into the window starting at the pixel position (10,50).

Notice that we didn't use put_window_attributes/2 to specify the font for the window, but instead used put_graphics_attributes/2. The difference is important. ProXL has many put_something_attributes/2 procedures, and in all cases the something refers to the attributes, not to the object being changed. In this case, put_window_attributes/2 changes window attributes of the window you pass it. But put_graphics_attributes/2 changes graphics attributes of the argument you pass it. Here that argument is a window; in pxl-tut-dbg we will use put_graphics_attributes/2 to change a pixmap.

The text is positioned at the coordinates (10,50). This means that the origin point for the first character is at that position, but what is the origin point? Actually, each type of font has its own way of positioning text relative to the origin point. For the typical latin fonts (fonts for the ASCII character set), however, all of a character is usually printed to the right of the origin point, and only descenders go below the origin point. So you can usually think of the origin as the left end of the baseline for the text being drawn.


  1. If you are using X11 Release 2, then use the font name 'vbg-25'. The way to specify fonts changed from Release 2 to Release 3.