コード例 #1
0
ファイル: rfic2009style.py プロジェクト: rhythmus/rinohtype
    def parse_input(self):
        self.title_par = Paragraph(self.title, style=styles['title'])
        self.author_par = Paragraph(self.author, style=styles['author'])
        self.affiliation_par = Paragraph(self.root.head.affiliation.text,
                                         style=styles['affiliation'])

        self.content = Chain(self)
        self.content << Abstract(self.root.head.abstract.text)
        self.content << IndexTerms(self.keywords)

        self.content << Heading(
            self, 'Table of Contents', style=styles['unnumbered'], level=1)
        toc = TableOfContents(
            style=styles['toc'],
            styles=[styles['toc1'], styles['toc2'], styles['toc3']])
        self.content << toc
        for section in self.root.body.section:
            for flowable in section.process(self):
                toc.register(flowable)
                self.content << flowable
        try:
            for flowable in self.root.body.acknowledgement.process(self):
                toc.register(flowable)
                self.content << flowable
        except AttributeError:
            pass
        self.content << Heading(
            self, 'References', style=styles['unnumbered'], level=1)
        self.bibliography.sort()
        self.content << self.bibliography.bibliography()
コード例 #2
0
def test_parse_class_selector():
    def helper(string):
        chars = CharIterator(string)
        return parse_class_selector(chars), ''.join(chars)

    assert helper('Paragraph') == (Paragraph, '')
    assert helper('Paragraph   ') == (Paragraph, '   ')
    assert helper('  Paragraph') == (Paragraph, '')
    assert helper('  Paragraph ') == (Paragraph, ' ')
    assert helper('Paragraph()') == (Paragraph.like(), '')
    assert helper('Paragraph(   )') == (Paragraph.like(), '')
    assert helper("Paragraph('style')") == (Paragraph.like('style'), '')
    assert helper("Paragraph('style', "
                  "meh=5)") == (Paragraph.like('style', meh=5), '')
    assert helper(" StyledText('style')  ") == (StyledText.like('style'), '  ')
コード例 #3
0
ファイル: test_parse.py プロジェクト: brechtm/rinohtype
def test_parse_class_selector():
    def helper(string):
        chars = CharIterator(string)
        return parse_class_selector(chars), ''.join(chars)

    assert helper('Paragraph') == (Paragraph, '')
    assert helper('Paragraph   ') == (Paragraph, '   ')
    assert helper('  Paragraph') == (Paragraph, '')
    assert helper('  Paragraph ') == (Paragraph, ' ')
    assert helper('Paragraph()') == (Paragraph.like(), '')
    assert helper('Paragraph(   )') == (Paragraph.like(), '')
    assert helper("Paragraph('style')") == (Paragraph.like('style'), '')
    assert helper("Paragraph('style', "
                  "meh=5)") == (Paragraph.like('style', meh=5), '')
    assert helper(" StyledText('style')  ") == (StyledText.like('style'), '  ')
コード例 #4
0
ファイル: rfic2009style.py プロジェクト: rhythmus/rinohtype
 def parse(self, document):
     if isinstance(self._parent, LI):
         style = 'list item'
     else:
         style = 'body'
     return Paragraph(self.process_content(document),
                      style=self.style(style))
コード例 #5
0
 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, font.width.title(),
                              font.slant.title(), font.weight.title()),
                      style=style)
コード例 #6
0
ファイル: article.py プロジェクト: frol/rinohtype
 def flowables(self, container):
     document = container.document
     meta = document.metadata
     yield Paragraph(meta['title'], style='title')
     if 'subtitle' in meta:
         yield Paragraph(meta['subtitle'], style='subtitle')
     if document.options['show_date'] and 'date' in meta:
         date = meta['date']
         try:
             yield Paragraph(date.strftime('%B %d, %Y'), style='author')
         except AttributeError:
             yield Paragraph(date, style='author')
     if 'author' in meta and document.options['show_author']:
         yield Paragraph(meta['author'], style='author')
     abstract_location = document.options['abstract_location']
     if 'abstract' in meta and abstract_location == TITLE:
         yield meta['abstract']
コード例 #7
0
ファイル: test_parse.py プロジェクト: brechtm/rinohtype
def test_parse_selector():
    assert parse_selector("Paragraph") == Paragraph
    assert parse_selector("Paragraph / StyledText") == Paragraph / StyledText
    assert parse_selector("  Paragraph / StyledText") == Paragraph / StyledText
    assert parse_selector(" Paragraph /StyledText  ") == Paragraph / StyledText
    assert parse_selector("Paragraph('aa') / StyledText('bb')") \
               == Paragraph.like('aa') / StyledText.like('bb')
    assert parse_selector("Paragraph('aa') / StyledText") \
               == Paragraph.like('aa') / StyledText
    assert parse_selector("Paragraph('aa' ,meh=5) / StyledText") \
               == Paragraph.like('aa', meh=5) / StyledText
    assert parse_selector("Paragraph /    StyledText('bb ') ") \
               == Paragraph / StyledText.like('bb ')
    assert parse_selector("Paragraph('aa') / ... / StyledText(blip ='blop')") \
               == Paragraph.like('aa') / ... / StyledText.like(blip='blop')
    assert parse_selector("  'paragraph' / StyledText")\
               == SelectorByName('paragraph') / StyledText
    assert parse_selector("Paragraph('aa') / ... / 'some style'") \
               == Paragraph.like('aa') / ... / SelectorByName('some style')
コード例 #8
0
def test_select_by_id():
    paragraph1 = Paragraph('A paragraph with an ID.', id='par')
    paragraph2 = Paragraph('A paragraph with another ID.', id='another')
    paragraph3 = Paragraph('A paragraph without ID.')

    selector1 = Paragraph.like(id='par')
    selector2 = Paragraph.like(id='another')
    selector3 = Paragraph

    assert selector1.match(paragraph1, stylesheet, document)
    assert selector2.match(paragraph2, stylesheet, document)
    assert selector3.match(paragraph1, stylesheet, document)
    assert selector3.match(paragraph2, stylesheet, document)
    assert selector3.match(paragraph3, stylesheet, document)

    assert not selector1.match(paragraph2, stylesheet, document)
    assert not selector1.match(paragraph3, stylesheet, document)
    assert not selector2.match(paragraph1, stylesheet, document)
    assert not selector2.match(paragraph3, stylesheet, document)
コード例 #9
0
def test_parse_selector():
    assert parse_selector("Paragraph") == Paragraph
    assert parse_selector("Paragraph / StyledText") == Paragraph / StyledText
    assert parse_selector("  Paragraph / StyledText") == Paragraph / StyledText
    assert parse_selector(" Paragraph /StyledText  ") == Paragraph / StyledText
    assert parse_selector("Paragraph('aa') / StyledText('bb')") \
               == Paragraph.like('aa') / StyledText.like('bb')
    assert parse_selector("Paragraph('aa') / StyledText") \
               == Paragraph.like('aa') / StyledText
    assert parse_selector("Paragraph('aa' ,meh=5) / StyledText") \
               == Paragraph.like('aa', meh=5) / StyledText
    assert parse_selector("Paragraph /    StyledText('bb ') ") \
               == Paragraph / StyledText.like('bb ')
    assert parse_selector("Paragraph('aa') / ... / StyledText(blip ='blop')") \
               == Paragraph.like('aa') / ... / StyledText.like(blip='blop')
    assert parse_selector("  'paragraph' / StyledText")\
               == SelectorByName('paragraph') / StyledText
    assert parse_selector("Paragraph('aa') / ... / 'some style'") \
               == Paragraph.like('aa') / ... / SelectorByName('some style')
コード例 #10
0
    def parse_input(self):
        self.title_par = Paragraph(self.title, style='title')
        self.author_par = Paragraph(self.author, style='author')
        self.affiliation_par = Paragraph(self.root.head.affiliation.text,
                                         style='affiliation')

        self.content = Chain(self)
        self.content << Abstract(self.root.head.abstract.text)
        self.content << IndexTerms(self.keywords)

        toc_heading = Heading('Table of Contents', style='unnumbered')
        toc = TableOfContents()
        self.content << rt.Section([toc_heading, toc])
        for element in self.root.body.getchildren():
            self.content << element.process()

        bib_heading = Heading('References', style='unnumbered')
        self.bibliography.sort()
        bib = Bibliography(self.bibliography)
        self.content << rt.Section([bib_heading, bib])
コード例 #11
0
ファイル: base.py プロジェクト: frol/rinohtype
 def __init__(self, document_part):
     paper = document_part.document.options['page_size']
     orientation = document_part.document.options['page_orientation']
     super().__init__(document_part, paper, orientation)
     options = self.document.options
     h_margin = options['page_horizontal_margin']
     v_margin = options['page_vertical_margin']
     body_width = self.width - (2 * h_margin)
     body_height = self.height - (2 * v_margin)
     title_top = self.height / 4
     self.title = FlowablesContainer('title', self, h_margin, title_top,
                                     body_width, body_height)
     self.title << Paragraph(self.document.metadata['title'],
                             style='title page title')
     if 'subtitle' in self.document.metadata:
         self.title << Paragraph(self.document.metadata['subtitle'],
                                 style='title page subtitle')
     if 'author' in self.document.metadata and options['show_author']:
         self.title << Paragraph(self.document.metadata['author'],
                                 style='title page author')
     if options['show_date']:
         date = self.document.metadata['date']
         try:
             self.title << Paragraph(date.strftime('%B %d, %Y'),
                                     style='title page date')
         except AttributeError:
             self.title << Paragraph(date, style='title page date')
     extra = options['extra']
     if extra:
         self.title << Paragraph(extra, style='title page extra')
コード例 #12
0
ファイル: __main__.py プロジェクト: wxtim/rinohtype
 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)
コード例 #13
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)
コード例 #14
0
from rinoh.attribute import Var
from rinoh.color import HexColor
from rinoh.dimension import PT, CM
from rinoh.document import DocumentTree, Document, FakeContainer
from rinoh.language import EN
from rinoh.paragraph import Paragraph
from rinoh.text import StyledText, SingleStyledText
from rinoh.style import StyleSheet, StyledMatcher

emphasis_selector = StyledText.like('emphasis')
emphasis2_selector = StyledText.like('emphasis2')
highlight_selector = StyledText.like('highlight')
highlight2_selector = StyledText.like('highlight2')
paragraph_selector = Paragraph
paragraph2_selector = Paragraph.like('paragraph2')
paragraph3_selector = Paragraph.like('paragraph3')
paragraph4_selector = Paragraph.like('paragraph4')
missing_selector = Paragraph.like('missing')

matcher = StyledMatcher({
    'emphasized text': emphasis_selector,
    'emphasized text 2': emphasis2_selector,
    'highlighted text': highlight_selector,
    'highlighted text 2': highlight2_selector,
    'paragraph': paragraph_selector,
    'paragraph 2': paragraph2_selector,
    'paragraph 4': paragraph4_selector,
    'missing style': missing_selector,
})
コード例 #15
0
 def flowables(self, document):
     for entry in self.bibliography.bibliography():
         yield Paragraph(entry, parent=self)
コード例 #16
0
ファイル: rfic2009style.py プロジェクト: rhythmus/rinohtype
 def __init__(self, items):
     items = [Paragraph(item, style=PARENT_STYLE) for item in items]
     for item in items:
         item.parent = self
     return super().__init__(items, style=styles['bibliography'])
コード例 #17
0
ファイル: rfic2009style.py プロジェクト: rhythmus/rinohtype
 def parse(self, document):
     par = Paragraph(self.process_content(document),
                     style=self.style('footnote'))
     return RinohFootnote(par)
コード例 #18
0
def front_matter_section_title_flowables(section_id):
    yield Paragraph(Reference(section_id, TITLE),
                    style='front matter section title')
コード例 #19
0
def body_matter_chapter_title_flowables(section_id):
    yield Paragraph('CHAPTER ' + Reference(section_id, NUMBER, style='number'),
                    style='body matter chapter label')
    yield Paragraph(Reference(section_id, TITLE),
                    style='body matter chapter title')
コード例 #20
0
ファイル: test_style.py プロジェクト: z00sts/rinohtype
paragraph_selector = Paragraph

matcher = StyledMatcher({
    'emphasized text': emphasis_selector,
    'paragraph': paragraph_selector,
})

ssheet1 = StyleSheet('base', matcher)
ssheet1('emphasized text', font_slant='italic')
ssheet1('paragraph', space_above=5 * PT)

ssheet2 = StyleSheet('test', base=ssheet1)
ssheet2('paragraph', space_below=10 * PT)

emphasized = SingleStyledText('emphasized', style='emphasis')
paragraph = Paragraph('A paragraph with ' + emphasized + ' text.')

doctree = DocumentTree([paragraph])

document = Document(doctree, ssheet2, EN)
container = FakeContainer(document)


def test_style():
    style1 = ssheet1['emphasized text']
    assert style1.font_width == 'normal'
    assert style1.font_slant == 'italic'

    style2 = ssheet1['paragraph']
    assert style2.space_above == 5 * PT
    assert style2.space_below == 0
コード例 #21
0
 def parse(self):
     return Paragraph(self.process_content())