Closed aruZeta closed 2 years ago
How it would look with Solution 2:
@@ -99,20 +99,21 @@ func printSvg*(
alRad: Percentage = 0,
moRad: Percentage = 0,
class: string = "qrCode",
- id: string = ""
+ id: string = "",
+ forceUseRect: bool = false
): string =
result = fmt(svgHeader)
- if moRad:
+ if moRad or forceUseRect:
let moRadPx: float32 = 0.4 * moRad / 100
drawRegionWithoutAlPatterns moduleRect
else:
result.add fmt(modulePathStart)
- if alRad:
+ if alRad or forceUseRect:
drawRegionWithoutAlPatterns modulePath
else:
drawRegion 0'u8, size, 0'u8, size, modulePath
result.add fmt(modulePathEnd)
- if alRad:
+ if alRad or forceUseRect:
let alRadPx: float32 = 3.5 * alRad / 100
drawRoundedAlignmentPatterns
result.add svgEnd
With this
let qr = newQR("https://github.com/aruZeta/QRgen")
writeFile(
"build" / "testingSvg.svg",
qr.printSvg("#1d2021", "#98971a", forceUseRect = true)
)
Outputs the same as pre- 530e7aa197afe81566b830fd636cff3ed1232779
let qr = newQR("https://github.com/aruZeta/QRgen")
writeFile(
"build" / "testingSvg.svg",
qr.printSvg("#1d2021", "#98971a", 0, 0)
)
I will go with Solution 2
For better readability and ease of feature adding (like I'm planning to add a "margin" field to separate the modules at will, and not the default 0.1 for rounded modules), I think it will be better to just have 1 single
printSvg
procedure.Issues:
The proc doesn't know if the user passed a 0 explicitly or not to
moRad
oralRad
, but this should not be an issue at all unless the user wants to have an SVG with individual modules and alignment patterns (I mean them being drawed as<rec>
instead of a<path>
).Solution 1: Use
Option
, problem: I don't like how the user will need to usesome()
to pass values.Solution 2 (imo the best): If the user really wants to do what I said before, we could just add a
useRect
bool field, if true the proc will not care if the specified radius is 0 or whatever.Comment which solution you like, or add a new one.
Edit: note how this also fixes an issue where you can't set
moRad
without settingalRad
.