Skip to content

Commit

Permalink
Measurements running only once + reference match working
Browse files Browse the repository at this point in the history
  • Loading branch information
andrestelex committed Jan 31, 2021
1 parent f0308ca commit 3e94293
Showing 1 changed file with 23 additions and 57 deletions.
80 changes: 23 additions & 57 deletions HT_LetterSpacer_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ def triangle(angle, y):
#result = round(result)
return result

def totalMarginList(layer,overshoot,angle):
y = NSMinY(layer.bounds)-overshoot
def totalMarginList(layer,referenceLayer,overshoot,angle,minY,maxY):
#the list of margins
y = NSMinY(referenceLayer.bounds)-overshoot
listL = []
listR = []

Expand All @@ -149,7 +150,7 @@ def totalMarginList(layer,overshoot,angle):
#result will be false if all the measured margins are emtpy (no outlines in reference zone)
result=False

while y <= NSMaxY(layer.bounds)+overshoot:
while y <= NSMaxY(referenceLayer.bounds)+overshoot:
lpos, rpos = getMargins(layer, y)

#get the default margin measure at a given y position
Expand All @@ -158,13 +159,15 @@ def totalMarginList(layer,overshoot,angle):

if lpos is not None:
listL.append(NSMakePoint(lpos, y))
result=True
if minY<=y<=maxY:
result=True
else:
listL.append(NSMakePoint(slantPosL, y))

if rpos is not None:
listR.append(NSMakePoint(rpos, y))
result=True
if minY<=y<=maxY:
result=True
else:
listR.append(NSMakePoint(slantPosR, y))

Expand All @@ -176,54 +179,13 @@ def totalMarginList(layer,overshoot,angle):
else:
return False,False

# a list of margins
def marginList(layer,referenceLayer,overshoot,angle):
y = NSMinY(referenceLayer.bounds)-overshoot
listL = []
listR = []

#calculate default depth, otherwise measurement is None
#calculate paralelogram extremes
origin=NSMinX(layer.bounds)
endpointx=NSMaxX(layer.bounds)
endpointy=NSMaxY(layer.bounds)

#calculate paralelogram top left
xpos=triangle(angle,endpointy)+origin
#paralelogram top side width
slantWidth=(endpointx-xpos)
#default depth
dfltDepth=slantWidth

#result will be false if all the measured margins are emtpy (no outlines in reference zone)
result=False

while y <= NSMaxY(referenceLayer.bounds)+overshoot:
lpos, rpos = getMargins(layer, y)
def zoneMargins(lMargins,rMargins,minY,maxY):
#filter those outside the range
pointsFilteredL = [ x for x in lMargins if x.y>=minY and x.y<=maxY]
pointsFilteredR = [ x for x in rMargins if x.y>=minY and x.y<=maxY]

#get the default margin measure at a given y position
slantPosL=origin+triangle(angle,y)+dfltDepth
slantPosR=origin+triangle(angle,y)

if lpos is not None:
listL.append(NSMakePoint(lpos, y))
result=True
else:
listL.append(NSMakePoint(slantPosL, y))

if rpos is not None:
listR.append(NSMakePoint(rpos, y))
result=True
else:
listR.append(NSMakePoint(slantPosR, y))

y += paramFreq

#if no measurements are taken, returns false and will abort in main function
if result:
return listL, listR
else:
return False,False
return pointsFilteredL,pointsFilteredR

# get appropriate config file path
def getConfigPath(directory, glyphsfile, mastername):
Expand Down Expand Up @@ -442,20 +404,24 @@ def setSpace(self, layer, referenceLayer):
self.minY = NSMinY(layer.bounds)
self.maxY = NSMaxY(layer.bounds)

#get the margins for the full outline
lTotalMargins, rTotalMargins = totalMarginList(layer,overshoot,self.angle)
# get all margins in the zone
lZoneMargins, rZoneMargins = marginList(layer,referenceLayer,overshoot,self.angle)
self.output+="Using reference layer: " + referenceLayer.parent.name+"\n"

#get the margins for the full outline
lTotalMargins, rTotalMargins = totalMarginList(layer,layer,overshoot,self.angle,self.minYref,self.maxYref)

#check there is some overlap with reference zone
if not lZoneMargins and not rZoneMargins:
if not lTotalMargins and not rTotalMargins:
self.output += 'The glyph outlines are outside the reference layer zone/height. No match with '+referenceLayer.parent.name
return

# get all margins in the zone
lZoneMargins, rZoneMargins = zoneMargins(lTotalMargins,rTotalMargins,self.minYref,self.maxYref)



#if the font has an angle, we need to deslant
if self.angle:
print("Using angle: " + str(self.angle))
self.output+="Using angle: " + str(self.angle)+"\n"
lZoneMargins = self.deslant(lZoneMargins)
rZoneMargins = self.deslant(rZoneMargins)

Expand Down

0 comments on commit 3e94293

Please sign in to comment.