File: load_font.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (97 lines) | stat: -rw-r--r-- 2,173 bytes parent folder | download | duplicates (6)
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
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				load_font.c

Purpose:
	Load font. If this is not posssible, try some replacements.

Input:
	(1) Pointer to WindowS structure, where font structure pointer will
	    be stored.
	(2) Pointer to display structure.
	(3) Font name (string).

Output:
	(1) Font structure pointer initialized.
	(2) Font flag set.
	(3) Return value.

Return value:
	(1) Positive on success.
	(2) Negative on failure.

========includes:============================================================*/

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======load font:===========================================================*/

int LoadFont_ (WindowS *winSP, Display *displaySP, char *font_nameP)
{
static XFontStruct	*fontSP;

/* The first attempt: */
fontSP = XLoadQueryFont (displaySP, font_nameP);
if (fontSP)
	{
	winSP->fontSP = fontSP;
	winSP->fontF = 1;
	return 1;
	}
else printf ("The font %s not available, trying 10x20 ...\n", font_nameP);

/* The second attempt - trying 10x20: */
fontSP = XLoadQueryFont (displaySP, "10x20");
if (fontSP) 
	{
	winSP->fontSP = fontSP;
	winSP->fontF = 1;
	return 2;
	}
else printf ("The font 10x20 not available, trying 9x15 ...\n");

/* The third attempt - 9x15: */
fontSP = XLoadQueryFont (displaySP, "9x15");
if (fontSP)
	{
	winSP->fontSP = fontSP;
	winSP->fontF = 1;
	return 3;
	}
else printf ("The font 9x15 not available, trying 7x14...\n");

/* The fourth attempt - 7x14: */
fontSP = XLoadQueryFont (displaySP, "7x14");
if (fontSP)
        {
        winSP->fontSP = fontSP;
	winSP->fontF = 1;
        return 4;
        }
else printf ("The font 7x14 not available, trying fixed ...\n");

/* The fifth (and last) attempt - fixed font: */
fontSP = XLoadQueryFont (displaySP, "fixed");
if (fontSP)
	{
	winSP->fontSP = fontSP;
	winSP->fontF = 1;
	return 5;
	}
else printf ("Fixed font not available, wouldn't try any more.\n");

return -1;
}

/*===========================================================================*/