本文整理汇总了Python中reportlab.lib.units.toLength函数的典型用法代码示例。如果您正苦于以下问题:Python toLength函数的具体用法?Python toLength怎么用?Python toLength使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toLength函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: doc
def doc(self, e):
format = e.get('format', 'A4')
raw_margins = e.get('margin', '2cm, 2cm, 2cm, 2cm')
title = e.get('title')
if ',' in format:
w, h = (toLength(i.strip()) for i in format.split(','))
format = (w, h)
else:
format = eval('pagesizes.' + format)
topMargin, rightMargin, bottomMargin, leftMargin = (toLength(i.strip()) for i in raw_margins.split(','))
def make_canvas(*args, **kwargs):
canvas = Canvas(*args, **kwargs)
canvas.setLineWidth(0.25)
return canvas
if self.document is None:
self.document = SimpleDocTemplate(self.out_buffer,
pagesize=format,
title=title,
topMargin=topMargin,
leftMargin=leftMargin,
rightMargin=rightMargin,
bottomMargin=bottomMargin,
canvasmaker=make_canvas)
for i in self.parse_children(e):
yield i
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:30,代码来源:parser.py
示例2: __init__
def __init__(self, labelsacross, labelsdown,
labelwidth, labelheight,
horizlabelgap, vertlabelgap,
pagesize=A4):
self.width = toLength(labelwidth)
self.height = toLength(labelheight)
self._pagesize = pagesize
horizlabelgap = toLength(horizlabelgap)
vertlabelgap = toLength(vertlabelgap)
pagewidth = pagesize[0]
pageheight = pagesize[1]
sidemargin = (pagewidth - (self.width * labelsacross) -
(horizlabelgap * (labelsacross - 1))) / 2
endmargin = (pageheight - (self.height * labelsdown) -
(vertlabelgap * (labelsdown - 1))) / 2
self.label = 0
self.ll = []
for y in range(0, labelsdown):
for x in range(0, labelsacross):
# We assume that labels are centered top-to-bottom
# and left-to-right, and that the gaps between them
# are consistent. The page origin is in the bottom-left.
# We record the bottom-left-hand corner of each label.
xpos = sidemargin + ((self.width + horizlabelgap) * x)
ypos = (pageheight - endmargin -
((self.height + vertlabelgap) * y) - self.height)
self.ll.append((xpos, ypos))
开发者ID:sde1000,项目名称:quicktill,代码行数:27,代码来源:pdrivers.py
示例3: sign
def sign(self, e):
text = e.get('text')
scale = float(e.get('scale', '1.0'))
width = toLength(e.get('width'))
height = toLength(e.get('height'))
template = """
<table cols="9.9cm, 1.9cm" align="right">
<tstyle padding="0" />
<tstyle area="0,0:-1,-1" padding-left="0.5cm"/>
<tr>
<td>
<p>................................................................</p>
<p><font size="8pt">{text}</font></p>
</td>
<td>
<vector src="common/pdf_img/left-pointing-arrow.svg" scale="{scale}" width="{width}" height="{height}" />
</td>
</tr>
</table>
""".format(
text=text,
scale=scale,
width=width,
height=height,
)
element = self.parse_parts(template)
for i in element:
yield i
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:29,代码来源:parser.py
示例4: vector
def vector(self, e):
scale = float(e.get('scale', '1.0'))
width = toLength(e.get('width'))
height = toLength(e.get('height'))
path = e.get('src')
search = e.get('search', None)
replace = e.get('replace', None)
fh = open(self.media_root + path, 'rb')
data = fh.read()
fh.close()
if search is not None:
data = data.replace(search, replace)
import xml.dom.minidom
svg = xml.dom.minidom.parseString(data).documentElement
from svglib.svglib import SvgRenderer
svgRenderer = SvgRenderer()
svgRenderer.render(svg)
svg_obj = svgRenderer.finish()
svg_obj.scale(scale, scale)
svg_obj.asDrawing(width, height)
yield svg_obj
开发者ID:gvangool,项目名称:django-pdfgen,代码行数:27,代码来源:parser.py
示例5: parseLength
def parseLength(length):
"""
Convert length to reportlab points.
"""
match = length_match(length)
if match is None:
raise SVGError("Not a valid length unit: '%s'" % length)
value = match.group('value')
unit = match.group('unit') or ''
if not value:
raise SVGError("Not a valid length unit: '%s'" % length)
if not unit:
if value[0] == 'e' or value[0] == 'E':
return float('1' + value)
else:
return float(value)
elif unit in ('em', 'ex', 'px', '%'):
# ignoring relative units
return float(value)
elif unit == 'pc':
return toLength(value + 'pica')
elif unit in ('mm', 'cm', 'in', 'i', 'pt', 'pica'):
return toLength(length)
else:
raise SVGError("Unknown unit '%s'" % unit)
开发者ID:eseifert,项目名称:svg2rlg,代码行数:32,代码来源:svg2rlg.py
示例6: img
def img(self, e):
width = toLength(e.get('width'))
height = toLength(e.get('height'))
path = e.get('src')
align = e.get('align', 'left').upper()
img_obj = Image(self.get_from_url(path), width=width, height=height)
img_obj.hAlign = align
yield img_obj
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:10,代码来源:parser.py
示例7: convertLength
def convertLength(self, svgAttr, percentOf=100):
"Convert length to points."
text = svgAttr
if not text:
return 0.0
if ' ' in text.replace(',', ' ').strip():
logger.debug("Only getting first value of %s" % text)
text = text.replace(',', ' ').split()[0]
if text.endswith('%'):
logger.debug("Fiddling length unit: %")
return float(text[:-1]) / 100 * percentOf
elif text.endswith("pc"):
return float(text[:-2]) * pica
elif text.endswith("pt"):
return float(text[:-2]) * 1.25
for unit in ("em", "ex", "px"):
if unit in text:
logger.warn("Ignoring unit: %s" % unit)
text = text.replace(unit, '')
text = text.strip()
length = toLength(text)
return length
开发者ID:pacoqueen,项目名称:ginn,代码行数:27,代码来源:svglib.py
示例8: convertLength
def convertLength(self, svgAttr, percentOf=100):
"Convert length to points."
text = svgAttr
if not text:
return 0.0
if text[-1] == '%':
if LOGMESSAGES:
print "Fiddling length unit: %"
return float(text[:-1]) / 100 * percentOf
elif text[-2:] == "pc":
return float(text[:-2]) * pica
newSize = text[:]
for u in "em ex px".split():
if newSize.find(u) >= 0:
if LOGMESSAGES:
print "Ignoring unit: %s" % u
newSize = newSize.replace(u, '')
newSize = newSize.strip()
length = toLength(newSize)
return length
开发者ID:philiptzou,项目名称:reportsvg,代码行数:25,代码来源:svglib.py
示例9: barcode
def barcode(self, e):
scale = float(e.get('scale', '1.0'))
width = toLength(e.get('width'))
height = toLength(e.get('height'))
value = e.get('value')
align = e.get('align', 'left').upper()
type = e.get('type', 'datamatrix')
barcode_obj = Barcode(library=self.barcode_library,
width=width,
height=height,
data=value,
scale=scale,
type=type,
align=align.lower())
barcode_obj.hAlign = align
yield barcode_obj
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:19,代码来源:parser.py
示例10: vector
def vector(self, e):
scale = float(e.get('scale', '1.0'))
width = toLength(e.get('width'))
height = toLength(e.get('height'))
path = e.get('src')
search = e.get('search', None)
replace = e.get('replace', None)
with open(self.get_from_url(path), 'rb') as fh:
data = fh.read()
if search is not None:
data = data.replace(search, replace)
svg = etree.fromstring(data)
renderer = SvgRenderer()
drawing = renderer.render(svg)
drawing.scale(scale, scale)
drawing.asDrawing(width, height)
yield drawing
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:20,代码来源:parser.py
示例11: __init__
def __init__(self, filename, tickets, fields, req, pagesize='A4',
stickysize=(75, 75), fontname='(auto)'):
self.req = req
self.tz = req.tz
locale = None
if hasattr(req, 'locale'):
locale = req.locale
self.filename = filename
self.tickets = tickets
self.pagesize = self._get_pagesize(pagesize)
self.stickysize = [units.toLength('%gmm' % val) for val in stickysize]
self.fontname = self._setup_font(fontname, locale)
self.fields = fields
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:13,代码来源:pdf.py
示例12: print_card
def print_card(user, barcode):
PAGE_HEIGHT = toLength('2.125in')
PAGE_WIDTH = toLength('3.37in')
XCENTER = PAGE_WIDTH / 2.0
YCENTER = PAGE_HEIGHT / 2.0
pdffile = NamedTemporaryFile()
if user.first_name:
username = '%s %s' % (user.first_name, user.last_name)
else:
username = user.username
c = canvas.Canvas(pdffile.name, pagesize=(PAGE_WIDTH, PAGE_HEIGHT))
if hasattr(settings, 'PRINT_CARD_IMAGES'):
for img in settings.PRINT_CARD_IMAGES:
c.drawImage(barcode if img['img'] == '$barcode$' else img['img'], toLength(img['x']), toLength(img['y']), width=(toLength(img['width'])), height=(toLength(img['height'])), preserveAspectRatio=True)
if hasattr(settings, 'PRINT_CARD_TEXT'):
for msg in settings.PRINT_CARD_TEXT:
c.setFont(msg['font'], msg['size'])
c.drawCentredString(toLength(msg.get('x', XCENTER)), toLength(msg.get('y', YCENTER)), username if msg['text'] == '$username$' else msg['text'])
c.showPage()
if hasattr(settings, 'PRINT_BACK_IMAGE'):
if os.path.isdir(settings.PRINT_BACK_IMAGE):
back_image = '%s/%s' % (settings.PRINT_BACK_IMAGE, random.choice(os.listdir(settings.PRINT_BACK_IMAGE))) # This is so ugly.
elif os.path.isfile(settings.PRINT_BACK_IMAGE):
back_image = settings.PRINT_BACK_IMAGE
c.drawImage(back_image, 0, 0, width=PAGE_WIDTH, height=PAGE_HEIGHT)
c.showPage()
c.save()
try:
printer = '-d %s' % settings.PRINTER
except NameError:
printer = ''
printjob = Popen('lp -s %s %s' % (printer, pdffile.name), shell=True)
printjob.wait()
开发者ID:lrvick,项目名称:django-barcode-auth,代码行数:39,代码来源:utils.py
示例13: table
def table(self, e):
cols = [toLength(i.strip()) for i in e.get('cols').split(',')]
height = e.get('height')
if height and len(height.split(',')) > 1:
height = [toLength(i.strip()) for i in height.split(',')]
elif height:
height = toLength(height)
align = e.get('align', 'left').upper()
tstyles = []
rows = []
for c in e:
if c.tag == 'tstyle':
tstyles += list(self.tstyle(c))
else:
rows.append(list(self.parse_element(c)))
table_obj = Table(rows, cols, rowHeights=height, hAlign=align, style=tstyles)
yield table_obj
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:22,代码来源:parser.py
示例14: tstyle
def tstyle(self, e):
area = e.get('area', '0:-1')
topleft, bottomright = (list(int(q) for q in p.split(',')) for p in area.split(':'))
top = topleft[0]
left = topleft[-1]
bottom = bottomright[0]
right = bottomright[-1]
cells = [(top, left), (bottom, right)]
tstyle_dict = dict(e.attrib)
if 'area' in tstyle_dict:
del tstyle_dict['area']
if 'border' in tstyle_dict:
border = tstyle_dict['border']
tstyle_dict.update({
'border-left': border,
'border-right': border,
'border-top': border,
'border-bottom': border
})
del tstyle_dict['border']
if 'padding' in tstyle_dict:
padding = tstyle_dict['padding']
tstyle_dict.update({
'padding-left': padding,
'padding-right': padding,
'padding-top': padding,
'padding-bottom': padding
})
del tstyle_dict['padding']
for key in tstyle_dict.keys():
value = tstyle_dict[key]
desc = CSS_DICT.get(key, key.upper())
params = value.split(',')
for i in xrange(len(params)):
param = params[i].strip()
if param[0] == '#':
params[i] = colors.HexColor(eval('0x' + param[1:]))
else:
try:
floatval = toLength(param)
params[i] = floatval
except ValueError:
params[i] = param.upper()
yield [desc] + cells + params
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:51,代码来源:parser.py
示例15: _lengthToFloat
def _lengthToFloat(self,value):
v = value
if not self.re_digits.search(v):
return v
try:
if v[-4:] == "inch":
# OO files use "inch" instead of "in" in Reportlab units
v = v[:-2]
except:
pass
try:
c = round(toLength(v))
return c
except:
return v
开发者ID:JustDevZero,项目名称:bulmages,代码行数:15,代码来源:tiny_sxw2rml.py
示例16: table
def table(self, e):
cols = [toLength(i.strip()) for i in e.get('cols').split(',')]
align = e.get('align', 'left').upper()
tstyles = []
rows = []
for c in e:
if c.tag == 'tstyle':
tstyles += list(self.tstyle(c))
else:
rows.append(list(self.parse_element(c)))
table_obj = Table(rows, cols, hAlign=align, style=tstyles)
yield table_obj
开发者ID:gvangool,项目名称:django-pdfgen,代码行数:15,代码来源:parser.py
示例17: getPt
def getPt(val):
"""Get numeric pt value from string value.
Strings can have the unit appended, like "3.5 in", "2 cm", "3 pica", "10 mm".
> print self.getPt("1 in")
72
> print self.getPt("1")
1
> print self.getPt(1)
1
"""
if isinstance(val, (int, long, float)):
# return as-is as the pt value.
return val
else:
# try to run it through reportlab's units.toLength() function:
return units.toLength(val)
开发者ID:biobot500,项目名称:addabaji-ci,代码行数:18,代码来源:util.py
示例18: parse_paragraph_style
def parse_paragraph_style(self, raw_style):
if '=' in raw_style:
# define
name, definition = (i.strip() for i in raw_style.split('=', 1))
if '+' in definition:
source_name, definition = (i.strip() for i in definition.split('+', 1))
else:
source_name = None
def_dict = eval(definition)
new_dict = {}
for k in def_dict.keys():
v = def_dict[k]
nk = CSS_DICT.get(k, k)
# translate v
v = CSS_DICT.get(v, v)
if nk == 'fontSize' or nk == 'leading':
v = toLength(v)
elif nk == 'color':
v = colors.HexColor(eval('0x' + v[1:]))
new_dict[nk] = v
if not new_dict.has_key('leading') and new_dict.has_key('fontSize'):
new_dict['leading'] = new_dict['fontSize'] + 2.0
if source_name is not None:
source_dict = self.styles[source_name].__dict__.copy()
source_dict.update(new_dict)
new_dict = source_dict
new_dict.update({'name': name})
if self.styles.has_key(name):
self.styles[name].__dict__.update(new_dict)
else:
self.styles.add(ParagraphStyle(**new_dict))
else:
name = raw_style.strip()
if name == 'end' or name == '':
self.style_stack.pop()
elif self.styles.has_key(name):
style = self.styles[name]
self.style_stack.append(style)
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:44,代码来源:parser.py
示例19: style
def style(self, e):
name = e.get('name')
source_name = e.get('base', None)
def_dict = dict(e.attrib)
del def_dict['name']
if 'base' in def_dict:
del def_dict['base']
new_dict = {}
for k in def_dict.keys():
v = def_dict[k]
nk = CSS_DICT.get(k, k)
# translate v
v = CSS_DICT.get(v, v)
if nk == 'fontSize' or nk == 'leading':
v = toLength(v)
elif nk == 'color':
v = colors.HexColor(eval('0x' + v[1:]))
new_dict[nk] = v
if not new_dict.has_key('leading') and new_dict.has_key('fontSize'):
new_dict['leading'] = new_dict['fontSize'] + 2.0
if source_name is not None:
source_dict = self.styles[source_name].__dict__.copy()
source_dict.update(new_dict)
new_dict = source_dict
new_dict.update({'name': name})
if self.styles.has_key(name):
self.styles[name].__dict__.update(new_dict)
else:
self.styles.add(ParagraphStyle(**new_dict))
# make this function an empty generator
if False:
yield
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:39,代码来源:parser.py
示例20: handle_document_properties
def handle_document_properties(self, raw_properties, title):
format, raw_unit, raw_margins = raw_properties.split(';')
format = A4
unit = toLength('1%s' % raw_unit)
self.unit = unit
topMargin, rightMargin, bottomMargin, leftMargin = (float(i) for i in raw_margins.split(','))
if self.doc is not None:
return
def make_canvas(*args, **kwargs):
canvas = Canvas(*args, **kwargs)
canvas.setLineWidth(0.25)
return canvas
self.doc = SimpleDocTemplate(self.out_buffer,
pagesize=format,
title=title,
topMargin=topMargin*unit,
leftMargin=leftMargin*unit,
rightMargin=rightMargin*unit,
bottomMargin=bottomMargin*unit,
canvasmaker=make_canvas)
开发者ID:mvpoland,项目名称:django-pdfgen,代码行数:23,代码来源:parser.py
注:本文中的reportlab.lib.units.toLength函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论