GSFont vs. GSInterpolationFontProxy

When drawing with a reporter plugin, I often need to get values from the parent font of the current layer. In G4, the parent now switches from a GSFont to GSInterpolationFontProxy when I view an interpolation. That means that I have to query different attributes depending on the parent type, which is a bit inconvenient :wink:

For example, the units per em:

try:
    # GSFont
    self.upm = self.layer.parent.parent.upm
except AttributeError:
    # GSInterpolationFontProxy
    self.upm = self.layer.parent.parent.unitsPerEm()

Or the grid length:

try:
    # GSFont
    self.options["grid_length"] = layer.parent.parent.gridLength
except AttributeError:
    # GSInterpolationFontProxy
    self.options["grid_length"] = layer.parent.parent.gridLength()

Perhaps GSInterpolationFontProxy could expose most of the same attributes as GSFont?

The second example doesn’t even work, because both classes have gridLength, it just is a float or int for GSFont, and an objc.native_selector for GSInterpolationFontProxy.

grid_length = layer.parent.parent.gridLength
if isinstance(grid_length, (float, int)):
    self.options["grid_length"] = grid_length
else:
    # GSInterpolationFontProxy
    self.options["grid_length"] = grid_length()

I’ll add them to the python wrapper. That is a good point.

Just to let you know, the grid can be different per master (you might need a finer grid on a 1 unit stem master).
better use this API:

print(Layer.gridLengthHorizontal(), Layer.gridLengthVertical())
master = Font.masters[0]
print(master.gridLengthHorizontal(), master.gridLengthVertical())

this are the available settings:

master.gridMainHorizontal
master.gridSubDivisionHorizontal
master.gridMainVertical
master.gridSubDivisionVertical
master.gridSlopeRise
master.gridSlopeRun

(I just added them to the wrapper, so until that is live, you need to add ())

To round a point to the grid.

grid = master.roundingSettings()
point = GSFontMaster.alignPoint_toGrid_type_(point, grid, 1)

the grid is defined like this:

typedef struct GSGridSettings {
	/// The effective interval for rounding horizontal coordinates.
	CGFloat lengthHorizontal;
	/// The effective interval for rounding vertical coordinates.
	CGFloat lengthVertical;

	/// The horizontal length of the main grid before subdivision.
	uint32_t mainHorizontal;
	/// The vertical length of the main grid before subdivision.
	uint32_t mainVertical;
	/// The number of horizontal subdivisions of the main grid.
	uint32_t subDivisionHorizontal;
	/// The number of vertical subdivisions of the main grid.
	uint32_t subDivisionVertical;
	/// The rise component of the grid slope.
	int32_t slopeRise;
	/// The run component of the grid slope.
	int32_t slopeRun;
} GSGridSettings;
1 Like