File: write simple GlyphData.py

package info (click to toggle)
glyphsinfo 0~git20171119-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,280 kB
  • sloc: xml: 57,614; python: 166; makefile: 2
file content (82 lines) | stat: -rw-r--r-- 2,217 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#MenuTitle: write simple GlyphData
# -*- coding: utf-8 -*-

infos = GSGlyphsInfo.sharedManager().glyphInfos()
# or:
# infos = GSGlyphsInfo.alloc().initWithLocalFile_(NSURL.fileURLWithPath_("path to custom GlyphData.xml file"))

f = open("GlyphData.xml", "w")
fIdeo = open("GlyphData_Ideographs.xml", "w")

def writeHeader(f):
	f.write('<?xml version="1.0" encoding="UTF-8" ?>\n\
<!DOCTYPE glyphData [\n\
<!ELEMENT glyphData (glyph)+>\n\
<!ELEMENT glyph EMPTY>\n\
<!ATTLIST glyph\n\
	unicode			CDATA		#IMPLIED\n\
	name			CDATA		#REQUIRED\n\
	category		CDATA		#REQUIRED\n\
	subCategory		CDATA		#IMPLIED\n\
	script			CDATA		#IMPLIED\n\
	description		CDATA		#REQUIRED\n\
	production		CDATA		#IMPLIED\n\
	altNames		CDATA		#IMPLIED>\n\
]>\n\
<glyphData>\n')

writeHeader(f)
writeHeader(fIdeo)

disabledGlyphs = ["brevecomb_acutecomb",
				"brevecomb_gravecomb",
				"brevecomb_hookabovecomb",
				"brevecomb_tildecomb",
				"circumflexcomb_acutecomb",
				"circumflexcomb_gravecomb",
				"circumflexcomb_hookabovecomb", 
				"circumflexcomb_tildecomb",
				"idotaccent.sc", 
				"i.sc",
				]
forcedGlyphs = ["ringcenter-ar"]

def printInfo(info):
	string = '	<glyph '
	if info.unicode:
		string += 'unicode="' + info.unicode + '" '
	string += 'name="' + info.name + '" '
# 	if info.sortName:
# 		string += 'sortName="' + info.sortName + '" '
	if info.category:
		string += 'category="' + info.category + '" '
	if info.subCategory and info.subCategory != "Other":
		string += 'subCategory="' + info.subCategory + '" '
	if info.script:
		string += 'script="' + info.script + '" '
	if info.productionName:
		string += 'production="' + info.productionName + '" '
	if info.altNames:
		string += 'altNames="' + ", ".join(info.altNames) + '" '
	if info.desc:
		string += 'description="' + info.desc + '" '
	
	string += '/>\n'
	return string
	
count = 0
for info in infos:
	if info.script == "han":
		fIdeo.write(printInfo(info))
	elif (info.name in disabledGlyphs or (info.script == "arabic" and info.unicode is None)) and (info.name not in forcedGlyphs):
		continue
	else:
		f.write(printInfo(info))
	count += 1

print "Written %d entries" % count
f.write('</glyphData>\n')
fIdeo.write('</glyphData>\n')

f.close()
fIdeo.close()