Пример #1
0
    def test_render_floating(self):
        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.use_package('wrapfig'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.expect(layout.get_converter().convert('The Caption')).result(
            'THE CAPTION')
        self.expect(layout.use_package('checkheight'))
        builder = self.stub()
        self.expect(layout.get_builder()).result(builder)
        self.expect(builder.build_directory).result('/tmp')
        self.expect(builder.add_file('checkheight.sty', ANY))
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator.render(self.image, '0.56', 'c',
                                 floatable=True,
                                 caption='The Caption')

        self.assertEqual(latex, '\n'.join((
                    r'\checkheight{\includegraphics[width=0.66\linewidth]{XUID_image}}',
                    r'\begin{wrapfigure}{c}{0.56\linewidth}',
                    r'\includegraphics[width=\linewidth]{XUID_image}',
                    r'\caption{THE CAPTION}',
                    r'\end{wrapfigure}',
                    r'\hspace{0em}%%'
                    )))
Пример #2
0
    def test_render_nofloating(self):
        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator.render(self.image, '0.56', 'c')

        self.assertEqual(latex, '\n'.join((
                    r'\begin{center}',
                    r'\includegraphics[width=0.56\linewidth]{XUID_image}',
                    r'\end{center}',
                    )))
Пример #3
0
    def test_render_floating(self):
        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.use_package('wrapfig'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.expect(layout.get_converter().convert('The Caption')).result(
            'THE CAPTION')
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator.render(self.image, '0.56', 'c',
                                 floatable=True,
                                 caption='The Caption')

        self.assertEqual(latex, '\n'.join((
                    r'\begin{wrapfigure}{c}{0.56\textwidth}',
                    r'\includegraphics[width=0.56\textwidth]{XUID_image}',
                    r'\caption{THE CAPTION}',
                    r'\end{wrapfigure}',
                    )))
Пример #4
0
    def test_full(self):
        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator(self.image, 'full')

        self.assertEqual(
            latex,
            r'\includegraphics[width=\linewidth]{XUID_image}')
Пример #5
0
    def test_small_right_nonfloating(self):
        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator(self.image, 'small-right')

        self.assertEqual(latex, '\n'.join((
                    r'\begin{flushright}',
                    r'\includegraphics[width=0.25\linewidth]{XUID_image}',
                    r'\end{flushright}',
                    )))
Пример #6
0
    def get_image_latex(self, floatable):
        image = self.context.getImage()

        if not image or image.get_size() == 0:
            return ''

        image_layout = IBlockConfig(self.context).image_layout
        caption = self.context.getImageCaption()
        generator = ImageLaTeXGenerator(self.context, self.layout)

        return generator(image,
                         image_layout,
                         floatable=floatable,
                         caption=caption)
Пример #7
0
    def test_small_left_nonfloating_caption(self):
        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.expect(layout.get_converter().convert('The Caption')).result(
            'THE CAPTION')
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator(self.image, 'small', caption='The Caption')

        self.assertEqual(latex, '\n'.join((
                    r'\includegraphics[width=0.25\linewidth]{XUID_image}',
                    generate_manual_caption('THE CAPTION', 'figure'),
                    )))
Пример #8
0
    def test_unkown_layout(self):
        # The includegraphics options should never have an empty width
        # option, like [image=], so the default is be 100% when the layout
        # is not recognized.
        # Having a [image=] will make pdflatex hang and this will block the
        # zope thread.

        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator(self.image, 'fancy-unkown')

        self.assertEqual(latex, '\n'.join((
                    r'\includegraphics[width=\linewidth]{XUID_image}',
                    )))
Пример #9
0
    def test_fullwidth_does_not_float(self):
        """Using a floating area (wrapfigure) with a 100% width causes the
        following text to be floated over the image.
        Since in this case floating is not possible (the image takes 100%)
        it should switch to non-floating even when called with
        ``floatable=True``.
        """

        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.expect(layout.get_converter().convert('My Image')).result(
            'MY IMAGE')
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator(self.image, 'full', floatable=True,
                          caption='My Image')

        self.assertEqual(latex, '\n'.join((
                    r'\includegraphics[width=\linewidth]{XUID_image}',
                    generate_manual_caption('MY IMAGE', 'figure'))))
Пример #10
0
    def test_small_left_floating(self):
        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.use_package('wrapfig'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.expect(layout.use_package('checkheight'))
        builder = self.stub()
        self.expect(layout.get_builder()).result(builder)
        self.expect(builder.build_directory).result('/tmp')
        self.expect(builder.add_file('checkheight.sty', ANY))
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator(self.image, 'small', floatable=True)

        self.assertEqual(latex, '\n'.join((
                    r'\checkheight{\includegraphics[width=0.35\linewidth]{XUID_image}}',
                    r'\begin{wrapfigure}{l}{0.25\linewidth}',
                    r'\includegraphics[width=\linewidth]{XUID_image}',
                    r'\end{wrapfigure}',
                    r'\hspace{0em}%%'
                    )))
Пример #11
0
    def test_no_image_layout(self):
        self.replay()

        generator = ImageLaTeXGenerator(None, None)
        self.assertEqual(generator(None, 'no-image'), '')
Пример #12
0
 def render(self):
     image = self.context.getImage()
     image_layout = IBlockConfig(self.context).image_layout
     caption = self.context.Description()
     generator = ImageLaTeXGenerator(self.context, self.layout)
     return generator(image, image_layout, floatable=False, caption=caption)