~gryc-ueusp/lazyhandwriterfont/main

« back to all changes in this revision

Viewing changes to generate-template.py

  • Committer: Gryc Ueusp
  • Date: 2007-12-28 09:58:49 UTC
  • Revision ID: gryc.ueusp@gmail.com-20071228095849-a4v6i3knl5om0q9a
added an svg template generator

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
header = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 
2
<!-- Created with Inkscape (http://www.inkscape.org/) -->
 
3
<svg
 
4
   xmlns:svg="http://www.w3.org/2000/svg"
 
5
   xmlns="http://www.w3.org/2000/svg"
 
6
   version="1.0"
 
7
   width="744"
 
8
   height="1052"
 
9
   id="svg2"
 
10
   xml:space="preserve">
 
11
  <defs
 
12
     id="defs4" />
 
13
"""
 
14
 
 
15
footer = """
 
16
</svg>
 
17
"""
 
18
 
 
19
template = """
 
20
  <g
 
21
     transform="translate({xtransform},{ytransform})"
 
22
     id="{id}">
 
23
    <g
 
24
       style="fill:none;stroke:#000000;stroke-width:3"
 
25
       id="maingroup">
 
26
      <rect
 
27
         width="97"
 
28
         height="147"
 
29
         ry="0.6"
 
30
         x="1"
 
31
         y="904"
 
32
         id="boundingbox" />
 
33
      <path
 
34
         d="M 2.6554782,932.07281 L 97.293604,932.07281"
 
35
         id="headingborder" />
 
36
    </g>
 
37
    <text
 
38
       x="50"
 
39
       y="925"
 
40
       style="font-size:16px;text-align:center;text-anchor:middle;fill:#000000;font-family:DejaVu Sans"
 
41
       id="text"
 
42
       xml:space="preserve"><tspan
 
43
         x="49.998158"
 
44
         y="922.93359"
 
45
         id="text_">{text} {code}</tspan></text>
 
46
  </g>
 
47
"""
 
48
 
 
49
complete_svg = header
 
50
 
 
51
combiningdiacriticals = (0x0300, 0x036f)
 
52
punctuation = (0x2000, 0x206f)
 
53
greek = (0x0370, 0x03ff)
 
54
subsuperscripts = (0x2070, 0x20ff)
 
55
letterlike = (0x2100, 0x214f)
 
56
mathematical = (0x2200, 0x22ff)
 
57
cyrillic = (0x400, 0x04ff)
 
58
hebrew = (0x0590, 0x05ff)
 
59
katakana = (0x30A0, 0x30ff)
 
60
hiragana = (0x3040, 0x309f)
 
61
 
 
62
codeblocks = []
 
63
#codeblocks.append(combiningdiacriticals)
 
64
#codeblocks.append(punctuation)
 
65
#codeblocks.append(greek)
 
66
#codeblocks.append(subsuperscripts)
 
67
#codeblocks.append(letterlike)
 
68
#codeblocks.append(mathematical)
 
69
#codeblocks.append(cyrillic)
 
70
#codeblocks.append(hebrew)
 
71
#codeblocks.append(katakana)
 
72
codeblocks.append(hiragana)
 
73
 
 
74
col = 0
 
75
row = 0
 
76
page = 0
 
77
for codeblock in codeblocks:
 
78
        for glyph in range(codeblock[0], codeblock[1]):
 
79
                #print(unichr(glyph))
 
80
                #print(glyph)
 
81
                if col == 7:#New row
 
82
                        col = 0
 
83
                        row += 1
 
84
                if row == 7:#New page
 
85
                        page += 1
 
86
                        complete_svg += footer
 
87
                        f = open('page'+str(page)+'.svg', 'w')
 
88
                        f.write(complete_svg)
 
89
                        f.close()
 
90
                        complete_svg = header
 
91
                        row = 0
 
92
                entity = '&#'+str(glyph)+';'
 
93
                newglyph = template
 
94
                newglyph = newglyph.replace("{xtransform}",str(col*100))#these calculations arent right.
 
95
                newglyph = newglyph.replace("{ytransform}",str((row*150)*-1))#these calculations arent right.
 
96
                newglyph = newglyph.replace("{text}",entity)
 
97
                newglyph = newglyph.replace("{id}",str(glyph))
 
98
                newglyph = newglyph.replace("{code}",hex(glyph))
 
99
                complete_svg += newglyph
 
100
                #print('&#'+str(glyph)+';')
 
101
                col += 1
 
102
                #print col, row
 
103
 
 
104
 
 
105
#print complete_svg
 
 
b'\\ No newline at end of file'