@@ -188,9 +188,22 @@ fn star<T: AsU64>(
188188
189189/// Generates a QR code from the input text.
190190#[ node_macro:: node( category( "Vector: Shape" ) , name( "QR Code" ) ) ]
191- fn qr_code ( _: impl Ctx , _primary : ( ) , #[ default( "https://graphite.art" ) ] text : String , #[ default( false ) ] individual_squares : bool
191+ fn qr_code (
192+ _: impl Ctx ,
193+ _primary : ( ) ,
194+ #[ default( "https://graphite.art" ) ] text : String ,
195+ /// Error correction level, from low (0) to high (3).
196+ #[ default( 1 ) ]
197+ error_correction : u32 ,
198+ #[ default( false ) ] individual_squares : bool ,
192199) -> Table < Vector > {
193- let ecc = qrcodegen:: QrCodeEcc :: Medium ;
200+ let ecc = match error_correction. max ( 3 ) {
201+ 0 => qrcodegen:: QrCodeEcc :: Low ,
202+ 1 => qrcodegen:: QrCodeEcc :: Medium ,
203+ 2 => qrcodegen:: QrCodeEcc :: Quartile ,
204+ 3 => qrcodegen:: QrCodeEcc :: High ,
205+ _ => unreachable ! ( ) ,
206+ } ;
194207
195208 let Ok ( qr_code) = qrcodegen:: QrCode :: encode_text ( & text, ecc) else {
196209 return Table :: default ( ) ;
@@ -394,7 +407,7 @@ mod tests {
394407
395408 #[ test]
396409 fn qr_code_test ( ) {
397- let qr = qr_code ( ( ) , ( ) , "https://graphite.art" . to_string ( ) , true ) ;
410+ let qr = qr_code ( ( ) , ( ) , "https://graphite.art" . to_string ( ) , 1 , true ) ;
398411 assert ! ( qr. iter( ) . next( ) . unwrap( ) . element. point_domain. ids( ) . len( ) > 0 ) ;
399412 assert ! ( qr. iter( ) . next( ) . unwrap( ) . element. segment_domain. ids( ) . len( ) > 0 ) ;
400413 }
0 commit comments