<commit_before>from .text import PDFText
from bericht.node.text import stringWidth

__all__ = ('PDFPage',)


class PDFPage:

    tag = '@page'

    def __init__(self, document, page_number, css, size='letter', layout='portrait'):
        self.parent = None
        self.classes = []
        self.style = None
        self.position = page_number
        css.apply(self)

        self.document = document
        self.size = size
        self.layout = layout

        dimensions = SIZES[self.size.upper()]
        self.width = dimensions[0 if self.layout is 'portrait' else 1]
        self.height = dimensions[1 if self.layout is 'portrait' else 0]

        margins = DEFAULT_MARGINS.copy()
        if self.style:
            for side in ('top', 'right', 'bottom', 'left'):
                attr = 'margin_'+side
                if attr in self.style.set_attrs:
                    margins[side] = getattr(self.style, attr)
        self.x = margins['left']
        self.y = self.height - margins['top']
        self.available_width = self.width - self.x - margins['right']
        self.margins = margins

        self.content = document.ref()

        # Initialize the Font, XObject, and ExtGState dictionaries
        self.resources = document.ref({
            'ProcSet': ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'],
        })

        if self.style and 'letterhead_page' in self.style.set_attrs:
            letterhead_page = self.document.letterhead[int(self.style.letterhead_page)-1]
            self.resources.meta.update({<commit_msg>ignore letterhead-page style setting if no letterhead is available<commit_after>from .text import PDFText
from bericht.node.text import stringWidth

__all__ = ('PDFPage',)


class PDFPage:

    tag = '@page'

    def __init__(self, document, page_number, css, size='letter', layout='portrait'):
        self.parent = None
        self.classes = []
        self.style = None
        self.position = page_number
        css.apply(self)

        self.document = document
        self.size = size
        self.layout = layout

        dimensions = SIZES[self.size.upper()]
        self.width = dimensions[0 if self.layout is 'portrait' else 1]
        self.height = dimensions[1 if self.layout is 'portrait' else 0]

        margins = DEFAULT_MARGINS.copy()
        if self.style:
            for side in ('top', 'right', 'bottom', 'left'):
                attr = 'margin_'+side
                if attr in self.style.set_attrs:
                    margins[side] = getattr(self.style, attr)
        self.x = margins['left']
        self.y = self.height - margins['top']
        self.available_width = self.width - self.x - margins['right']
        self.margins = margins

        self.content = document.ref()

        # Initialize the Font, XObject, and ExtGState dictionaries
        self.resources = document.ref({
            'ProcSet': ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'],
        })

        if self.style and 'letterhead_page' in self.style.set_attrs and self.document.letterhead:
            letterhead_page = self.document.letterhead[int(self.style.letterhead_page)-1]
            self.resources.meta.update({
{'fraction_non_alphanumeric': 0.11915297092288243, 'fraction_numerical': 0.0031605562579013905, 'mean_word_length': 2.256172839506173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7205541', 'n_tokens_mistral': 938, 'n_tokens_neox': 913, 'n_words': 229}