def draw_to_file(self, output_file, title): """Write the comparative plot to a file. Arguments: o output_file - The name of the file to output the information to, or a handle to write to. o title - A title to display on the graphic. """ width, height = self.page_size cur_drawing = Drawing(width, height) self._draw_title(cur_drawing, title, width, height) start_x = inch * .5 end_x = width - inch * .5 end_y = height - 1.5 * inch start_y = .5 * inch self._draw_scatter_plot(cur_drawing, start_x, start_y, end_x, end_y) if self.output_format == 'pdf': out_canvas = canvas.Canvas(output_file, pagesize = self.page_size) renderPDF.draw(cur_drawing, out_canvas, 0, 0) out_canvas.showPage() out_canvas.save() elif self.output_format == 'eps': renderPS.drawToFile(cur_drawing, output_file) else: raise ValueError("Invalid output format %s" % self.output_format)
def draw_to_file(self, output_file, title): """Write the comparative plot to a file. Arguments: o output_file - The name of the file to output the information to, or a handle to write to. o title - A title to display on the graphic. """ width, height = self.page_size cur_drawing = Drawing(width, height) self._draw_title(cur_drawing, title, width, height) start_x = inch * .5 end_x = width - inch * .5 end_y = height - 1.5 * inch start_y = .5 * inch self._draw_scatter_plot(cur_drawing, start_x, start_y, end_x, end_y) if self.output_format == 'pdf': out_canvas = canvas.Canvas(output_file, pagesize=self.page_size) renderPDF.draw(cur_drawing, out_canvas, 0, 0) out_canvas.showPage() out_canvas.save() elif self.output_format == 'eps': renderPS.drawToFile(cur_drawing, output_file) else: raise ValueError("Invalid output format %s" % self.output_format)
def test0(self): "Test two strings in drawing." path = outputfile("axestest0.ps") from reportlab.graphics.charts.axes import XCategoryAxis d = XCategoryAxis().demo() renderPS.drawToFile(d, path)
def test0(self): "Test two strings in drawing." path = outputfile("test_renderPS_simple_test0.ps") d = Drawing(200, 100) d.add(String(0, 0, "foo")) d.add(String(100, 0, "bar")) renderPS.drawToFile(d, path)
def test4(self): "Test character encoding." path = outputfile("test_renderPS_simple_test4.ps") specialChar = u'\u2019' d = Drawing(200, 100) d.add(String(0, 0, "foo"+specialChar)) d.add(String(100, 0, "bar")) renderPS.drawToFile(d, path)
def test3(self): from reportlab.lib.units import cm from reportlab.lib import colors width=300 height=60 #Create fairly simple drawing object, drawing=Drawing(width, height) p=ArcPath(strokeColor=colors.darkgreen, fillColor=colors.green, hrefURL="http://en.wikipedia.org/wiki/Vector_path", hrefTitle="This big letter C is actually a closed vector path.", strokewidth=0) p.addArc(1*cm, 1*cm, 0.8*cm, 20, 340, moveTo=True) p.addArc(1*cm, 1*cm, 0.9*cm, 20, 340, reverse=True) p.closePath() drawing.add(p) drawing.add(Rect(2.25*cm, 0.1*cm, 1.5*cm, 0.8*cm, rx=0.25*cm, ry=0.25*cm, hrefURL="http://en.wikipedia.org/wiki/Rounded_rectangle", hrefTitle="Rounded Rectangle", strokeColor=colors.red, fillColor=colors.yellow)) drawing.add(String(1*cm, 1*cm, "Hello World!", hrefURL="http://en.wikipedia.org/wiki/Hello_world", hrefTitle="Why 'Hello World'?", fillColor=colors.darkgreen)) drawing.add(Rect(4.5*cm, 0.5*cm, 5*cm, 1*cm, hrefURL="http://en.wikipedia.org/wiki/Rectangle", hrefTitle="Wikipedia page on rectangles", strokeColor=colors.blue, fillColor=colors.red)) drawing.add(Ellipse(7*cm, 1*cm, 2*cm, 0.95*cm, hrefURL="http://en.wikipedia.org/wiki/Ellipse", strokeColor=colors.black, fillColor=colors.yellow)) drawing.add(Circle(7*cm, 1*cm, 0.9*cm, hrefURL="http://en.wikipedia.org/wiki/Circle", strokeColor=colors.black, fillColor=colors.brown)) drawing.add(Ellipse(7*cm, 1*cm, 0.5*cm, 0.9*cm, hrefTitle="Tooltip with no link?", strokeColor=colors.black, fillColor=colors.black)) drawing.add(Polygon([4.5*cm, 1.25*cm, 5*cm, 0.1*cm, 4*cm, 0.1*cm], hrefURL="http://en.wikipedia.org/wiki/Polygon", hrefTitle="This triangle is a simple polygon.", strokeColor=colors.darkgreen, fillColor=colors.green)) renderPS.drawToFile(drawing, outputfile("test_renderPS_simple_test3.ps"))
def test2(self): "Test two strings in transformed group in drawing." path = outputfile("test_renderPS_simple_test2.ps") d = Drawing(200, 100) g = Group() g.add(String(0, 0, "foo")) g.add(String(100, 0, "bar")) g.scale(1.5, 1.2) g.translate(50, 0) d.add(g) renderPS.drawToFile(d, path)
def draw(self, output_file, title): """Draw out the information for the Organism. Arguments: o output_file -- The name of a file specifying where the document should be saved, or a handle to be written to. The output format is set when creating the Organism object. o title -- The output title of the produced document. """ width, height = self.page_size cur_drawing = Drawing(width, height) self._draw_title(cur_drawing, title, width, height) cur_x_pos = inch * 0.5 if len(self._sub_components) > 0: x_pos_change = (width - inch) / len(self._sub_components) # no sub_components else: pass for sub_component in self._sub_components: # set the drawing location of the chromosome sub_component.start_x_position = cur_x_pos sub_component.end_x_position = cur_x_pos + 0.9 * x_pos_change sub_component.start_y_position = height - 1.5 * inch sub_component.end_y_position = 3 * inch # do the drawing sub_component.draw(cur_drawing) # update the locations for the next chromosome cur_x_pos += x_pos_change self._draw_legend(cur_drawing, 2.5 * inch, width) if self.output_format == "pdf": out_canvas = canvas.Canvas(output_file, pagesize=self.page_size) renderPDF.draw(cur_drawing, out_canvas, 0, 0) out_canvas.showPage() out_canvas.save() elif self.output_format == "eps": renderPS.drawToFile(cur_drawing, output_file) else: raise ValueError("Invalid output format %s" % self.output_format)
def draw(self, output_file, title): """Draw out the information for the Organism. Arguments: o output_file -- The name of a file specifying where the document should be saved, or a handle to be written to. The output format is set when creating the Organism object. o title -- The output title of the produced document. """ width, height = self.page_size cur_drawing = Drawing(width, height) self._draw_title(cur_drawing, title, width, height) cur_x_pos = inch * .5 if len(self._sub_components) > 0: x_pos_change = (width - inch) / len(self._sub_components) # no sub_components else: pass for sub_component in self._sub_components: # set the drawing location of the chromosome sub_component.start_x_position = cur_x_pos sub_component.end_x_position = cur_x_pos + .9 * x_pos_change sub_component.start_y_position = height - 1.5 * inch sub_component.end_y_position = 3 * inch # do the drawing sub_component.draw(cur_drawing) # update the locations for the next chromosome cur_x_pos += x_pos_change self._draw_legend(cur_drawing, 2.5 * inch, width) if self.output_format == 'pdf': out_canvas = canvas.Canvas(output_file, pagesize=self.page_size) renderPDF.draw(cur_drawing, out_canvas, 0, 0) out_canvas.showPage() out_canvas.save() elif self.output_format == 'eps': renderPS.drawToFile(cur_drawing, output_file) else: raise ValueError("Invalid output format %s" % self.output_format)
def guardar_a_ps(self, nombrearchivo = None): """ Dibuja el código de barras en EPS. Devuelve el nombre del archivo. """ if not nombrearchivo: import time, os from tempfile import gettempdir nombrearchivo = os.path.join(gettempdir(), "barcode39_%s.eps" % ('_'.join(map(str, time.localtime()[:6])))) from reportlab.graphics.shapes import Drawing, String # @UnusedImport from reportlab.lib.units import cm tamcanvas = (self.width + 2, self.height + 10 + 0.4 * cm) dw = Drawing(width = tamcanvas[0], height = tamcanvas[1]) self.drawOnDW(dw, 1, tamcanvas[1] - 5 - self.height) from reportlab.graphics import renderPS renderPS.drawToFile(dw, nombrearchivo, "EPS") return nombrearchivo
def draw(self, output_file, title): """Draw out the distribution information. Arguments: o output_file - The name of the file to output the information to, or a handle to write to. o title - A title to display on the graphic. """ width, height = self.page_size cur_drawing = Drawing(width, height) self._draw_title(cur_drawing, title, width, height) # calculate the x and y position changes for each distribution cur_x_pos = inch * .5 end_x_pos = width - inch * .5 cur_y_pos = height - 1.5 * inch end_y_pos = .5 * inch x_pos_change = ((end_x_pos - cur_x_pos) / float(self.number_of_columns)) num_y_rows = math.ceil(float(len(self.distributions)) / float(self.number_of_columns)) y_pos_change = (cur_y_pos - end_y_pos) / num_y_rows self._draw_distributions(cur_drawing, cur_x_pos, x_pos_change, cur_y_pos, y_pos_change, num_y_rows) self._draw_legend(cur_drawing, 2.5 * inch, width) if self.output_format == 'pdf': out_canvas = canvas.Canvas(output_file, pagesize = self.page_size) renderPDF.draw(cur_drawing, out_canvas, 0, 0) out_canvas.showPage() out_canvas.save() elif self.output_format == 'eps': renderPS.drawToFile(cur_drawing, output_file) else: raise ValueError("Invalid output format %s" % self.output_format)
def draw(self, output_file, title): """Draw out the distribution information. Arguments: o output_file - The name of the file to output the information to, or a handle to write to. o title - A title to display on the graphic. """ width, height = self.page_size cur_drawing = Drawing(width, height) self._draw_title(cur_drawing, title, width, height) # calculate the x and y position changes for each distribution cur_x_pos = inch * .5 end_x_pos = width - inch * .5 cur_y_pos = height - 1.5 * inch end_y_pos = .5 * inch x_pos_change = ((end_x_pos - cur_x_pos) / float(self.number_of_columns)) num_y_rows = math.ceil( float(len(self.distributions)) / float(self.number_of_columns)) y_pos_change = (cur_y_pos - end_y_pos) / num_y_rows self._draw_distributions(cur_drawing, cur_x_pos, x_pos_change, cur_y_pos, y_pos_change, num_y_rows) self._draw_legend(cur_drawing, 2.5 * inch, width) if self.output_format == 'pdf': out_canvas = canvas.Canvas(output_file, pagesize=self.page_size) renderPDF.draw(cur_drawing, out_canvas, 0, 0) out_canvas.showPage() out_canvas.save() elif self.output_format == 'eps': renderPS.drawToFile(cur_drawing, output_file) else: raise ValueError("Invalid output format %s" % self.output_format)
def drawToFile(bc, filename): """Write barcode to Postscript file <filename>.""" renderPS.drawToFile(barcode.rl.draw_barcode(bc), filename)
def generate(self, value, stream=None, format='eps', includeText=None, textSize=14, dpi=300, lineWidth = 1.2, lineHeight = 36): """ Generates the requested bar code either via a stream or as the requested object type. @param value: The string to convert to a barcode @param stream: Optional argument of file name as a string, or any open file style object. @param format: The format in which the output should be generated. Valid file formats include pdf, eps, svg and will require the stream argument be provided. Valid object formats include rldrawing (ReportLab Drawing object will be returned, No stream argument is required). @param includeText: Boolean. If true then human readable text will be printed centered under the barcode. @param textSize: The point size of the human readable text. @param dpi: The dots per inch at which the bitmap should be generated. @return: None or a format dependent object. Valid return values:: eps : None pdf : None svg : None rl : ReportLab Drawing @rtype: misc """ assert (format in ('rl','pil') or stream is not None) d = self._generateDrawing(value, includeText, textSize, dpi) # # Process formats that return value instead of write to a file # if format == 'rl': return d # # A stream is required for the remaining formats # if not hasattr(stream, 'write'): closeFile = True stream = open(stream,'w') else: closeFile = False if format == 'pdf': from reportlab.graphics import renderPDF renderPDF.drawToFile(d, stream, 'GNUe') elif format == 'eps': from reportlab.graphics import renderPS renderPS.drawToFile(d, stream) elif format == 'svg': from reportlab.graphics import renderSVG renderSVG.drawToFile(d, stream) ## elif format in ('png','tiff'): ## from reportlab.graphics import renderPM ## renderPM.drawToFile(d, stream,format.upper(), dpi=dpi) ## elif format in ('pil',): ## from reportlab.graphics import renderPM ## return renderPM.drawToPIL(d, dpi=dpi) # # This code *should* be replaced with calls to renderPM # but that appears broken in the .debs # ## ## Raster-based output using PIL ## elif format in ('png','tiff','ppm','xbm'): code = value ## lineWidth = int(lineWidth * dpi/72+.5) # 300dpi lineHeight = int(lineHeight * dpi/72+.5) # 300dpi # Special case for PostNet lineHeight2 = int(lineHeight * .45+.5) # Create a new monochrome image with a white backgint image = Image.new('1',(int(len(code)*lineWidth+.5), int(lineHeight+.5)), 1) draw = ImageDraw.Draw(image) offs = 0 for ch in code: if ch == '1': draw.rectangle((offs,0,offs+lineWidth-1,lineHeight), outline=0, fill=0) # Special case for PostNet elif ch == '2': draw.rectangle((offs,0,offs+lineWidth-1,lineHeight2), outline=0, fill=0) offs += lineWidth image.save(stream, format) if closeFile: stream.close()