1 //
2 //
3 // Displays Greek letters and mathematically interesting Unicode ranges
4 // Copyright (C) 2005,2008 Alan Irwin
5 // Copyright (C) 2005,2008 Andrew Ross
6 //
7 //
8 // This file is part of PLplot.
9 //
10 // PLplot is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Library General Public License as published
12 // by the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // PLplot is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU Library General Public License
21 // along with PLplot; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 //
25
26 #include "plcdemos.h"
27
28 //
29 // main
30 //
31 // Displays Greek letters and mathematically interesting Unicode ranges
32 //
33
34 static PLCHAR_VECTOR Greek[] = {
35 "#gA", "#gB", "#gG", "#gD", "#gE", "#gZ", "#gY", "#gH", "#gI", "#gK", "#gL", "#gM",
36 "#gN", "#gC", "#gO", "#gP", "#gR", "#gS", "#gT", "#gU", "#gF", "#gX", "#gQ", "#gW",
37 "#ga", "#gb", "#gg", "#gd", "#ge", "#gz", "#gy", "#gh", "#gi", "#gk", "#gl", "#gm",
38 "#gn", "#gc", "#go", "#gp", "#gr", "#gs", "#gt", "#gu", "#gf", "#gx", "#gq", "#gw",
39 };
40
41 static int Type1[] = {
42 0x0020, 0x0021, 0x0023, 0x0025, 0x0026,
43 0x0028, 0x0029, 0x002b, 0x002c, 0x002e,
44 0x002f, 0x0030, 0x0031, 0x0032, 0x0033,
45 0x0034, 0x0035, 0x0036, 0x0037, 0x0038,
46 0x0039, 0x003a, 0x003b, 0x003c, 0x003d,
47 0x003e, 0x003f, 0x005b, 0x005d, 0x005f,
48 0x007b, 0x007c, 0x007d, 0x00a9, 0x00ac,
49 0x00ae, 0x00b0, 0x00b1, 0x00d7, 0x00f7,
50 0x0192, 0x0391, 0x0392, 0x0393, 0x0394,
51 0x0395, 0x0396, 0x0397, 0x0398, 0x0399,
52 0x039a, 0x039b, 0x039c, 0x039d, 0x039e,
53 0x039f, 0x03a0, 0x03a1, 0x03a3, 0x03a4,
54 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9,
55 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5,
56 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba,
57 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
58 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4,
59 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9,
60 0x03d1, 0x03d2, 0x03d5, 0x03d6, 0x2022,
61 0x2026, 0x2032, 0x2033, 0x203e, 0x2044,
62 0x2111, 0x2118, 0x211c, 0x2122, 0x2126,
63 0x2135, 0x2190, 0x2191, 0x2192, 0x2193,
64 0x2194, 0x21b5, 0x21d0, 0x21d1, 0x21d2,
65 0x21d3, 0x21d4, 0x2200, 0x2202, 0x2203,
66 0x2205, 0x2206, 0x2207, 0x2208, 0x2209,
67 0x220b, 0x220f, 0x2211, 0x2212, 0x2215,
68 0x2217, 0x221a, 0x221d, 0x221e, 0x2220,
69 0x2227, 0x2228, 0x2229, 0x222a, 0x222b,
70 0x2234, 0x223c, 0x2245, 0x2248, 0x2260,
71 0x2261, 0x2264, 0x2265, 0x2282, 0x2283,
72 0x2284, 0x2286, 0x2287, 0x2295, 0x2297,
73 0x22a5, 0x22c5, 0x2320, 0x2321, 0x2329,
74 0x232a, 0x25ca, 0x2660, 0x2663, 0x2665,
75 0x2666,
76 };
77
78 static PLCHAR_VECTOR title[] = {
79 "#<0x10>PLplot Example 23 - Greek Letters",
80 "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (a)",
81 "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (b)",
82 "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (c)",
83 "#<0x10>PLplot Example 23 - Number Forms Unicode Block",
84 "#<0x10>PLplot Example 23 - Arrows Unicode Block (a)",
85 "#<0x10>PLplot Example 23 - Arrows Unicode Block (b)",
86 "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (a)",
87 "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (b)",
88 "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (c)",
89 "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (d)",
90 };
91
92 static int lo[] = {
93 0x0,
94 0x0,
95 0x40,
96 0x80,
97 0x2153,
98 0x2190,
99 0x21d0,
100 0x2200,
101 0x2240,
102 0x2280,
103 0x22c0,
104 };
105
106 static int hi[] = {
107 0x30,
108 0x40,
109 0x80,
110 0xA6,
111 0x2184,
112 0x21d0,
113 0x2200,
114 0x2240,
115 0x2280,
116 0x22c0,
117 0x2300,
118 };
119
120 static int nxcells[] = {
121 12,
122 8,
123 8,
124 8,
125 8,
126 8,
127 8,
128 8,
129 8,
130 8,
131 8,
132 };
133
134 static int nycells[] = {
135 8,
136 8,
137 8,
138 8,
139 8,
140 8,
141 8,
142 8,
143 8,
144 8,
145 8,
146 };
147
148 // non-zero values Must be consistent with nxcells and nycells.
149 static int offset[] = {
150 0,
151 0,
152 64,
153 128,
154 0,
155 0,
156 0,
157 0,
158 0,
159 0,
160 0,
161 };
162
163 // 30 possible FCI values.
164
165 #define FCI_COMBINATIONS 30
166 static PLUNICODE fci[] = {
167 0x80000000,
168 0x80000001,
169 0x80000002,
170 0x80000003,
171 0x80000004,
172 0x80000010,
173 0x80000011,
174 0x80000012,
175 0x80000013,
176 0x80000014,
177 0x80000020,
178 0x80000021,
179 0x80000022,
180 0x80000023,
181 0x80000024,
182 0x80000100,
183 0x80000101,
184 0x80000102,
185 0x80000103,
186 0x80000104,
187 0x80000110,
188 0x80000111,
189 0x80000112,
190 0x80000113,
191 0x80000114,
192 0x80000120,
193 0x80000121,
194 0x80000122,
195 0x80000123,
196 0x80000124,
197 };
198
199 static PLCHAR_VECTOR family[] = {
200 "sans-serif",
201 "serif",
202 "monospace",
203 "script",
204 "symbol",
205 };
206 static PLCHAR_VECTOR style[] = {
207 "upright",
208 "italic",
209 "oblique",
210 };
211 static PLCHAR_VECTOR weight[] = {
212 "medium",
213 "bold",
214 };
215
216 int
main(int argc,char * argv[])217 main( int argc, char *argv[] )
218 {
219 PLFLT xmin, xmax, ymin, ymax, ycharacter_scale, yoffset;
220 PLFLT chardef, charht, deltax, deltay, x, y;
221 int i, j, page, length, slice;
222 char cmdString[20];
223
224 PLUNICODE fci_old;
225 PLINT ifamily, istyle, iweight;
226
227
228 plparseopts( &argc, argv, PL_PARSE_FULL );
229
230 plinit();
231
232 for ( page = 0; page < 11; page++ )
233 {
234 pladv( 0 );
235
236 // Set up viewport and window
237
238 plvpor( 0.02, 0.98, 0.02, 0.90 );
239 plwind( 0.0, 1.0, 0.0, 1.0 );
240 plgspa( &xmin, &xmax, &ymin, &ymax );
241 plschr( 0., 0.8 );
242 ycharacter_scale = ( 1.0 - 0.0 ) / ( ymax - ymin );
243
244 // Factor should be 0.5, but heuristically it turns out to be larger.
245 plgchr( &chardef, &charht );
246 yoffset = 1.0 * charht * ycharacter_scale;
247
248 // Draw the grid using plbox
249
250 plcol0( 2 );
251 deltax = 1.0 / ( (PLFLT) nxcells[page] );
252 deltay = 1.0 / ( (PLFLT) nycells[page] );
253 plbox( "bcg", deltax, 0, "bcg", deltay, 0 );
254 plcol0( 15 );
255 length = hi[page] - lo[page];
256 slice = 0;
257 for ( j = nycells[page] - 1; j >= -1; j-- )
258 {
259 y = ( 0.5 + j ) * deltay;
260 for ( i = 0; i < nxcells[page]; i++ )
261 {
262 x = ( 0.5 + i ) * deltax;
263 if ( slice < length )
264 {
265 if ( page == 0 )
266 {
267 sprintf( cmdString, "#%s", Greek[slice] );
268 }
269 else if ( ( page >= 1 ) && ( page <= 3 ) )
270 {
271 sprintf( cmdString, "##[0x%.4x]", Type1[offset[page] + slice] );
272 }
273 else if ( page >= 4 )
274 {
275 sprintf( cmdString, "##[0x%.4x]", lo[page] + slice );
276 }
277 plptex( x, y + yoffset, 1., 0., 0.5, &cmdString[1] );
278 plptex( x, y - yoffset, 1., 0., 0.5, cmdString );
279 }
280 slice += 1;
281 }
282 }
283
284 plschr( 0., 1.0 );
285 // Page title
286 plmtex( "t", 1.5, 0.5, 0.5, title[page] );
287 }
288
289 // Demonstrate methods of getting the current fonts
290 plgfci( &fci_old );
291 plgfont( &ifamily, &istyle, &iweight );
292 printf( "For example 23 prior to page 12 the FCI is 0x%x\n", fci_old );
293 printf( "For example 23 prior to page 12 the font family, style and weight are %s %s %s\n", family[ifamily], style[istyle], weight[iweight] );
294
295 for ( page = 11; page < 16; page++ )
296 {
297 PLFLT dy = 0.030;
298 int family_index, style_index, weight_index;
299 // Must be big enough to contain the prefix strings, the font-changing
300 // commands, and the "The quick brown..." string.
301 char string[200];
302
303 pladv( 0 );
304 plvpor( 0.02, 0.98, 0.02, 0.90 );
305 plwind( 0.0, 1.0, 0.0, 1.0 );
306 plsfci( 0 );
307 if ( page == 11 )
308 {
309 plmtex( "t", 1.5, 0.5, 0.5,
310 "#<0x10>PLplot Example 23 - "
311 "Set Font with plsfci" );
312 }
313 else if ( page == 12 )
314 {
315 plmtex( "t", 1.5, 0.5, 0.5,
316 "#<0x10>PLplot Example 23 - "
317 "Set Font with plsfont" );
318 }
319 else if ( page == 13 )
320 {
321 plmtex( "t", 1.5, 0.5, 0.5,
322 "#<0x10>PLplot Example 23 - "
323 "Set Font with ##<0x8nnnnnnn> construct" );
324 }
325 else if ( page == 14 )
326 {
327 plmtex( "t", 1.5, 0.5, 0.5,
328 "#<0x10>PLplot Example 23 - "
329 "Set Font with ##<0xmn> constructs" );
330 }
331 else if ( page == 15 )
332 {
333 plmtex( "t", 1.5, 0.5, 0.5,
334 "#<0x10>PLplot Example 23 - "
335 "Set Font with ##<FCI COMMAND STRING/> constructs" );
336 }
337 plschr( 0., 0.75 );
338 for ( i = 0; i < FCI_COMBINATIONS; i++ )
339 {
340 family_index = i % 5;
341 style_index = ( i / 5 ) % 3;
342 weight_index = ( ( i / 5 ) / 3 ) % 2;
343 if ( page == 11 )
344 {
345 plsfci( fci[i] );
346 sprintf( string,
347 "Page 12, %s, %s, %s: "
348 "The quick brown fox jumps over the lazy dog",
349 family[family_index],
350 style[style_index],
351 weight[weight_index] );
352 }
353 else if ( page == 12 )
354 {
355 plsfont( family_index, style_index, weight_index );
356 sprintf( string,
357 "Page 13, %s, %s, %s: "
358 "The quick brown fox jumps over the lazy dog",
359 family[family_index],
360 style[style_index],
361 weight[weight_index] );
362 }
363 else if ( page == 13 )
364 {
365 sprintf( string,
366 "Page 14, %s, %s, %s: "
367 "#<0x%x>"
368 "The quick brown fox jumps over the lazy dog",
369 family[family_index],
370 style[style_index],
371 weight[weight_index],
372 fci[i] );
373 }
374 else if ( page == 14 )
375 {
376 sprintf( string,
377 "Page 15, %s, %s, %s: "
378 "#<0x%1x0>#<0x%1x1>#<0x%1x2>"
379 "The quick brown fox jumps over the lazy dog",
380 family[family_index],
381 style[style_index],
382 weight[weight_index],
383 family_index,
384 style_index,
385 weight_index );
386 }
387 else if ( page == 15 )
388 {
389 sprintf( string,
390 "Page 16, %s, %s, %s: "
391 "#<%s/>#<%s/>#<%s/>"
392 "The quick brown fox jumps over the lazy dog",
393 family[family_index],
394 style[style_index],
395 weight[weight_index],
396 family[family_index],
397 style[style_index],
398 weight[weight_index] );
399 }
400 plptex( 0., 1. - ( i + 0.5 ) * dy, 1., 0., 0., string );
401 }
402
403 plschr( 0., 1.0 );
404 }
405
406 // Restore defaults
407 plcol0( 1 );
408
409 plend();
410 exit( 0 );
411 }
412