Download hfd_iclr2027_draft/tools/python/pypdf/generic/_rectangle.py from Tinghong-Ye22/code-iclr: direct link, hf CLI and curl.
- Browser
- Download file 3.9 kB
-
https://huggingface.co/Tinghong-Ye22/code-iclr/resolve/main/hfd_iclr2027_draft/tools/python/pypdf/generic/_rectangle.py
- Command line
-
hf download hf://Tinghong-Ye22/code-iclr/hfd_iclr2027_draft/tools/python/pypdf/generic/_rectangle.py
-
curl -L -o _rectangle.py https://huggingface.co/Tinghong-Ye22/code-iclr/resolve/main/hfd_iclr2027_draft/tools/python/pypdf/generic/_rectangle.py
3.9 kB
| from collections.abc import Sequence | |
| from typing import Any, Union | |
| from ._base import FloatObject, NumberObject | |
| from ._data_structures import ArrayObject | |
| class RectangleObject(ArrayObject): | |
| """ | |
| This class is used to represent *page boxes* in pypdf. | |
| These boxes include: | |
| * :attr:`artbox <pypdf._page.PageObject.artbox>` | |
| * :attr:`bleedbox <pypdf._page.PageObject.bleedbox>` | |
| * :attr:`cropbox <pypdf._page.PageObject.cropbox>` | |
| * :attr:`mediabox <pypdf._page.PageObject.mediabox>` | |
| * :attr:`trimbox <pypdf._page.PageObject.trimbox>` | |
| """ | |
| def __init__(self, arr: Sequence[Any]) -> None: | |
| # must have four points | |
| assert len(arr) == 4 | |
| # automatically convert arr[x] into NumberObject(arr[x]) if necessary | |
| ArrayObject.__init__(self, [self._ensure_is_number(x) for x in arr]) | |
| def _ensure_is_number(self, value: Any) -> Union[FloatObject, NumberObject]: | |
| if not isinstance(value, (FloatObject, NumberObject)): | |
| return FloatObject(value) | |
| return value | |
| def scale(self, sx: float, sy: float) -> "RectangleObject": | |
| return RectangleObject( | |
| ( | |
| float(self.left) * sx, | |
| float(self.bottom) * sy, | |
| float(self.right) * sx, | |
| float(self.top) * sy, | |
| ) | |
| ) | |
| def __repr__(self) -> str: | |
| return f"RectangleObject({list(self)!r})" | |
| def left(self) -> FloatObject: | |
| value: FloatObject = self[0] | |
| return value | |
| def left(self, f: float) -> None: | |
| self[0] = FloatObject(f) | |
| def bottom(self) -> FloatObject: | |
| value: FloatObject = self[1] | |
| return value | |
| def bottom(self, f: float) -> None: | |
| self[1] = FloatObject(f) | |
| def right(self) -> FloatObject: | |
| value: FloatObject = self[2] | |
| return value | |
| def right(self, f: float) -> None: | |
| self[2] = FloatObject(f) | |
| def top(self) -> FloatObject: | |
| value: FloatObject = self[3] | |
| return value | |
| def top(self, f: float) -> None: | |
| self[3] = FloatObject(f) | |
| def lower_left(self) -> tuple[float, float]: | |
| """ | |
| Property to read and modify the lower left coordinate of this box | |
| in (x,y) form. | |
| """ | |
| return self.left, self.bottom | |
| def lower_left(self, value: tuple[float, float]) -> None: | |
| self[0], self[1] = (self._ensure_is_number(x) for x in value) | |
| def lower_right(self) -> tuple[float, float]: | |
| """ | |
| Property to read and modify the lower right coordinate of this box | |
| in (x,y) form. | |
| """ | |
| return self.right, self.bottom | |
| def lower_right(self, value: tuple[float, float]) -> None: | |
| self[2], self[1] = (self._ensure_is_number(x) for x in value) | |
| def upper_left(self) -> tuple[float, float]: | |
| """ | |
| Property to read and modify the upper left coordinate of this box | |
| in (x,y) form. | |
| """ | |
| return self.left, self.top | |
| def upper_left(self, value: tuple[float, float]) -> None: | |
| self[0], self[3] = (self._ensure_is_number(x) for x in value) | |
| def upper_right(self) -> tuple[float, float]: | |
| """ | |
| Property to read and modify the upper right coordinate of this box | |
| in (x,y) form. | |
| """ | |
| return self.right, self.top | |
| def upper_right(self, value: tuple[float, float]) -> None: | |
| self[2], self[3] = (self._ensure_is_number(x) for x in value) | |
| def width(self) -> float: | |
| return self.right - self.left | |
| def height(self) -> float: | |
| return self.top - self.bottom | |