From 48dfd772244670e1b638ddaf0ada3f61d14cc955 Mon Sep 17 00:00:00 2001 From: Brecht Machiels Date: Sat, 3 Dec 2022 21:08:20 +0100 Subject: [PATCH] Test case triggering issue described in #379 https://github.com/brechtm/rinohtype/issues/379#issuecomment-1315038522 --- .../sphinx/test-customtemplate/conf.py | 35 +++++++++++ .../sphinx/test-customtemplate/index.rst | 4 ++ .../test-customtemplate/mystylesheet.rts | 12 ++++ .../sphinx/test-customtemplate/mytemplate.py | 59 +++++++++++++++++++ .../sphinx/test-customtemplate/mytemplate.rtt | 7 +++ .../test-customtemplate/rear_page_1.png | 1 + .../test-customtemplate/rear_page_2.png | 1 + .../test-customtemplate/rear_page_bg.png | 1 + 8 files changed, 120 insertions(+) create mode 100644 tests_regression/sphinx/test-customtemplate/conf.py create mode 100644 tests_regression/sphinx/test-customtemplate/index.rst create mode 100644 tests_regression/sphinx/test-customtemplate/mystylesheet.rts create mode 100644 tests_regression/sphinx/test-customtemplate/mytemplate.py create mode 100644 tests_regression/sphinx/test-customtemplate/mytemplate.rtt create mode 120000 tests_regression/sphinx/test-customtemplate/rear_page_1.png create mode 120000 tests_regression/sphinx/test-customtemplate/rear_page_2.png create mode 120000 tests_regression/sphinx/test-customtemplate/rear_page_bg.png diff --git a/tests_regression/sphinx/test-customtemplate/conf.py b/tests_regression/sphinx/test-customtemplate/conf.py new file mode 100644 index 000000000..4c2146429 --- /dev/null +++ b/tests_regression/sphinx/test-customtemplate/conf.py @@ -0,0 +1,35 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'Custom Template' +copyright = '1999, Author' +author = 'Author' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [] + +templates_path = ['_templates'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for rinohtype PDF output ---------------------------------------- + +import os +import sys + +sys.path.insert(0, os.path.abspath('.')) + +import mytemplate + +rinoh_documents = [dict( + doc='index', + target='customtemplate', + template='mytemplate.rtt', +)] diff --git a/tests_regression/sphinx/test-customtemplate/index.rst b/tests_regression/sphinx/test-customtemplate/index.rst new file mode 100644 index 000000000..348d8e69f --- /dev/null +++ b/tests_regression/sphinx/test-customtemplate/index.rst @@ -0,0 +1,4 @@ +Rear Cover Page +=============== + +Hello! diff --git a/tests_regression/sphinx/test-customtemplate/mystylesheet.rts b/tests_regression/sphinx/test-customtemplate/mystylesheet.rts new file mode 100644 index 000000000..4ec58bb05 --- /dev/null +++ b/tests_regression/sphinx/test-customtemplate/mystylesheet.rts @@ -0,0 +1,12 @@ +[STYLESHEET] +name=Custom +base=sphinx +description=The Sphinx stylesheet, but using core PDF fonts + +[VARIABLES] +mono_typeface=Courier +serif_typeface=Times +sans_typeface=Helvetica + +[title page date : Paragraph('title page date')] +hide = true diff --git a/tests_regression/sphinx/test-customtemplate/mytemplate.py b/tests_regression/sphinx/test-customtemplate/mytemplate.py new file mode 100644 index 000000000..f492e35f7 --- /dev/null +++ b/tests_regression/sphinx/test-customtemplate/mytemplate.py @@ -0,0 +1,59 @@ +from pathlib import Path + +from rinoh import register_template +from rinoh.attribute import OverrideDefault +from rinoh.dimension import CM, PT +from rinoh.image import Image +from rinoh.layout import CONTENT, DownExpandingContainer, UpExpandingContainer +from rinoh.paragraph import Paragraph +from rinoh.template import (DocumentTemplate, DocumentPartTemplate, + PageBase, PageTemplateBase) +from rinoh.templates import Book +from rinoh.text import StyledText + + +class RearCoverPageTemplate(PageTemplateBase): + def page(self, document_part, page_number, chain): + return RearCoverPage(document_part, self, page_number) + + +REAR_COVER_PAGE_TEXT = r""" +'Some '(style 1) 'Text\n'(style 2) +'Some '(style 1) 'Text'(style 2) +""".replace('\n', '') # work around rinohtype bug + + +class RearCoverPage(PageBase): + configuration_class = RearCoverPageTemplate + + def __init__(self, document_part, template, page_number): + super().__init__(document_part, template, page_number) + margin = 2*CM + split = 20*CM + width = self.width - 2 * margin + self.text = UpExpandingContainer('text', CONTENT, self, left=margin, + bottom=split, width=width) + self.text << Paragraph(StyledText.from_string(REAR_COVER_PAGE_TEXT), + style='rear cover page text') + self.imgs = DownExpandingContainer('images', CONTENT, self, + left=margin, top=split, width=width) + self.imgs << Image(Path(__file__).parent / 'rear_page_1.png', + width=2*CM, align='right') + self.imgs << Image(Path(__file__).parent / 'rear_page_2.png', + width=2*CM, align='right') + + +class RearCoverPartTemplate(DocumentPartTemplate): + drop_if_empty = OverrideDefault(False) + + def _flowables(self, document): + return iter([]) # content is static, placed in RearCoverPage + + +class MyDocumentTemplate(Book): + parts = OverrideDefault(['title', 'front_matter', 'contents', 'back_matter', + 'rear_cover']) + rear_cover = RearCoverPartTemplate() + rear_cover_page = RearCoverPageTemplate(base='page') + +register_template('my_template', MyDocumentTemplate) diff --git a/tests_regression/sphinx/test-customtemplate/mytemplate.rtt b/tests_regression/sphinx/test-customtemplate/mytemplate.rtt new file mode 100644 index 000000000..99a348c20 --- /dev/null +++ b/tests_regression/sphinx/test-customtemplate/mytemplate.rtt @@ -0,0 +1,7 @@ +[TEMPLATE_CONFIGURATION] +name=my template configuration +template=my_template +stylesheet=mystylesheet.rts + +[rear_cover_page] +background = 'rear_page_bg.png', scale=fit diff --git a/tests_regression/sphinx/test-customtemplate/rear_page_1.png b/tests_regression/sphinx/test-customtemplate/rear_page_1.png new file mode 120000 index 000000000..94514d650 --- /dev/null +++ b/tests_regression/sphinx/test-customtemplate/rear_page_1.png @@ -0,0 +1 @@ +../../images/title.png \ No newline at end of file diff --git a/tests_regression/sphinx/test-customtemplate/rear_page_2.png b/tests_regression/sphinx/test-customtemplate/rear_page_2.png new file mode 120000 index 000000000..58e9a2d67 --- /dev/null +++ b/tests_regression/sphinx/test-customtemplate/rear_page_2.png @@ -0,0 +1 @@ +../../images/biohazard.png \ No newline at end of file diff --git a/tests_regression/sphinx/test-customtemplate/rear_page_bg.png b/tests_regression/sphinx/test-customtemplate/rear_page_bg.png new file mode 120000 index 000000000..94514d650 --- /dev/null +++ b/tests_regression/sphinx/test-customtemplate/rear_page_bg.png @@ -0,0 +1 @@ +../../images/title.png \ No newline at end of file