"Fossies" - the Fresh Open Source Software Archive

Member "screentest-2.0/text_test.c" (28 Jul 2007, 2756 Bytes) of package /linux/privat/old/screentest-2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "text_test.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *  Screentest - CRT/LCD monitor testing utility.
    3  *  http://screentest.sourceforge.net/
    4  *  Copyright (C) 2001 Jan "Yenya" Kasprzak <kas@fi.muni.cz>
    5  *  Copyright (C) 2006-2007 Tobias Gruetzmacher <tobias@portfolio16.de>
    6  *
    7  *  This program is free software; you can redistribute it and/or modify
    8  *  it under the terms of the GNU General Public License version 2 as
    9  *  published by the Free Software Foundation.
   10  *
   11  *  This program is distributed in the hope that it will be useful,
   12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  *  GNU General Public License for more details.
   15  *
   16  *  You should have received a copy of the GNU General Public License
   17  *  along with this program; if not, write to the Free Software
   18  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
   19  */
   20 
   21 #ifdef HAVE_CONFIG_H
   22 #  include <config.h>
   23 #endif
   24 
   25 #include <stdio.h>
   26 #include <gtk/gtk.h>
   27 
   28 #include "callbacks.h"
   29 
   30 static gchar *fontnames[] = {
   31     "-adobe-times-medium-r-normal-*-*-80-*-*-p-*-iso8859-1",
   32     "-adobe-times-medium-r-normal-*-*-100-*-*-p-*-iso8859-1",
   33     "-adobe-times-medium-r-normal-*-*-120-*-*-p-*-iso8859-1",
   34     "-adobe-times-medium-r-normal-*-*-140-*-*-p-*-iso8859-1",
   35     "-adobe-times-medium-r-normal-*-*-180-*-*-p-*-iso8859-1",
   36     "-adobe-times-medium-r-normal-*-*-240-*-*-p-*-iso8859-1",
   37     NULL
   38 };
   39 
   40 static gint font_num;
   41 
   42 static gchar text[] =
   43     "The Screentest home page: http://screentest.sourceforge.net/";
   44 
   45 GdkFont *font;
   46 gint baselineskip, textwidth;
   47 
   48 static void font_init(G_GNUC_UNUSED GtkWidget * widget)
   49 {
   50     gint lbear, rbear, width, asc, desc;
   51 
   52     font = gdk_font_load(fontnames[font_num]);
   53 
   54     if (!font) {
   55         printf("Cannot load font %s, trying 'fixed'.\n",
   56                fontnames[font_num]);
   57         font = gdk_font_load("fixed");
   58     }
   59 
   60     gdk_string_extents(font, text, &lbear, &rbear, &width, &asc,
   61                &desc);
   62     baselineskip = 6 * (asc + desc) / 5;    /* 1.2x text height */
   63     textwidth = width + baselineskip;   /* the actual width plus space */
   64 }
   65 
   66 static void text_init(GtkWidget * widget)
   67 {
   68     font_num = 1;
   69     font_init(widget);
   70 }
   71 
   72 static void text_draw(GtkWidget * widget)
   73 {
   74     GdkWindow *win = widget->window;
   75     gint w, h;
   76     gint x, y;
   77 
   78     gdk_window_get_size(win, &w, &h);
   79 
   80     x = w + textwidth;
   81     for (y = 0; y < h; y += baselineskip)
   82         for (x -= w + textwidth; x < w; x += textwidth)
   83             gdk_draw_string(win, font, gc, x, y, text);
   84 }
   85 
   86 static void text_close(G_GNUC_UNUSED GtkWidget * widget)
   87 {
   88     gdk_font_unref(font);
   89 }
   90 
   91 static void text_cycle(GtkWidget * widget)
   92 {
   93     gdk_font_unref(font);
   94     if (fontnames[++font_num] == NULL)
   95         font_num = 0;
   96     font_init(widget);
   97 }
   98 
   99 struct test_ops text_ops = {
  100     init:text_init,
  101     draw:text_draw,
  102     cycle:text_cycle,
  103     close:text_close,
  104 };