def createField(xmlfield): field=AttrDict() for i,v in xmlfield.items(): n=i[0].upper()+i[1:] if v.startswith('rgba(') and n != 'Value': field[n]=tuple([int(c) for c in re.findall('\d+',v)]) elif n == 'Value': field[n] = html.unescape(v) else: field[n]=v field.Width=int(field.Width)/4 field.Height=int(field.Height)/4 field.Left=int(field.Left)/4 field.Top=int(field.Top)/4 if field.FontSize: field.FontSize=int(field.FontSize) fstyle='Bold' if field.FontBold == '1' else 'Regular' fn = get_font_file(field.FontFamily,fstyle) field.FontFile = fn if fn else 'arial.ttf' if field.Type == 'label': return Label(field) elif field.Type == 'image': return Image(field) elif field.Type == 'barcode': return Barcode(field) elif field.Type == 'reactangle': return Rectangle(field) elif field.Type == 'circle': return Circle(field) else: return field
def __init__(self,xmlfield=None): super(ContainerField,self).__init__() for i,v in xmlfield.items(): n=i[0].upper()+i[1:] if v.startswith('rgba(') and n != 'Value': self[n]=tuple([int(c) for c in re.findall('\d+',v)]) else: self[n]=v self.Width=int(self.Width)/4 self.Height=int(self.Height)/4 self.Left=int(self.Left)/4 self.Top=int(self.Top)/4 self.FontSize=int(self.FontSize) fstyle='Bold' if self.FontBold == '1' else 'Regular' fn=get_font_file(self.FontFamily,fstyle) self.FontFile= fn if fn else 'arial.ttf'
#!/usr/bin/env python # -*- coding: utf-8 -*- import getfontname from getfontname import fontname,fontfile ffilename=getfontname.get_font_file('宋体') print('font file:', ffilename) fname=getfontname.get_font_name(ffilename) print('font name:',fname)