/usr/share/doc/xviewg/examples/fonts/type_font.c is in xview-examples 3.2p1.4-28.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | /*
* simple_font.c -- very simple program showing how to render text
* using fonts loaded by XView.
*/
#include <ctype.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/font.h>
Display *dpy;
GC gc;
XFontStruct *font_info;
main(argc, argv)
int argc;
char *argv[];
{
Frame frame;
Panel panel;
Canvas canvas;
XGCValues gcvalues;
Xv_Font font;
void my_event_proc();
extern void exit();
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
frame = (Frame)xv_create(XV_NULL, FRAME,
FRAME_LABEL, argv[0],
NULL);
panel = (Panel)xv_create(frame, PANEL,
PANEL_LAYOUT, PANEL_VERTICAL,
NULL);
xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Quit",
PANEL_NOTIFY_PROC, exit,
NULL);
window_fit(panel);
canvas = (Canvas)xv_create(frame, CANVAS,
XV_WIDTH, 400,
XV_HEIGHT, 200,
CANVAS_X_PAINT_WINDOW, TRUE,
NULL);
xv_set(canvas_paint_window(canvas),
WIN_EVENT_PROC, my_event_proc,
NULL);
window_fit(frame);
dpy = (Display *)xv_get(frame, XV_DISPLAY);
font = (Xv_Font)xv_get(frame, XV_FONT);
font_info = (XFontStruct *)xv_get(font, FONT_INFO);
gcvalues.font = (Font)xv_get(font, XV_XID);
gcvalues.foreground = BlackPixel(dpy, DefaultScreen(dpy));
gcvalues.background = WhitePixel(dpy, DefaultScreen(dpy));
gcvalues.graphics_exposures = False;
gc = XCreateGC(dpy, RootWindow(dpy, DefaultScreen(dpy)),
GCForeground | GCBackground | GCFont | GCGraphicsExposures, &gcvalues);
xv_main_loop(frame);
}
void
my_event_proc(win, event)
Xv_Window win;
Event *event;
{
static int x = 10, y = 10;
Window xwin = (Window)xv_get(win, XV_XID);
char c;
if (event_is_up(event))
return;
if (event_is_ascii(event)) {
c = (char)event_id(event);
if (c == '\n' || c == '\r') {
y += font_info->max_bounds.ascent +
font_info->max_bounds.descent;
x = 10;
} else if (c == 7 || c == 127) { /* backspace or delete */
if (x > 10)
x -= XTextWidth(font_info, "m", 1);
/* use XDrawImageString to overwrite previous text */
XDrawImageString(dpy, xwin, gc, x, y, " ", 2);
} else {
XDrawString(dpy, xwin, gc, x, y, &c, 1);
x += XTextWidth(font_info, &c, 1);
}
} else if (event_action(event) == ACTION_SELECT) {
x = event_x(event);
y = event_y(event);
}
}
|