def display_fonts(filename): def font_paragraph(typeface, font): style = ParagraphStyle(typeface=typeface, font_width=font.width, font_slant=font.slant, font_weight=font.weight) return Paragraph('{} {} {} {}'.format( typeface.name, FontWidth.to_name(font.width).title(), font.slant.title(), FontWeight.to_name(font.weight).title()), style=style) def typeface_section(typeface, distribution): group_style = GroupedFlowablesStyle(space_below=10 * PT) title_style = ParagraphStyle(keep_with_next=True, tab_stops='100% RIGHT', border_bottom='0.5pt, #000', padding_bottom=1 * PT, space_below=2 * PT) title = Paragraph('{}\t[{}]'.format(typeface.name, distribution), style=title_style) return StaticGroupedFlowables( [title] + [font_paragraph(typeface, font) for font in typeface.fonts()], style=group_style) document_tree = DocumentTree( typeface_section(typeface, dist) for typeface, dist in installed_typefaces()) template_cfg = Article.Configuration('fonts overview', parts=['contents']) document = template_cfg.document(document_tree) document.render(filename)
def test_sphinx_config_rinoh_template(tmpdir): template_cfg = Article.Configuration('test', stylesheet='sphinx_article') template_cfg = get_template_cfg(tmpdir, rinoh_template=template_cfg) assert template_cfg.template == Article assert (template_cfg.get_attribute_value('stylesheet').name == 'Sphinx (article)')
def test_sphinx_config_rinoh_template(tmpdir): template_cfg = Article.Configuration('test', stylesheet='sphinx_article') app = create_sphinx_app(tmpdir, rinoh_template=template_cfg) template_cfg = template_from_config(app.config, CONFIG_DIR, print) assert template_cfg.template == Article assert template_cfg['stylesheet'].name == 'Sphinx (article)'
def test_rstdemo(tmpdir): configuration = Article.Configuration(stylesheet=sphinx_base14, abstract_location='title', table_of_contents=False) configuration('title_page', top_margin=2 * CM) with open(os.path.join(TEST_DIR, 'demo.txt')) as file: parser = ReStructuredTextReader() flowables = parser.parse(file) document = Article(flowables, configuration=configuration, backend=pdf) os.chdir(tmpdir.strpath) document.render('demo') _, _, _, badlinks, _, _ = check_pdf_links('demo.pdf') pytest.assume(badlinks == ['table-of-contents']) if not diff_pdf(os.path.join(TEST_DIR, 'reference/demo.pdf'), 'demo.pdf'): pytest.fail('The generated PDF is different from the reference PDF.\n' 'Generated files can be found in {}'.format( tmpdir.strpath))
def test_sphinx_config_template_from_instance(tmp_path): base = Article.Configuration('test', stylesheet='sphinx_base14') template_cfg = get_template_configuration(tmp_path, template=base) assert template_cfg.template == Article assert (template_cfg.get_attribute_value('stylesheet').name == 'Sphinx (PDF Core Fonts)')
from rinoh.backend import pdf from rinoh.dimension import CM from rinoh.frontend.rst import ReStructuredTextReader from rinoh.structure import AdmonitionTitles from rinoh.stylesheets import sphinx_article from rinoh.templates import Article if __name__ == '__main__': strings = (AdmonitionTitles(important='IMPORTANT:', tip='TIP:'), ) configuration = Article.Configuration(stylesheet=sphinx_article, abstract_location='title', table_of_contents=False) configuration('title_page', top_margin=2 * CM) for name in ('demo', 'quickstart', 'FAQ', 'THANKS'): parser = ReStructuredTextReader() with open(name + '.txt') as file: flowables = parser.parse(file) document = Article(flowables, strings=strings, configuration=configuration, backend=pdf) document.render(name)