예제 #1
0
def make_alphabet_array(fname, fd):
	d = collections.defaultdict(list)
	for g in parseSVG.parse_path(fname):
		for k, v in g.items():
			if v:
				d[k].extend(v)
	
	if fname.startswith("glyphs/") and fname.endswith(".svg"):
		glyph = fname[7:8]
	else:
		return False
	# Segment algin the glyphs and return the width, height of the glyph.
	width, height = segment_algin(d)
	print("Width and height of {} = ({}, {})".format(glyph, width, height))
	
	fd.write('''\t'{0}' => array(\n'''.format(glyph))
	fd.write('''\t\t'width' => {},\n'''.format(width))
	fd.write('''\t\t'height' => {},\n'''.format(height))
	fd.write('''\t\t'glyph_data' => array(\n'''.format(height))
	data = []
	j = 0
	for k, v in d.items():
		data = []
		j += 1
		fd.write('\t\t\t\'{0}\' => array(\n'.format(k))
		for i, shape in enumerate(v):
			fmt = ['array({0}), ', 'array({0})'][i == len(v)-1] # Last array elements don't have commas
			data.append(fmt.format(', '.join(['new Point(%d, %d)' % p for p in shape])))
		for i in range(0, len(data), 3):
			fd.write('\t\t\t\t{0}\n'.format(''.join(data[i:i+4])))
			end = ['\t\t\t),\n', '\t\t))\n'][j == len(d)]
		fd.write(end)
	fd.write('\t),\n')
예제 #2
0
	def glyph_from_svg(self, fname):
		try:
			import parseSVG
		except ImportError as e:
			print('[-] Couldnt find svg parser module')
			return False
		# Proud on that one. First time I use collections ;)
		d = collections.defaultdict(list)
		for g in parseSVG.parse_path(fname):
			for k, v in g.items():
				if v:
					d[k].extend(v)
		self.data = d
예제 #3
0
def write_switch_case(fname, fd):
	d = collections.defaultdict(list)
	for g in parseSVG.parse_path(fname):
		for k, v in g.items():
			if v:
				d[k].extend(v)
	glyph = fname.rstrip('.svg').lstrip('glyphs/')
	fd.write('''\tcase '{0}':\n\t\t$this->glyphdata = array(\n'''.format(glyph))
	data = []
	j = 0
	for k, v in d.items():
		data = []
		j += 1
		fd.write('\t\t\t\'{0}\' => array(\n'.format(k))
		for i, shape in enumerate(v):
			fmt = ['array({0}), ', 'array({0})'][i == len(v)-1] # Last array elements don't have commas
			data.append(fmt.format(', '.join(['new CunningPoint(%d, %d)' % p for p in shape])))
		for i in range(0, len(data), 3):
			fd.write('\t\t\t\t{0}\n'.format(''.join(data[i:i+4])))
			end = ['\t\t\t),\n', '\t\t\t)\n'][j == len(d)]
		fd.write(end)
	fd.write('\t\t);\n\t\tbreak;\n')