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