def add_styles(self): """Add the css to the svg""" colors = self.graph.config.style.get_colors(self.id) all_css = [] for css in ['base.css'] + list(self.graph.css): if '://' in css: self.processing_instructions.append( etree.PI(u('xml-stylesheet'), u('href="%s"' % css))) else: if css.startswith('inline:'): css_text = css[len('inline:'):] else: if not os.path.exists(css): css = os.path.join(os.path.dirname(__file__), 'css', css) with io.open(css, encoding='utf-8') as f: css_text = template( f.read(), style=self.graph.config.style, colors=colors, font_sizes=self.graph.config.font_sizes(), id=self.id) if not self.graph.pretty_print: css_text = minify_css(css_text) all_css.append(css_text) self.node(self.defs, 'style', type='text/css').text = '\n'.join(all_css)
def add_styles(self): """Add the css to the svg""" colors = self.graph.style.get_colors(self.id, self.graph._order) strokes = self.get_strokes() all_css = [] auto_css = ['template://{}'.format(CSS_BASE)] if self.graph.style._google_fonts: auto_css.append( '//fonts.googleapis.com/css?family=%s' % quote_plus('|'.join(self.graph.style._google_fonts))) for css in auto_css + list(self.graph.css): css_text = None if css.startswith('inline:'): css_text = css[len('inline:'):] elif css.startswith('template://'): css = css[len('template://'):] css_text = template(css, style=self.graph.style, colors=colors, strokes=strokes, id=self.id) elif css.startswith('file://'): css = css[len('file://'):] if not os.path.exists(css): css = os.path.join(os.path.dirname(__file__), 'css', css) with io.open(css, encoding='utf-8') as f: css_text = template(f.read(), style=self.graph.style, colors=colors, strokes=strokes, id=self.id) if css_text is not None: if not self.graph.pretty_print: css_text = minify_css(css_text) all_css.append(css_text) else: if css.startswith('//') and self.graph.force_uri_protocol: css = '%s:%s' % (self.graph.force_uri_protocol, css) self.processing_instructions.append( etree.PI(u('xml-stylesheet'), u('href="%s"' % css))) self.node(self.defs, 'style', type='text/css').text = '\n'.join(all_css)