11ae29591efbb29492ce05378909ccf4028d7c1eeBehdad Esfahbodfrom __future__ import print_function, division, absolute_import
221bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbodfrom fontTools.misc.py23 import *
321bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod
470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod_accessstrings = {0: "", 1: "readonly", 2: "executeonly", 3: "noaccess"}
570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_object:
870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	literal = 1
1070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	access = 0
1170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	value = None
1270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
1370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __init__(self, value):
1470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.value = value
1570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.type = self.__class__.__name__[3:] + "type"
1670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
1770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __repr__(self):
1870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return "<%s %s>" % (self.__class__.__name__[3:], repr(self.value))
1970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
2070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
2170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_operator(ps_object):
2270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
2370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	literal = 0
2470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
2570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __init__(self, name, function):
2670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.name = name
2770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.function = function
2870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.type = self.__class__.__name__[3:] + "type"
2970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __repr__(self):
3070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return "<operator %s>" % self.name
3170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
3270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_procedure(ps_object):
3370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	literal = 0
3470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __repr__(self):
3570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return "<procedure>"
3670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
3770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		psstring = '{'
3870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for i in range(len(self.value)):
3970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			if i:
4070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				psstring = psstring + ' ' + str(self.value[i])
4170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			else:
4270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				psstring = psstring + str(self.value[i])
4370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return psstring + '}'
4470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
4570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_name(ps_object):
4670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	literal = 0
4770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
4870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if self.literal:
4970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			return '/' + self.value
5070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		else:
5170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			return self.value
5270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
5370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_literal(ps_object):
5470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
5570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return '/' + self.value
5670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
5770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_array(ps_object):
5870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
5970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		psstring = '['
6070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for i in range(len(self.value)):
6170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			item = self.value[i]
6270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			access = _accessstrings[item.access]
6370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			if access:
6470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				access = ' ' + access
6570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			if i:
6670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				psstring = psstring + ' ' + str(item) + access
6770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			else:
6870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				psstring = psstring + str(item) + access
6970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return psstring + ']'
7070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __repr__(self):
7170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return "<array>"
7270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
7370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod_type1_pre_eexec_order = [
7470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"FontInfo",
7570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"FontName",
7670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"Encoding",
7770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"PaintType",
7870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"FontType",
7970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"FontMatrix",
8070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"FontBBox",
8170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"UniqueID",
8270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"Metrics",
8370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"StrokeWidth"
8470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	]
8570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
8670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod_type1_fontinfo_order = [
8770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"version",
8870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"Notice",
8970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"FullName",
9070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"FamilyName",
9170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"Weight",
9270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"ItalicAngle",
9370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"isFixedPitch",
9470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"UnderlinePosition",
9570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"UnderlineThickness"
9670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	]
9770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
9870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod_type1_post_eexec_order = [
9970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"Private",
10070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"CharStrings",
10170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		"FID"
10270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	]
10370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
10470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahboddef _type1_item_repr(key, value):
10570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	psstring = ""
10670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	access = _accessstrings[value.access]
10770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	if access:
10870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		access = access + ' '
10970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	if key == 'CharStrings':
11070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		psstring = psstring + "/%s %s def\n" % (key, _type1_CharString_repr(value.value))
11170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	elif key == 'Encoding':
11270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		psstring = psstring + _type1_Encoding_repr(value, access)
11370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	else:
11470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		psstring = psstring + "/%s %s %sdef\n" % (str(key), str(value), access)
11570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	return psstring
11670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
11770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahboddef _type1_Encoding_repr(encoding, access):
11870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	encoding = encoding.value
11970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	psstring = "/Encoding 256 array\n0 1 255 {1 index exch /.notdef put} for\n"
12070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	for i in range(256):
12170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		name = encoding[i].value
12221bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		if name != '.notdef':
12370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			psstring = psstring + "dup %d /%s put\n" % (i, name)
12470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	return psstring + access + "def\n"
12570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
12670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahboddef _type1_CharString_repr(charstrings):
12721bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod	items = sorted(charstrings.items())
12870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	return 'xxx'
12970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
13070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_font(ps_object):
13170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
13270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		psstring = "%d dict dup begin\n" % len(self.value)
13370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for key in _type1_pre_eexec_order:
13470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			try:
13570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				value = self.value[key]
13670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			except KeyError:
13770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				pass
13870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			else:
13970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				psstring = psstring + _type1_item_repr(key, value)
14021bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		items = sorted(self.value.items())
14170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for key, value in items:
14270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			if key not in _type1_pre_eexec_order + _type1_post_eexec_order:
14370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				psstring = psstring + _type1_item_repr(key, value)
14470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		psstring = psstring + "currentdict end\ncurrentfile eexec\ndup "
14570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for key in _type1_post_eexec_order:
14670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			try:
14770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				value = self.value[key]
14870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			except KeyError:
14970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				pass
15070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			else:
15170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				psstring = psstring + _type1_item_repr(key, value)
15270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return psstring + 'dup/FontName get exch definefont pop\nmark currentfile closefile\n' + \
15370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				8 * (64 * '0' + '\n') + 'cleartomark' + '\n'
15470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __repr__(self):
15570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return '<font>'
15670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
15770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_file(ps_object):
15870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	pass
15970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
16070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_dict(ps_object):
16170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
16270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		psstring = "%d dict dup begin\n" % len(self.value)
16321bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		items = sorted(self.value.items())
16470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for key, value in items:
16570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			access = _accessstrings[value.access]
16670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			if access:
16770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				access = access + ' '
16870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			psstring = psstring + "/%s %s %sdef\n" % (str(key), str(value), access)
16970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return psstring + 'end '
17070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __repr__(self):
17170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		return "<dict>"
17270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
17370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_mark(ps_object):
17470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __init__(self):
17570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.value = 'mark'
17670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.type = self.__class__.__name__[3:] + "type"
17770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
17870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_procmark(ps_object):
17970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __init__(self):
18070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.value = 'procmark'
18170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.type = self.__class__.__name__[3:] + "type"
18270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
18370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_null(ps_object):
18470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __init__(self):
18570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.type = self.__class__.__name__[3:] + "type"
18670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
18770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_boolean(ps_object):
18870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
18970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if self.value:
19070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			return 'true'
19170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		else:
19270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			return 'false'
19370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
19470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_string(ps_object):
19570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
19621bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		return "(%s)" % repr(self.value)[1:-1]
19770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
19870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_integer(ps_object):
19970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
20021bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		return repr(self.value)
20170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
20270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass ps_real(ps_object):
20370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def __str__(self):
20421bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		return repr(self.value)
20570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
20670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
20770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodclass PSOperators:
20870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
20970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_def(self):
210153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		obj = self.pop()
21170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		name = self.pop()
212153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		self.dictstack[-1][name.value] = obj
21370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
21470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_bind(self):
21570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		proc = self.pop('proceduretype')
21670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.proc_bind(proc)
21770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(proc)
21870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
21970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def proc_bind(self, proc):
22070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for i in range(len(proc.value)):
22170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			item = proc.value[i]
22270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			if item.type == 'proceduretype':
22370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.proc_bind(item)
22470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			else:
22570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				if not item.literal:
22670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod					try:
227153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod						obj = self.resolve_name(item.value)
22870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod					except:
22970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod						pass
23070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod					else:
231153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod						if obj.type == 'operatortype':
232153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod							proc.value[i] = obj
23370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
23470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_exch(self):
23570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if len(self.stack) < 2:
23621bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod			raise RuntimeError('stack underflow')
23770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj1 = self.pop()
23870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj2 = self.pop()
23970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(obj1)
24070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(obj2)
24170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
24270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_dup(self):
24370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if not self.stack:
24421bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod			raise RuntimeError('stack underflow')
24570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(self.stack[-1])
24670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
24770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_exec(self):
248153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		obj = self.pop()
249153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		if obj.type == 'proceduretype':
250153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod			self.call_procedure(obj)
25170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		else:
252153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod			self.handle_object(obj)
25370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
25470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_count(self):
25570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_integer(len(self.stack)))
25670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
25770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_eq(self):
25870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		any1 = self.pop()
25970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		any2 = self.pop()
26070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_boolean(any1.value == any2.value))
26170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
26270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_ne(self):
26370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		any1 = self.pop()
26470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		any2 = self.pop()
26521bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		self.push(ps_boolean(any1.value != any2.value))
26670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
26770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_cvx(self):
26870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj = self.pop()
26970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj.literal = 0
27070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(obj)
27170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
27270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_matrix(self):
27370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		matrix = [ps_real(1.0), ps_integer(0), ps_integer(0), ps_real(1.0), ps_integer(0), ps_integer(0)]
27470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_array(matrix))
27570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
27670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_string(self):
27770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		num = self.pop('integertype').value
27870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_string('\0' * num))
27970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
28070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_type(self):
28170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj = self.pop()
28270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_string(obj.type))
28370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
28470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_store(self):
28570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		value = self.pop()
28670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		key = self.pop()
28770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		name = key.value
28870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for i in range(len(self.dictstack)-1, -1, -1):
28921bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod			if name in self.dictstack[i]:
29070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.dictstack[i][name] = value
29170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				break
29270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.dictstack[-1][name] = value
29370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
29470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_where(self):
29570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		name = self.pop()
29670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		# XXX
29770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_boolean(0))
29870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
29970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_systemdict(self):
30070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_dict(self.dictstack[0]))
30170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
30270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_userdict(self):
30370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_dict(self.dictstack[1]))
30470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
30570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_currentdict(self):
30670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_dict(self.dictstack[-1]))
30770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
30870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_currentfile(self):
30970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_file(self.tokenizer))
31070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
31170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_eexec(self):
312153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		f = self.pop('filetype').value
313153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		f.starteexec()
31470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
31570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_closefile(self):
316153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		f = self.pop('filetype').value
317153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		f.skipwhite()
318153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		f.stopeexec()
31970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
32070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_cleartomark(self):
32170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj = self.pop()
32221bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		while obj != self.mark:
32370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj = self.pop()
32470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
32570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_readstring(self,
32670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				ps_boolean = ps_boolean,
32770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				len = len):
32870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		s = self.pop('stringtype')
32970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		oldstr = s.value
330153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		f = self.pop('filetype')
33170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		#pad = file.value.read(1)
33270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		# for StringIO, this is faster
333153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		f.value.pos = f.value.pos + 1
334153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		newstr = f.value.read(len(oldstr))
33570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		s.value = newstr
33670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(s)
33770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(ps_boolean(len(oldstr) == len(newstr)))
33870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
33970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_known(self):
34070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		key = self.pop()
341153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		d = self.pop('dicttype', 'fonttype')
342153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		self.push(ps_boolean(key.value in d.value))
34370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
34470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_if(self):
34570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		proc = self.pop('proceduretype')
346153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		if self.pop('booleantype').value:
34770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.call_procedure(proc)
34870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
34970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_ifelse(self):
35070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		proc2 = self.pop('proceduretype')
35170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		proc1 = self.pop('proceduretype')
352153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		if self.pop('booleantype').value:
35370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.call_procedure(proc1)
35470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		else:
35570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.call_procedure(proc2)
35670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
35770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_readonly(self):
35870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj = self.pop()
35970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if obj.access < 1:
36070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj.access = 1
36170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(obj)
36270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
36370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_executeonly(self):
36470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj = self.pop()
36570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if obj.access < 2:
36670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj.access = 2
36770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(obj)
36870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
36970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_noaccess(self):
37070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj = self.pop()
37170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if obj.access < 3:
37270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj.access = 3
37370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(obj)
37470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
37570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_not(self):
37670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj = self.pop('booleantype', 'integertype')
37770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if obj.type == 'booleantype':
37870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(ps_boolean(not obj.value))
37970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		else:
38070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(ps_integer(~obj.value))
38170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
38270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_print(self):
38370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		str = self.pop('stringtype')
38421bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod		print('PS output --->', str.value)
38570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
38670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_anchorsearch(self):
38770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		seek = self.pop('stringtype')
38870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		s = self.pop('stringtype')
38970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		seeklen = len(seek.value)
39070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if s.value[:seeklen] == seek.value:
39170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(ps_string(s.value[seeklen:]))
39270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(seek)
39370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(ps_boolean(1))
39470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		else:
39570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(s)
39670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(ps_boolean(0))
39770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
39870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_array(self):
39970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		num = self.pop('integertype')
40070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		array = ps_array([None] * num.value)
40170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(array)
40270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
40370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_astore(self):
40470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		array = self.pop('arraytype')
40570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		for i in range(len(array.value)-1, -1, -1):
40670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			array.value[i] = self.pop()
40770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(array)
40870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
40970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_load(self):
41070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		name = self.pop()
411153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		self.push(self.resolve_name(name.value))
41270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
41370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_put(self):
41470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj1 = self.pop()
41570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj2 = self.pop()
41670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj3 = self.pop('arraytype', 'dicttype', 'stringtype', 'proceduretype')
41770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		tp = obj3.type
41870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if tp == 'arraytype' or tp == 'proceduretype':
41970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj3.value[obj2.value] = obj1
42070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		elif tp == 'dicttype':
42170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj3.value[obj2.value] = obj1
42270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		elif tp == 'stringtype':
42370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			index = obj2.value
42470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj3.value = obj3.value[:index] + chr(obj1.value) + obj3.value[index+1:]
42570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
42670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_get(self):
42770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj1 = self.pop()
42870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if obj1.value == "Encoding":
42970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			pass
43070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj2 = self.pop('arraytype', 'dicttype', 'stringtype', 'proceduretype', 'fonttype')
43170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		tp = obj2.type
43270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if tp in ('arraytype', 'proceduretype'):
43370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(obj2.value[obj1.value])
43470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		elif tp in ('dicttype', 'fonttype'):
43570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(obj2.value[obj1.value])
43670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		elif tp == 'stringtype':
43770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(ps_integer(ord(obj2.value[obj1.value])))
43870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		else:
439153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod			assert False, "shouldn't get here"
44070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
44170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_getinterval(self):
44270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj1 = self.pop('integertype')
44370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj2 = self.pop('integertype')
44470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj3 = self.pop('arraytype', 'stringtype')
44570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		tp = obj3.type
44670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if tp == 'arraytype':
44770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(ps_array(obj3.value[obj2.value:obj2.value + obj1.value]))
44870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		elif tp == 'stringtype':
44970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.push(ps_string(obj3.value[obj2.value:obj2.value + obj1.value]))
45070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
45170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_putinterval(self):
45270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj1 = self.pop('arraytype', 'stringtype')
45370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj2 = self.pop('integertype')
45470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj3 = self.pop('arraytype', 'stringtype')
45570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		tp = obj3.type
45670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if tp == 'arraytype':
45770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj3.value[obj2.value:obj2.value + len(obj1.value)] = obj1.value
45870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		elif tp == 'stringtype':
45970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			newstr = obj3.value[:obj2.value]
46070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			newstr = newstr + obj1.value
46170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			newstr = newstr + obj3.value[obj2.value + len(obj1.value):]
46270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			obj3.value = newstr
46370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
46470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_cvn(self):
465153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		self.push(ps_name(self.pop('stringtype').value))
46670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
46770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_index(self):
46870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		n = self.pop('integertype').value
46970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if n < 0:
47021bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod			raise RuntimeError('index may not be negative')
47170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(self.stack[-1-n])
47270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
47370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_for(self):
47470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		proc = self.pop('proceduretype')
47570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		limit = self.pop('integertype', 'realtype').value
47670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		increment = self.pop('integertype', 'realtype').value
47770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		i = self.pop('integertype', 'realtype').value
47870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		while 1:
47970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			if increment > 0:
48070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				if i > limit:
48170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod					break
48270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			else:
48370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				if i < limit:
48470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod					break
48570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			if type(i) == type(0.0):
48670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.push(ps_real(i))
48770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			else:
48870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.push(ps_integer(i))
48970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			self.call_procedure(proc)
49070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			i = i + increment
49170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
49270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_forall(self):
49370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		proc = self.pop('proceduretype')
49470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		obj = self.pop('arraytype', 'stringtype', 'dicttype')
49570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		tp = obj.type
49670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if tp == 'arraytype':
49770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			for item in obj.value:
49870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.push(item)
49970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.call_procedure(proc)
50070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		elif tp == 'stringtype':
50170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			for item in obj.value:
50270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.push(ps_integer(ord(item)))
50370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.call_procedure(proc)
50470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		elif tp == 'dicttype':
50570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			for key, value in obj.value.items():
50670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.push(ps_name(key))
50770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.push(value)
50870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod				self.call_procedure(proc)
50970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
51070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_definefont(self):
51170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		font = self.pop('dicttype')
51270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		name = self.pop()
51370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		font = ps_font(font.value)
51470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.dictstack[0]['FontDirectory'].value[name.value] = font
51570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(font)
51670c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
51770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_findfont(self):
51870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		name = self.pop()
51970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		font = self.dictstack[0]['FontDirectory'].value[name.value]
52070c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.push(font)
52170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
52270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_pop(self):
52370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		self.pop()
52470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
52570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_dict(self):
526153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		self.pop('integertype')
527153ec402094adbea673e914385b87f1d99191d0bBehdad Esfahbod		self.push(ps_dict({}))
52870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
52970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_begin(self):
5308851bcfd3264aed242f3228d2afb88cc9db3600dKhaled Hosny		self.dictstack.append(self.pop('dicttype').value)
53170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
53270c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod	def ps_end(self):
53370c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		if len(self.dictstack) > 2:
53470c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod			del self.dictstack[-1]
53570c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod		else:
53621bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbod			raise RuntimeError('dictstack underflow')
53770c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
53870c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodnotdef = '.notdef'
53970c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbodfrom fontTools.encodings.StandardEncoding import StandardEncoding
54021bae0e3db763c401c06033f0bdb773d1c6a966aBehdad Esfahbodps_StandardEncoding = list(map(ps_name, StandardEncoding))
54170c46de63510be06fe3b136b34a96efef1e05c8dBehdad Esfahbod
542