OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [demos/] [nanox/] [ftdemo.c] - Blame information for rev 673

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Demonstration program for freetype truetype font support
3
 * Martin Jolicoeur 2000 martinj@visuaide.com.
4
 */
5
#include <stdio.h>
6
#define MWINCLUDECOLORS
7
#include "nano-X.h"
8
 
9
#if HAVE_T1LIB_SUPPORT
10
#define FONTNAME "bchr"
11
#if 0
12
#define FONTNAME "bchb"
13
#define FONTNAME "dcr10"
14
#define FONTNAME "dcbx10"
15
#endif
16
#elif HAVE_FREETYPE_SUPPORT
17
#define FONTNAME "lt1-r-omega-serif"
18
#if 0
19
#define FONTNAME "times"
20
#define FONTNAME "cour"
21
#endif
22
#else
23
#define FONTNAME GR_FONT_SYSTEM_VAR
24
#endif
25
 
26
#define MAXW 400
27
#define MAXH 400
28
 
29
GR_GC_ID gid;
30
GR_FONT_ID fontid, fontid2;
31
GR_BOOL kerning = GR_FALSE;
32
GR_BOOL aa = GR_TRUE;
33
GR_BOOL underline = GR_FALSE;
34
int angle = 0;
35
int state = GR_TFBOTTOM;
36
char buffer[128];
37
int n;
38
void Render(GR_WINDOW_ID window);
39
 
40
int
41
main()
42
{
43
  FILE *file;
44
  GR_EVENT event;
45
  GR_WINDOW_ID window;
46
 
47
  if (GrOpen() < 0) {
48
        fprintf(stderr, "cannot open graphics\n");
49
        exit(1);
50
  }
51
 
52
  window = GrNewWindow(GR_ROOT_WINDOW_ID, 50,50, MAXW,MAXH, 4, BLACK, WHITE);
53
  GrMapWindow(window);
54
 
55
  gid = GrNewGC ();
56
  GrSelectEvents(window, GR_EVENT_MASK_KEY_DOWN |
57
                GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE);
58
 
59
  if ((file = fopen("ftdemo.txt", "r")) == NULL) {
60
        printf("Can't open text file\n");
61
        return (-1);
62
  }
63
 
64
  n = 0;
65
 
66
  if(fgets(buffer, 128, file) != NULL) {
67
        for (n = 0; n < 128 && buffer[n]; n++) {
68
                if (buffer[n] == '\n')
69
                        break;
70
        }
71
  }
72
  fclose(file);
73
 
74
  fontid = GrCreateFont(FONTNAME, 20, NULL);
75
  fontid2 = GrCreateFont(FONTNAME, 36, NULL);
76
 
77
  Render(window);
78
 
79
  while (1) {
80
    GrGetNextEvent(&event);
81
 
82
    switch (event.type) {
83
    case GR_EVENT_TYPE_KEY_DOWN:
84
      switch(event.keystroke.ch) {
85
        case 171: /* + */
86
        case '+':
87
        case '=':
88
          angle += 100; /* Increase 10 degrees */
89
          angle %= 3600;
90
          break;
91
        case 173: /* - */
92
        case '-':
93
        case '_':
94
          angle -= 100; /* Decrease 10 degrees */
95
          angle %= 3600;
96
          break;
97
        case 'a':
98
          aa = (aa == GR_FALSE)?GR_TRUE:GR_FALSE;
99
          break;
100
        case 'k':
101
          kerning = (kerning == GR_FALSE)?GR_TRUE:GR_FALSE;
102
          break;
103
        case 'l':
104
          state = (state == GR_TFBOTTOM)?GR_TFBASELINE: \
105
                  (state == GR_TFBASELINE)?GR_TFTOP:GR_TFBOTTOM;
106
          break;
107
        case 'u':
108
          underline = underline? GR_FALSE: GR_TRUE;
109
          break;
110
        default:
111
          continue;
112
          /* Unknown keystroke */
113
      }
114
      Render(window);
115
      break;
116
    case GR_EVENT_TYPE_EXPOSURE:
117
      Render(window);
118
      break;
119
    case GR_EVENT_TYPE_CLOSE_REQ:
120
      GrClose();
121
      exit(0);
122
    }
123
  }
124
 
125
  return 0;
126
}
127
 
128
void Render(GR_WINDOW_ID window)
129
{
130
   GrSetGCBackground(gid, WHITE);
131
   GrSetGCForeground (gid, WHITE);
132
   GrSetGCUseBackground(gid, GR_FALSE);
133
   GrFillRect(window, gid, 0, 0, MAXW, MAXH);
134
   GrSetGCForeground (gid, BLACK);
135
 
136
   /* Draw menu */
137
   GrSetGCFont(gid, fontid);
138
   GrSetFontAttr(fontid, GR_TFKERNING | GR_TFANTIALIAS, 0);
139
   GrText(window, gid, 5, 20, "+ Rotate string clockwise", 25, GR_TFASCII);
140
   GrText(window, gid, 5, 40, "-  Rotate string counter-clockwise", 34, GR_TFASCII);
141
   GrText(window, gid, 5, 60, "a Toggle anti-aliasing", 22, GR_TFASCII);
142
   GrText(window, gid, 5, 80, "k Toggle kerning", 16, GR_TFASCII);
143
   GrText(window, gid, 5, 100, "u Toggle underline", 18, GR_TFASCII);
144
   GrText(window, gid, 5, 120, "l  Toggle alignment bottom/baseline/top", 39, GR_TFASCII);
145
 
146
   /* Draw test string */
147
   GrSetGCFont(gid, fontid2);
148
   GrSetFontAttr(fontid2, (kerning?GR_TFKERNING:0) | (aa?GR_TFANTIALIAS:0) |
149
        (underline?GR_TFUNDERLINE: 0), -1);
150
   GrSetFontRotation(fontid2, angle);
151
   GrText(window, gid, MAXW/2, MAXH/2, buffer, n, state|GR_TFUTF8);
152
 
153
   /* Draw arrow */
154
   GrLine (window, gid, (MAXW/2)-10 , MAXH/2, (MAXW/2)+10, MAXH/2);
155
   GrLine (window, gid, MAXW/2, (MAXH/2)-10, MAXW/2, (MAXH/2)+10);
156
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.