Exemple #1
0
def test_get_ucs():
    mtext = MText()
    mtext.dxf.insert = (1, 2, 3)
    m = mtext.ucs().matrix
    assert m.origin.isclose((1, 2, 3))
    assert m.ux.isclose((1, 0, 0))
    assert m.uy.isclose((0, 1, 0))
    assert m.uz.isclose((0, 0, 1))
Exemple #2
0
def test_do_not_write_line_endings():
    txt = MText()
    txt.text = 'test\ntext\r'
    collector = TagCollector(optional=True)
    txt.export_dxf(collector)
    for tag in collector.tags:
        if tag[0] == 1:
            assert tag[1] == 'test\\Ptext\\P'
def test_load_mtext_attribs_from_embedded_object(obj):
    embedded_obj = Tags.from_text(obj)
    dxf = MText().dxf
    dxf.rotation = 45

    load_columns_from_embedded_object(dxf, embedded_obj)
    assert dxf.width == 62.6
    assert dxf.text_direction == (1, 0, 0)
    assert dxf.hasattr('rotation') is False, "remove rotation attribute"
    assert dxf.insert == (69.8, 276.1, 0)
Exemple #4
0
def test_virtual_text_attribute():
    """The MText content is stored in multiple tags (1, 3, 3, ...) and cannot
    be supported as a simple DXF tag.
    """
    entity = MText()
    assert entity.is_supported_dxf_attrib("text") is True

    entity.dxf.text = "Hello"
    assert entity.text == "Hello"
    assert entity.dxf.text == "Hello"
Exemple #5
0
def test_load_dynamic_cols_manual_height():
    """Every column can have a different height.

    The linked MTEXT entities do NOT have the "defined_height" stored in the
    XDATA section ACAD. The only source for the column height is the
    MTextColumns.heights list.

    The linked MTEXT entities do not have an ACAD section at all.

    """
    xdata = get_xdata(DYNAMIC_MANUAL_HEIGHT)
    cols = load_columns_from_xdata(MText().dxf, xdata)
    assert cols.count == 3
    assert cols.column_type == ColumnType.DYNAMIC
    assert cols.auto_height is False
    assert cols.reversed_column_flow is False
    assert cols.defined_height == 0.0, "not defined if auto_height is False"
    assert cols.width == 50.0
    assert cols.gutter_width == 12.5
    assert cols.total_width == 175.0  # 3 * 50 + 2 * 12.5
    # total_height = max(heights) even if the last column is the tallest
    assert cols.total_height == 164.8  # max height
    assert len(cols.linked_handles) == 2
    assert len(cols.heights) == 3  # not stored the main MTEXT entity
    assert cols.heights[-1] == 0.0, "last column height has to be 0.0"
    assert cols.heights == [164.8, 154.3, 0.0]
Exemple #6
0
def new_mtext_with_linked_columns(count=3) -> MText:
    columns = MTextColumns()
    columns.count = count
    columns.width = 10
    columns.gutter_width = 0.5
    columns.defined_height = 50
    mtext = MText.new()
    mtext.setup_columns(columns, linked=True)
    return mtext
Exemple #7
0
def test_mtext_to_code():
    from ezdxf.entities.mtext import MText
    entity = MText.new(handle='ABBA', owner='0', dxfattribs={
        'color': '7',
        'insert': (2, 3, 4),
    })
    text = 'xxx "yyy" \'zzz\''
    entity.text = text
    new_entity = translate_to_code_and_execute(entity)
    for name in ('color', 'insert'):
        assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
    assert new_entity.text == "xxx \"yyy\" 'zzz'"
Exemple #8
0
def test_default_new():
    entity = MText.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "color": 7,
            "insert": (1, 2, 3),
            "char_height": 1.8,
            "width": 20,
            "defined_height": 30,
            "attachment_point": 3,
            "flow_direction": 3,
            "style": "OpenSans",
            "extrusion": (4, 5, 6),
            "text_direction": (7, 8, 9),
            "rect_width": 42,
            "rect_height": 43,
            "rotation": 50,
            "line_spacing_style": 2,
            "line_spacing_factor": 1.7,
            "box_fill_scale": 1.1,
            "bg_fill": 3,
            "bg_fill_color": 14,
            "bg_fill_true_color": 111222,
            "bg_fill_color_name": "magenta",
            "bg_fill_transparency": 1,
        },
    )
    assert entity.dxf.layer == "0"
    assert entity.dxf.color == 7
    assert entity.dxf.insert == (1, 2, 3)
    assert entity.dxf.char_height == 1.8
    assert entity.dxf.width == 20
    assert entity.dxf.defined_height == 30
    assert entity.dxf.attachment_point == 3
    assert entity.dxf.flow_direction == 3
    assert entity.dxf.extrusion == (4, 5, 6)
    assert entity.dxf.text_direction == (7, 8, 9)
    assert entity.dxf.rect_width == 42
    assert entity.dxf.rect_height == 43
    assert entity.dxf.rotation == 50
    assert entity.dxf.line_spacing_style == 2
    assert entity.dxf.line_spacing_factor == 1.7
    assert entity.dxf.box_fill_scale == 1.1
    assert entity.dxf.bg_fill == 3
    assert entity.dxf.bg_fill_color == 14
    assert entity.dxf.bg_fill_true_color == 111222
    assert entity.dxf.bg_fill_color_name == "magenta"
    assert entity.dxf.bg_fill_transparency == 1
def test_load_static_cols():
    """ All columns have the same column height. """
    embedded_obj = Tags.from_text(STATIC)
    cols = load_columns_from_embedded_object(MText().dxf, embedded_obj)
    assert cols.count == 3
    assert cols.column_type == ColumnType.STATIC
    assert cols.auto_height is False
    assert cols.reversed_column_flow is False
    assert cols.defined_height == 150.0, "required for static columns"
    assert cols.width == 50.0
    assert cols.gutter_width == 12.5
    assert cols.total_width == 175.0  # 3 * 50 + 2 * 12.5
    assert cols.total_height == 150.0
    assert len(cols.linked_columns) == 0, "MTEXT is a single entity in R2018"
    assert len(cols.heights) == 0
Exemple #10
0
def test_bg_fill_flags():
    mtext = MText.new()
    mtext.dxf.bg_fill = 0  # bg fill off
    mtext.dxf.bg_fill = 1  # bg fill as color
    assert mtext.dxf.bg_fill == 1
    mtext.dxf.bg_fill = 2  # bg fill as window color
    assert mtext.dxf.bg_fill == 2
    mtext.dxf.bg_fill = 3  # bg fill as background color
    assert mtext.dxf.bg_fill == 3
    mtext.dxf.bg_fill = 0x10  # text frame?
    assert mtext.dxf.bg_fill == 0x10
    mtext.dxf.bg_fill = 4  # invalid flag
    assert mtext.dxf.bg_fill == 0
    mtext.dxf.bg_fill = 0x20  # invalid flag
    assert mtext.dxf.bg_fill == 0
def test_load_dynamic_cols_with_auto_height():
    """ All columns have the same column height. """
    embedded_obj = Tags.from_text(DYNAMIC_AUTO_HEIGHT)
    cols = load_columns_from_embedded_object(MText().dxf, embedded_obj)
    # Count is a calculated value, group code 72 (column height count) is 0!
    assert cols.count == 3
    assert cols.column_type == ColumnType.DYNAMIC
    assert cols.auto_height is True
    assert cols.reversed_column_flow is False
    assert cols.defined_height == 158.1, "required if auto_height is True"
    assert cols.width == 50.0
    assert cols.gutter_width == 12.5
    assert cols.total_width == 175.0  # 3 * 50 + 2 * 12.5
    assert cols.total_height == 158.1
    assert len(cols.linked_columns) == 0, "MTEXT is a single entity in R2018"
    assert len(cols.heights) == 0
Exemple #12
0
def test_default_new():
    entity = MText.new(handle='ABBA',
                       owner='0',
                       dxfattribs={
                           'color': 7,
                           'insert': (1, 2, 3),
                           'char_height': 1.8,
                           'width': 20,
                           'defined_height': 30,
                           'attachment_point': 3,
                           'flow_direction': 3,
                           'style': 'OpenSans',
                           'extrusion': (4, 5, 6),
                           'text_direction': (7, 8, 9),
                           'rect_width': 42,
                           'rect_height': 43,
                           'rotation': 50,
                           'line_spacing_style': 2,
                           'line_spacing_factor': 1.7,
                           'box_fill_scale': 1.1,
                           'bg_fill': 3,
                           'bg_fill_color': 14,
                           'bg_fill_true_color': 111222,
                           'bg_fill_color_name': 'magenta',
                           'bg_fill_transparency': 1,
                       })
    assert entity.dxf.layer == '0'
    assert entity.dxf.color == 7
    assert entity.dxf.insert == (1, 2, 3)
    assert entity.dxf.char_height == 1.8
    assert entity.dxf.width == 20
    assert entity.dxf.defined_height == 30
    assert entity.dxf.attachment_point == 3
    assert entity.dxf.flow_direction == 3
    assert entity.dxf.extrusion == (4, 5, 6)
    assert entity.dxf.text_direction == (7, 8, 9)
    assert entity.dxf.rect_width == 42
    assert entity.dxf.rect_height == 43
    assert entity.dxf.rotation == 50
    assert entity.dxf.line_spacing_style == 2
    assert entity.dxf.line_spacing_factor == 1.7
    assert entity.dxf.box_fill_scale == 1.1
    assert entity.dxf.bg_fill == 3
    assert entity.dxf.bg_fill_color == 14
    assert entity.dxf.bg_fill_true_color == 111222
    assert entity.dxf.bg_fill_color_name == 'magenta'
    assert entity.dxf.bg_fill_transparency == 1
Exemple #13
0
def test_mtext_to_code():
    from ezdxf.entities.mtext import MText

    entity = MText.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "color": "7",
            "insert": (2, 3, 4),
        },
    )
    text = "xxx \"yyy\" 'zzz'"
    entity.text = text
    new_entity = translate_to_code_and_execute(entity)
    for name in ("color", "insert"):
        assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
    assert new_entity.text == "xxx \"yyy\" 'zzz'"
Exemple #14
0
def test_convert_rotation_to_text_direction():
    mtext = MText()
    mtext.dxf.rotation = 45
    mtext.convert_rotation_to_text_direction()
    assert mtext.dxf.hasattr("rotation") is False
    assert mtext.dxf.hasattr("text_direction") is True
    old = mtext.dxf.text_direction

    # calling again, does nothing
    mtext.convert_rotation_to_text_direction()
    assert mtext.dxf.hasattr("rotation") is False
    assert mtext.dxf.hasattr("text_direction") is True
    assert old.isclose(mtext.dxf.text_direction)
def test_load_dynamic_cols_manual_height():
    """ Every column can have a different height. """
    embedded_obj = Tags.from_text(DYNAMIC_MANUAL_HEIGHT)
    cols = load_columns_from_embedded_object(MText().dxf, embedded_obj)
    assert cols.count == 3
    assert cols.column_type == ColumnType.DYNAMIC
    assert cols.auto_height is False
    assert cols.reversed_column_flow is False
    assert cols.defined_height == 0.0, "not defined if auto_height is False"
    assert cols.width == 50.0
    assert cols.gutter_width == 12.5
    assert cols.total_width == 175.0  # 3 * 50 + 2 * 12.5
    # total_height = max(heights) even if the last column is the tallest
    assert cols.total_height == 164.8
    assert cols.total_height == max(cols.heights)
    assert len(cols.linked_columns) == 0, "MTEXT is a single entity in R2018"
    assert len(cols.heights) == 3
    assert cols.heights[-1] == 0.0, "last column height has to be 0.0"
    assert cols.heights == [164.8, 154.3, 0.0]
Exemple #16
0
def test_load_static_cols():
    """All columns have the same column height.

    Each linked MTEXT has the "defined_height" stored in the XDATA section ACAD.

    """
    xdata = get_xdata(STATIC)
    cols = load_columns_from_xdata(MText().dxf, xdata)
    assert cols.count == 3
    assert cols.column_type == ColumnType.STATIC
    assert cols.auto_height is False
    assert cols.reversed_column_flow is False
    assert cols.defined_height == 150.0, "required for static columns"
    assert cols.width == 50.0
    assert cols.gutter_width == 12.5
    assert cols.total_width == 175.0  # 3 * 50 + 2 * 12.5
    assert cols.total_height == 150.0
    assert len(cols.linked_handles) == 2
    assert len(cols.heights) == 0
Exemple #17
0
def test_load_dynamic_cols_with_auto_height():
    """All columns have the same column height.

    Each linked MTEXT has the "defined_height" stored in the XDATA section ACAD.

    """
    xdata = get_xdata(DYNAMIC_AUTO_HEIGHT)
    cols = load_columns_from_xdata(MText().dxf, xdata)
    # Count is a calculated value, group code 72 (column height count) is 0!
    assert cols.count == 3
    assert cols.column_type == ColumnType.DYNAMIC
    assert cols.auto_height is True
    assert cols.reversed_column_flow is False
    assert cols.defined_height == 158.1, "required if auto_height is True"
    assert cols.width == 50.0
    assert cols.gutter_width == 12.5
    assert cols.total_width == 175.0  # 3 * 50 + 2 * 12.5
    assert cols.total_height == 158.1
    assert len(cols.linked_handles) == 2
    assert len(cols.heights) == 0
Exemple #18
0
def make_mtext(txt: str) -> MText:
    mtext = MText()
    xdata = get_xdata(txt)
    mtext._columns = load_columns_from_xdata(mtext.dxf, xdata)
    return mtext
Exemple #19
0
def test_default_init():
    entity = MText()
    assert entity.dxftype() == 'MTEXT'
    assert entity.dxf.handle is None
    assert entity.dxf.owner is None
Exemple #20
0
def entity():
    return MText.from_text(MTEXT)
Exemple #21
0
def test_get_text_direction_from_rotation():
    mtext = MText()
    mtext.dxf.rotation = 45
    s = math.sin(math.radians(mtext.dxf.rotation))
    assert mtext.get_text_direction().isclose((s, s, 0))
Exemple #22
0
def test_transform_interface():
    mtext = MText()
    mtext.dxf.insert = (1, 0, 0)
    mtext.translate(1, 2, 3)
    assert mtext.dxf.insert == (2, 2, 3)
Exemple #23
0
def test_write_dxf():
    entity = MText.from_text(MTEXT)
    result = TagCollector.dxftags(entity)
    expected = basic_tags_from_text(MTEXT)
    assert result == expected
Exemple #24
0
def test_mtext_set_text():
    mtext = MText.from_text(MTEXT)
    mtext.text = "Hello?"
    assert mtext.text == "Hello?"
    assert mtext.dxf.line_spacing_factor == 1.0
Exemple #25
0
def test_mtext_structure(mtext_tags):
    assert len(mtext_tags.subclasses[2]) == 10

    mtext = MText.from_text(MTEXT)
    assert mtext.dxf.handle == "278"
    assert mtext.dxf.line_spacing_factor == 1.0
Exemple #26
0
def test_get_text_direction_from_text_direction():
    mtext = MText()
    mtext.dxf.text_direction = (1, 2, 3)
    assert mtext.get_text_direction().isclose((1, 2, 3))
Exemple #27
0
def test_hasattr_for_virtual_text_attribute_is_always_false():
    entity = MText()
    entity.dxf.text = "Hello"
    assert entity.dxf.hasattr("text") is False
Exemple #28
0
def test_setup_by_virtual_text_attribute():
    entity = MText.new(dxfattribs={"text": "content"})
    assert entity.text == "content"
    assert entity.dxf.text == "content"
Exemple #29
0
def entity():
    e = MText.from_text(MTEXT)
    return e
Exemple #30
0
def test_mtext_without_column_info():
    xdata = get_xdata(NO_COLUMN_INFO)
    cols = load_columns_from_xdata(MText().dxf, xdata)
    assert cols is None