Skip to content

Commit e903087

Browse files
committed
Autoformatting
1 parent 715b088 commit e903087

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

qrcode/image/styles/moduledrawers/svg.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import abc
24
from decimal import Decimal
35
from typing import TYPE_CHECKING, NamedTuple
@@ -21,7 +23,7 @@ class Coords(NamedTuple):
2123

2224

2325
class BaseSvgQRModuleDrawer(QRModuleDrawer):
24-
img: "SvgFragmentImage"
26+
img: SvgFragmentImage
2527

2628
def __init__(self, *, size_ratio: Decimal = Decimal(1), **kwargs):
2729
self.size_ratio = size_ratio
@@ -97,7 +99,7 @@ def el(self, box):
9799

98100

99101
class SvgPathQRModuleDrawer(BaseSvgQRModuleDrawer):
100-
img: "SvgPathImage"
102+
img: SvgPathImage
101103

102104
def drawrect(self, box, is_active: bool):
103105
if not is_active:
@@ -148,6 +150,7 @@ class SvgRoundedModuleDrawer(SvgPathQRModuleDrawer):
148150
means that the radius of the rounded edge will be 0 (and thus back to 90
149151
degrees again).
150152
"""
153+
151154
needs_neighbors = True
152155

153156
def __init__(self, radius_ratio: Decimal = Decimal(1), **kwargs):
@@ -161,9 +164,9 @@ def initialize(self, *args, **kwargs) -> None:
161164
def drawrect(self, box, is_active):
162165
if not is_active:
163166
return
164-
167+
165168
# Check if is_active has neighbor information (ActiveWithNeighbors object)
166-
if hasattr(is_active, 'N'):
169+
if hasattr(is_active, "N"):
167170
# Neighbor information is available
168171
self.img._subpaths.append(self.subpath(box, is_active))
169172
else:
@@ -178,36 +181,36 @@ def subpath_all_rounded(self, box) -> str:
178181
x1 = self.img.units(coords.x1, text=False)
179182
y1 = self.img.units(coords.y1, text=False)
180183
r = self.img.units(self.corner_radius, text=False)
181-
184+
182185
# Build the path with all corners rounded
183186
path = []
184-
187+
185188
# Start at top-left after the rounded part
186189
path.append(f"M{x0 + r},{y0}")
187-
190+
188191
# Top edge to top-right corner
189192
path.append(f"H{x1 - r}")
190193
# Top-right rounded corner
191194
path.append(f"A{r},{r} 0 0 1 {x1},{y0 + r}")
192-
195+
193196
# Right edge to bottom-right corner
194197
path.append(f"V{y1 - r}")
195198
# Bottom-right rounded corner
196199
path.append(f"A{r},{r} 0 0 1 {x1 - r},{y1}")
197-
200+
198201
# Bottom edge to bottom-left corner
199202
path.append(f"H{x0 + r}")
200203
# Bottom-left rounded corner
201204
path.append(f"A{r},{r} 0 0 1 {x0},{y1 - r}")
202-
205+
203206
# Left edge to top-left corner
204207
path.append(f"V{y0 + r}")
205208
# Top-left rounded corner
206209
path.append(f"A{r},{r} 0 0 1 {x0 + r},{y0}")
207-
210+
208211
# Close the path
209212
path.append("z")
210-
213+
211214
return "".join(path)
212215

213216
def subpath(self, box, is_active) -> str:
@@ -217,58 +220,58 @@ def subpath(self, box, is_active) -> str:
217220
ne_rounded = not is_active.N and not is_active.E
218221
se_rounded = not is_active.E and not is_active.S
219222
sw_rounded = not is_active.S and not is_active.W
220-
223+
221224
coords = self.coords(box)
222225
x0 = self.img.units(coords.x0, text=False)
223226
y0 = self.img.units(coords.y0, text=False)
224227
x1 = self.img.units(coords.x1, text=False)
225228
y1 = self.img.units(coords.y1, text=False)
226229
r = self.img.units(self.corner_radius, text=False)
227-
230+
228231
# Build the path
229232
path = []
230-
233+
231234
# Start at top-left and move clockwise
232235
if nw_rounded:
233236
# Start at top-left corner, after the rounded part
234237
path.append(f"M{x0 + r},{y0}")
235238
else:
236239
# Start at the top-left corner
237240
path.append(f"M{x0},{y0}")
238-
241+
239242
# Top edge to top-right corner
240243
if ne_rounded:
241244
path.append(f"H{x1 - r}")
242245
# Top-right rounded corner
243246
path.append(f"A{r},{r} 0 0 1 {x1},{y0 + r}")
244247
else:
245248
path.append(f"H{x1}")
246-
249+
247250
# Right edge to bottom-right corner
248251
if se_rounded:
249252
path.append(f"V{y1 - r}")
250253
# Bottom-right rounded corner
251254
path.append(f"A{r},{r} 0 0 1 {x1 - r},{y1}")
252255
else:
253256
path.append(f"V{y1}")
254-
257+
255258
# Bottom edge to bottom-left corner
256259
if sw_rounded:
257260
path.append(f"H{x0 + r}")
258261
# Bottom-left rounded corner
259262
path.append(f"A{r},{r} 0 0 1 {x0},{y1 - r}")
260263
else:
261264
path.append(f"H{x0}")
262-
265+
263266
# Left edge back to start
264267
if nw_rounded:
265268
path.append(f"V{y0 + r}")
266269
# Top-left rounded corner
267270
path.append(f"A{r},{r} 0 0 1 {x0 + r},{y0}")
268271
else:
269272
path.append(f"V{y0}")
270-
273+
271274
# Close the path
272275
path.append("z")
273-
276+
274277
return "".join(path)

qrcode/tests/test_qrcode_svg.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@ def test_svg_rounded_module_drawer():
6060
"""Test that the SvgRoundedModuleDrawer works correctly."""
6161
qr = qrcode.QRCode()
6262
qr.add_data(UNICODE_TEXT)
63-
63+
6464
# Test with default parameters
6565
module_drawer = SvgRoundedModuleDrawer()
6666
img = qr.make_image(image_factory=svg.SvgPathImage, module_drawer=module_drawer)
6767
img.save(io.BytesIO())
68-
68+
6969
# Test with custom radius_ratio
70-
module_drawer = SvgRoundedModuleDrawer(radius_ratio=Decimal('0.5'))
70+
module_drawer = SvgRoundedModuleDrawer(radius_ratio=Decimal("0.5"))
7171
img = qr.make_image(image_factory=svg.SvgPathImage, module_drawer=module_drawer)
7272
img.save(io.BytesIO())
73-
73+
7474
# Test with custom size_ratio
75-
module_drawer = SvgRoundedModuleDrawer(size_ratio=Decimal('0.8'))
75+
module_drawer = SvgRoundedModuleDrawer(size_ratio=Decimal("0.8"))
7676
img = qr.make_image(image_factory=svg.SvgPathImage, module_drawer=module_drawer)
7777
img.save(io.BytesIO())
78-
78+
7979
# Test with both custom parameters
80-
module_drawer = SvgRoundedModuleDrawer(radius_ratio=Decimal('0.3'), size_ratio=Decimal('0.9'))
80+
module_drawer = SvgRoundedModuleDrawer(
81+
radius_ratio=Decimal("0.3"), size_ratio=Decimal("0.9")
82+
)
8183
img = qr.make_image(image_factory=svg.SvgPathImage, module_drawer=module_drawer)
8284
img.save(io.BytesIO())

0 commit comments

Comments
 (0)