@@ -77,10 +77,12 @@ class BaseWriter(object):
7777
7878 def __init__ (self , initialize = None , paint_module = None , paint_text = None ,
7979 finish = None ):
80- self ._callbacks = dict (
81- initialize = initialize , paint_module = paint_module ,
82- paint_text = paint_text , finish = finish
83- )
80+ self ._callbacks = {
81+ 'initialize' : initialize ,
82+ 'paint_module' : paint_module ,
83+ 'paint_text' : paint_text ,
84+ 'finish' : finish ,
85+ }
8486 self .module_width = 10
8587 self .module_height = 10
8688 self .font_size = 10
@@ -111,7 +113,10 @@ def calculate_size(self, modules_per_line, number_of_lines, dpi=300):
111113 height = 2.0 + self .module_height * number_of_lines
112114 number_of_text_lines = len (self .text .splitlines ())
113115 if self .font_size and self .text :
114- height += pt2mm (self .font_size ) / 2 * number_of_text_lines + self .text_distance
116+ height += (
117+ pt2mm (self .font_size ) / 2
118+ * number_of_text_lines + self .text_distance
119+ )
115120 height += self .text_line_distance * (number_of_text_lines - 1 )
116121 return int (mm2px (width , dpi )), int (mm2px (height , dpi ))
117122
@@ -235,27 +240,36 @@ def _init(self, code):
235240 width , height = self .calculate_size (len (code [0 ]), len (code ), self .dpi )
236241 self ._document = create_svg_object ()
237242 self ._root = self ._document .documentElement
238- attributes = dict (width = SIZE .format (width ), height = SIZE .format (height ))
243+ attributes = {
244+ 'width' : SIZE .format (width ),
245+ 'height' : SIZE .format (height ),
246+ }
239247 _set_attributes (self ._root , ** attributes )
240248 self ._root .appendChild (self ._document .createComment (COMMENT ))
241249 # create group for easier handling in 3rd party software
242250 # like corel draw, inkscape, ...
243251 group = self ._document .createElement ('g' )
244- attributes = dict ( id = ' barcode_group')
252+ attributes = { 'id' : ' barcode_group'}
245253 _set_attributes (group , ** attributes )
246254 self ._group = self ._root .appendChild (group )
247255 background = self ._document .createElement ('rect' )
248- attributes = dict (width = '100%' , height = '100%' ,
249- style = 'fill:{0}' .format (self .background ))
256+ attributes = {
257+ 'width' : '100%' ,
258+ 'height' : '100%' ,
259+ 'style' : 'fill:{0}' .format (self .background )
260+ }
250261 _set_attributes (background , ** attributes )
251262 self ._group .appendChild (background )
252263
253264 def _create_module (self , xpos , ypos , width , color ):
254265 element = self ._document .createElement ('rect' )
255- attributes = dict (x = SIZE .format (xpos ), y = SIZE .format (ypos ),
256- width = SIZE .format (width ),
257- height = SIZE .format (self .module_height ),
258- style = 'fill:{0};' .format (color ))
266+ attributes = {
267+ 'x' : SIZE .format (xpos ),
268+ 'y' : SIZE .format (ypos ),
269+ 'width' : SIZE .format (width ),
270+ 'height' : SIZE .format (self .module_height ),
271+ 'style' : 'fill:{0};' .format (color )
272+ }
259273 _set_attributes (element , ** attributes )
260274 self ._group .appendChild (element )
261275
@@ -268,14 +282,14 @@ def _create_text(self, xpos, ypos):
268282 barcodetext = self .text
269283 for subtext in barcodetext .split ('\n ' ):
270284 element = self ._document .createElement ('text' )
271- attributes = dict (
272- x = SIZE .format (xpos ),
273- y = SIZE .format (ypos ),
274- style = 'fill:{0};font-size:{1}pt;text-anchor:middle;' .format (
285+ attributes = {
286+ 'x' : SIZE .format (xpos ),
287+ 'y' : SIZE .format (ypos ),
288+ ' style' : 'fill:{0};font-size:{1}pt;text-anchor:middle;' .format (
275289 self .foreground ,
276290 self .font_size ,
277291 )
278- )
292+ }
279293 _set_attributes (element , ** attributes )
280294 text_element = self ._document .createTextNode (subtext )
281295 element .appendChild (text_element )
@@ -328,7 +342,7 @@ def _paint_module(self, xpos, ypos, width, color):
328342
329343 def _paint_text (self , xpos , ypos ):
330344 for subtext in self .text .split ('\n ' ):
331- font = ImageFont .truetype (FONT , self .font_size * 2 )
345+ font = ImageFont .truetype (FONT , self .font_size * 2 )
332346 width , height = font .getsize (subtext )
333347 # determine the maximum width of each line
334348 pos = (mm2px (xpos , self .dpi ) - width // 2 ,
0 commit comments