#!/usr/bin/env python2
""" Simple Load Font Example
http://www.robodocs.info/roboFabDocs/source/howtos/world.html#openfont-path
Some process in UFO fonts (whthout any GUI junk).
note:
$ pip install fonttols robofab
"""

from robofab.world import RFont, RGlyph
from fontTools.misc.transform import Identity
import argparse, robofab, math, sys

######
# Args handling 

parser = argparse.ArgumentParser()
parser.add_argument(
	"ufo_in",
	help = "the ufo file to process"
)
parser.add_argument(
	"ufo_out",
	help = "the ufo file to save"
)
parser.add_argument(
	"-v", "--verbose",
	help = "increase output verbosity",
	action = "store_true"
)
args = parser.parse_args()

path = args.ufo_in


######
# Trigonometry 

matrix = Identity
matrix = matrix.rotate(math.radians(45))


######
# Font load and gliph Process

font = RFont(path)
print "The current font is:",font.info.postscriptFullName


if font == None:
	print "You should open a font first, there's nothing to look at now!"
else:
	if args.verbose:
		# let's have a look at some of the attributes a RoboFab Font object has
		print "the number of glyphs:", len(font)
		print "full name of this font:", font.info.postscriptFullName
		print 'ascender:', font.info.ascender
		print 'descender:', font.info.descender

print '-----'
print "list of glyph names:", font.keys()
print '-----'
#for key in font:
for glyph in font:
	# print vars(glyph)
	print glyph.name
	glyph.transform(matrix)

font.save(args.ufo_out)



# Borrar Curvas:

# for g in [glyph.name for glyph in font]:
#     old = font[g]
#     print len(old)
#     new = font.newGlyph("dummytmp", clear=True)
# 
# 
#     pen = new.getPointPen()
#     for contour in old:
#         pen.beginPath()
#         for point in contour.points:
#             if point.type != "offCurve":
#                 pen.addPoint((point.x,point.y),"line")
#         pen.endPath()
# 
# 
#     font.newGlyph(g, clear=True)
#     old.appendGlyph(new)
# font.removeGlyph("dummytmp")
# font.update()
