Comments (4)
For anyone interested, since flPinPoint has no __slots__
or __dict__
and seems basically immutable, I used regex to recreate the anchors. Kudos to FL developers for creating friendly APIs...
This is how I cleared all anchor, advance width and sidebearing expressions across masters in selected glyphs:
#FLM: Clear All Expressions
import re
from typerig.proxy import pFont
def clearExpressions():
font = pFont()
for glyph in font.selected_pGlyphs():
for layer in glyph.masters():
glyph.setLSBeq("", layer.name)
glyph.setRSBeq("", layer.name)
glyph.setADVeq("", layer.name)
anchors = []
for anchor in layer.anchors:
x = re.search("(x=)(-?\d+)",str(anchor)).group(2);
y = re.search("(y=)(-?\d+)",str(anchor)).group(2);
name = re.search("(objectName=')([^']+)'",str(anchor)).group(2);
anchors.append({ 'x': int(x), 'y': int(y), 'name': name });
layer.clearAnchors();
for a in anchors:
glyph.addAnchor((a['x'], a['y']), a['name'], layer.name)
glyph.update()
fontlab.Update(fontlab.CurrentFont())
print 'cleared expressions'
clearExpressions()
from typerig.
Thanks. I usually try to learn by listing the properties of an object using dir
e.g. print dir(anchor)
. I could swear it didn't work yesterday, but apparently it does work.
This would be the more sane version of the code then:
#FLM: Clear All Expressions
import re
from typerig.proxy import pFont
def clearExpr():
font = pFont()
for glyph in font.selected_pGlyphs():
for layer in glyph.masters():
glyph.setLSBeq("", layer.name)
glyph.setRSBeq("", layer.name)
glyph.setADVeq("", layer.name)
for anchor in layer.anchors:
anchor.expressionX = ""
anchor.expressionY = ""
glyph.update()
fontlab.Update(fontlab.CurrentFont())
print 'cleared expressions'
clearExpr()
from typerig.
hey @hyvyys thank you for your patience and interesting solution :)
flPinPoint() is the correct anchor object in FL 6&7. In fact flAnchor does nothing (or at least nothing that has interest to us) :) Moving anchors around (setting .x
or .y
) is done using the .point
property of the flPinPont
obejct. The .point
property is of QtCore.QPointF
class so you could set your anchors as follows:
import fontlab as fl6
import fontgate as fgt
import PythonQt as pqt
from typerig.proxy.fl import *
font = pFont()
g = eGlyph()
a = g.anchors()[0]
a.point = pqt.QtCore.QPointF(10,10) # Will move the anchor to (10,10)
g.updateObject(g.fl)
Also do not forget that we have all of these already implemented in TypeRig, thus the eGlyph()
object has the following methods (direct copy from the code):
def dropAnchor(self, name, layer, coordTuple, alignTuple=(None,None), tolerance=5, italic=False):
'''Drop anchor at given layer
Args:
name (str): Anchor Name
layer (int or str): Layer index or name, works with both
coordTuple (int, int): New anchor coordinates or auto aligment offsets*
alignTuple (str,str): New anchor aligment*
tolerance (int): Outline feature auto detection tolerance*
*Aligment rules: (width, height)
- (None,None) - Uses coordinates given
- width - (L) Left; (R) Right; (A) Auto Bottom with tolerance; (AT) Auto Top with tolerance; (C) Center;
- height - (T) Top; (B) Bottom; (C) Center;
Returns:
None
'''
def moveAnchor(self, name, layer, coordTuple=(0,0), alignTuple=(None,None), tolerance=5, italic=False):
'''Move anchor at given layer
Args:
name (str): Anchor Name
layer (int or str): Layer index or name, works with both
coordTuple (int, int): New anchor coordinates or auto aligment offsets*
alignTuple (str,str): New anchor aligment*
tolerance (int): Outline feature auto detection tolerance*
*Aligment rules: (width, height)
- (None,None) - Uses coordinates given
- width - (L) Left; (R) Right; (A) Auto Bottom with tolerance; (AT) Auto Top with tolerance; (C) Center;
- height - (T) Top; (B) Bottom; (C) Center;
Returns:
flPinPoint
'''
Also the base pGlyph()
object has:
def anchors(self, layer=None):
'''Return list of anchors (list[flAnchor]) at given layer (int or str)'''
def addAnchor(self, coordTuple, name, layer=None, isAnchor=True):
''' Adds named Anchor at given layer.
Args:
coordTuple (tuple(float,float)): Anchor coordinates X, Y
name (str): Anchor name
layer (int or str): Layer index or name. If None returns ActiveLayer
isAnchor (bool): True creates a true flAnchor, False ? (flPinPoint)
Returns:
None
'''
def newAnchor(self, coordTuple, name, anchorType=1):
'''
Creates new anchor
Args:
coordTuple (tuple(float,float)): Anchor coordinates X, Y
name (str): Anchor name
anchorType:
Returns:
flPinPoint
'''
def clearAnchors(self, layer=None):
'''Remove all anchors at given layer (int or str)'''
def findAnchor(self, anchorName, layer=None):
'''Find anchor by name/tag'''
def findAnchorCoords(self, anchorName, layer=None):
'''Find anchor coordinates by name/tag '''
Note: pGlyph()
object is proxy glyph object, while eGlyph()
object is and extension of pGlyph()
, thus you just need to import eGlyph()
PS: Feel free to explore the TR code and find solutions to your problems. Every object and function is fully documented inside the code - i just don't have time to export it as external API
from typerig.
Also acessing anchor expressions in flPinPoint is done trough .expressionX
, .expressionY
and we have the following in eGlyph()
:
def exprAnchor(self, name, layer, expression_x=None, expression_y=None):
'''Set anchor expressions at given layer
Args:
name (str): Anchor Name
layer (int or str): Layer index or name, works with both
expression_x (str): Expression for evaluating anchors X coordinate
expression_Y (str): Expression for evaluating anchors Y coordinate
Returns:
flPinPoint
'''
from typerig.
Related Issues (20)
- Delta [Panel] Redesign
- Contour [Panel] Redesign
- [Bug] Interpolated nudge
- [Bug] Delta [Panel] layer change messing stem value in spinboxes
- [Proxy] Glyph and Font .update()
- [Bug] Layer [Panel] Change layer type HOT 1
- GUI OS check failing on older MacOs
- Copy anchors proportionally option HOT 29
- Panel 3.11 HOT 7
- TypeRig Panel Delta – some glyphs are not affected HOT 1
- Little Rename Anchors Script Bug HOT 1
- Kerning manipulations
- Error messages with Delta Machine, TypeRig GUI Manager on FontLab 8, Windows 11 OS HOT 3
- FL8: pGlyph.addComponents not working HOT 1
- TR Manager does not start anymore HOT 3
- Can't access functions
- TypeRig Panel & TypeRig Toolbar not working HOT 2
- Proportionally harmonise control handles to master? HOT 5
- [Epic] Undo states and object updates
- TypeRig Panel error upon reinstallation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typerig.