Example #1
0
class TestStraightLine(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()
        self.master = DummyMaster()
        self.sl = StraightLine(mode='h', length=20, name='straight_test', master=self.master)

    def test_relative_x(self):
        actual = self.sl.relative_x
        expected = self.master.get_slave_position(self.sl, 'x')
        self.assertEqual(expected, actual)

    def test_get_relative_x(self):
        actual = self.sl.get_relative_x2()
        expected = self.sl.relative_x + self.sl.length
        self.assertEqual(expected, actual)

    def test_get_width(self):
        actual = self.sl.get_width()
        expected = self.sl.left_margin + self.sl.length + self.sl.right_margin
        self.assertEqual(expected, actual)

    def test_get_height(self):
        actual = self.sl.get_height()
        expected = self.sl.top_margin + self.sl.bottom_margin
        self.assertEqual(expected, actual)

    def test_draw(self):
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.sl.draw(self.pdf)
            self.pdf.write(pdf_path)
Example #2
0
class Test(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()

    def test_draw(self):
        pdf_path = create_test_path(path, 'draw.pdf')
        scene = Scene(relative_x=10, relative_y=10)
        scene.add_draw_object(SegmentedHorizontalLine(name='I', lengths=[3, 10, 5, 15]))
        scene.add_draw_object(SegmentedHorizontalLine(name='II', lengths=[3, 10, 5, 15, 20]))
        scene.draw(self.pdf)
        self.pdf.write(pdf_path)
        # self.assertCompareFiles(pdf_path)

    def test_draw_with_margins(self):
        self.assertFalse(True)

    def test_get_height(self):
        scene = Scene()
        do1 = scene.add_draw_object(HorizontalLine(relative_x=10, length=20, top_margin=10, bottom_margin=10))
        do2 = scene.add_draw_object(HorizontalLine(length=10, relative_x=10))
        expected = sum([do.get_height() + do.top_margin + do.bottom_margin + do.relative_y for do in [do1, do2]])
        actual = scene.get_height()
        self.assertEqual(expected, actual)

    def test_get_width(self):
        self.assertFalse(True)

    def test_get_relative_y2(self):
        self.assertFalse(True)

    def test_frame(self):
        self.assertFalse(True)
Example #3
0
    def test_1(self):
        pdf = Pdf(orientation='landscape', t_margin=25, l_margin=20)
        title = PageText(value='t e s t',
                         v_position='center',
                         h_position='top',
                         relative_y=-14,
                         font_size=18,
                         font_weight='bold')
        composer = PageText(value='A. G. 2019',
                            v_position='right',
                            h_position='top',
                            relative_y=-14)

        pdf_path = path + '_test_1.pdf'
        stl = ScoreTimeLine(
            instruments=[VIOLIN, VIOLA, CELLO, PERCUSSION, ACCORDION],
            units_per_line=60)
        stl.add_module_time_line(
            ModuleTimeLine(start_time=0,
                           module=square.get_module(1, 2),
                           instruments=[VIOLIN, VIOLA, CELLO]))
        stl.add_module_time_line(
            ModuleTimeLine(start_time=16,
                           module=square.get_module(2, 3),
                           instruments=[PERCUSSION]))
        stl.add_module_time_line(
            ModuleTimeLine(start_time=20,
                           module=square.get_module(3, 1),
                           instruments=[ACCORDION]))
        stl.add_module_time_line(
            ModuleTimeLine(
                start_time=60,
                module=square.get_module(3, 3),
                instruments=[VIOLIN, VIOLA, CELLO, PERCUSSION, ACCORDION]))

        stl.add_module_time_line(
            ModuleTimeLine(start_time=120,
                           module=square.get_module(1, 3),
                           instruments=[VIOLIN, VIOLA, CELLO]))

        stl.add_module_time_line(
            ModuleTimeLine(start_time=135,
                           module=square.get_module(3, 3),
                           instruments=[ACCORDION, PERCUSSION]))

        stl.add_module_time_line(
            ModuleTimeLine(start_time=160,
                           module=square.get_module(3, 3),
                           instruments=[ACCORDION, PERCUSSION]))

        stl.draw(pdf)
        for page in pdf.pages:
            pdf.page = page
            title.draw(pdf)
            composer.draw(pdf)
        pdf.write(pdf_path)
        self.assertCompareFiles(actual_file_path=pdf_path)
Example #4
0
class TestCanvas(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()

    def test_empty_draw(self):
        pdf_path = create_test_path(path, 'empty_draw.pdf')
        canvas = Canvas()
        canvas.draw(self.pdf)
        self.pdf.write(pdf_path)
        self.assertCompareFiles(pdf_path)
Example #5
0
 def test_draw_ruler_with_break(self):
     pdf_path = create_test_path(path, 'draw_ruler_with_break.pdf')
     pdf = Pdf(orientation='p')
     tl = TimeLine(length=300)
     printable = (pdf.w - pdf.r_margin - pdf.l_margin)
     tl.unit = Fraction(Fraction(printable), Fraction(20))
     tl.show_interval = 10
     tl.draw(pdf)
     pdf.write(pdf_path)
     self.assertCompareFiles(actual_file_path=pdf_path)
Example #6
0
class TestMarkLine(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()
        self.master = DummyMaster()
        self.ml = MarkLine(mode='v',
                           placement='start',
                           name='mark_line_test',
                           master=self.master)

    def test_relative_x(self):
        actual = self.ml.relative_x
        expected = self.master.get_slave_position(self.ml, 'x')
        self.assertEqual(expected, actual)

    def test_get_relative_x2(self):
        actual = self.ml.get_relative_x2()
        expected = self.ml.relative_x
        self.assertEqual(expected, actual)

    def test_get_relative_y2(self):
        actual = self.ml.get_relative_y2()
        expected = self.ml.relative_y + self.ml.length
        self.assertEqual(expected, actual)

    def test_get_height(self):
        actual = self.ml.get_height()
        expected = self.ml.top_margin + self.ml.length + self.ml.bottom_margin
        self.assertEqual(expected, actual)

    def test_draw(self):
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.ml.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_multiple(self):
        self.ml.master.get_slave_position = lambda slave, position: 0
        self.ml.master.get_slave_margin = lambda slave, margin: 0
        with self.file_path(path, 'draw_multiple', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.ml.draw(self.pdf)
            self.ml.master.get_slave_margin = lambda slave, margin: 5 if margin in [
                'l', 'left'
            ] else 0
            self.ml.draw(self.pdf)
            self.pdf.write(pdf_path)
class TestGenerateLayerSegmentedLine(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf(orientation='l')

    def test_draw(self):
        def change_ft_graphic():
            ft.graphic.unit = unit
            ft.graphic.add_labels(lambda node: round(float(node.value), 2),
                                  placement='above',
                                  font_size=6,
                                  bottom_margin=2,
                                  left_margin=0.5)
            ft.graphic.add_labels(lambda node: node.fractal_order,
                                  placement='below',
                                  font_size=6,
                                  top_margin=1,
                                  left_margin=0.5)

            ft.graphic.change_segment_attributes(bottom_margin=5)

        def change_layer_graphic(layer_graphic):
            for segment in layer_graphic.segments:
                segment.straight_line.add_label(round(
                    float(segment.node.value), 2),
                                                font_size=6,
                                                bottom_margin=3)

        unit = 20
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            ft = make_ft()
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h', first_label=-1, unit=unit)
            self.pdf.draw_ruler('v')
            self.pdf.translate(15, 10)
            pt = PageText('Some Title',
                          v_position='center',
                          font_weight='bold',
                          font_size=12)
            pt.draw(self.pdf)
            self.pdf.translate(0, 10)
            change_ft_graphic()
            ft.graphic.draw(self.pdf)
            self.pdf.translate(0, ft.graphic.get_height() + 10)
            segmented_line = ft.generate_layer_segmented_line(layer_number=2,
                                                              unit=unit)
            change_layer_graphic(segmented_line)
            segmented_line.segments[0].start_mark_line.add_text_label(
                'blabla', placement='left', right_margin=1)
            segmented_line.draw(self.pdf)
            self.pdf.write(pdf_path)
Example #8
0
class TestPdfColumn(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf(orientation='l')

    def test_draw(self):
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            ft = make_ft()
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            ft.graphic.unit = 2
            ft.graphic.draw(self.pdf)

            self.pdf.write(pdf_path)

    def test_add_labels(self):
        def generate_ruler():
            ruler_length = self.pdf.w - self.pdf.l_margin - self.pdf.r_margin
            ruler = HorizontalRuler(length=ruler_length,
                                    unit=3,
                                    show_first_label=True,
                                    label_show_interval=5)
            for segment in ruler.segments:
                try:
                    segment.start_mark_line.text_labels[0].font_size = 8
                except IndexError:
                    pass
            return ruler

        with self.file_path(path, 'add_labels', 'pdf') as pdf_path:
            ft = make_ft()
            self.pdf.translate_page_margins()

            ruler = generate_ruler()
            ruler.draw(self.pdf)
            self.pdf.translate(0, 10)
            ft.graphic.unit = 3
            ft.graphic.add_labels(lambda node: node.fractal_order
                                  if node.fractal_order is not None else '',
                                  font_size=8,
                                  bottom_margin=3)
            ft.graphic.add_labels(lambda node: round(float(node.value), 2),
                                  placement='below',
                                  font_size=6,
                                  top_margin=2)
            ft.graphic.change_segment_attributes(bottom_margin=5)

            ft.graphic.draw(self.pdf)
            self.pdf.write(pdf_path)
Example #9
0
class TestVerticalLineSegment(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()
        self.vls = VerticalLineSegment(length=10)

    def test_get_relative_x2(self):
        actual = self.vls.get_relative_x2()
        expected = self.vls.get_width()
        self.assertEqual(expected, actual)

    def test_start_mark_line_relative_x(self):
        actual = self.vls.start_mark_line.relative_x
        expected = -1.5
        self.assertEqual(expected, actual)

    def test_start_mark_line_relative_y(self):
        actual = self.vls.start_mark_line.relative_y
        expected = self.vls.relative_y
        self.assertEqual(expected, actual)

    def test_end_mark_line_relative_y(self):
        actual = self.vls.end_mark_line.relative_y
        expected = self.vls.relative_y + self.vls.length
        self.assertEqual(expected, actual)

    def test_end_mark_line_relative_x(self):
        actual = self.vls.end_mark_line.relative_x
        expected = -1.5
        self.assertEqual(expected, actual)

    def test_start_mark_line_top_margin(self):
        actual = self.vls.start_mark_line.top_margin
        expected = 0
        self.assertEqual(expected, actual)

    def test_get_width(self):
        actual = self.vls.get_width()
        expected = 3
        self.assertEqual(expected, actual)

    def test_draw(self):
        with self.file_path(parent_path=path, name='draw', extension='pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            self.vls.end_mark_line.show = True
            self.vls.draw(self.pdf)
            self.pdf.write(pdf_path)
Example #10
0
class Test(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()

    # def test_ruler_bottom_margin(self):
    #     tl = TimeLine(length=30, bottom_margin=40)
    #     tl.add_voice('v1')
    #     print(tl.bottom_margin)
    #     print(tl.ruler.bottom_margin)
    #     print(tl.get_height())

    def test_draw_ruler(self):
        pdf_path = create_test_path(path, 'draw_ruler.pdf')
        pdf = Pdf(orientation='p')
        tl = TimeLine(length=50, bottom_margin=40)
        printable = (pdf.w - pdf.r_margin - pdf.l_margin)
        tl.unit = Fraction(Fraction(printable), Fraction(20))
        tl.show_interval = 10
        tl.draw(pdf)
        pdf.write(pdf_path)
        self.assertCompareFiles(actual_file_path=pdf_path)

    def test_draw_ruler_with_break(self):
        pdf_path = create_test_path(path, 'draw_ruler_with_break.pdf')
        pdf = Pdf(orientation='p')
        tl = TimeLine(length=300)
        printable = (pdf.w - pdf.r_margin - pdf.l_margin)
        tl.unit = Fraction(Fraction(printable), Fraction(20))
        tl.show_interval = 10
        tl.draw(pdf)
        pdf.write(pdf_path)
        self.assertCompareFiles(actual_file_path=pdf_path)

    def test_time_line_with_voices(self):
        pdf_path = create_test_path(path, 'time_line_with_voices.pdf')
        tl = TimeLine(length=200, inner_distance=20, bottom_margin=30)
        # voice = tl.add_voice(name='v1')
        # voice.name.relative_x = -5
        # for segment in voice.segments[5:15]:
        #     segment.show = True

        tl.draw(self.pdf)
        self.pdf.write(pdf_path)
class TestVerticalSegmentedLine(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()
        self.vsl = VerticalSegmentedLine(lengths=[10, 15, 20, 25])

    def test_draw(self):
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            self.vsl.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_get_width(self):
        self.vsl.segments[1].start_mark_line.length = 5
        actual = self.vsl.get_width()
        expected = 5
        self.assertEqual(expected, actual)
Example #12
0
class TestHorizontalSegmentedLine(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()
        self.hsl = HorizontalSegmentedLine(lengths=[10, 15, 20, 25])

    def test_draw(self):
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            with self.file_path(parent_path=path, name='draw',
                                extension='pdf') as pdf_path:
                self.pdf.translate_page_margins()
                self.pdf.draw_ruler('h')
                self.pdf.draw_ruler('v')
                self.pdf.translate(10, 10)
                self.hsl.draw(self.pdf)
                self.pdf.write(pdf_path)

    def test_get_height(self):
        self.hsl.segments[1].start_mark_line.length = 5
        actual = self.hsl.get_height()
        expected = 5
        self.assertEqual(expected, actual)

    def test_add_label_left(self):
        self.hsl.add_label('first left label', placement='left')
        self.hsl.add_label('second left label', placement='left')
        self.hsl.add_label('third left label', placement='left')
        self.hsl.add_label('fourth left label', placement='left')
        self.hsl.segments[0].start_mark_line.length = 10
        self.pdf.translate_page_margins()
        self.pdf.draw_ruler('h')
        self.pdf.draw_ruler('v')
        self.pdf.translate(20, 20)
        self.hsl.draw(self.pdf)
        # print(self.hsl.get_relative_position())
        # print(self.hsl.text_labels[0].get_relative_position())
        # print(self.hsl.get_relative_y2())
        # print(self.hsl.get_height())
        with self.file_path(path, 'add_label_left', 'pdf') as pdf_path:
            self.pdf.write(pdf_path)
Example #13
0
class TestAddPage(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()

    def test_absolute_y(self):
        self.pdf.translate(10, 10)
        self.pdf.add_page()
        actual = self.pdf.absolute_positions
        expected = {1: [10, 10], 2: [0, 0]}
        self.assertEqual(expected, actual)

    def test_draw(self):
        self.pdf.translate_page_margins()
        self.pdf.draw_ruler(mode='h')
        self.pdf.draw_ruler(mode='v')
        self.pdf.translate(10, 10)
        vsl = VerticalSegmentedLine(lengths=[10, 20, 30, 40])
        vsl.draw(self.pdf)
        self.pdf.add_page()
        self.pdf.translate_page_margins()
        self.pdf.draw_ruler(mode='h')
        self.pdf.draw_ruler(mode='v')
        self.pdf.translate(10, 10)
        # print(self.pdf.absolute_positions)
        vsl.draw(self.pdf)
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            self.pdf.write(pdf_path)

    def test_page_number(self):
        for i in range(3):
            self.pdf.add_page()
        self.pdf.draw_page_numbers(v_position='center', h_position='bottom')

        with self.file_path(path, 'page_number', 'pdf') as pdf_path:
            self.pdf.write(pdf_path)

    def test_draw_in_reversed_order(self):
        self.pdf.translate(30, 30)
        self.pdf.add_page()
        self.pdf.translate(80, 80)
        self.pdf.add_page()
        self.pdf.page = 2
        text = Text('second page')
        text.draw(self.pdf)
        self.pdf.page = 1
        text = Text('first page')
        text.draw(self.pdf)

        for page in self.pdf.pages:
            self.pdf.page = page
            self.pdf.reset_position()
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')

        self.pdf.draw_page_numbers(v_position='center', h_position='bottom')

        with self.file_path(path, 'draw_in_reversed_order', 'pdf') as pdf_path:
            self.pdf.write(pdf_path)
Example #14
0
class TestTextLabel(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()

    def test_draw(self):
        t = TextLabel(master=DummyPositionMaster(), name='t1', text='Fox is going to be dead.')

        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            t.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_multiple(self):
        t1 = TextLabel(master=DummyPositionMaster(), name='t1', text='Fox is going to be dead.')
        t1.top_margin = -5
        t2 = TextLabel(master=DummyPositionMaster(), name='t2', text='What should we do??')
        t3 = TextLabel(master=DummyPositionMaster(), name='t3', text='What should we do??')
        with self.file_path(path, 'draw_multiple', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            t1.draw(self.pdf)
            self.pdf.translate(0, t1.get_height())
            t2.draw(self.pdf)
            self.pdf.translate(0, t2.get_height())
            t3.draw(self.pdf)
            self.pdf.translate(0, t3.get_height())
            self.pdf.write(pdf_path)

    def test_left_labels(self):
        unit = 1
        length = 40

        lvl = LabeledVerticalLine(lengths=int(length / unit) * [unit])
        for index, segment in enumerate(lvl.segments):
            if index % 10 == 0:
                segment.start_mark_line.length = 3
            else:
                segment.start_mark_line.length = 1.5

        lvl.add_label('first one one', placement='left', font_size=8)
        lvl.add_label('second two two', placement='left')
        lvl.add_label('third three three', placement='left', font_size=12)
        lvl.add_label('fourth four four', placement='left')
        lvl.add_label('fifth five five', placement='left')
        lvl.add_label('sixth six six', placement='left')
        lvl.add_label('seventh seven seven', placement='left')
        with self.file_path(path, 'left_labels', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(30, 10)
            lvl.draw(self.pdf)
            self.pdf.write(pdf_path)
Example #15
0
class TestRuler(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()

    def test_h_ruler(self):
        r = HorizontalRuler(length=50)
        with self.file_path(path, 'h_ruler', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            r.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_h_ruler_A4(self):
        with self.file_path(path, 'h_ruler_A4', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler(mode='h')
            self.pdf.write(pdf_path)

    def test_both_rulers_A4(self):
        with self.file_path(path, 'both_rulers_A4', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler(mode='h')
            self.pdf.draw_ruler(mode='v')
            self.pdf.write(pdf_path)
class TestMarkLineLabels(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()
        self.ls = HorizontalLineSegment(length=20)

    def test_draw_above(self):
        ml = self.ls.start_mark_line
        ml.add_text_label('first text label above')
        ml.add_text_label('second text label above')
        ml.add_text_label('third  text label above')
        self.ls.relative_x = 10
        self.ls.relative_y = 20
        with self.file_path(path, 'draw_above', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')

            self.ls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_one_above(self):
        ml = self.ls.start_mark_line
        ml.length = 20
        ml.add_text_label('first text label above')

        with self.file_path(path, 'draw_one_above', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            # self.pdf.draw_ruler('h')
            # self.pdf.draw_ruler('v')
            self.pdf.translate(30, 30)
            self.ls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_below(self):
        ml = self.ls.start_mark_line
        ml.add_text_label('first text label below', placement='below')
        ml.add_text_label('second text label below', placement='below')
        self.ls.relative_x = 10
        self.ls.relative_y = 20
        with self.file_path(path, 'draw_below', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.ls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_left(self):
        ml = self.ls.start_mark_line
        ml.add_text_label('first text label left', placement='left')
        ml.add_text_label('second text label left left left', placement='left')
        ml.add_text_label('third text label left left left', placement='left')
        ml.left_text_labels[1].font.size = 8
        self.ls.relative_x = 40
        self.ls.relative_y = 10
        with self.file_path(path, 'draw_left', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.ls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_different_sizes(self):
        ml = self.ls.start_mark_line
        ml.add_text_label('first text label above', font_size=7)
        ml.add_text_label('second text label above', font_size=8)
        ml.add_text_label('third text label above', font_size=9)
        with self.file_path(path, 'different_sizes', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 20)
            self.ls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_font_size_8(self):
        ml = self.ls.start_mark_line
        ml.add_text_label('first text label above',
                          font_size=8,
                          bottom_margin=2)
        ml.add_text_label('second text label above',
                          font_size=8,
                          bottom_margin=4)
        ml.add_text_label('third text label above', font_size=8)
        with self.file_path(path, 'font_size_8', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 20)
            self.ls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_below_with_different_mark_line_lengths(self):
        hsl = HorizontalSegmentedLine(lengths=[10, 15, 20])
        hsl.segments[0].start_mark_line.length = 6
        hsl.segments[0].start_mark_line.add_label(1,
                                                  placement='below',
                                                  font_size=8)
        hsl.segments[1].start_mark_line.add_label(2,
                                                  placement='below',
                                                  font_size=8)
        hsl.segments[2].start_mark_line.add_label(3,
                                                  placement='below',
                                                  font_size=8)
        with self.file_path(path, 'below_with_different_mark_line_lengths',
                            'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            hsl.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_vertical_with_left_text_labels(self):
        vsl = VerticalSegmentedLine(lengths=[10, 15, 20])
        vsl.segments[0].start_mark_line.length = 6
        vsl.segments[0].start_mark_line.add_label(1,
                                                  placement='left',
                                                  font_size=8)
        vsl.segments[1].start_mark_line.add_label(2,
                                                  placement='left',
                                                  font_size=8)
        vsl.segments[2].start_mark_line.add_label(3,
                                                  placement='left',
                                                  font_size=8)
        with self.file_path(path, 'vertical_with_left_text_labels',
                            'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            vsl.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_above_with_different_bottom_margins(self):
        ml = self.ls.start_mark_line
        ml.add_text_label('first text label above', bottom_margin=2)
        ml.add_text_label('second text label above', bottom_margin=4)
        ml.add_text_label('third  text label above', bottom_margin=15)
        self.ls.relative_x = 10
        self.ls.relative_y = 40
        with self.file_path(path, 'draw_above_with_different_bottom_margins',
                            'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')

            self.ls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_left_position(self):
        ml = self.ls.start_mark_line
        # print(ml.get_relative_position())
        # print(ml.get_height())
        left_l = ml.add_text_label('left one', placement='left')
        # print(left_l.get_relative_position())
        left_l = ml.add_text_label('left two', placement='left')
        left_l = ml.add_text_label('left three', placement='left')
        left_l = ml.add_text_label('left four', placement='left')

        with self.file_path(path, 'left_position', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(30, 30)
            self.ls.draw(self.pdf)
            self.pdf.write(pdf_path)
Example #17
0
class TestFractal(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf(orientation='l')
        self.ft = FractalTree(value=20)
        self.ft.add_layer()
        self.factor = 2
        fill_tree_with_columns(self.ft, self.factor)

    def test_draw(self):
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            self.ft.manual_graphic.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_with_text(self):
        leaf = self.ft.get_leaves()[1]
        leaf_start_mark_line = leaf.manual_graphic.draw_objects[
            0].start_mark_line
        leaf_start_mark_line.add_label('bla')
        leaf_start_mark_line.add_label('blue')
        row = self.ft.manual_graphic.draw_objects[1]
        row.top_margin = max([
            do.draw_objects[0].start_mark_line.get_above_text_labels_height()
            for do in row.draw_objects
        ])
        print(row.top_margin)
        with self.file_path(path, 'draw_with_text', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            self.ft.manual_graphic.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_filled_tree(self):
        ft = FractalTree(value=20)
        ft.add_layer()
        ft.get_children()[1].add_layer()
        fill_tree_with_columns(ft, 2)

        with self.file_path(path, 'draw_filled_tree', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            ft.manual_graphic.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_unpruned_tree_with_some_text(self):
        ft = FractalTree(value=20)
        ft.add_layer()
        ft.get_children()[0].add_layer()
        ft.get_children()[-1].add_layer()
        fill_tree_with_columns(ft, 2)
        selected_node = ft.select_index([1])
        child_1 = selected_node.get_children()[1]
        child_2 = selected_node.get_children()[2]
        lb1 = child_1.manual_graphic.draw_objects[0].start_mark_line.add_label(
            1, font_size=8, bottom_margin=1)
        lb2 = child_1.manual_graphic.draw_objects[0].start_mark_line.add_label(
            2, font_size=8, bottom_margin=1)
        lb3 = child_2.manual_graphic.draw_objects[0].start_mark_line.add_label(
            3, font_size=8, bottom_margin=1)

        for child in ft.get_children():
            try:
                child.manual_graphic.draw_objects[1].top_margin += 2
            except IndexError:
                pass

        with self.file_path(path, 'draw_unpruned_tree_with_some_text',
                            'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            ft.manual_graphic.draw(self.pdf)
            self.pdf.write(pdf_path)
class TestStraightLineLabels(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()
        self.hls = HorizontalLineSegment(length=20)
        self.hls.start_mark_line.show = False
        self.vls = VerticalLineSegment(length=20)
        self.vls.start_mark_line.show = False

    def test_horizontal_above(self):
        self.hls.straight_line.add_text_label('one above')
        self.hls.straight_line.add_text_label('two above')
        self.hls.straight_line.add_text_label('three above')
        with self.file_path(path, 'horizontal_above', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.hls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_horizontal_below(self):
        self.hls.straight_line.add_text_label('one below', placement='below')
        self.hls.straight_line.add_text_label('two below', placement='below')
        self.hls.straight_line.add_text_label('three below', placement='below')
        with self.file_path(path, 'test_horizontal_below', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.hls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_horizontal_left(self):
        self.hls.straight_line.add_text_label('one left', placement='left')
        self.hls.straight_line.add_text_label('two left', placement='left')
        self.hls.straight_line.add_text_label('three left', placement='left')
        with self.file_path(path, 'horizontal_left', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.hls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_vertical_above(self):
        self.vls.straight_line.add_text_label('one above')
        self.vls.straight_line.add_text_label('two above')
        self.vls.straight_line.add_text_label('three above')
        with self.file_path(path, 'vertical_above', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.vls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_vertical_above_with_relative_y(self):
        self.vls.relative_y = -10
        # print(self.vls.straight_line.relative_y)
        self.vls.straight_line.add_text_label('one above')
        self.vls.straight_line.add_text_label('two above')
        self.vls.straight_line.add_text_label('three above')
        with self.file_path(path, 'vertical_above_with_relative_y', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.vls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_vertical_below(self):
        self.vls.straight_line.add_text_label('one below', placement='below')
        self.vls.straight_line.add_text_label('two below', placement='below')
        self.vls.straight_line.add_text_label('three below', placement='below')
        with self.file_path(path, 'test_vertical_below', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.vls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_vertical_left(self):
        self.vls.straight_line.add_text_label('one left', placement='left')
        self.vls.straight_line.add_text_label('two left', placement='left')
        self.vls.straight_line.add_text_label('three left', placement='left')
        with self.file_path(path, 'vertical_left', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.vls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_vertical_left_with_top_margin(self):
        self.vls.top_margin = 20
        self.vls.straight_line.add_text_label('one left', placement='left')
        self.vls.straight_line.add_text_label('two left', placement='left')
        self.vls.straight_line.add_text_label('three left', placement='left')
        with self.file_path(path, 'vertical_left_with_top_margin', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(20, 20)
            self.vls.draw(self.pdf)
            self.pdf.write(pdf_path)
Example #19
0
class TestText(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()

    def test_draw(self):
        t = Text('The fox is going to be dead.')
        with self.file_path(path, 'draw', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            t.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_with_top_margin(self):
        t = Text('The fox is going to be dead.')
        t.top_margin = 5
        with self.file_path(path, 'draw_with_top_margin', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            t.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_get_height(self):
        t = Text('fox is going to be dead.')
        t.font_size = 14
        t.top_margin = 3
        expected = 7.682066666666666
        actual = t.get_height()
        self.assertEqual(expected, actual)

    def test_height_graphical(self):
        t = Text('The fox is going to be dead.')
        with self.file_path(path, 'height_graphical', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            hls = HorizontalLineSegment(length=t.get_text_width(),
                                        relative_y=-t.get_text_height() * 3 /
                                        4)
            hls.start_mark_line.length = t.get_height()
            hls.end_mark_line.show = True

            with self.pdf.saved_state():
                self.pdf.rect(hls.relative_x, hls.relative_y, hls.get_width(),
                              t.get_height())
                hls.draw(self.pdf)
            t.draw(self.pdf)

            self.pdf.write(pdf_path)

    def test_draw_multiple(self):
        t1 = Text(value='Fox is going to be dead.')
        t2 = Text(value='What should we do??', relative_y=0)
        t3 = Text(value='What should we do??', relative_y=0)
        with self.file_path(path, 'draw_multiple', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            t1.draw(self.pdf)
            self.pdf.translate(0, t1.get_height())
            t2.draw(self.pdf)
            self.pdf.translate(0, t1.get_height())
            t3.draw(self.pdf)
            self.pdf.translate(0, t1.get_height())
            self.pdf.write(pdf_path)

    def test_draw_multiple_with_relative_y(self):
        t1 = Text(value='Fox is going to be dead.',
                  relative_x=10,
                  relative_y=10)
        t2 = Text(value='What should we do??', relative_x=10, relative_y=20)
        t3 = Text(value='What should we do??', relative_x=10, relative_y=30)

        with self.file_path(path, 'draw_multiple_with_relative_y',
                            'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')

            t1.draw(self.pdf)
            t2.draw(self.pdf)
            t3.draw(self.pdf)

            self.pdf.write(pdf_path)
Example #20
0
class TestRowColumn(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf(orientation='l')
        self._make_row()
        self._make_column()

    def _make_row(self):
        r = DrawObjectRow()
        r.add_draw_object(HorizontalLineSegment(10))
        do2 = r.add_draw_object(HorizontalLineSegment(20))
        r.add_draw_object(VerticalSegmentedLine(lengths=[5, 6, 7, 8]))
        do2.start_mark_line.length = 6
        self.row = r

    def _make_column(self):
        c = DrawObjectColumn()
        c.add_draw_object(HorizontalLineSegment(10))
        do2 = c.add_draw_object(HorizontalLineSegment(20))
        c.add_draw_object(VerticalSegmentedLine(lengths=[5, 6, 7, 8]))
        do2.start_mark_line.length = 6
        self.column = c

    def test_draw_row(self):
        with self.file_path(path, 'draw_row', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            r = self.row
            r.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_row_of_segments(self):
        r = DrawObjectRow()
        r.add_draw_object(HorizontalLineSegment(30))
        r.add_draw_object(HorizontalLineSegment(10))
        r.add_draw_object(HorizontalLineSegment(20))
        with self.file_path(path, 'draw_row_of_segments', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            r.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_column_of_row_of_segments(self):
        r = DrawObjectRow()
        r.add_draw_object(HorizontalLineSegment(30))
        r.add_draw_object(HorizontalLineSegment(10))
        r.add_draw_object(HorizontalLineSegment(20))
        c = DrawObjectColumn()
        c.add_draw_object(HorizontalLineSegment(60))
        c.add_draw_object(r)

        with self.file_path(path, 'draw_column_of_row_of_segments', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            c.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_row_of_column_of_segments(self):
        c = DrawObjectColumn()
        c.add_draw_object(HorizontalLineSegment(30))
        c.add_draw_object(HorizontalLineSegment(10))
        c.add_draw_object(HorizontalLineSegment(20))
        r = DrawObjectRow()
        r.add_draw_object(c)

        with self.file_path(path, 'draw_row_of_column_of_segments', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            c.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_column(self):
        with self.file_path(path, 'draw_column', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            c = self.column
            c.draw(self.pdf)
            self.pdf.write(pdf_path)
class TestHorizontalLineSegment(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()
        self.hls = HorizontalLineSegment(length=10)

    def test_get_relative_x2(self):
        actual = self.hls.get_relative_x2()
        expected = self.hls.length
        self.assertEqual(expected, actual)

    def test_start_mark_line_relative_x(self):
        actual = self.hls.start_mark_line.relative_x
        expected = self.hls.relative_x
        self.assertEqual(expected, actual)

    def test_start_mark_line_relative_y(self):
        actual = self.hls.start_mark_line.relative_y
        expected = -1.5
        self.assertEqual(expected, actual)

    def test_end_mark_line_relative_x(self):
        actual = self.hls.end_mark_line.relative_x
        expected = self.hls.relative_x + self.hls.length
        self.assertEqual(expected, actual)

    def test_end_mark_line_relative_y(self):
        actual = self.hls.end_mark_line.relative_y
        expected = -1.5
        self.assertEqual(expected, actual)

    def test_straight_line_top_margin(self):
        actual = self.hls.straight_line.top_margin
        expected = 0
        self.assertEqual(expected, actual)

    def test_start_mark_line_top_margin(self):
        actual = self.hls.start_mark_line.top_margin
        expected = 0
        self.assertEqual(expected, actual)

    def test_get_height(self):
        actual = self.hls.get_height()
        expected = 3
        self.assertEqual(expected, actual)

    def test_draw(self):
        with self.file_path(parent_path=path, name='draw', extension='pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            self.hls.end_mark_line.show = True
            self.hls.draw(self.pdf)
            self.pdf.write(pdf_path)

    def test_draw_list(self):
        segments = [HorizontalLineSegment(length) for length in range(10, 30, 5)]
        segments[-1].end_mark_line.show = True
        with self.file_path(parent_path=path, name='draw_list', extension='pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            for segment in segments:
                segment.draw(self.pdf)
                self.pdf.translate(segment.get_width(), 0)

            self.pdf.write(pdf_path)

    def test_draw_with_top_margin(self):
        self.hls.top_margin = 15

        with self.file_path(parent_path=path, name='draw_with_top_margin', extension='pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)

            self.hls.end_mark_line.show = True
            self.hls.draw(self.pdf)

            self.pdf.write(pdf_path)

    def test_end_mark_line_labels(self):
        self.hls.end_mark_line.add_label('end mark line')
        with self.file_path(parent_path=path, name='end_mark_line_labels', extension='pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)

            self.hls.end_mark_line.show = True
            self.hls.draw(self.pdf)

            self.pdf.write(pdf_path)
Example #22
0
class TestClip(TestCase):
    def setUp(self) -> None:
        self.pdf = Pdf()

    def test_line(self):
        pdf_path = create_test_path(path, 'line.pdf')
        self.pdf.rect(0, 0, 50, 50)
        self.pdf.clip_rect(0, 0, 50, 50)
        self.pdf.line(10, 20, 100, 100)
        self.pdf.write(pdf_path)
        self.assertCompareFiles(pdf_path)

    def test_line_break(self):
        def draw_with_clip(index):
            with self.pdf.saved_state():
                self.pdf.clip_rect(-1, -5, 196, 50)
                self.pdf.translate(index * -190, 0)
                ruler.draw(self.pdf)

        ruler = HorizontalRuler(length=800, unit=10)
        with self.file_path(path, 'line_break', 'pdf') as pdf_path:
            self.pdf.translate(10, 10)
            number_of_rows = int(ceil(ruler.length / 190))
            for index in range(number_of_rows):
                if index != 0:
                    self.pdf.translate(0, 30)
                draw_with_clip(index)
            self.pdf.write(pdf_path)

    def test_column_line_break(self):
        def draw_with_clip(index):
            with self.pdf.saved_state():
                self.pdf.clip_rect(-1, -5, 196, 50)
                self.pdf.translate(index * -190, 0)
                c.draw(self.pdf)

        c = DrawObjectColumn()
        c.bottom_margin = 10
        c.add_draw_object(HorizontalRuler(length=800))
        c.add_draw_object(HorizontalSegmentedLine(lengths=400 * [2]))
        with self.file_path(path, 'column_line_break', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            number_of_rows = int(ceil(c.get_width() / 190))
            for index in range(number_of_rows):
                if index != 0:
                    self.pdf.translate(0, c.get_height())
                draw_with_clip(index)
            self.pdf.write(pdf_path)

    def test_column_page_break(self):
        self.pdf.t_margin = 15

        def _prepare_page():
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('v')
            self.pdf.draw_ruler('h')
            self.pdf.translate(clip_area_left_margin, clip_area_top_margin)

        def _add_page():
            self.pdf.add_page()
            _prepare_page()

        def draw_with_clip(index):
            with self.pdf.saved_state():
                self.pdf.clip_rect(-1, -5, clip_area_width + 1.14,
                                   clip_area_height)
                self.pdf.translate(index * -clip_area_width, 0)
                c.draw(self.pdf)

        c = DrawObjectColumn()
        c.bottom_margin = 60
        c.add_draw_object(HorizontalRuler(length=1200, bottom_margin=5))
        c.add_draw_object(HorizontalSegmentedLine(lengths=600 * [2]))

        clip_area_left_margin = 10
        clip_area_top_margin = 10
        clip_area_width = self.pdf.w - self.pdf.l_margin - self.pdf.r_margin - clip_area_left_margin
        clip_area_height = c.get_height()

        with self.file_path(path, 'column_page_break', 'pdf') as pdf_path:
            _prepare_page()
            number_of_rows = int(ceil(c.get_width() / clip_area_width))
            for index in range(number_of_rows):
                if index != 0:
                    self.pdf.translate(0, c.get_height())
                if self.pdf.absolute_y > self.pdf.h - self.pdf.b_margin:
                    _add_page()
                draw_with_clip(index)
            self.pdf.write(pdf_path)

    def test_with_clipping_area(self):
        c = DrawObjectColumn()
        c.bottom_margin = 60
        c.add_draw_object(HorizontalRuler(length=1200, bottom_margin=5))
        c.add_draw_object(HorizontalSegmentedLine(lengths=600 * [2]))
        ca = ClippingArea(self.pdf, draw_object=c)
        self.pdf.translate_page_margins()
        ca.draw()
        with self.file_path(path, 'with_clipping_area', 'pdf') as pdf_path:
            self.pdf.write(pdf_path)

    def test_clipped_draw(self):
        c = DrawObjectColumn()
        c.bottom_margin = 60
        c.add_draw_object(HorizontalRuler(length=1200, bottom_margin=5))
        c.add_draw_object(HorizontalSegmentedLine(lengths=600 * [2]))
        self.pdf.translate_page_margins()
        title = PageText('A very nice title',
                         v_position='center',
                         font_weight='bold',
                         font_size=12,
                         top_margin=10)
        title.draw(self.pdf)
        self.pdf.translate(0, title.get_height())
        c.clipped_draw(self.pdf)

        for page in self.pdf.pages:
            self.pdf.page = page
            self.pdf.reset_position()
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
        with self.file_path(path, 'clipped_draw', 'pdf') as pdf_path:
            self.pdf.write(pdf_path)