Exemple #1
0
 def test_without_indentation(self):
     flow = tl.FlowText(width=12, align=tl.FlowTextAlignment.CENTER)
     set_flow_content(flow)
     flow.place(0, 0)
     for line in flow:
         assert line.total_width == 10
         assert line.final_location()[0] == 1
Exemple #2
0
 def test_right_indentation(self):
     flow = tl.FlowText(width=12,
                        indent=(0, 0, 0.5),
                        align=tl.FlowTextAlignment.CENTER)
     set_flow_content(flow)
     flow.place(0, 0)
     for line in flow:
         assert line.total_width == 10
         assert line.final_location()[0] == 0.75  # (11.5 - 10) / 2
Exemple #3
0
    def test_without_indentation(self):
        flow = tl.FlowText(width=12, align=tl.FlowTextAlignment.JUSTIFIED)
        set_flow_content(flow)
        flow.place(0, 0)
        lines = list(flow)
        for line in lines[:-1]:
            assert line.total_width == 12  # expand across paragraph width
            assert line.final_location()[0] == 0

        # last line is not expanded
        last_line = lines[-1]
        assert last_line.total_width == 10
        assert last_line.final_location()[0] == 0
def create_layout(align, content):
    # Create a flow text paragraph for the content:
    paragraph = text_layout.FlowText(align=align)
    paragraph.append_content(content)

    # Start the layout engine and set default column width:
    layout = text_layout.Layout(
        width=8,  # default column width for columns without define width
        margins=(0.5, ),  # space around the layout
        # The render object of collections like Layout, Column or Paragraph is
        # called before the render objects of the content managed by the
        # collection.
        # This could be used to render a frame or a background:
        renderer=FrameRenderer(color=2))

    # Append the first column with default width and a content height of 12 drawing
    # units. At least the first column has to be created by the client.
    layout.append_column(height=COLUMN_HEIGHT, gutter=1)

    # Append the content. The content will be distributed across the available
    # columns and automatically overflow into adjacent columns if necessary.
    # The layout engine creates new columns automatically if required by
    # cloning the last column.
    layout.append_paragraphs([paragraph])

    # Content- and total size is always up to date, only the final location
    # has to be updated by calling Layout.place().
    print()
    print(f"Layout has {len(layout)} columns.")
    print(f"Layout total width: {layout.total_width}")
    print(f"Layout total height: {layout.total_height}")

    for n, column in enumerate(layout, start=1):
        print()
        print(f"  {n}. column has {len(column)} paragraph(s)")
        print(f"  Column total width: {column.total_width}")
        print(f"  Column total height: {column.total_height}")

    # It is recommended to place the layout at origin (0, 0) and use a
    # transformation matrix to move the layout to the final location in
    # the DXF target layout - the model space in this example.
    # Set final layout location in the xy-plane with alignment:
    layout.place(align=text_layout.LayoutAlignment.BOTTOM_LEFT)

    # It is possible to add content after calling place(), but place has to be
    # called again before calling the render() method of the layout.
    return layout
Exemple #5
0
 def test_left_indentation(self):
     flow = tl.FlowText(width=12,
                        indent=(0.7, 0.5, 0),
                        align=tl.FlowTextAlignment.LEFT)
     set_flow_content(flow)
     flow.place(0, 0)
     lines = list(flow)
     # first line:
     assert flow.line_width(True) == 12 - 0.7  # available content space
     assert lines[0].final_location()[0] == 0.7
     assert lines[0].total_width == 10
     # remaining lines:
     for line in lines[1:]:
         assert flow.line_width(
             False) == 12 - 0.5  # available content space
         assert line.total_width == 10
         assert line.final_location()[0] == 0.5
Exemple #6
0
    def test_with_indentation(self):
        flow = tl.FlowText(width=12,
                           indent=(0.7, 0.5, 0.5),
                           align=tl.FlowTextAlignment.JUSTIFIED)
        set_flow_content(flow)
        flow.place(0, 0)
        lines = list(flow)
        # first line:
        assert lines[0].total_width == 10.8  # 12 - (0.7 + 0.5)
        assert lines[0].final_location()[0] == 0.7

        # remaining lines:
        for line in lines[1:-1]:
            assert line.total_width == 11  # 12 - (0.5 + 0.5)
            assert line.final_location()[0] == 0.5

        # last line is not expanded:
        assert lines[-1].total_width == 10
        assert lines[-1].final_location()[0] == 0.5
Exemple #7
0
def new_paragraph(cells: List,
                  ctx: MTextContext,
                  cap_height: float,
                  line_spacing: float = 1):
    if cells:
        p = ctx.paragraph
        align = ALIGN.get(p.align, text_layout.FlowTextAlignment.LEFT)
        left = p.left * cap_height
        right = p.right * cap_height
        first = left + p.indent * cap_height  # relative to left
        paragraph = text_layout.FlowText(
            align=align,
            indent=(first, left, right),
            line_spacing=line_spacing,
        )
        paragraph.append_content(cells)
    else:
        paragraph = text_layout.EmptyParagraph(cap_height=ctx.cap_height,
                                               line_spacing=line_spacing)
    return paragraph
Exemple #8
0
 def flow(self):
     # Paragraph alignment is not important for content distribution.
     return tl.FlowText(width=10, renderer=Rect('PAR'))
Exemple #9
0
 def flow(self):
     # Paragraph alignment is not important for content distribution,
     # because the required space is independent from alignment (left,
     # right, center or justified).
     # This may change by implementing regular tabulator support.
     return tl.FlowText(width=10, renderer=Rect('PAR'))
Exemple #10
0
def test_flow_text_available_line_content_space():
    flow = tl.FlowText(width=12, indent=(0.7, 0.5, 0.9))
    assert flow.line_width(first=True) == 12 - 0.7 - 0.9
    assert flow.line_width(first=False) == 12 - 0.5 - 0.9