1#  Copyright (C) 2005-2017 Alan W. Irwin
2
3#  Displays Greek letters and mathematically interesting Unicode ranges.
4#
5#  This file is part of PLplot.
6#
7#  PLplot is free software; you can redistribute it and/or modify
8#  it under the terms of the GNU Library General Public License as published
9#  by the Free Software Foundation; either version 2 of the License, or
10#  (at your option) any later version.
11#
12#  PLplot is distributed in the hope that it will be useful,
13#  but WITHOUT ANY WARRANTY; without even the implied warranty of
14#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#  GNU Library General Public License for more details.
16#
17#  You should have received a copy of the GNU Library General Public License
18#  along with PLplot; if not, write to the Free Software
19#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20#
21from numpy import *
22
23# main
24#
25# Displays Greek letters and mathematically interesting Unicode ranges
26
27Greek = (
28"#gA","#gB","#gG","#gD","#gE","#gZ","#gY","#gH","#gI","#gK","#gL","#gM",
29"#gN","#gC","#gO","#gP","#gR","#gS","#gT","#gU","#gF","#gX","#gQ","#gW",
30"#ga","#gb","#gg","#gd","#ge","#gz","#gy","#gh","#gi","#gk","#gl","#gm",
31"#gn","#gc","#go","#gp","#gr","#gs","#gt","#gu","#gf","#gx","#gq","#gw",
32)
33
34Type1 = (
35"0x0020","0x0021","0x0023","0x0025","0x0026",
36"0x0028","0x0029","0x002b","0x002c","0x002e",
37"0x002f","0x0030","0x0031","0x0032","0x0033",
38"0x0034","0x0035","0x0036","0x0037","0x0038",
39"0x0039","0x003a","0x003b","0x003c","0x003d",
40"0x003e","0x003f","0x005b","0x005d","0x005f",
41"0x007b","0x007c","0x007d","0x00a9","0x00ac",
42"0x00ae","0x00b0","0x00b1","0x00d7","0x00f7",
43"0x0192","0x0391","0x0392","0x0393","0x0394",
44"0x0395","0x0396","0x0397","0x0398","0x0399",
45"0x039a","0x039b","0x039c","0x039d","0x039e",
46"0x039f","0x03a0","0x03a1","0x03a3","0x03a4",
47"0x03a5","0x03a6","0x03a7","0x03a8","0x03a9",
48"0x03b1","0x03b2","0x03b3","0x03b4","0x03b5",
49"0x03b6","0x03b7","0x03b8","0x03b9","0x03ba",
50"0x03bb","0x03bc","0x03bd","0x03be","0x03bf",
51"0x03c0","0x03c1","0x03c2","0x03c3","0x03c4",
52"0x03c5","0x03c6","0x03c7","0x03c8","0x03c9",
53"0x03d1","0x03d2","0x03d5","0x03d6","0x2022",
54"0x2026","0x2032","0x2033","0x203e","0x2044",
55"0x2111","0x2118","0x211c","0x2122","0x2126",
56"0x2135","0x2190","0x2191","0x2192","0x2193",
57"0x2194","0x21b5","0x21d0","0x21d1","0x21d2",
58"0x21d3","0x21d4","0x2200","0x2202","0x2203",
59"0x2205","0x2206","0x2207","0x2208","0x2209",
60"0x220b","0x220f","0x2211","0x2212","0x2215",
61"0x2217","0x221a","0x221d","0x221e","0x2220",
62"0x2227","0x2228","0x2229","0x222a","0x222b",
63"0x2234","0x223c","0x2245","0x2248","0x2260",
64"0x2261","0x2264","0x2265","0x2282","0x2283",
65"0x2284","0x2286","0x2287","0x2295","0x2297",
66"0x22a5","0x22c5","0x2320","0x2321","0x2329",
67"0x232a","0x25ca","0x2660","0x2663","0x2665",
68"0x2666",
69)
70
71title = (
72"#<0x10>PLplot Example 23 - Greek Letters",
73"#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (a)",
74"#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (b)",
75"#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (c)",
76"#<0x10>PLplot Example 23 - Number Forms Unicode Block",
77"#<0x10>PLplot Example 23 - Arrows Unicode Block (a)",
78"#<0x10>PLplot Example 23 - Arrows Unicode Block (b)",
79"#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (a)",
80"#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (b)",
81"#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (c)",
82"#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (d)",
83)
84
85lo = (
86"0x0",
87"0x0",
88"0x40",
89"0x80",
90"0x2153",
91"0x2190",
92"0x21d0",
93"0x2200",
94"0x2240",
95"0x2280",
96"0x22c0",
97)
98
99hi = (
100"0x30",
101"0x40",
102"0x80",
103"0xA6",
104"0x2184",
105"0x21d0",
106"0x2200",
107"0x2240",
108"0x2280",
109"0x22c0",
110"0x2300",
111)
112nxcells = (
11312,
1148,
1158,
1168,
1178,
1188,
1198,
1208,
1218,
1228,
1238,
124)
125
126nycells = (
1278,
1288,
1298,
1308,
1318,
1328,
1338,
1348,
1358,
1368,
1378,
138)
139
140# non-zero values Must be consistent with nxcells and nycells.
141offset = (
1420,
1430,
14464,
145128,
1460,
1470,
1480,
1490,
1500,
1510,
1520,
153)
154
155# 30 possible FCI values.
156
157fci = (
1580x80000000,
1590x80000001,
1600x80000002,
1610x80000003,
1620x80000004,
1630x80000010,
1640x80000011,
1650x80000012,
1660x80000013,
1670x80000014,
1680x80000020,
1690x80000021,
1700x80000022,
1710x80000023,
1720x80000024,
1730x80000100,
1740x80000101,
1750x80000102,
1760x80000103,
1770x80000104,
1780x80000110,
1790x80000111,
1800x80000112,
1810x80000113,
1820x80000114,
1830x80000120,
1840x80000121,
1850x80000122,
1860x80000123,
1870x80000124,
188)
189
190family = (
191"sans-serif",
192"serif",
193"monospace",
194"script",
195"symbol",
196)
197style = (
198"upright",
199"italic",
200  "oblique",
201)
202weight = (
203"medium",
204"bold",
205)
206
207def main(w):
208
209    for page in range(11):
210        w.pladv(0)
211
212        # Set up viewport and window
213
214        w.plvpor(0.02, 0.98, 0.02, 0.90)
215        w.plwind(0.0, 1.0, 0.0, 1.0)
216        mm = w.plgspa()
217        w.plschr(0., 0.8)
218        ycharacter_scale = (1.0 - 0.0)/(mm[3]-mm[2])
219        # Factor should be 0.5, but heuristically it turns out to be larger.
220        yoffset = 1.0*w.plgchr()[1]*ycharacter_scale
221
222        # Draw the grid using w.plbox
223
224        w.plcol0(2)
225        deltax = 1./float(nxcells[page])
226        deltay = 1./float(nycells[page])
227        w.plbox("bcg", deltax, 0, "bcg", deltay, 0)
228        w.plcol0(15)
229        length = int(hi[page],16) - int(lo[page],16)
230        slice = 0
231        for y in (0.5+arange(nycells[page]-1,-1,-1))*deltay:
232            for x in (0.5+arange(nxcells[page]))*deltax:
233                if slice < length:
234                    if page == 0:
235                        # Greek letters.
236                        CommandString = str(Greek[slice]);
237                    elif 1 <= page and page <= 3:
238                        # Unicode for Type 1 Symbol Glyphs.
239                        CommandString = "#[" + str(Type1\
240                        [offset[page]+slice]) + "]"
241                    elif page >= 4:
242                        CommandString = "#[" + hex(int(lo[page],16)+slice) + "]"
243                    w.plptex(x,y+yoffset,1.,0.,0.5, CommandString)
244                    w.plptex(x,y-yoffset,1.,0.,0.5, "#" +CommandString)
245                slice += 1
246
247        w.plschr(0., 1.0)
248        # Page title
249        w.plmtex("t", 1.5, 0.5, 0.5, title[page])
250
251    # Demonstrate methods of getting the current fonts
252
253    fci_old = w.plgfci()
254    font = w.plgfont()
255    ifamily = font[0]
256    istyle = font[1]
257    iweight = font[2]
258    print("For example 23 prior to page 12 the FCI is 0x%x" % (fci_old))
259    print("For example 23 prior to page 12 the font family, style and weight are %s %s %s" % (family[ifamily],style[istyle],weight[iweight]))
260
261    FCI_COMBINATIONS = 30
262    dy = 0.030
263    for page in range(11,16):
264        w.pladv(0)
265        w.plvpor(0.02, 0.98, 0.02, 0.90)
266        w.plwind(0.0, 1.0, 0.0, 1.0)
267        w.plsfci(0)
268        if(page == 11):
269            w.plmtex("t", 1.5, 0.5, 0.5,"#<0x10>PLplot Example 23 - Set Font with plsfci")
270        elif(page == 12):
271            w.plmtex("t", 1.5, 0.5, 0.5,"#<0x10>PLplot Example 23 - Set Font with plsfont")
272        elif(page == 13):
273            w.plmtex("t", 1.5, 0.5, 0.5,"#<0x10>PLplot Example 23 - Set Font with ##<0x8nnnnnnn> construct")
274        elif(page == 14):
275            w.plmtex("t", 1.5, 0.5, 0.5,"#<0x10>PLplot Example 23 - Set Font with ##<0xmn> constructs")
276        elif(page == 15):
277          w.plmtex("t", 1.5, 0.5, 0.5,"#<0x10>PLplot Example 23 - Set Font with ##<FCI COMMAND STRING/> constructs")
278        w.plschr(0., 0.75)
279        for i in range(0,FCI_COMBINATIONS):
280            family_index = i % 5
281            style_index = int((i/5) % 3)
282            weight_index = int(((i/5)/3) % 2)
283            if(page == 11):
284                w.plsfci(fci[i])
285                string = "Page 12, "+family[family_index]+", "+style[style_index]+", "+weight[weight_index]+":  "+"The quick brown fox jumps over the lazy dog"
286            elif(page == 12):
287                w.plsfont(family_index, style_index, weight_index)
288                string = "Page 13, "+family[family_index]+", "+style[style_index]+", "+weight[weight_index]+":  "+"The quick brown fox jumps over the lazy dog"
289            elif(page == 13):
290                string = "Page 14, "+family[family_index]+", "+style[style_index]+", "+weight[weight_index]+":  #<"+hex(fci[i]).rstrip('L')+">"+"The quick brown fox jumps over the lazy dog"
291            elif(page == 14):
292                string = "Page 15, "+family[family_index]+", "+style[style_index]+", "+weight[weight_index]+":  #<"+hex(family_index)+"0>"+"#<"+hex(style_index)+"1>"+"#<"+hex(weight_index)+"2>"+"The quick brown fox jumps over the lazy dog"
293            elif(page == 15):
294                string = "Page 16, "+family[family_index]+", "+style[style_index]+", "+weight[weight_index]+":  #<"+family[family_index]+"/>#<"+style[style_index]+"/>#<"+weight[weight_index]+"/>"+"The quick brown fox jumps over the lazy dog"
295            w.plptex (0., 1. - (i+0.5)*dy, 1., 0., 0., string)
296
297        w.plschr(0., 1.0)
298
299    # Restore defaults
300    w.plschr( 0.0, 1.0 )
301
302    # Would not do this ordinarily, but this is required to follow C example.
303    w.plcol0(1)
304
305    # Must be done independently because otherwise this changes output files
306    # and destroys agreement with C examples.
307    #w.plcol0(1)
308
309