-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bounds Named Positions #704
Comments
These are based on the bounds. Is there also a need for the same values, but based on the width, descender and ascender? |
A |
as long as they're all read-only, right? |
That was my idea, yes. Not sure if Tal had other ideas but I imagine a setter for this would be a bit weird haha |
Here's what I'm thinking of for bounds: class Bounds(tuple):
def _get_xMin(self):
return self[0]
def _get_xMax(self):
return self[2]
def _get_xCenter(self):
return ((self[2] - self[0]) / 2) + self[0]
def _get_yMin(self):
return self[1]
def _get_yMax(self):
return self[3]
def _get_yCenter(self):
return ((self[3] - self[1]) / 2) + self[1]
xMin = property(_get_xMin)
xMax = property(_get_xMax)
xCenter = property(_get_xCenter)
yMin = property(_get_yMin)
yMax = property(_get_yMax)
yCenter = property(_get_yCenter)
glyph = CurrentGlyph()
bounds = Bounds(glyph.bounds)
print(bounds.xMin, bounds.xCenter) All Values based on metrics are complicated. We could add dynamic def _get_xCenter(self):
return self.width / 2
def _get_yCenter(self):
return self.height / 2
xCenter = property(_get_xCenter)
yCenter = property(_get_yCenter) |
I voter for bounds being more then just a tuple! so they can be used in different places, it just has to be a subclass of Tuple |
Suggest to subclass import typing
class Point(typing.NamedTuple):
x: float
y: float
class Rectangle(typing.NamedTuple):
xMin: float
yMin: float
xMax: float
yMax: float
@property
def center(self):
return Point((self.xMin + self.xMax) / 2, (self.yMin + self.yMax) / 2)
b = Rectangle(10, 20, 30, 40)
print(b)
print(b.xMin)
print(b.center) Output:
|
I thought about a named tuple, but didn't think I could subclass it. Here's a new sketch: import typing
class Bounds(typing.NamedTuple):
xMin: float
yMin: float
xMax: float
yMax: float
@property
def width(self):
return self.xMax - self.xMin
@property
def xCenter(self):
return self.xMin + (self.width / 2)
@property
def height(self):
return self.yMax - self.yMin
@property
def yCenter(self):
return self.yMin + (self.height / 2)
glyph = CurrentGlyph()
bounds = Bounds(*glyph.bounds)
print(isinstance(bounds, tuple))
print(bounds.xMin)
print(bounds.width)
print(bounds.xCenter) I'm still not convinced that we need the (x, y) combination values so I've left those off. Also, I guess I'll finally learn about decorators now. 😬 |
Is this solving a problem, rather than just convenience? |
fontParts is mostly about making things easy for scripters, and I'm tired of doing bounds calculations so I see the need for this. |
I am all for this, yes: read only. PRs gratefully accepted! |
PRs with tests, joyfully accepted! |
Hey! Just dropping this here based on the Discord conversation! This only applies to glyphs' bounds but I liked @typesupply's suggestion for all bounds!
The text was updated successfully, but these errors were encountered: