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 1765

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

powered by: WebSVN 2.1.0

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