/usr/share/doc/xviewg/examples/fonts/simple_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 | /*
* simple_font.c -- very simple program showing how to render text
* using a font gotten from xv_find(). Hello World is printed in
* the top-left corner of a canvas window.
*/
#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h> /* X.h and Xlib.h used for Xlib graphics */
#include <xview/xview.h>
#include <xview/canvas.h>
#include <xview/font.h>
#include <xview/xv_xrect.h>
#define GC_KEY 10 /* any arbitrary number -- used for XV_KEY_DATA */
main(argc, argv)
int argc;
char *argv[];
{
Frame frame;
Canvas canvas;
XGCValues gcvalues;
Xv_Font font;
void my_repaint_proc();
Display *dpy;
GC gc;
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
frame = (Frame)xv_create(XV_NULL, FRAME, NULL);
canvas = (Canvas)xv_create(frame, CANVAS,
XV_WIDTH, 400,
XV_HEIGHT, 200,
CANVAS_X_PAINT_WINDOW, TRUE,
CANVAS_REPAINT_PROC, my_repaint_proc,
NULL);
window_fit(frame);
dpy = (Display *)xv_get(frame, XV_DISPLAY);
#ifndef __linux__
font = (Xv_Font)xv_find(frame, FONT, FONT_NAME, "courier", NULL);
#else
font = (Xv_Font)xv_find(frame, FONT, FONT_NAME, "fixed", NULL);
#endif
if (!font) {
fprintf(stderr, "%s: cannot use font: courier.\n", argv[0]);
font = (Xv_Font)xv_get(frame, XV_FONT);
}
/* Create a GC to use with Xlib graphics -- set the fg/bg colors
* and set the Font, which is the XV_XID of the XView font object.
*/
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);
/* Assign the gc to the canvas object so we can use the same gc
* each time we draw into the canvas. Also avoids a global
* variable to store the GC.
*/
xv_set(canvas, XV_KEY_DATA, GC_KEY, gc, NULL);
xv_main_loop(frame);
}
/*
* Called every time the window needs repainting.
*/
void
my_repaint_proc(canvas, pw, dpy, xwin, xrects)
Canvas canvas;
Xv_Window pw;
Display *dpy;
Window xwin;
Xv_xrectlist *xrects;
{
GC gc = (GC)xv_get(canvas, XV_KEY_DATA, GC_KEY);
XDrawString(dpy, xwin, gc, 10, 20,
"Hello World", 11); /* 11 = strlen("Hello World") */
}
|