@@ -117,7 +117,7 @@ def element( self ):
117117 d = super ().element ()
118118 d ['type' ] = 'T'
119119 d ['font' ] = FONTS .get ( self .font ) or self .font or FONTS .get ( 'sans' )
120- line_height = (self .y2 - self .y1 ) * 72 # points
120+ line_height = (self .y2 - self .y1 ) * 72 # Postscript point == 1/72 inch
121121 d ['size' ] = self .size or ( line_height * self .size_ratio ) # No need for int(round(..))
122122 if self .text is not None :
123123 d ['text' ] = self .text
@@ -307,10 +307,10 @@ def layout_wallet(
307307
308308 # Make Public QR Code square w/ min of height, width, anchored at lower-left corner
309309 public .add_region_proportional (
310- Text ( 'address-qr-top' , x1 = 1 / 16 , y1 = 8 / 16 , x2 = 1 , y2 = 9 / 16 )
310+ Text ( 'address-qr-top' , x1 = 1 / 16 , y1 = 5 / 16 , x2 = 1 , y2 = 6 / 16 )
311311 )
312312 public_qr = public .add_region_proportional (
313- Image ( 'address-qr' , x1 = 1 / 16 , y1 = 9 / 16 , x2 = 1 , y2 = 15 / 16 )
313+ Image ( 'address-qr' , x1 = 1 / 16 , y1 = 6 / 16 , x2 = 1 , y2 = 15 / 16 )
314314 )
315315 public_qr_size = min ( public_qr .x2 - public_qr .x1 , public_qr .y2 - public_qr .y1 )
316316 public_qr .x2 = public_qr .x1 + public_qr_size
@@ -319,17 +319,42 @@ def layout_wallet(
319319 Text ( 'address-qr-bot' , x1 = 1 / 16 , y1 = 15 / 16 , x2 = 1 , y2 = 16 / 16 )
320320 )
321321
322+ # Private region
322323 private .add_region_proportional (
323- Text ( 'private-qr-top' , x1 = 1 / 16 , y1 = 5 / 16 , x2 = 1 , y2 = 6 / 16 )
324+ Text ( 'private-qr-top' , x1 = 0 / 16 , y1 = 5 / 16 , x2 = 1 , y2 = 6 / 16 )
324325 )
325326 private_qr = private .add_region_proportional (
326- Image ( 'private-qr' , x1 = 1 / 16 , y1 = 6 / 16 , x2 = 1 , y2 = 15 / 16 )
327+ Image ( 'private-qr' , x1 = 0 / 16 , y1 = 6 / 16 , x2 = 1 , y2 = 15 / 16 )
327328 )
328329 private_qr_size = min ( private_qr .x2 - private_qr .x1 , private_qr .y2 - private_qr .y1 )
329330 private_qr .x2 = private_qr .x1 + private_qr_size
330331 private_qr .y1 = private_qr .y2 - private_qr_size
331332 private .add_region_proportional (
332- Text ( 'private-qr-bot' , x1 = 1 / 16 , y1 = 15 / 16 , x2 = 1 , y2 = 16 / 16 )
333+ Text ( 'private-qr-bot' , x1 = 0 / 16 , y1 = 15 / 16 , x2 = 1 , y2 = 16 / 16 )
334+ )
335+
336+ # We'll use the right side of the private region, rotated down and right. So, we need the
337+ # upper-left corner of the private-bg anchored at the upper-right corner of private.
338+ private_length = private .y2 - private .y1
339+ private_height = private .x2 - private_qr .x2
340+ private_fontsize = 8 # points == 1/72 inch
341+ private_fontwidth = private_length
342+
343+ public .add_region (
344+ Image (
345+ 'private-bg' ,
346+ x1 = private .x2 ,
347+ y1 = private .y1 ,
348+ x2 = private .x2 + private_height ,
349+ y2 = private .y1 - private_length ,
350+ rotate = - 180 ,
351+ )
352+ ).add_region (
353+ Text (
354+ 'private' ,
355+ size = private_fontsize ,
356+ rotate = - 180 ,
357+ )
333358 )
334359 return wallet
335360
@@ -662,8 +687,15 @@ def write_pdfs(
662687 if p != page_n :
663688 pdf .add_page ( orientation = 'P' )
664689 page_n = p
690+ try :
691+ private_bip38 = account .bip38 ( 'password' )
692+ except NotImplementedError as exc :
693+ log .exception ( f"{ account .crypto } doesn't support BIP-38: { exc } " )
694+ continue
695+
665696 wall_n += 1
666- log .info ( f"{ ordinal (wall_n ):5} { account .crypto } Paper Wallet at { offsetx :5} ,{ offsety :5} " )
697+ log .info ( f"{ ordinal ( wall_n ):5} { account .crypto } Paper Wallet at { offsetx :5} ,{ offsety :5} " )
698+
667699 images = os .path .join ( os .path .dirname ( __file__ ), '..' , 'images' )
668700 wall_tpl ['wallet-bg' ] = os .path .join ( images , 'paper-wallet-background.png' )
669701 wall_tpl [f"crypto-f{ c_n } " ] = account .crypto
@@ -673,7 +705,7 @@ def write_pdfs(
673705 version = None ,
674706 error_correction = qrcode .constants .ERROR_CORRECT_M ,
675707 box_size = 10 ,
676- border = 2 ,
708+ border = 1 ,
677709 )
678710 public_qr .add_data ( account .address )
679711 wall_tpl ['address-l-bg' ] = os .path .join ( images , '1x1-ffffff7f.png' )
@@ -684,14 +716,17 @@ def write_pdfs(
684716 wall_tpl ['address-qr' ] = public_qr .make_image ( back_color = "transparent" ).get_image ()
685717 wall_tpl ['address-qr-bot' ] = 'DEPOSIT/VERIFY'
686718
719+
687720 private_qr = qrcode .QRCode (
688721 version = None ,
689722 error_correction = qrcode .constants .ERROR_CORRECT_M ,
690723 box_size = 10 ,
691- border = 2 ,
724+ border = 1 ,
692725 )
693- private_qr .add_data ( account .key )
694- #wall_tpl['private'] = # TODO: Get BIP-38 encrypted private key
726+ private_qr .add_data ( private_bip38 )
727+
728+ wall_tpl ['private-bg' ] = os .path .join ( images , '1x1-ffffff7f.png' )
729+ wall_tpl ['private' ] = private_bip38
695730 wall_tpl ['private-qr-top' ] = 'PRIVATE KEY'
696731 wall_tpl ['private-qr' ] = private_qr .make_image ( back_color = "transparent" ).get_image ()
697732 wall_tpl ['private-qr-bot' ] = 'SPEND'
0 commit comments