Beispiel #1
0
    def __init__(self, file_name, **kwargs):

        fin = open(file_name, 'rb')

        pict_type = self.PICT_TYPES[file_name[-3:].lower()]
        if pict_type == self.PNG_LIB:
            width, height = _get_png_dimensions(fin.read(100))
        else:
            width, height = _get_jpg_dimensions(fin)

        codes = [
            pict_type, 'picwgoal%s' % (width * 20),
            'pichgoal%s' % (height * 20)
        ]
        for kwarg, code, default in [('scale_x', 'scalex', '100'), (
                'scale_y', 'scaley', '100'), ('crop_left', 'cropl', '0'), (
                    'crop_right', 'cropr', '0'), ('crop_top', 'cropt', '0'),
                                     ('crop_bottom', 'cropb', '0')]:
            codes.append('pic%s%s' % (code, kwargs.pop(kwarg, default)))

        #  reset back to the start of the file to get all of it and now
        #  turn it into hex.
        fin.seek(0, 0)
        data = []
        image = hexlify(fin.read())
        for i in range(0, len(image), 128):
            data.append(image[i:i + 128])

        data = r'{\pict{\%s}%s}' % ('\\'.join(codes), '\n'.join(data))
        RawCode.__init__(self, data)
Beispiel #2
0
    def format_item(self, item, styles, monitoring_profile, section):
        keywords = get_keywords_in_text(item.get('body_str'),
                                        (monitoring_profile
                                         or {}).get('keywords', []))

        p2 = Paragraph(styles.ParagraphStyles.Normal)
        p2.append(LINE,
                  TEXT('Headline: {}'.format(item.get('headline')), bold=True))
        p2.append(LINE, TEXT('Source: {}'.format(item.get('source')),
                             bold=True))
        p2.append(LINE,
                  TEXT('Keywords: {}'.format(', '.join(keywords)), bold=True))
        if item.get('byline'):
            p2.append(LINE, ('By ' + item['byline']))

        p3 = Paragraph(styles.ParagraphStyles.Normal)
        body_lines = item.get('body_str', '').split('\n')
        for line in body_lines:
            p3.append(line, LINE, LINE)

        if monitoring_profile['alert_type'] == 'linked_text':
            p3.append(
                LINE, LINE,
                RawCode(r'{\field {\*\fldinst HYPERLINK "' +
                        url_for_wire(item, True, section='monitoring') +
                        r'"}{\fldrslt{\ul View Article}}}'))
        section.append(p2)
        section.append(p3)
Beispiel #3
0
 def _bullet_point(self, **kwargs):
     from PyRTF.document.base import RawCode
     hub = {
         'bullet': RawCode(
             r'\u9679\'3f'),  #RawCode(r'\u8729\'b7'),#RawCode(r'\u8226'),
         'star': '*',
         'minus': '-',
         'plus': '+',
         'circle': 'o',
     }
     return hub
Beispiel #4
0
    def make_pictures():
        doc, section, styles = RTFTestCase.initializeDoc()

        # text can be added directly to the section a paragraph object is create as needed
        section.append('Image Example 1')

        section.append(
            'You can add images in one of two ways, either converting the '
            'image each and every time like;')

        image = Image('examples/image.jpg')
        section.append(Paragraph(image))

        section.append(
            'Or you can use the image object to convert the image and then '
            'save it to a raw code element that can be included later.')

        # Test RawCode -- split into separate test?
        rawCodeDecl = image.ToRawCode('TEST_IMAGE')
        assert rawCodeDecl.startswith('TEST_IMAGE = RawCode( """')
        assert rawCodeDecl.endswith('""" )')

        rawCode = RawCode(image.Data)
        section.append(rawCode)
        section.append(
            'The above picture was displayed from a RawCode object without a Paragraph wrapper.'
        )

        section.append('Here are some png files')
        for f in [
                'examples/img1.png', 'examples/img2.png', 'examples/img3.png',
                'examples/img4.png'
        ]:
            section.append(Paragraph(Image(f)))

        return doc
Beispiel #5
0
                        (2, TabPropertySet.DEFAULT_WIDTH * 2),
                        (3, TabPropertySet.DEFAULT_WIDTH * 3)]:
        indent = TabPropertySet.DEFAULT_WIDTH
        ps = ParagraphStyle(
            'List %s' % idx, TextStyle(TextPropertySet(result.Fonts.Arial,
                                                       22)),
            ParagraphPropertySet(space_before=60,
                                 space_after=60,
                                 first_line_indent=-indent,
                                 left_indent=indent))
        result.ParagraphStyles.append(ps)

    return result


PAGE_NUMBER = RawCode(r'{\field{\fldinst page}}')
TOTAL_PAGES = RawCode(r'{\field{\fldinst numpages}}')
SECTION_PAGES = RawCode(r'{\field{\fldinst sectionpages}}')
ARIAL_BULLET = RawCode(r'{\f2\'95}')


class Document:
    def __init__(self,
                 style_sheet=None,
                 default_language=None,
                 view_kind=None,
                 view_zoom_kind=None,
                 view_scale=None):
        self.StyleSheet = style_sheet or MakeDefaultStyleSheet()
        self.Sections = AttributedList(Section)