本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.circle方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.circle方法的具体用法?Python Canvas.circle怎么用?Python Canvas.circle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.pdfgen.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.circle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_05_coordinates
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import circle [as 别名]
def test_05_coordinates(self):
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.units import inch
from reportlab.lib.colors import pink, black, red, blue, green
c = Canvas('demo.pdf', pagesize=A4)
c.translate(inch,inch)
c.setStrokeColor(pink)
c.grid([1*inch,2*inch,3*inch,4*inch],[0.5*inch, 1*inch, .5*inch, 2*inch, 2.5*inch])
c.setFont("Times-Roman", 20)
c.drawString(0,0, "(0,0) the Origin")
c.drawString(2.5*inch, 1*inch, "(2.5,1) in inches")
c.drawString(4*inch, 2.5*inch, "(4,2.5)")
c.setFillColor(red)
c.rect(0,2*inch,0.2*inch, 0.3*inch, fill=1)
c.setFillColor(green)
c.circle(4.5*inch, 0.4*inch, 0.2*inch, fill=1)
c.showPage()
c.save()
示例2: main
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import circle [as 别名]
def main():
pdfmetrics.registerFont(TTFont('Dosis', 'Dosis-Medium.ttf'))
stars = []
with open('bsc5.dat', 'rb') as f:
for line in f:
line = '.' + line # switch to 1-based indexing
if not line[62].strip():
continue # skip coordinate-less novas
letter = intern(line[8:11])
if letter == ' ':
letter = None
h, m, s = float(line[61:63]), float(line[63:65]), float(line[65:69])
ra = (h + (m + s / 60.0) / 60.0) * tau / 24.0
d, m, s = float(line[69:72]), float(line[72:74]), float(line[76:78])
dec = (d + (m + s / 60.0) / 60.0) * tau / 360.0
mag = float(line[103:108])
stars.append((letter, ra, dec, mag))
h, w = 48, 96
c = Canvas('logo.pdf', pagesize=(w, h))
c.setFillColor('white')
c.rect(0, 0, w, h, stroke=0, fill=1)
c.setFillColor(bright_star_color)
rotation = 10.0 * tau / 360.0
# magscale = 0.1
# For 10 degrees:
x_offset = 96 -33.5
y_offset = h +37.5
# For 15 degrees:
# x_offset = 96 -28.5
# y_offset = 96 +0.5
# for 45 degrees:
# x_offset = 96 -13.5
# y_offset = 96 -10
small_glyphs = []
c.setFont('Helvetica', 2)
for letter, ra, dec, mag in stars:
# if mag > 4.0:
# continue
d = - (dec - quarter_tau) * 100
ra += rotation
x = d * sin(ra)
y = d * cos(ra)
if y < -63.0 or y > -39.0:
continue
if x < -43.0 or x > 19.0:
continue
x += x_offset
y += y_offset
r = ((13.0 - mag) / 10.0) ** 4.0 #* magscale
r = min(r, 1.0)
if r < 0.5:
small_glyphs.append((x, y, r))
else:
if letter is not None:
c.saveState()
greek_letter, offset = greeks[letter]
c.setFillColor(greek_color)
c.drawString(x+offset, y+0.5, greek_letter)
if letter == 'Alp':
c.setFillColor(alpha_star_color)
c.circle(x, y, r, stroke=0, fill=1)
c.restoreState()
if letter != 'Alp':
c.circle(x, y, r, stroke=0, fill=1)
else:
c.circle(x, y, r, stroke=0, fill=1)
c.setFillColor(dim_star_color)
for x, y, r in small_glyphs:
c.circle(x, y, r, stroke=0, fill=1)
c.setFillColor(text_color) #, alpha=0.5)
c.setFont('Dosis', 24)
sw = c.stringWidth('Skyfield')
c.drawString(w // 2 - sw // 2, h - 40, 'Skyfield')
c.showPage()
with open('logo.pdf', 'wb') as f:
f.write(c.getpdfdata())
示例3: render
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import circle [as 别名]
def render(self, outfile, font_name, font_size):
"""
Render the binary heat map as a PDF to the file-like object or filename
``outfile``. All text will be typeset in the font named ``font_name``
at size ``font_size``.
"""
c = Canvas(outfile)
c.setFont(font_name, font_size)
leftlen = max(map(c.stringWidth, self.row_labels)) + LABEL_PAD * 2
toplen = max(map(c.stringWidth, self.column_labels)) + LABEL_PAD * 2
miny = self.rows * font_size * 1.2
maxx = self.columns * font_size * 1.2
c.setPageSize((leftlen + maxx + PADDING*2, miny + toplen + PADDING*2))
# Set coordinates so that LL corner has coord (-leftlen-PADDING,
# -miny-PADDING) and the origin is at the point where the borders of the
# row & column labels meet:
c.translate(leftlen+PADDING, miny+PADDING)
lineheight = font_size * 1.2
radius = lineheight / 3
c.setFillColorRGB(*COL_BG_COLOR)
for i in range(0, self.columns, 2):
c.rect(
i * lineheight,
-miny,
lineheight,
miny + toplen,
stroke=0,
fill=1,
)
c.setFillColorRGB(*ROW_BG_COLOR)
for i in range(2, self.rows+1, 2):
# Yes, it starts at 2, so that the positive rectangle height will
# make it fill row 1.
c.rect(
-leftlen,
-i * lineheight,
leftlen + maxx,
lineheight,
stroke=0,
fill=1,
)
c.setFillColorRGB(0, 0, 0)
c.line(0, toplen, 0, -miny)
c.line(-leftlen, 0, maxx, 0)
for i, label in enumerate(self.row_labels):
c.drawRightString(
-LABEL_PAD,
-(i+1) * lineheight + font_size / 3,
label,
)
for i, label in enumerate(self.column_labels):
c.saveState()
c.translate((i+1) * lineheight, 0)
c.rotate(90)
c.drawString(LABEL_PAD, font_size / 3, label)
c.restoreState()
for row, col in self.get_indexed_pairs():
c.circle(
(col+0.5) * lineheight,
-(row+0.5) * lineheight,
radius,
stroke=0,
fill=1,
)
c.showPage()
c.save()
示例4: drawNode
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import circle [as 别名]
def drawNode(self, pos, col):
Canvas.setFillColor(self, col)
Canvas.circle(self, pos[0], pos[1], 0.3, fill=1)
示例5: PDFGenerator
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import circle [as 别名]
#.........这里部分代码省略.........
# Set element colors
self.set_fill_color(graphic.fill_color or self.report.default_fill_color)
self.set_stroke_color(graphic.stroke_color or self.report.default_stroke_color)
self.set_stroke_width(graphic.stroke_width)
if isinstance(element, RoundRect):
self.canvas.roundRect(
self.report.margin_left + graphic.left,
top_position - graphic.top - graphic.height,
graphic.width,
graphic.height,
graphic.radius,
graphic.stroke,
graphic.fill,
)
elif isinstance(element, Rect):
self.canvas.rect(
self.report.margin_left + graphic.left,
top_position - graphic.top - graphic.height,
graphic.width,
graphic.height,
graphic.stroke,
graphic.fill,
)
elif isinstance(element, Line):
self.canvas.line(
self.report.margin_left + graphic.left,
top_position - graphic.top,
self.report.margin_left + graphic.right,
top_position - graphic.bottom,
)
elif isinstance(element, Circle):
self.canvas.circle(
self.report.margin_left + graphic.left_center,
top_position - graphic.top_center,
graphic.radius,
graphic.stroke,
graphic.fill,
)
elif isinstance(element, Arc):
self.canvas.arc(
self.report.margin_left + graphic.left,
top_position - graphic.top,
self.report.margin_left + graphic.right,
top_position - graphic.bottom,
graphic.start_angle,
graphic.extent,
)
elif isinstance(element, Ellipse):
self.canvas.ellipse(
self.report.margin_left + graphic.left,
top_position - graphic.top,
self.report.margin_left + graphic.right,
top_position - graphic.bottom,
graphic.stroke,
graphic.fill,
)
elif isinstance(element, Image):
self.canvas.drawInlineImage(
graphic.image,
self.report.margin_left + graphic.left,
top_position - graphic.top - graphic.height,
graphic.width,
graphic.height,
)
示例6: create_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import circle [as 别名]
def create_pdf(hocr, filename, font="Courier", author=None, keywords=None, subject=None, title=None, image_path=None, draft=False):
""" transform hOCR information into a searchable PDF.
@param hocr the hocr structure as coming from extract_hocr.
@param filename the name of the PDF generated in output.
@param font the default font (e.g. Courier, Times-Roman).
@param author the author name.
@param subject the subject of the document.
@param title the title of the document.
@param image_path the default path where images are stored. If not specified
relative image paths will be resolved to the current directory.
@param draft whether to enable debug information in the output.
"""
def adjust_image_size(width, height):
return max(width / A4[0], height / A4[1])
canvas = Canvas(filename)
if author:
canvas.setAuthor(author)
if keywords:
canvas.setKeywords(keywords)
if title:
canvas.setTitle(title)
if subject:
canvas.setSubject(subject)
for bbox, image, lines in hocr:
if not image.startswith('/') and image_path:
image = os.path.abspath(os.path.join(image_path, image))
img_width, img_height = bbox[2:]
ratio = adjust_image_size(img_width, img_height)
if draft:
canvas.drawImage(image, 0, A4[1] - img_height / ratio , img_width / ratio, img_height / ratio)
canvas.setFont(font, 12)
for bbox, line in lines:
if draft:
canvas.setFillColor(red)
x0, y0, x1, y1 = bbox
width = (x1 - x0) / ratio
height = ((y1 - y0) / ratio)
x0 = x0 / ratio
#for ch in 'gjpqy,(){}[];[email protected]':
#if ch in line:
#y0 = A4[1] - (y0 / ratio) - height
#break
#else:
y0 = A4[1] - (y0 / ratio) - height / 1.3
#canvas.setFontSize(height * 1.5)
canvas.setFontSize(height)
text_width = canvas.stringWidth(line)
if text_width:
## If text_width != 0
text_object = canvas.beginText(x0, y0)
text_object.setHorizScale(1.0 * width / text_width * 100)
text_object.textOut(line)
canvas.drawText(text_object)
else:
info('%s, %s has width 0' % (bbox, line))
if draft:
canvas.setStrokeColor(green)
canvas.rect(x0, y0, width, height)
if draft:
canvas.circle(0, 0, 10, fill=1)
canvas.circle(0, A4[1], 10, fill=1)
canvas.circle(A4[0], 0, 10, fill=1)
canvas.circle(A4[0], A4[1], 10, fill=1)
canvas.setFillColor(green)
canvas.setStrokeColor(green)
canvas.circle(0, A4[1] - img_height / ratio, 5, fill=1)
canvas.circle(img_width / ratio, img_height /ratio, 5, fill=1)
else:
canvas.drawImage(image, 0, A4[1] - img_height / ratio , img_width / ratio, img_height / ratio)
canvas.save()