File: text_test.c

package info (click to toggle)
screentest 2.0-2.2
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 1,652 kB
  • ctags: 149
  • sloc: sh: 8,940; ansic: 802; makefile: 65
file content (104 lines) | stat: -rw-r--r-- 2,756 bytes parent folder | download | duplicates (4)
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
100
101
102
103
104
/*
 *  Screentest - CRT/LCD monitor testing utility.
 *  http://screentest.sourceforge.net/
 *  Copyright (C) 2001 Jan "Yenya" Kasprzak <kas@fi.muni.cz>
 *  Copyright (C) 2006-2007 Tobias Gruetzmacher <tobias@portfolio16.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <gtk/gtk.h>

#include "callbacks.h"

static gchar *fontnames[] = {
	"-adobe-times-medium-r-normal-*-*-80-*-*-p-*-iso8859-1",
	"-adobe-times-medium-r-normal-*-*-100-*-*-p-*-iso8859-1",
	"-adobe-times-medium-r-normal-*-*-120-*-*-p-*-iso8859-1",
	"-adobe-times-medium-r-normal-*-*-140-*-*-p-*-iso8859-1",
	"-adobe-times-medium-r-normal-*-*-180-*-*-p-*-iso8859-1",
	"-adobe-times-medium-r-normal-*-*-240-*-*-p-*-iso8859-1",
	NULL
};

static gint font_num;

static gchar text[] =
    "The Screentest home page: http://screentest.sourceforge.net/";

GdkFont *font;
gint baselineskip, textwidth;

static void font_init(G_GNUC_UNUSED GtkWidget * widget)
{
	gint lbear, rbear, width, asc, desc;

	font = gdk_font_load(fontnames[font_num]);

	if (!font) {
		printf("Cannot load font %s, trying 'fixed'.\n",
		       fontnames[font_num]);
		font = gdk_font_load("fixed");
	}

	gdk_string_extents(font, text, &lbear, &rbear, &width, &asc,
			   &desc);
	baselineskip = 6 * (asc + desc) / 5;	/* 1.2x text height */
	textwidth = width + baselineskip;	/* the actual width plus space */
}

static void text_init(GtkWidget * widget)
{
	font_num = 1;
	font_init(widget);
}

static void text_draw(GtkWidget * widget)
{
	GdkWindow *win = widget->window;
	gint w, h;
	gint x, y;

	gdk_window_get_size(win, &w, &h);

	x = w + textwidth;
	for (y = 0; y < h; y += baselineskip)
		for (x -= w + textwidth; x < w; x += textwidth)
			gdk_draw_string(win, font, gc, x, y, text);
}

static void text_close(G_GNUC_UNUSED GtkWidget * widget)
{
	gdk_font_unref(font);
}

static void text_cycle(GtkWidget * widget)
{
	gdk_font_unref(font);
	if (fontnames[++font_num] == NULL)
		font_num = 0;
	font_init(widget);
}

struct test_ops text_ops = {
	init:text_init,
	draw:text_draw,
	cycle:text_cycle,
	close:text_close,
};