Use anchor and direction in ImageFont

This commit is contained in:
Andrew Murray 2025-01-26 13:52:43 +11:00
parent 83c19d8f3e
commit dd7e092513
2 changed files with 14 additions and 13 deletions

View File

@ -37,7 +37,7 @@ from types import ModuleType
from typing import IO, TYPE_CHECKING, Any, BinaryIO, TypedDict, cast from typing import IO, TYPE_CHECKING, Any, BinaryIO, TypedDict, cast
from . import Image, features from . import Image, features
from ._typing import StrOrBytesPath from ._typing import Anchor, Direction, StrOrBytesPath
from ._util import DeferredError, is_path from ._util import DeferredError, is_path
if TYPE_CHECKING: if TYPE_CHECKING:
@ -313,7 +313,7 @@ class FreeTypeFont:
self, self,
text: str | bytes, text: str | bytes,
mode: str = "", mode: str = "",
direction: str | None = None, direction: Direction | None = None,
features: list[str] | None = None, features: list[str] | None = None,
language: str | None = None, language: str | None = None,
) -> float: ) -> float:
@ -392,11 +392,11 @@ class FreeTypeFont:
self, self,
text: str | bytes, text: str | bytes,
mode: str = "", mode: str = "",
direction: str | None = None, direction: Direction | None = None,
features: list[str] | None = None, features: list[str] | None = None,
language: str | None = None, language: str | None = None,
stroke_width: float = 0, stroke_width: float = 0,
anchor: str | None = None, anchor: Anchor | None = None,
) -> tuple[float, float, float, float]: ) -> tuple[float, float, float, float]:
""" """
Returns bounding box (in pixels) of given text relative to given anchor Returns bounding box (in pixels) of given text relative to given anchor
@ -458,11 +458,11 @@ class FreeTypeFont:
self, self,
text: str | bytes, text: str | bytes,
mode: str = "", mode: str = "",
direction: str | None = None, direction: Direction | None = None,
features: list[str] | None = None, features: list[str] | None = None,
language: str | None = None, language: str | None = None,
stroke_width: float = 0, stroke_width: float = 0,
anchor: str | None = None, anchor: Anchor | None = None,
ink: int = 0, ink: int = 0,
start: tuple[float, float] | None = None, start: tuple[float, float] | None = None,
) -> Image.core.ImagingCore: ) -> Image.core.ImagingCore:
@ -549,11 +549,11 @@ class FreeTypeFont:
self, self,
text: str | bytes, text: str | bytes,
mode: str = "", mode: str = "",
direction: str | None = None, direction: Direction | None = None,
features: list[str] | None = None, features: list[str] | None = None,
language: str | None = None, language: str | None = None,
stroke_width: float = 0, stroke_width: float = 0,
anchor: str | None = None, anchor: Anchor | None = None,
ink: int = 0, ink: int = 0,
start: tuple[float, float] | None = None, start: tuple[float, float] | None = None,
*args: Any, *args: Any,

View File

@ -1,6 +1,7 @@
from typing import Any, Callable from typing import Any, Callable
from . import ImageFont, _imaging from . import ImageFont, _imaging
from ._typing import Anchor, Direction
class Font: class Font:
@property @property
@ -24,11 +25,11 @@ class Font:
string: str | bytes, string: str | bytes,
fill: Callable[[int, int], _imaging.ImagingCore], fill: Callable[[int, int], _imaging.ImagingCore],
mode: str, mode: str,
dir: str | None, dir: Direction | None,
features: list[str] | None, features: list[str] | None,
lang: str | None, lang: str | None,
stroke_width: float, stroke_width: float,
anchor: str | None, anchor: Anchor | None,
foreground_ink_long: int, foreground_ink_long: int,
x_start: float, x_start: float,
y_start: float, y_start: float,
@ -38,17 +39,17 @@ class Font:
self, self,
string: str | bytes | bytearray, string: str | bytes | bytearray,
mode: str, mode: str,
dir: str | None, dir: Direction | None,
features: list[str] | None, features: list[str] | None,
lang: str | None, lang: str | None,
anchor: str | None, anchor: Anchor | None,
/, /,
) -> tuple[tuple[int, int], tuple[int, int]]: ... ) -> tuple[tuple[int, int], tuple[int, int]]: ...
def getlength( def getlength(
self, self,
string: str | bytes, string: str | bytes,
mode: str, mode: str,
dir: str | None, dir: Direction | None,
features: list[str] | None, features: list[str] | None,
lang: str | None, lang: str | None,
/, /,