def test_style(): style = ssheet1['emphasized text'] assert style.font_width == 'normal' assert style.font_slant == 'italic' assert style.font_size == Var('font-size') style = ssheet1['emphasized text 2'] assert style.font_slant == 'oblique' style = ssheet1['paragraph'] assert style.space_above == 5 * PT assert style.text_align == Var('text-align') assert style.font_width == 'normal' assert style.font_color == Var('font-color') assert style.indent_first == 2 * PT style = ssheet2['paragraph'] assert style.space_below == 10 * PT assert style.indent_first == Var('indent-first') style = ssheet1['paragraph 2'] assert style.padding_bottom == 3 * PT style = ssheet2['paragraph 3'] assert style.margin_left == 1 * PT style = ssheet1['paragraph 4'] assert style.base == 'paragraph' assert style.padding_top == 5 * PT
def test_style(): style = ssheet1['emphasized text'] assert style.font_width == FontWidth.NORMAL assert style.font_slant == FontSlant.ITALIC assert style.font_size == Var('font-size') style = ssheet1['emphasized text 2'] assert style.font_slant == FontSlant.OBLIQUE style = ssheet1['paragraph'] assert style.space_above == 5 * PT assert style.text_align == Var('text-align') assert style.font_width == FontWidth.NORMAL assert style.font_color == Var('font-color') assert style.indent_first == 2 * PT style = ssheet2['paragraph'] assert style.space_below == 10 * PT assert style.indent_first == Var('indent-first') style = ssheet1['paragraph 2'] assert style.padding_bottom == 3 * PT style = ssheet2['paragraph 3'] assert style.margin_left == 1 * PT style = ssheet1['paragraph 4'] assert style.base == 'paragraph' assert style.padding_top == 5 * PT
def test_template_configuration_file_base(): with TemporaryDirectory() as tmpdir: dir = Path(tmpdir) with (dir / 'a.rtt').open('w') as a: a.write(CONFIGURATION_A) with (dir / 'b.rtt').open('w') as b: b.write(CONFIGURATION_B) conf = TemplateConfigurationFile(b.name) assert conf.template == MyDocumentTemplate header_text = conf.get_variable(PageTemplate, 'header_text', Var('my_header_text')) expected_header_text = SingleStyledText('Configuration B Header') assert header_text == expected_header_text doc = create_document(conf) assert doc.get_option('a') is True assert doc.get_option('b') is False assert doc.get_option('c') is False part_template, = doc.part_templates part = part_template.document_part(doc, 'number') assert part.template_name == 'contents' page = part.new_page(1, new_chapter=False) assert page.template_name == 'contents_page' assert page.get_config_value('columns', doc) == 1 assert page.get_config_value('column_spacing', doc) == 1 * PT # the retrieved config values have a parent (Header/Footer), so we can't # use == but compare their repr (which doesn't include the parent) assert (repr(page.get_config_value('header_text', doc)) == repr(expected_header_text)) assert (repr(page.get_config_value( 'footer_text', doc)) == repr(Field(PAGE_NUMBER) + ' / ' + Field(NUMBER_OF_PAGES)))
class Configuration(TemplateConfiguration): a = Attribute(Bool, True, 'flag A') b = Attribute(Bool, True, 'flag B') c = Attribute(Bool, True, 'flag C') page_tmpl = PageTemplate(page_size=Var('paper_size'), column_spacing=1 * PT)
class MinimalTemplate(DocumentTemplate): stylesheet = OverrideDefault('sphinx_base14') parts = OverrideDefault(['contents']) contents = ContentsPartTemplate() page = PageTemplate(page_size=Var('paper_size'), chapter_title_flowables=None, header_text=None, footer_text=None) contents_page = PageTemplate(base='page')
class Minimal(DocumentTemplate): variables = dict(paper_size='a5') stylesheet = OverrideDefault('sphinx_base14') parts = OverrideDefault(['contents']) contents = ContentsPartTemplate() page = PageTemplate(page_size=Var('paper_size'), chapter_title_flowables=None) contents_page = PageTemplate(base='page')
class MyDocumentTemplate(DocumentTemplate): a = Attribute(Bool, True, 'flag A') b = Attribute(Bool, True, 'flag B') c = Attribute(Bool, True, 'flag C') parts = OverrideDefault(['contents']) contents = ContentsPartTemplate() contents_page = PageTemplate(page_size=Var('paper_size'), column_spacing=1 * PT)
class MyDocumentTemplate(DocumentTemplate): identifier = 'my_document_template' stylesheet = OverrideDefault(sphinx_article) parts = OverrideDefault(['title', 'front_matter', 'contents']) # default document part templates title = MyTitlePartTemplate() front_matter = FixedDocumentPartTemplate(page_number_format='continue') contents = ContentsPartTemplate(page_number_format='continue') # default page templates page = PageTemplate(page_size=Var('paper_size')) title_page = MyTitlePageTemplate(base='page', top_margin=8 * CM) front_matter_page = PageTemplate(base='page') contents_page = PageTemplate(base='page') TEMPLATE_IMAGE = Image(Path(__file__).parent / 'template.png')
'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, }) ssheet1 = StyleSheet('ssheet1', matcher) ssheet1.variables['font-size'] = 5 * PT ssheet1.variables['text-align'] = 'center' ssheet1.variables['font-color'] = HexColor('f00') ssheet1('emphasized text', font_slant='italic', font_size=Var('font-size')) ssheet1('emphasized text 2', base='emphasized text', font_slant='oblique') ssheet1('highlighted text', font_color=HexColor('00f')) ssheet1('highlighted text 2', base='highlighted text', font_size=12 * PT) ssheet1('paragraph', margin_right=55 * PT, space_above=5 * PT, text_align=Var('text-align'), font_size=8 * PT, font_color=Var('font-color'), indent_first=2 * PT) ssheet1('paragraph 2', padding_bottom=3 * PT) ssheet1('paragraph 4', base='paragraph', padding_top=5 * PT) matcher2 = StyledMatcher({ 'paragraph 3': paragraph3_selector,
'highlighted text 2': highlight2_selector, 'paragraph': paragraph_selector, 'paragraph 2': paragraph2_selector, 'paragraph 4': paragraph4_selector, 'missing style': missing_selector, }) ssheet1 = StyleSheet('ssheet1', matcher) ssheet1.variables['font-size'] = 5*PT ssheet1.variables['text-align'] = 'center' ssheet1.variables['font-color'] = HexColor('f00') ssheet1('emphasized text', font_slant='italic', font_size=Var('font-size')) ssheet1('emphasized text 2', base='emphasized text', font_slant='oblique') ssheet1('highlighted text', font_color=HexColor('00f')) ssheet1('highlighted text 2', base='highlighted text', font_size=12*PT) ssheet1('paragraph', margin_right=55*PT, space_above=5*PT, text_align=Var('text-align'), font_size=8*PT, font_color=Var('font-color'), indent_first=2*PT)