[Text] fixup bounds and normalized form
This commit is contained in:
parent
89cdd23f00
commit
f34b9b2f5c
2 changed files with 37 additions and 4 deletions
|
|
@ -108,6 +108,7 @@ class Text(PositionableImpl, RotatableImpl, Shape):
|
|||
and self.string == other.string
|
||||
and self.height == other.height
|
||||
and self.font_path == other.font_path
|
||||
and self.mirrored == other.mirrored
|
||||
and self.rotation == other.rotation
|
||||
and self.repetition == other.repetition
|
||||
and annotations_eq(self.annotations, other.annotations)
|
||||
|
|
@ -127,6 +128,8 @@ class Text(PositionableImpl, RotatableImpl, Shape):
|
|||
return self.font_path < other.font_path
|
||||
if not numpy.array_equal(self.offset, other.offset):
|
||||
return tuple(self.offset) < tuple(other.offset)
|
||||
if self.mirrored != other.mirrored:
|
||||
return self.mirrored < other.mirrored
|
||||
if self.rotation != other.rotation:
|
||||
return self.rotation < other.rotation
|
||||
if self.repetition != other.repetition:
|
||||
|
|
@ -174,22 +177,25 @@ class Text(PositionableImpl, RotatableImpl, Shape):
|
|||
(self.offset, self.height / norm_value, rotation, bool(self.mirrored)),
|
||||
lambda: Text(
|
||||
string=self.string,
|
||||
height=self.height * norm_value,
|
||||
height=norm_value,
|
||||
font_path=self.font_path,
|
||||
rotation=rotation,
|
||||
).mirror2d(across_x=self.mirrored),
|
||||
)
|
||||
|
||||
def get_bounds_single(self) -> NDArray[numpy.float64]:
|
||||
def get_bounds_single(self) -> NDArray[numpy.float64] | None:
|
||||
# rotation makes this a huge pain when using slot.advance and glyph.bbox(), so
|
||||
# just convert to polygons instead
|
||||
polys = self.to_polygons()
|
||||
if not polys:
|
||||
return None
|
||||
|
||||
pbounds = numpy.full((len(polys), 2, 2), nan)
|
||||
for pp, poly in enumerate(polys):
|
||||
pbounds[pp] = poly.get_bounds_nonempty()
|
||||
bounds = numpy.vstack((
|
||||
numpy.min(pbounds[: 0, :], axis=0),
|
||||
numpy.max(pbounds[: 1, :], axis=0),
|
||||
numpy.min(pbounds[:, 0, :], axis=0),
|
||||
numpy.max(pbounds[:, 1, :], axis=0),
|
||||
))
|
||||
|
||||
return bounds
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue