1+ from __future__ import annotations
2+
13import abc
24from decimal import Decimal
35from typing import TYPE_CHECKING , NamedTuple
@@ -21,7 +23,7 @@ class Coords(NamedTuple):
2123
2224
2325class 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
99101class 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 )
0 commit comments