Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ This application helps designing letters. """
- #__author__ = 'Christoph Knoth, ECAL/Ecole cantonale d art de Lausanne'
- from math import atan2, atan, pi
- import wx
- import wx.lib.scrolledpanel as scrolled
- ########################################################################
- # preferences vars
- #DebugMode = False
- DebugMode = True
- NodeNames = False
- #NodeNames = True
- ShowOffCurvePoints = False
- ShowOffCurvePoints = True
- #sortedLetters = False
- #sortedLetters = True
- row = 0
- letter = 0
- globalWidth = 500.
- StrokeWidth = 6.
- PenWidth = 10. #thickness
- ConnectionDotColor= (1, 0, 0)
- ##################
- # type based Variables
- #connectionType = "straight" #straight only
- connectionType = "round" #straight and round mixed
- baseline = 0.
- xHeight = 400.
- xHeightSave = xHeight
- descHeight = -300.
- SerifHeight = StrokeWidth * 0.9
- xHeightSerif = xHeight - SerifHeight
- capHeight = xHeight*15/10.
- # things that have to do with the beginning and ending of strokes or with arms and ...
- openess = 0.2 #0 very open -> too 0.5 closed
- openAngle = 1.5
- StemShoulderConnectionHeight = xHeight * 6/10.
- BottomBowlConnectionHeight = xHeight * 3/10.
- rightOpenContourFromTopCaps = (1 - openess) * capHeight + baseline
- rightOpenContourFromBottomCaps = openess * capHeight + baseline
- rightOpenContourFromTopMinors = (1 - openess) * xHeight + baseline
- rightOpenContourFromBottomMinors = openess * xHeight + baseline
- left = 0.
- offsetdrawing = 200.
- #roundness / curviness
- exponent = 6. #if bigger it makes the extrema: very thin and extended more pronounced, if smaller there is no squariness in thin and wide letters
- stretchFactor = pi/800. #the perfect roundness is at this point
- minimumCurveHori = 0.58
- minimumCurveVerti = 0.6
- ########################################################################
- # Viewport
- ScaleFactor = 0.27
- #############
- # Colors Display
- #wx.Colour(r, g, b, wx.ALPHA_OPAQUE)
- blue = wx.Colour(0, 255, 0, 255)
- black = wx.Colour(0, 0, 0, 255)
- HandlePenWidth = 4.
- HandleOvalWidth = 5
- # Class that defines a Node
- class Node(object):
- """Defining a Node with the parameters x, y and its name.
- Draws an oval at the position of the node with the name next to it."""
- fonts = 10. / ScaleFactor
- fontName = "Helvetica"
- nameOffset = 15, 15
- dotSize = StrokeWidth/ 2.
- def __init__(self, x, y, name=""):
- self.x = x
- self.y = y
- self.name = name
- def draw(self,gc):
- if DebugMode:
- gc.SetPen(wx.Pen(black, PenWidth))
- else:
- gc.SetPen(wx.Pen(blue, PenWidth))
- class Connection(object):
- """Defining a connection with the start and end point and a name.
- Draws a stroke from the start to the end."""
- def __init__(self, start, end, name=""):
- self.start = start
- self.end = end
- self.name = name
- self._parent = None
- def setParent(self, obj):
- self._parent = obj
- def getParent(self):
- return self._parent
- def getAngle(self):
- xDiff = self.end.x - self.start.x
- yDiff = self.end.y - self.start.y
- angle = atan2(xDiff, yDiff)
- return angle
- def getPreviousConnection(self):
- p = self.getParent()
- i = p.index(self)
- if i <= 0:
- return None
- elif i >= len(p):
- return None
- return p[i-1]
- def getFollowingConnection(self):
- p = self.getParent()
- i = p.index(self)
- if i <= 0:
- return None
- elif i >= len(p):
- return None
- return p[i]
- def draw(self,gc):
- #print self.getAngle() #works
- #print self.getPreviousConnection() # does not work
- #print self.getFollowingConnection()
- debugPath=gc.CreatePath()
- path=gc.CreatePath()
- path.MoveToPoint(self.start.x, self.start.y)
- offCurvePoint1x = self.start.x
- offCurvePoint1y = self.start.y
- offCurvePoint2x = self.end.x
- offCurvePoint2y = self.end.y
- #test if there is any roundness involved. if yes, check in which direction the roundness points
- if any(x in self.name for x in ['rb', 'lb', 'rt', 'lt']):
- if ((
- 'lt' in self.name and self.start.x >= self.end.x and self.start.y >= self.end.y
- ) or (
- 'rt' in self.name and self.start.x <= self.end.x and self.start.y >= self.end.y
- ) or (
- 'lb' in self.name and self.start.x >= self.end.x and self.start.y <= self.end.y
- ) or (
- 'rb' in self.name and self.start.x <= self.end.x and self.start.y <= self.end.y
- )):
- offCurvePoint1xMultiplicator = -1
- offCurvePoint1yMultiplicator = 0
- offCurvePoint2xMultiplicator = 0
- offCurvePoint2yMultiplicator = 1
- else:
- offCurvePoint1xMultiplicator = 0
- offCurvePoint1yMultiplicator = -1
- offCurvePoint2xMultiplicator = 1
- offCurvePoint2yMultiplicator = 0
- distanceHori = self.start.x - self.end.x
- distanceVerti = self.start.y - self.end.y
- # no division by zero
- if distanceHori == 0:
- distanceHori = distanceHori + 0.00001
- if distanceVerti == 0:
- distanceVerti = distanceVerti + 0.00001
- CurveHori = distanceHori * ((1-minimumCurveHori) * 2./pi * (atan(stretchFactor*(distanceVerti / distanceHori ) **exponent)) + minimumCurveHori)
- CurveVerti = distanceVerti * ((1-minimumCurveVerti) * 2./pi * (atan(stretchFactor*(distanceHori / distanceVerti ) **exponent)) + minimumCurveVerti)
- offCurvePoint1x = self.start.x + offCurvePoint1xMultiplicator * CurveHori
- offCurvePoint1y = self.start.y + offCurvePoint1yMultiplicator * CurveVerti
- offCurvePoint2x = self.end.x + offCurvePoint2xMultiplicator * CurveHori
- offCurvePoint2y = self.end.y + offCurvePoint2yMultiplicator * CurveVerti
- if DebugMode:
- if "rb" in self.name:
- gc.SetPen(wx.Pen(black, HandlePenWidth))
- elif "lb" in self.name:
- gc.SetPen(wx.Pen(black, HandlePenWidth))
- elif "rt" in self.name:
- gc.SetPen(wx.Pen(black, HandlePenWidth))
- elif "lt" in self.name:
- gc.SetPen(wx.Pen(black, HandlePenWidth))
- else:
- gc.SetPen(wx.Pen(black, HandlePenWidth))
- if ShowOffCurvePoints and (("rb" in self.name) or ("lb" in self.name) or ("rt" in self.name) or ("lt" in self.name)):
- debugPath.MoveToPoint(self.start.x, self.start.y)
- debugPath.AddLineToPoint(offCurvePoint1x, offCurvePoint1y)
- debugPath.MoveToPoint(offCurvePoint2x, offCurvePoint2y)
- debugPath.AddLineToPoint(self.end.x, self.end.y)
- gc.DrawEllipse(offCurvePoint1x-HandleOvalWidth/2., offCurvePoint1y-HandleOvalWidth/2., HandleOvalWidth, HandleOvalWidth)
- gc.DrawEllipse(offCurvePoint2x-HandleOvalWidth/2., offCurvePoint2y-HandleOvalWidth/2., HandleOvalWidth, HandleOvalWidth)
- gc.DrawPath(debugPath)
- if "rb" in self.name:
- gc.SetPen(wx.Pen(blue, PenWidth))
- elif "lb" in self.name:
- gc.SetPen(wx.Pen("#0000FF", PenWidth))
- elif "rt" in self.name:
- gc.SetPen(wx.Pen("#FF0000", PenWidth))
- elif "lt" in self.name:
- gc.SetPen(wx.Pen("#FFFF00", PenWidth))
- #if debug is off make it black
- else:
- gc.SetPen(wx.Pen(black, PenWidth))
- path.AddCurveToPoint(offCurvePoint1x, offCurvePoint1y, offCurvePoint2x, offCurvePoint2y, self.end.x, self.end.y)
- #if there is no roundness, it is probably a straight line, so draw it
- else:
- gc.SetPen(wx.Pen(black, PenWidth))
- path.AddLineToPoint(self.end.x, self.end.y)
- gc.DrawPath(path)
- class Stroke(object):
- def __init__(self, connections):
- self.connections = connections
- for connection in self.connections:
- connection.setParent(self.connections)
- def subscribeStrokes(self):
- for connection in self.connections:
- connection.setParent(self)
- def __len__(self):
- return len(self.connections)
- def index(self, obj):
- if obj in self.connections:
- return None
- return self.connections.index(obj)
- def getStrokes(self, index):
- return self.connections[index]
- def draw(self,gc):
- for c in self.connections:
- #c1=c.getPreviousConnection()
- #c2=c.getFollowingConnection()
- c.draw(gc)
- #if c1 != None:
- # c1.draw(gc)
- # print c.getAngle()
- #if c.getFollowingConnection()
- # Class that defines a Childconnection of two Nodes
- # for now it splits those two connections and connects the cutting points useful for A, H, for B, E, F,P, R, T, X, Y i need something else i guess?
- class ccCrossbar(object):
- """Takes two connections and draws a crossbar in between them"""
- def __init__(self, firstConnection, lastConnection, t1=.51, t2=.51):
- self.firstConnection = firstConnection
- self.lastConnection = lastConnection
- self.t1 = t1
- self.t2 = t2
- def draw(self,gc):
- firstDiffX = self.firstConnection.end.x - self.firstConnection.start.x
- firstDiffY = self.firstConnection.end.y - self.firstConnection.start.y
- lastDiffX = self.lastConnection.end.x - self.lastConnection.start.x
- lastDiffY = self.lastConnection.end.y - self.lastConnection.start.y
- s = Node(self.firstConnection.start.x + firstDiffX*self.t1, self.firstConnection.start.y + firstDiffY*self.t1)
- s.draw(gc)
- e = Node(self.lastConnection.start.x + lastDiffX* self.t2, self.lastConnection.start.y + lastDiffY* self.t2)
- e.draw(gc)
- if DebugMode:
- gc.SetPen(wx.Pen("#AAAAAA", PenWidth))
- else:
- gc.SetPen(wx.Pen(black, PenWidth))
- debugPath=gc.CreatePath()
- path=gc.CreatePath()
- path.MoveToPoint(s.x, s.y)
- path.AddLineToPoint(e.x, e.y)
- gc.DrawPath(debugPath)
- gc.DrawPath(path)
- class Glyph(object):
- def __init__(self, strokes):
- self.strokes = strokes
- def subscribeStrokes(self):
- for stroke in self.strokes:
- stroke.setParent(self)
- def __len__(self):
- return len(self.strokes)
- def index(self, obj):
- if obj in self.strokes:
- return None
- return self.strokes.index(obj)
- def getStrokes(self, index):
- return self.strokes[index]
- def draw(self,gc):
- for c in self.strokes:
- c.draw(gc)
- class Info(object):
- def __init__(self):
- self.unitsPerEm = 1000
- class Font(dict):
- """ Class that defines a Font as a Dictonary with its inherited Glyphs"""
- def _get_info(self):
- if not hasattr(self, "_info"):
- self._info = Info()
- return self._info
- info = property(_get_info)
- def draw(self,gc):
- print "Font.draw"
- row = 0
- translateWidth = globalWidth
- line = 0
- for key in sorted(self):
- glyph = self[key]
- glyph.draw(gc)
- #make rows that letters wont go out of the screen
- gc.Translate((glyph.individualWidth * 1.4), 0)
- row = row + 1
- translateWidth = translateWidth + glyph.individualWidth * 1.4
- if translateWidth > globalWidth * 8:
- line = line + 1
- #print "line", line
- row = 0
- lineHeight = max(capHeight,xHeight)
- gc.Translate(-translateWidth + globalWidth , -lineHeight*1.5)
- translateWidth = globalWidth
- def createGlyphs(self):
- functionName = "_glyph_"
- #cycle through all the names of def in font
- for key in dir(self):
- if functionName in key:
- name = key.replace(functionName, "")
- #print key
- #print(name)
- #call _glyph_function
- getattr(self, key)(name)
- def _glyph_A(self, name):
- #print "initializing ", name
- individualWidth = globalWidth*0.9
- n = {0:0}
- n[1] = Node(left, baseline, "left, bottom")
- n[2] = Node((left + individualWidth)/ 2., capHeight+baseline, "top, middle")
- c = {0:0}
- c[1] = Connection(n[1], n[2], "straight")
- n[3] = Node(individualWidth, baseline, "right, bottom")
- c[2] = Connection(n[3], n[2], "straight")
- cb = ccCrossbar(c[1], c[2], .3, .3)
- self[name] = Glyph([c[1], c[2], cb])
- self[name].individualWidth = individualWidth
- def _glyph_B(self, name):
- individualWidth = globalWidth*0.6
- n = {0:0}
- c = {0:0}
- s = {0:0}
- #top bowl
- n[1] = Node( left, capHeight + baseline, "left, top") #make list
- n[2] = Node( individualWidth * 600/self.info.unitsPerEm, capHeight + baseline, "top bowl, start curve, right ")
- n[3] = Node( individualWidth * 960/1000, (capHeight + baseline) * 760/1000, "right extrema, bowl, middle curve")
- n[4] = Node( individualWidth* 600/1000, (capHeight + baseline) / 2., "right, bowl, curve, vertical middle of letter")
- n[5] = Node( left, (capHeight + baseline) / 2., "touching stem, middle vertical, joint")
- #connecting all nodes
- c[1] = Connection(n[1], n[2])
- c[2] = Connection(n[2], n[3], "rt")
- c[3] = Connection(n[3], n[4], "rb")
- c[4] = Connection(n[4], n[5])
- s[1] = Stroke([ c[1], c[2], c[3], c[4] ])
- #bottom bowl
- n[5] = Node( individualWidth * 600/1000, (capHeight + baseline) / 2., "rightStart")
- n[6] = Node( individualWidth * 1050/1000, (capHeight + baseline) * 1/4, "rightStart")
- n[7] = Node( individualWidth * 600/1000, baseline, "rightStart")
- n[8] = Node( left, baseline, "rightStart")
- c[5] = Connection(n[5], n[6], "rt")
- c[6] = Connection(n[6], n[7], "rb")
- c[7] = Connection(n[7], n[8])
- s[2] = Stroke([c[5], c[6], c[7]])
- #stem
- c[8] = Connection(n[1], n[8])
- s[3] = Stroke([c[8]])
- self[name] = Glyph([s[1], s[2], s[3]])
- self[name].individualWidth = individualWidth
- def _glyph_C(self, name):
- #print "initializing ", name
- individualWidth = globalWidth*0.7
- n1 = Node( individualWidth, rightOpenContourFromTopCaps, "rightTopStart")
- n2 = Node( (left + individualWidth)/ 2., capHeight+baseline, "middleTop")
- n3 = Node( left, (capHeight)/ 2. + baseline, "leftMiddle")
- n4 = Node( (left + individualWidth)/ 2., baseline, "middleBottom")
- n5 = Node( individualWidth, rightOpenContourFromBottomCaps, "right Bottom End")
- c1 = Connection(n1, n2, "rt")
- c2 = Connection(n2, n3, "lt")
- c3 = Connection(n3, n4, "lb")
- c4 = Connection(n4, n5, "rb")
- s1 = Stroke([c1, c2, c3, c4])
- self[name] = Glyph([s1])
- self[name].individualWidth = individualWidth
- def _glyph_E(self, name):
- individualWidth = globalWidth*0.55
- n1 = Node( individualWidth, capHeight + baseline, "rightStart")
- n2 = Node( left, capHeight + baseline, "middleTop")
- n3 = Node( left, (capHeight)/ 2. + baseline, "leftMiddle")
- n4 = Node( individualWidth, (capHeight)/ 2. + baseline, "leftMiddle")
- n5 = Node( left, baseline, "middleBottom")
- n6 = Node( individualWidth, baseline, "rightEnd")
- c1 = Connection(n1, n2, "top stroke")
- c2 = Connection(n2, n3, "left stroke")
- c3 = Connection(n3, n4, "middle bar")
- c4 = Connection(n3, n5)
- c5 = Connection(n5, n6, "bottom stroke")
- s1 = Stroke([c1, c2, c3, c4, c5])
- self[name] = Glyph([s1])
- self[name].individualWidth = individualWidth
- def _glyph_H(self, name):
- individualWidth = globalWidth * 0.7
- s = Node(left, baseline, "left")
- e = Node(left, capHeight + baseline, "top")
- c = Connection(s, e)
- s = Node(left + individualWidth, baseline, "left")
- e = Node(left + individualWidth, capHeight + baseline, "top")
- c2 = Connection(s, e)
- cc = ccCrossbar(c, c2, .5, .5)
- self[name] = Glyph([c, c2, cc])
- self[name].individualWidth = individualWidth
- def _glyph_M1(self, name):
- individualWidth = globalWidth * 1.0
- n1 = Node(left, baseline, "leftStart")
- n2 = Node(2/10. * (left + individualWidth), capHeight + baseline, "leftTop")
- n3 = Node(1/ 2. * (left + individualWidth), baseline, "middleBottom")
- n4 = Node(8/10. * (left + individualWidth), capHeight + baseline, "rightTop")
- n5 = Node(left + individualWidth, baseline, "rightEnd")
- c1 = Connection(n1, n2)
- c2 = Connection(n2, n3)
- c3 = Connection(n3, n4)
- c4 = Connection(n4, n5)
- s = Stroke([c1, c2, c3, c4])
- self[name] = Glyph([s])
- self[name].individualWidth = individualWidth
- def _glyph_N(self, name):
- individualWidth = globalWidth * 0.7
- n1 = Node(left, baseline, "leftTop")
- n2 = Node(left, capHeight, "middleBottom")
- n3 = Node(left + individualWidth, baseline, "rightTop")
- n4 = Node(left + individualWidth, capHeight, "rightEnd")
- c1 = Connection(n1, n2)
- c2 = Connection(n2, n3)
- c3 = Connection(n3, n4)
- s = Stroke([c1, c2, c3])
- self[name] = Glyph([s])
- self[name].individualWidth = individualWidth
- def _glyph_U(self, name):
- #print "initializing ", name
- individualWidth = globalWidth*0.8
- n={0:0}
- n[1] = Node( left, capHeight+baseline, "middleTop")
- n[2] = Node( left, capHeight * 1/3 + baseline, "leftMiddle")
- n[3] = Node( (left + individualWidth) / 2., baseline, "middleBottom")
- n[4] = Node( individualWidth, capHeight * 1/3 + baseline, "rightEnd")
- n[5] = Node( individualWidth, capHeight, "rightEnd")
- c1 = Connection(n[1], n[2],)
- c2 = Connection(n[2], n[3], "lb")
- c3 = Connection(n[3], n[4], "rb")
- c4 = Connection(n[4], n[5],)
- s = Stroke([c1, c2, c3, c4])
- self[name] = Glyph([s])
- self[name].individualWidth = individualWidth
- def _glyph_W2(self, name):
- individualWidth = globalWidth * 1.2
- n1 = Node(left, capHeight, "leftStart")
- n2 = Node(1/3.*(left + individualWidth), baseline, "leftTop")
- n3 = Node(3/5.*(left + individualWidth), capHeight, "middleBottom")
- n4 = Node(2/5.*(left + individualWidth), capHeight, "middleBottom")
- n5 = Node(2/3.*(left + individualWidth), baseline, "rightTop")
- n6 = Node(left + individualWidth, capHeight, "rightEnd")
- c1 = Connection(n1, n2)
- c2 = Connection(n2, n3)
- c3 = Connection(n4, n5)
- c4 = Connection(n5, n6)
- stroke1 = Stroke([c1, c2])
- stroke2 = Stroke([c3, c4])
- self[name] = Glyph([stroke1, stroke2])
- self[name].individualWidth = individualWidth
- def _glyph_n1(self, name):
- individualWidth = globalWidth * 0.6
- #stem
- n1 = Node(left, baseline, "leftTop")
- n2 = Node(left, xHeight, "middleBottom")
- c1 = Connection(n1, n2)
- stroke1 = Stroke([c1])
- #bogen
- n3 = Node( left, StemShoulderConnectionHeight, "rightTop")
- n4 = Node( (left + individualWidth)*550/1000 , xHeight, "rightTop")
- n5 = Node(left + individualWidth, xHeight*650/1000, "rightEnd")
- n6 = Node(left + individualWidth, baseline, "rightEnd")
- c2 = Connection(n3, n4, "lt")
- c3 = Connection(n4, n5, "rt")
- c4 = Connection(n5, n6)
- stroke2 = Stroke([c2,c3,c4])
- self[name] = Glyph([stroke1, stroke2])
- self[name].individualWidth = individualWidth
- def _glyph_a1(self, name):
- individualWidth = globalWidth * 0.65
- n1 = Node(left + individualWidth, StemShoulderConnectionHeight, "rightTopStartBowl")
- n2 = Node( (left + individualWidth) / 2. , xHeight, "MiddleTopBowl")
- n3 = Node( left, xHeight / 2., "leftHorizontalMiddle")
- n4 = Node( (left + individualWidth) / 2. , baseline, "rightTop")
- n5 = Node(left + individualWidth, BottomBowlConnectionHeight, "rightEnd")
- c1 = Connection(n1, n2, "rt")
- c2 = Connection(n2, n3, "lt")
- c3 = Connection(n3, n4, "lb")
- c4 = Connection(n4, n5, "rb")
- stroke1 = Stroke([c1, c2, c3, c4])
- #stem
- st1 = Node(left + individualWidth, baseline, "leftTop")
- st2 = Node(left + individualWidth, xHeight, "middleBottom")
- cs1 = Connection(st1, st2)
- stroke2 = Stroke([cs1])
- self[name] = Glyph([stroke1, stroke2])
- self[name].individualWidth = individualWidth
- def _glyph_a2(self, name):
- individualWidth = globalWidth * 0.65
- n1 = Node(left + individualWidth, xHeight * 300/1000, "rightTopStartBowl")
- n2 = Node( (left + individualWidth) / 2. , xHeight* 6/10, "MiddleTopBowl")
- n3 = Node( left, xHeight * 300/1000, "leftHorizontalMiddle")
- n4 = Node( (left + individualWidth) / 2. , baseline, "rightTop")
- n5 = Node(left + individualWidth, xHeight * 300/1000, "rightEnd")
- c1 = Connection(n1, n2, "rt")
- c2 = Connection(n2, n3, "lt")
- c3 = Connection(n3, n4, "lb")
- c4 = Connection(n4, n5, "rb")
- stroke1 = Stroke([c1, c2, c3, c4])
- #stem
- st1 = Node(left, xHeight*750/1000, "left Arm, Start")
- st2 = Node(left + individualWidth/ 2., xHeight, "MiddleTop")
- st3 = Node(left + individualWidth, xHeight*750/1000, "Right Shoulder")
- st4 = Node(left + individualWidth, baseline, "leftTop")
- cs1 = Connection(st1, st2, "lt")
- cs2 = Connection(st2, st3, "rt")
- cs3 = Connection(st3, st4)
- stroke2 = Stroke([cs1, cs2, cs3])
- self[name] = Glyph([stroke1, stroke2])
- self[name].individualWidth = individualWidth
- def _glyph_c(self, name):
- individualWidth = globalWidth * 0.65
- n1 = Node(left + individualWidth, rightOpenContourFromTopMinors, "rightTopStartBowl")
- n2 = Node( (left + individualWidth) / 2. , xHeight, "MiddleTopBowl")
- n3 = Node( left, xHeight/ 2., "leftHorizontalMiddle")
- n4 = Node( (left + individualWidth) / 2. , baseline, "rightTop")
- n5 = Node(left + individualWidth, rightOpenContourFromBottomMinors, "rightEnd")
- c1 = Connection(n1, n2, "rt start")
- c2 = Connection(n2, n3, "lt")
- c3 = Connection(n3, n4, "lb")
- c4 = Connection(n4, n5, "rb end")
- s = Stroke([c1, c2, c3, c4])
- self[name] = Glyph([s])
- self[name].individualWidth = individualWidth
- def _glyph_e3(self, name):
- individualWidth = globalWidth * 0.65
- #crossbar
- n1 = Node(left, xHeight / 2., "crossbar, left")
- n2 = Node((left + individualWidth) * 950 / 1000 , xHeight / 2., "crossbar, right")
- #round stroke
- n3 = Node(left + individualWidth, xHeight * 2/3, "right, top, bowl")
- n4 = Node( (left + individualWidth) / 2. , xHeight, "vertical middle, top, bowl")
- n5 = Node( left, xHeight / 2., "left, vertical middle")
- n6 = Node( (left + individualWidth) / 2. , baseline, "horizontal, middle, bottom")
- n7 = Node(left + individualWidth, rightOpenContourFromBottomMinors, "right, bottom, arm")
- c1 = Connection(n1, n2)
- c2 = Connection(n2, n3, "rb")
- c3 = Connection(n3, n4, "rt")
- c4 = Connection(n4, n5, "lt")
- c5 = Connection(n5, n6, "lb")
- c6 = Connection(n6, n7, "rb")
- s1 = Stroke([c1])
- s2 = Stroke([c2, c3, c4, c5, c6])
- self[name] = Glyph([s1, s2])
- self[name].individualWidth = individualWidth
- def _glyph_g(self, name):
- individualWidth = globalWidth * 0.7
- n1 = Node(left + individualWidth, xHeight * 600/1000, "rightTopStartBowl")
- n2 = Node( (left + individualWidth) / 2. , xHeight, "MiddleTopBowl")
- n3 = Node( left, xHeight * 600/1000, "leftHorizontalMiddle")
- n4 = Node( (left + individualWidth) / 2. , xHeight*200/1000, "rightTop")
- c={0:0}
- c[1] = Connection(n1, n2, "rt")
- c[2] = Connection(n2, n3, "lt")
- c[3] = Connection(n3, n4, "lb")
- c[4] = Connection(n4, n1, "rb")
- s={0:0}
- s[1] = Stroke([c[1], c[2], c[3], c[4]])
- #lower thingy
- n5 = Node( (left+ individualWidth)*0.1 , xHeight*0.3, "rightTop")
- n6 = Node( left , xHeight*0.15, "rightTop")
- n7 = Node( (left + individualWidth)*0.2 , baseline, "rightTop")
- n8 = Node( (left + individualWidth)*0.7 , baseline, "rightTop")
- n9 = Node( left + individualWidth, descHeight / 2., "leftHorizontalMiddle")
- n10 = Node( (left + individualWidth) / 2. , descHeight, "MiddleTopBowl")
- n11 = Node(left, descHeight * 500/1000, "rightTopStartBowl")
- c[5] = Connection(n5, n6, "lt")
- c[6] = Connection(n6, n7, "lb")
- c[7] = Connection(n7, n8, "")
- c[8] = Connection(n8, n9, "rt")
- c[9] = Connection(n9, n10, "rb")
- c[10] = Connection(n10, n11, "lb")
- s[2] = Stroke([c[5], c[6], c[7], c[8], c[9], c[10]])
- self[name] = Glyph([s[1],s[2]])
- self[name].individualWidth = individualWidth
- def _glyph_o(self, name):
- individualWidth = globalWidth * 0.7
- n1 = Node(left + individualWidth, xHeight * 500/1000, "rightTopStartBowl")
- n2 = Node( (left + individualWidth) / 2. , xHeight, "MiddleTopBowl")
- n3 = Node( left, xHeight / 2., "leftHorizontalMiddle")
- n4 = Node( (left + individualWidth) / 2. , baseline, "rightTop")
- c={0:0}
- c[1] = Connection(n1, n2, "rt")
- c[2] = Connection(n2, n3, "lt")
- c[3] = Connection(n3, n4, "lb")
- c[4] = Connection(n4, n1, "rb")
- s1 = Stroke([c[1], c[2], c[3], c[4]])
- self[name] = Glyph([s1])
- self[name].individualWidth = individualWidth
- def _glyph_s1(self, name):
- individualWidth = globalWidth * 0.6
- n={0:0}
- n[1] = Node(left + individualWidth, rightOpenContourFromTopMinors, "right top bowl")
- n[2] = Node( (left + individualWidth) / 2. , xHeight, "MiddleTopBowl")
- n[3] = Node( left, xHeight*800/1000, "left top bowl middle")
- n[4] = Node( left + individualWidth*300/1000, xHeight*600/1000, "tob bowl, connection to straight middle part")
- n[5] = Node( left + individualWidth*700/1000, xHeight*500/1000, "lower bowl, connection to straight middle part")
- n[6] = Node( left + individualWidth, xHeight*250/1000, "right, verical middle of bottom bowl")
- n[7] = Node( left + individualWidth*500/1000, baseline, "bottom, horizontal middle")
- n[8] = Node( left, rightOpenContourFromBottomMinors, "left, vertical middle of bottom bowl")
- c={0:0}
- c[1] = Connection(n[1], n[2], "rt arm")
- c[2] = Connection(n[2], n[3], "lt")
- c[3] = Connection(n[3], n[4], "lb")
- c[4] = Connection(n[4], n[5], "crossbar straight")
- c[5] = Connection(n[5], n[6], "rt")
- c[6] = Connection(n[6], n[7], "rb")
- c[7] = Connection(n[7], n[8], "lb")
- s1 = Stroke([c[1], c[2], c[3], c[4], c[5], c[6], c[7] ])
- self[name] = Glyph([s1])
- self[name].individualWidth = individualWidth
- def _glyph_z(self, name):
- individualWidth = globalWidth * 0.55
- n1 = Node(left, xHeight, "rightTopStartBowl")
- n2 = Node( (left + individualWidth), xHeight, "MiddleTopBowl")
- n3 = Node( left, baseline, "leftHorizontalMiddle")
- n4 = Node( (left + individualWidth) , baseline, "rightTop")
- c={0:0}
- c[1] = Connection(n1, n2)
- c[2] = Connection(n2, n3)
- c[3] = Connection(n3, n4)
- s1 = Stroke([c[1], c[2], c[3]])
- self[name] = Glyph([s1])
- self[name].individualWidth = individualWidth
- class Path(object):
- def paint(self,gc):
- print "Path Drawn"
- f = Font()
- f.createGlyphs()
- print "drawing font"
- f.draw(gc)
- class LetterPanel(scrolled.ScrolledPanel):
- def __init__(self,parent=None,id=-1):
- scrolled.ScrolledPanel.__init__(self, parent, id, pos=(0, 0), size=(wx.DisplaySize()[0]-400, wx.DisplaySize()[1]-220), style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="LetterPanel" )
- #wx.Panel.__init__(self, parent, id, pos=(0, 0), size=(wx.DisplaySize()[0]-400, wx.DisplaySize()[1]-200), style=wx.TAB_TRAVERSAL)
- self.SetAutoLayout(True)
- self.SetBackgroundColour("#FFFFFF")
- self.Bind(wx.EVT_PAINT,self.onPaint)
- self.SetDoubleBuffered(True)
- self.path=Path()
- def onPaint(self, event):
- event.Skip()
- dc = wx.PaintDC(self)
- dc.BeginDrawing()
- gc = wx.GraphicsContext.Create(dc)
- gc.Scale(ScaleFactor, -ScaleFactor)
- gc.Translate(ScaleFactor+100, ScaleFactor - 800)
- gc.PushState()
- self.path.paint(gc)
- gc.PopState()
- dc.EndDrawing()
- class SliderPanel(wx.Panel):
- """
- class SliderPanel creates a panel with 2 sliders on it, inherits wx.Panel
- putting your components/widgets on a panel gives additional versatility
- """
- def __init__(self, parent, id):
- # create a panel
- #,pos=(0, wx.DisplaySize()[1]-400), size=(400,wx.DisplaySize()[1]-200)
- wx.Panel.__init__(self, parent, id, pos=(wx.DisplaySize()[0]-400, 0), size=(400,wx.DisplaySize()[1]-200))
- self.SetBackgroundColour("white")
- # wx.SL_VERTICAL displays the slider vertically
- # wx.SL_HORIZONTAL displays the slider horizontally
- # wx.SL_AUTOTICKS displays tick marks
- # wx.SL_LABELS displays minimum, maximum and value labels
- # initial value = 100, min value = 0, max value = 400
- self.xHeightSlider = wx.Slider(self, -1, 100, 0, 400, (10, 10), (300, 50), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
- self.slider2 = wx.Slider(self, -1, 100, 0, 400, (10, 50), (300, 50), wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
- # respond to changes in slider position ...
- self.Bind(wx.EVT_SLIDER, self.sliderUpdate)
- def sliderUpdate(self, event):
- self.xHeightSliderValue = self.xHeightSlider.GetValue()
- self.pos2 = self.slider2.GetValue()
- str1 = "xHeightSliderValue = %d pos2 = %d" % (self.xHeightSliderValue, self.pos2)
- global xHeight
- global xHeightSave
- xHeight = xHeightSave * self.xHeightSliderValue/100.
- global StemShoulderConnectionHeight
- StemShoulderConnectionHeight = xHeight * 6/10.
- global BottomBowlConnectionHeight
- BottomBowlConnectionHeight = xHeight * 3/10.
- global rightOpenContourFromTopCaps
- rightOpenContourFromTopCaps = (1 - openess) * capHeight + baseline
- global rightOpenContourFromTopCaps
- rightOpenContourFromBottomCaps = openess * capHeight + baseline
- global rightOpenContourFromTopMinors
- rightOpenContourFromTopMinors = (1 - openess) * xHeight + baseline
- global rightOpenContourFromBottomMinors
- rightOpenContourFromBottomMinors = openess * xHeight + baseline
- # display current slider positions in the frame's title
- frame.SetTitle(str1)
- class LetterFrame(wx.Frame):
- def __init__(self, parent, title):
- #opening a window
- wx.Frame.__init__(self, parent, title=title, pos=(0, 22), size=(wx.DisplaySize()[0],wx.DisplaySize()[1]-200))
- self.LetterPanel=LetterPanel(self,-1)
- self.SliderPanel=SliderPanel(self,-1)
- self.Show(True)
- app = wx.App(False)
- frame = LetterFrame(None,"Type as Graph")
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement