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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mw/] [src/] [demos/] [nanox/] [t1demo.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * font demo for Nano-X
3
 * also includes region clipping demo
4
 */
5
#include <stdio.h>
6
#include <stdlib.h>
7
#if UNIX | DOS_DJGPP
8
#include <time.h>
9
#endif
10
#define MWINCLUDECOLORS
11
#include "nano-X.h"
12
 
13
#define MAXW            (630-50)
14
#define MAXH            (470-50)
15
 
16
#define CLIP_POLYGON    0        /* =1 for polygonal region test*/
17
 
18
#if HAVE_HZK_SUPPORT
19
#define BIG5
20
 
21
#define MAXFONTS 1
22
#ifndef BIG5 
23
#define FONT1 "HZKFONT"
24
#define FONT2 "HZKFONT"
25
#define FONT3 "HZKFONT"
26
#define FONT4 "HZKFONT"
27
#define FONT5 "HZKFONT"
28
#else
29
#define FONT1 "HZXFONT"
30
#define FONT2 "HZXFONT"
31
#define FONT3 "HZXFONT"
32
#define FONT4 "HZXFONT"
33
#define FONT5 "HZXFONT"
34
#endif
35
#elif HAVE_T1LIB_SUPPORT
36
#define MAXFONTS 5
37
#define FONT1 "bchr"
38
#define FONT2 "bchb"
39
#define FONT3 "dcr10"
40
#define FONT4 "dcbx10"
41
#define FONT5 "bchri"
42
#else
43
/* truetype*/
44
#define MAXFONTS 5
45
#define FONT1 "lt1-r-omega-serif"
46
#define FONT2 "arial"
47
#define FONT3 "times"
48
#define FONT4 "cour"
49
#define FONT5 "timesi"
50
#endif
51
 
52
static char * names[5] = { FONT1, FONT2, FONT3, FONT4, FONT5 };
53
 
54
int main()
55
{
56
        GR_WINDOW_ID    window;
57
        GR_EVENT        event;
58
        GR_GC_ID        gc;
59
        GR_FONT_ID      fontid;
60
        int             i, x, y;
61
        GR_REGION_ID    regionid = 0;
62
#if CLIP_POLYGON
63
        GR_POINT        points[]={ {100, 100},
64
                                {300, 100},
65
                                {300, 300},
66
                                {100, 300}};
67
#else
68
        GR_RECT         clip_rect={100,100,300,300};
69
#endif
70
 
71
        srand(time(0));
72
 
73
        GrOpen();
74
        window = GrNewWindow(GR_ROOT_WINDOW_ID, 50,50, MAXW,MAXH, 4, BLACK,BLUE);
75
        GrMapWindow(window);
76
 
77
        gc = GrNewGC();
78
 
79
#if CLIP_POLYGON
80
        /* polygon clip region*/
81
        regionid = GrNewPolygonRegion(MWPOLY_EVENODD, 3, points);
82
#else
83
        /* rectangle clip region*/
84
        regionid = GrNewRegion();
85
        GrUnionRectWithRegion(regionid, &clip_rect);
86
#endif
87
 
88
        GrSetGCRegion(gc, regionid);
89
 
90
        GrSelectEvents(window,GR_EVENT_MASK_ALL);
91
        GrSetGCUseBackground(gc,GR_FALSE);
92
        GrSetGCBackground(gc, GR_RGB(0, 0, 0));
93
        while(1) {
94
              GrCheckNextEvent(&event);
95
 
96
              i = (int)((float)MAXFONTS * rand() / (RAND_MAX + 1.0));
97
              fontid = GrCreateFont(names[i], 20, NULL);
98
              GrSetFontSize(fontid, 1+(int)(80.0 * rand() / (RAND_MAX+1.0)));
99
              GrSetFontRotation(fontid, 330);   /* 33 degrees*/
100
              GrSetFontAttr(fontid, GR_TFKERNING | GR_TFANTIALIAS, 0);
101
              GrSetGCFont(gc, fontid);
102
              /*GrSetGCBackground(gc, rand() & 0xffffff);*/
103
              GrSetGCForeground(gc, rand() & 0xffffff);
104
              x = (int) ((MAXW * 1.0) *rand()/(RAND_MAX+1.0));
105
              y = (int) ((MAXH * 1.0) *rand()/(RAND_MAX+1.0));
106
 
107
#if HAVE_HZK_SUPPORT
108
             {  /* to test Unicode 16 chinese characters display ,use HZK font Bitmap font (Metrix font). */
109
#ifndef BIG5            
110
                char buffer[256];
111
                buffer[0]=0x6c;
112
                buffer[1]=0x49;
113
                buffer[2]=0x73;
114
                buffer[3]=0x8b;
115
                buffer[4]=0x79;
116
                buffer[5]=0xd1;
117
                buffer[6]=0x62;
118
                buffer[7]=0x80;
119
                buffer[8]=0x61;
120
                buffer[9]=0x00;
121
                buffer[10]=0x41;
122
                buffer[11]=0x00;
123
 
124
                buffer[12]=0x00;
125
                buffer[13]=0xa1;
126
                buffer[14]=0x00;
127
                buffer[15]=0xa6;
128
                buffer[16]=0x6c;
129
                buffer[17]=0x49;
130
                buffer[18]=0x0;
131
                buffer[19]=0x0;
132
                GrText(window, gc,x,y+20, buffer,17, GR_TFUC16);
133
                x=0;y=16;
134
                GrText(window, gc,x,y+20, buffer,17, GR_TFUC16);
135
#else
136
                unsigned short buffer[7];
137
                buffer[0]=0x9060;
138
                buffer[1]=0x898b;
139
                buffer[2]=0x79d1;
140
                buffer[3]=0x6280;
141
                buffer[4]=0x0061;
142
                buffer[5]=0x0041;
143
                buffer[6]=0x0;
144
                GrText(window, gc,x,y+20, buffer,7, GR_TFUC16);
145
                x=0;y=16;
146
                GrText(window, gc,x,y+20, buffer,7, GR_TFUC16);
147
#endif
148
              }
149
 
150
#ifndef BIG5
151
              x=0;y=16;
152
              /* HZK Metrix font test, includes Chinese and English*/
153
              GrText(window, gc,x,y, "Microwindows,欢迎使用中英文点阵字体",
154
                      -1, GR_TFASCII);
155
#else   
156
              GrText(window, gc,x,y, "Microwindows,舧ㄏノい璣ゅ翴皚砰",
157
                      -1, GR_TFASCII);
158
              x=0;y=16*3+4;
159
              GrText(window, gc,x,y, "89:", -1, GR_TFASCII);
160
#endif
161
              GrFlush();
162
 
163
#else /* !HZK_FONT_SUPPORT*/
164
 
165
#if HAVE_BIG5_SUPPORT
166
              /* ENCODING_BIG5 test*/
167
              GrText(window, gc,x,y, "眃眃", -1, GR_TFASCII);
168
#else
169
#if HAVE_GB2312_SUPPORT
170
              /* ENCODING_GB2312 test*/
171
              GrText(window, gc,x,y, "\275\241\275\241", -1, GR_TFASCII);
172
#else
173
              /* ASCII test*/
174
              GrText(window, gc,x,y, "Microwindows", -1, GR_TFASCII);
175
#endif
176
#endif
177
 
178
#endif /* HZK_FONT_SUPPORT*/
179
 
180
 
181
              GrDestroyFont(fontid);
182
 
183
                if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
184
                        GrClose();
185
                        exit(0);
186
                }
187
        }
188
 
189
        GrDestroyRegion(regionid);
190
        GrClose();
191
}

powered by: WebSVN 2.1.0

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