class PDFBezier(object): def __init__(self, session, page, points, draw_color=None, style="S", stroke="solid"): self.session = session self.page = page self.points = points self.style = style self.stroke = stroke if draw_color is None: self.draw_color = PDFColor() else: self.draw_color = draw_color self.stroke = stroke for point in points: if not isinstance(point, PDFCursor): raise Exception("Must be a PDFCursor object", point) def draw(self): self._set_color() s = '%.2f %.2f m' % (self.points[0].x, self.points[0].y_prime) self.session._out(s, self.page) for point in self.points[1:]: self.session._out('%.2f %.2f l' % (point.x, point.y_prime), self.page) self.session._out('%s ' % self.style, self.page) def _set_color(self): self.draw_color._set_type('d') if not self.session._compare_color(self.draw_color): self.session._out(self.draw_color._get_color_string(), self.page) self.session._save_color(self.draw_color.copy())
def setDrawColor(self, drawcolor): if drawcolor is None: drawcolor = PDFColor("d") elif isinstance(drawcolor, PDFColor) and drawcolor.colortype is "d": pass else: drawcolor.setColorType("d") self.drawcolor = drawcolor
def setTextColor(self, textcolor): if textcolor is None: textcolor = PDFColor("t") elif isinstance(textcolor, PDFColor) and textcolor.colortype is "t": pass else: textcolor.setColorType("t") self.textcolor = textcolor self._setColorFlag()
def setFillColor(self, fillcolor): if fillcolor is None: fillcolor = PDFColor("f") elif isinstance(fillcolor, PDFColor) and fillcolor.colortype is "f": pass else: fillcolor.setColorType("f") self.fillcolor = fillcolor self._setColorFlag()
def set_colors(self, border_colors, fill_colors): if self.bar_style == "S": self.bar_border_colors = border_colors self.bar_fill_colors = None if border_colors is None: self.bar_border_colors = self.background.default_color_list if self.bar_style == "F": self.bar_border_colors = None self.bar_fill_colors = fill_colors if fill_colors is None: self.bar_fill_colors = self.background.default_color_list if self.bar_style == "B": self.bar_border_colors = border_colors self.bar_fill_colors = fill_colors if fill_colors is None: self.bar_fill_colors = self.background.default_color_list if border_colors is None: self.bar_border_colors = [] for color in self.background.default_color_list: r = min(int(color.red * 0.75), 255) g = min(int(color.green * 0.75), 255) b = min(int(color.blue * 0.75), 255) self.bar_border_colors.append(PDFColor(r, g, b)) if self.bar_fill_colors is not None: if isinstance(self.bar_fill_colors, PDFColor): self.bar_fill_colors._set_type('f') else: for color in self.bar_fill_colors: color._set_type('f')
def __init__(self, session, page, cursor, width, height, title=None, background=None, legend=None, axis=True): self.session = session self.page = page self.font = self.session.parent.document.font self.origin = cursor self.axis_labels = None self.legend = legend self.axis = axis self.base_color = PDFColor(77, 77, 77) if background is None: self.background = PDFGraphBackground() else: self.background = background self._set_accessories(title, width, height) self._draw_background(width, height) self._pad(width, height) self._draw_title()
def __init__(self, session, page, points, draw_color=None, style="S", stroke="solid"): self.session = session self.page = page self.points = points self.style = style self.stroke = stroke if draw_color is None: self.draw_color = PDFColor() else: self.draw_color = draw_color self.stroke = stroke for point in points: if not isinstance(point, PDFCursor): raise Exception("Must be a PDFCursor object", point)
def __init__(self, session, page, data, cursor, width, height, title, data_type="raw", fill_colors=None, labels=False, background=None, legend=None): super(PDFPieChart, self).__init__(session, page, cursor, width, height, title, background, legend) self._parse_data(data, data_type) self._set_center() self.style = "S" self.fill_colors = fill_colors self.labels = labels self.base_color = PDFColor(77, 77, 77) self.get_colors() self.draw_base_circle() self.draw_data()
def __init__(self, background_style=None, border_size=None, background_border_color=None, background_fill_color=None, padding=0.0, stroke=None): self.style = background_style self.size = border_size self.border_color = background_border_color self.fill_color = background_fill_color self.padding = padding self.stroke = stroke self.default_color_list = [ PDFColor(79, 129, 189), PDFColor(192, 80, 77), PDFColor(55, 187, 89), PDFColor(128, 100, 162), PDFColor(72, 172, 198), PDFColor(247, 150, 70), PDFColor(208, 146, 167), PDFColor(162, 200, 22), PDFColor(231, 188, 41), PDFColor(156, 133, 192), PDFColor(243, 164, 71), PDFColor(128, 158, 194) ]
self.size = border_size self.border_color = background_border_color self.fill_color = background_fill_color self.padding = padding self.stroke = stroke self.default_color_list = [ PDFColor(79, 129, 189), PDFColor(192, 80, 77), PDFColor(55, 187, 89), PDFColor(128, 100, 162), PDFColor(72, 172, 198), PDFColor(247, 150, 70), PDFColor(208, 146, 167), PDFColor(162, 200, 22), PDFColor(231, 188, 41), PDFColor(156, 133, 192), PDFColor(243, 164, 71), PDFColor(128, 158, 194) ] @property def exists(self): if self.style is None and self.size is None and self.border_color is None and self.fill_color is None: return False else: return True BasicBackground = PDFGraphBackground("S", 1, PDFColor(), None, 0.1, "solid")