コード例 #1
0
ファイル: __main__.py プロジェクト: wxtim/rinohtype
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)
コード例 #2
0
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)')
コード例 #3
0
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)'
コード例 #4
0
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))
コード例 #5
0
def test_select_referencingparagraph():
    paragraph = Paragraph('A paragraph with some text.', style='boxed')
    paragraph.classes.append('cls1')
    paragraph_with_id = Paragraph('A paragraph with an ID.', id='par')
    paragraph_with_id.classes.extend(['cls2', 'cls3'])
    refpar = ReferencingParagraph(paragraph)
    refpar_by_id = ReferencingParagraph('par')
    doctree = DocumentTree(
        [paragraph, paragraph_with_id, refpar, refpar_by_id])
    document = Article(doctree)
    container = FakeContainer(document)
    document.prepare(container)
    stylesheet = document.stylesheet

    refpar_match1 = ReferencingParagraph.like(target_style='boxed')
    refpar_match2 = ReferencingParagraph.like(target_has_class='cls1')
    refpar_match3 = ReferencingParagraph.like(target_style='boxed',
                                              target_has_class='cls1')
    refpar_by_id_match = ReferencingParagraph.like(
        target_has_classes=['cls2', 'cls3'])
    bad_match = ReferencingParagraph.like(target_style='boxed',
                                          target_has_class='cls2')

    assert refpar_match1.match(refpar, stylesheet, document)
    assert refpar_match2.match(refpar, stylesheet, document)
    assert refpar_match3.match(refpar, stylesheet, document)
    assert refpar_by_id_match.match(refpar_by_id, stylesheet, document)

    assert not refpar_match1.match(refpar_by_id, stylesheet, document)
    assert not refpar_match2.match(refpar_by_id, stylesheet, document)
    assert not refpar_match3.match(refpar_by_id, stylesheet, document)
    assert not refpar_by_id_match.match(refpar, stylesheet, document)

    assert not bad_match.match(paragraph, stylesheet, document)
    assert not bad_match.match(paragraph_with_id, stylesheet, document)
    assert not bad_match.match(refpar, stylesheet, document)
    assert not bad_match.match(refpar_by_id, stylesheet, document)
コード例 #6
0
ファイル: commonmark.py プロジェクト: z00sts/rinohtype
from rinoh.backend import pdf
from rinoh.frontend.commonmark import CommonMarkReader
from rinoh.templates import Article

if __name__ == '__main__':
    reader = CommonMarkReader()
    for name in ('README', ):
        with open(name + '.md', 'rb') as file:
            document_tree = reader.parse(file)
        document = Article(document_tree, backend=pdf)
        document.render(name)
コード例 #7
0
ファイル: test_sphinx.py プロジェクト: wxtim/rinohtype
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)')
コード例 #8
0
ファイル: test.py プロジェクト: calve/rinohtype
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)