Root/nanonote-files/example-files/data/Examples/lua-plplot-examples/x23.lua

1--[[ $Id: x23.lua 9533 2009-02-16 22:18:37Z smekal $
2
3    Displays Greek letters and mathematically interesting Unicode ranges
4    
5    Copyright (C) 2009 Werner Smekal
6
7    This file is part of PLplot.
8
9    PLplot is free software you can redistribute it and/or modify
10    it under the terms of the GNU General Library Public License as published
11    by the Free Software Foundation either version 2 of the License, or
12    (at your option) any later version.
13
14    PLplot is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17    GNU Library General Public License for more details.
18
19    You should have received a copy of the GNU Library General Public License
20    along with PLplot if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27----------------------------------------------------------------------------
28-- main
29--
30-- Displays Greek letters and mathematically interesting Unicode ranges
31----------------------------------------------------------------------------
32
33Greek = {
34  "#gA","#gB","#gG","#gD","#gE","#gZ","#gY","#gH","#gI","#gK","#gL","#gM",
35  "#gN","#gC","#gO","#gP","#gR","#gS","#gT","#gU","#gF","#gX","#gQ","#gW",
36  "#ga","#gb","#gg","#gd","#ge","#gz","#gy","#gh","#gi","#gk","#gl","#gm",
37  "#gn","#gc","#go","#gp","#gr","#gs","#gt","#gu","#gf","#gx","#gq","#gw"
38}
39
40Type1 = {
41  32, 33, 35, 37, 38,
42  40, 41, 43, 44, 46,
43  47, 48, 49, 50, 51,
44  52, 53, 54, 55, 56,
45  57, 58, 59, 60, 61,
46  62, 63, 91, 93, 95,
47  123, 124, 125, 169, 172,
48  174, 176, 177, 215, 247,
49  402, 913, 914, 915, 916,
50  917, 918, 919, 920, 921,
51  922, 923, 924, 925, 926,
52  927, 928, 929, 931, 932,
53  933, 934, 935, 936, 937,
54  945, 946, 947, 948, 949,
55  950, 951, 952, 953, 954,
56  955, 956, 957, 958, 959,
57  960, 961, 962, 963, 964,
58  965, 966, 967, 968, 969,
59  977, 978, 981, 982, 8226,
60  8230, 8242, 8243, 8254, 8260,
61  8465, 8472, 8476, 8482, 8486,
62  8501, 8592, 8593, 8594, 8595,
63  8596, 8629, 8656, 8657, 8658,
64  8659, 8660, 8704, 8706, 8707,
65  8709, 8710, 8711, 8712, 8713,
66  8715, 8719, 8721, 8722, 8725,
67  8727, 8730, 8733, 8734, 8736,
68  8743, 8744, 8745, 8746, 8747,
69  8756, 8764, 8773, 8776, 8800,
70  8801, 8804, 8805, 8834, 8835,
71  8836, 8838, 8839, 8853, 8855,
72  8869, 8901, 8992, 8993, 9001,
73  9002, 9674, 9824, 9827, 9829,
74  9830
75}
76
77title = {
78  "#<0x10>PLplot Example 23 - Greek Letters",
79  "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (a)",
80  "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (b)",
81  "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (c)",
82  "#<0x10>PLplot Example 23 - Number Forms Unicode Block",
83  "#<0x10>PLplot Example 23 - Arrows Unicode Block (a)",
84  "#<0x10>PLplot Example 23 - Arrows Unicode Block (b)",
85  "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (a)",
86  "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (b)",
87  "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (c)",
88  "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (d)"
89}
90
91lo = {
92  0,
93  0,
94  64,
95  128,
96  8531,
97  8592,
98  8656,
99  8704,
100  8768,
101  8832,
102  8896
103}
104
105hi = {
106  48,
107  64,
108  128,
109  166,
110  8580,
111  8656,
112  8704,
113  8768,
114  8832,
115  8896,
116  8960
117}
118
119nxcells = {
120  12,
121  8,
122  8,
123  8,
124  8,
125  8,
126  8,
127  8,
128  8,
129  8,
130  8
131}
132
133nycells = {
134  8,
135  8,
136  8,
137  8,
138  8,
139  8,
140  8,
141  8,
142  8,
143  8,
144  8
145}
146
147-- non-zero values Must be consistent with nxcells and nycells.
148offset = {
149  0,
150  0,
151  64,
152  128,
153  0,
154  0,
155  0,
156  0,
157  0,
158  0,
159  0
160}
161
162-- 30 possible FCI values.
163FCI_COMBINATIONS = 30
164fci = {
165  2147483648,
166  2147483649,
167  2147483650,
168  2147483651,
169  2147483652,
170  2147483664,
171  2147483665,
172  2147483666,
173  2147483667,
174  2147483668,
175  2147483680,
176  2147483681,
177  2147483682,
178  2147483683,
179  2147483684,
180  2147483904,
181  2147483905,
182  2147483906,
183  2147483907,
184  2147483908,
185  2147483920,
186  2147483921,
187  2147483922,
188  2147483923,
189  2147483924,
190  2147483936,
191  2147483937,
192  2147483938,
193  2147483939,
194  2147483940
195}
196
197family = {
198  "sans-serif",
199  "serif",
200  "monospace",
201  "script",
202  "symbol"
203}
204
205style = {
206  "upright",
207  "italic",
208  "oblique"
209}
210
211weight = {
212  "medium",
213  "bold"
214}
215
216-- Parse and process command line arguments
217pl.parseopts(arg, pl.PL_PARSE_FULL)
218
219-- Initialize plplot
220pl.init()
221
222for page=1, 11 do
223  pl.adv(0)
224
225  -- Set up viewport and window
226  pl.vpor(0.02, 0.98, 0.02, 0.90)
227  pl.wind(0, 1, 0, 1)
228  xmin, xmax, ymin, ymax = pl.gspa()
229  pl.schr(0, 0.8)
230  ycharacter_scale = (1-0)/(ymax-ymin)
231
232  -- Factor should be 0.5, but heuristically it turns out to be larger.
233  chardef, charht = pl.gchr()
234  yoffset = charht*ycharacter_scale
235
236  -- Draw the grid using plbox
237  pl.col0(2)
238  deltax = 1.0/nxcells[page]
239  deltay = 1.0/nycells[page]
240  pl.box("bcg", deltax, 0, "bcg", deltay, 0)
241  pl.col0(15)
242  length=hi[page]-lo[page]
243  slice = 1
244  
245  for j=nycells[page]-1, -1, -1 do
246    y = (0.5+j)*deltay
247    for i=1, nxcells[page] do
248      x = (i-0.5)*deltax
249      if slice<=length then
250        if page==1 then
251          cmdString = "#" .. Greek[slice]
252        elseif (page>=2) and (page<=4) then
253          cmdString = string.format("##[0x%.4x]", Type1[offset[page]+slice])
254        elseif page>4 then
255          cmdString = string.format("##[0x%.4x]", lo[page]+slice-1)
256        end
257        pl.ptex(x, y+yoffset, 1, 0, 0.5, string.sub(cmdString,2))
258        pl.ptex(x, y-yoffset, 1, 0, 0.5, cmdString)
259      end
260      slice = slice + 1
261    end
262  end
263
264  pl.schr(0, 1)
265  
266  -- Page title
267  pl.mtex("t", 1.5, 0.5, 0.5, title[page])
268end
269
270-- Demonstrate methods of getting the current fonts
271fci_old = pl.gfci()
272ifamily, istyle, iweight = pl.gfont()
273print(string.format("For example 23 prior to page 12 the FCI is 0x%x", fci_old))
274print(string.format("For example 23 prior to page 12 the font family, style and weight are %s %s %s",
275                    family[ifamily+1], style[istyle+1], weight[iweight+1]))
276
277for page=12, 16 do
278  dy = 0.030
279
280  pl.adv(0)
281  pl.vpor(0.02, 0.98, 0.02, 0.90)
282  pl.wind(0, 1, 0, 1)
283  pl.sfci(0)
284  
285  if page==12 then
286    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with plsfci")
287  elseif page==13 then
288    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with plsfont")
289  elseif page==14 then
290    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with ##<0x8nnnnnnn> construct")
291  elseif page==15 then
292    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with ##<0xmn> constructs")
293  elseif page==16 then
294    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with ##<FCI COMMAND STRING/> constructs")
295  end
296  
297  pl.schr(0, 0.75)
298  for i=1, FCI_COMBINATIONS do
299    family_index = math.mod(i-1, 5)+1
300    style_index = math.mod(math.floor((i-1)/5), 3)+1
301    weight_index = math.mod(math.floor((i-1)/5/3), 2)+1
302    if page==12 then
303      pl.sfci(fci[i])
304      str = string.format("Page 12, %s, %s, %s: The quick brown fox jumps over the lazy dog",
305                          family[family_index], style[style_index], weight[weight_index])
306    elseif page==13 then
307      pl.sfont(family_index-1, style_index-1, weight_index-1)
308      str = string.format("Page 13, %s, %s, %s: The quick brown fox jumps over the lazy dog",
309                          family[family_index], style[style_index], weight[weight_index])
310    elseif page==14 then
311      str = string.format("Page 14, %s, %s, %s: #<0x%x>The quick brown fox jumps over the lazy dog",
312                          family[family_index], style[style_index], weight[weight_index], fci[i])
313    elseif page==15 then
314      str = string.format("Page 15, %s, %s, %s: #<0x%1x0>#<0x%1x1>#<0x%1x2>The quick brown fox jumps over the lazy dog",
315                          family[family_index], style[style_index], weight[weight_index],
316                          family_index-1, style_index-1, weight_index-1)
317    elseif page==16 then
318      str = string.format("Page 16, %s, %s, %s: #<%s/>#<%s/>#<%s/>The quick brown fox jumps over the lazy dog",
319                          family[family_index], style[style_index], weight[weight_index],
320                          family[family_index], style[style_index], weight[weight_index])
321    end
322    pl.ptex(0, 1-(i-0.5)*dy, 1, 0, 0, str)
323  end
324
325  pl.schr(0, 1)
326end
327
328-- Restore defaults
329pl.col0(1)
330
331pl.plend()
332

Archive Download this file



interactive