Use snake case

This commit is contained in:
Andrew Murray 2025-10-15 19:36:10 +11:00
parent 4889863139
commit 95a85dc669

View File

@ -562,17 +562,17 @@ class ImageDraw:
) -> None: ) -> None:
"""Draw text.""" """Draw text."""
if isinstance(text, ImageText.Text): if isinstance(text, ImageText.Text):
imagetext = text image_text = text
else: else:
if font is None: if font is None:
font = self._getfont(kwargs.get("font_size")) font = self._getfont(kwargs.get("font_size"))
imagetext = ImageText.Text( image_text = ImageText.Text(
text, font, self.mode, spacing, direction, features, language text, font, self.mode, spacing, direction, features, language
) )
if embedded_color: if embedded_color:
imagetext.embed_color() image_text.embed_color()
if stroke_width: if stroke_width:
imagetext.stroke(stroke_width, stroke_fill) image_text.stroke(stroke_width, stroke_fill)
def getink(fill: _Ink | None) -> int: def getink(fill: _Ink | None) -> int:
ink, fill_ink = self._getink(fill) ink, fill_ink = self._getink(fill)
@ -586,14 +586,14 @@ class ImageDraw:
return return
stroke_ink = None stroke_ink = None
if imagetext.stroke_width: if image_text.stroke_width:
stroke_ink = ( stroke_ink = (
getink(imagetext.stroke_fill) getink(image_text.stroke_fill)
if imagetext.stroke_fill is not None if image_text.stroke_fill is not None
else ink else ink
) )
for xy, anchor, line in imagetext._split(xy, anchor, align): for xy, anchor, line in image_text._split(xy, anchor, align):
def draw_text(ink: int, stroke_width: float = 0) -> None: def draw_text(ink: int, stroke_width: float = 0) -> None:
mode = self.fontmode mode = self.fontmode
@ -604,7 +604,7 @@ class ImageDraw:
coord.append(int(xy[i])) coord.append(int(xy[i]))
start = (math.modf(xy[0])[0], math.modf(xy[1])[0]) start = (math.modf(xy[0])[0], math.modf(xy[1])[0])
try: try:
mask, offset = imagetext.font.getmask2( # type: ignore[union-attr,misc] mask, offset = image_text.font.getmask2( # type: ignore[union-attr,misc]
line, line,
mode, mode,
direction=direction, direction=direction,
@ -621,7 +621,7 @@ class ImageDraw:
coord = [coord[0] + offset[0], coord[1] + offset[1]] coord = [coord[0] + offset[0], coord[1] + offset[1]]
except AttributeError: except AttributeError:
try: try:
mask = imagetext.font.getmask( # type: ignore[misc] mask = image_text.font.getmask( # type: ignore[misc]
line, line,
mode, mode,
direction, direction,
@ -635,9 +635,9 @@ class ImageDraw:
**kwargs, **kwargs,
) )
except TypeError: except TypeError:
mask = imagetext.font.getmask(line) mask = image_text.font.getmask(line)
if mode == "RGBA": if mode == "RGBA":
# imagetext.font.getmask2(mode="RGBA") # image_text.font.getmask2(mode="RGBA")
# returns color in RGB bands and mask in A # returns color in RGB bands and mask in A
# extract mask and set text alpha # extract mask and set text alpha
color, mask = mask, mask.getband(3) color, mask = mask, mask.getband(3)
@ -653,7 +653,7 @@ class ImageDraw:
if stroke_ink is not None: if stroke_ink is not None:
# Draw stroked text # Draw stroked text
draw_text(stroke_ink, imagetext.stroke_width) draw_text(stroke_ink, image_text.stroke_width)
# Draw normal text # Draw normal text
if ink != stroke_ink: if ink != stroke_ink:
@ -721,7 +721,7 @@ class ImageDraw:
"""Get the length of a given string, in pixels with 1/64 precision.""" """Get the length of a given string, in pixels with 1/64 precision."""
if font is None: if font is None:
font = self._getfont(font_size) font = self._getfont(font_size)
imagetext = ImageText.Text( image_text = ImageText.Text(
text, text,
font, font,
self.mode, self.mode,
@ -730,8 +730,8 @@ class ImageDraw:
language=language, language=language,
) )
if embedded_color: if embedded_color:
imagetext.embed_color() image_text.embed_color()
return imagetext.get_length() return image_text.get_length()
def textbbox( def textbbox(
self, self,
@ -757,14 +757,14 @@ class ImageDraw:
"""Get the bounding box of a given string, in pixels.""" """Get the bounding box of a given string, in pixels."""
if font is None: if font is None:
font = self._getfont(font_size) font = self._getfont(font_size)
imagetext = ImageText.Text( image_text = ImageText.Text(
text, font, self.mode, spacing, direction, features, language text, font, self.mode, spacing, direction, features, language
) )
if embedded_color: if embedded_color:
imagetext.embed_color() image_text.embed_color()
if stroke_width: if stroke_width:
imagetext.stroke(stroke_width) image_text.stroke(stroke_width)
return imagetext.get_bbox(xy, anchor, align) return image_text.get_bbox(xy, anchor, align)
def multiline_textbbox( def multiline_textbbox(
self, self,